Skip to content

Commit

Permalink
Merge branch 'yuji/ibc-balance-query' (#1951)
Browse files Browse the repository at this point in the history
* origin/yuji/ibc-balance-query:
  remove trace-path
  add changelog
  query balances for IbcToken
  transfer and query with trace-path
  • Loading branch information
tzemanovic committed Oct 24, 2023
2 parents 7ffbf56 + b874ffa commit ed3cb64
Show file tree
Hide file tree
Showing 13 changed files with 495 additions and 269 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/1946-ibc-balance-query.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Query also IBC token balances
([\#1946](https://github.com/anoma/namada/issues/1946))
16 changes: 16 additions & 0 deletions apps/src/lib/cli/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;

use color_eyre::eyre::Result;
use namada::ledger::ibc::storage::ibc_token;
use namada::types::address::{Address, InternalAddress};
use namada::types::chain::ChainId;
use namada::types::ethereum_events::EthAddress;
use namada::types::ibc::is_ibc_denom;
use namada::types::io::Io;
use namada::types::key::*;
use namada::types::masp::*;
Expand Down Expand Up @@ -387,6 +389,20 @@ impl ArgFromContext for Address {
})
.unwrap_or(Err(Skip))
})
// An IBC token
.or_else(|_| {
is_ibc_denom(raw)
.map(|(trace_path, base_denom)| {
let base_token = ctx
.wallet
.find_address(&base_denom)
.map(|addr| addr.to_string())
.unwrap_or(base_denom);
let ibc_denom = format!("{trace_path}/{base_token}");
ibc_token(ibc_denom)
})
.ok_or(Skip)
})
// Or it can be an alias that may be found in the wallet
.or_else(|_| ctx.wallet.find_address(raw).cloned().ok_or(Skip))
.map_err(|_| format!("Unknown address {raw}"))
Expand Down
Loading

0 comments on commit ed3cb64

Please sign in to comment.