Skip to content

Commit

Permalink
Merge 'murisi/sdk-refactor-rebased' (#1963)
Browse files Browse the repository at this point in the history
* origin/murisi/sdk-refactor-rebased:
  Added a change log entry.
  Changes to enable better usage of the SDK in the absence of wallet or shielded context.
  Separated an SDK crate out of the shared crate.
  SDK can now query for the native token address from the network. Also added null IO implementation.
  Reintegrated generic IO support.
  Enabled parallel usage of the Namada trait using read and write locks.
  Removed unnecessary requirement for mutable references in Namada trait.
  Added function to construct DenominatedAmounts from Amounts.
  Made the ShieldedUtils trait similar to the WalletStorage trait.
  Adding saving and loading function to Wallet.
  Moved FsShieldedUtils into the SDK behind a feature flag.
  Allow the prototypical Tx builder to be modified in NamadaImpl instances.
  Created builders and constructors for each type of transaction.
  Combined construction of signing data with transaction construction.
  • Loading branch information
Fraccaman committed Oct 23, 2023
2 parents 7ed1058 + 94b2d4b commit dd1f4e2
Show file tree
Hide file tree
Showing 86 changed files with 7,029 additions and 5,288 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/SDK/1963-sdk-refactor-rebased.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Improved the usability of the SDK and moved it to separate crate.
([\#1963](https://github.com/anoma/namada/pull/1963))
52 changes: 52 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ members = [
"macros",
"vp_prelude",
"encoding_spec",
"sdk",
]

# wasm packages have to be built separately
Expand Down
3 changes: 2 additions & 1 deletion apps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ mainnet = [
"namada/mainnet",
]
dev = ["namada/dev"]
std = ["ed25519-consensus/std", "rand/std", "rand_core/std", "namada/std"]
std = ["ed25519-consensus/std", "rand/std", "rand_core/std", "namada/std", "namada_sdk/std"]
# for integration tests and test utilies
testing = ["dev"]

Expand All @@ -67,6 +67,7 @@ abciplus = [

[dependencies]
namada = {path = "../shared", features = ["ferveo-tpke", "masp-tx-gen", "multicore", "http-client"]}
namada_sdk = {path = "../sdk", default-features = false, features = ["wasm-runtime", "masp-tx-gen"]}
ark-serialize.workspace = true
ark-std.workspace = true
arse-merkle-tree = { workspace = true, features = ["blake2b"] }
Expand Down
3 changes: 2 additions & 1 deletion apps/src/bin/namada-client/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ 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,
)
.await
}
2 changes: 1 addition & 1 deletion apps/src/bin/namada-relayer/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ async fn main() -> Result<()> {

let cmd = cli::namada_relayer_cli()?;
// run the CLI
CliApi::<CliIo>::handle_relayer_command::<HttpClient>(None, cmd).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)
CliApi::handle_wallet_command(cmd, ctx, &CliIo)
}
11 changes: 6 additions & 5 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub mod wallet;

use clap::{ArgGroup, ArgMatches, ColorChoice};
use color_eyre::eyre::Result;
use namada::types::io::DefaultIo;
use namada::types::io::StdIo;
use utils::*;
pub use utils::{safe_exit, Cmd};

Expand Down Expand Up @@ -2517,7 +2517,6 @@ pub mod args {
use std::str::FromStr;

use namada::ibc::core::ics24_host::identifier::{ChannelId, PortId};
pub use namada::sdk::args::*;
use namada::types::address::Address;
use namada::types::chain::{ChainId, ChainIdPrefix};
use namada::types::dec::Dec;
Expand All @@ -2530,10 +2529,12 @@ pub mod args {
use namada::types::token;
use namada::types::token::NATIVE_MAX_DECIMAL_PLACES;
use namada::types::transaction::GasLimit;
pub use namada_sdk::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 Expand Up @@ -3525,8 +3526,8 @@ pub mod args {
target,
token,
amount,
native_token: (),
tx_code_path,
native_token: (),
}
}

Expand Down Expand Up @@ -3881,8 +3882,8 @@ pub mod args {
validator,
amount,
source,
native_token: (),
tx_code_path,
native_token: (),
}
}

Expand Down Expand Up @@ -5799,7 +5800,7 @@ pub fn namada_relayer_cli() -> Result<NamadaRelayer> {
cmds::EthBridgePool::WithContext(sub_cmd),
) => {
let global_args = args::Global::parse(&matches);
let context = Context::new::<DefaultIo>(global_args)?;
let context = Context::new::<StdIo>(global_args)?;
Ok(NamadaRelayer::EthBridgePoolWithCtx(Box::new((
sub_cmd, context,
))))
Expand Down
14 changes: 6 additions & 8 deletions apps/src/lib/cli/api.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::marker::PhantomData;

use namada::sdk::queries::Client;
use namada::sdk::rpc::wait_until_node_is_synched;
use namada::tendermint_rpc::HttpClient;
use namada::types::control_flow::Halt;
use namada::types::io::Io;
use namada_sdk::queries::Client;
use namada_sdk::rpc::wait_until_node_is_synched;
use tendermint_config::net::Address as TendermintAddress;

use crate::client::utils;
Expand All @@ -13,7 +11,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 +20,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 All @@ -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;
Loading

0 comments on commit dd1f4e2

Please sign in to comment.