Skip to content

Commit

Permalink
chore: switch to use namada_sdk instead of namada (#890)
Browse files Browse the repository at this point in the history
* chore: switch to use namada_sdk instead of namada

* chore: bump namada_sdk to 0.43.0 (#1029)

* chore: bump namada_sdk to 0.43.0

* fix: import DispatcherCache for Node

---------

Co-authored-by: Justin R. Evans <[email protected]>

---------

Co-authored-by: Mateusz Jasiuk <[email protected]>
Co-authored-by: Justin R. Evans <[email protected]>
  • Loading branch information
3 people authored Aug 21, 2024
1 parent 0b2e7a7 commit 12eb4c4
Show file tree
Hide file tree
Showing 18 changed files with 404 additions and 266 deletions.
409 changes: 261 additions & 148 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.43.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
20 changes: 17 additions & 3 deletions packages/shared/lib/src/sdk/masp/masp_node.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use async_trait::async_trait;
use namada::sdk::{
use namada_sdk::{
borsh::{BorshDeserialize, BorshSerialize},
masp::{ContextSyncStatus, ShieldedContext, ShieldedUtils},
masp::{ContextSyncStatus, DispatcherCache, ShieldedContext, ShieldedUtils},
masp_proofs::prover::LocalTxProver,
};
use wasm_bindgen::{prelude::wasm_bindgen, JsValue};
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 Expand Up @@ -136,6 +136,20 @@ impl ShieldedUtils for NodeShieldedUtils {

Ok(())
}

/// Save a cache of data as part of shielded sync if that
/// process gets interrupted.
async fn cache_save(&self, _cache: &DispatcherCache) -> std::io::Result<()> {
// TODO:
todo!()
}

/// Load a cache of data as part of shielded sync if that
/// process gets interrupted.
async fn cache_load(&self) -> std::io::Result<DispatcherCache> {
// TODO:
todo!()
}
}

fn path_buf_to_js_value(path: PathBuf) -> JsValue {
Expand Down
22 changes: 17 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, DispatcherCache, 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 Expand Up @@ -180,4 +180,16 @@ impl ShieldedUtils for WebShieldedUtils {

Ok(())
}

/// Save a cache of data as part of shielded sync if that
/// process gets interrupted.
async fn cache_save(&self, _cache: &DispatcherCache) -> std::io::Result<()> {
todo!()
}

/// Load a cache of data as part of shielded sync if that
/// process gets interrupted.
async fn cache_load(&self) -> std::io::Result<DispatcherCache> {
todo!()
}
}
Loading

0 comments on commit 12eb4c4

Please sign in to comment.