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

Query for IBC tokens #1951

Merged
merged 4 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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,11 +6,13 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;

use color_eyre::eyre::Result;
use namada::ledger::ibc::storage::ibc_token;
use namada::sdk::masp::ShieldedContext;
use namada::sdk::wallet::Wallet;
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 @@ -367,6 +369,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