From 3883174145f8b738dfc9f3007ac3e4c2a391df7c Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Tue, 4 Aug 2020 20:54:00 -0700 Subject: [PATCH] Adapt to https://github.com/solana-labs/solana/pull/11370 --- token-cli/src/main.rs | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/token-cli/src/main.rs b/token-cli/src/main.rs index e3161b9500a..4efdfea077f 100644 --- a/token-cli/src/main.rs +++ b/token-cli/src/main.rs @@ -80,10 +80,6 @@ fn ui_amount_to_amount(ui_amount: f64, decimals: u8) -> u64 { (ui_amount * 10_usize.pow(decimals as u32) as f64) as u64 } -fn amount_to_ui_amount(amount: u64, decimals: u8) -> f64 { - amount as f64 / 10_usize.pow(decimals as u32) as f64 -} - fn command_create_token(config: &Config, decimals: u8) -> CommmandResult { let token = Keypair::new(); println!("Creating token {}", token.pubkey()); @@ -408,17 +404,7 @@ fn command_balance(config: &Config, address: Pubkey) -> CommmandResult { .rpc_client .get_token_account_balance_with_commitment(&address, config.commitment_config)? .value; - - let mint = config - .rpc_client - .get_token_account_with_commitment(&address, config.commitment_config)? - .value - .ok_or_else(|| format!("Failed to fetch token account"))? - .mint - .parse::()?; - - let decimals = get_decimals_for_token(config, &mint)?; - println!("{}", amount_to_ui_amount(dbg!(balance), dbg!(decimals))); + println!("{}", balance); Ok(None) } @@ -428,8 +414,7 @@ fn command_supply(config: &Config, address: Pubkey) -> CommmandResult { .get_token_supply_with_commitment(&address, config.commitment_config)? .value; - let decimals = get_decimals_for_token(config, &address)?; - println!("{}", amount_to_ui_amount(supply, decimals)); + println!("{}", supply); Ok(None) } @@ -452,13 +437,15 @@ fn command_accounts(config: &Config, token: Option) -> CommmandResult { println!("Account Token Balance"); println!("-------------------------------------------------------------------------------------------------"); for (address, account) in accounts { - let decimals = get_decimals_for_token(config, &account.mint.parse::()?)?; - println!( - "{:<44} {:<44} {}", - address, - account.mint, - amount_to_ui_amount(account.amount, decimals) - ); + let balance = match config + .rpc_client + .get_token_account_balance_with_commitment(&address, config.commitment_config) + { + Ok(response) => response.value.to_string(), + Err(err) => format!("{}", err), + }; + + println!("{:<44} {:<44} {}", address, account.mint, balance); } Ok(None) }