Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Sync native token foundries #1318

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 7 additions & 2 deletions cli/src/command/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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:#?}");

Expand Down
14 changes: 7 additions & 7 deletions sdk/src/wallet/account/types/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ pub struct Balance {
pub(crate) required_storage_deposit: RequiredStorageDeposit,
/// Native tokens
pub(crate) native_tokens: Vec<NativeTokensBalance>,
/// Nfts
pub(crate) nfts: Vec<NftId>,
/// Aliases
pub(crate) aliases: Vec<AliasId>,
/// Foundries
pub(crate) foundries: Vec<FoundryId>,
/// Nfts
pub(crate) nfts: Vec<NftId>,
/// 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
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -88,20 +88,20 @@ 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,
}

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;
}
Expand Down Expand Up @@ -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,
},
Expand Down
Loading