Skip to content

Commit

Permalink
chore: switch to use namada_sdk instead of namada
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Jun 24, 2024
1 parent ff29f8e commit 6183b87
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 93 deletions.
4 changes: 2 additions & 2 deletions packages/shared/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ crate-type = ["cdylib", "rlib"]
[features]
default = []
dev = []
multicore = ["wasm-bindgen-rayon", "namada/multicore"]
multicore = ["wasm-bindgen-rayon", "namada_sdk/multicore"]
nodejs = []
web = []

Expand All @@ -24,7 +24,7 @@ chrono = "0.4.22"
getrandom = { version = "0.2.7", features = ["js"] }
gloo-utils = { version = "0.1.5", features = ["serde"] }
js-sys = "0.3.60"
namada = { git = "https://github.com/anoma/namada", version = "0.39.0", default-features = false, features = ["namada-sdk"] }
namada_sdk = { git = "https://github.com/anoma/namada", version = "0.40.0", default-features = false }
rand = "0.8.5"
rexie = "0.5"
serde = "^1.0.181"
Expand Down
40 changes: 20 additions & 20 deletions packages/shared/lib/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
use js_sys::Uint8Array;
use namada::address::Address;
use namada::core::borsh::BorshSerialize;
use namada::core::collections::{HashMap, HashSet};
use namada::eth_bridge_pool::TransferToEthereum;
use namada::governance::storage::keys as governance_storage;
use namada::governance::utils::{
use namada_sdk::address::Address;
use namada_sdk::borsh::BorshSerialize;
use namada_sdk::collections::{HashMap, HashSet};
use namada_sdk::eth_bridge_pool::TransferToEthereum;
use namada_sdk::governance::storage::keys as governance_storage;
use namada_sdk::governance::utils::{
compute_proposal_result, ProposalVotes, TallyResult, TallyType, VotePower,
};
use namada::governance::{ProposalType, ProposalVote};
use namada::ledger::eth_bridge::bridge_pool::query_signed_bridge_pool;
use namada::ledger::parameters::storage;
use namada::ledger::queries::RPC;
use namada::masp::ExtendedViewingKey;
use namada::proof_of_stake::Epoch;
use namada::sdk::masp::{DefaultLogger, ShieldedContext};
use namada::sdk::masp_primitives::asset_type::AssetType;
use namada::sdk::masp_primitives::sapling::ViewingKey;
use namada::sdk::masp_primitives::transaction::components::ValueSum;
use namada::sdk::masp_primitives::zip32::ExtendedFullViewingKey;
use namada::sdk::rpc::{
use namada_sdk::governance::{ProposalType, ProposalVote};
use namada_sdk::eth_bridge::bridge_pool::query_signed_bridge_pool;
use namada_sdk::parameters::storage;
use namada_sdk::queries::RPC;
use namada_sdk::masp::ExtendedViewingKey;
use namada_sdk::proof_of_stake::Epoch;
use namada_sdk::masp::{DefaultLogger, ShieldedContext};
use namada_sdk::masp_primitives::asset_type::AssetType;
use namada_sdk::masp_primitives::sapling::ViewingKey;
use namada_sdk::masp_primitives::transaction::components::ValueSum;
use namada_sdk::masp_primitives::zip32::ExtendedFullViewingKey;
use namada_sdk::rpc::{
format_denominated_amount, get_public_key_at, get_token_balance, get_total_staked_tokens,
is_steward, query_epoch, query_masp_epoch, query_native_token, query_proposal_by_id,
query_proposal_votes, query_storage_value,
};
use namada::token;
use namada::uint::I256;
use namada_sdk::token;
use namada_sdk::uint::I256;
use std::collections::BTreeMap;
use std::str::FromStr;
use wasm_bindgen::prelude::*;
Expand Down
16 changes: 8 additions & 8 deletions packages/shared/lib/src/rpc_client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use js_sys::JSON::stringify;
use namada::storage::BlockHeight;
use namada_sdk::storage::BlockHeight;
use std::fmt::Debug;
use std::fmt::Display;
use thiserror::Error;
Expand All @@ -8,9 +8,9 @@ use wasm_bindgen::JsCast;
use wasm_bindgen_futures::JsFuture;
use web_sys::Response;

use namada::ledger::queries::{Client, EncodedResponseQuery};
use namada::tendermint::{self, abci::Code};
use namada::tendermint_rpc::{
use namada_sdk::queries::{Client, EncodedResponseQuery};
use namada_sdk::tendermint::{self, abci::Code};
use namada_sdk::tendermint_rpc::{
error::Error as TendermintRpcError, Response as RpcResponse, SimpleRequest,
};

Expand Down Expand Up @@ -41,14 +41,14 @@ impl From<std::io::Error> for RpcError {
}
}

impl From<namada::tendermint::Error> for RpcError {
fn from(error: namada::tendermint::Error) -> Self {
impl From<namada_sdk::tendermint::Error> for RpcError {
fn from(error: namada_sdk::tendermint::Error) -> Self {
RpcError::new(&error.to_string())
}
}

impl From<namada::tendermint_rpc::Error> for RpcError {
fn from(error: namada::tendermint_rpc::Error) -> Self {
impl From<namada_sdk::tendermint_rpc::Error> for RpcError {
fn from(error: namada_sdk::tendermint_rpc::Error) -> Self {
RpcError::new(&error.to_string())
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/lib/src/sdk/io.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use namada::io::Io;
use namada_sdk::io::Io;
use wasm_bindgen::JsValue;

fn read(question: Option<&str>) -> std::io::Result<String> {
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/lib/src/sdk/masp/masp_node.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use async_trait::async_trait;
use namada::sdk::{
use namada_sdk::{
borsh::{BorshDeserialize, BorshSerialize},
masp::{ContextSyncStatus, ShieldedContext, ShieldedUtils},
masp_proofs::prover::LocalTxProver,
Expand All @@ -25,7 +25,7 @@ const SPECULATIVE_TMP_FILE_NAME: &str = "speculative_shielded.tmp";
/// Mostly copied from the Namada CLI

#[derive(Default, Debug, BorshSerialize, BorshDeserialize, Clone)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct NodeShieldedUtils {
#[borsh(skip)]
context_dir: PathBuf,
Expand Down
10 changes: 5 additions & 5 deletions packages/shared/lib/src/sdk/masp/masp_web.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use async_trait::async_trait;
use gloo_utils::format::JsValueSerdeExt;
use namada::core::borsh::{BorshDeserialize, BorshSerialize};
use namada::sdk::masp::{ContextSyncStatus, ShieldedContext, ShieldedUtils};
use namada::sdk::masp_proofs::prover::LocalTxProver;
use namada_sdk::borsh::{BorshDeserialize, BorshSerialize};
use namada_sdk::masp::{ContextSyncStatus, ShieldedContext, ShieldedUtils};
use namada_sdk::masp_proofs::prover::LocalTxProver;
use rexie::{Error, ObjectStore, Rexie, TransactionMode};
use wasm_bindgen::{JsError, JsValue};

use crate::utils::to_bytes;

const DB_PREFIX: &str = "Namada::MASP";
const DB_PREFIX: &str = "namada_sdk::MASP";
const SHIELDED_CONTEXT_TABLE: &str = "ShieldedContext";
const SHIELDED_CONTEXT_KEY_CONFIRMED: &str = "shielded-context-confirmed";
const SHIELDED_CONTEXT_KEY_SPECULATIVE: &str = "shielded-context-speculative";

#[derive(Default, Debug, BorshSerialize, BorshDeserialize, Clone)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct WebShieldedUtils {
spend_param_bytes: Vec<u8>,
output_param_bytes: Vec<u8>,
Expand Down
28 changes: 14 additions & 14 deletions packages/shared/lib/src/sdk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ use crate::rpc_client::HttpClient;
use crate::utils::set_panic_hook;
use crate::utils::to_js_result;
use js_sys::Uint8Array;
use namada::address::Address;
use namada::core::borsh::{self, BorshDeserialize};
use namada::hash::Hash;
use namada::key::{common, ed25519, SigScheme};
use namada::ledger::eth_bridge::bridge_pool::build_bridge_pool_tx;
use namada::sdk::masp::ShieldedContext;
use namada::sdk::rpc::query_epoch;
use namada::sdk::signing::SigningTxData;
use namada::sdk::tx::build_redelegation;
use namada::sdk::tx::{
use namada_sdk::address::Address;
use namada_sdk::borsh::{self, BorshDeserialize};
use namada_sdk::hash::Hash;
use namada_sdk::key::{common, ed25519, SigScheme};
use namada_sdk::eth_bridge::bridge_pool::build_bridge_pool_tx;
use namada_sdk::masp::ShieldedContext;
use namada_sdk::rpc::query_epoch;
use namada_sdk::signing::SigningTxData;
use namada_sdk::tx::build_redelegation;
use namada_sdk::tx::{
build_bond, build_ibc_transfer, build_reveal_pk, build_transparent_transfer, build_unbond,
build_vote_proposal, build_withdraw, is_reveal_pk_needed, process_tx,
};
use namada::sdk::wallet::{Store, Wallet};
use namada::sdk::{Namada, NamadaImpl};
use namada::string_encoding::Format;
use namada::tx::Tx;
use namada_sdk::wallet::{Store, Wallet};
use namada_sdk::{Namada, NamadaImpl};
use namada_sdk::string_encoding::Format;
use namada_sdk::tx::Tx;
use std::str::FromStr;
use wasm_bindgen::{prelude::wasm_bindgen, JsError, JsValue};

Expand Down
6 changes: 3 additions & 3 deletions packages/shared/lib/src/sdk/signature.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use namada::core::borsh::{BorshDeserialize, BorshSerialize};
use namada::{
use namada_sdk::borsh::{BorshDeserialize, BorshSerialize};
use namada_sdk::{
key::common::{PublicKey, Signature},
tx::{CompressedAuthorization, Section, Signer, Tx},
};
use std::collections::BTreeMap;
use wasm_bindgen::JsError;

#[derive(BorshSerialize, BorshDeserialize)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct SignatureMsg {
pub pubkey: Vec<u8>,
pub raw_indices: Vec<u8>,
Expand Down
34 changes: 17 additions & 17 deletions packages/shared/lib/src/sdk/tx.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use std::{path::PathBuf, str::FromStr};

use namada::core::borsh::{self, BorshDeserialize, BorshSerialize};
use namada::core::ibc::core::host::types::identifiers::{ChannelId, PortId};
use namada::sdk::signing::SigningTxData;
use namada::tendermint_rpc;
use namada::tx::data::GasLimit;
use namada::{
use namada_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use namada_sdk::ibc::core::host::types::identifiers::{ChannelId, PortId};
use namada_sdk::signing::SigningTxData;
use namada_sdk::tendermint_rpc;
use namada_sdk::tx::data::GasLimit;
use namada_sdk::{
address::Address,
args::{self, InputAmount, TxExpiration},
chain::ChainId,
ethereum_events::EthAddress,
key::common::PublicKey,
masp::TransferSource,
sdk::args::{self, InputAmount, TxExpiration},
token::{Amount, DenominatedAmount, NATIVE_MAX_DECIMAL_PLACES},
};
use wasm_bindgen::JsError;

#[derive(BorshSerialize, BorshDeserialize)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct SigningData {
owner: Option<String>,
public_keys: Vec<u8>,
Expand Down Expand Up @@ -78,7 +78,7 @@ impl SigningData {
}

#[derive(BorshSerialize, BorshDeserialize)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct WrapperTxMsg {
token: String,
fee_amount: String,
Expand All @@ -90,7 +90,7 @@ pub struct WrapperTxMsg {
}

#[derive(BorshSerialize, BorshDeserialize)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct BondMsg {
source: String,
validator: String,
Expand Down Expand Up @@ -136,7 +136,7 @@ pub fn bond_tx_args(bond_msg: &[u8], tx_msg: &[u8]) -> Result<args::Bond, JsErro
}

#[derive(BorshSerialize, BorshDeserialize)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct UnbondMsg {
source: String,
validator: String,
Expand Down Expand Up @@ -181,7 +181,7 @@ pub fn unbond_tx_args(unbond_msg: &[u8], tx_msg: &[u8]) -> Result<args::Unbond,
}

#[derive(BorshSerialize, BorshDeserialize)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct WithdrawMsg {
source: String,
validator: String,
Expand Down Expand Up @@ -218,7 +218,7 @@ pub fn withdraw_tx_args(withdraw_msg: &[u8], tx_msg: &[u8]) -> Result<args::With
}

#[derive(BorshSerialize, BorshDeserialize)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct RedelegateMsg {
owner: String,
source_validator: String,
Expand Down Expand Up @@ -269,7 +269,7 @@ pub fn redelegate_tx_args(
}

#[derive(BorshSerialize, BorshDeserialize)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct VoteProposalMsg {
signer: String,
proposal_id: u64,
Expand Down Expand Up @@ -313,7 +313,7 @@ pub fn vote_proposal_tx_args(
}

#[derive(BorshSerialize, BorshDeserialize)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct TransparentTransferMsg {
source: String,
target: String,
Expand Down Expand Up @@ -368,7 +368,7 @@ pub fn transparent_transfer_tx_args(
}

#[derive(BorshSerialize, BorshDeserialize)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct IbcTransferMsg {
source: String,
receiver: String,
Expand Down Expand Up @@ -437,7 +437,7 @@ pub fn ibc_transfer_tx_args(
}

#[derive(BorshSerialize, BorshDeserialize)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct EthBridgeTransferMsg {
nut: bool,
asset: String,
Expand Down
8 changes: 3 additions & 5 deletions packages/shared/lib/src/sdk/wallet/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use namada::{
use namada_sdk::{
key::common::SecretKey,
masp::{ExtendedSpendingKey, ExtendedViewingKey, PaymentAddress},
sdk::{
masp_primitives::zip32::ExtendedFullViewingKey,
wallet::{alias::Alias, Wallet, WalletIo},
},
masp_primitives::zip32::ExtendedFullViewingKey,
wallet::{alias::Alias, Wallet, WalletIo},
};
use std::str::FromStr;
use zeroize::Zeroizing;
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/lib/src/sdk/wallet/wallet_node.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::PathBuf;

use namada::sdk::{
use namada_sdk::{
borsh::{BorshDeserialize, BorshSerialize},
wallet::{LoadStoreError, Store, Wallet, WalletIo, WalletStorage},
};
Expand All @@ -10,7 +10,7 @@ use wasm_bindgen::{prelude::wasm_bindgen, JsValue};
use crate::utils::to_bytes;

#[derive(Debug, BorshSerialize, BorshDeserialize, Clone)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct NodeWalletUtils {
#[borsh(skip)]
store_dir: PathBuf,
Expand Down Expand Up @@ -40,7 +40,7 @@ impl NodeWalletStorage for NodeWalletUtils {
const FILE_NAME: &str = "wallet.toml";

impl WalletStorage for NodeWalletUtils {
fn save<U>(&self, wallet: &Wallet<U>) -> Result<(), namada::sdk::wallet::LoadStoreError> {
fn save<U>(&self, wallet: &Wallet<U>) -> Result<(), namada_sdk::wallet::LoadStoreError> {
let data = wallet.store().encode();

let wallet_path = self.store_dir().join(FILE_NAME);
Expand All @@ -57,7 +57,7 @@ impl WalletStorage for NodeWalletUtils {
Ok(())
}

fn load<U>(&self, wallet: &mut Wallet<U>) -> Result<(), namada::sdk::wallet::LoadStoreError> {
fn load<U>(&self, wallet: &mut Wallet<U>) -> Result<(), namada_sdk::wallet::LoadStoreError> {
let wallet_file = self.store_dir().join(FILE_NAME);

let stored_data: Vec<u8> =
Expand Down
Loading

0 comments on commit 6183b87

Please sign in to comment.