From e24c13ed5f377a10f7dc2481f5b1cb51705cdc44 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Tue, 18 Oct 2022 17:36:11 +0200 Subject: [PATCH] Fix --no-conversions flag --- apps/src/lib/client/rpc.rs | 60 ++++++++++++++++++++++++++------------ apps/src/lib/client/tx.rs | 6 ++-- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/apps/src/lib/client/rpc.rs b/apps/src/lib/client/rpc.rs index 515b322e14..755996fbcb 100644 --- a/apps/src/lib/client/rpc.rs +++ b/apps/src/lib/client/rpc.rs @@ -19,6 +19,7 @@ use masp_primitives::merkle_tree::MerklePath; use masp_primitives::primitives::ViewingKey; use masp_primitives::sapling::Node; use masp_primitives::zip32::ExtendedFullViewingKey; +use masp_primitives::transaction::components::Amount; use namada::ledger::governance::parameters::GovParams; use namada::ledger::governance::storage as gov_storage; use namada::ledger::governance::utils::Votes; @@ -162,7 +163,6 @@ pub async fn query_tx_deltas( query_token: &Option
, ) -> BTreeMap<(BlockHeight, TxIndex), (Epoch, TransferDelta, TransactionDelta)> { - use masp_primitives::transaction::components::Amount; const TXS_PER_PAGE: u8 = 100; // Connect to the Tendermint server holding the transactions let client = HttpClient::new(ledger_address.clone()).unwrap(); @@ -1009,7 +1009,6 @@ pub async fn query_shielded_balance( let viewing_key = ExtendedFullViewingKey::from(viewing_keys[0]).fvk.vk; let balance; - let decoded_balance; if no_conversions { balance = ctx .shielded @@ -1018,10 +1017,11 @@ pub async fn query_shielded_balance( ) .expect("context should contain viewing key"); // Print balances by human-readable token names - decoded_balance = ctx + let decoded_balance = ctx .shielded .decode_all_amounts(client.clone(), balance) .await; + print_decoded_balance_with_epoch(decoded_balance); } else { balance = ctx .shielded @@ -1029,29 +1029,53 @@ pub async fn query_shielded_balance( .await .expect("context should contain viewing key"); // Print balances by human-readable token names - decoded_balance = ctx + let decoded_balance = ctx .shielded .decode_amount(client.clone(), balance, epoch) .await; - } - let mut found_any = false; - for (addr, value) in decoded_balance.components() { - let asset_value = token::Amount::from(*value as u64); - let addr_enc = addr.encode(); - println!( - "{}: {}", - tokens.get(addr).cloned().unwrap_or(addr_enc.as_str()), - asset_value - ); - found_any = true; - } - if !found_any { - println!("No shielded balance found for given key"); + print_decoded_balance(decoded_balance); } } } } +pub fn print_decoded_balance(decoded_balance: Amount
) { + let tokens = address::tokens(); + let mut found_any = false; + for (addr, value) in decoded_balance.components() { + let asset_value = token::Amount::from(*value as u64); + let addr_enc = addr.encode(); + println!( + "{} : {}", + tokens.get(addr).cloned().unwrap_or(addr_enc.as_str()), + asset_value + ); + found_any = true; + } + if !found_any { + println!("No shielded balance found for given key"); + } +} + +pub fn print_decoded_balance_with_epoch(decoded_balance: Amount<(Address, Epoch)>) { + let tokens = address::tokens(); + let mut found_any = false; + for ((addr, epoch), value) in decoded_balance.components() { + let asset_value = token::Amount::from(*value as u64); + let addr_enc = addr.encode(); + println!( + "{} | {} : {}", + tokens.get(addr).cloned().unwrap_or(addr_enc.as_str()), + epoch, + asset_value + ); + found_any = true; + } + if !found_any { + println!("No shielded balance found for given key"); + } +} + /// Query token amount of owner. pub async fn get_token_balance( client: &HttpClient, diff --git a/apps/src/lib/client/tx.rs b/apps/src/lib/client/tx.rs index 824dabc0a1..8ab639e42f 100644 --- a/apps/src/lib/client/tx.rs +++ b/apps/src/lib/client/tx.rs @@ -1280,7 +1280,7 @@ impl ShieldedContext { &mut self, client: HttpClient, amt: Amount, - ) -> Amount
{ + ) -> Amount<(Address, Epoch)> { let mut res = Amount::zero(); for (asset_type, val) in amt.components() { // Decode the asset type @@ -1288,8 +1288,8 @@ impl ShieldedContext { self.decode_asset_type(client.clone(), *asset_type).await; // Only assets with the target timestamp count match decoded { - Some((addr, _)) => { - res += &Amount::from_pair(addr, *val).unwrap() + Some((addr, epoch)) => { + res += &Amount::from_pair((addr, epoch), *val).unwrap() } _ => {} }