Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: switch to use namada_sdk instead of namada #890

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
295 changes: 156 additions & 139 deletions packages/shared/lib/Cargo.lock

Large diffs are not rendered by default.

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.41.0", default-features = false, features = ["namada-sdk"] }
namada_sdk = { git = "https://github.com/anoma/namada", version = "0.42.0", default-features = false }
rand = "0.8.5"
rexie = "0.5"
serde = "^1.0.181"
Expand Down
46 changes: 23 additions & 23 deletions packages/shared/lib/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
use gloo_utils::format::JsValueSerdeExt;
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::bridge_pool::query_signed_bridge_pool;
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::hash::Hash;
use namada::sdk::masp::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::hash::Hash;
use namada_sdk::masp::ExtendedViewingKey;
use namada_sdk::masp::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::parameters::storage;
use namada_sdk::proof_of_stake::Epoch;
use namada_sdk::queries::RPC;
use namada_sdk::rpc::{
self, 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::sdk::state::Key;
use namada::sdk::tx::{
use namada_sdk::state::Key;
use namada_sdk::token;
use namada_sdk::tx::{
TX_BOND_WASM, TX_CLAIM_REWARDS_WASM, TX_REDELEGATE_WASM, TX_REVEAL_PK, TX_TRANSFER_WASM,
TX_UNBOND_WASM, TX_VOTE_PROPOSAL, TX_WITHDRAW_WASM,
};
use namada::token;
use namada::uint::I256;
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
43 changes: 22 additions & 21 deletions packages/shared/lib/src/sdk/args.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::{BorshDeserialize, BorshSerialize};
use namada::core::ibc::core::host::types::identifiers::{ChannelId, PortId};
use namada::ibc::IbcShieldingData;
use namada::tendermint_rpc;
use namada::tx::data::GasLimit;
use namada::{
use namada_sdk::borsh::{BorshDeserialize, BorshSerialize};
use namada_sdk::ibc::core::host::types::identifiers::{ChannelId, PortId};
use namada_sdk::ibc::IbcShieldingData;
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, Debug)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct RevealPkMsg {
public_key: String,
}
Expand All @@ -29,7 +29,7 @@ impl RevealPkMsg {
}

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

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

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

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

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

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

#[derive(BorshSerialize, BorshDeserialize, Debug)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct ClaimRewardsMsg {
validator: String,
source: Option<String>,
Expand Down Expand Up @@ -379,7 +379,7 @@ pub fn claim_rewards_tx_args(
}

#[derive(BorshSerialize, BorshDeserialize, Debug)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct TransferDataMsg {
owner: String,
token: String,
Expand All @@ -397,7 +397,7 @@ impl TransferDataMsg {
}

#[derive(BorshSerialize, BorshDeserialize, Debug)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct TransferMsg {
sources: Vec<TransferDataMsg>,
targets: Vec<TransferDataMsg>,
Expand All @@ -419,7 +419,7 @@ impl TransferMsg {
}

#[derive(BorshSerialize, BorshDeserialize, Debug)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct TransparentTransferDataMsg {
source: String,
target: String,
Expand All @@ -428,7 +428,7 @@ pub struct TransparentTransferDataMsg {
}

#[derive(BorshSerialize, BorshDeserialize, Debug)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct TransparentTransferMsg {
data: Vec<TransparentTransferDataMsg>,
}
Expand Down Expand Up @@ -481,7 +481,7 @@ pub fn transparent_transfer_tx_args(
}

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

#[derive(BorshSerialize, BorshDeserialize, Debug)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct EthBridgeTransferMsg {
nut: bool,
asset: String,
Expand Down Expand Up @@ -693,6 +693,7 @@ fn tx_msg_into_args(tx_msg: &[u8]) -> Result<args::Tx, JsError> {
use_device: false,
password: None,
memo,
device_transport: Default::default(),
};

Ok(args)
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
30 changes: 15 additions & 15 deletions packages/shared/lib/src/sdk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@ use crate::utils::to_bytes;
use crate::utils::to_js_result;
use gloo_utils::format::JsValueSerdeExt;
use js_sys::Uint8Array;
use namada::address::Address;
use namada::core::borsh::{self, BorshDeserialize, BorshSerialize};
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::{
use namada_sdk::address::Address;
use namada_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use namada_sdk::eth_bridge::bridge_pool::build_bridge_pool_tx;
use namada_sdk::hash::Hash;
use namada_sdk::key::{common, ed25519, SigScheme};
use namada_sdk::masp::ShieldedContext;
use namada_sdk::rpc::query_epoch;
use namada_sdk::signing::SigningTxData;
use namada_sdk::string_encoding::Format;
use namada_sdk::tx::Tx;
use namada_sdk::tx::{
build_batch, build_bond, build_claim_rewards, build_ibc_transfer, build_redelegation,
build_reveal_pk, build_transparent_transfer, build_unbond, build_vote_proposal, build_withdraw,
is_reveal_pk_needed, process_tx, ProcessTxResponse,
};
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 std::str::FromStr;
use wasm_bindgen::{prelude::wasm_bindgen, JsError, JsValue};

#[wasm_bindgen]
#[derive(BorshSerialize, BorshDeserialize)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct BatchTxResult {
hash: String,
is_applied: bool,
}

#[wasm_bindgen]
#[derive(BorshSerialize, BorshDeserialize)]
#[borsh(crate = "namada::core::borsh")]
#[borsh(crate = "namada_sdk::borsh")]
pub struct TxResponse {
code: String,
commitments: Vec<BatchTxResult>,
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
Loading
Loading