Skip to content

Commit aff4d3c

Browse files
committed
Merge branch 'bat/feature/refactor-cli' (#1738)
* bat/feature/refactor-cli: [feat]: Moved cli commands common to testing, cli, and sdk out into apps
2 parents 1f18bf7 + ca154cd commit aff4d3c

File tree

11 files changed

+820
-229
lines changed

11 files changed

+820
-229
lines changed

apps/src/bin/namada-client/main.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
mod cli;
2-
31
use color_eyre::eyre::Result;
4-
use namada_apps::logging;
2+
use namada_apps::cli::api::CliApi;
3+
use namada_apps::facade::tendermint_rpc::HttpClient;
4+
use namada_apps::{cli, logging};
55
use tracing_subscriber::filter::LevelFilter;
66

77
#[tokio::main]
@@ -13,5 +13,9 @@ async fn main() -> Result<()> {
1313
let _log_guard = logging::init_from_env_or(LevelFilter::INFO)?;
1414

1515
// run the CLI
16-
cli::main().await
16+
CliApi::<()>::handle_client_command::<HttpClient>(
17+
None,
18+
cli::namada_client_cli()?,
19+
)
20+
.await
1721
}

apps/src/bin/namada-relayer/cli.rs

Lines changed: 0 additions & 143 deletions
This file was deleted.
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
mod cli;
2-
31
use color_eyre::eyre::Result;
4-
use namada_apps::logging;
2+
use namada::tendermint_rpc::HttpClient;
3+
use namada_apps::cli::api::CliApi;
4+
use namada_apps::{cli, logging};
55
use tracing_subscriber::filter::LevelFilter;
66

77
#[tokio::main]
@@ -12,6 +12,7 @@ async fn main() -> Result<()> {
1212
// init logging
1313
logging::init_from_env_or(LevelFilter::INFO)?;
1414

15+
let (cmd, _) = cli::namada_relayer_cli()?;
1516
// run the CLI
16-
cli::main().await
17+
CliApi::<()>::handle_relayer_command::<HttpClient>(None, cmd).await
1718
}

apps/src/bin/namada-wallet/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
mod cli;
21
use color_eyre::eyre::Result;
2+
use namada_apps::cli;
3+
use namada_apps::cli::api::CliApi;
34

45
pub fn main() -> Result<()> {
56
color_eyre::install()?;
6-
7+
let (cmd, ctx) = cli::namada_wallet_cli()?;
78
// run the CLI
8-
cli::main()
9+
CliApi::<()>::handle_wallet_command(cmd, ctx)
910
}

apps/src/lib/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
//! client can be dispatched via `namada node ...` or `namada client ...`,
77
//! respectively.
88
9+
pub mod api;
10+
pub mod client;
911
pub mod context;
12+
pub mod relayer;
1013
mod utils;
14+
pub mod wallet;
1115

1216
use clap::{ArgGroup, ArgMatches, ColorChoice};
1317
use color_eyre::eyre::Result;

apps/src/lib/cli/api.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use std::marker::PhantomData;
2+
3+
use namada::ledger::queries::Client;
4+
use namada::ledger::rpc::wait_until_node_is_synched;
5+
use namada::tendermint_rpc::HttpClient;
6+
use namada::types::control_flow::Halt;
7+
use tendermint_config::net::Address as TendermintAddress;
8+
9+
use crate::client::utils;
10+
11+
/// Trait for clients that can be used with the CLI.
12+
#[async_trait::async_trait(?Send)]
13+
pub trait CliClient: Client + Sync {
14+
fn from_tendermint_address(address: &mut TendermintAddress) -> Self;
15+
async fn wait_until_node_is_synced(&self) -> Halt<()>;
16+
}
17+
18+
#[async_trait::async_trait(?Send)]
19+
impl CliClient for HttpClient {
20+
fn from_tendermint_address(address: &mut TendermintAddress) -> Self {
21+
HttpClient::new(utils::take_config_address(address)).unwrap()
22+
}
23+
24+
async fn wait_until_node_is_synced(&self) -> Halt<()> {
25+
wait_until_node_is_synched(self).await
26+
}
27+
}
28+
29+
pub struct CliApi<IO>(PhantomData<IO>);

0 commit comments

Comments
 (0)