Skip to content

Commit

Permalink
Merge branch 'mariari/sdk-folder' (#1868)
Browse files Browse the repository at this point in the history
* origin/mariari/sdk-folder:
  Create Changelog
  Move namada::types::error into namada::sdk::error
  Move wallet to the SDK
  Move the Client code into the queries module
  Move args.rs into the sdk folder
  Move masp.rs over to the SDK crate
  Move singing.rs over to the SDK folder
  Move tx.rs to the SDK crate
  Create the SDK folder and move RPC to it
  • Loading branch information
Fraccaman committed Sep 25, 2023
2 parents 71b7423 + fbbdedb commit d8c2287
Show file tree
Hide file tree
Showing 43 changed files with 493 additions and 455 deletions.
21 changes: 21 additions & 0 deletions .changelog/unreleased/SDK/1868-shared-utils-folder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- The shared-utils topic ([#1868](https://github.com/anoma/namada/pull/1868)) moves the following:
+ _Modules_
| From | To |
|-----------------------------------------|--------------------------------------|
| namada::ledger::tx | namada::sdk::tx |
| namada::ledger::rpc | namada::sdk::rpc |
| namada::ledger::signing | namada::sdk::signing |
| namada::ledger::masp | namada::sdk::masp |
| namada::ledger::args | namada::sdk::args |
| namada::ledger::wallet::alias | namada::sdk::wallet::alias |
| namada::ledger::wallet::derivation_path | namada::sdk::wallet::derivation_path |
| namada::ledger::wallet::keys | namada::sdk::wallet::keys |
| namada::ledger::wallet::pre_genesis | namada::sdk::wallet::pre_genesis |
| namada::ledger::wallet::store | namada::sdk::wallet::store |
| namada::types::error | namada::sdk::error |

+ _Types_

| From | To |
|---------------------------------|------------------------------|
| namada::ledger::queires::Client | namada::sdk::queires::Client |
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Move all functions considered to be apart of the SDK to the SDK
folder. ([#1868](https://github.com/anoma/namada/pull/1868))
2 changes: 1 addition & 1 deletion apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2460,7 +2460,7 @@ pub mod args {
use std::str::FromStr;

use namada::ibc::core::ics24_host::identifier::{ChannelId, PortId};
pub use namada::ledger::args::*;
pub use namada::sdk::args::*;
use namada::types::address::Address;
use namada::types::chain::{ChainId, ChainIdPrefix};
use namada::types::dec::Dec;
Expand Down
4 changes: 2 additions & 2 deletions apps/src/lib/cli/api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::marker::PhantomData;

use namada::ledger::queries::Client;
use namada::ledger::rpc::wait_until_node_is_synched;
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 tendermint_config::net::Address as TendermintAddress;
Expand Down
4 changes: 2 additions & 2 deletions apps/src/lib/cli/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use color_eyre::eyre::{eyre, Report, Result};
use namada::ledger::eth_bridge::bridge_pool;
use namada::ledger::tx::dump_tx;
use namada::ledger::{signing, tx as sdk_tx};
use namada::sdk::tx::dump_tx;
use namada::sdk::{signing, tx as sdk_tx};
use namada::types::control_flow::ProceedOrElse;

use crate::cli;
Expand Down
4 changes: 2 additions & 2 deletions apps/src/lib/cli/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;

use color_eyre::eyre::Result;
use namada::ledger::masp::ShieldedContext;
use namada::ledger::wallet::Wallet;
use namada::sdk::masp::ShieldedContext;
use namada::sdk::wallet::Wallet;
use namada::types::address::{Address, InternalAddress};
use namada::types::chain::ChainId;
use namada::types::ethereum_events::EthAddress;
Expand Down
4 changes: 2 additions & 2 deletions apps/src/lib/cli/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use borsh::BorshSerialize;
use color_eyre::eyre::Result;
use itertools::sorted;
use masp_primitives::zip32::ExtendedFullViewingKey;
use namada::ledger::masp::find_valid_diversifier;
use namada::ledger::wallet::{DecryptionError, FindKeyError};
use namada::sdk::masp::find_valid_diversifier;
use namada::sdk::wallet::{DecryptionError, FindKeyError};
use namada::types::key::*;
use namada::types::masp::{MaspValue, PaymentAddress};
use rand_core::OsRng;
Expand Down
79 changes: 40 additions & 39 deletions apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,29 @@ use namada::core::ledger::governance::utils::{
use namada::core::ledger::pgf::parameters::PgfParameters;
use namada::core::ledger::pgf::storage::steward::StewardDetail;
use namada::ledger::events::Event;
use namada::ledger::masp::{
Conversions, MaspAmount, MaspChange, ShieldedContext, ShieldedUtils,
};
use namada::ledger::parameters::{storage as param_storage, EpochDuration};
use namada::ledger::pos::{CommissionPair, PosParams, Slash};
use namada::ledger::queries::RPC;
use namada::ledger::rpc::{
use namada::ledger::storage::ConversionState;
use namada::proof_of_stake::types::{ValidatorState, WeightedValidator};
use namada::sdk::error;
use namada::sdk::error::{is_pinned_error, Error, PinnedBalanceError};
use namada::sdk::masp::{
Conversions, MaspAmount, MaspChange, ShieldedContext, ShieldedUtils,
};
use namada::sdk::rpc::{
self, enriched_bonds_and_unbonds, format_denominated_amount, query_epoch,
TxResponse,
};
use namada::ledger::storage::ConversionState;
use namada::ledger::wallet::{AddressVpType, Wallet};
use namada::proof_of_stake::types::{ValidatorState, WeightedValidator};
use namada::sdk::wallet::{AddressVpType, Wallet};
use namada::types::address::{masp, Address};
use namada::types::control_flow::ProceedOrElse;
use namada::types::error::{is_pinned_error, Error, PinnedBalanceError};
use namada::types::hash::Hash;
use namada::types::key::*;
use namada::types::masp::{BalanceOwner, ExtendedViewingKey, PaymentAddress};
use namada::types::storage::{BlockHeight, BlockResults, Epoch, Key, KeySeg};
use namada::types::token::{Change, MaspDenom};
use namada::types::{error, storage, token};
use namada::types::{storage, token};
use tokio::time::Instant;

use crate::cli::{self, args};
Expand All @@ -65,10 +66,10 @@ use crate::wallet::CliWalletUtils;
/// error.
pub async fn query_tx_status<C: namada::ledger::queries::Client + Sync>(
client: &C,
status: namada::ledger::rpc::TxEventQuery<'_>,
status: namada::sdk::rpc::TxEventQuery<'_>,
deadline: Instant,
) -> Event {
namada::ledger::rpc::query_tx_status(client, status, deadline)
namada::sdk::rpc::query_tx_status(client, status, deadline)
.await
.proceed()
}
Expand All @@ -79,7 +80,7 @@ pub async fn query_and_print_epoch<
>(
client: &C,
) -> Epoch {
let epoch = namada::ledger::rpc::query_epoch(client).await.unwrap();
let epoch = namada::sdk::rpc::query_epoch(client).await.unwrap();
println!("Last committed epoch: {}", epoch);
epoch
}
Expand All @@ -88,7 +89,7 @@ pub async fn query_and_print_epoch<
pub async fn query_block<C: namada::ledger::queries::Client + Sync>(
client: &C,
) {
let block = namada::ledger::rpc::query_block(client).await.unwrap();
let block = namada::sdk::rpc::query_block(client).await.unwrap();
match block {
Some(block) => {
println!(
Expand Down Expand Up @@ -625,7 +626,7 @@ pub async fn query_proposal_by_id<C: namada::ledger::queries::Client + Sync>(
client: &C,
proposal_id: u64,
) -> Result<Option<StorageProposal>, error::Error> {
namada::ledger::rpc::query_proposal_by_id(client, proposal_id).await
namada::sdk::rpc::query_proposal_by_id(client, proposal_id).await
}

/// Query token shielded balance(s)
Expand Down Expand Up @@ -905,7 +906,7 @@ pub async fn get_token_balance<C: namada::ledger::queries::Client + Sync>(
token: &Address,
owner: &Address,
) -> token::Amount {
namada::ledger::rpc::get_token_balance(client, token, owner)
namada::sdk::rpc::get_token_balance(client, token, owner)
.await
.unwrap()
}
Expand Down Expand Up @@ -1802,7 +1803,7 @@ where
{
println!(
"Dry-run result: {}",
namada::ledger::rpc::dry_run_tx(client, tx_bytes).await?
namada::sdk::rpc::dry_run_tx(client, tx_bytes).await?
);
Ok(())
}
Expand All @@ -1813,15 +1814,15 @@ pub async fn get_public_key<C: namada::ledger::queries::Client + Sync>(
address: &Address,
index: u8,
) -> Result<Option<common::PublicKey>, error::Error> {
namada::ledger::rpc::get_public_key_at(client, address, index).await
namada::sdk::rpc::get_public_key_at(client, address, index).await
}

/// Check if the given address is a known validator.
pub async fn is_validator<C: namada::ledger::queries::Client + Sync>(
client: &C,
address: &Address,
) -> bool {
namada::ledger::rpc::is_validator(client, address)
namada::sdk::rpc::is_validator(client, address)
.await
.unwrap()
}
Expand All @@ -1831,7 +1832,7 @@ pub async fn is_delegator<C: namada::ledger::queries::Client + Sync>(
client: &C,
address: &Address,
) -> bool {
namada::ledger::rpc::is_delegator(client, address)
namada::sdk::rpc::is_delegator(client, address)
.await
.unwrap()
}
Expand All @@ -1841,7 +1842,7 @@ pub async fn is_delegator_at<C: namada::ledger::queries::Client + Sync>(
address: &Address,
epoch: Epoch,
) -> bool {
namada::ledger::rpc::is_delegator_at(client, address, epoch)
namada::sdk::rpc::is_delegator_at(client, address, epoch)
.await
.unwrap()
}
Expand All @@ -1853,7 +1854,7 @@ pub async fn known_address<C: namada::ledger::queries::Client + Sync>(
client: &C,
address: &Address,
) -> bool {
namada::ledger::rpc::known_address(client, address)
namada::sdk::rpc::known_address(client, address)
.await
.unwrap()
}
Expand Down Expand Up @@ -1933,15 +1934,15 @@ pub async fn query_conversion<C: namada::ledger::queries::Client + Sync>(
masp_primitives::transaction::components::I32Sum,
MerklePath<Node>,
)> {
namada::ledger::rpc::query_conversion(client, asset_type).await
namada::sdk::rpc::query_conversion(client, asset_type).await
}

/// Query a wasm code hash
pub async fn query_wasm_code_hash<C: namada::ledger::queries::Client + Sync>(
client: &C,
code_path: impl AsRef<str>,
) -> Result<Hash, error::Error> {
namada::ledger::rpc::query_wasm_code_hash(client, code_path).await
namada::sdk::rpc::query_wasm_code_hash(client, code_path).await
}

/// Query a storage value and decode it with [`BorshDeserialize`].
Expand All @@ -1952,7 +1953,7 @@ pub async fn query_storage_value<C: namada::ledger::queries::Client + Sync, T>(
where
T: BorshDeserialize,
{
namada::ledger::rpc::query_storage_value(client, key).await
namada::sdk::rpc::query_storage_value(client, key).await
}

/// Query a storage value and the proof without decoding.
Expand All @@ -1964,7 +1965,7 @@ pub async fn query_storage_value_bytes<
height: Option<BlockHeight>,
prove: bool,
) -> (Option<Vec<u8>>, Option<Proof>) {
namada::ledger::rpc::query_storage_value_bytes(client, key, height, prove)
namada::sdk::rpc::query_storage_value_bytes(client, key, height, prove)
.await
.unwrap()
}
Expand All @@ -1982,7 +1983,7 @@ pub async fn query_storage_prefix<
where
T: BorshDeserialize,
{
namada::ledger::rpc::query_storage_prefix(client, key)
namada::sdk::rpc::query_storage_prefix(client, key)
.await
.unwrap()
}
Expand All @@ -1994,7 +1995,7 @@ pub async fn query_has_storage_key<
client: &C,
key: &storage::Key,
) -> bool {
namada::ledger::rpc::query_has_storage_key(client, key)
namada::sdk::rpc::query_has_storage_key(client, key)
.await
.unwrap()
}
Expand All @@ -2003,21 +2004,21 @@ pub async fn query_has_storage_key<
/// the current status of a transation.
pub async fn query_tx_events<C: namada::ledger::queries::Client + Sync>(
client: &C,
tx_event_query: namada::ledger::rpc::TxEventQuery<'_>,
tx_event_query: namada::sdk::rpc::TxEventQuery<'_>,
) -> std::result::Result<
Option<Event>,
<C as namada::ledger::queries::Client>::Error,
> {
namada::ledger::rpc::query_tx_events(client, tx_event_query).await
namada::sdk::rpc::query_tx_events(client, tx_event_query).await
}

/// Lookup the full response accompanying the specified transaction event
// TODO: maybe remove this in favor of `query_tx_status`
pub async fn query_tx_response<C: namada::ledger::queries::Client + Sync>(
client: &C,
tx_query: namada::ledger::rpc::TxEventQuery<'_>,
tx_query: namada::sdk::rpc::TxEventQuery<'_>,
) -> Result<TxResponse, TError> {
namada::ledger::rpc::query_tx_response(client, tx_query).await
namada::sdk::rpc::query_tx_response(client, tx_query).await
}

/// Lookup the results of applying the specified transaction to the
Expand All @@ -2029,7 +2030,7 @@ pub async fn query_result<C: namada::ledger::queries::Client + Sync>(
// First try looking up application event pertaining to given hash.
let tx_response = query_tx_response(
client,
namada::ledger::rpc::TxEventQuery::Applied(&args.tx_hash),
namada::sdk::rpc::TxEventQuery::Applied(&args.tx_hash),
)
.await;
match tx_response {
Expand All @@ -2043,7 +2044,7 @@ pub async fn query_result<C: namada::ledger::queries::Client + Sync>(
// If this fails then instead look for an acceptance event.
let tx_response = query_tx_response(
client,
namada::ledger::rpc::TxEventQuery::Accepted(&args.tx_hash),
namada::sdk::rpc::TxEventQuery::Accepted(&args.tx_hash),
)
.await;
match tx_response {
Expand Down Expand Up @@ -2096,7 +2097,7 @@ pub async fn get_all_validators<C: namada::ledger::queries::Client + Sync>(
client: &C,
epoch: Epoch,
) -> HashSet<Address> {
namada::ledger::rpc::get_all_validators(client, epoch)
namada::sdk::rpc::get_all_validators(client, epoch)
.await
.unwrap()
}
Expand All @@ -2107,7 +2108,7 @@ pub async fn get_total_staked_tokens<
client: &C,
epoch: Epoch,
) -> token::Amount {
namada::ledger::rpc::get_total_staked_tokens(client, epoch)
namada::sdk::rpc::get_total_staked_tokens(client, epoch)
.await
.unwrap()
}
Expand Down Expand Up @@ -2135,7 +2136,7 @@ pub async fn get_delegators_delegation<
client: &C,
address: &Address,
) -> HashSet<Address> {
namada::ledger::rpc::get_delegators_delegation(client, address)
namada::sdk::rpc::get_delegators_delegation(client, address)
.await
.unwrap()
}
Expand All @@ -2147,7 +2148,7 @@ pub async fn get_delegators_delegation_at<
address: &Address,
epoch: Epoch,
) -> HashMap<Address, token::Amount> {
namada::ledger::rpc::get_delegators_delegation_at(client, address, epoch)
namada::sdk::rpc::get_delegators_delegation_at(client, address, epoch)
.await
.unwrap()
}
Expand All @@ -2157,7 +2158,7 @@ pub async fn query_governance_parameters<
>(
client: &C,
) -> GovernanceParameters {
namada::ledger::rpc::query_governance_parameters(client).await
namada::sdk::rpc::query_governance_parameters(client).await
}

/// A helper to unwrap client's response. Will shut down process on error.
Expand Down Expand Up @@ -2241,7 +2242,7 @@ pub async fn compute_proposal_votes<
proposal_id: u64,
epoch: Epoch,
) -> ProposalVotes {
let votes = namada::ledger::rpc::query_proposal_votes(client, proposal_id)
let votes = namada::sdk::rpc::query_proposal_votes(client, proposal_id)
.await
.unwrap();

Expand Down
8 changes: 4 additions & 4 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ use namada::core::ledger::governance::cli::offline::{
use namada::core::ledger::governance::cli::onchain::{
DefaultProposal, PgfFundingProposal, PgfStewardProposal, ProposalVote,
};
use namada::ledger::rpc::{TxBroadcastData, TxResponse};
use namada::ledger::wallet::{Wallet, WalletUtils};
use namada::ledger::{masp, pos, signing, tx};
use namada::ledger::pos;
use namada::proof_of_stake::parameters::PosParams;
use namada::proto::Tx;
use namada::sdk::rpc::{TxBroadcastData, TxResponse};
use namada::sdk::wallet::{Wallet, WalletUtils};
use namada::sdk::{error, masp, signing, tx};
use namada::tendermint_rpc::HttpClient;
use namada::types::address::{Address, ImplicitAddress};
use namada::types::dec::Dec;
use namada::types::error;
use namada::types::key::{self, *};
use namada::types::transaction::pos::InitValidator;

Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/client/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use borsh::BorshSerialize;
use flate2::read::GzDecoder;
use flate2::write::GzEncoder;
use flate2::Compression;
use namada::ledger::wallet::Wallet;
use namada::sdk::wallet::Wallet;
use namada::types::address;
use namada::types::chain::ChainId;
use namada::types::dec::Dec;
Expand Down
Loading

0 comments on commit d8c2287

Please sign in to comment.