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

Generic IO #1746

Merged
merged 12 commits into from
Sep 25, 2023
2 changes: 2 additions & 0 deletions .changelog/unreleased/features/1746-generic-io.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Replaced standard IO in SDK and client code with a trait that allows custom
handling. ([\#1746](https://github.com/anoma/namada/pull/1746))
4 changes: 2 additions & 2 deletions apps/src/bin/namada-client/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use color_eyre::eyre::Result;
use namada_apps::cli::api::CliApi;
use namada_apps::cli::api::{CliApi, CliIo};
use namada_apps::facade::tendermint_rpc::HttpClient;
use namada_apps::{cli, logging};
use tracing_subscriber::filter::LevelFilter;
Expand All @@ -13,7 +13,7 @@ async fn main() -> Result<()> {
let _log_guard = logging::init_from_env_or(LevelFilter::INFO)?;

// run the CLI
CliApi::<()>::handle_client_command::<HttpClient>(
CliApi::<CliIo>::handle_client_command::<HttpClient>(
None,
cli::namada_client_cli()?,
)
Expand Down
4 changes: 2 additions & 2 deletions apps/src/bin/namada-relayer/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use color_eyre::eyre::Result;
use namada::tendermint_rpc::HttpClient;
use namada_apps::cli::api::CliApi;
use namada_apps::cli::api::{CliApi, CliIo};
use namada_apps::{cli, logging};
use tracing_subscriber::filter::LevelFilter;

Expand All @@ -14,5 +14,5 @@ async fn main() -> Result<()> {

let (cmd, _) = cli::namada_relayer_cli()?;
// run the CLI
CliApi::<()>::handle_relayer_command::<HttpClient>(None, cmd).await
CliApi::<CliIo>::handle_relayer_command::<HttpClient>(None, cmd).await
}
4 changes: 2 additions & 2 deletions apps/src/bin/namada-wallet/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use color_eyre::eyre::Result;
use namada_apps::cli;
use namada_apps::cli::api::CliApi;
use namada_apps::cli::api::{CliApi, CliIo};

pub fn main() -> Result<()> {
color_eyre::install()?;
let (cmd, ctx) = cli::namada_wallet_cli()?;
// run the CLI
CliApi::<()>::handle_wallet_command(cmd, ctx)
CliApi::<CliIo>::handle_wallet_command(cmd, ctx)
}
3 changes: 2 additions & 1 deletion apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use utils::*;
pub use utils::{dispatch_prompt, safe_exit, Cmd, TESTIN};

pub use self::context::Context;
use crate::cli::api::CliIo;

include!("../../version.rs");

Expand Down Expand Up @@ -5128,7 +5129,7 @@ pub fn namada_client_cli() -> Result<NamadaClient> {
let global_args = args::Global::parse(&matches);
match cmd {
cmds::NamadaClient::WithContext(sub_cmd) => {
let context = Context::new(global_args)?;
let context = Context::new::<CliIo>(global_args)?;
Ok(NamadaClient::WithContext(Box::new((sub_cmd, context))))
}
cmds::NamadaClient::WithoutContext(sub_cmd) => {
Expand Down
14 changes: 10 additions & 4 deletions apps/src/lib/cli/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use namada::ledger::queries::Client;
use namada::ledger::rpc::wait_until_node_is_synched;
use namada::tendermint_rpc::HttpClient;
use namada::types::control_flow::Halt;
use namada::types::io::Io;
use tendermint_config::net::Address as TendermintAddress;

use crate::client::utils;
Expand All @@ -12,7 +13,7 @@ use crate::client::utils;
#[async_trait::async_trait(?Send)]
pub trait CliClient: Client + Sync {
fn from_tendermint_address(address: &mut TendermintAddress) -> Self;
async fn wait_until_node_is_synced(&self) -> Halt<()>;
async fn wait_until_node_is_synced<IO: Io>(&self) -> Halt<()>;
}

#[async_trait::async_trait(?Send)]
Expand All @@ -21,9 +22,14 @@ impl CliClient for HttpClient {
HttpClient::new(utils::take_config_address(address)).unwrap()
}

async fn wait_until_node_is_synced(&self) -> Halt<()> {
wait_until_node_is_synched(self).await
async fn wait_until_node_is_synced<IO: Io>(&self) -> Halt<()> {
wait_until_node_is_synched::<_, IO>(self).await
}
}

pub struct CliApi<IO>(PhantomData<IO>);
pub struct CliIo;

#[async_trait::async_trait(?Send)]
impl Io for CliIo {}

pub struct CliApi<IO: Io = CliIo>(PhantomData<IO>);
Loading