Skip to content

Commit

Permalink
Merge branch 'yuji/ibc-token-query' (#2729)
Browse files Browse the repository at this point in the history
* origin/yuji/ibc-token-query:
  specify token addr to query_tokens
  fix e2e test
  fix balance query
  add changelog
  ibc token query

# Conflicts:
#	crates/apps/src/lib/client/rpc.rs
#	crates/sdk/src/wallet/mod.rs
  • Loading branch information
tzemanovic committed Apr 11, 2024
2 parents 4d53cee + 76c3849 commit 134be07
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 92 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/SDK/2729-ibc-token-query.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- move query_ibc_tokens and lookup_ibc_token_alias to sdk
([\#2729](https://github.com/anoma/namada/issues/2729))
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/2809-ibc-token-query.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fix the balance query not to show ibc tokens as default
([\#2809](https://github.com/anoma/namada/issues/2809))
2 changes: 2 additions & 0 deletions .changelog/unreleased/features/2729-ibc-token-query.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add ibc-token command to get a list of IBC tokens
([\#2729](https://github.com/anoma/namada/issues/2729))
67 changes: 67 additions & 0 deletions crates/apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ pub mod cmds {
.subcommand(QueryMaspRewardTokens::def().display_order(5))
.subcommand(QueryBlock::def().display_order(5))
.subcommand(QueryBalance::def().display_order(5))
.subcommand(QueryIbcToken::def().display_order(5))
.subcommand(QueryBonds::def().display_order(5))
.subcommand(QueryBondedStake::def().display_order(5))
.subcommand(QuerySlashes::def().display_order(5))
Expand Down Expand Up @@ -324,6 +325,7 @@ pub mod cmds {
Self::parse_with_ctx(matches, QueryMaspRewardTokens);
let query_block = Self::parse_with_ctx(matches, QueryBlock);
let query_balance = Self::parse_with_ctx(matches, QueryBalance);
let query_ibc_token = Self::parse_with_ctx(matches, QueryIbcToken);
let query_bonds = Self::parse_with_ctx(matches, QueryBonds);
let query_bonded_stake =
Self::parse_with_ctx(matches, QueryBondedStake);
Expand Down Expand Up @@ -385,6 +387,7 @@ pub mod cmds {
.or(query_masp_reward_tokens)
.or(query_block)
.or(query_balance)
.or(query_ibc_token)
.or(query_bonds)
.or(query_bonded_stake)
.or(query_slashes)
Expand Down Expand Up @@ -475,6 +478,7 @@ pub mod cmds {
QueryMaspRewardTokens(QueryMaspRewardTokens),
QueryBlock(QueryBlock),
QueryBalance(QueryBalance),
QueryIbcToken(QueryIbcToken),
QueryBonds(QueryBonds),
QueryBondedStake(QueryBondedStake),
QueryCommissionRate(QueryCommissionRate),
Expand Down Expand Up @@ -1718,6 +1722,25 @@ pub mod cmds {
}
}

#[derive(Clone, Debug)]
pub struct QueryIbcToken(pub args::QueryIbcToken<args::CliTypes>);

impl SubCmd for QueryIbcToken {
const CMD: &'static str = "ibc-token";

fn parse(matches: &ArgMatches) -> Option<Self> {
matches.subcommand_matches(Self::CMD).map(|matches| {
QueryIbcToken(args::QueryIbcToken::parse(matches))
})
}

fn def() -> App {
App::new(Self::CMD)
.about("Query IBC token(s).")
.add_args::<args::QueryIbcToken<args::CliTypes>>()
}
}

#[derive(Clone, Debug)]
pub struct QueryBonds(pub args::QueryBonds<args::CliTypes>);

Expand Down Expand Up @@ -3224,6 +3247,7 @@ pub mod args {
arg("self-bond-amount");
pub const SENDER: Arg<String> = arg("sender");
pub const SHIELDED: ArgFlag = flag("shielded");
pub const SHOW_IBC_TOKENS: ArgFlag = flag("show-ibc-tokens");
pub const SIGNER: ArgOpt<WalletAddress> = arg_opt("signer");
pub const SIGNING_KEYS: ArgMulti<WalletPublicKey, GlobStar> =
arg_multi("signing-keys");
Expand All @@ -3241,6 +3265,7 @@ pub mod args {
pub const TIMEOUT_SEC_OFFSET: ArgOpt<u64> = arg_opt("timeout-sec-offset");
pub const TM_ADDRESS: ArgOpt<String> = arg_opt("tm-address");
pub const TOKEN_OPT: ArgOpt<WalletAddress> = TOKEN.opt();
pub const TOKEN_STR_OPT: ArgOpt<String> = TOKEN_STR.opt();
pub const TOKEN: Arg<WalletAddress> = arg("token");
pub const TOKEN_STR: Arg<String> = arg("token");
pub const TRANSFER_SOURCE: Arg<WalletTransferSource> = arg("source");
Expand Down Expand Up @@ -5294,6 +5319,7 @@ pub mod args {
owner: self.owner.map(|x| chain_ctx.get_cached(&x)),
token: self.token.map(|x| chain_ctx.get(&x)),
no_conversions: self.no_conversions,
show_ibc_tokens: self.show_ibc_tokens,
}
}
}
Expand All @@ -5304,11 +5330,13 @@ pub mod args {
let owner = BALANCE_OWNER.parse(matches);
let token = TOKEN_OPT.parse(matches);
let no_conversions = NO_CONVERSIONS.parse(matches);
let show_ibc_tokens = SHOW_IBC_TOKENS.parse(matches);
Self {
query,
owner,
token,
no_conversions,
show_ibc_tokens,
}
}

Expand All @@ -5329,6 +5357,45 @@ pub mod args {
"Whether not to automatically perform conversions.",
),
)
.arg(SHOW_IBC_TOKENS.def().help(
"Show IBC tokens. When the given token is an IBC denom, \
IBC tokens will be shown even if this flag is false.",
))
}
}

impl CliToSdk<QueryIbcToken<SdkTypes>> for QueryIbcToken<CliTypes> {
fn to_sdk(self, ctx: &mut Context) -> QueryIbcToken<SdkTypes> {
let query = self.query.to_sdk(ctx);
let chain_ctx = ctx.borrow_mut_chain_or_exit();
QueryIbcToken::<SdkTypes> {
query,
token: self.token,
owner: self.owner.map(|x| chain_ctx.get_cached(&x)),
}
}
}

impl Args for QueryIbcToken<CliTypes> {
fn parse(matches: &ArgMatches) -> Self {
let query = Query::parse(matches);
let token = TOKEN_STR_OPT.parse(matches);
let owner = BALANCE_OWNER.parse(matches);
Self {
query,
owner,
token,
}
}

fn def(app: App) -> App {
app.add_args::<Query<CliTypes>>()
.arg(TOKEN_STR_OPT.def().help("The base token to query."))
.arg(
BALANCE_OWNER
.def()
.help("The account address whose token to query."),
)
}
}

Expand Down
12 changes: 12 additions & 0 deletions crates/apps/src/lib/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,18 @@ impl CliApi {
let namada = ctx.to_sdk(client, io);
rpc::query_balance(&namada, args).await;
}
Sub::QueryIbcToken(QueryIbcToken(args)) => {
let chain_ctx = ctx.borrow_mut_chain_or_exit();
let ledger_address =
chain_ctx.get(&args.query.ledger_address);
let client = client.unwrap_or_else(|| {
C::from_tendermint_address(&ledger_address)
});
client.wait_until_node_is_synced(&io).await?;
let args = args.to_sdk(&mut ctx);
let namada = ctx.to_sdk(client, io);
rpc::query_ibc_tokens(&namada, args).await;
}
Sub::QueryBonds(QueryBonds(args)) => {
let chain_ctx = ctx.borrow_mut_chain_or_exit();
let ledger_address =
Expand Down
Loading

0 comments on commit 134be07

Please sign in to comment.