-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add query wallet subcommand and query wallet balancer CLI * Add TODO to correctly parse ibc denom from str
- Loading branch information
Showing
7 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
crates/cli/cli-components/src/impls/commands/queries/balance.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use core::fmt::Display; | ||
use core::marker::PhantomData; | ||
|
||
use cgp::prelude::*; | ||
use hermes_relayer_components::build::traits::builders::chain_builder::CanBuildChain; | ||
use hermes_relayer_components::chain::traits::types::chain_id::HasChainIdType; | ||
use hermes_relayer_components::multi::types::index::Index; | ||
use hermes_test_components::chain::traits::queries::balance::CanQueryBalance; | ||
|
||
use crate::traits::build::CanLoadBuilder; | ||
use crate::traits::command::CommandRunner; | ||
use crate::traits::output::CanProduceOutput; | ||
use crate::traits::parse::CanParseArg; | ||
|
||
pub struct RunQueryBalanceCommand; | ||
|
||
#[derive(Debug, clap::Parser, HasField)] | ||
pub struct QueryBalanceArgs { | ||
#[clap( | ||
long = "chain", | ||
required = true, | ||
value_name = "CHAIN_ID", | ||
help_heading = "REQUIRED", | ||
help = "Identifier of the chain to query" | ||
)] | ||
chain_id: String, | ||
|
||
#[clap( | ||
long = "address", | ||
required = true, | ||
value_name = "ADDRESS", | ||
help_heading = "REQUIRED", | ||
help = "Wallet address to query for balance" | ||
)] | ||
address: String, | ||
|
||
#[clap( | ||
long = "denom", | ||
required = true, | ||
value_name = "DENOM", | ||
help_heading = "REQUIRED", | ||
help = "Token denom queried" | ||
)] | ||
denom: String, | ||
} | ||
|
||
impl<App, Args, Build, Chain> CommandRunner<App, Args> for RunQueryBalanceCommand | ||
where | ||
App: CanLoadBuilder<Builder = Build> | ||
+ CanProduceOutput<Chain::Amount> | ||
+ CanParseArg<Args, symbol!("chain_id"), Parsed = Chain::ChainId> | ||
+ CanParseArg<Args, symbol!("address"), Parsed = Chain::Address> | ||
+ CanParseArg<Args, symbol!("denom"), Parsed = Chain::Denom> | ||
+ CanRaiseError<Build::Error> | ||
+ CanRaiseError<Chain::Error>, | ||
Build: CanBuildChain<Index<0>, Chain = Chain>, | ||
Chain: HasChainIdType + CanQueryBalance, | ||
Args: Async, | ||
Chain::Amount: Display, | ||
{ | ||
async fn run_command(app: &App, args: &Args) -> Result<App::Output, App::Error> { | ||
let chain_id = app.parse_arg(args, PhantomData::<symbol!("chain_id")>)?; | ||
let address = app.parse_arg(args, PhantomData::<symbol!("address")>)?; | ||
let denom = app.parse_arg(args, PhantomData::<symbol!("denom")>)?; | ||
|
||
let builder = app.load_builder().await?; | ||
|
||
let chain = builder | ||
.build_chain(PhantomData, &chain_id) | ||
.await | ||
.map_err(App::raise_error)?; | ||
|
||
let balance = chain | ||
.query_balance(&address, &denom) | ||
.await | ||
.map_err(App::raise_error)?; | ||
|
||
Ok(app.produce_output(balance)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
crates/cli/cli-components/src/impls/commands/queries/wallet.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::impls::commands::queries::balance::QueryBalanceArgs; | ||
use crate::traits::command::{CanRunCommand, CommandRunner}; | ||
|
||
pub struct RunQueryWalletSubCommand; | ||
|
||
#[derive(Debug, clap::Subcommand)] | ||
pub enum QueryWalletSubCommand { | ||
/// Query wallet balance | ||
Balance(QueryBalanceArgs), | ||
} | ||
|
||
impl<App> CommandRunner<App, QueryWalletSubCommand> for RunQueryWalletSubCommand | ||
where | ||
App: CanRunCommand<QueryBalanceArgs>, | ||
{ | ||
async fn run_command( | ||
app: &App, | ||
subcommand: &QueryWalletSubCommand, | ||
) -> Result<App::Output, App::Error> { | ||
match subcommand { | ||
QueryWalletSubCommand::Balance(args) => app.run_command(args).await, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
crates/cosmos/cosmos-test-components/src/chain/types/amount.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters