Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
409 changes: 223 additions & 186 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"blob_codec",
"ddex_parser",
"log_macros",
"ow_wallet",
"owen",
"prover",
"validator_node",
Expand All @@ -16,6 +17,7 @@ log_macros = { path = "./log_macros" }
blob_codec = { path = "./blob_codec" }
ddex_parser = { path = "./ddex_parser" }
owen = { path = "./owen" }
ow_wallet = { path = "./ow_wallet" }
prover = { path = "./prover" }
log = "0.4.27"
thiserror = "2.0.12"
Expand Down
1 change: 1 addition & 0 deletions aws/blobs_batch_sender/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ lambda_runtime = "0.14.3"
tokio = { workspace = true }
owen = { workspace = true, features = ["aws-integration"] }
serde = { workspace = true }
ow_wallet = { workspace = true }
serde_json = { workspace = true }
aws-sdk-s3 = "1.98.0"
alloy = { version = "1.0.32", features = ["full"] }
Expand Down
12 changes: 5 additions & 7 deletions aws/blobs_batch_sender/src/event_handler.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
use aws_lambda_events::event::sqs::SqsEvent;
use blobs_batch_sender::BlobsBatchSenderConfig;
use lambda_runtime::{Error, LambdaEvent};
use owen::{
blobs_queue::BlobsQueueMessageBody,
wallet::{OwenWallet, OwenWalletConfig},
};
use ow_wallet::{OwWallet, OwWalletConfig};
use owen::blobs_queue::BlobsQueueMessageBody;

use crate::{contract::SmartEoaManager, s3::BlobsStorage};

pub(crate) async fn function_handler(event: LambdaEvent<SqsEvent>) -> Result<(), Error> {
println!("Building...");
let config = BlobsBatchSenderConfig::build()?;
let blobs_storage = BlobsStorage::build(&config).await?;
let owen_wallet_config = OwenWalletConfig::from(&config)?;
let owen_wallet = OwenWallet::build(&owen_wallet_config).await?;
let smart_eoa_manager = SmartEoaManager::build(&config, owen_wallet.wallet)?;
let ow_wallet_config = OwWalletConfig::from(&config)?;
let ow_wallet = OwWallet::build(&ow_wallet_config).await?;
let smart_eoa_manager = SmartEoaManager::build(&config, ow_wallet.wallet)?;

println!("Build complate");
let blobhashes = extract_blobhashes(event)?;
Expand Down
4 changes: 2 additions & 2 deletions aws/blobs_batch_sender/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use alloy::primitives::Address;
use lambda_runtime::Error;
use ow_wallet::HasOwWalletFields;
use owen::constants;
use owen::wallet::HasOwenWalletFields;
use std::env;
use std::str::FromStr;

impl HasOwenWalletFields for BlobsBatchSenderConfig {
impl HasOwWalletFields for BlobsBatchSenderConfig {
fn use_kms(&self) -> bool {
self.use_kms
}
Expand Down
14 changes: 14 additions & 0 deletions ow_wallet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "ow_wallet"
version = "0.1.0"
edition = "2024"

[dependencies]
alloy = "1.5.2"
alloy-signer-aws = "1.5.2"
anyhow.workspace = true
aws-config = "1.8.12"
aws-sdk-kms = "1.98.0"
dotenvy.workspace = true
log = { workspace = true }
log_macros.workspace = true
45 changes: 17 additions & 28 deletions owen/src/wallet.rs → ow_wallet/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,54 +1,39 @@
use crate::Config;
use alloy::network::EthereumWallet;
use alloy::primitives::Address;
use alloy::providers::{Provider, ProviderBuilder};
use alloy::signers::local::PrivateKeySigner;
use alloy::signers::Signer;
use alloy::signers::local::PrivateKeySigner;
use alloy_signer_aws::AwsSigner;
use anyhow::Context;
use aws_config::meta::region::RegionProviderChain;
use aws_config::BehaviorVersion;
use aws_config::meta::region::RegionProviderChain;
use log_macros::{format_error, log_info};
use std::env;

pub struct OwenWallet {
pub struct OwWallet {
pub use_kms: bool,
aws_signer: Option<AwsSigner>,
private_key_signer: Option<PrivateKeySigner>,
pub wallet: EthereumWallet,
}

pub trait HasOwenWalletFields {
pub trait HasOwWalletFields {
fn use_kms(&self) -> bool;
fn rpc_url(&self) -> String;
fn private_key(&self) -> Option<String>;
fn signer_kms_id(&self) -> Option<String>;
}

impl HasOwenWalletFields for Config {
fn use_kms(&self) -> bool {
self.use_kms
}
fn rpc_url(&self) -> String {
self.rpc_url.clone()
}
fn private_key(&self) -> Option<String> {
self.private_key.clone()
}
fn signer_kms_id(&self) -> Option<String> {
self.signer_kms_id.clone()
}
}

pub struct OwenWalletConfig {
pub struct OwWalletConfig {
pub use_kms: bool,
pub rpc_url: String,
pub private_key: Option<String>,
pub signer_kms_id: Option<String>,
}

impl OwenWalletConfig {
impl OwWalletConfig {
pub fn build() -> anyhow::Result<Self> {
let rpc_url = Config::get_env_var("RPC_URL");
let rpc_url = Self::get_env_var("RPC_URL");
let mut signer_kms_id = None;
let mut private_key = None;
let use_kms = matches!(
Expand All @@ -59,9 +44,9 @@ impl OwenWalletConfig {
);

if use_kms {
signer_kms_id = Some(Config::get_env_var("SIGNER_KMS_ID"));
signer_kms_id = Some(Self::get_env_var("SIGNER_KMS_ID"));
} else {
private_key = Some(Config::get_env_var("PRIVATE_KEY"));
private_key = Some(Self::get_env_var("PRIVATE_KEY"));
}

Ok(Self {
Expand All @@ -72,7 +57,11 @@ impl OwenWalletConfig {
})
}

pub fn from<C: HasOwenWalletFields>(config_source: &C) -> anyhow::Result<Self> {
fn get_env_var(key: &str) -> String {
env::var(key).expect(format!("Missing env variable: {key}").as_str())
}

pub fn from<C: HasOwWalletFields>(config_source: &C) -> anyhow::Result<Self> {
Ok(Self {
use_kms: config_source.use_kms(),
rpc_url: config_source.rpc_url(),
Expand Down Expand Up @@ -105,8 +94,8 @@ impl OwenWalletConfig {
}
}

impl OwenWallet {
pub async fn build(config: &OwenWalletConfig) -> anyhow::Result<Self> {
impl OwWallet {
pub async fn build(config: &OwWalletConfig) -> anyhow::Result<Self> {
let wallet: EthereumWallet;
let mut aws_signer = None;
let mut private_key_signer: Option<PrivateKeySigner> = None;
Expand Down
1 change: 1 addition & 0 deletions owen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ sentry = { workspace = true }
sentry-log = { workspace = true }
pretty_env_logger = { workspace = true }
prover = { workspace = true }
ow_wallet = { workspace = true }
ravif = "0.12.0"
image = "0.25.6"
rgb = "0.8.52"
Expand Down
8 changes: 4 additions & 4 deletions owen/src/contracts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::blob::BlobTransactionData;
use crate::wallet::OwenWallet;
use crate::{is_local, Config};
use crate::Config;
use alloy::primitives::FixedBytes;
use alloy::providers::{Provider, ProviderBuilder};
use alloy::sol_types::private::Bytes;
Expand All @@ -16,6 +15,7 @@ use alloy::{
sol,
};
use log_macros::{format_error, log_info, log_warn};
use ow_wallet::OwWallet;
use serde_json::json;
use DdexEmitter::getSupportedBlobImageIdsReturn;

Expand Down Expand Up @@ -51,8 +51,8 @@ pub struct ContractsManager {
}

impl ContractsManager {
pub async fn build(config: &Config, owen_wallet: &OwenWallet) -> anyhow::Result<Self> {
let wallet = owen_wallet.wallet.clone();
pub async fn build(config: &Config, ow_wallet: &OwWallet) -> anyhow::Result<Self> {
let wallet = ow_wallet.wallet.clone();

let provider = ProviderBuilder::new()
.wallet(wallet)
Expand Down
10 changes: 5 additions & 5 deletions owen/src/ipfs.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::{
constants::{self, IPFS_API_ADD_FILE, REQWEST_CLIENT},
wallet::OwenWallet,
Config,
};
use alloy::hex;
use anyhow::Context;
use log_macros::{format_error, log_info};
use ow_wallet::OwWallet;
use reqwest::{multipart, Body};
use serde::{Deserialize, Serialize};
use tokio_util::codec::{BytesCodec, FramedRead};
Expand All @@ -26,16 +26,16 @@ pub struct IpfsManager<'a> {
local_ipfs: bool,
ipfs_api_base_url: String,
storacha_bridge_url: String,
owen_wallet: &'a OwenWallet,
ow_wallet: &'a OwWallet,
}

impl<'a> IpfsManager<'a> {
pub async fn build(config: &Config, owen_wallet: &'a OwenWallet) -> anyhow::Result<Self> {
pub async fn build(config: &Config, ow_wallet: &'a OwWallet) -> anyhow::Result<Self> {
Ok(Self {
local_ipfs: config.local_ipfs.clone(),
ipfs_api_base_url: config.ipfs_api_base_url.clone(),
storacha_bridge_url: config.storacha_bridge_url.clone(),
owen_wallet,
ow_wallet,
})
}

Expand Down Expand Up @@ -80,7 +80,7 @@ impl<'a> IpfsManager<'a> {
}

async fn sign_authorization_header(&self) -> anyhow::Result<String> {
let signature = self.owen_wallet.sign_message(constants::CLIENT).await?;
let signature = self.ow_wallet.sign_message(constants::CLIENT).await?;

let authorization = format!("{}::0x{}", "OWEN", hex::encode(signature.as_bytes()));
Ok(authorization)
Expand Down
26 changes: 20 additions & 6 deletions owen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ mod image_processor;
mod ipfs;
pub mod logger;
pub mod output_generator;
pub mod wallet;
use alloy::primitives::Address;
use blob::BlobTransactionData;
use contracts::ContractsManager;
use ddex_parser::ParserError;
pub use log;
use log_macros::log_error;
use ow_wallet::{HasOwWalletFields, OwWallet, OwWalletConfig};
use sentry::User;
use serde_json::json;
use std::env;
use std::str::FromStr;

use crate::ipfs::IpfsManager;
use crate::output_generator::{DdexMessage, OutputFilesGenerator};
use crate::wallet::{OwenWallet, OwenWalletConfig};

#[cfg(any(feature = "aws-integration", feature = "local-s3"))]
pub mod s3_message_storage;
Expand Down Expand Up @@ -157,12 +156,12 @@ impl Config {
}

pub async fn run(config: &Config) -> anyhow::Result<Vec<DdexMessage>> {
let owen_wallet_config = OwenWalletConfig::from(config)?;
let owen_wallet = OwenWallet::build(&owen_wallet_config).await?;
let contracts_manager = ContractsManager::build(&config, &owen_wallet).await?;
let ow_wallet_config = OwWalletConfig::from(config)?;
let ow_wallet = OwWallet::build(&ow_wallet_config).await?;
let contracts_manager = ContractsManager::build(&config, &ow_wallet).await?;
contracts_manager.check_image_compatibility().await?;

let ipfs_manager = IpfsManager::build(&config, &owen_wallet).await?;
let ipfs_manager = IpfsManager::build(&config, &ow_wallet).await?;
let output_files_generator = OutputFilesGenerator::build(&config, &ipfs_manager)?;
let ddex_messages = output_files_generator.generate_files().await?;

Expand Down Expand Up @@ -213,3 +212,18 @@ pub async fn run_with_sentry(config: &Config) -> anyhow::Result<Vec<DdexMessage>

anyhow::Ok(ddex_messages)
}

impl HasOwWalletFields for Config {
fn use_kms(&self) -> bool {
self.use_kms
}
fn rpc_url(&self) -> String {
self.rpc_url.clone()
}
fn private_key(&self) -> Option<String> {
self.private_key.clone()
}
fn signer_kms_id(&self) -> Option<String> {
self.signer_kms_id.clone()
}
}
14 changes: 7 additions & 7 deletions owen/src/output_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ impl<'a, 'b> OutputFilesGenerator<'a, 'b> {
#[cfg(test)]
mod tests {
use super::*;
use crate::wallet::{OwenWallet, OwenWalletConfig};
use alloy::primitives::Address;
use ow_wallet::{OwWallet, OwWalletConfig};
use std::str::FromStr;

fn find_cid_in_file(ddex_message: &DdexMessage) -> anyhow::Result<bool> {
Expand Down Expand Up @@ -335,9 +335,9 @@ mod tests {
signer_kms_id: None,
use_batch_sender: false,
};
let owen_wallet_config = OwenWalletConfig::from(&config)?;
let owen_wallet = OwenWallet::build(&owen_wallet_config).await?;
let ipfs_manager = IpfsManager::build(&config, &owen_wallet).await?;
let ow_wallet_config = OwWalletConfig::from(&config)?;
let ow_wallet = OwWallet::build(&ow_wallet_config).await?;
let ipfs_manager = IpfsManager::build(&config, &ow_wallet).await?;
let output_files_generator = OutputFilesGenerator::build(&config, &ipfs_manager)?;
let ddex_messages = output_files_generator.generate_files().await?;

Expand Down Expand Up @@ -375,9 +375,9 @@ mod tests {
use_batch_sender: false,
};
fs::create_dir_all(&config.input_files_dir).unwrap();
let owen_wallet_config = OwenWalletConfig::from(&config).unwrap();
let owen_wallet = OwenWallet::build(&owen_wallet_config).await.unwrap();
let ipfs_manager = IpfsManager::build(&config, &owen_wallet).await.unwrap();
let ow_wallet_config = OwWalletConfig::from(&config).unwrap();
let ow_wallet = OwWallet::build(&ow_wallet_config).await.unwrap();
let ipfs_manager = IpfsManager::build(&config, &ow_wallet).await.unwrap();
let output_files_generator = OutputFilesGenerator::build(&config, &ipfs_manager).unwrap();
let _ = output_files_generator.generate_files().await.unwrap();

Expand Down