Skip to content

Commit

Permalink
better conversions debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Sep 11, 2024
1 parent 39c940d commit d602c60
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
7 changes: 7 additions & 0 deletions crates/apps_lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3364,6 +3364,7 @@ pub mod args {
pub const DRY_RUN_TX: ArgFlag = flag("dry-run");
pub const DRY_RUN_WRAPPER_TX: ArgFlag = flag("dry-run-wrapper");
pub const DUMP_TX: ArgFlag = flag("dump-tx");
pub const DUMP_CONVERSION_TREE: ArgFlag = flag("dump-conversion-tree");
pub const EPOCH: ArgOpt<Epoch> = arg_opt("epoch");
pub const ERC20: Arg<EthAddress> = arg("erc20");
pub const ETH_CONFIRMATIONS: Arg<u64> = arg("confirmations");
Expand Down Expand Up @@ -6135,6 +6136,7 @@ pub mod args {
query: self.query.to_sdk(ctx)?,
token: self.token.map(|x| ctx.borrow_chain_or_exit().get(&x)),
epoch: self.epoch,
dump_tree: self.dump_tree,
})
}
}
Expand All @@ -6144,10 +6146,12 @@ pub mod args {
let query = Query::parse(matches);
let token = TOKEN_OPT.parse(matches);
let epoch = MASP_EPOCH.parse(matches);
let dump_tree = DUMP_CONVERSION_TREE.parse(matches);
Self {
query,
epoch,
token,
dump_tree,
}
}

Expand All @@ -6159,6 +6163,9 @@ pub mod args {
.arg(TOKEN_OPT.def().help(wrap!(
"The token address for which to query conversions."
)))
.arg(DUMP_CONVERSION_TREE.def().help(wrap!(
"Dumps the full conversion tree if the flag is set."
)))
}
}

Expand Down
9 changes: 7 additions & 2 deletions crates/apps_lib/src/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,7 @@ pub async fn query_conversions(
let total_rewards = rpc::query_masp_total_rewards(context.client())
.await
.expect("MASP total rewards should be present");
display!(
display_line!(
context.io(),
"Total rewards of native token minted for shielded pool: {}",
total_rewards.to_string_native()
Expand All @@ -1900,6 +1900,11 @@ pub async fn query_conversions(
let conversions = rpc::query_conversions(context.client())
.await
.expect("Conversions should be defined");

if args.dump_tree {
display_line!(context.io(), "Conversions: {conversions:?}");
}

// Track whether any non-sentinel conversions are found
let mut conversions_found = false;
for (addr, _denom, digit, epoch, amt) in conversions.values() {
Expand Down Expand Up @@ -1945,7 +1950,7 @@ pub async fn query_conversions(
if !conversions_found {
display_line!(
context.io(),
"No conversions found satisfying specified criteria."
"\nNo conversions found satisfying specified criteria."
);
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/sdk/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,8 @@ pub struct QueryConversions<C: NamadaTypes = SdkTypes> {
pub token: Option<C::Address>,
/// Epoch of the asset
pub epoch: Option<MaspEpoch>,
/// Flag to dump the conversion tree
pub dump_tree: bool,
}

/// Query token balance(s)
Expand Down

0 comments on commit d602c60

Please sign in to comment.