diff --git a/bindings/core/src/lib.rs b/bindings/core/src/lib.rs index d589a5fead..2c2dd4e9db 100644 --- a/bindings/core/src/lib.rs +++ b/bindings/core/src/lib.rs @@ -17,7 +17,7 @@ pub use iota_sdk; use iota_sdk::{ client::secret::{SecretManager, SecretManagerDto}, types::block::address::Bech32Address, - wallet::{ClientOptions, Wallet}, + wallet::{core::SecretData, ClientOptions, Wallet, WalletBuilder}, }; use serde::Deserialize; @@ -91,9 +91,9 @@ impl WalletOptions { self } - pub async fn build(self) -> iota_sdk::wallet::Result> { + pub async fn build(self) -> iota_sdk::wallet::Result>> { log::debug!("wallet options: {self:?}"); - let mut builder = Wallet::builder() + let mut builder = WalletBuilder::new() .with_address(self.address) .with_alias(self.alias) .with_public_key_options(self.public_key_options) diff --git a/bindings/core/src/method_handler/call_method.rs b/bindings/core/src/method_handler/call_method.rs index 0b20b5789b..134ba9da75 100644 --- a/bindings/core/src/method_handler/call_method.rs +++ b/bindings/core/src/method_handler/call_method.rs @@ -6,7 +6,7 @@ use std::pin::Pin; use futures::Future; use iota_sdk::{ client::{secret::SecretManager, Client}, - wallet::Wallet, + wallet::{core::SecretData, Wallet}, }; use crate::{ @@ -35,7 +35,7 @@ impl CallMethod for Client { } } -impl CallMethod for Wallet { +impl CallMethod for Wallet> { type Method = WalletMethod; fn call_method<'a>(&'a self, method: Self::Method) -> Pin + 'a>> { @@ -55,7 +55,7 @@ pub async fn call_client_method(client: &Client, method: ClientMethod) -> Respon } /// Call a wallet method. -pub async fn call_wallet_method(wallet: &Wallet, method: WalletMethod) -> Response { +pub async fn call_wallet_method(wallet: &Wallet>, method: WalletMethod) -> Response { log::debug!("Wallet method: {method:?}"); let result = convert_async_panics(|| async { call_wallet_method_internal(wallet, method).await }).await; diff --git a/bindings/core/src/method_handler/wallet.rs b/bindings/core/src/method_handler/wallet.rs index a9b9617ea2..a99df5715b 100644 --- a/bindings/core/src/method_handler/wallet.rs +++ b/bindings/core/src/method_handler/wallet.rs @@ -11,7 +11,8 @@ use iota_sdk::{ }, types::TryFromDto, wallet::{ - types::TransactionWithMetadataDto, BlockIssuerKeySource, PreparedCreateNativeTokenTransactionDto, Wallet, + core::SecretData, types::TransactionWithMetadataDto, BlockIssuerKeySource, + PreparedCreateNativeTokenTransactionDto, Wallet, }, }; @@ -19,7 +20,7 @@ use crate::{method::WalletMethod, response::Response}; /// Call a wallet method. pub(crate) async fn call_wallet_method_internal( - wallet: &Wallet, + wallet: &Wallet>, method: WalletMethod, ) -> crate::Result { let response = match method { @@ -72,7 +73,7 @@ pub(crate) async fn call_wallet_method_internal( } #[cfg(feature = "ledger_nano")] WalletMethod::GetLedgerNanoStatus => { - let ledger_nano_status = (&*wallet.get_secret_manager().read().await) + let ledger_nano_status = (&*wallet.secret_manager().read().await) .as_ledger_nano()? .get_ledger_nano_status() .await; diff --git a/bindings/nodejs/src/wallet.rs b/bindings/nodejs/src/wallet.rs index 182854e900..bf3f426ed8 100644 --- a/bindings/nodejs/src/wallet.rs +++ b/bindings/nodejs/src/wallet.rs @@ -7,7 +7,7 @@ use iota_sdk_bindings_core::{ call_wallet_method as rust_call_wallet_method, iota_sdk::{ client::secret::SecretManager, - wallet::{events::WalletEventType, Wallet}, + wallet::{core::SecretData, events::WalletEventType, Wallet}, }, Response, WalletMethod, WalletOptions, }; @@ -17,7 +17,7 @@ use tokio::sync::RwLock; use crate::{client::ClientMethodHandler, secret_manager::SecretManagerMethodHandler, NodejsError}; -pub type WalletMethodHandler = Arc>>>; +pub type WalletMethodHandler = Arc>>>>; #[napi(js_name = "createWallet")] pub async fn create_wallet(options: String) -> Result> { @@ -100,7 +100,7 @@ pub async fn get_client(wallet: External) -> Result) -> Result> { if let Some(wallet) = &*wallet.as_ref().read().await { - Ok(External::new(wallet.get_secret_manager().clone())) + Ok(External::new(wallet.secret_manager().clone())) } else { Err(Error::new( Status::GenericFailure, diff --git a/bindings/python/src/wallet.rs b/bindings/python/src/wallet.rs index 3a5e1ed57e..b5f60be504 100644 --- a/bindings/python/src/wallet.rs +++ b/bindings/python/src/wallet.rs @@ -120,7 +120,7 @@ pub fn get_secret_manager_from_wallet(wallet: &Wallet) -> Result .read() .await .as_ref() - .map(|w| w.get_secret_manager().clone()) + .map(|w| w.secret_manager().clone()) .ok_or_else(|| { Error::from( serde_json::to_string(&Response::Panic("wallet got destroyed".into())) diff --git a/bindings/wasm/src/wallet.rs b/bindings/wasm/src/wallet.rs index ed794d02eb..8d6bb9d1fe 100644 --- a/bindings/wasm/src/wallet.rs +++ b/bindings/wasm/src/wallet.rs @@ -8,6 +8,7 @@ use iota_sdk_bindings_core::{ iota_sdk::{ client::secret::SecretManager, wallet::{ + core::SecretData, events::types::{WalletEvent, WalletEventType}, Wallet, }, @@ -25,7 +26,7 @@ use crate::{client::ClientMethodHandler, secret_manager::SecretManagerMethodHand /// The Wallet method handler. #[wasm_bindgen(js_name = WalletMethodHandler)] pub struct WalletMethodHandler { - wallet: Arc>>>, + wallet: Arc>>>>, } /// Creates a method handler with the given options. @@ -69,7 +70,7 @@ pub async fn get_secret_manager(method_handler: &WalletMethodHandler) -> Result< .await .as_ref() .ok_or_else(|| "wallet got destroyed".to_string())? - .get_secret_manager() + .secret_manager() .clone(); Ok(SecretManagerMethodHandler { secret_manager }) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index c9d6b3ca99..9b6fb22945 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -13,7 +13,7 @@ use iota_sdk::{ }, crypto::keys::bip44::Bip44, types::block::address::Bech32Address, - wallet::ClientOptions, + wallet::{ClientOptions, WalletBuilder}, }; use log::LevelFilter; @@ -291,7 +291,7 @@ pub async fn init_command( .with_address_index(bip.address_index) }); - Ok(Wallet::builder() + Ok(WalletBuilder::new() .with_secret_manager(secret_manager) .with_client_options(ClientOptions::new().with_node(init_params.node_url.as_str())?) .with_storage_path(storage_path.to_str().expect("invalid unicode")) @@ -332,7 +332,7 @@ pub async fn node_info_command(storage_path: &Path) -> Result { pub async fn restore_command(storage_path: &Path, snapshot_path: &Path, backup_path: &Path) -> Result { check_file_exists(backup_path).await?; - let mut builder = Wallet::builder(); + let mut builder = WalletBuilder::new().with_secret_type(); if check_file_exists(snapshot_path).await.is_ok() { println!( "Detected a stronghold file at {}. Enter password to unlock:", @@ -400,7 +400,7 @@ pub async fn unlock_wallet( None }; - let maybe_wallet = Wallet::builder() + let maybe_wallet = WalletBuilder::new() .with_secret_manager(secret_manager) .with_storage_path(storage_path.to_str().expect("invalid unicode")) .finish() diff --git a/cli/src/main.rs b/cli/src/main.rs index d8e4d83401..73e938f11f 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -8,7 +8,7 @@ mod wallet_cli; use clap::Parser; use fern_logger::{LoggerConfigBuilder, LoggerOutputConfigBuilder}; -use iota_sdk::client::secret::stronghold::StrongholdSecretManager; +use iota_sdk::{client::secret::stronghold::StrongholdSecretManager, wallet::core::SecretData}; use log::LevelFilter; use self::{ @@ -16,7 +16,7 @@ use self::{ error::Error, }; -pub type Wallet = iota_sdk::wallet::Wallet; +pub type Wallet = iota_sdk::wallet::Wallet>; #[macro_export] macro_rules! println_log_info { diff --git a/cli/src/wallet_cli/mod.rs b/cli/src/wallet_cli/mod.rs index 5f31a51288..6e4ab55887 100644 --- a/cli/src/wallet_cli/mod.rs +++ b/cli/src/wallet_cli/mod.rs @@ -1016,7 +1016,7 @@ async fn print_wallet_address(wallet: &Wallet) -> Result<(), Error> { } } - let bip_path = wallet.data().await.signing_options().clone(); + let bip_path = wallet.signing_options().clone(); log = format!("{log}\nBIP path: {bip_path:?}"); log = format!( diff --git a/sdk/examples/how_tos/account/create.rs b/sdk/examples/how_tos/account/create.rs index a9d44a25ca..cf50f18822 100644 --- a/sdk/examples/how_tos/account/create.rs +++ b/sdk/examples/how_tos/account/create.rs @@ -12,7 +12,7 @@ //! cargo run --release --all-features --example create_account_output //! ``` -use iota_sdk::{wallet::Result, Wallet}; +use iota_sdk::{client::secret::SecretManager, wallet::Result, Wallet}; #[tokio::main] async fn main() -> Result<()> { @@ -24,6 +24,7 @@ async fn main() -> Result<()> { } let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/account/destroy.rs b/sdk/examples/how_tos/account/destroy.rs index 20930776f6..c6b1a2f561 100644 --- a/sdk/examples/how_tos/account/destroy.rs +++ b/sdk/examples/how_tos/account/destroy.rs @@ -11,7 +11,7 @@ //! cargo run --release --all-features --example destroy_account_output //! ``` -use iota_sdk::{wallet::Result, Wallet}; +use iota_sdk::{client::secret::SecretManager, wallet::Result, Wallet}; #[tokio::main] async fn main() -> Result<()> { @@ -19,6 +19,7 @@ async fn main() -> Result<()> { dotenvy::dotenv().ok(); let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/account/implicit_account_creation.rs b/sdk/examples/how_tos/account/implicit_account_creation.rs index e14ed9fb92..720bf930e1 100644 --- a/sdk/examples/how_tos/account/implicit_account_creation.rs +++ b/sdk/examples/how_tos/account/implicit_account_creation.rs @@ -14,7 +14,7 @@ use iota_sdk::{ secret::{mnemonic::MnemonicSecretManager, PublicKeyOptions, SecretManager}, }, crypto::keys::bip44::Bip44, - wallet::{ClientOptions, Result, Wallet}, + wallet::{ClientOptions, Result, Wallet, WalletBuilder}, }; #[tokio::main] @@ -25,7 +25,7 @@ async fn main() -> Result<()> { let secret_manager = MnemonicSecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?; let client_options = ClientOptions::new().with_node("https://api.testnet.shimmer.network")?; - let wallet = Wallet::builder() + let wallet = WalletBuilder::new() .with_secret_manager(secret_manager) .with_client_options(client_options) .with_storage_path("implicit_account_creation") diff --git a/sdk/examples/how_tos/account_wallet/request_funds.rs b/sdk/examples/how_tos/account_wallet/request_funds.rs index 2604143aea..cedd9e84a5 100644 --- a/sdk/examples/how_tos/account_wallet/request_funds.rs +++ b/sdk/examples/how_tos/account_wallet/request_funds.rs @@ -7,7 +7,7 @@ //! `cargo run --release --all-features --example account_wallet_request_funds` use iota_sdk::{ - client::request_funds_from_faucet, + client::{request_funds_from_faucet, secret::SecretManager}, types::block::address::{AccountAddress, ToBech32Ext}, wallet::{AccountSyncOptions, Result, SyncOptions}, Wallet, @@ -26,6 +26,7 @@ async fn main() -> Result<()> { // Create the wallet let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/account_wallet/transaction.rs b/sdk/examples/how_tos/account_wallet/transaction.rs index a6183ef651..e937c3ecea 100644 --- a/sdk/examples/how_tos/account_wallet/transaction.rs +++ b/sdk/examples/how_tos/account_wallet/transaction.rs @@ -7,7 +7,10 @@ //! `cargo run --release --all-features --example account_wallet_transaction` use iota_sdk::{ - client::node_api::indexer::query_parameters::BasicOutputQueryParameters, + client::{ + node_api::indexer::query_parameters::BasicOutputQueryParameters, + secret::{stronghold::StrongholdSecretManager, SecretManager}, + }, types::block::address::{AccountAddress, ToBech32Ext}, wallet::{AccountSyncOptions, Result, SyncOptions, TransactionOptions}, Wallet, @@ -32,6 +35,7 @@ async fn main() -> Result<()> { // Create the wallet let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/accounts_and_addresses/check_balance.rs b/sdk/examples/how_tos/accounts_and_addresses/check_balance.rs index 6cfda4f7a1..cffdf2a962 100644 --- a/sdk/examples/how_tos/accounts_and_addresses/check_balance.rs +++ b/sdk/examples/how_tos/accounts_and_addresses/check_balance.rs @@ -11,7 +11,7 @@ //! cargo run --release --all-features --example check_balance //! ``` -use iota_sdk::{wallet::Result, Wallet}; +use iota_sdk::{client::secret::SecretManager, wallet::Result, Wallet}; #[tokio::main] async fn main() -> Result<()> { @@ -23,6 +23,7 @@ async fn main() -> Result<()> { } let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/accounts_and_addresses/consolidate_outputs.rs b/sdk/examples/how_tos/accounts_and_addresses/consolidate_outputs.rs index 6280965836..7b6b238901 100644 --- a/sdk/examples/how_tos/accounts_and_addresses/consolidate_outputs.rs +++ b/sdk/examples/how_tos/accounts_and_addresses/consolidate_outputs.rs @@ -13,6 +13,7 @@ //! ``` use iota_sdk::{ + client::secret::SecretManager, types::block::address::ToBech32Ext, wallet::{ConsolidationParams, Result}, Wallet, @@ -30,6 +31,7 @@ async fn main() -> Result<()> { } let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/accounts_and_addresses/create_wallet.rs b/sdk/examples/how_tos/accounts_and_addresses/create_wallet.rs index 2c719e6ee3..993eb0c021 100644 --- a/sdk/examples/how_tos/accounts_and_addresses/create_wallet.rs +++ b/sdk/examples/how_tos/accounts_and_addresses/create_wallet.rs @@ -16,7 +16,7 @@ use iota_sdk::{ secret::{stronghold::StrongholdSecretManager, PublicKeyOptions, SecretManager}, }, crypto::keys::{bip39::Mnemonic, bip44::Bip44}, - wallet::{ClientOptions, Result, Wallet}, + wallet::{ClientOptions, Result, Wallet, WalletBuilder}, }; #[tokio::main] @@ -48,7 +48,7 @@ async fn main() -> Result<()> { let client_options = ClientOptions::new().with_node(&std::env::var("NODE_URL").unwrap())?; // Create the wallet - let wallet = Wallet::builder() + let wallet = WalletBuilder::new() .with_secret_manager(secret_manager) .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .with_client_options(client_options) diff --git a/sdk/examples/how_tos/accounts_and_addresses/list_outputs.rs b/sdk/examples/how_tos/accounts_and_addresses/list_outputs.rs index 08b416c09f..62306048c1 100644 --- a/sdk/examples/how_tos/accounts_and_addresses/list_outputs.rs +++ b/sdk/examples/how_tos/accounts_and_addresses/list_outputs.rs @@ -8,7 +8,7 @@ //! cargo run --release --all-features --example list_outputs //! ``` -use iota_sdk::{wallet::Result, Wallet}; +use iota_sdk::{client::secret::SecretManager, wallet::Result, Wallet}; #[tokio::main] async fn main() -> Result<()> { @@ -21,6 +21,7 @@ async fn main() -> Result<()> { } let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/accounts_and_addresses/list_transactions.rs b/sdk/examples/how_tos/accounts_and_addresses/list_transactions.rs index 3b416eabad..0e7f41bd35 100644 --- a/sdk/examples/how_tos/accounts_and_addresses/list_transactions.rs +++ b/sdk/examples/how_tos/accounts_and_addresses/list_transactions.rs @@ -9,6 +9,7 @@ //! ``` use iota_sdk::{ + client::secret::SecretManager, wallet::{Result, SyncOptions}, Wallet, }; @@ -24,6 +25,7 @@ async fn main() -> Result<()> { } let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/advanced_transactions/advanced_transaction.rs b/sdk/examples/how_tos/advanced_transactions/advanced_transaction.rs index 6b07de8487..ee4e58b3d1 100644 --- a/sdk/examples/how_tos/advanced_transactions/advanced_transaction.rs +++ b/sdk/examples/how_tos/advanced_transactions/advanced_transaction.rs @@ -8,6 +8,7 @@ //! `cargo run --release --all-features --example advanced_transaction` use iota_sdk::{ + client::secret::SecretManager, types::block::{ address::Bech32Address, output::{ @@ -31,6 +32,7 @@ async fn main() -> Result<()> { // Get the wallet we generated with `create_wallet`. let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/advanced_transactions/claim_transaction.rs b/sdk/examples/how_tos/advanced_transactions/claim_transaction.rs index 6e8a8a60f3..41b44c11a4 100644 --- a/sdk/examples/how_tos/advanced_transactions/claim_transaction.rs +++ b/sdk/examples/how_tos/advanced_transactions/claim_transaction.rs @@ -7,6 +7,7 @@ //! `cargo run --release --all-features --example claim_transaction` use iota_sdk::{ + client::secret::SecretManager, wallet::{OutputsToClaim, Result}, Wallet, }; @@ -22,6 +23,7 @@ async fn main() -> Result<()> { // Get the wallet we generated with `create_wallet`. let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/advanced_transactions/send_micro_transaction.rs b/sdk/examples/how_tos/advanced_transactions/send_micro_transaction.rs index 80b50eae56..04a058f4d6 100644 --- a/sdk/examples/how_tos/advanced_transactions/send_micro_transaction.rs +++ b/sdk/examples/how_tos/advanced_transactions/send_micro_transaction.rs @@ -12,6 +12,7 @@ //! ``` use iota_sdk::{ + client::secret::SecretManager, wallet::{Result, TransactionOptions}, Wallet, }; @@ -32,6 +33,7 @@ async fn main() -> Result<()> { // Get the wallet we generated with `create_wallet`. let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/native_tokens/burn.rs b/sdk/examples/how_tos/native_tokens/burn.rs index 42e2a3773e..4b50dc78e5 100644 --- a/sdk/examples/how_tos/native_tokens/burn.rs +++ b/sdk/examples/how_tos/native_tokens/burn.rs @@ -17,6 +17,7 @@ //! ``` use iota_sdk::{ + client::secret::SecretManager, types::block::output::{NativeToken, TokenId}, wallet::Result, Wallet, U256, @@ -37,6 +38,7 @@ async fn main() -> Result<()> { } let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/native_tokens/create.rs b/sdk/examples/how_tos/native_tokens/create.rs index 467162c741..03db46d979 100644 --- a/sdk/examples/how_tos/native_tokens/create.rs +++ b/sdk/examples/how_tos/native_tokens/create.rs @@ -12,6 +12,7 @@ //! ``` use iota_sdk::{ + client::secret::SecretManager, types::block::output::feature::Irc30Metadata, wallet::{CreateNativeTokenParams, Result}, Wallet, U256, @@ -32,6 +33,7 @@ async fn main() -> Result<()> { } let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/native_tokens/destroy_foundry.rs b/sdk/examples/how_tos/native_tokens/destroy_foundry.rs index 3304548b9d..37565c5542 100644 --- a/sdk/examples/how_tos/native_tokens/destroy_foundry.rs +++ b/sdk/examples/how_tos/native_tokens/destroy_foundry.rs @@ -12,7 +12,7 @@ //! cargo run --release --all-features --example destroy_foundry //! ``` -use iota_sdk::{types::block::output::TokenId, wallet::Result, Wallet}; +use iota_sdk::{client::secret::SecretManager, types::block::output::TokenId, wallet::Result, Wallet}; #[tokio::main] async fn main() -> Result<()> { @@ -24,6 +24,7 @@ async fn main() -> Result<()> { } let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/native_tokens/melt.rs b/sdk/examples/how_tos/native_tokens/melt.rs index 779beda4fe..bad1480f5a 100644 --- a/sdk/examples/how_tos/native_tokens/melt.rs +++ b/sdk/examples/how_tos/native_tokens/melt.rs @@ -16,7 +16,7 @@ //! cargo run --release --all-features --example melt_native_token [TOKEN_ID] //! ``` -use iota_sdk::{types::block::output::TokenId, wallet::Result, Wallet}; +use iota_sdk::{client::secret::SecretManager, types::block::output::TokenId, wallet::Result, Wallet}; // The amount of native tokens to melt const MELT_AMOUNT: u64 = 10; @@ -31,6 +31,7 @@ async fn main() -> Result<()> { } let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/native_tokens/mint.rs b/sdk/examples/how_tos/native_tokens/mint.rs index 44ed6db3ab..2da22d3fa9 100644 --- a/sdk/examples/how_tos/native_tokens/mint.rs +++ b/sdk/examples/how_tos/native_tokens/mint.rs @@ -16,7 +16,7 @@ //! cargo run --release --all-features --example mint_native_token [TOKEN_ID] //! ``` -use iota_sdk::{types::block::output::TokenId, wallet::Result, Wallet}; +use iota_sdk::{client::secret::SecretManager, types::block::output::TokenId, wallet::Result, Wallet}; // The amount of native tokens to mint const MINT_AMOUNT: u64 = 10; @@ -31,6 +31,7 @@ async fn main() -> Result<()> { } let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/native_tokens/send.rs b/sdk/examples/how_tos/native_tokens/send.rs index 5e765bd153..392edaafca 100644 --- a/sdk/examples/how_tos/native_tokens/send.rs +++ b/sdk/examples/how_tos/native_tokens/send.rs @@ -12,6 +12,7 @@ //! ``` use iota_sdk::{ + client::secret::SecretManager, types::block::address::Bech32Address, wallet::{Result, SendNativeTokenParams}, Wallet, @@ -33,6 +34,7 @@ async fn main() -> Result<()> { } let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/nft_collection/00_mint_issuer_nft.rs b/sdk/examples/how_tos/nft_collection/00_mint_issuer_nft.rs index 2a0e5bca56..c22c1143c4 100644 --- a/sdk/examples/how_tos/nft_collection/00_mint_issuer_nft.rs +++ b/sdk/examples/how_tos/nft_collection/00_mint_issuer_nft.rs @@ -15,6 +15,7 @@ //! ``` use iota_sdk::{ + client::secret::{stronghold::StrongholdSecretManager, SecretManager}, types::block::{ output::{NftId, Output, OutputId}, payload::signed_transaction::TransactionId, @@ -33,6 +34,7 @@ async fn main() -> Result<()> { } let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/nft_collection/01_mint_collection_nft.rs b/sdk/examples/how_tos/nft_collection/01_mint_collection_nft.rs index 914897800e..a481383c8b 100644 --- a/sdk/examples/how_tos/nft_collection/01_mint_collection_nft.rs +++ b/sdk/examples/how_tos/nft_collection/01_mint_collection_nft.rs @@ -15,6 +15,7 @@ //! ``` use iota_sdk::{ + client::secret::SecretManager, types::block::{ address::{Bech32Address, NftAddress}, output::{feature::Irc27Metadata, NftId}, @@ -44,6 +45,7 @@ async fn main() -> Result<()> { .parse::()?; let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/nfts/burn_nft.rs b/sdk/examples/how_tos/nfts/burn_nft.rs index 227a777063..fa31d7be81 100644 --- a/sdk/examples/how_tos/nfts/burn_nft.rs +++ b/sdk/examples/how_tos/nfts/burn_nft.rs @@ -11,7 +11,7 @@ //! cargo run --release --all-features --example burn_nft //! ``` -use iota_sdk::{wallet::Result, Wallet}; +use iota_sdk::{client::secret::SecretManager, wallet::Result, Wallet}; #[tokio::main] async fn main() -> Result<()> { @@ -24,6 +24,7 @@ async fn main() -> Result<()> { // Create the wallet let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/nfts/mint_nft.rs b/sdk/examples/how_tos/nfts/mint_nft.rs index 10264f07c9..92ea359535 100644 --- a/sdk/examples/how_tos/nfts/mint_nft.rs +++ b/sdk/examples/how_tos/nfts/mint_nft.rs @@ -12,6 +12,7 @@ //! ``` use iota_sdk::{ + client::secret::SecretManager, types::block::output::{ feature::{Irc27Metadata, IssuerFeature, SenderFeature}, unlock_condition::AddressUnlockCondition, @@ -41,6 +42,7 @@ async fn main() -> Result<()> { // Get the wallet we generated with `create_wallet`. let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/nfts/send_nft.rs b/sdk/examples/how_tos/nfts/send_nft.rs index ba4b29d288..c61cf0650c 100644 --- a/sdk/examples/how_tos/nfts/send_nft.rs +++ b/sdk/examples/how_tos/nfts/send_nft.rs @@ -12,6 +12,7 @@ //! ``` use iota_sdk::{ + client::secret::SecretManager, wallet::{Result, SendNftParams}, Wallet, }; @@ -30,6 +31,7 @@ async fn main() -> Result<()> { // Create the wallet let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/simple_transaction/request_funds.rs b/sdk/examples/how_tos/simple_transaction/request_funds.rs index 13a0de5254..71448d930e 100644 --- a/sdk/examples/how_tos/simple_transaction/request_funds.rs +++ b/sdk/examples/how_tos/simple_transaction/request_funds.rs @@ -11,7 +11,11 @@ //! cargo run --release --all-features --example request_funds //! ``` -use iota_sdk::{client::request_funds_from_faucet, wallet::Result, Wallet}; +use iota_sdk::{ + client::{request_funds_from_faucet, secret::SecretManager}, + wallet::Result, + Wallet, +}; #[tokio::main] async fn main() -> Result<()> { @@ -23,6 +27,7 @@ async fn main() -> Result<()> { } let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/how_tos/simple_transaction/simple_transaction.rs b/sdk/examples/how_tos/simple_transaction/simple_transaction.rs index 9990e6843e..673bbd30a7 100644 --- a/sdk/examples/how_tos/simple_transaction/simple_transaction.rs +++ b/sdk/examples/how_tos/simple_transaction/simple_transaction.rs @@ -11,7 +11,7 @@ //! cargo run --release --all-features --example simple_transaction //! ``` -use iota_sdk::{wallet::Result, Wallet}; +use iota_sdk::{client::secret::SecretManager, wallet::Result, Wallet}; // The base coin amount to send const SEND_AMOUNT: u64 = 1_000_000; @@ -28,6 +28,7 @@ async fn main() -> Result<()> { } let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/wallet/17_check_unlock_conditions.rs b/sdk/examples/wallet/17_check_unlock_conditions.rs index dda853bc04..fa902694f4 100644 --- a/sdk/examples/wallet/17_check_unlock_conditions.rs +++ b/sdk/examples/wallet/17_check_unlock_conditions.rs @@ -11,6 +11,7 @@ //! ``` use iota_sdk::{ + client::secret::SecretManager, types::block::output::{unlock_condition::AddressUnlockCondition, BasicOutputBuilder, UnlockCondition}, wallet::Result, Wallet, @@ -30,6 +31,7 @@ async fn main() -> Result<()> { } let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/wallet/background_syncing.rs b/sdk/examples/wallet/background_syncing.rs index 4abf8f1aac..6aa8ebf860 100644 --- a/sdk/examples/wallet/background_syncing.rs +++ b/sdk/examples/wallet/background_syncing.rs @@ -15,7 +15,7 @@ use iota_sdk::{ secret::{mnemonic::MnemonicSecretManager, PublicKeyOptions}, }, crypto::keys::bip44::Bip44, - wallet::{ClientOptions, Result, Wallet}, + wallet::{ClientOptions, Result, Wallet, WalletBuilder}, }; #[tokio::main] @@ -30,7 +30,7 @@ async fn main() -> Result<()> { // Create a wallet let client_options = ClientOptions::new().with_node(&std::env::var("NODE_URL").unwrap())?; let secret_manager = MnemonicSecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?; - let wallet = Wallet::builder() + let wallet = WalletBuilder::new() .with_secret_manager(secret_manager) .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .with_client_options(client_options) diff --git a/sdk/examples/wallet/events.rs b/sdk/examples/wallet/events.rs index ed0435e274..0feab0a067 100644 --- a/sdk/examples/wallet/events.rs +++ b/sdk/examples/wallet/events.rs @@ -19,7 +19,7 @@ use iota_sdk::{ address::Address, output::{unlock_condition::AddressUnlockCondition, BasicOutputBuilder}, }, - wallet::{ClientOptions, Result, Wallet}, + wallet::{ClientOptions, Result, Wallet, WalletBuilder}, }; // The amount of base coins we'll send @@ -40,7 +40,7 @@ async fn main() -> Result<()> { let secret_manager = MnemonicSecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?; - let wallet = Wallet::builder() + let wallet = WalletBuilder::new() .with_secret_manager(secret_manager) .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .with_client_options(client_options) diff --git a/sdk/examples/wallet/getting_started.rs b/sdk/examples/wallet/getting_started.rs index 7f4b5cc154..bf41adec67 100644 --- a/sdk/examples/wallet/getting_started.rs +++ b/sdk/examples/wallet/getting_started.rs @@ -14,7 +14,7 @@ use iota_sdk::{ secret::{stronghold::StrongholdSecretManager, PublicKeyOptions}, }, crypto::keys::bip44::Bip44, - wallet::{ClientOptions, Result, Wallet}, + wallet::{ClientOptions, Result, Wallet, WalletBuilder}, }; #[tokio::main] @@ -36,7 +36,7 @@ async fn main() -> Result<()> { let client_options = ClientOptions::new().with_node(&std::env::var("NODE_URL").unwrap())?; // Set up and store the wallet. - let wallet = Wallet::builder() + let wallet = WalletBuilder::new() .with_secret_manager(secret_manager) .with_client_options(client_options) .with_storage_path("getting-started-db") diff --git a/sdk/examples/wallet/ledger_nano.rs b/sdk/examples/wallet/ledger_nano.rs index bda465d466..7ffeba5d6d 100644 --- a/sdk/examples/wallet/ledger_nano.rs +++ b/sdk/examples/wallet/ledger_nano.rs @@ -24,7 +24,7 @@ use iota_sdk::{ }, crypto::keys::bip44::Bip44, types::block::address::{Ed25519Address, ToBech32Ext}, - wallet::{ClientOptions, Result, Wallet}, + wallet::{ClientOptions, Result, Wallet, WalletBuilder}, }; // The address to send coins to @@ -43,7 +43,7 @@ async fn main() -> Result<()> { let client_options = ClientOptions::new().with_node(&std::env::var("NODE_URL").unwrap())?; let secret_manager = std::sync::Arc::new(LedgerSecretManager::new(true)); - let wallet = Wallet::builder() + let wallet = WalletBuilder::new() .with_secret_manager(secret_manager.clone()) .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .with_client_options(client_options) diff --git a/sdk/examples/wallet/logger.rs b/sdk/examples/wallet/logger.rs index 578af986ac..9197d65f82 100644 --- a/sdk/examples/wallet/logger.rs +++ b/sdk/examples/wallet/logger.rs @@ -15,7 +15,7 @@ use iota_sdk::{ }, crypto::keys::bip44::Bip44, types::block::address::Ed25519Address, - wallet::{ClientOptions, Result, Wallet}, + wallet::{ClientOptions, Result, Wallet, WalletBuilder}, }; #[tokio::main] @@ -42,7 +42,7 @@ async fn main() -> Result<()> { let secret_manager = std::sync::Arc::new(MnemonicSecretManager::try_from_mnemonic( std::env::var("MNEMONIC").unwrap(), )?); - let wallet = Wallet::builder() + let wallet = WalletBuilder::new() .with_secret_manager(secret_manager.clone()) .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .with_client_options(client_options) diff --git a/sdk/examples/wallet/offline_signing/0_generate_address.rs b/sdk/examples/wallet/offline_signing/0_generate_address.rs index a1d574c747..ca6701bff0 100644 --- a/sdk/examples/wallet/offline_signing/0_generate_address.rs +++ b/sdk/examples/wallet/offline_signing/0_generate_address.rs @@ -14,7 +14,7 @@ use iota_sdk::{ secret::{stronghold::StrongholdSecretManager, PublicKeyOptions, SecretManage}, }, crypto::keys::{bip39::Mnemonic, bip44::Bip44}, - wallet::{ClientOptions, Result, Wallet}, + wallet::{ClientOptions, Result, Wallet, WalletBuilder}, }; const OFFLINE_WALLET_DB_PATH: &str = "./examples/wallet/offline_signing/example-offline-walletdb"; @@ -43,7 +43,7 @@ async fn main() -> Result<()> { secret_manager.store_mnemonic(mnemonic).await?; // Create the wallet with the secret_manager and client options - let wallet = Wallet::builder() + let wallet = WalletBuilder::new() .with_secret_manager(secret_manager) .with_storage_path(OFFLINE_WALLET_DB_PATH) .with_client_options(offline_client) @@ -57,7 +57,7 @@ async fn main() -> Result<()> { write_wallet_address_to_file(&wallet).await } -async fn write_wallet_address_to_file(wallet: &Wallet) -> Result<()> { +async fn write_wallet_address_to_file(wallet: &Wallet) -> Result<()> { use tokio::io::AsyncWriteExt; let wallet_address = wallet.address().await; diff --git a/sdk/examples/wallet/offline_signing/1_prepare_transaction.rs b/sdk/examples/wallet/offline_signing/1_prepare_transaction.rs index 7971cc4ee2..4fcb84fe84 100644 --- a/sdk/examples/wallet/offline_signing/1_prepare_transaction.rs +++ b/sdk/examples/wallet/offline_signing/1_prepare_transaction.rs @@ -15,7 +15,7 @@ use iota_sdk::{ secret::SecretManager, }, crypto::keys::bip44::Bip44, - wallet::{types::Bip44Address, ClientOptions, Result, SendParams, Wallet}, + wallet::{types::Bip44Address, ClientOptions, Result, SendParams, Wallet, WalletBuilder}, }; use serde::Serialize; @@ -45,7 +45,7 @@ async fn main() -> Result<()> { let client_options = ClientOptions::new().with_node(&std::env::var("NODE_URL").unwrap())?; // Create the wallet with the secret_manager and client options - let wallet = Wallet::builder() + let wallet = WalletBuilder::new() .with_secret_manager(SecretManager::Placeholder) .with_storage_path(ONLINE_WALLET_DB_PATH) .with_client_options(client_options.clone()) diff --git a/sdk/examples/wallet/participation.rs b/sdk/examples/wallet/participation.rs index 190ff79462..83fefe3c40 100644 --- a/sdk/examples/wallet/participation.rs +++ b/sdk/examples/wallet/participation.rs @@ -17,7 +17,7 @@ //! ``` use iota_sdk::{ - client::node_manager::node::Node, + client::{node_manager::node::Node, secret::SecretManager}, wallet::{types::participation::ParticipationEventRegistrationOptions, Result}, Wallet, }; @@ -47,6 +47,7 @@ async fn main() -> Result<()> { } let wallet = Wallet::builder() + .with_secret_type::() .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .finish() .await?; diff --git a/sdk/examples/wallet/spammer.rs b/sdk/examples/wallet/spammer.rs index e497f3af21..488656d5f2 100644 --- a/sdk/examples/wallet/spammer.rs +++ b/sdk/examples/wallet/spammer.rs @@ -20,7 +20,7 @@ use iota_sdk::{ output::BasicOutput, payload::signed_transaction::TransactionId, }, - wallet::{ClientOptions, FilterOptions, Result, SendParams, Wallet}, + wallet::{core::SecretData, ClientOptions, FilterOptions, Result, SendParams, Wallet, WalletBuilder}, }; // The number of spamming rounds. @@ -52,7 +52,7 @@ async fn main() -> Result<()> { .await? .to_bech32_unchecked("smr"); - let wallet = Wallet::builder() + let wallet = WalletBuilder::new() .with_secret_manager(secret_manager) .with_client_options(client_options) .with_public_key_options(PublicKeyOptions::new(IOTA_COIN_TYPE)) @@ -156,8 +156,8 @@ async fn main() -> Result<()> { Ok(()) } -async fn ensure_enough_funds( - wallet: &Wallet, +async fn ensure_enough_funds( + wallet: &Wallet, bech32_address: &Bech32Address, ) -> Result<()> { let balance = wallet.sync(None).await?; @@ -201,7 +201,7 @@ async fn ensure_enough_funds( } async fn wait_for_inclusion( - wallet: &Wallet, + wallet: &Wallet>, transaction_id: &TransactionId, ) -> Result<()> { println!( diff --git a/sdk/examples/wallet/storage.rs b/sdk/examples/wallet/storage.rs index 9cdf963007..a624b096d4 100644 --- a/sdk/examples/wallet/storage.rs +++ b/sdk/examples/wallet/storage.rs @@ -14,7 +14,7 @@ use iota_sdk::{ secret::{mnemonic::MnemonicSecretManager, PublicKeyOptions, SecretManage}, }, crypto::keys::bip44::Bip44, - wallet::{ClientOptions, Result, Wallet}, + wallet::{ClientOptions, Result, Wallet, WalletBuilder}, }; #[tokio::main] @@ -30,7 +30,7 @@ async fn main() -> Result<()> { let client_options = ClientOptions::new().with_node(&std::env::var("NODE_URL").unwrap())?; - let wallet = Wallet::builder() + let wallet = WalletBuilder::new() .with_secret_manager(secret_manager) .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .with_client_options(client_options) @@ -49,7 +49,7 @@ async fn main() -> Result<()> { Ok(()) } -async fn sync_print_balance(wallet: &Wallet) -> Result<()> { +async fn sync_print_balance(wallet: &Wallet) -> Result<()> { let alias = wallet.alias().await; let now = tokio::time::Instant::now(); let balance = wallet.sync(None).await?; diff --git a/sdk/examples/wallet/wallet.rs b/sdk/examples/wallet/wallet.rs index a5c2973091..4a4268aade 100644 --- a/sdk/examples/wallet/wallet.rs +++ b/sdk/examples/wallet/wallet.rs @@ -21,7 +21,7 @@ use iota_sdk::{ secret::{mnemonic::MnemonicSecretManager, PublicKeyOptions, SecretManage}, }, types::block::payload::signed_transaction::TransactionId, - wallet::{ClientOptions, Result, Wallet}, + wallet::{core::SecretData, ClientOptions, Result, Wallet, WalletBuilder}, }; // The amount of coins to send @@ -53,10 +53,10 @@ async fn main() -> Result<()> { Ok(()) } -async fn create_wallet() -> Result> { +async fn create_wallet() -> Result>> { let client_options = ClientOptions::new().with_node(&std::env::var("NODE_URL").unwrap())?; let secret_manager = MnemonicSecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?; - Wallet::builder() + WalletBuilder::new() .with_secret_manager(secret_manager) .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) .with_client_options(client_options) @@ -66,7 +66,7 @@ async fn create_wallet() -> Result> { .await } -async fn sync_print_balance(wallet: &Wallet, full_report: bool) -> Result<()> { +async fn sync_print_balance(wallet: &Wallet, full_report: bool) -> Result<()> { let now = tokio::time::Instant::now(); let balance = wallet.sync(None).await?; println!("Wallet synced in: {:.2?}", now.elapsed()); @@ -79,7 +79,7 @@ async fn sync_print_balance(wallet: &Wallet, full_ } async fn wait_for_inclusion( - wallet: &Wallet, + wallet: &Wallet>, transaction_id: &TransactionId, ) -> Result<()> { println!( diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index ce004f33d2..97cfe39c79 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -28,5 +28,7 @@ pub use crypto; pub use packable; pub use primitive_types::U256; +use crate::wallet::core::SecretData; + #[cfg(feature = "wallet")] -pub type Wallet = self::wallet::Wallet; +pub type Wallet = self::wallet::Wallet>; diff --git a/sdk/src/wallet/core/builder.rs b/sdk/src/wallet/core/builder.rs index c9b3ef6d48..e18f48583a 100644 --- a/sdk/src/wallet/core/builder.rs +++ b/sdk/src/wallet/core/builder.rs @@ -15,66 +15,48 @@ use crate::wallet::storage::adapter::memory::Memory; #[cfg(feature = "storage")] use crate::wallet::storage::{StorageManager, StorageOptions}; use crate::{ - client::secret::{SecretManage, SecretManager, SecretManagerConfig}, + client::secret::{SecretManage, SecretManagerConfig}, types::block::address::{Bech32Address, Ed25519Address, ToBech32Ext}, wallet::{ - core::{WalletData, WalletInner}, + core::{SecretData, WalletData, WalletInner}, operations::syncing::SyncOptions, ClientOptions, Wallet, }, }; /// Builder for the wallet. -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, Default)] #[serde(rename_all = "camelCase")] -pub struct WalletBuilder { - pub(crate) public_key_options: Option, - pub(crate) signing_options: Option, +pub struct WalletBuilder { + #[serde(flatten)] + pub(crate) secret_data: T, pub(crate) address: Option, pub(crate) alias: Option, pub(crate) client_options: Option, #[cfg(feature = "storage")] pub(crate) storage_options: Option, +} + +#[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct SecretDataBuilder { + pub(crate) public_key_options: Option, + pub(crate) signing_options: Option, #[serde(skip)] pub(crate) secret_manager: Option>>, } -impl Default for WalletBuilder { +impl Default for SecretDataBuilder { fn default() -> Self { Self { public_key_options: Default::default(), signing_options: Default::default(), - address: Default::default(), - alias: Default::default(), - client_options: Default::default(), - #[cfg(feature = "storage")] - storage_options: Default::default(), secret_manager: Default::default(), } } } -impl WalletBuilder { - /// Initialises a new instance of the wallet builder with the default storage adapter. - pub fn new() -> Self { - Self { - secret_manager: None, - ..Default::default() - } - } - - /// Set the public key options. - pub fn with_public_key_options(mut self, public_key_options: impl Into>) -> Self { - self.public_key_options = public_key_options.into(); - self - } - - /// Set the signing options. - pub fn with_signing_options(mut self, signing_options: impl Into>) -> Self { - self.signing_options = signing_options.into(); - self - } - +impl WalletBuilder { /// Set the wallet address. pub fn with_address(mut self, address: impl Into>) -> Self { self.address = address.into(); @@ -101,37 +83,222 @@ impl WalletBuilder { self } + /// Set the storage path to be used. + #[cfg(feature = "storage")] + #[cfg_attr(docsrs, doc(cfg(feature = "storage")))] + pub fn with_storage_path(mut self, path: &str) -> Self { + self.storage_options = Some(StorageOptions { + path: path.into(), + ..Default::default() + }); + self + } +} + +impl WalletBuilder { + /// Initialises a new instance of the wallet builder with the default storage adapter. + pub fn new() -> Self { + Self::default() + } + + pub fn with_secret_type(self) -> WalletBuilder> { + WalletBuilder { + secret_data: Default::default(), + address: self.address, + alias: self.alias, + client_options: self.client_options, + storage_options: self.storage_options, + } + } + + /// Set the public key options. + pub fn with_public_key_options( + mut self, + public_key_options: impl Into>, + ) -> WalletBuilder> { + self.with_secret_type::().with_public_key_options(public_key_options) + } + + /// Set the signing options. + pub fn with_signing_options( + mut self, + signing_options: impl Into>, + ) -> WalletBuilder> { + self.with_secret_type::().with_signing_options(signing_options) + } + + /// Set the secret_manager to be used. + pub fn with_secret_manager( + mut self, + secret_manager: impl Into>, + ) -> WalletBuilder> { + self.with_secret_type::().with_secret_manager(secret_manager) + } + + /// Set the secret_manager to be used wrapped in an Arc> so it can be cloned and mutated also outside of + /// the Wallet. + pub fn with_secret_manager_arc( + mut self, + secret_manager: impl Into>>>, + ) -> WalletBuilder> { + self.with_secret_type::().with_secret_manager_arc(secret_manager) + } +} + +impl WalletBuilder> { + /// Set the public key options. + pub fn with_public_key_options(mut self, public_key_options: impl Into>) -> Self { + self.secret_data.public_key_options = public_key_options.into(); + self + } + + /// Set the signing options. + pub fn with_signing_options(mut self, signing_options: impl Into>) -> Self { + self.secret_data.signing_options = signing_options.into(); + self + } + /// Set the secret_manager to be used. pub fn with_secret_manager(mut self, secret_manager: impl Into>) -> Self { - self.secret_manager = secret_manager.into().map(|sm| Arc::new(RwLock::new(sm))); + self.secret_data.secret_manager = secret_manager.into().map(|sm| Arc::new(RwLock::new(sm))); self } /// Set the secret_manager to be used wrapped in an Arc> so it can be cloned and mutated also outside of /// the Wallet. pub fn with_secret_manager_arc(mut self, secret_manager: impl Into>>>) -> Self { - self.secret_manager = secret_manager.into(); + self.secret_data.secret_manager = secret_manager.into(); self } +} - /// Set the storage path to be used. - #[cfg(feature = "storage")] - #[cfg_attr(docsrs, doc(cfg(feature = "storage")))] - pub fn with_storage_path(mut self, path: &str) -> Self { - self.storage_options = Some(StorageOptions { - path: path.into(), - ..Default::default() - }); - self +impl WalletBuilder { + /// Builds the wallet. + pub async fn finish(mut self) -> crate::wallet::Result { + log::debug!("[WalletBuilder]"); + + #[cfg(feature = "storage")] + let storage_options = self.storage_options.clone().unwrap_or_default(); + // Check if the db exists and if not, return an error if one parameter is missing, because otherwise the db + // would be created with an empty parameter which just leads to errors later + #[cfg(feature = "storage")] + if !storage_options.path.is_dir() && self.client_options.is_none() { + return Err(crate::wallet::Error::MissingParameter("client_options")); + } + + #[cfg(all(feature = "rocksdb", feature = "storage"))] + let storage = + crate::wallet::storage::adapter::rocksdb::RocksdbStorageAdapter::new(storage_options.path.clone())?; + #[cfg(all(not(feature = "rocksdb"), feature = "storage"))] + let storage = Memory::default(); + + #[cfg(feature = "storage")] + let mut storage_manager = StorageManager::new(storage, storage_options.encryption_key.clone()).await?; + + #[cfg(feature = "storage")] + let loaded_wallet_builder = Self::load::<()>(&storage_manager).await?; + #[cfg(not(feature = "storage"))] + let loaded_wallet_builder: Option = None; + + // May use a previously stored client options if those weren't provided + let provided_client_options = if self.client_options.is_none() { + let loaded_client_options = loaded_wallet_builder + .as_ref() + .and_then(|data| data.client_options.clone()) + .ok_or(crate::wallet::Error::MissingParameter("client_options"))?; + + // Update self so it gets used and stored again + self.client_options = Some(loaded_client_options); + false + } else { + true + }; + + // May use a previously stored wallet alias if it wasn't provided + if self.alias.is_none() { + self.alias = loaded_wallet_builder.as_ref().and_then(|builder| builder.alias.clone()); + } + + // May use a previously stored wallet address if it wasn't provided + if self.address.is_none() { + self.address = loaded_wallet_builder + .as_ref() + .and_then(|builder| builder.address.clone()); + } + + let address = self + .address + .as_ref() + .ok_or(crate::wallet::Error::MissingParameter("address"))? + .clone(); + + #[cfg(feature = "storage")] + let mut wallet_data = storage_manager.load_wallet_data().await?; + + // Store the wallet builder (for convenience reasons) + #[cfg(feature = "storage")] + self.save(&storage_manager).await?; + + #[cfg(feature = "events")] + let event_emitter = tokio::sync::RwLock::new(EventEmitter::new()); + + // It happened that inputs got locked, the transaction failed, but they weren't unlocked again, so we do this + // here + #[cfg(feature = "storage")] + if let Some(wallet_data) = &mut wallet_data { + unlock_unused_inputs(wallet_data)?; + } + + // Create the node client. + let client = self + .client_options + .clone() + .ok_or(crate::wallet::Error::MissingParameter("client_options"))? + .finish() + .await?; + + // Build the wallet. + let wallet_inner = WalletInner { + default_sync_options: Mutex::new(SyncOptions::default()), + last_synced: Mutex::new(0), + background_syncing_status: AtomicUsize::new(0), + client, + #[cfg(feature = "events")] + event_emitter, + #[cfg(feature = "storage")] + storage_options, + #[cfg(feature = "storage")] + storage_manager: tokio::sync::RwLock::new(storage_manager), + }; + #[cfg(feature = "storage")] + let wallet_data = match wallet_data { + Some(d) => d, + None => WalletData::new(address, self.alias.clone()), + }; + #[cfg(not(feature = "storage"))] + let wallet_data = WalletData::new(self.bip_path, address, self.alias.clone()); + let wallet = Wallet { + inner: Arc::new(wallet_inner), + data: Arc::new(RwLock::new(wallet_data)), + secret_data: (), + }; + + // If the wallet builder is not set, it means the user provided it and we need to update the addresses. + // In the other case it was loaded from the database and addresses are up to date. + if provided_client_options { + wallet.update_bech32_hrp().await?; + } + + Ok(wallet) } } -impl WalletBuilder +impl WalletBuilder> where for<'a> &'a S::GenerationOptions: PartialEq, { /// Builds the wallet. - pub async fn finish(mut self) -> crate::wallet::Result> { + pub async fn finish(mut self) -> crate::wallet::Result>> { log::debug!("[WalletBuilder]"); #[cfg(feature = "storage")] @@ -153,7 +320,7 @@ where let mut storage_manager = StorageManager::new(storage, storage_options.encryption_key.clone()).await?; #[cfg(feature = "storage")] - let loaded_wallet_builder = Self::load(&storage_manager).await?; + let loaded_wallet_builder = Self::load::>(&storage_manager).await?; #[cfg(not(feature = "storage"))] let loaded_wallet_builder: Option = None; @@ -171,20 +338,39 @@ where true }; - // May use a previously stored secret manager if it wasn't provided - if self.secret_manager.is_none() { - let secret_manager = loaded_wallet_builder + // May use previously stored options if they weren't provided + if self.secret_data.public_key_options.is_none() { + self.secret_data.public_key_options = loaded_wallet_builder .as_ref() - .and_then(|builder| builder.secret_manager.clone()); + .and_then(|builder| builder.secret_data.public_key_options.clone()); + } + + #[cfg(feature = "storage")] + let secret_data = storage_manager.load_secret_data::().await?; - self.secret_manager = secret_manager; + // The public key options must not change. + #[cfg(feature = "storage")] + if let Some(secret_data) = &secret_data { + let old = &secret_data.public_key_options; + if let Some(new) = self.secret_data.public_key_options.as_ref() { + if new != old { + return Err(crate::wallet::Error::PublicKeyOptionsMismatch { + new: serde_json::to_value(new)?, + old: serde_json::to_value(old)?, + }); + } + } else { + self.secret_data.public_key_options = Some(old.clone()); + } } - // May use previously stored options if they weren't provided - if self.public_key_options.is_none() { - self.public_key_options = loaded_wallet_builder + // May use a previously stored secret manager if it wasn't provided + if self.secret_data.secret_manager.is_none() { + let secret_manager = loaded_wallet_builder .as_ref() - .and_then(|builder| builder.public_key_options.clone()); + .and_then(|builder| builder.secret_data.secret_manager.clone()); + + self.secret_data.secret_manager = secret_manager; } // May use a previously stored wallet alias if it wasn't provided @@ -201,7 +387,7 @@ where // May create a default Ed25519 wallet address if there's a secret manager. if self.address.is_none() { - if self.secret_manager.is_some() { + if self.secret_data.secret_manager.is_some() { let address = self.create_default_wallet_address().await?; self.address = Some(address); } else { @@ -212,23 +398,7 @@ where let address = self.address.as_ref().unwrap().clone(); #[cfg(feature = "storage")] - let mut wallet_data = storage_manager.load_wallet_data::().await?; - - // The public key options must not change. - #[cfg(feature = "storage")] - if let Some(wallet_data) = &wallet_data { - let old = &wallet_data.public_key_options; - if let Some(new) = self.public_key_options.as_ref() { - if new != old { - return Err(crate::wallet::Error::PublicKeyOptionsMismatch { - new: serde_json::to_value(new)?, - old: serde_json::to_value(old)?, - }); - } - } else { - self.public_key_options = Some(old.clone()); - } - } + let mut wallet_data = storage_manager.load_wallet_data().await?; // Store the wallet builder (for convenience reasons) #[cfg(feature = "storage")] @@ -258,7 +428,6 @@ where last_synced: Mutex::new(0), background_syncing_status: AtomicUsize::new(0), client, - secret_manager: self.secret_manager.expect("make WalletInner::secret_manager optional?"), #[cfg(feature = "events")] event_emitter, #[cfg(feature = "storage")] @@ -269,20 +438,27 @@ where #[cfg(feature = "storage")] let wallet_data = match wallet_data { Some(d) => d, - None => WalletData::new( - self.public_key_options - .ok_or(crate::wallet::Error::MissingParameter("public_key_options"))?, - self.signing_options - .ok_or(crate::wallet::Error::MissingParameter("signing_options"))?, - address, - self.alias.clone(), - ), + None => WalletData::new(address, self.alias.clone()), }; #[cfg(not(feature = "storage"))] let wallet_data = WalletData::new(self.bip_path, address, self.alias.clone()); let wallet = Wallet { inner: Arc::new(wallet_inner), data: Arc::new(RwLock::new(wallet_data)), + secret_data: SecretData { + public_key_options: self + .secret_data + .public_key_options + .ok_or(crate::wallet::Error::MissingParameter("signing_options"))?, + signing_options: self + .secret_data + .signing_options + .ok_or(crate::wallet::Error::MissingParameter("public_key_options"))?, + secret_manager: self + .secret_data + .secret_manager + .ok_or(crate::wallet::Error::MissingParameter("secret_manager"))?, + }, }; // If the wallet builder is not set, it means the user provided it and we need to update the addresses. @@ -303,10 +479,11 @@ where .network_info .protocol_parameters .bech32_hrp; - let options = self.public_key_options.as_ref().unwrap(); + let options = self.secret_data.public_key_options.as_ref().unwrap(); Ok(Ed25519Address::from_public_key_bytes( - self.secret_manager + self.secret_data + .secret_manager .as_ref() .unwrap() .read() @@ -317,21 +494,72 @@ where ) .to_bech32(bech32_hrp)) } +} +impl WalletBuilder { #[cfg(feature = "storage")] - pub(crate) async fn from_wallet(wallet: &Wallet) -> Self + pub(crate) async fn from_wallet(wallet: &Wallet) -> Self where - S::GenerationOptions: Clone, - S::SigningOptions: Clone, + Wallet: BuilderFrom, { - Self { - public_key_options: Some(wallet.data().await.public_key_options.clone()), - signing_options: Some(wallet.data().await.signing_options.clone()), - address: Some(wallet.address().await), - alias: wallet.alias().await, - client_options: Some(wallet.client_options().await), - storage_options: Some(wallet.storage_options.clone()), - secret_manager: Some(wallet.secret_manager.clone()), + BuilderFrom::from(wallet).await + } +} + +#[async_trait::async_trait] +pub trait BuilderFrom { + type Builder; + + async fn from(&self) -> Self::Builder; +} + +#[cfg(feature = "storage")] +mod builder_from { + use async_trait::async_trait; + + use super::BuilderFrom; + use crate::{ + client::secret::SecretManage, + wallet::{ + core::{builder::SecretDataBuilder, SecretData}, + Wallet, WalletBuilder, + }, + }; + + #[async_trait] + impl BuilderFrom for SecretData { + type Builder = SecretDataBuilder; + + async fn from(&self) -> Self::Builder { + Self::Builder { + public_key_options: Some(self.public_key_options.clone()), + signing_options: Some(self.signing_options.clone()), + secret_manager: Some(self.secret_manager.clone()), + } + } + } + + #[async_trait] + impl BuilderFrom for () { + type Builder = (); + + async fn from(&self) -> Self::Builder { + () + } + } + + #[async_trait] + impl BuilderFrom for Wallet { + type Builder = WalletBuilder; + + async fn from(&self) -> Self::Builder { + Self::Builder { + address: Some(self.address().await), + alias: self.alias().await, + client_options: Some(self.client_options().await), + storage_options: Some(self.storage_options.clone()), + secret_data: BuilderFrom::from(&self.secret_data).await, + } } } } @@ -339,7 +567,7 @@ where // Check if any of the locked inputs is not used in a transaction and unlock them, so they get available for new // transactions #[cfg(feature = "storage")] -fn unlock_unused_inputs(wallet_data: &mut WalletData) -> crate::wallet::Result<()> { +fn unlock_unused_inputs(wallet_data: &mut WalletData) -> crate::wallet::Result<()> { log::debug!("[unlock_unused_inputs]"); let mut used_inputs = HashSet::new(); for transaction_id in &wallet_data.pending_transactions { @@ -369,11 +597,9 @@ pub(crate) mod dto { #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] - pub struct WalletBuilderDto { - #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")] - pub(crate) public_key_options: Option, - #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")] - pub(crate) signing_options: Option, + pub struct WalletBuilderDto { + #[serde(flatten)] + secret_data: T, #[serde(default, skip_serializing_if = "Option::is_none")] pub(crate) address: Option, #[serde(default, skip_serializing_if = "Option::is_none")] @@ -385,22 +611,39 @@ pub(crate) mod dto { pub(crate) storage_options: Option, } - impl From> for WalletBuilder { - fn from(value: WalletBuilderDto) -> Self { + #[derive(Debug, Deserialize)] + #[serde(rename_all = "camelCase")] + pub struct SecretDataDto { + #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")] + pub(crate) public_key_options: Option, + #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")] + pub(crate) signing_options: Option, + } + + impl From> for SecretDataBuilder { + fn from(value: SecretDataDto) -> Self { Self { public_key_options: value.public_key_options, signing_options: value.signing_options, + secret_manager: None, + } + } + } + + impl, T2> From> for WalletBuilder { + fn from(value: WalletBuilderDto) -> Self { + Self { + secret_data: value.secret_data.into(), address: value.address, alias: value.alias, client_options: value.client_options, #[cfg(feature = "storage")] storage_options: value.storage_options, - secret_manager: None, } } } - impl<'de, S: SecretManage> Deserialize<'de> for WalletBuilder + impl<'de, S: SecretManage> Deserialize<'de> for SecretDataBuilder where S::GenerationOptions: Deserialize<'de>, S::SigningOptions: Deserialize<'de>, @@ -409,7 +652,16 @@ pub(crate) mod dto { where D: serde::Deserializer<'de>, { - WalletBuilderDto::::deserialize(d).map(Into::into) + SecretDataDto::::deserialize(d).map(Into::into) + } + } + + impl<'de, T: Deserialize<'de>> Deserialize<'de> for WalletBuilder { + fn deserialize(d: D) -> Result + where + D: serde::Deserializer<'de>, + { + WalletBuilderDto::::deserialize(d).map(Into::into) } } } diff --git a/sdk/src/wallet/core/mod.rs b/sdk/src/wallet/core/mod.rs index ea47dba06e..587f3276f3 100644 --- a/sdk/src/wallet/core/mod.rs +++ b/sdk/src/wallet/core/mod.rs @@ -37,39 +37,50 @@ use crate::{ }; /// The stateful wallet used to interact with an IOTA network. +#[derive(Debug, Clone)] +pub struct Wallet { + pub(crate) inner: Arc, + pub(crate) data: Arc>, + pub(crate) secret_data: T, +} + #[derive(Debug)] -pub struct Wallet { - pub(crate) inner: Arc>, - pub(crate) data: Arc>>, +pub struct SecretData { + /// The public key generation options. + pub(crate) public_key_options: S::GenerationOptions, + /// The signing options for transactions and blocks. + pub(crate) signing_options: S::SigningOptions, + pub(crate) secret_manager: Arc>, } -impl Clone for Wallet { +impl Clone for SecretData { fn clone(&self) -> Self { Self { - inner: self.inner.clone(), - data: self.data.clone(), + public_key_options: self.public_key_options.clone(), + signing_options: self.signing_options.clone(), + secret_manager: self.secret_manager.clone(), } } } -impl core::ops::Deref for Wallet { - type Target = WalletInner; +impl core::ops::Deref for Wallet { + type Target = WalletInner; fn deref(&self) -> &Self::Target { &self.inner } } -impl Wallet { +impl Wallet { /// Initialises the wallet builder. - pub fn builder() -> WalletBuilder { - WalletBuilder::::new() + pub fn builder() -> WalletBuilder { + WalletBuilder::new() } } /// Wallet inner. #[derive(Debug)] -pub struct WalletInner { +pub struct WalletInner { // mutex to prevent multiple sync calls at the same or almost the same time, the u128 is a timestamp // if the last synced time was < `MIN_SYNC_INTERVAL` second ago, we don't sync, but only calculate the balance // again, because sending transactions can change that @@ -78,7 +89,7 @@ pub struct WalletInner { // 0 = not running, 1 = running, 2 = stopping pub(crate) background_syncing_status: AtomicUsize, pub(crate) client: Client, - pub(crate) secret_manager: Arc>, + #[cfg(feature = "events")] pub(crate) event_emitter: tokio::sync::RwLock, #[cfg(feature = "storage")] @@ -88,11 +99,8 @@ pub struct WalletInner { } /// Wallet data. -pub struct WalletData { - /// The public key generation options. - pub(crate) public_key_options: S::GenerationOptions, - /// The signing options for transactions and blocks. - pub(crate) signing_options: S::SigningOptions, +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct WalletData { /// The wallet address. pub(crate) address: Bech32Address, /// The wallet alias. @@ -125,16 +133,9 @@ pub struct WalletData { pub(crate) native_token_foundries: HashMap, } -impl WalletData { - pub(crate) fn new( - public_key_options: S::GenerationOptions, - signing_options: S::SigningOptions, - address: Bech32Address, - alias: Option, - ) -> Self { +impl WalletData { + pub(crate) fn new(address: Bech32Address, alias: Option) -> Self { Self { - public_key_options, - signing_options, address, alias, outputs: HashMap::new(), @@ -228,16 +229,6 @@ impl WalletData { }) } - /// Returns the public key options. - pub fn public_key_options(&self) -> &S::GenerationOptions { - &self.public_key_options - } - - /// Returns the signing options. - pub fn signing_options(&self) -> &S::SigningOptions { - &self.signing_options - } - /// Returns outputs map of the wallet. pub fn outputs(&self) -> &HashMap { &self.outputs @@ -351,66 +342,9 @@ impl WalletData { } } -impl PartialEq for WalletData { - fn eq(&self, other: &Self) -> bool { - self.public_key_options == other.public_key_options - && self.signing_options == other.signing_options - && self.address == other.address - && self.alias == other.alias - && self.outputs == other.outputs - && self.locked_outputs == other.locked_outputs - && self.unspent_outputs == other.unspent_outputs - && self.transactions == other.transactions - && self.pending_transactions == other.pending_transactions - && self.incoming_transactions == other.incoming_transactions - && self.inaccessible_incoming_transactions == other.inaccessible_incoming_transactions - && self.native_token_foundries == other.native_token_foundries - } -} -impl Eq for WalletData {} -impl core::fmt::Debug for WalletData { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.debug_struct("WalletData") - .field("public_key_options", &self.public_key_options) - .field("signing_options", &self.signing_options) - .field("address", &self.address) - .field("alias", &self.alias) - .field("outputs", &self.outputs) - .field("locked_outputs", &self.locked_outputs) - .field("unspent_outputs", &self.unspent_outputs) - .field("transactions", &self.transactions) - .field("pending_transactions", &self.pending_transactions) - .field("incoming_transactions", &self.incoming_transactions) - .field( - "inaccessible_incoming_transactions", - &self.inaccessible_incoming_transactions, - ) - .field("native_token_foundries", &self.native_token_foundries) - .finish() - } -} -impl Clone for WalletData { - fn clone(&self) -> Self { - Self { - public_key_options: self.public_key_options.clone(), - signing_options: self.signing_options.clone(), - address: self.address.clone(), - alias: self.alias.clone(), - outputs: self.outputs.clone(), - locked_outputs: self.locked_outputs.clone(), - unspent_outputs: self.unspent_outputs.clone(), - transactions: self.transactions.clone(), - pending_transactions: self.pending_transactions.clone(), - incoming_transactions: self.incoming_transactions.clone(), - inaccessible_incoming_transactions: self.inaccessible_incoming_transactions.clone(), - native_token_foundries: self.native_token_foundries.clone(), - } - } -} - -impl Wallet { +impl Wallet { /// Create a new wallet. - pub(crate) async fn new(inner: Arc>, data: WalletData) -> Result { + pub(crate) async fn new(inner: Arc, data: WalletData, secret_data: T) -> Result { #[cfg(feature = "storage")] let default_sync_options = inner .storage_manager @@ -433,6 +367,7 @@ impl Wallet { Ok(Self { inner, data: Arc::new(RwLock::new(data)), + secret_data, }) } @@ -459,7 +394,7 @@ impl Wallet { /// Save the wallet to the database, accepts the updated wallet data as option so we don't need to drop it before /// saving #[cfg(feature = "storage")] - pub(crate) async fn save(&self, updated_wallet: Option<&WalletData>) -> Result<()> { + pub(crate) async fn save(&self, updated_wallet: Option<&WalletData>) -> Result<()> { log::debug!("[save] wallet data"); match updated_wallet { Some(wallet) => { @@ -483,11 +418,11 @@ impl Wallet { self.inner.emit(wallet_event).await } - pub async fn data(&self) -> tokio::sync::RwLockReadGuard<'_, WalletData> { + pub async fn data(&self) -> tokio::sync::RwLockReadGuard<'_, WalletData> { self.data.read().await } - pub(crate) async fn data_mut(&self) -> tokio::sync::RwLockWriteGuard<'_, WalletData> { + pub(crate) async fn data_mut(&self) -> tokio::sync::RwLockWriteGuard<'_, WalletData> { self.data.write().await } @@ -521,12 +456,22 @@ impl Wallet { } } -impl WalletInner { +impl Wallet> { /// Get the [SecretManager] - pub fn get_secret_manager(&self) -> &Arc> { - &self.secret_manager + pub fn secret_manager(&self) -> &Arc> { + &self.secret_data.secret_manager } + pub fn public_key_options(&self) -> &S::GenerationOptions { + &self.secret_data.public_key_options + } + + pub fn signing_options(&self) -> &S::SigningOptions { + &self.secret_data.signing_options + } +} + +impl WalletInner { /// Listen to wallet events, empty vec will listen to all events #[cfg(feature = "events")] #[cfg_attr(docsrs, doc(cfg(feature = "events")))] @@ -574,18 +519,10 @@ impl WalletInner { } } -impl Drop for Wallet { - fn drop(&mut self) { - log::debug!("drop Wallet"); - } -} - /// Dto for the wallet data. #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct WalletDataDto { - pub public_key_options: G, - pub signing_options: S, +pub struct WalletDataDto { pub address: Bech32Address, pub alias: Option, pub outputs: HashMap, @@ -598,16 +535,14 @@ pub struct WalletDataDto { pub native_token_foundries: HashMap, } -impl TryFromDto> for WalletData { +impl TryFromDto for WalletData { type Error = crate::wallet::Error; fn try_from_dto_with_params_inner( - dto: WalletDataDto, + dto: WalletDataDto, params: Option<&ProtocolParameters>, ) -> core::result::Result { Ok(Self { - public_key_options: dto.public_key_options, - signing_options: dto.signing_options, address: dto.address, alias: dto.alias, outputs: dto.outputs, @@ -630,15 +565,9 @@ impl TryFromDto From<&WalletData> for WalletDataDto -where - S::GenerationOptions: Clone, - S::SigningOptions: Clone, -{ - fn from(value: &WalletData) -> Self { +impl From<&WalletData> for WalletDataDto { + fn from(value: &WalletData) -> Self { Self { - public_key_options: value.public_key_options.clone(), - signing_options: value.signing_options.clone(), address: value.address.clone(), alias: value.alias.clone(), outputs: value.outputs.clone(), @@ -753,8 +682,6 @@ mod test { ); let wallet_data = WalletData { - public_key_options: PublicKeyOptions::new(4218), - signing_options: Bip44::new(4218), address: crate::types::block::address::Bech32Address::from_str( "rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy", ) @@ -770,18 +697,16 @@ mod test { native_token_foundries: HashMap::new(), }; - let deser_wallet_data = WalletData::::try_from_dto( - serde_json::from_str::>( - &serde_json::to_string(&WalletDataDto::from(&wallet_data)).unwrap(), - ) - .unwrap(), + let deser_wallet_data = WalletData::try_from_dto( + serde_json::from_str::(&serde_json::to_string(&WalletDataDto::from(&wallet_data)).unwrap()) + .unwrap(), ) .unwrap(); assert_eq!(wallet_data, deser_wallet_data); } - impl> WalletData { + impl WalletData { /// Returns a mock of this type with the following values: /// index: 0, coin_type: 4218, alias: "Alice", address: /// rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy, all other fields are set to their Rust @@ -789,8 +714,6 @@ mod test { #[cfg(feature = "storage")] pub(crate) fn mock() -> Self { Self { - public_key_options: PublicKeyOptions::new(4218), - signing_options: Bip44::new(4218), address: crate::types::block::address::Bech32Address::from_str( "rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy", ) diff --git a/sdk/src/wallet/core/operations/address_generation.rs b/sdk/src/wallet/core/operations/address_generation.rs index 1e237f318f..2700e93c2b 100644 --- a/sdk/src/wallet/core/operations/address_generation.rs +++ b/sdk/src/wallet/core/operations/address_generation.rs @@ -12,7 +12,7 @@ // wallet::events::types::{AddressData, WalletEvent}, // }; -// impl Wallet { +// impl Wallet { // /// Generate an address without storing it // /// ```ignore // /// let public_addresses = wallet diff --git a/sdk/src/wallet/core/operations/background_syncing.rs b/sdk/src/wallet/core/operations/background_syncing.rs index fb1dcc7c66..9a68dcb284 100644 --- a/sdk/src/wallet/core/operations/background_syncing.rs +++ b/sdk/src/wallet/core/operations/background_syncing.rs @@ -5,15 +5,12 @@ use std::{sync::atomic::Ordering, time::Duration}; use tokio::time::sleep; -use crate::{ - client::secret::SecretManage, - wallet::{operations::syncing::SyncOptions, Wallet}, -}; +use crate::wallet::{operations::syncing::SyncOptions, Wallet}; /// The default interval for background syncing pub(crate) const DEFAULT_BACKGROUNDSYNCING_INTERVAL: Duration = Duration::from_secs(7); -impl Wallet { +impl Wallet { /// Start the background syncing process for the wallet, default interval is 7 seconds pub async fn start_background_syncing( &self, diff --git a/sdk/src/wallet/core/operations/client.rs b/sdk/src/wallet/core/operations/client.rs index e193b774fa..a3f6f8b142 100644 --- a/sdk/src/wallet/core/operations/client.rs +++ b/sdk/src/wallet/core/operations/client.rs @@ -3,6 +3,7 @@ use std::collections::{HashMap, HashSet}; +use serde::Serialize; use url::Url; use crate::{ @@ -11,13 +12,12 @@ use crate::{ builder::NodeManagerBuilder, node::{Node, NodeAuth, NodeDto}, }, - secret::{SecretManage, SecretManagerConfig}, Client, ClientBuilder, }, - wallet::{Wallet, WalletBuilder}, + wallet::{core::builder::BuilderFrom, Wallet, WalletBuilder}, }; -impl Wallet { +impl Wallet { pub fn client(&self) -> &Client { &self.client } @@ -27,7 +27,10 @@ impl Wallet { } } -impl Wallet { +impl Wallet +where + T::Builder: Send + Sync + Serialize, +{ pub async fn set_client_options(&self, client_options: ClientBuilder) -> crate::wallet::Result<()> { let ClientBuilder { node_manager_builder, diff --git a/sdk/src/wallet/core/operations/storage.rs b/sdk/src/wallet/core/operations/storage.rs index dad5e85b7f..b0036ce8e8 100644 --- a/sdk/src/wallet/core/operations/storage.rs +++ b/sdk/src/wallet/core/operations/storage.rs @@ -1,49 +1,34 @@ // Copyright 2023 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +use serde::{de::DeserializeOwned, Serialize}; + use crate::{ - client::{secret::SecretManagerConfig, storage::StorageAdapter}, - wallet::{ - core::builder::dto::WalletBuilderDto, - storage::constants::{SECRET_MANAGER_KEY, WALLET_BUILDER_KEY}, - WalletBuilder, - }, + client::storage::StorageAdapter, + wallet::{core::builder::dto::WalletBuilderDto, storage::constants::WALLET_BUILDER_KEY, WalletBuilder}, }; -impl WalletBuilder { +impl WalletBuilder { pub(crate) async fn save( &self, storage: &impl StorageAdapter, ) -> crate::wallet::Result<()> { log::debug!("[save] wallet builder"); storage.set(WALLET_BUILDER_KEY, self).await?; - - if let Some(secret_manager) = &self.secret_manager { - let secret_manager = secret_manager.read().await; - if let Some(config) = secret_manager.to_config() { - log::debug!("[save] secret manager: {config:?}"); - storage.set(SECRET_MANAGER_KEY, &config).await?; - } - } Ok(()) } - pub(crate) async fn load( + pub(crate) async fn load( storage: &impl StorageAdapter, - ) -> crate::wallet::Result> { + ) -> crate::wallet::Result> + where + T: From, + { log::debug!("[load] wallet builder"); - if let Some(wallet_builder_dto) = storage - .get::>(WALLET_BUILDER_KEY) - .await? - { + if let Some(wallet_builder_dto) = storage.get::>(WALLET_BUILDER_KEY).await? { log::debug!("[load] wallet builder dto: {wallet_builder_dto:?}"); - let secret_manager_dto = storage.get(SECRET_MANAGER_KEY).await?; - log::debug!("[load] secret manager dto: {secret_manager_dto:?}"); - - Ok(Some(Self::from(wallet_builder_dto).with_secret_manager( - secret_manager_dto.map(|dto| S::from_config(&dto)).transpose()?, - ))) + Ok(Some(Self::from(wallet_builder_dto))) } else { Ok(None) } diff --git a/sdk/src/wallet/core/operations/stronghold.rs b/sdk/src/wallet/core/operations/stronghold.rs index 79dd195669..1b634f5ed3 100644 --- a/sdk/src/wallet/core/operations/stronghold.rs +++ b/sdk/src/wallet/core/operations/stronghold.rs @@ -7,16 +7,16 @@ use crypto::keys::bip39::Mnemonic; use crate::{ client::{secret::SecretManager, stronghold::StrongholdAdapter, utils::Password}, - wallet::Wallet, + wallet::{core::SecretData, Wallet}, }; // TODO: Remove these and just use the secret manager directly -impl Wallet { +impl Wallet> { /// Sets the Stronghold password pub async fn set_stronghold_password(&self, password: impl Into + Send) -> crate::wallet::Result<()> { let password = password.into(); - if let SecretManager::Stronghold(stronghold) = &mut *self.secret_manager.write().await { + if let SecretManager::Stronghold(stronghold) = &mut *self.secret_manager().write().await { stronghold.set_password(password).await?; Ok(()) } else { @@ -33,7 +33,7 @@ impl Wallet { let current_password = current_password.into(); let new_password = new_password.into(); - if let SecretManager::Stronghold(stronghold) = &mut *self.secret_manager.write().await { + if let SecretManager::Stronghold(stronghold) = &mut *self.secret_manager().write().await { stronghold.set_password(current_password).await?; stronghold.change_password(new_password).await?; Ok(()) @@ -44,7 +44,7 @@ impl Wallet { /// Sets the Stronghold password clear interval pub async fn set_stronghold_password_clear_interval(&self, timeout: Option) -> crate::wallet::Result<()> { - if let SecretManager::Stronghold(stronghold) = &mut *self.secret_manager.write().await { + if let SecretManager::Stronghold(stronghold) = &mut *self.secret_manager().write().await { stronghold.set_timeout(timeout).await; Ok(()) } else { @@ -54,7 +54,7 @@ impl Wallet { /// Stores a mnemonic into the Stronghold vault pub async fn store_mnemonic(&self, mnemonic: Mnemonic) -> crate::wallet::Result<()> { - if let SecretManager::Stronghold(stronghold) = &mut *self.secret_manager.write().await { + if let SecretManager::Stronghold(stronghold) = &mut *self.secret_manager().write().await { stronghold.store_mnemonic(mnemonic).await?; Ok(()) } else { @@ -65,7 +65,7 @@ impl Wallet { /// Clears the Stronghold password from memory. pub async fn clear_stronghold_password(&self) -> crate::wallet::Result<()> { log::debug!("[clear_stronghold_password]"); - if let SecretManager::Stronghold(stronghold) = &mut *self.secret_manager.write().await { + if let SecretManager::Stronghold(stronghold) = &mut *self.secret_manager().write().await { stronghold.clear_key().await; Ok(()) } else { @@ -76,7 +76,7 @@ impl Wallet { /// Checks if the Stronghold password is available. pub async fn is_stronghold_password_available(&self) -> crate::wallet::Result { log::debug!("[is_stronghold_password_available]"); - if let SecretManager::Stronghold(stronghold) = &*self.secret_manager.write().await { + if let SecretManager::Stronghold(stronghold) = &*self.secret_manager().write().await { Ok(stronghold.is_key_available().await) } else { Err(crate::client::Error::SecretManagerMismatch.into()) @@ -84,10 +84,10 @@ impl Wallet { } } -impl Wallet { +impl Wallet> { /// Sets the Stronghold password pub async fn set_stronghold_password(&self, password: impl Into + Send) -> crate::wallet::Result<()> { - Ok(self.secret_manager.write().await.set_password(password).await?) + Ok(self.secret_manager().write().await.set_password(password).await?) } /// Change the Stronghold password to another one and also re-encrypt the values in the loaded snapshot with it. @@ -96,7 +96,7 @@ impl Wallet { current_password: impl Into + Send, new_password: impl Into + Send, ) -> crate::wallet::Result<()> { - let stronghold = &mut *self.secret_manager.write().await; + let stronghold = &mut *self.secret_manager().write().await; stronghold.set_password(current_password).await?; stronghold.change_password(new_password).await?; Ok(()) @@ -104,25 +104,25 @@ impl Wallet { /// Sets the Stronghold password clear interval pub async fn set_stronghold_password_clear_interval(&self, timeout: Option) -> crate::wallet::Result<()> { - self.secret_manager.write().await.set_timeout(timeout).await; + self.secret_manager().write().await.set_timeout(timeout).await; Ok(()) } /// Stores a mnemonic into the Stronghold vault pub async fn store_mnemonic(&self, mnemonic: Mnemonic) -> crate::wallet::Result<()> { - Ok(self.secret_manager.write().await.store_mnemonic(mnemonic).await?) + Ok(self.secret_manager().write().await.store_mnemonic(mnemonic).await?) } /// Clears the Stronghold password from memory. pub async fn clear_stronghold_password(&self) -> crate::wallet::Result<()> { log::debug!("[clear_stronghold_password]"); - self.secret_manager.write().await.clear_key().await; + self.secret_manager().write().await.clear_key().await; Ok(()) } /// Checks if the Stronghold password is available. pub async fn is_stronghold_password_available(&self) -> crate::wallet::Result { log::debug!("[is_stronghold_password_available]"); - Ok(self.secret_manager.write().await.is_key_available().await) + Ok(self.secret_manager().write().await.is_key_available().await) } } diff --git a/sdk/src/wallet/core/operations/stronghold_backup/mod.rs b/sdk/src/wallet/core/operations/stronghold_backup/mod.rs index 523935e45c..99506b9426 100644 --- a/sdk/src/wallet/core/operations/stronghold_backup/mod.rs +++ b/sdk/src/wallet/core/operations/stronghold_backup/mod.rs @@ -14,10 +14,10 @@ use crate::{ utils::Password, }, types::block::address::Hrp, - wallet::Wallet, + wallet::{core::SecretData, Wallet}, }; -impl Wallet { +impl Wallet> { /// Backup the wallet data in a Stronghold file /// stronghold_password must be the current one when Stronghold is used as SecretManager. pub async fn backup( @@ -28,7 +28,7 @@ impl Wallet { let stronghold_password = stronghold_password.into(); log::debug!("[backup] creating a stronghold backup"); - let secret_manager = self.secret_manager.read().await; + let secret_manager = self.secret_manager().read().await; match (&*secret_manager).as_stronghold() { // Backup with existing stronghold @@ -81,7 +81,7 @@ impl Wallet { let mut wallet_data = self.data.write().await; - let mut secret_manager = self.secret_manager.as_ref().write().await; + let mut secret_manager = self.secret_manager().as_ref().write().await; // Get the current snapshot path if set let new_snapshot_path = if let Ok(stronghold) = (&*secret_manager).as_stronghold() { stronghold.snapshot_path.clone() @@ -94,16 +94,16 @@ impl Wallet { .password(stronghold_password.clone()) .build(backup_path.clone())?; - let (loaded_client_options, loaded_secret_manager_config, loaded_wallet_data) = + let (loaded_client_options, loaded_secret_manager_config, loaded_wallet_data, loaded_secret_data) = read_wallet_data_from_stronghold_snapshot::(&new_stronghold).await?; - let loaded_pub_key_opts = loaded_wallet_data.as_ref().map(|data| &data.public_key_options); + let loaded_pub_key_opts = loaded_secret_data.as_ref().map(|data| &data.public_key_options); // If the bip path is not matching the current one, we may ignore the backup let ignore_backup_values = ignore_if_bip_path_mismatch.map_or(false, |ignore| { if ignore { // TODO: #1279 okay that if both are none we always load the backup values? - loaded_pub_key_opts.is_some_and(|opts| &wallet_data.public_key_options != opts) + loaded_pub_key_opts.is_some_and(|opts| self.public_key_options() != opts) } else { false } @@ -111,7 +111,8 @@ impl Wallet { if !ignore_backup_values { if let Some(opts) = loaded_pub_key_opts { - wallet_data.public_key_options = opts.clone(); + // TODO + // self.secret_data.public_key_options = opts.clone(); } } @@ -163,7 +164,7 @@ impl Wallet { #[cfg(feature = "storage")] { let wallet_builder = WalletBuilder::new() - .with_secret_manager_arc(self.secret_manager.clone()) + .with_secret_manager_arc(self.secret_manager().clone()) .with_storage_path( &self .storage_options @@ -174,8 +175,8 @@ impl Wallet { .expect("can't convert os string"), ) .with_client_options(self.client_options().await) - .with_public_key_options(self.data().await.public_key_options.clone()) - .with_signing_options(self.data().await.signing_options.clone()); + .with_public_key_options(self.public_key_options().clone()) + .with_signing_options(self.signing_options().clone()); wallet_builder.save(&*self.storage_manager.read().await).await?; diff --git a/sdk/src/wallet/core/operations/stronghold_backup/stronghold_snapshot.rs b/sdk/src/wallet/core/operations/stronghold_backup/stronghold_snapshot.rs index ad9cd80d48..6140553c6a 100644 --- a/sdk/src/wallet/core/operations/stronghold_backup/stronghold_snapshot.rs +++ b/sdk/src/wallet/core/operations/stronghold_backup/stronghold_snapshot.rs @@ -5,7 +5,7 @@ use crate::{ client::{secret::SecretManagerConfig, storage::StorageAdapter, stronghold::StrongholdAdapter}, types::TryFromDto, wallet::{ - core::{WalletData, WalletDataDto}, + core::{SecretData, WalletData, WalletDataDto}, migration::{latest_backup_migration_version, migrate, MIGRATION_VERSION_KEY}, ClientOptions, Wallet, }, @@ -15,7 +15,7 @@ pub(crate) const CLIENT_OPTIONS_KEY: &str = "client_options"; pub(crate) const SECRET_MANAGER_KEY: &str = "secret_manager"; pub(crate) const WALLET_DATA_KEY: &str = "wallet_data"; -impl Wallet { +impl Wallet> { pub(crate) async fn store_data_to_stronghold(&self, stronghold: &StrongholdAdapter) -> crate::wallet::Result<()> { // Set migration version stronghold @@ -25,7 +25,7 @@ impl Wallet { let client_options = self.client_options().await; stronghold.set(CLIENT_OPTIONS_KEY, &client_options).await?; - if let Some(secret_manager_dto) = self.secret_manager.read().await.to_config() { + if let Some(secret_manager_dto) = self.secret_manager().read().await.to_config() { stronghold.set(SECRET_MANAGER_KEY, &secret_manager_dto).await?; } @@ -38,7 +38,12 @@ impl Wallet { pub(crate) async fn read_wallet_data_from_stronghold_snapshot( stronghold: &StrongholdAdapter, -) -> crate::wallet::Result<(Option, Option, Option>)> { +) -> crate::wallet::Result<( + Option, + Option, + Option, + Option>, +)> { migrate(stronghold).await?; // Get client_options @@ -64,10 +69,17 @@ pub(crate) async fn read_wallet_data_from_stronghold_snapshot>(WALLET_DATA_KEY) + .get::(WALLET_DATA_KEY) .await? .map(WalletData::try_from_dto) .transpose()?; - Ok((client_options, restored_secret_manager, restored_wallet_data)) + let restored_secret_data = todo!(); + + Ok(( + client_options, + restored_secret_manager, + restored_wallet_data, + restored_secret_data, + )) } diff --git a/sdk/src/wallet/operations/balance.rs b/sdk/src/wallet/operations/balance.rs index b269acce17..3d3112cc04 100644 --- a/sdk/src/wallet/operations/balance.rs +++ b/sdk/src/wallet/operations/balance.rs @@ -16,7 +16,7 @@ use crate::{ }, }; -impl Wallet { +impl Wallet { /// Get the balance of the wallet. pub async fn balance(&self) -> Result { log::debug!("[BALANCE] balance"); @@ -29,7 +29,7 @@ impl Wallet { async fn balance_inner( &self, // addresses_with_unspent_outputs: impl Iterator + Send, - wallet_data: &WalletData, + wallet_data: &WalletData, ) -> Result { let network_id = self.client().get_network_id().await?; let storage_score_params = self.client().get_storage_score_parameters().await?; @@ -248,7 +248,7 @@ impl Wallet { fn finish( &self, mut balance: Balance, - wallet_data: &WalletData, + wallet_data: &WalletData, network_id: u64, total_storage_cost: u64, total_native_tokens: NativeTokensBuilder, diff --git a/sdk/src/wallet/operations/block.rs b/sdk/src/wallet/operations/block.rs index 3327508d39..bcf85520e3 100644 --- a/sdk/src/wallet/operations/block.rs +++ b/sdk/src/wallet/operations/block.rs @@ -4,10 +4,10 @@ use crate::{ client::secret::{BlockSignExt, SecretManage}, types::block::{output::AccountId, payload::Payload, BlockId}, - wallet::{Result, Wallet}, + wallet::{core::SecretData, Result, Wallet}, }; -impl Wallet { +impl Wallet> { pub(crate) async fn submit_basic_block( &self, payload: Option, @@ -22,10 +22,7 @@ impl Wallet { .client() .build_basic_block(issuer_id, payload) .await? - .sign_ed25519( - &*self.get_secret_manager().read().await, - &self.data().await.signing_options, - ) + .sign_ed25519(&*self.secret_manager().read().await, &self.signing_options()) .await?; let block_id = self.client().post_block(&block).await?; diff --git a/sdk/src/wallet/operations/output_claiming.rs b/sdk/src/wallet/operations/output_claiming.rs index 2e887bc1f4..d86f056846 100644 --- a/sdk/src/wallet/operations/output_claiming.rs +++ b/sdk/src/wallet/operations/output_claiming.rs @@ -19,7 +19,7 @@ use crate::{ slot::SlotIndex, }, wallet::{ - core::WalletData, + core::{SecretData, WalletData}, operations::{helpers::time::can_output_be_unlocked_now, transaction::TransactionOptions}, types::{OutputData, TransactionWithMetadata}, Wallet, @@ -37,7 +37,7 @@ pub enum OutputsToClaim { All, } -impl WalletData { +impl WalletData { /// Get basic and nft outputs that have /// [`ExpirationUnlockCondition`](crate::types::block::output::unlock_condition::ExpirationUnlockCondition), /// [`StorageDepositReturnUnlockCondition`] or @@ -125,7 +125,7 @@ impl WalletData { } } -impl Wallet { +impl Wallet { /// Get basic and nft outputs that have /// [`ExpirationUnlockCondition`](crate::types::block::output::unlock_condition::ExpirationUnlockCondition), /// [`StorageDepositReturnUnlockCondition`] or @@ -174,7 +174,9 @@ impl Wallet { log::debug!("[OUTPUT_CLAIMING] available basic outputs: {}", basic_outputs.len()); Ok(basic_outputs) } +} +impl Wallet> { /// Try to claim basic or nft outputs that have additional unlock conditions to their [AddressUnlockCondition] /// from [`Wallet::claimable_outputs()`]. pub async fn claim_outputs + Send>( @@ -213,7 +215,9 @@ impl Wallet { ); Ok(claim_tx) } +} +impl Wallet { /// Try to claim basic outputs that have additional unlock conditions to their [AddressUnlockCondition]. pub async fn prepare_claim_outputs + Send>( &self, diff --git a/sdk/src/wallet/operations/output_consolidation.rs b/sdk/src/wallet/operations/output_consolidation.rs index 2de51f570c..dd51ef18df 100644 --- a/sdk/src/wallet/operations/output_consolidation.rs +++ b/sdk/src/wallet/operations/output_consolidation.rs @@ -15,6 +15,7 @@ use crate::{ }, wallet::{ constants::DEFAULT_OUTPUT_CONSOLIDATION_THRESHOLD, + core::SecretData, operations::{helpers::time::can_output_be_unlocked_now, transaction::TransactionOptions}, types::{OutputData, TransactionWithMetadata}, Result, Wallet, @@ -65,7 +66,7 @@ impl ConsolidationParams { } } -impl Wallet { +impl Wallet { fn should_consolidate_output( &self, output_data: &OutputData, @@ -94,7 +95,9 @@ impl Wallet { false }) } +} +impl Wallet> { /// Consolidates basic outputs with only an [AddressUnlockCondition] from an account by sending them to a provided /// address or to an own address again if the output amount is >= the output_threshold. When `force` /// is set to `true`, the threshold is ignored. Only consolidates the amount of outputs that fit into a single @@ -149,7 +152,7 @@ impl Wallet { None => { #[cfg(feature = "ledger_nano")] { - let secret_manager = self.secret_manager.read().await; + let secret_manager = self.secret_manager().read().await; if (&*secret_manager).as_ledger_nano().is_ok() { DEFAULT_LEDGER_OUTPUT_CONSOLIDATION_THRESHOLD } else { @@ -176,7 +179,7 @@ impl Wallet { #[cfg(feature = "ledger_nano")] let max_inputs = { - let secret_manager = self.secret_manager.read().await; + let secret_manager = self.secret_manager().read().await; if let Ok(ledger) = (&*secret_manager).as_ledger_nano() { let ledger_nano_status = ledger.get_ledger_nano_status().await; // With blind signing we are only limited by the protocol diff --git a/sdk/src/wallet/operations/participation/event.rs b/sdk/src/wallet/operations/participation/event.rs index 6bea5f81cf..21862b3ddd 100644 --- a/sdk/src/wallet/operations/participation/event.rs +++ b/sdk/src/wallet/operations/participation/event.rs @@ -14,7 +14,7 @@ use crate::{ }, }; -impl Wallet { +impl Wallet { /// Stores participation information for the given events locally and returns them all. /// /// This will NOT store the node url and auth inside the client options. diff --git a/sdk/src/wallet/operations/participation/mod.rs b/sdk/src/wallet/operations/participation/mod.rs index 28690f3380..800385668e 100644 --- a/sdk/src/wallet/operations/participation/mod.rs +++ b/sdk/src/wallet/operations/participation/mod.rs @@ -46,7 +46,7 @@ pub struct ParticipationEventWithNodes { pub nodes: Vec, } -impl Wallet { +impl Wallet { /// Calculates the voting overview of a wallet. If event_ids are provided, only return outputs and tracked /// participations for them. pub async fn get_participation_overview( @@ -273,7 +273,7 @@ impl Wallet { } } -impl WalletData { +impl WalletData { /// Returns the voting output ("PARTICIPATION" tag). /// /// If multiple outputs with this tag exist, the one with the largest amount will be returned. diff --git a/sdk/src/wallet/operations/participation/voting.rs b/sdk/src/wallet/operations/participation/voting.rs index cb7a62ead5..65e86f8e36 100644 --- a/sdk/src/wallet/operations/participation/voting.rs +++ b/sdk/src/wallet/operations/participation/voting.rs @@ -13,10 +13,12 @@ use crate::{ payload::TaggedDataPayload, }, }, - wallet::{operations::transaction::TransactionOptions, types::TransactionWithMetadata, Result, Wallet}, + wallet::{ + core::SecretData, operations::transaction::TransactionOptions, types::TransactionWithMetadata, Result, Wallet, + }, }; -impl Wallet { +impl Wallet> { /// Casts a given number of votes for a given (voting) event. /// /// If voting for other events, continues voting for them. @@ -39,7 +41,23 @@ impl Wallet { self.sign_and_submit_transaction(prepared, None, None).await } +} + +impl Wallet> { + /// Removes metadata corresponding to a given (voting) event ID from the voting output if it contains it. + /// + /// If voting for other events, continues voting for them. + /// Removes metadata for any event that has expired (use event IDs to get cached event information, checks event + /// milestones in there against latest network milestone). + /// If NOT already voting for this event, throws an error. + pub async fn stop_participating(&self, event_id: ParticipationEventId) -> Result { + let prepared = self.prepare_stop_participating(event_id).await?; + self.sign_and_submit_transaction(prepared, None, None).await + } +} + +impl Wallet { /// Prepares the transaction for [Wallet::vote()]. pub async fn prepare_vote( &self, @@ -118,18 +136,6 @@ impl Wallet { .await } - /// Removes metadata corresponding to a given (voting) event ID from the voting output if it contains it. - /// - /// If voting for other events, continues voting for them. - /// Removes metadata for any event that has expired (use event IDs to get cached event information, checks event - /// milestones in there against latest network milestone). - /// If NOT already voting for this event, throws an error. - pub async fn stop_participating(&self, event_id: ParticipationEventId) -> Result { - let prepared = self.prepare_stop_participating(event_id).await?; - - self.sign_and_submit_transaction(prepared, None, None).await - } - /// Prepares the transaction for [Wallet::stop_participating()]. pub async fn prepare_stop_participating(&self, event_id: ParticipationEventId) -> Result { let voting_output = self diff --git a/sdk/src/wallet/operations/participation/voting_power.rs b/sdk/src/wallet/operations/participation/voting_power.rs index cca6c50b4a..722b5a1c40 100644 --- a/sdk/src/wallet/operations/participation/voting_power.rs +++ b/sdk/src/wallet/operations/participation/voting_power.rs @@ -14,10 +14,13 @@ use crate::{ payload::TaggedDataPayload, }, }, - wallet::{operations::transaction::TransactionOptions, types::TransactionWithMetadata, Error, Result, Wallet}, + wallet::{ + core::SecretData, operations::transaction::TransactionOptions, types::TransactionWithMetadata, Error, Result, + Wallet, + }, }; -impl Wallet { +impl Wallet> { /// Returns an account's total voting power (voting or NOT voting). pub async fn get_voting_power(&self) -> Result { Ok(self @@ -43,6 +46,23 @@ impl Wallet { self.sign_and_submit_transaction(prepared, None, None).await } + /// Reduces an account's "voting power" by a given amount. + /// This will stop voting, but the voting data isn't lost and calling `Vote` without parameters will revote. + /// + /// If amount is higher than actual voting power, throws an error. + /// If voting and amount is equal to voting power, removes tagged data payload and output metadata. + /// Removes metadata for any events that have expired (uses event IDs to get cached event information, checks event + /// milestones in there against latest network milestone). + /// Prioritizes consuming outputs that are designated for voting but don't have any metadata (only possible if user + /// increases voting power then decreases immediately after). + pub async fn decrease_voting_power(&self, amount: u64) -> Result { + let prepared = self.prepare_decrease_voting_power(amount).await?; + + self.sign_and_submit_transaction(prepared, None, None).await + } +} + +impl Wallet { /// Prepares the transaction for [Wallet::increase_voting_power()]. pub async fn prepare_increase_voting_power(&self, amount: u64) -> Result { let (new_output, tx_options) = match self.get_voting_output().await? { @@ -76,21 +96,6 @@ impl Wallet { self.prepare_transaction([new_output], tx_options).await } - /// Reduces an account's "voting power" by a given amount. - /// This will stop voting, but the voting data isn't lost and calling `Vote` without parameters will revote. - /// - /// If amount is higher than actual voting power, throws an error. - /// If voting and amount is equal to voting power, removes tagged data payload and output metadata. - /// Removes metadata for any events that have expired (uses event IDs to get cached event information, checks event - /// milestones in there against latest network milestone). - /// Prioritizes consuming outputs that are designated for voting but don't have any metadata (only possible if user - /// increases voting power then decreases immediately after). - pub async fn decrease_voting_power(&self, amount: u64) -> Result { - let prepared = self.prepare_decrease_voting_power(amount).await?; - - self.sign_and_submit_transaction(prepared, None, None).await - } - /// Prepares the transaction for [Wallet::decrease_voting_power()]. pub async fn prepare_decrease_voting_power(&self, amount: u64) -> Result { let current_output_data = self diff --git a/sdk/src/wallet/operations/reissue.rs b/sdk/src/wallet/operations/reissue.rs index 186186cd89..7eec5af561 100644 --- a/sdk/src/wallet/operations/reissue.rs +++ b/sdk/src/wallet/operations/reissue.rs @@ -13,13 +13,13 @@ use crate::{ BlockId, }, }, - wallet::{types::InclusionState, Error, Wallet}, + wallet::{core::SecretData, types::InclusionState, Error, Wallet}, }; const DEFAULT_REISSUE_UNTIL_INCLUDED_INTERVAL: u64 = 1; const DEFAULT_REISSUE_UNTIL_INCLUDED_MAX_AMOUNT: u64 = 40; -impl Wallet { +impl Wallet> { /// Reissues a transaction sent from the account for a provided transaction id until it's /// included (referenced by a milestone). Returns the included block id. pub async fn reissue_transaction_until_included( @@ -57,10 +57,7 @@ impl Wallet { Some(Payload::SignedTransaction(Box::new(transaction.payload.clone()))), ) .await? - .sign_ed25519( - &*self.get_secret_manager().read().await, - &self.data().await.signing_options, - ) + .sign_ed25519(&*self.secret_manager().read().await, self.signing_options()) .await? .id(&protocol_parameters), }; @@ -105,10 +102,7 @@ impl Wallet { Some(Payload::SignedTransaction(Box::new(transaction.payload.clone()))), ) .await? - .sign_ed25519( - &*self.get_secret_manager().read().await, - &self.data().await.signing_options, - ) + .sign_ed25519(&*self.secret_manager().read().await, self.signing_options()) .await?; block_ids.push(reissued_block.id(&protocol_parameters)); } diff --git a/sdk/src/wallet/operations/syncing/addresses/output_ids/account_foundry.rs b/sdk/src/wallet/operations/syncing/addresses/output_ids/account_foundry.rs index 4ae451adf0..59b13a7646 100644 --- a/sdk/src/wallet/operations/syncing/addresses/output_ids/account_foundry.rs +++ b/sdk/src/wallet/operations/syncing/addresses/output_ids/account_foundry.rs @@ -19,7 +19,7 @@ use crate::{ wallet::{operations::syncing::SyncOptions, task, Wallet}, }; -impl Wallet { +impl Wallet { /// Returns output ids of account outputs pub(crate) async fn get_account_and_foundry_output_ids( &self, diff --git a/sdk/src/wallet/operations/syncing/addresses/output_ids/basic.rs b/sdk/src/wallet/operations/syncing/addresses/output_ids/basic.rs index 1213cd2b4f..ee94d49f7a 100644 --- a/sdk/src/wallet/operations/syncing/addresses/output_ids/basic.rs +++ b/sdk/src/wallet/operations/syncing/addresses/output_ids/basic.rs @@ -8,7 +8,7 @@ use crate::{ wallet::Wallet, }; -impl Wallet { +impl Wallet { /// Returns output ids of basic outputs that have only the address unlock condition pub(crate) async fn get_basic_output_ids_with_address_unlock_condition_only( &self, diff --git a/sdk/src/wallet/operations/syncing/addresses/output_ids/mod.rs b/sdk/src/wallet/operations/syncing/addresses/output_ids/mod.rs index 48860984af..6d3f159e2e 100644 --- a/sdk/src/wallet/operations/syncing/addresses/output_ids/mod.rs +++ b/sdk/src/wallet/operations/syncing/addresses/output_ids/mod.rs @@ -12,10 +12,7 @@ use futures::FutureExt; use instant::Instant; use crate::{ - client::{ - node_api::indexer::query_parameters::{FoundryOutputQueryParameters, OutputQueryParameters}, - secret::SecretManage, - }, + client::node_api::indexer::query_parameters::{FoundryOutputQueryParameters, OutputQueryParameters}, types::block::{address::Bech32Address, output::OutputId}, wallet::{ constants::PARALLEL_REQUESTS_AMOUNT, operations::syncing::SyncOptions, @@ -23,7 +20,7 @@ use crate::{ }, }; -impl Wallet { +impl Wallet { /// Returns output ids for outputs that are directly (Ed25519 address in AddressUnlockCondition) or indirectly /// (account/nft address in AddressUnlockCondition and the account/nft output is controlled with the Ed25519 /// address) connected to diff --git a/sdk/src/wallet/operations/syncing/addresses/output_ids/nft.rs b/sdk/src/wallet/operations/syncing/addresses/output_ids/nft.rs index bbb566437c..b5c28b5948 100644 --- a/sdk/src/wallet/operations/syncing/addresses/output_ids/nft.rs +++ b/sdk/src/wallet/operations/syncing/addresses/output_ids/nft.rs @@ -8,7 +8,7 @@ use crate::{ wallet::Wallet, }; -impl Wallet { +impl Wallet { /// Returns output ids of NFT outputs that have the address in the `AddressUnlockCondition` or /// `ExpirationUnlockCondition` pub(crate) async fn get_nft_output_ids_with_any_unlock_condition( diff --git a/sdk/src/wallet/operations/syncing/addresses/outputs.rs b/sdk/src/wallet/operations/syncing/addresses/outputs.rs index a2db37f604..9b0cafca17 100644 --- a/sdk/src/wallet/operations/syncing/addresses/outputs.rs +++ b/sdk/src/wallet/operations/syncing/addresses/outputs.rs @@ -3,17 +3,14 @@ use instant::Instant; -use crate::{ - client::secret::SecretManage, - wallet::{ - constants::PARALLEL_REQUESTS_AMOUNT, - task, - types::{address::AddressWithUnspentOutputs, OutputData}, - Wallet, - }, +use crate::wallet::{ + constants::PARALLEL_REQUESTS_AMOUNT, + task, + types::{address::AddressWithUnspentOutputs, OutputData}, + Wallet, }; -impl Wallet { +impl Wallet { /// Get outputs from addresses pub(crate) async fn get_outputs_from_address_output_ids( &self, diff --git a/sdk/src/wallet/operations/syncing/foundries.rs b/sdk/src/wallet/operations/syncing/foundries.rs index 839a11ee1a..44bb5f6ce9 100644 --- a/sdk/src/wallet/operations/syncing/foundries.rs +++ b/sdk/src/wallet/operations/syncing/foundries.rs @@ -9,7 +9,7 @@ use crate::{ wallet::{task, Wallet}, }; -impl Wallet { +impl Wallet { pub(crate) async fn request_and_store_foundry_outputs( &self, foundry_ids: HashSet, diff --git a/sdk/src/wallet/operations/syncing/mod.rs b/sdk/src/wallet/operations/syncing/mod.rs index 31ff45f093..98eafef0f1 100644 --- a/sdk/src/wallet/operations/syncing/mod.rs +++ b/sdk/src/wallet/operations/syncing/mod.rs @@ -23,7 +23,7 @@ use crate::{ }, }; -impl Wallet { +impl Wallet { /// Set the fallback SyncOptions for account syncing. /// If storage is enabled, will persist during restarts. pub async fn set_default_sync_options(&self, options: SyncOptions) -> crate::wallet::Result<()> { @@ -41,7 +41,9 @@ impl Wallet { pub async fn default_sync_options(&self) -> SyncOptions { self.default_sync_options.lock().await.clone() } +} +impl Wallet { /// Sync the wallet by fetching new information from the nodes. Will also reissue pending transactions /// if necessary. A custom default can be set using set_default_sync_options. pub async fn sync(&self, options: Option) -> crate::wallet::Result { diff --git a/sdk/src/wallet/operations/syncing/outputs.rs b/sdk/src/wallet/operations/syncing/outputs.rs index 06aec25554..14f73638a1 100644 --- a/sdk/src/wallet/operations/syncing/outputs.rs +++ b/sdk/src/wallet/operations/syncing/outputs.rs @@ -21,7 +21,7 @@ use crate::{ }, }; -impl Wallet { +impl Wallet { /// Convert OutputWithMetadataResponse to OutputData with the network_id added pub(crate) async fn output_response_to_output_data( &self, diff --git a/sdk/src/wallet/operations/syncing/transactions.rs b/sdk/src/wallet/operations/syncing/transactions.rs index 0f7de427f9..478c3d0e9a 100644 --- a/sdk/src/wallet/operations/syncing/transactions.rs +++ b/sdk/src/wallet/operations/syncing/transactions.rs @@ -19,7 +19,7 @@ use crate::{ // also revalidate that the locked outputs needs to be there, maybe there was a conflict or the transaction got // confirmed, then they should get removed -impl Wallet { +impl Wallet { /// Sync transactions and reissue them if unconfirmed. Returns the transaction with updated metadata and spent /// output ids that don't need to be locked anymore /// Return true if a transaction got confirmed for which we don't have an output already, based on this outputs will @@ -196,14 +196,15 @@ impl Wallet { } drop(wallet_data); - for mut transaction in transactions_to_reissue { - log::debug!("[SYNC] reissue transaction"); - let reissued_block = self - .submit_signed_transaction(transaction.payload.clone(), None) - .await?; - transaction.block_id.replace(reissued_block); - updated_transactions.push(transaction); - } + // TODO: this is a problem + // for mut transaction in transactions_to_reissue { + // log::debug!("[SYNC] reissue transaction"); + // let reissued_block = self + // .submit_signed_transaction(transaction.payload.clone(), None) + // .await?; + // transaction.block_id.replace(reissued_block); + // updated_transactions.push(transaction); + // } // updates account with balances, output ids, outputs self.update_with_transactions(updated_transactions, spent_output_ids, output_ids_to_unlock) @@ -233,8 +234,8 @@ fn updated_transaction_and_outputs( // When a transaction got pruned, the inputs and outputs are also not available, then this could mean that it was // confirmed and the created outputs got also already spent and pruned or the inputs got spent in another transaction -fn process_transaction_with_unknown_state( - wallet_data: &WalletData, +fn process_transaction_with_unknown_state( + wallet_data: &WalletData, mut transaction: TransactionWithMetadata, updated_transactions: &mut Vec, output_ids_to_unlock: &mut Vec, diff --git a/sdk/src/wallet/operations/transaction/account.rs b/sdk/src/wallet/operations/transaction/account.rs index 0732cc1256..ee219e76dc 100644 --- a/sdk/src/wallet/operations/transaction/account.rs +++ b/sdk/src/wallet/operations/transaction/account.rs @@ -15,12 +15,13 @@ use crate::{ }, }, wallet::{ + core::SecretData, operations::transaction::{TransactionOptions, TransactionWithMetadata}, Error, Result, Wallet, }, }; -impl Wallet { +impl Wallet> { /// Transitions an implicit account to an account. pub async fn implicit_account_transition( &self, @@ -57,12 +58,12 @@ impl Wallet { let key_source = match key_source.into() { Some(key_source) => key_source, - None => BlockIssuerKeySource::Options(self.data().await.public_key_options.clone()), + None => BlockIssuerKeySource::Options(self.public_key_options().clone()), }; let public_key = match key_source { BlockIssuerKeySource::Key(public_key) => public_key, - BlockIssuerKeySource::Options(options) => self.secret_manager.read().await.generate(&options).await?, + BlockIssuerKeySource::Options(options) => self.secret_manager().read().await.generate(&options).await?, }; let account_id = AccountId::from(output_id); diff --git a/sdk/src/wallet/operations/transaction/build_transaction.rs b/sdk/src/wallet/operations/transaction/build_transaction.rs index 3651052793..d9dc3d1378 100644 --- a/sdk/src/wallet/operations/transaction/build_transaction.rs +++ b/sdk/src/wallet/operations/transaction/build_transaction.rs @@ -15,7 +15,7 @@ use crate::{ wallet::{operations::transaction::TransactionOptions, Wallet}, }; -impl Wallet { +impl Wallet { /// Builds the transaction from the selected in and outputs. pub(crate) async fn build_transaction( &self, diff --git a/sdk/src/wallet/operations/transaction/high_level/burning_melting/melt_native_token.rs b/sdk/src/wallet/operations/transaction/high_level/burning_melting/melt_native_token.rs index ee17b2f5d9..8c7454ace2 100644 --- a/sdk/src/wallet/operations/transaction/high_level/burning_melting/melt_native_token.rs +++ b/sdk/src/wallet/operations/transaction/high_level/burning_melting/melt_native_token.rs @@ -10,13 +10,14 @@ use crate::{ TokenScheme, }, wallet::{ + core::SecretData, operations::transaction::TransactionOptions, types::{OutputData, TransactionWithMetadata}, Error, Wallet, }, }; -impl Wallet { +impl Wallet> { /// Melts native tokens. /// /// This happens with the foundry output which minted them, by increasing it's @@ -36,7 +37,9 @@ impl Wallet { self.sign_and_submit_transaction(prepared_transaction, None, options) .await } +} +impl Wallet { /// Prepares the transaction for [Wallet::melt_native_token()]. pub async fn prepare_melt_native_token( &self, diff --git a/sdk/src/wallet/operations/transaction/high_level/burning_melting/mod.rs b/sdk/src/wallet/operations/transaction/high_level/burning_melting/mod.rs index 1d22610a7b..3dc65168ec 100644 --- a/sdk/src/wallet/operations/transaction/high_level/burning_melting/mod.rs +++ b/sdk/src/wallet/operations/transaction/high_level/burning_melting/mod.rs @@ -6,12 +6,12 @@ use crate::{ api::{input_selection::Burn, PreparedTransactionData}, secret::SecretManage, }, - wallet::{operations::transaction::TransactionOptions, types::TransactionWithMetadata, Wallet}, + wallet::{core::SecretData, operations::transaction::TransactionOptions, types::TransactionWithMetadata, Wallet}, }; pub(crate) mod melt_native_token; -impl Wallet { +impl Wallet> { /// A generic function that can be used to burn native tokens, nfts, foundries and accounts. /// /// Note that burning **native tokens** doesn't require the foundry output which minted them, but will not increase @@ -27,7 +27,9 @@ impl Wallet { self.sign_and_submit_transaction(prepared, None, options).await } +} +impl Wallet { /// A generic `prepare_burn()` function that can be used to prepare the burn of native tokens, nfts, foundries and /// accounts. /// diff --git a/sdk/src/wallet/operations/transaction/high_level/create_account.rs b/sdk/src/wallet/operations/transaction/high_level/create_account.rs index c9adb9cfc5..56a151880c 100644 --- a/sdk/src/wallet/operations/transaction/high_level/create_account.rs +++ b/sdk/src/wallet/operations/transaction/high_level/create_account.rs @@ -13,6 +13,7 @@ use crate::{ }, utils::serde::option_prefix_hex_bytes, wallet::{ + core::SecretData, operations::transaction::TransactionOptions, types::{OutputData, TransactionWithMetadata}, Wallet, @@ -34,7 +35,7 @@ pub struct CreateAccountParams { pub metadata: Option>, } -impl Wallet { +impl Wallet> { /// Creates an account output. /// ```ignore /// let params = CreateAccountParams { @@ -61,7 +62,9 @@ impl Wallet { self.sign_and_submit_transaction(prepared_transaction, None, options) .await } +} +impl Wallet { /// Prepares the transaction for [Wallet::create_account_output()]. pub async fn prepare_create_account_output( &self, diff --git a/sdk/src/wallet/operations/transaction/high_level/minting/create_native_token.rs b/sdk/src/wallet/operations/transaction/high_level/minting/create_native_token.rs index 38d5886117..67b1edefb6 100644 --- a/sdk/src/wallet/operations/transaction/high_level/minting/create_native_token.rs +++ b/sdk/src/wallet/operations/transaction/high_level/minting/create_native_token.rs @@ -17,6 +17,7 @@ use crate::{ }, }, wallet::{ + core::SecretData, operations::transaction::TransactionOptions, types::{TransactionWithMetadata, TransactionWithMetadataDto}, Wallet, @@ -86,7 +87,7 @@ impl From<&PreparedCreateNativeTokenTransaction> for PreparedCreateNativeTokenTr } } -impl Wallet { +impl Wallet> { /// Creates a new foundry output with minted native tokens. /// /// Calls [Wallet::send_outputs()] internally, the options may define the remainder value strategy or custom inputs. @@ -120,7 +121,9 @@ impl Wallet { transaction, }) } +} +impl Wallet { /// Prepares the transaction for [Wallet::create_native_token()]. pub async fn prepare_create_native_token( &self, diff --git a/sdk/src/wallet/operations/transaction/high_level/minting/mint_native_token.rs b/sdk/src/wallet/operations/transaction/high_level/minting/mint_native_token.rs index 87a233f898..b04c11102c 100644 --- a/sdk/src/wallet/operations/transaction/high_level/minting/mint_native_token.rs +++ b/sdk/src/wallet/operations/transaction/high_level/minting/mint_native_token.rs @@ -8,10 +8,12 @@ use crate::{ types::block::output::{ AccountOutputBuilder, FoundryOutputBuilder, Output, SimpleTokenScheme, TokenId, TokenScheme, }, - wallet::{operations::transaction::TransactionOptions, types::TransactionWithMetadata, Error, Wallet}, + wallet::{ + core::SecretData, operations::transaction::TransactionOptions, types::TransactionWithMetadata, Error, Wallet, + }, }; -impl Wallet { +impl Wallet> { /// Mints additional native tokens. /// /// The max supply must not be reached yet. The foundry needs to be @@ -41,7 +43,9 @@ impl Wallet { Ok(transaction) } +} +impl Wallet { /// Prepares the transaction for [Wallet::mint_native_token()]. pub async fn prepare_mint_native_token( &self, diff --git a/sdk/src/wallet/operations/transaction/high_level/minting/mint_nfts.rs b/sdk/src/wallet/operations/transaction/high_level/minting/mint_nfts.rs index f120e95ef8..018a85e54d 100644 --- a/sdk/src/wallet/operations/transaction/high_level/minting/mint_nfts.rs +++ b/sdk/src/wallet/operations/transaction/high_level/minting/mint_nfts.rs @@ -16,6 +16,7 @@ use crate::{ }, utils::ConvertTo, wallet::{ + core::SecretData, operations::transaction::{TransactionOptions, TransactionWithMetadata}, Wallet, }, @@ -109,7 +110,7 @@ impl MintNftParams { } } -impl Wallet { +impl Wallet> { /// Mints NFTs. /// /// Calls [Wallet::send_outputs()] internally. The options may define the remainder value strategy or custom inputs. @@ -146,7 +147,9 @@ impl Wallet { self.sign_and_submit_transaction(prepared_transaction, None, options) .await } +} +impl Wallet { /// Prepares the transaction for [Wallet::mint_nfts()]. pub async fn prepare_mint_nfts + Send>( &self, diff --git a/sdk/src/wallet/operations/transaction/high_level/send.rs b/sdk/src/wallet/operations/transaction/high_level/send.rs index 84f1b4bf5c..7866ce1ba1 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send.rs @@ -17,6 +17,7 @@ use crate::{ utils::{serde::string, ConvertTo}, wallet::{ constants::DEFAULT_EXPIRATION_SLOTS, + core::SecretData, operations::transaction::{TransactionOptions, TransactionWithMetadata}, Error, Wallet, }, @@ -73,7 +74,7 @@ impl SendParams { } } -impl Wallet { +impl Wallet> { /// Sends a certain amount of base coins to a single address. /// /// Calls [Wallet::send_with_params()] internally. @@ -120,7 +121,9 @@ impl Wallet { self.sign_and_submit_transaction(prepared_transaction, None, options) .await } +} +impl Wallet { /// Prepares the transaction for [Wallet::send()]. pub async fn prepare_send + Send>( &self, diff --git a/sdk/src/wallet/operations/transaction/high_level/send_native_tokens.rs b/sdk/src/wallet/operations/transaction/high_level/send_native_tokens.rs index 7702871d65..7669e65b11 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send_native_tokens.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send_native_tokens.rs @@ -18,6 +18,7 @@ use crate::{ utils::ConvertTo, wallet::{ constants::DEFAULT_EXPIRATION_SLOTS, + core::SecretData, operations::transaction::{TransactionOptions, TransactionWithMetadata}, Error, Result, Wallet, }, @@ -73,7 +74,7 @@ impl SendNativeTokenParams { } } -impl Wallet { +impl Wallet> { /// Sends native tokens in basic outputs with a /// [`StorageDepositReturnUnlockCondition`](crate::types::block::output::unlock_condition::StorageDepositReturnUnlockCondition) /// and an [`ExpirationUnlockCondition`], so that the storage deposit is returned to the sender and the sender @@ -110,7 +111,9 @@ impl Wallet { self.sign_and_submit_transaction(prepared_transaction, None, options) .await } +} +impl Wallet { /// Prepares the transaction for [Wallet::send_native_tokens()]. pub async fn prepare_send_native_tokens + Send>( &self, diff --git a/sdk/src/wallet/operations/transaction/high_level/send_nft.rs b/sdk/src/wallet/operations/transaction/high_level/send_nft.rs index 820ccbf505..18ce7d5d23 100644 --- a/sdk/src/wallet/operations/transaction/high_level/send_nft.rs +++ b/sdk/src/wallet/operations/transaction/high_level/send_nft.rs @@ -12,6 +12,7 @@ use crate::{ }, utils::ConvertTo, wallet::{ + core::SecretData, operations::transaction::{TransactionOptions, TransactionWithMetadata}, Wallet, }, @@ -42,7 +43,7 @@ impl SendNftParams { } } -impl Wallet { +impl Wallet> { /// Sends native tokens in basic outputs with a /// [`StorageDepositReturnUnlockCondition`](crate::types::block::output::unlock_condition::StorageDepositReturnUnlockCondition) and an /// [`ExpirationUnlockCondition`](crate::types::block::output::unlock_condition::ExpirationUnlockCondition), so that @@ -78,7 +79,9 @@ impl Wallet { self.sign_and_submit_transaction(prepared_transaction, None, options) .await } +} +impl Wallet { /// Prepares the transaction for [Wallet::send_nft()]. pub async fn prepare_send_nft + Send>( &self, diff --git a/sdk/src/wallet/operations/transaction/input_selection.rs b/sdk/src/wallet/operations/transaction/input_selection.rs index 82e0b5db39..e6d4b12727 100644 --- a/sdk/src/wallet/operations/transaction/input_selection.rs +++ b/sdk/src/wallet/operations/transaction/input_selection.rs @@ -21,7 +21,7 @@ use crate::{ }, }; -impl Wallet { +impl Wallet { /// Selects inputs for a transaction and locks them in the wallet, so they don't get used again pub(crate) async fn select_inputs( &self, @@ -211,8 +211,8 @@ impl Wallet { /// | [Address, StorageDepositReturn, ...] | no | /// | [Address, StorageDepositReturn, expired Expiration] | yes | #[allow(clippy::too_many_arguments)] -fn filter_inputs( - wallet_data: &WalletData, +fn filter_inputs( + wallet_data: &WalletData, available_outputs: Values<'_, OutputId, OutputData>, slot_index: SlotIndex, custom_inputs: Option<&HashSet>, diff --git a/sdk/src/wallet/operations/transaction/mod.rs b/sdk/src/wallet/operations/transaction/mod.rs index 574f4d8c6b..16dced0a62 100644 --- a/sdk/src/wallet/operations/transaction/mod.rs +++ b/sdk/src/wallet/operations/transaction/mod.rs @@ -29,12 +29,13 @@ use crate::{ }, }, wallet::{ + core::SecretData, types::{InclusionState, TransactionWithMetadata}, Wallet, }, }; -impl Wallet { +impl Wallet> { /// Sends a transaction by specifying its outputs. /// /// Note that, if sending a block fails, the method will return `None` for the block id, but the wallet @@ -194,7 +195,9 @@ impl Wallet { Ok(transaction) } +} +impl Wallet { // unlock outputs async fn unlock_inputs(&self, inputs: &[InputSigningData]) -> crate::wallet::Result<()> { let mut wallet_data = self.data_mut().await; diff --git a/sdk/src/wallet/operations/transaction/prepare_output.rs b/sdk/src/wallet/operations/transaction/prepare_output.rs index 758b87c6fe..85c282d1a1 100644 --- a/sdk/src/wallet/operations/transaction/prepare_output.rs +++ b/sdk/src/wallet/operations/transaction/prepare_output.rs @@ -27,7 +27,7 @@ use crate::{ }, }; -impl Wallet { +impl Wallet { /// Prepare a basic or NFT output for sending /// If the amount is below the minimum required storage deposit, by default the remaining amount will automatically /// be added with a StorageDepositReturn UnlockCondition, when setting the ReturnStrategy to `gift`, the full diff --git a/sdk/src/wallet/operations/transaction/prepare_transaction.rs b/sdk/src/wallet/operations/transaction/prepare_transaction.rs index dfde411a99..98c25f381d 100644 --- a/sdk/src/wallet/operations/transaction/prepare_transaction.rs +++ b/sdk/src/wallet/operations/transaction/prepare_transaction.rs @@ -18,7 +18,7 @@ use crate::{ }, }; -impl Wallet { +impl Wallet { /// Get inputs and build the transaction pub async fn prepare_transaction( &self, diff --git a/sdk/src/wallet/operations/transaction/sign_transaction.rs b/sdk/src/wallet/operations/transaction/sign_transaction.rs index f8a5b2008d..a5470fb692 100644 --- a/sdk/src/wallet/operations/transaction/sign_transaction.rs +++ b/sdk/src/wallet/operations/transaction/sign_transaction.rs @@ -1,12 +1,6 @@ // Copyright 2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -#[cfg(all(feature = "events", feature = "ledger_nano"))] -use { - crate::client::api::PreparedTransactionDataDto, - crate::client::secret::ledger_nano::{needs_blind_signing, LedgerSecretManager}, -}; - #[cfg(feature = "events")] use crate::wallet::events::types::{TransactionProgressEvent, WalletEvent}; use crate::{ @@ -16,10 +10,10 @@ use crate::{ }, secret::SecretManage, }, - wallet::{operations::transaction::SignedTransactionPayload, Wallet}, + wallet::{core::SecretData, operations::transaction::SignedTransactionPayload, Wallet}, }; -impl Wallet { +impl Wallet> { /// Signs a transaction. pub async fn sign_transaction( &self, @@ -70,14 +64,10 @@ impl Wallet { let protocol_parameters = self.client().get_protocol_parameters().await?; let unlocks = match self - .secret_manager + .secret_manager() .read() .await - .transaction_unlocks( - prepared_transaction_data, - &protocol_parameters, - self.data().await.signing_options(), - ) + .transaction_unlocks(prepared_transaction_data, &protocol_parameters, self.signing_options()) .await { Ok(res) => res, diff --git a/sdk/src/wallet/operations/transaction/submit_transaction.rs b/sdk/src/wallet/operations/transaction/submit_transaction.rs index fab7ac0ee7..9135ffeb23 100644 --- a/sdk/src/wallet/operations/transaction/submit_transaction.rs +++ b/sdk/src/wallet/operations/transaction/submit_transaction.rs @@ -6,10 +6,10 @@ use crate::wallet::events::types::{TransactionProgressEvent, WalletEvent}; use crate::{ client::secret::SecretManage, types::block::{output::AccountId, payload::Payload, BlockId}, - wallet::{operations::transaction::SignedTransactionPayload, Wallet}, + wallet::{core::SecretData, operations::transaction::SignedTransactionPayload, Wallet}, }; -impl Wallet { +impl Wallet> { /// Submits a signed transaction in a block. pub(crate) async fn submit_signed_transaction( &self, diff --git a/sdk/src/wallet/storage/manager.rs b/sdk/src/wallet/storage/manager.rs index 470f8ce964..dde6019356 100644 --- a/sdk/src/wallet/storage/manager.rs +++ b/sdk/src/wallet/storage/manager.rs @@ -7,7 +7,7 @@ use crate::{ client::{secret::SecretManage, storage::StorageAdapter}, types::TryFromDto, wallet::{ - core::{WalletData, WalletDataDto}, + core::{SecretData, WalletData, WalletDataDto}, migration::migrate, operations::syncing::SyncOptions, storage::{constants::*, DynStorageAdapter, Storage}, @@ -49,22 +49,27 @@ impl StorageManager { Ok(storage_manager) } - pub(crate) async fn load_wallet_data(&mut self) -> crate::wallet::Result>> { - if let Some(dto) = self - .get::>(WALLET_DATA_KEY) - .await? - { + pub(crate) async fn load_wallet_data(&mut self) -> crate::wallet::Result> { + if let Some(dto) = self.get::(WALLET_DATA_KEY).await? { Ok(Some(WalletData::try_from_dto(dto)?)) } else { Ok(None) } } - pub(crate) async fn save_wallet_data( + pub(crate) async fn save_wallet_data(&mut self, wallet_data: &WalletData) -> crate::wallet::Result<()> { + self.set(WALLET_DATA_KEY, &WalletDataDto::from(wallet_data)).await + } + + pub(crate) async fn load_secret_data(&mut self) -> crate::wallet::Result>> { + todo!() + } + + pub(crate) async fn save_secret_data( &mut self, - wallet_data: &WalletData, + secret_data: &SecretData, ) -> crate::wallet::Result<()> { - self.set(WALLET_DATA_KEY, &WalletDataDto::from(wallet_data)).await + todo!() } pub(crate) async fn set_default_sync_options(&self, sync_options: &SyncOptions) -> crate::wallet::Result<()> { @@ -102,8 +107,12 @@ mod tests { use super::*; use crate::{ - client::secret::{mnemonic::MnemonicSecretManager, SecretManager}, - wallet::{storage::adapter::memory::Memory, WalletBuilder}, + client::secret::mnemonic::MnemonicSecretManager, + wallet::{ + core::builder::{dto::SecretDataDto, SecretDataBuilder}, + storage::adapter::memory::Memory, + WalletBuilder, + }, }; #[tokio::test] @@ -130,21 +139,12 @@ mod tests { #[tokio::test] async fn save_load_wallet_data() { let mut storage_manager = StorageManager::new(Memory::default(), None).await.unwrap(); - assert!( - storage_manager - .load_wallet_data::() - .await - .unwrap() - .is_none() - ); + assert!(storage_manager.load_wallet_data().await.unwrap().is_none()); - let wallet_data = WalletData::::mock(); + let wallet_data = WalletData::mock(); storage_manager.save_wallet_data(&wallet_data).await.unwrap(); - let wallet = storage_manager - .load_wallet_data::() - .await - .unwrap(); + let wallet = storage_manager.load_wallet_data().await.unwrap(); assert!(matches!(wallet, Some(data) if data.alias == Some("Alice".to_string()))); } @@ -152,17 +152,17 @@ mod tests { async fn save_load_wallet_builder() { let storage_manager = StorageManager::new(Memory::default(), None).await.unwrap(); assert!( - WalletBuilder::::load(&storage_manager) + WalletBuilder::>::load::>(&storage_manager) .await .unwrap() .is_none() ); - let wallet_builder = WalletBuilder::::new(); + let wallet_builder = WalletBuilder::new().with_secret_type::(); wallet_builder.save(&storage_manager).await.unwrap(); assert!( - WalletBuilder::::load(&storage_manager) + WalletBuilder::>::load::>(&storage_manager) .await .unwrap() .is_some() diff --git a/sdk/src/wallet/update.rs b/sdk/src/wallet/update.rs index 4e8ed4fbba..2d41e826db 100644 --- a/sdk/src/wallet/update.rs +++ b/sdk/src/wallet/update.rs @@ -3,25 +3,21 @@ use std::collections::HashMap; -use crate::{ - client::secret::{SecretManage, Sign}, - types::block::{ - output::{OutputId, OutputMetadata}, - signature::Ed25519Signature, - }, - wallet::{ - types::{InclusionState, OutputData, TransactionWithMetadata}, - Wallet, - }, -}; #[cfg(feature = "events")] use crate::{ types::api::core::OutputWithMetadataResponse, types::block::payload::signed_transaction::dto::SignedTransactionPayloadDto, wallet::events::types::{NewOutputEvent, SpentOutputEvent, TransactionInclusionEvent, WalletEvent}, }; +use crate::{ + types::block::output::{OutputId, OutputMetadata}, + wallet::{ + types::{InclusionState, OutputData, TransactionWithMetadata}, + Wallet, + }, +}; -impl Wallet { +impl Wallet { /// Set the alias for the wallet. pub async fn set_alias(&self, alias: &str) -> crate::wallet::Result<()> { let mut wallet_data = self.data_mut().await; diff --git a/sdk/tests/wallet/address_generation.rs b/sdk/tests/wallet/address_generation.rs index fcd39b44d7..18b17f85a2 100644 --- a/sdk/tests/wallet/address_generation.rs +++ b/sdk/tests/wallet/address_generation.rs @@ -16,7 +16,7 @@ use iota_sdk::{ secret::{mnemonic::MnemonicSecretManager, PublicKeyOptions, SecretManageExt}, }, types::block::address::{Ed25519Address, ToBech32Ext}, - wallet::{ClientOptions, Result, Wallet}, + wallet::{ClientOptions, Result, Wallet, WalletBuilder}, }; use pretty_assertions::assert_eq; @@ -31,7 +31,7 @@ async fn wallet_address_generation_mnemonic() -> Result<()> { let secret_manager = MnemonicSecretManager::try_from_mnemonic(DEFAULT_MNEMONIC.to_owned())?; #[allow(unused_mut)] - let mut wallet_builder = Wallet::builder() + let mut wallet_builder = WalletBuilder::new() .with_secret_manager(secret_manager) .with_client_options(client_options) .with_public_key_options(PublicKeyOptions::new(IOTA_COIN_TYPE)) @@ -43,7 +43,7 @@ async fn wallet_address_generation_mnemonic() -> Result<()> { } let wallet = wallet_builder.finish().await?; - let address = (*wallet.get_secret_manager().read().await) + let address = (*wallet.secret_manager().read().await) .generate::(&PublicKeyOptions::new(IOTA_COIN_TYPE)) .await?; @@ -73,7 +73,7 @@ async fn wallet_address_generation_stronghold() -> Result<()> { let client_options = ClientOptions::new().with_node(NODE_LOCAL)?; #[allow(unused_mut)] - let mut wallet_builder = Wallet::builder() + let mut wallet_builder = WalletBuilder::new() .with_secret_manager(secret_manager) .with_client_options(client_options) .with_public_key_options(PublicKeyOptions::new(IOTA_COIN_TYPE)) @@ -84,7 +84,7 @@ async fn wallet_address_generation_stronghold() -> Result<()> { } let wallet = wallet_builder.finish().await?; - let address = (*wallet.get_secret_manager().read().await) + let address = (*wallet.secret_manager().read().await) .generate::(&PublicKeyOptions::new(IOTA_COIN_TYPE)) .await?; @@ -109,7 +109,7 @@ async fn wallet_address_generation_ledger() -> Result<()> { secret_manager.non_interactive = true; #[allow(unused_mut)] - let mut wallet_builder = Wallet::builder() + let mut wallet_builder = WalletBuilder::new() .with_secret_manager(secret_manager) .with_client_options(client_options) .with_public_key_options(LedgerOptions::new(PublicKeyOptions::new(IOTA_COIN_TYPE))) @@ -121,7 +121,7 @@ async fn wallet_address_generation_ledger() -> Result<()> { } let wallet = wallet_builder.finish().await?; - let address = (*wallet.get_secret_manager().read().await) + let address = (*wallet.secret_manager().read().await) .generate::(&LedgerOptions::new(PublicKeyOptions::new(IOTA_COIN_TYPE))) .await? .to_bech32(SHIMMER_TESTNET_BECH32_HRP); @@ -149,7 +149,7 @@ async fn wallet_address_generation_ledger() -> Result<()> { }) .await; - let address = (*wallet.get_secret_manager().read().await) + let address = (*wallet.secret_manager().read().await) .generate::( &LedgerOptions::new(PublicKeyOptions::new(IOTA_COIN_TYPE)).with_ledger_nano_prompt(true), ) diff --git a/sdk/tests/wallet/backup_restore.rs b/sdk/tests/wallet/backup_restore.rs index 7fd0ceec97..86e7f51376 100644 --- a/sdk/tests/wallet/backup_restore.rs +++ b/sdk/tests/wallet/backup_restore.rs @@ -103,7 +103,7 @@ // // secret manager is the same // assert_eq!( // wallet -// .get_secret_manager() +// .secret_manager() // .read() // .await // .generate_ed25519_addresses(GetAddressesOptions { @@ -113,7 +113,7 @@ // }) // .await?, // restored_wallet -// .get_secret_manager() +// .secret_manager() // .read() // .await // .generate_ed25519_addresses(GetAddressesOptions { diff --git a/sdk/tests/wallet/burn_outputs.rs b/sdk/tests/wallet/burn_outputs.rs index 8973700dae..e1866d9ca2 100644 --- a/sdk/tests/wallet/burn_outputs.rs +++ b/sdk/tests/wallet/burn_outputs.rs @@ -7,7 +7,7 @@ use iota_sdk::{ unlock_condition::{AddressUnlockCondition, ExpirationUnlockCondition}, NativeToken, NftId, NftOutputBuilder, OutputId, UnlockCondition, }, - wallet::{CreateNativeTokenParams, MintNftParams, Result, Wallet}, + wallet::{core::SecretData, CreateNativeTokenParams, MintNftParams, Result, Wallet}, U256, }; use pretty_assertions::assert_eq; @@ -177,7 +177,7 @@ async fn create_and_melt_native_token() -> Result<()> { tear_down(storage_path) } -async fn destroy_foundry(wallet: &Wallet) -> Result<()> { +async fn destroy_foundry(wallet: &Wallet>) -> Result<()> { let balance = wallet.sync(None).await?; println!("wallet balance -> {}", serde_json::to_string(&balance).unwrap()); @@ -200,7 +200,7 @@ async fn destroy_foundry(wallet: &Wallet) -> Resul Ok(()) } -async fn destroy_account(wallet: &Wallet) -> Result<()> { +async fn destroy_account(wallet: &Wallet>) -> Result<()> { let balance = wallet.sync(None).await.unwrap(); println!("account balance -> {}", serde_json::to_string(&balance).unwrap()); diff --git a/sdk/tests/wallet/common/mod.rs b/sdk/tests/wallet/common/mod.rs index 2748476704..0c8725d34d 100644 --- a/sdk/tests/wallet/common/mod.rs +++ b/sdk/tests/wallet/common/mod.rs @@ -8,10 +8,10 @@ use iota_sdk::{ client::{ constants::SHIMMER_COIN_TYPE, request_funds_from_faucet, - secret::{mnemonic::MnemonicSecretManager, PublicKeyOptions, SecretManage}, + secret::{mnemonic::MnemonicSecretManager, PublicKeyOptions}, Client, }, - wallet::{ClientOptions, Result, Wallet}, + wallet::{core::SecretData, ClientOptions, Result, Wallet, WalletBuilder}, }; pub use self::constants::*; @@ -33,13 +33,13 @@ pub(crate) async fn make_wallet( storage_path: &str, mnemonic: Option, node: Option<&str>, -) -> Result> { +) -> Result>> { let client_options = ClientOptions::new().with_node(node.unwrap_or(NODE_LOCAL))?; let secret_manager = MnemonicSecretManager::try_from_mnemonic(mnemonic.unwrap_or_else(|| Client::generate_mnemonic().unwrap()))?; #[allow(unused_mut)] - let mut wallet_builder = Wallet::builder() + let mut wallet_builder = WalletBuilder::new() .with_secret_manager(secret_manager) .with_client_options(client_options) .with_public_key_options(PublicKeyOptions::new(SHIMMER_COIN_TYPE)) @@ -58,7 +58,7 @@ pub(crate) async fn make_wallet( pub(crate) async fn make_ledger_nano_wallet( storage_path: &str, node: Option<&str>, -) -> Result> { +) -> Result>> { use iota_sdk::client::secret::ledger_nano::{LedgerOptions, LedgerSecretManager}; let client_options = ClientOptions::new().with_node(node.unwrap_or(NODE_LOCAL))?; @@ -66,7 +66,7 @@ pub(crate) async fn make_ledger_nano_wallet( secret_manager.non_interactive = true; #[allow(unused_mut)] - let mut wallet_builder = Wallet::builder() + let mut wallet_builder = WalletBuilder::new() .with_secret_manager(secret_manager) .with_client_options(client_options) .with_public_key_options(LedgerOptions::new(PublicKeyOptions::new(SHIMMER_COIN_TYPE))) @@ -81,7 +81,7 @@ pub(crate) async fn make_ledger_nano_wallet( /// Request funds from the faucet and sync the wallet. #[allow(dead_code)] -pub(crate) async fn request_funds(wallet: &Wallet) -> Result<()> { +pub(crate) async fn request_funds(wallet: &Wallet) -> Result<()> { request_funds_from_faucet(FAUCET_URL, &wallet.address().await).await?; // Continue only after funds are received diff --git a/sdk/tests/wallet/core.rs b/sdk/tests/wallet/core.rs index c992feb768..c532cf869b 100644 --- a/sdk/tests/wallet/core.rs +++ b/sdk/tests/wallet/core.rs @@ -15,7 +15,7 @@ use iota_sdk::{ }, crypto::keys::bip44::Bip44, types::block::address::Bech32Address, - wallet::{ClientOptions, Result, Wallet}, + wallet::{ClientOptions, Result, WalletBuilder}, }; use pretty_assertions::assert_eq; use url::Url; @@ -88,7 +88,7 @@ async fn changed_bip_path() -> Result<()> { drop(wallet); - let err = Wallet::builder() + let err = WalletBuilder::new() .with_secret_manager(MnemonicSecretManager::try_from_mnemonic(mnemonic.clone())?) .with_public_key_options(PublicKeyOptions::new(IOTA_COIN_TYPE)) .with_signing_options(Bip44::new(IOTA_COIN_TYPE)) @@ -105,7 +105,7 @@ async fn changed_bip_path() -> Result<()> { // Building the wallet with the same coin type still works assert!( - Wallet::builder() + WalletBuilder::new() .with_secret_manager(MnemonicSecretManager::try_from_mnemonic(mnemonic,)?) .with_storage_path(storage_path) .finish() @@ -142,7 +142,7 @@ async fn iota_coin_type() -> Result<()> { let secret_manager = MnemonicSecretManager::try_from_mnemonic(DEFAULT_MNEMONIC.to_owned())?; #[allow(unused_mut)] - let mut wallet_builder = Wallet::builder() + let mut wallet_builder = WalletBuilder::new() .with_secret_manager(secret_manager) .with_client_options(client_options) .with_public_key_options(PublicKeyOptions::new(IOTA_COIN_TYPE)) diff --git a/sdk/tests/wallet/migrate_stronghold_snapshot_v2_to_v3.rs b/sdk/tests/wallet/migrate_stronghold_snapshot_v2_to_v3.rs index 70e2ffedfb..820bd82a7d 100644 --- a/sdk/tests/wallet/migrate_stronghold_snapshot_v2_to_v3.rs +++ b/sdk/tests/wallet/migrate_stronghold_snapshot_v2_to_v3.rs @@ -13,7 +13,7 @@ use iota_sdk::{ }, crypto::keys::bip44::Bip44, types::block::address::{Ed25519Address, ToBech32Ext}, - wallet::{ClientOptions, Error as WalletError, Wallet}, + wallet::{ClientOptions, Error as WalletError, Wallet, WalletBuilder}, }; use pretty_assertions::assert_eq; @@ -79,7 +79,7 @@ async fn stronghold_snapshot_v2_v3_migration() { ] ); - let restore_manager = Wallet::builder() + let restore_manager = WalletBuilder::new() .with_storage_path("test-storage/stronghold_snapshot_v2_v3_migration") .with_secret_manager(stronghold_secret_manager) .with_client_options(ClientOptions::new().with_node(NODE_LOCAL).unwrap())