Skip to content

Commit

Permalink
[feat]: Made sdk and client io generic
Browse files Browse the repository at this point in the history
  • Loading branch information
batconjurer committed Jul 21, 2023
1 parent ca154cd commit d618365
Show file tree
Hide file tree
Showing 23 changed files with 1,813 additions and 932 deletions.
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 @@ pub use utils::safe_exit;
use utils::*;

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

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

Expand Down Expand Up @@ -5044,7 +5045,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
12 changes: 8 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,12 @@ 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;
impl Io for CliIo {}

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

0 comments on commit d618365

Please sign in to comment.