Skip to content

Commit

Permalink
SDK can now query for the native token address from the network. Also…
Browse files Browse the repository at this point in the history
… added null IO implementation.
  • Loading branch information
murisi committed Oct 9, 2023
1 parent b1bc845 commit 615ebc8
Show file tree
Hide file tree
Showing 16 changed files with 167 additions and 87 deletions.
2 changes: 1 addition & 1 deletion apps/src/bin/namada-client/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async fn main() -> Result<()> {
let _log_guard = logging::init_from_env_or(LevelFilter::INFO)?;

// run the CLI
CliApi::<CliIo>::handle_client_command::<HttpClient>(
CliApi::handle_client_command::<HttpClient, _>(
None,
cli::namada_client_cli()?,
&CliIo,
Expand Down
3 changes: 1 addition & 2 deletions apps/src/bin/namada-relayer/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ async fn main() -> Result<()> {

let cmd = cli::namada_relayer_cli()?;
// run the CLI
CliApi::<CliIo>::handle_relayer_command::<HttpClient>(None, cmd, &CliIo)
.await
CliApi::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, &CliIo)
CliApi::handle_wallet_command(cmd, ctx, &CliIo)
}
4 changes: 1 addition & 3 deletions apps/src/lib/cli/api.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::marker::PhantomData;

use namada::sdk::queries::Client;
use namada::sdk::rpc::wait_until_node_is_synched;
use namada::tendermint_rpc::HttpClient;
Expand Down Expand Up @@ -32,4 +30,4 @@ pub struct CliIo;
#[async_trait::async_trait(?Send)]
impl Io for CliIo {}

pub struct CliApi<IO: Io = CliIo>(PhantomData<IO>);
pub struct CliApi;
7 changes: 4 additions & 3 deletions apps/src/lib/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ fn error() -> Report {
eyre!("Fatal error")
}

impl<IO: Io> CliApi<IO> {
pub async fn handle_client_command<C>(
impl CliApi {
pub async fn handle_client_command<C, IO: Io>(
client: Option<C>,
cmd: cli::NamadaClient,
io: &IO,
Expand Down Expand Up @@ -139,11 +139,12 @@ impl<IO: Io> CliApi<IO> {
.await
.proceed_or_else(error)?;
let args = args.to_sdk(&mut ctx);
let namada = NamadaImpl::new(
let namada = NamadaImpl::native_new(
&client,
&mut ctx.wallet,
&mut ctx.shielded,
io,
ctx.native_token,
);
tx::submit_init_validator(
&namada,
Expand Down
8 changes: 7 additions & 1 deletion apps/src/lib/cli/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,13 @@ impl Context {
C: namada::ledger::queries::Client + Sync,
IO: Io,
{
NamadaImpl::new(client, &mut self.wallet, &mut self.shielded, io)
NamadaImpl::native_new(
client,
&mut self.wallet,
&mut self.shielded,
io,
self.native_token.clone(),
)
}

/// Parse and/or look-up the value from the context.
Expand Down
4 changes: 2 additions & 2 deletions apps/src/lib/cli/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ fn error() -> Report {
eyre!("Fatal error")
}

impl<IO: Io> CliApi<IO> {
impl CliApi {
pub async fn handle_relayer_command<C>(
client: Option<C>,
cmd: cli::NamadaRelayer,
io: &IO,
io: &impl Io,
) -> Result<()>
where
C: CliClient,
Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/cli/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::cli::args::CliToSdk;
use crate::cli::{args, cmds, Context};
use crate::wallet::{read_and_confirm_encryption_password, CliWalletUtils};

impl<IO: Io> CliApi<IO> {
impl CliApi {
pub fn handle_wallet_command(
cmd: cmds::NamadaWallet,
mut ctx: Context,
Expand Down
4 changes: 2 additions & 2 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ where
})?;
let author_balance = rpc::get_token_balance(
namada.client(),
&namada.native_token().await,
&namada.native_token(),
&proposal.proposal.author,
)
.await;
Expand All @@ -665,7 +665,7 @@ where
})?;
let author_balane = rpc::get_token_balance(
namada.client(),
&namada.native_token().await,
&namada.native_token(),
&proposal.proposal.author,
)
.await;
Expand Down
6 changes: 3 additions & 3 deletions apps/src/lib/node/ledger/shell/testing/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn run(
NamadaClient::WithoutContext(sub_cmd, global)
}
};
rt.block_on(CliApi::<TestingIo>::handle_client_command(
rt.block_on(CliApi::handle_client_command(
Some(node),
cmd,
&TestingIo,
Expand All @@ -61,7 +61,7 @@ pub fn run(

let cmd = cmds::NamadaWallet::parse(&matches)
.expect("Could not parse wallet command");
CliApi::<TestingIo>::handle_wallet_command(cmd, ctx, &TestingIo)
CliApi::handle_wallet_command(cmd, ctx, &TestingIo)
}
Bin::Relayer => {
args.insert(0, "relayer");
Expand All @@ -83,7 +83,7 @@ pub fn run(
NamadaRelayer::ValidatorSet(sub_cmd)
}
};
rt.block_on(CliApi::<TestingIo>::handle_relayer_command(
rt.block_on(CliApi::handle_relayer_command(
Some(node),
cmd,
&TestingIo,
Expand Down
3 changes: 2 additions & 1 deletion benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,11 +810,12 @@ impl BenchShieldedCtx {
&[],
))
.unwrap();
let namada = NamadaImpl::new(
let namada = NamadaImpl::native_new(
&self.shell,
&mut self.wallet,
&mut self.shielded,
&StdIo,
self.shell.wl_storage.storage.native_token.clone(),
);
let shielded = async_runtime
.block_on(
Expand Down
Loading

0 comments on commit 615ebc8

Please sign in to comment.