From ac8255e3ce5b5ec9212aa514dc4da491eda8883c Mon Sep 17 00:00:00 2001 From: Alexander Schmidt Date: Mon, 30 Oct 2023 15:25:36 +0100 Subject: [PATCH] remove remaining account mentioning in prints --- sdk/examples/how_tos/native_tokens/create.rs | 4 +- .../nft_collection/01_mint_collection_nft.rs | 2 +- sdk/examples/wallet/participation.rs | 12 +- sdk/examples/wallet/spammer.rs | 4 +- sdk/examples/wallet/split_funds.rs | 131 ------------------ sdk/examples/wallet/wallet.rs | 2 +- 6 files changed, 12 insertions(+), 143 deletions(-) delete mode 100644 sdk/examples/wallet/split_funds.rs diff --git a/sdk/examples/how_tos/native_tokens/create.rs b/sdk/examples/how_tos/native_tokens/create.rs index 1da59a0e4b..994b3cb379 100644 --- a/sdk/examples/how_tos/native_tokens/create.rs +++ b/sdk/examples/how_tos/native_tokens/create.rs @@ -57,7 +57,7 @@ async fn main() -> Result<()> { ); wallet.sync(None).await?; - println!("Account synced"); + println!("Wallet synced"); } let metadata = @@ -88,7 +88,7 @@ async fn main() -> Result<()> { // Ensure the account is synced after creating the native token. wallet.sync(None).await?; - println!("Account synced"); + println!("Wallet synced"); Ok(()) } 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 5e323ccada..4592ea1acc 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 @@ -45,7 +45,7 @@ async fn main() -> Result<()> { .await?; wallet.sync(None).await?; - println!("Account synced!"); + println!("Wallet synced!"); // Set the stronghold password wallet diff --git a/sdk/examples/wallet/participation.rs b/sdk/examples/wallet/participation.rs index 9f55b913ce..810d1f4b9b 100644 --- a/sdk/examples/wallet/participation.rs +++ b/sdk/examples/wallet/participation.rs @@ -119,7 +119,7 @@ async fn main() -> Result<()> { } let balance = wallet.sync(None).await?; - println!("Account synced"); + println!("Wallet synced"); //////////////////////////////////////////////// // create voting output or increase voting power @@ -142,7 +142,7 @@ async fn main() -> Result<()> { ); let balance = wallet.sync(None).await?; - println!("Account synced"); + println!("Wallet synced"); println!("New voting power: {}", balance.base_coin().voting_power()); let voting_output = wallet.get_voting_output().await?.unwrap(); @@ -167,7 +167,7 @@ async fn main() -> Result<()> { ); let balance = wallet.sync(None).await?; - println!("Account synced"); + println!("Wallet synced"); println!("New voting power: {}", balance.base_coin().voting_power()); //////////////////////////////////////////////// @@ -192,7 +192,7 @@ async fn main() -> Result<()> { ); wallet.sync(None).await?; - println!("Account synced"); + println!("Wallet synced"); //////////////////////////////////////////////// // get voting overview @@ -219,7 +219,7 @@ async fn main() -> Result<()> { ); wallet.sync(None).await?; - println!("Account synced"); + println!("Wallet synced"); //////////////////////////////////////////////// // destroy voting output @@ -243,7 +243,7 @@ async fn main() -> Result<()> { ); wallet.sync(None).await?; - println!("Account synced"); + println!("Wallet synced"); assert!(wallet.get_voting_output().await.is_err()); diff --git a/sdk/examples/wallet/spammer.rs b/sdk/examples/wallet/spammer.rs index 7d6d3ded54..92530c285a 100644 --- a/sdk/examples/wallet/spammer.rs +++ b/sdk/examples/wallet/spammer.rs @@ -138,13 +138,13 @@ async fn main() -> Result<()> { if error_state.is_err() { // Sync when getting an error, because that's probably when no outputs are available anymore let mut balance = wallet.sync(None).await?; - println!("Account synced"); + println!("Wallet synced"); while balance.base_coin().available() == 0 { println!("No funds available"); tokio::time::sleep(std::time::Duration::from_secs(2)).await; balance = wallet.sync(None).await?; - println!("Account synced"); + println!("Wallet synced"); } } diff --git a/sdk/examples/wallet/split_funds.rs b/sdk/examples/wallet/split_funds.rs deleted file mode 100644 index 49f3be624d..0000000000 --- a/sdk/examples/wallet/split_funds.rs +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright 2021 IOTA Stiftung -// SPDX-License-Identifier: Apache-2.0 - -//! In this example we will split funds among a pre-defined number of addresses. -//! -//! Make sure there's no folder yet at `WALLET_DB_PATH`. -//! For this example it's best to use a fresh mnemonic and start with a balance on the first address only. -//! -//! Rename `.env.example` to `.env` first, then run the command: -//! ```sh -//! cargo run --release --all-features --example split_funds -//! ``` - -use iota_sdk::{ - client::{ - constants::SHIMMER_COIN_TYPE, - secret::{mnemonic::MnemonicSecretManager, SecretManager}, - }, - types::block::output::{unlock_condition::AddressUnlockCondition, BasicOutputBuilder}, - wallet::{account::types::Bip44Address, Account, ClientOptions, Result, Wallet}, -}; - -// The base coin amount to send -const SEND_AMOUNT: u64 = 1_000_000; -// The number of addresses funds are distributed to -const ADDRESSES_TO_SPLIT_FUNDS: usize = 15; - -#[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 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() - .with_secret_manager(SecretManager::Mnemonic(secret_manager)) - .with_storage_path(&std::env::var("WALLET_DB_PATH").unwrap()) - .with_client_options(client_options) - .with_coin_type(SHIMMER_COIN_TYPE) - .finish() - .await?; - - // Get account or create a new one - let account = wallet.get_or_create_account("Alice").await?; - - let _ = ensure_enough_addresses(&account, ADDRESSES_TO_SPLIT_FUNDS).await?; - - let addresses = account.addresses().await; - println!("Total address count: {}", addresses.len()); - - sync_print_balance(&account).await?; - - let addresses_with_unspent_outputs = account.addresses_with_unspent_outputs().await?; - println!( - "Addresses with balance count (before): {}", - addresses_with_unspent_outputs.len() - ); - - let token_supply = account.client().get_token_supply().await?; - - // Send split transactions - for addresses_chunk in addresses.chunks(2).map(|chunk| chunk.to_vec()) { - let outputs_per_transaction = addresses_chunk - .into_iter() - .map(|a| { - BasicOutputBuilder::new_with_amount(SEND_AMOUNT) - .add_unlock_condition(AddressUnlockCondition::new(a.address())) - .finish_output(token_supply) - .unwrap() - }) - .collect::>(); - - println!( - "Sending '{}' coins in {} outputs...", - SEND_AMOUNT, - outputs_per_transaction.len() - ); - let transaction = account.send_outputs(outputs_per_transaction, None).await?; - println!( - "Transaction sent: {}/transaction/{}", - std::env::var("EXPLORER_URL").unwrap(), - transaction.transaction_id - ); - - // Wait for transaction to get included - let block_id = account - .reissue_transaction_until_included(&transaction.transaction_id, None, None) - .await?; - - println!( - "Block included: {}/block/{}", - std::env::var("EXPLORER_URL").unwrap(), - block_id - ); - } - - sync_print_balance(&account).await?; - - let addresses_with_unspent_outputs = account.addresses_with_unspent_outputs().await?; - println!( - "Addresses with balance count (after): {}", - addresses_with_unspent_outputs.len() - ); - - println!("Example finished successfully"); - - Ok(()) -} - -async fn sync_print_balance(account: &Account) -> Result<()> { - let alias = account.alias().await; - let now = tokio::time::Instant::now(); - let balance = account.sync(None).await?; - println!("{alias}'s account synced in: {:.2?}", now.elapsed()); - println!("{alias}'s balance:\n{:#?}", balance.base_coin()); - Ok(()) -} - -async fn ensure_enough_addresses(account: &Account, limit: usize) -> Result> { - let alias = account.alias().await; - if account.addresses().await.len() < limit { - let num_addresses_to_generate = limit - account.addresses().await.len(); - println!("Generating {num_addresses_to_generate} addresses for account '{alias}'..."); - account - .generate_ed25519_addresses(num_addresses_to_generate as u32, None) - .await?; - } - Ok(account.addresses().await) -} diff --git a/sdk/examples/wallet/wallet.rs b/sdk/examples/wallet/wallet.rs index 844a9837ed..66ef70eaaf 100644 --- a/sdk/examples/wallet/wallet.rs +++ b/sdk/examples/wallet/wallet.rs @@ -70,7 +70,7 @@ async fn sync_print_balance(wallet: &Wallet, full_report: bool) -> Result<()> { let alias = wallet.alias().await; let now = tokio::time::Instant::now(); let balance = wallet.sync(None).await?; - println!("{alias}'s account synced in: {:.2?}", now.elapsed()); + println!("{alias}'s wallet synced in: {:.2?}", now.elapsed()); if full_report { println!("{alias}'s balance:\n{balance:#?}"); } else {