Skip to content

Commit

Permalink
overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Coats committed Dec 7, 2023
1 parent ea20926 commit 8eebdef
Show file tree
Hide file tree
Showing 100 changed files with 814 additions and 568 deletions.
6 changes: 3 additions & 3 deletions bindings/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -91,9 +91,9 @@ impl WalletOptions {
self
}

pub async fn build(self) -> iota_sdk::wallet::Result<Wallet<SecretManager>> {
pub async fn build(self) -> iota_sdk::wallet::Result<Wallet<SecretData<SecretManager>>> {
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)
Expand Down
6 changes: 3 additions & 3 deletions bindings/core/src/method_handler/call_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -35,7 +35,7 @@ impl CallMethod for Client {
}
}

impl CallMethod for Wallet<SecretManager> {
impl CallMethod for Wallet<SecretData<SecretManager>> {
type Method = WalletMethod;

fn call_method<'a>(&'a self, method: Self::Method) -> Pin<Box<dyn Future<Output = Response> + 'a>> {
Expand All @@ -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<SecretManager>, method: WalletMethod) -> Response {
pub async fn call_wallet_method(wallet: &Wallet<SecretData<SecretManager>>, method: WalletMethod) -> Response {
log::debug!("Wallet method: {method:?}");
let result = convert_async_panics(|| async { call_wallet_method_internal(wallet, method).await }).await;

Expand Down
7 changes: 4 additions & 3 deletions bindings/core/src/method_handler/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ use iota_sdk::{
},
types::TryFromDto,
wallet::{
types::TransactionWithMetadataDto, BlockIssuerKeySource, PreparedCreateNativeTokenTransactionDto, Wallet,
core::SecretData, types::TransactionWithMetadataDto, BlockIssuerKeySource,
PreparedCreateNativeTokenTransactionDto, Wallet,
},
};

use crate::{method::WalletMethod, response::Response};

/// Call a wallet method.
pub(crate) async fn call_wallet_method_internal(
wallet: &Wallet<SecretManager>,
wallet: &Wallet<SecretData<SecretManager>>,
method: WalletMethod,
) -> crate::Result<Response> {
let response = match method {
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions bindings/nodejs/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -17,7 +17,7 @@ use tokio::sync::RwLock;

use crate::{client::ClientMethodHandler, secret_manager::SecretManagerMethodHandler, NodejsError};

pub type WalletMethodHandler = Arc<RwLock<Option<Wallet<SecretManager>>>>;
pub type WalletMethodHandler = Arc<RwLock<Option<Wallet<SecretData<SecretManager>>>>>;

#[napi(js_name = "createWallet")]
pub async fn create_wallet(options: String) -> Result<External<WalletMethodHandler>> {
Expand Down Expand Up @@ -100,7 +100,7 @@ pub async fn get_client(wallet: External<WalletMethodHandler>) -> Result<Externa
#[napi(js_name = "getSecretManager")]
pub async fn get_secret_manager(wallet: External<WalletMethodHandler>) -> Result<External<SecretManagerMethodHandler>> {
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,
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub fn get_secret_manager_from_wallet(wallet: &Wallet) -> Result<SecretManager>
.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()))
Expand Down
5 changes: 3 additions & 2 deletions bindings/wasm/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use iota_sdk_bindings_core::{
iota_sdk::{
client::secret::SecretManager,
wallet::{
core::SecretData,
events::types::{WalletEvent, WalletEventType},
Wallet,
},
Expand All @@ -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<Mutex<Option<Wallet<SecretManager>>>>,
wallet: Arc<Mutex<Option<Wallet<SecretData<SecretManager>>>>>,
}

/// Creates a method handler with the given options.
Expand Down Expand Up @@ -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 })
Expand Down
8 changes: 4 additions & 4 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use iota_sdk::{
},
crypto::keys::bip44::Bip44,
types::block::address::Bech32Address,
wallet::ClientOptions,
wallet::{ClientOptions, WalletBuilder},
};
use log::LevelFilter;

Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -332,7 +332,7 @@ pub async fn node_info_command(storage_path: &Path) -> Result<Wallet, Error> {
pub async fn restore_command(storage_path: &Path, snapshot_path: &Path, backup_path: &Path) -> Result<Wallet, Error> {
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:",
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ 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::{
cli::{new_wallet, Cli},
error::Error,
};

pub type Wallet = iota_sdk::wallet::Wallet<StrongholdSecretManager>;
pub type Wallet = iota_sdk::wallet::Wallet<SecretData<StrongholdSecretManager>>;

#[macro_export]
macro_rules! println_log_info {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/wallet_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
3 changes: 2 additions & 1 deletion sdk/examples/how_tos/account/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand All @@ -24,6 +24,7 @@ async fn main() -> Result<()> {
}

let wallet = Wallet::builder()
.with_secret_type::<SecretManager>()
.with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap())
.finish()
.await?;
Expand Down
3 changes: 2 additions & 1 deletion sdk/examples/how_tos/account/destroy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
//! 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<()> {
// This example uses secrets in environment variables for simplicity which should not be done in production.
dotenvy::dotenv().ok();

let wallet = Wallet::builder()
.with_secret_type::<SecretManager>()
.with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap())
.finish()
.await?;
Expand Down
4 changes: 2 additions & 2 deletions sdk/examples/how_tos/account/implicit_account_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion sdk/examples/how_tos/account_wallet/request_funds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -26,6 +26,7 @@ async fn main() -> Result<()> {

// Create the wallet
let wallet = Wallet::builder()
.with_secret_type::<SecretManager>()
.with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap())
.finish()
.await?;
Expand Down
6 changes: 5 additions & 1 deletion sdk/examples/how_tos/account_wallet/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -32,6 +35,7 @@ async fn main() -> Result<()> {

// Create the wallet
let wallet = Wallet::builder()
.with_secret_type::<SecretManager>()
.with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap())
.finish()
.await?;
Expand Down
3 changes: 2 additions & 1 deletion sdk/examples/how_tos/accounts_and_addresses/check_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand All @@ -23,6 +23,7 @@ async fn main() -> Result<()> {
}

let wallet = Wallet::builder()
.with_secret_type::<SecretManager>()
.with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap())
.finish()
.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//! ```
use iota_sdk::{
client::secret::SecretManager,
types::block::address::ToBech32Ext,
wallet::{ConsolidationParams, Result},
Wallet,
Expand All @@ -30,6 +31,7 @@ async fn main() -> Result<()> {
}

let wallet = Wallet::builder()
.with_secret_type::<SecretManager>()
.with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap())
.finish()
.await?;
Expand Down
4 changes: 2 additions & 2 deletions sdk/examples/how_tos/accounts_and_addresses/create_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion sdk/examples/how_tos/accounts_and_addresses/list_outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand All @@ -21,6 +21,7 @@ async fn main() -> Result<()> {
}

let wallet = Wallet::builder()
.with_secret_type::<SecretManager>()
.with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap())
.finish()
.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//! ```
use iota_sdk::{
client::secret::SecretManager,
wallet::{Result, SyncOptions},
Wallet,
};
Expand All @@ -24,6 +25,7 @@ async fn main() -> Result<()> {
}

let wallet = Wallet::builder()
.with_secret_type::<SecretManager>()
.with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap())
.finish()
.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//! `cargo run --release --all-features --example advanced_transaction`
use iota_sdk::{
client::secret::SecretManager,
types::block::{
address::Bech32Address,
output::{
Expand All @@ -31,6 +32,7 @@ async fn main() -> Result<()> {

// Get the wallet we generated with `create_wallet`.
let wallet = Wallet::builder()
.with_secret_type::<SecretManager>()
.with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap())
.finish()
.await?;
Expand Down
Loading

0 comments on commit 8eebdef

Please sign in to comment.