Skip to content

Commit

Permalink
Reintegrated generic IO support.
Browse files Browse the repository at this point in the history
  • Loading branch information
murisi committed Oct 6, 2023
1 parent 9f06a4b commit 0572aa3
Show file tree
Hide file tree
Showing 26 changed files with 1,767 additions and 1,821 deletions.
1 change: 1 addition & 0 deletions apps/src/bin/namada-client/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ async fn main() -> Result<()> {
CliApi::<CliIo>::handle_client_command::<HttpClient>(
None,
cli::namada_client_cli()?,
&CliIo,
)
.await
}
3 changes: 2 additions & 1 deletion apps/src/bin/namada-relayer/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ async fn main() -> Result<()> {

let cmd = cli::namada_relayer_cli()?;
// run the CLI
CliApi::<CliIo>::handle_relayer_command::<HttpClient>(None, cmd).await
CliApi::<CliIo>::handle_relayer_command::<HttpClient>(None, cmd, &CliIo)
.await
}
2 changes: 1 addition & 1 deletion apps/src/bin/namada-wallet/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ pub fn main() -> Result<()> {
color_eyre::install()?;
let (cmd, ctx) = cli::namada_wallet_cli()?;
// run the CLI
CliApi::<CliIo>::handle_wallet_command(cmd, ctx)
CliApi::<CliIo>::handle_wallet_command(cmd, ctx, &CliIo)
}
1 change: 1 addition & 0 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2534,6 +2534,7 @@ pub mod args {
use super::context::*;
use super::utils::*;
use super::{ArgGroup, ArgMatches};
use crate::cli::context::FromContext;
use crate::config::{self, Action, ActionAtHeight};
use crate::facade::tendermint::Timeout;
use crate::facade::tendermint_config::net::Address as TendermintAddress;
Expand Down
6 changes: 3 additions & 3 deletions apps/src/lib/cli/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,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<IO: Io>(&self) -> Halt<()>;
async fn wait_until_node_is_synced(&self, io: &impl Io) -> Halt<()>;
}

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

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

Expand Down
305 changes: 143 additions & 162 deletions apps/src/lib/cli/client.rs

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion apps/src/lib/cli/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;

use color_eyre::eyre::Result;
use namada::ledger::{Namada, NamadaImpl};
use namada::sdk::masp::fs::FsShieldedUtils;
use namada::sdk::masp::ShieldedContext;
use namada::sdk::wallet::Wallet;
use namada::sdk::masp::fs::FsShieldedUtils;
use namada::types::address::{Address, InternalAddress};
use namada::types::chain::ChainId;
use namada::types::ethereum_events::EthAddress;
Expand Down Expand Up @@ -150,6 +151,19 @@ impl Context {
})
}

/// Make an implementation of Namada from this object and parameters.
pub fn to_sdk<'a, C, IO>(
&'a mut self,
client: &'a C,
io: &'a IO,
) -> impl Namada
where
C: namada::ledger::queries::Client + Sync,
IO: Io,
{
NamadaImpl::new(client, &mut self.wallet, &mut self.shielded, io)
}

/// Parse and/or look-up the value from the context.
pub fn get<T>(&self, from_context: &FromContext<T>) -> T
where
Expand Down
52 changes: 27 additions & 25 deletions apps/src/lib/cli/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ impl<IO: Io> CliApi<IO> {
pub async fn handle_relayer_command<C>(
client: Option<C>,
cmd: cli::NamadaRelayer,
io: &IO,
) -> Result<()>
where
C: CliClient,
Expand All @@ -36,11 +37,12 @@ impl<IO: Io> CliApi<IO> {
)
});
client
.wait_until_node_is_synced::<IO>()
.wait_until_node_is_synced(io)
.await
.proceed_or_else(error)?;
let args = args.to_sdk(&mut ctx);
bridge_pool::recommend_batch::<_, IO>(&client, args)
let namada = ctx.to_sdk(&client, io);
bridge_pool::recommend_batch(&namada, args)
.await
.proceed_or_else(error)?;
}
Expand All @@ -56,11 +58,11 @@ impl<IO: Io> CliApi<IO> {
)
});
client
.wait_until_node_is_synced::<IO>()
.wait_until_node_is_synced(io)
.await
.proceed_or_else(error)?;
let args = args.to_sdk_ctxless();
bridge_pool::construct_proof::<_, IO>(&client, args)
bridge_pool::construct_proof(&client, io, args)
.await
.proceed_or_else(error)?;
}
Expand All @@ -71,16 +73,16 @@ impl<IO: Io> CliApi<IO> {
)
});
client
.wait_until_node_is_synced::<IO>()
.wait_until_node_is_synced(io)
.await
.proceed_or_else(error)?;
let eth_client = Arc::new(
Provider::<Http>::try_from(&args.eth_rpc_endpoint)
.unwrap(),
);
let args = args.to_sdk_ctxless();
bridge_pool::relay_bridge_pool_proof::<_, _, IO>(
eth_client, &client, args,
bridge_pool::relay_bridge_pool_proof(
eth_client, &client, io, args,
)
.await
.proceed_or_else(error)?;
Expand All @@ -92,10 +94,10 @@ impl<IO: Io> CliApi<IO> {
C::from_tendermint_address(&mut query.ledger_address)
});
client
.wait_until_node_is_synced::<IO>()
.wait_until_node_is_synced(io)
.await
.proceed_or_else(error)?;
bridge_pool::query_bridge_pool::<_, IO>(&client).await;
bridge_pool::query_bridge_pool(&client, io).await;
}
EthBridgePoolWithoutCtx::QuerySigned(
QuerySignedBridgePool(mut query),
Expand All @@ -104,10 +106,10 @@ impl<IO: Io> CliApi<IO> {
C::from_tendermint_address(&mut query.ledger_address)
});
client
.wait_until_node_is_synced::<IO>()
.wait_until_node_is_synced(io)
.await
.proceed_or_else(error)?;
bridge_pool::query_signed_bridge_pool::<_, IO>(&client)
bridge_pool::query_signed_bridge_pool(&client, io)
.await
.proceed_or_else(error)?;
}
Expand All @@ -118,10 +120,10 @@ impl<IO: Io> CliApi<IO> {
C::from_tendermint_address(&mut query.ledger_address)
});
client
.wait_until_node_is_synced::<IO>()
.wait_until_node_is_synced(io)
.await
.proceed_or_else(error)?;
bridge_pool::query_relay_progress::<_, IO>(&client).await;
bridge_pool::query_relay_progress(&client, io).await;
}
},
cli::NamadaRelayer::ValidatorSet(sub) => match sub {
Expand All @@ -134,12 +136,12 @@ impl<IO: Io> CliApi<IO> {
)
});
client
.wait_until_node_is_synced::<IO>()
.wait_until_node_is_synced(io)
.await
.proceed_or_else(error)?;
let args = args.to_sdk_ctxless();
validator_set::query_bridge_validator_set::<_, IO>(
&client, args,
validator_set::query_bridge_validator_set(
&client, io, args,
)
.await;
}
Expand All @@ -152,12 +154,12 @@ impl<IO: Io> CliApi<IO> {
)
});
client
.wait_until_node_is_synced::<IO>()
.wait_until_node_is_synced(io)
.await
.proceed_or_else(error)?;
let args = args.to_sdk_ctxless();
validator_set::query_governnace_validator_set::<_, IO>(
&client, args,
validator_set::query_governnace_validator_set(
&client, io, args,
)
.await;
}
Expand All @@ -170,12 +172,12 @@ impl<IO: Io> CliApi<IO> {
)
});
client
.wait_until_node_is_synced::<IO>()
.wait_until_node_is_synced(io)
.await
.proceed_or_else(error)?;
let args = args.to_sdk_ctxless();
validator_set::query_validator_set_update_proof::<_, IO>(
&client, args,
validator_set::query_validator_set_update_proof(
&client, io, args,
)
.await;
}
Expand All @@ -188,16 +190,16 @@ impl<IO: Io> CliApi<IO> {
)
});
client
.wait_until_node_is_synced::<IO>()
.wait_until_node_is_synced(io)
.await
.proceed_or_else(error)?;
let eth_client = Arc::new(
Provider::<Http>::try_from(&args.eth_rpc_endpoint)
.unwrap(),
);
let args = args.to_sdk_ctxless();
validator_set::relay_validator_set_update::<_, _, IO>(
eth_client, &client, args,
validator_set::relay_validator_set_update(
eth_client, &client, io, args,
)
.await
.proceed_or_else(error)?;
Expand Down
3 changes: 2 additions & 1 deletion apps/src/lib/cli/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use clap::{ArgAction, ArgMatches};
use color_eyre::eyre::Result;

use super::args;
use super::context::{Context, FromContext};
use super::context::Context;
use crate::cli::api::CliIo;
use crate::cli::context::FromContext;

// We only use static strings
pub type App = clap::Command;
Expand Down
Loading

0 comments on commit 0572aa3

Please sign in to comment.