From 26e78ee096c60a271da1de4ab229896b053552f2 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 25 Sep 2023 16:07:57 +0200 Subject: [PATCH 1/3] CLI: Sync native token foundries --- cli/src/command/account.rs | 9 +++++++-- sdk/src/wallet/account/types/balance.rs | 14 +++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cli/src/command/account.rs b/cli/src/command/account.rs index 66c869cd73..e882e74384 100644 --- a/cli/src/command/account.rs +++ b/cli/src/command/account.rs @@ -21,7 +21,7 @@ use iota_sdk::{ wallet::{ account::{ types::{AccountAddress, AccountIdentifier}, - Account, ConsolidationParams, OutputsToClaim, TransactionOptions, + Account, ConsolidationParams, OutputsToClaim, SyncOptions, TransactionOptions, }, CreateNativeTokenParams, MintNftParams, SendNativeTokensParams, SendNftParams, SendParams, }, @@ -768,7 +768,12 @@ pub async fn send_nft_command( // `sync` command pub async fn sync_command(account: &Account) -> Result<(), Error> { - let balance = account.sync(None).await?; + let balance = account + .sync(Some(SyncOptions { + sync_native_token_foundries: true, + ..Default::default() + })) + .await?; println_log_info!("Synced."); println_log_info!("{balance:#?}"); diff --git a/sdk/src/wallet/account/types/balance.rs b/sdk/src/wallet/account/types/balance.rs index 16571f0235..71b9eafe7f 100644 --- a/sdk/src/wallet/account/types/balance.rs +++ b/sdk/src/wallet/account/types/balance.rs @@ -21,12 +21,12 @@ pub struct Balance { pub(crate) required_storage_deposit: RequiredStorageDeposit, /// Native tokens pub(crate) native_tokens: Vec, - /// Nfts - pub(crate) nfts: Vec, /// Aliases pub(crate) aliases: Vec, /// Foundries pub(crate) foundries: Vec, + /// Nfts + pub(crate) nfts: Vec, /// Outputs with multiple unlock conditions and if they can currently be spent or not. If there is a /// [`TimelockUnlockCondition`](crate::types::block::output::unlock_condition::TimelockUnlockCondition) or /// [`ExpirationUnlockCondition`](crate::types::block::output::unlock_condition::ExpirationUnlockCondition) this @@ -51,9 +51,9 @@ impl std::ops::AddAssign for Balance { } } - self.nfts.extend(rhs.nfts); self.aliases.extend(rhs.aliases); self.foundries.extend(rhs.foundries); + self.nfts.extend(rhs.nfts); } } @@ -88,11 +88,11 @@ impl std::ops::AddAssign for BaseCoinBalance { #[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize, CopyGetters)] #[getset(get_copy = "pub")] pub struct RequiredStorageDeposit { - #[serde(with = "crate::utils::serde::string")] - pub(crate) alias: u64, #[serde(with = "crate::utils::serde::string")] pub(crate) basic: u64, #[serde(with = "crate::utils::serde::string")] + pub(crate) alias: u64, + #[serde(with = "crate::utils::serde::string")] pub(crate) foundry: u64, #[serde(with = "crate::utils::serde::string")] pub(crate) nft: u64, @@ -100,8 +100,8 @@ pub struct RequiredStorageDeposit { impl std::ops::AddAssign for RequiredStorageDeposit { fn add_assign(&mut self, rhs: Self) { - self.alias += rhs.alias; self.basic += rhs.basic; + self.alias += rhs.alias; self.foundry += rhs.foundry; self.nft += rhs.nft; } @@ -205,8 +205,8 @@ impl Balance { voting_power: total / 4, }, required_storage_deposit: RequiredStorageDeposit { - alias: total / 16, basic: total / 8, + alias: total / 16, foundry: total / 4, nft: total / 2, }, From afcea4c8ff8bab267f7196375e6a1454b63cbb3b Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 25 Sep 2023 16:09:18 +0200 Subject: [PATCH 2/3] Changelog --- cli/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 6c0a28cc01..a29478f436 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - UX improvements (Ctrl+l, TAB completion/suggestions and more) during interactive account management; - `WalletCommand::SetPow` command; - Check for existing stronghold on `restore`; +- Sync native token foundries to show their metadata; ### Changed From e7635c5ed8ad075cfc920972a6a185ec88bf6c65 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Mon, 25 Sep 2023 17:03:13 +0200 Subject: [PATCH 3/3] Addresses pretty print --- cli/src/command/account.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/src/command/account.rs b/cli/src/command/account.rs index e882e74384..f5754104f6 100644 --- a/cli/src/command/account.rs +++ b/cli/src/command/account.rs @@ -916,7 +916,7 @@ pub async fn voting_output_command(account: &Account) -> Result<(), Error> { async fn print_address(account: &Account, address: &AccountAddress) -> Result<(), Error> { let mut log = format!( - "Address {}:\n {:<10}{}\n {:<10}{:?}", + "Address: {}\n{:<9}{}\n{:<9}{:?}", address.key_index(), "Bech32:", address.address(), @@ -979,7 +979,7 @@ async fn print_address(account: &Account, address: &AccountAddress) -> Result<() } log = format!( - "{log}\n Outputs: {:#?}\n Base coin amount: {}\n Native Tokens: {:?}\n NFTs: {:?}\n Aliases: {:?}\n Foundries: {:?}\n", + "{log}\nOutputs: {:#?}\nBase coin amount: {}\nNative Tokens: {:#?}\nNFTs: {:#?}\nAliases: {:#?}\nFoundries: {:#?}\n", output_ids, amount, native_tokens.finish_vec()?,