diff --git a/Cargo.lock b/Cargo.lock index 42692fb29e..6fff41381c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4619,10 +4619,19 @@ dependencies = [ "lazy_static", "masp_primitives", "masp_proofs", + "namada_account", "namada_core", "namada_ethereum_bridge", + "namada_governance", + "namada_ibc", + "namada_parameters", "namada_proof_of_stake", + "namada_state", + "namada_storage", "namada_test_utils", + "namada_token", + "namada_tx", + "namada_vote_ext", "num256", "orion", "owo-colors", diff --git a/account/src/lib.rs b/account/src/lib.rs index be393d9288..faff8c98ff 100644 --- a/account/src/lib.rs +++ b/account/src/lib.rs @@ -7,7 +7,8 @@ mod storage_key; use borsh::{BorshDeserialize, BorshSerialize}; use namada_core::types::address::Address; -use namada_core::types::key::{common, AccountPublicKeysMap}; +use namada_core::types::key::common; +pub use namada_core::types::key::AccountPublicKeysMap; use serde::{Deserialize, Serialize}; pub use storage::*; pub use storage_key::*; diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index f4d23d57b9..843a44b295 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -19,27 +19,17 @@ default = ["tendermint-rpc", "download-params"] multicore = ["masp_proofs/multicore"] -namada-sdk = [ - "tendermint-rpc", - "masp_primitives/transparent-inputs" -] +namada-sdk = ["tendermint-rpc", "masp_primitives/transparent-inputs"] std = ["fd-lock"] # tendermint-rpc support -tendermint-rpc = [ - "async-client", - "dep:tendermint-rpc", -] +tendermint-rpc = ["async-client", "dep:tendermint-rpc"] -wasm-runtime = [ - "namada_core/wasm-runtime", -] +wasm-runtime = ["namada_core/wasm-runtime"] # Enable queries support for an async client -async-client = [ - "async-trait", -] +async-client = ["async-trait"] async-send = [] @@ -56,7 +46,20 @@ testing = [ download-params = ["masp_proofs/download-params"] [dependencies] -async-trait = {version = "0.1.51", optional = true} +namada_account = { path = "../account" } +namada_core = { path = "../core" } +namada_ethereum_bridge = { path = "../ethereum_bridge", default-features = false } +namada_governance = { path = "../governance" } +namada_ibc = { path = "../ibc" } +namada_parameters = { path = "../parameters" } +namada_proof_of_stake = { path = "../proof_of_stake", default-features = false } +namada_state = { path = "../state" } +namada_storage = { path = "../storage" } +namada_token = { path = "../token" } +namada_tx = { path = "../tx" } +namada_vote_ext = { path = "../vote_ext" } + +async-trait = { version = "0.1.51", optional = true } bimap.workspace = true borsh.workspace = true borsh-ext.workspace = true @@ -68,18 +71,15 @@ ethers.workspace = true fd-lock = { workspace = true, optional = true } futures.workspace = true itertools.workspace = true -lazy_static.workspace= true +lazy_static.workspace = true masp_primitives.workspace = true masp_proofs.workspace = true -namada_core = {path = "../core", default-features = false, features = ["rand"]} -namada_ethereum_bridge = {path = "../ethereum_bridge", default-features = false} -namada_proof_of_stake = {path = "../proof_of_stake", default-features = false} num256.workspace = true orion.workspace = true owo-colors = "3.5.0" parse_duration = "2.1.1" paste.workspace = true -proptest = {workspace = true, optional = true} +proptest = { workspace = true, optional = true } prost.workspace = true rand.workspace = true rand_core.workspace = true @@ -88,7 +88,7 @@ serde.workspace = true serde_json.workspace = true sha2.workspace = true slip10_ed25519.workspace = true -tendermint-rpc = {workspace = true, optional = true} +tendermint-rpc = { workspace = true, optional = true } thiserror.workspace = true tiny-bip39.workspace = true tiny-hderive.workspace = true @@ -97,18 +97,25 @@ tracing.workspace = true zeroize.workspace = true [target.'cfg(not(target_family = "wasm"))'.dependencies] -tokio = {workspace = true, features = ["full"]} +tokio = { workspace = true, features = ["full"] } [target.'cfg(target_family = "wasm")'.dependencies] -tokio = {workspace = true, default-features = false, features = ["sync"]} +tokio = { workspace = true, default-features = false, features = ["sync"] } wasmtimer = "0.2.0" [dev-dependencies] assert_matches.workspace = true base58.workspace = true -namada_core = {path = "../core", default-features = false, features = ["rand", "testing"]} -namada_ethereum_bridge = {path = "../ethereum_bridge", default-features = false, features = ["testing"]} -namada_proof_of_stake = {path = "../proof_of_stake", default-features = false, features = ["testing"]} -namada_test_utils = {path = "../test_utils"} +namada_core = { path = "../core", default-features = false, features = [ + "rand", + "testing", +] } +namada_ethereum_bridge = { path = "../ethereum_bridge", default-features = false, features = [ + "testing", +] } +namada_proof_of_stake = { path = "../proof_of_stake", default-features = false, features = [ + "testing", +] } +namada_test_utils = { path = "../test_utils" } proptest.workspace = true tempfile.workspace = true diff --git a/sdk/src/args.rs b/sdk/src/args.rs index c12ecdf537..1fa2a7d323 100644 --- a/sdk/src/args.rs +++ b/sdk/src/args.rs @@ -4,9 +4,6 @@ use std::collections::HashMap; use std::path::PathBuf; use std::time::Duration as StdDuration; -use namada_core::ledger::governance::cli::onchain::{ - DefaultProposal, PgfFundingProposal, PgfStewardProposal, -}; use namada_core::types::address::Address; use namada_core::types::chain::ChainId; use namada_core::types::dec::Dec; @@ -16,8 +13,11 @@ use namada_core::types::key::{common, SchemeType}; use namada_core::types::masp::PaymentAddress; use namada_core::types::storage::Epoch; use namada_core::types::time::DateTimeUtc; -use namada_core::types::transaction::GasLimit; use namada_core::types::{storage, token}; +use namada_governance::cli::onchain::{ + DefaultProposal, PgfFundingProposal, PgfStewardProposal, +}; +use namada_tx::data::GasLimit; use serde::{Deserialize, Serialize}; use zeroize::Zeroizing; @@ -178,7 +178,7 @@ impl TxCustom { pub async fn build( &self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData)> { + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> { tx::build_custom(context, self).await } } @@ -283,7 +283,7 @@ impl TxTransfer { pub async fn build( &mut self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData, Option)> + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData, Option)> { tx::build_transfer(context, self).await } @@ -397,7 +397,7 @@ impl TxIbcTransfer { pub async fn build( &self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData, Option)> + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData, Option)> { tx::build_ibc_transfer(context, self).await } @@ -486,7 +486,7 @@ impl InitProposal { pub async fn build( &self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData)> { + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> { let current_epoch = rpc::query_epoch(context.client()).await?; let governance_parameters = rpc::query_governance_parameters(context.client()).await; @@ -642,7 +642,7 @@ impl VoteProposal { pub async fn build( &self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData)> { + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> { let current_epoch = rpc::query_epoch(context.client()).await?; tx::build_vote_proposal(context, self, current_epoch).await } @@ -714,7 +714,7 @@ impl TxInitAccount { pub async fn build( &self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData)> { + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> { tx::build_init_account(context, self).await } } @@ -868,7 +868,7 @@ impl TxUpdateAccount { pub async fn build( &self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData)> { + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> { tx::build_update_account(context, self).await } } @@ -945,7 +945,7 @@ impl Bond { pub async fn build( &self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData)> { + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> { tx::build_bond(context, self).await } } @@ -972,7 +972,7 @@ impl Unbond { &self, context: &impl Namada, ) -> crate::error::Result<( - crate::proto::Tx, + namada_tx::Tx, SigningTxData, Option<(Epoch, token::Amount)>, )> { @@ -1043,7 +1043,7 @@ impl Redelegate { pub async fn build( &self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData)> { + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> { tx::build_redelegation(context, self).await } } @@ -1124,7 +1124,7 @@ impl RevealPk { pub async fn build( &self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData)> { + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> { tx::build_reveal_pk(context, &self.tx, &self.public_key).await } } @@ -1207,7 +1207,7 @@ impl Withdraw { pub async fn build( &self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData)> { + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> { tx::build_withdraw(context, self).await } } @@ -1243,7 +1243,7 @@ impl ClaimRewards { pub async fn build( &self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData)> { + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> { tx::build_claim_rewards(context, self).await } } @@ -1375,7 +1375,7 @@ impl CommissionRateChange { pub async fn build( &self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData)> { + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> { tx::build_validator_commission_change(context, self).await } } @@ -1435,7 +1435,7 @@ pub struct ConsensusKeyChange { // pub async fn build( // &self, // context: &impl Namada, -// ) -> crate::error::Result<(crate::proto::Tx, SigningTxData, +// ) -> crate::error::Result<(namada_tx::Tx, SigningTxData, // Option)> { // tx::build_change_consensus_key(context, self).await // } @@ -1494,7 +1494,7 @@ impl MetaDataChange { pub async fn build( &self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData)> { + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> { tx::build_validator_metadata_change(context, self).await } } @@ -1549,7 +1549,7 @@ impl UpdateStewardCommission { pub async fn build( &self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData)> { + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> { tx::build_update_steward_commission(context, self).await } } @@ -1597,7 +1597,7 @@ impl ResignSteward { pub async fn build( &self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData)> { + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> { tx::build_resign_steward(context, self).await } } @@ -1645,7 +1645,7 @@ impl TxUnjailValidator { pub async fn build( &self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData)> { + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> { tx::build_unjail_validator(context, self).await } } @@ -1693,7 +1693,7 @@ impl TxDeactivateValidator { pub async fn build( &self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData)> { + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> { tx::build_deactivate_validator(context, self).await } } @@ -1741,7 +1741,7 @@ impl TxReactivateValidator { pub async fn build( &self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData)> { + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> { tx::build_reactivate_validator(context, self).await } } @@ -2273,7 +2273,7 @@ impl EthereumBridgePool { pub async fn build( self, context: &impl Namada, - ) -> crate::error::Result<(crate::proto::Tx, SigningTxData)> { + ) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> { bridge_pool::build_bridge_pool_tx(context, self).await } } diff --git a/sdk/src/error.rs b/sdk/src/error.rs index 18be902d10..0216e3a059 100644 --- a/sdk/src/error.rs +++ b/sdk/src/error.rs @@ -1,11 +1,11 @@ //! Generic Error Type for all of the Shared Crate -use namada_core::proto::Tx; use namada_core::types::address::Address; use namada_core::types::dec::Dec; use namada_core::types::ethereum_events::EthAddress; use namada_core::types::storage; use namada_core::types::storage::Epoch; +use namada_tx::Tx; use prost::EncodeError; use tendermint_rpc::Error as RpcError; use thiserror::Error; diff --git a/sdk/src/eth_bridge/bridge_pool.rs b/sdk/src/eth_bridge/bridge_pool.rs index fa6eba1d02..98c394019d 100644 --- a/sdk/src/eth_bridge/bridge_pool.rs +++ b/sdk/src/eth_bridge/bridge_pool.rs @@ -9,17 +9,19 @@ use borsh_ext::BorshSerializeExt; use ethbridge_bridge_contract::Bridge; use ethers::providers::Middleware; use futures::future::FutureExt; -use namada_core::ledger::eth_bridge::storage::bridge_pool::get_pending_key; -use namada_core::ledger::eth_bridge::storage::wrapped_erc20s; use namada_core::types::address::{Address, InternalAddress}; use namada_core::types::eth_abi::Encode; use namada_core::types::eth_bridge_pool::{ - GasFee, PendingTransfer, TransferToEthereum, TransferToEthereumKind, + erc20_token_address, GasFee, PendingTransfer, TransferToEthereum, + TransferToEthereumKind, }; use namada_core::types::ethereum_events::EthAddress; use namada_core::types::keccak::KeccakHash; -use namada_core::types::token::{balance_key, Amount}; use namada_core::types::voting_power::FractionalVotingPower; +use namada_ethereum_bridge::storage::bridge_pool::get_pending_key; +use namada_token::storage_key::balance_key; +use namada_token::Amount; +use namada_tx::Tx; use owo_colors::OwoColorize; use serde::Serialize; @@ -32,7 +34,6 @@ use crate::error::{ use crate::eth_bridge::ethers::abi::AbiDecode; use crate::internal_macros::echo_error; use crate::io::Io; -use crate::proto::Tx; use crate::queries::{ Client, GenBridgePoolProofReq, GenBridgePoolProofRsp, TransferToErcArgs, TransferToEthereumStatus, RPC, @@ -124,7 +125,7 @@ async fn validate_bridge_pool_tx( fee_payer: Option
, fee_token: Address, ) -> Result { - let token_addr = wrapped_erc20s::token(&asset); + let token_addr = erc20_token_address(&asset); let validate_token_amount = validate_amount(context, amount, &token_addr, force).map(|result| { result.map_err(|e| { @@ -207,7 +208,7 @@ async fn validate_bridge_pool_tx( EthereumBridgeError::InvalidFeeToken(transfer.gas_fee.token), )); } - fee_token if fee_token == &wrapped_erc20s::token(&wnam_addr) => { + fee_token if fee_token == &erc20_token_address(&wnam_addr) => { return Err(Error::EthereumBridge( EthereumBridgeError::InvalidFeeToken(transfer.gas_fee.token), )); @@ -733,7 +734,7 @@ mod recommendations { use namada_core::types::ethereum_events::Uint as EthUint; use namada_core::types::storage::BlockHeight; use namada_core::types::uint::{self, Uint, I256}; - use namada_core::types::vote_extensions::validator_set_update::{ + use namada_vote_ext::validator_set_update::{ EthAddrBook, VotingPowersMap, VotingPowersMapExt, }; diff --git a/sdk/src/eth_bridge/mod.rs b/sdk/src/eth_bridge/mod.rs index cfcc750444..9107798938 100644 --- a/sdk/src/eth_bridge/mod.rs +++ b/sdk/src/eth_bridge/mod.rs @@ -8,11 +8,11 @@ use std::ops::ControlFlow; pub use ethers; use ethers::providers::Middleware; use itertools::Either; -pub use namada_core::ledger::eth_bridge::storage::wrapped_erc20s; pub use namada_core::ledger::eth_bridge::{ADDRESS, INTERNAL_ADDRESS}; pub use namada_core::types::ethereum_structs as structs; pub use namada_ethereum_bridge::storage::eth_bridge_queries::*; pub use namada_ethereum_bridge::storage::parameters::*; +pub use namada_ethereum_bridge::storage::wrapped_erc20s; pub use namada_ethereum_bridge::*; use num256::Uint256; diff --git a/sdk/src/eth_bridge/validator_set.rs b/sdk/src/eth_bridge/validator_set.rs index e92e5c545e..c11b9b62c6 100644 --- a/sdk/src/eth_bridge/validator_set.rs +++ b/sdk/src/eth_bridge/validator_set.rs @@ -14,10 +14,10 @@ use namada_core::hints; use namada_core::types::eth_abi::EncodeCell; use namada_core::types::ethereum_events::EthAddress; use namada_core::types::storage::Epoch; -use namada_core::types::vote_extensions::validator_set_update::{ +use namada_ethereum_bridge::storage::proof::EthereumProof; +use namada_vote_ext::validator_set_update::{ ValidatorSetArgs, VotingPowersMap, }; -use namada_ethereum_bridge::storage::proof::EthereumProof; use super::{block_on_eth_sync, eth_sync_or, eth_sync_or_exit, BlockOnEthSync}; use crate::control_flow::install_shutdown_signal; diff --git a/sdk/src/events/mod.rs b/sdk/src/events/mod.rs index 8c5dc8573f..646fd1b8d3 100644 --- a/sdk/src/events/mod.rs +++ b/sdk/src/events/mod.rs @@ -10,7 +10,7 @@ use std::str::FromStr; use borsh::{BorshDeserialize, BorshSerialize}; use namada_core::types::ethereum_structs::{BpTransferStatus, EthBridgeEvent}; use namada_core::types::ibc::IbcEvent; -use namada_core::types::transaction::TxType; +use namada_tx::data::TxType; use serde_json::Value; // use crate::ledger::governance::utils::ProposalEvent; @@ -126,7 +126,7 @@ impl FromStr for EventType { impl Event { /// Creates a new event with the hash and height of the transaction /// already filled in - pub fn new_tx_event(tx: &crate::proto::Tx, height: u64) -> Self { + pub fn new_tx_event(tx: &namada_tx::Tx, height: u64) -> Self { let mut event = match tx.header().tx_type { TxType::Wrapper(_) => { let mut event = Event { diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 65b4a45cf4..88a7b9edf4 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -1,6 +1,8 @@ extern crate alloc; -pub use namada_core::{ibc, proto, tendermint, tendermint_proto}; +pub use namada_core::{ibc, tendermint, tendermint_proto}; +pub use namada_tx::proto; +use namada_tx::Tx; #[cfg(feature = "tendermint-rpc")] pub use tendermint_rpc; pub use { @@ -42,12 +44,11 @@ use namada_core::types::ethereum_events::EthAddress; use namada_core::types::key::*; use namada_core::types::masp::{TransferSource, TransferTarget}; use namada_core::types::token; -use namada_core::types::transaction::GasLimit; +use namada_tx::data::wrapper::GasLimit; use tokio::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; use crate::io::Io; use crate::masp::{ShieldedContext, ShieldedUtils}; -use crate::proto::Tx; use crate::rpc::{ denominate_amount, format_denominated_amount, query_native_token, }; diff --git a/sdk/src/masp.rs b/sdk/src/masp.rs index 576f311cb1..714fa13e66 100644 --- a/sdk/src/masp.rs +++ b/sdk/src/masp.rs @@ -57,10 +57,10 @@ use namada_core::types::masp::{ use namada_core::types::storage::{BlockHeight, Epoch, Key, KeySeg, TxIndex}; use namada_core::types::time::{DateTimeUtc, DurationSecs}; use namada_core::types::token; -use namada_core::types::token::{ - Change, MaspDenom, Transfer, HEAD_TX_KEY, PIN_KEY_PREFIX, TX_KEY_PREFIX, -}; -use namada_core::types::transaction::WrapperTx; +use namada_token::storage_key::{HEAD_TX_KEY, PIN_KEY_PREFIX, TX_KEY_PREFIX}; +use namada_token::{Change, MaspDenom, Transfer}; +use namada_tx::data::WrapperTx; +use namada_tx::Tx; use rand_core::{CryptoRng, OsRng, RngCore}; use ripemd::Digest as RipemdDigest; use sha2::Digest; @@ -70,7 +70,6 @@ use thiserror::Error; use crate::error::EncodingError; use crate::error::{Error, PinnedBalanceError, QueryError}; use crate::io::Io; -use crate::proto::Tx; use crate::queries::Client; use crate::rpc::{query_conversion, query_storage_value}; use crate::tendermint_rpc::query::Query; @@ -1604,7 +1603,7 @@ impl ShieldedContext { expiration.0.signed_duration_since(current_time.0); let max_expected_time_per_block_key = - namada_core::ledger::parameters::storage::get_max_expected_time_per_block_key(); + namada_parameters::storage::get_max_expected_time_per_block_key(); let max_block_time = crate::rpc::query_storage_value::<_, DurationSecs>( context.client(), diff --git a/sdk/src/queries/mod.rs b/sdk/src/queries/mod.rs index 4dbc5173b8..1813226039 100644 --- a/sdk/src/queries/mod.rs +++ b/sdk/src/queries/mod.rs @@ -2,10 +2,8 @@ //! defined via `router!` macro. // Re-export to show in rustdoc! -use namada_core::ledger::storage::traits::StorageHasher; -use namada_core::ledger::storage::{DBIter, DB}; -use namada_core::ledger::storage_api; use namada_core::types::storage::BlockHeight; +use namada_state::{DBIter, StorageHasher, DB}; pub use shell::Shell; use shell::SHELL; pub use types::{ @@ -18,7 +16,7 @@ pub use self::shell::eth_bridge::{ Erc20FlowControl, GenBridgePoolProofReq, GenBridgePoolProofRsp, TransferToErcArgs, TransferToEthereumStatus, }; -use crate::{MaybeSend, MaybeSync}; +use crate::MaybeSend; #[macro_use] mod router; @@ -40,7 +38,7 @@ router! {RPC, pub fn handle_path( ctx: RequestCtx<'_, D, H, V, T>, request: &RequestQuery, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -55,7 +53,7 @@ where pub fn require_latest_height( ctx: &RequestCtx<'_, D, H, V, T>, request: &RequestQuery, -) -> storage_api::Result<()> +) -> namada_storage::Result<()> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -64,7 +62,7 @@ where && request.height.value() != ctx.wl_storage.storage.get_last_block_height().0 { - return Err(storage_api::Error::new_const( + return Err(namada_storage::Error::new_const( "This query doesn't support arbitrary block heights, only the \ latest committed block height ('0' can be used as a special \ value that means the latest block height)", @@ -75,9 +73,9 @@ where /// For queries that do not support proofs, check that proof is not requested, /// otherwise return an error. -pub fn require_no_proof(request: &RequestQuery) -> storage_api::Result<()> { +pub fn require_no_proof(request: &RequestQuery) -> namada_storage::Result<()> { if request.prove { - return Err(storage_api::Error::new_const( + return Err(namada_storage::Error::new_const( "This query doesn't support proofs", )); } @@ -86,9 +84,9 @@ pub fn require_no_proof(request: &RequestQuery) -> storage_api::Result<()> { /// For queries that don't use request data, require that there are no data /// attached. -pub fn require_no_data(request: &RequestQuery) -> storage_api::Result<()> { +pub fn require_no_data(request: &RequestQuery) -> namada_storage::Result<()> { if !request.data.is_empty() { - return Err(storage_api::Error::new_const( + return Err(namada_storage::Error::new_const( "This query doesn't accept request data", )); } @@ -158,7 +156,7 @@ mod testing { #[cfg_attr(not(feature = "async-send"), async_trait::async_trait(?Send))] impl Client for TestClient where - RPC: Router + MaybeSync, + RPC: Router + crate::MaybeSync, { type Error = std::io::Error; diff --git a/sdk/src/queries/router.rs b/sdk/src/queries/router.rs index d27e612d66..bf55143a2c 100644 --- a/sdk/src/queries/router.rs +++ b/sdk/src/queries/router.rs @@ -759,7 +759,7 @@ macro_rules! router_type { /// Handler functions used in the patterns should have the expected signature: /// ```rust,ignore /// fn handler(ctx: RequestCtx<'_, D, H>, args ...) -/// -> storage_api::Result +/// -> namada_storage::Result /// where /// D: 'static + DB + for<'iter> DBIter<'iter> + Sync, /// H: 'static + StorageHasher + Sync; @@ -769,7 +769,7 @@ macro_rules! router_type { /// `(with_options $handler)` and then the expected signature is: /// ```rust,ignore /// fn handler(ctx: RequestCtx<'_, D, H>, request: &RequestQuery, args -/// ...) -> storage_api::Result> +/// ...) -> namada_storage::Result> /// where /// D: 'static + DB + for<'iter> DBIter<'iter> + Sync, /// H: 'static + StorageHasher + Sync; @@ -791,14 +791,14 @@ macro_rules! router { ctx: $crate::queries::RequestCtx<'_, D, H, V, T>, request: &$crate::queries::RequestQuery, start: usize - ) -> namada_core::ledger::storage_api::Result<$crate::queries::EncodedResponseQuery> + ) -> namada_storage::Result<$crate::queries::EncodedResponseQuery> where - D: 'static + namada_core::ledger::storage::DB + for<'iter> namada_core::ledger::storage::DBIter<'iter> + Sync, - H: 'static + namada_core::ledger::storage::StorageHasher + Sync, + D: 'static + namada_state::DB + for<'iter> namada_state::DBIter<'iter> + Sync, + H: 'static + namada_state::StorageHasher + Sync, { // Import for `.into_storage_result()` - use namada_core::ledger::storage_api::ResultExt; + use namada_storage::ResultExt; // Import helper from this crate used inside the macros use $crate::queries::router::find_next_slash_index; @@ -835,10 +835,9 @@ macro_rules! router { #[cfg(test)] mod test_rpc_handlers { use borsh_ext::BorshSerializeExt; - use namada_core::ledger::storage::{DBIter, StorageHasher, DB}; - use namada_core::ledger::storage_api; use namada_core::types::storage::Epoch; use namada_core::types::token; + use namada_state::{DBIter, StorageHasher, DB}; use crate::queries::{ EncodedResponseQuery, RequestCtx, RequestQuery, ResponseQuery, @@ -857,7 +856,7 @@ mod test_rpc_handlers { pub fn $name( _ctx: RequestCtx<'_, D, H, V, T>, $( $( $param: $param_ty ),* )? - ) -> storage_api::Result + ) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -906,7 +905,7 @@ mod test_rpc_handlers { a1: token::DenominatedAmount, a2: token::DenominatedAmount, a3: Option, - ) -> storage_api::Result + ) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -926,7 +925,7 @@ mod test_rpc_handlers { a2: token::DenominatedAmount, a3: Option, a4: Option, - ) -> storage_api::Result + ) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -944,7 +943,7 @@ mod test_rpc_handlers { pub fn c( _ctx: RequestCtx<'_, D, H, V, T>, _request: &RequestQuery, - ) -> storage_api::Result + ) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -1001,7 +1000,6 @@ mod test_rpc { #[cfg(test)] mod test { - use namada_core::ledger::storage_api; use namada_core::tendermint::block; use namada_core::types::storage::Epoch; use namada_core::types::token; @@ -1013,7 +1011,7 @@ mod test { /// Test all the possible paths in `TEST_RPC` router. #[tokio::test] - async fn test_router_macro() -> storage_api::Result<()> { + async fn test_router_macro() -> namada_storage::Result<()> { let client = TestClient::new(TEST_RPC); // Test request with an invalid path diff --git a/sdk/src/queries/shell.rs b/sdk/src/queries/shell.rs index 813348dacb..a3c64b9b38 100644 --- a/sdk/src/queries/shell.rs +++ b/sdk/src/queries/shell.rs @@ -7,19 +7,18 @@ use borsh_ext::BorshSerializeExt; use masp_primitives::asset_type::AssetType; use masp_primitives::merkle_tree::MerklePath; use masp_primitives::sapling::Node; +use namada_account::{Account, AccountPublicKeysMap}; use namada_core::hints; -use namada_core::ledger::storage::traits::StorageHasher; -use namada_core::ledger::storage::{DBIter, LastBlock, DB}; -use namada_core::ledger::storage_api::{self, ResultExt, StorageRead}; -use namada_core::types::account::{Account, AccountPublicKeysMap}; use namada_core::types::address::Address; use namada_core::types::hash::Hash; use namada_core::types::storage::{ self, BlockHeight, BlockResults, Epoch, KeySeg, PrefixValue, }; use namada_core::types::token::MaspDenom; +use namada_state::{DBIter, LastBlock, StorageHasher, DB}; +use namada_storage::{self, ResultExt, StorageRead}; #[cfg(any(test, feature = "async-client"))] -use namada_core::types::transaction::TxResult; +use namada_tx::data::TxResult; use self::eth_bridge::{EthBridge, ETH_BRIDGE}; use crate::events::log::dumb_queries; @@ -115,7 +114,7 @@ router! {SHELL, fn dry_run_tx( _ctx: RequestCtx<'_, D, H, V, T>, _request: &RequestQuery, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -126,7 +125,7 @@ where /// Query to read block results from storage pub fn read_results( ctx: RequestCtx<'_, D, H, V, T>, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -138,19 +137,19 @@ where ]; for (key, value, _gas) in iter { let key = u64::parse(key.clone()).map_err(|_| { - storage_api::Error::new(std::io::Error::new( + namada_storage::Error::new(std::io::Error::new( std::io::ErrorKind::NotFound, format!("expected integer for block height {}", key), )) })?; let value = BlockResults::try_from_slice(&value).map_err(|_| { - storage_api::Error::new(std::io::Error::new( + namada_storage::Error::new(std::io::Error::new( std::io::ErrorKind::InvalidData, "expected BlockResults bytes", )) })?; let idx: usize = key.try_into().map_err(|_| { - storage_api::Error::new(std::io::Error::new( + namada_storage::Error::new(std::io::Error::new( std::io::ErrorKind::InvalidData, "expected block height to fit into usize", )) @@ -163,7 +162,7 @@ where /// Query to read the conversion state fn read_conversions( ctx: RequestCtx<'_, D, H, V, T>, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -184,7 +183,7 @@ where fn read_conversion( ctx: RequestCtx<'_, D, H, V, T>, asset_type: AssetType, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -207,7 +206,7 @@ where ctx.wl_storage.storage.conversion_state.tree.path(*pos), )) } else { - Err(storage_api::Error::new(std::io::Error::new( + Err(namada_storage::Error::new(std::io::Error::new( std::io::ErrorKind::NotFound, format!("No conversion found for asset type: {}", asset_type), ))) @@ -217,7 +216,7 @@ where /// Query to read the tokens that earn masp rewards. fn masp_reward_tokens( ctx: RequestCtx<'_, D, H, V, T>, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -227,7 +226,7 @@ where fn epoch( ctx: RequestCtx<'_, D, H, V, T>, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -238,7 +237,7 @@ where fn native_token( ctx: RequestCtx<'_, D, H, V, T>, -) -> storage_api::Result
+) -> namada_storage::Result
where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -250,7 +249,7 @@ where fn epoch_at_height( ctx: RequestCtx<'_, D, H, V, T>, height: BlockHeight, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -260,7 +259,7 @@ where fn last_block( ctx: RequestCtx<'_, D, H, V, T>, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -276,7 +275,7 @@ fn storage_value( ctx: RequestCtx<'_, D, H, V, T>, request: &RequestQuery, storage_key: storage::Key, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -295,7 +294,7 @@ where if let Some(past_height_limit) = ctx.storage_read_past_height_limit { if queried_height + past_height_limit < last_committed_height { - return Err(storage_api::Error::new(std::io::Error::new( + return Err(namada_storage::Error::new(std::io::Error::new( std::io::ErrorKind::InvalidInput, format!( "Cannot query more than {past_height_limit} blocks in the \ @@ -353,15 +352,15 @@ fn storage_prefix( ctx: RequestCtx<'_, D, H, V, T>, request: &RequestQuery, storage_key: storage::Key, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, { require_latest_height(&ctx, request)?; - let iter = storage_api::iter_prefix_bytes(ctx.wl_storage, &storage_key)?; - let data: storage_api::Result> = iter + let iter = namada_storage::iter_prefix_bytes(ctx.wl_storage, &storage_key)?; + let data: namada_storage::Result> = iter .map(|iter_result| { let (key, value) = iter_result?; Ok(PrefixValue { key, value }) @@ -408,7 +407,7 @@ where fn storage_has_key( ctx: RequestCtx<'_, D, H, V, T>, storage_key: storage::Key, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -420,7 +419,7 @@ where fn accepted( ctx: RequestCtx<'_, D, H, V, T>, tx_hash: Hash, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -437,7 +436,7 @@ where fn applied( ctx: RequestCtx<'_, D, H, V, T>, tx_hash: Hash, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -455,7 +454,7 @@ fn ibc_client_update( ctx: RequestCtx<'_, D, H, V, T>, client_id: ClientId, consensus_height: BlockHeight, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -480,7 +479,7 @@ fn ibc_packet( destination_port: PortId, destination_channel: ChannelId, sequence: Sequence, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -504,18 +503,16 @@ where fn account( ctx: RequestCtx<'_, D, H, V, T>, owner: Address, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, { - let account_exists = storage_api::account::exists(ctx.wl_storage, &owner)?; + let account_exists = namada_account::exists(ctx.wl_storage, &owner)?; if account_exists { - let public_keys = - storage_api::account::public_keys(ctx.wl_storage, &owner)?; - let threshold = - storage_api::account::threshold(ctx.wl_storage, &owner)?; + let public_keys = namada_account::public_keys(ctx.wl_storage, &owner)?; + let threshold = namada_account::threshold(ctx.wl_storage, &owner)?; Ok(Some(Account { public_keys_map: AccountPublicKeysMap::from_iter(public_keys), @@ -530,13 +527,12 @@ where fn revealed( ctx: RequestCtx<'_, D, H, V, T>, owner: Address, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, { - let public_keys = - storage_api::account::public_keys(ctx.wl_storage, &owner)?; + let public_keys = namada_account::public_keys(ctx.wl_storage, &owner)?; Ok(!public_keys.is_empty()) } @@ -544,6 +540,7 @@ where #[cfg(test)] mod test { use namada_core::types::{address, token}; + use namada_token::storage_key::balance_key; use crate::queries::RPC; @@ -554,7 +551,7 @@ mod test { let token_addr = address::testing::established_address_1(); let owner = address::testing::established_address_2(); - let key = token::balance_key(&token_addr, &owner); + let key = balance_key(&token_addr, &owner); let path = RPC.shell().storage_value_path(&key); assert_eq!(format!("/shell/value/{}", key), path); diff --git a/sdk/src/queries/shell/eth_bridge.rs b/sdk/src/queries/shell/eth_bridge.rs index b113eef1f8..4d59564159 100644 --- a/sdk/src/queries/shell/eth_bridge.rs +++ b/sdk/src/queries/shell/eth_bridge.rs @@ -7,12 +7,6 @@ use std::str::FromStr; use borsh::{BorshDeserialize, BorshSerialize}; use borsh_ext::BorshSerializeExt; use namada_core::hints; -use namada_core::ledger::eth_bridge::storage::bridge_pool::get_key_from_hash; -use namada_core::ledger::storage::merkle_tree::StoreRef; -use namada_core::ledger::storage::{DBIter, StorageHasher, StoreType, DB}; -use namada_core::ledger::storage_api::{ - self, CustomError, ResultExt, StorageRead, -}; use namada_core::types::address::Address; use namada_core::types::eth_abi::{Encode, EncodeCell}; use namada_core::types::eth_bridge_pool::{ @@ -23,16 +17,13 @@ use namada_core::types::ethereum_events::{ }; use namada_core::types::ethereum_structs; use namada_core::types::keccak::KeccakHash; -use namada_core::types::storage::MembershipProof::BridgePool; use namada_core::types::storage::{BlockHeight, DbKeySeg, Epoch, Key}; use namada_core::types::token::Amount; -use namada_core::types::vote_extensions::validator_set_update::{ - ValidatorSetArgs, VotingPowersMap, -}; use namada_core::types::voting_power::FractionalVotingPower; use namada_ethereum_bridge::protocol::transactions::votes::{ EpochedVotingPower, EpochedVotingPowerExt, }; +use namada_ethereum_bridge::storage::bridge_pool::get_key_from_hash; use namada_ethereum_bridge::storage::eth_bridge_queries::EthBridgeQueries; use namada_ethereum_bridge::storage::parameters::UpgradeableContract; use namada_ethereum_bridge::storage::proof::{sort_sigs, EthereumProof}; @@ -41,6 +32,12 @@ use namada_ethereum_bridge::storage::{ bridge_contract_key, native_erc20_key, vote_tallies, }; use namada_proof_of_stake::pos_queries::PosQueries; +use namada_state::MembershipProof::BridgePool; +use namada_state::{DBIter, StorageHasher, StoreRef, StoreType, DB}; +use namada_storage::{self, CustomError, ResultExt, StorageRead}; +use namada_vote_ext::validator_set_update::{ + ValidatorSetArgs, VotingPowersMap, +}; use serde::{Deserialize, Serialize}; use crate::eth_bridge::ethers::abi::AbiDecode; @@ -222,7 +219,7 @@ router! {ETH_BRIDGE, fn pending_eth_transfer_status( ctx: RequestCtx<'_, D, H, V, T>, request: &RequestQuery, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -339,7 +336,7 @@ where fn get_erc20_flow_control( ctx: RequestCtx<'_, D, H, V, T>, asset: EthAddress, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -363,14 +360,14 @@ where fn read_contract( key: &Key, ctx: RequestCtx<'_, D, H, V, U>, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, T: BorshDeserialize, { let Some(contract) = StorageRead::read(ctx.wl_storage, key)? else { - return Err(storage_api::Error::SimpleMessage( + return Err(namada_storage::Error::SimpleMessage( "Failed to read contract: The Ethereum bridge \ storage is not initialized", )); @@ -383,7 +380,7 @@ where #[inline] fn read_bridge_contract( ctx: RequestCtx<'_, D, H, V, T>, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -396,7 +393,7 @@ where #[inline] fn read_native_erc20_contract( ctx: RequestCtx<'_, D, H, V, T>, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -408,7 +405,7 @@ where /// pool. fn read_ethereum_bridge_pool( ctx: RequestCtx<'_, D, H, V, T>, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -423,7 +420,7 @@ where /// pool covered by the latest signed root. fn read_signed_ethereum_bridge_pool( ctx: RequestCtx<'_, D, H, V, T>, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -433,7 +430,7 @@ where .wl_storage .ethbridge_queries() .get_signed_bridge_pool_root() - .ok_or(storage_api::Error::SimpleMessage( + .ok_or(namada_storage::Error::SimpleMessage( "No signed root for the Ethereum bridge pool exists in storage.", )) .into_storage_result()?; @@ -483,7 +480,7 @@ where fn generate_bridge_pool_proof( ctx: RequestCtx<'_, D, H, V, T>, request: &RequestQuery, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -499,7 +496,7 @@ where .wl_storage .ethbridge_queries() .get_signed_bridge_pool_root() - .ok_or(storage_api::Error::SimpleMessage( + .ok_or(namada_storage::Error::SimpleMessage( "No signed root for the Ethereum bridge pool exists in \ storage.", )) @@ -510,7 +507,7 @@ where let latest_bp_nonce = ctx.wl_storage.ethbridge_queries().get_bridge_pool_nonce(); if latest_bp_nonce != signed_root.data.1 { - return Err(storage_api::Error::Custom(CustomError( + return Err(namada_storage::Error::Custom(CustomError( format!( "Mismatch between the nonce in the Bridge pool root proof \ ({}) and the latest Bridge pool nonce in storage ({})", @@ -528,7 +525,7 @@ where .into_storage_result()?; // from the hashes of the transfers, get the actual values. let mut missing_hashes = vec![]; - let (keys, values): (Vec<_>, Vec<_>) = transfer_hashes + let (keys, values): (Vec<_>, Vec>) = transfer_hashes .iter() .filter_map(|hash| { let key = get_key_from_hash(hash); @@ -542,7 +539,7 @@ where }) .unzip(); if !missing_hashes.is_empty() { - return Err(storage_api::Error::Custom(CustomError( + return Err(namada_storage::Error::Custom(CustomError( format!( "One or more of the provided hashes had no corresponding \ transfer in storage: {:?}", @@ -601,10 +598,10 @@ where }) } Ok(_) => unreachable!(), - Err(e) => Err(storage_api::Error::new(e)), + Err(e) => Err(namada_storage::Error::new(e)), } } else { - Err(storage_api::Error::SimpleMessage( + Err(namada_storage::Error::SimpleMessage( "Could not deserialize transfers", )) } @@ -615,7 +612,7 @@ where /// backing each `TransferToEthereum` event. fn transfer_to_ethereum_progress( ctx: RequestCtx<'_, D, H, V, T>, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -690,13 +687,13 @@ where fn read_valset_upd_proof( ctx: RequestCtx<'_, D, H, V, T>, epoch: Epoch, -) -> storage_api::Result>> +) -> namada_storage::Result>> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, { if epoch.0 == 0 { - return Err(storage_api::Error::Custom(CustomError( + return Err(namada_storage::Error::Custom(CustomError( "Validator set update proofs should only be requested from epoch \ 1 onwards" .into(), @@ -704,7 +701,7 @@ where } let current_epoch = ctx.wl_storage.storage.last_epoch; if epoch > current_epoch.next() { - return Err(storage_api::Error::Custom(CustomError( + return Err(namada_storage::Error::Custom(CustomError( format!( "Requesting validator set update proof for {epoch:?}, but the \ last installed epoch is still {current_epoch:?}" @@ -714,7 +711,7 @@ where } if !ctx.wl_storage.ethbridge_queries().valset_upd_seen(epoch) { - return Err(storage_api::Error::Custom(CustomError( + return Err(namada_storage::Error::Custom(CustomError( format!( "Validator set update proof is not yet available for the \ queried epoch: {epoch:?}" @@ -740,14 +737,14 @@ where fn read_bridge_valset( ctx: RequestCtx<'_, D, H, V, T>, epoch: Epoch, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, { let current_epoch = ctx.wl_storage.storage.last_epoch; if epoch > current_epoch.next() { - Err(storage_api::Error::Custom(CustomError( + Err(namada_storage::Error::Custom(CustomError( format!( "Requesting Bridge validator set at {epoch:?}, but the last \ installed epoch is still {current_epoch:?}" @@ -770,14 +767,14 @@ where fn read_governance_valset( ctx: RequestCtx<'_, D, H, V, T>, epoch: Epoch, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, { let current_epoch = ctx.wl_storage.storage.last_epoch; if epoch > current_epoch.next() { - Err(storage_api::Error::Custom(CustomError( + Err(namada_storage::Error::Custom(CustomError( format!( "Requesting Governance validator set at {epoch:?}, but the \ last installed epoch is still {current_epoch:?}" @@ -798,14 +795,14 @@ where fn voting_powers_at_height( ctx: RequestCtx<'_, D, H, V, T>, height: BlockHeight, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, { let maybe_epoch = ctx.wl_storage.pos_queries().get_epoch(height); let Some(epoch) = maybe_epoch else { - return Err(storage_api::Error::SimpleMessage( + return Err(namada_storage::Error::SimpleMessage( "The epoch of the requested height does not exist", )); }; @@ -817,14 +814,14 @@ where fn voting_powers_at_epoch( ctx: RequestCtx<'_, D, H, V, T>, epoch: Epoch, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, { let current_epoch = ctx.wl_storage.storage.get_current_epoch().0; if epoch > current_epoch + 1u64 { - return Err(storage_api::Error::SimpleMessage( + return Err(namada_storage::Error::SimpleMessage( "The requested epoch cannot be queried", )); } @@ -845,7 +842,6 @@ mod test_ethbridge_router { }; use namada_core::ledger::eth_bridge::storage::whitelist; use namada_core::ledger::storage::mockdb::MockDBWriteBatch; - use namada_core::ledger::storage_api::StorageWrite; use namada_core::types::address::nam; use namada_core::types::address::testing::established_address_1; use namada_core::types::eth_abi::Encode; @@ -864,6 +860,7 @@ mod test_ethbridge_router { use namada_ethereum_bridge::protocol::transactions::validator_set_update::aggregate_votes; use namada_ethereum_bridge::storage::proof::BridgePoolRootProof; use namada_proof_of_stake::pos_queries::PosQueries; + use namada_storage::StorageWrite; use super::test_utils::bertha_address; use super::*; diff --git a/sdk/src/queries/types.rs b/sdk/src/queries/types.rs index a9e2fb3566..6263a5419d 100644 --- a/sdk/src/queries/types.rs +++ b/sdk/src/queries/types.rs @@ -1,8 +1,7 @@ use std::fmt::Debug; -use namada_core::ledger::storage::{DBIter, StorageHasher, WlStorage, DB}; -use namada_core::ledger::storage_api; use namada_core::types::storage::BlockHeight; +use namada_state::{DBIter, StorageHasher, WlStorage, DB}; use thiserror::Error; use crate::events::log::EventLog; @@ -39,7 +38,7 @@ pub trait Router { &self, ctx: RequestCtx<'_, D, H, V, T>, request: &RequestQuery, - ) -> storage_api::Result + ) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -58,7 +57,7 @@ pub trait Router { ctx: RequestCtx<'_, D, H, V, T>, request: &RequestQuery, start: usize, - ) -> storage_api::Result + ) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync; diff --git a/sdk/src/queries/vp/governance.rs b/sdk/src/queries/vp/governance.rs index 1e3a5a8ece..28368ca76b 100644 --- a/sdk/src/queries/vp/governance.rs +++ b/sdk/src/queries/vp/governance.rs @@ -1,10 +1,9 @@ // cd shared && cargo expand ledger::queries::vp::governance -use namada_core::ledger::governance::parameters::GovernanceParameters; -use namada_core::ledger::governance::storage::proposal::StorageProposal; -use namada_core::ledger::governance::utils::Vote; -use namada_core::ledger::storage::{DBIter, StorageHasher, DB}; -use namada_core::ledger::storage_api; +use namada_governance::parameters::GovernanceParameters; +use namada_governance::storage::proposal::StorageProposal; +use namada_governance::utils::Vote; +use namada_state::{DBIter, StorageHasher, DB}; use crate::queries::types::RequestCtx; @@ -19,33 +18,33 @@ router! {GOV, fn proposal_id( ctx: RequestCtx<'_, D, H, V, T>, id: u64, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, { - storage_api::governance::get_proposal_by_id(ctx.wl_storage, id) + namada_governance::storage::get_proposal_by_id(ctx.wl_storage, id) } /// Find if the given address belongs to a validator account. fn proposal_id_votes( ctx: RequestCtx<'_, D, H, V, T>, id: u64, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, { - storage_api::governance::get_proposal_votes(ctx.wl_storage, id) + namada_governance::storage::get_proposal_votes(ctx.wl_storage, id) } /// Get the governane parameters fn parameters( ctx: RequestCtx<'_, D, H, V, T>, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, { - storage_api::governance::get_parameters(ctx.wl_storage) + namada_governance::storage::get_parameters(ctx.wl_storage) } diff --git a/sdk/src/queries/vp/pgf.rs b/sdk/src/queries/vp/pgf.rs index a7400f2732..4b8431e854 100644 --- a/sdk/src/queries/vp/pgf.rs +++ b/sdk/src/queries/vp/pgf.rs @@ -1,9 +1,8 @@ -use namada_core::ledger::governance::storage::proposal::StoragePgfFunding; -use namada_core::ledger::pgf::parameters::PgfParameters; -use namada_core::ledger::pgf::storage::steward::StewardDetail; -use namada_core::ledger::storage::{DBIter, StorageHasher, DB}; -use namada_core::ledger::storage_api; use namada_core::types::address::Address; +use namada_governance::pgf::parameters::PgfParameters; +use namada_governance::pgf::storage::steward::StewardDetail; +use namada_governance::storage::proposal::StoragePgfFunding; +use namada_state::{DBIter, StorageHasher, DB}; use crate::queries::types::RequestCtx; @@ -18,44 +17,44 @@ router! {PGF, /// Query the current pgf steward set fn stewards( ctx: RequestCtx<'_, D, H, V, T>, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, { - storage_api::pgf::get_stewards(ctx.wl_storage) + namada_governance::pgf::storage::get_stewards(ctx.wl_storage) } /// Check if an address is a pgf steward fn is_steward( ctx: RequestCtx<'_, D, H, V, T>, address: Address, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, { - storage_api::pgf::is_steward(ctx.wl_storage, &address) + namada_governance::pgf::storage::is_steward(ctx.wl_storage, &address) } /// Query the continuous pgf fundings fn funding( ctx: RequestCtx<'_, D, H, V, T>, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, { - storage_api::pgf::get_payments(ctx.wl_storage) + namada_governance::pgf::storage::get_payments(ctx.wl_storage) } /// Query the PGF parameters fn parameters( ctx: RequestCtx<'_, D, H, V, T>, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, { - storage_api::pgf::get_parameters(ctx.wl_storage) + namada_governance::pgf::storage::get_parameters(ctx.wl_storage) } diff --git a/sdk/src/queries/vp/pos.rs b/sdk/src/queries/vp/pos.rs index ff1b073dc4..0c06b51cb7 100644 --- a/sdk/src/queries/vp/pos.rs +++ b/sdk/src/queries/vp/pos.rs @@ -3,10 +3,6 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; -use namada_core::ledger::storage::{DBIter, StorageHasher, DB}; -use namada_core::ledger::storage_api; -use namada_core::ledger::storage_api::collections::lazy_map; -use namada_core::ledger::storage_api::OptionExt; use namada_core::types::address::Address; use namada_core::types::key::common; use namada_core::types::storage::Epoch; @@ -34,6 +30,9 @@ use namada_proof_of_stake::types::{ Slash, ValidatorMetaData, ValidatorState, WeightedValidator, }; use namada_proof_of_stake::{self, bond_amount, query_reward_tokens}; +use namada_state::{DBIter, StorageHasher, DB}; +use namada_storage::collections::lazy_map; +use namada_storage::OptionExt; use crate::queries::types::RequestCtx; @@ -174,7 +173,7 @@ impl Enriched { /// Get the PoS parameters fn pos_params( ctx: RequestCtx<'_, D, H, V, T>, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -186,7 +185,7 @@ where fn is_validator( ctx: RequestCtx<'_, D, H, V, T>, addr: Address, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -199,7 +198,7 @@ fn is_delegator( ctx: RequestCtx<'_, D, H, V, T>, addr: Address, epoch: Option, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -212,7 +211,7 @@ where fn validator_addresses( ctx: RequestCtx<'_, D, H, V, T>, epoch: Option, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -226,7 +225,7 @@ fn validator_commission( ctx: RequestCtx<'_, D, H, V, T>, validator: Address, epoch: Option, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -256,7 +255,7 @@ where fn validator_metadata( ctx: RequestCtx<'_, D, H, V, T>, validator: Address, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -284,7 +283,7 @@ fn validator_state( ctx: RequestCtx<'_, D, H, V, T>, validator: Address, epoch: Option, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -303,7 +302,7 @@ where fn validator_last_infraction_epoch( ctx: RequestCtx<'_, D, H, V, T>, validator: Address, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -320,7 +319,7 @@ fn validator_stake( ctx: RequestCtx<'_, D, H, V, T>, validator: Address, epoch: Option, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -342,7 +341,7 @@ fn validator_incoming_redelegation( ctx: RequestCtx<'_, D, H, V, T>, src_validator: Address, delegator: Address, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -355,7 +354,7 @@ where fn consensus_validator_set( ctx: RequestCtx<'_, D, H, V, T>, epoch: Option, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -368,7 +367,7 @@ where fn below_capacity_validator_set( ctx: RequestCtx<'_, D, H, V, T>, epoch: Option, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -384,7 +383,7 @@ where fn total_stake( ctx: RequestCtx<'_, D, H, V, T>, epoch: Option, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -398,7 +397,7 @@ fn bond_deltas( ctx: RequestCtx<'_, D, H, V, T>, source: Address, validator: Address, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -413,7 +412,7 @@ fn bond( source: Address, validator: Address, epoch: Option, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -433,7 +432,7 @@ fn bond_with_slashing( source: Address, validator: Address, epoch: Option, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -448,7 +447,7 @@ fn unbond( ctx: RequestCtx<'_, D, H, V, T>, source: Address, validator: Address, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -473,7 +472,7 @@ fn unbond_with_slashing( ctx: RequestCtx<'_, D, H, V, T>, source: Address, validator: Address, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -500,7 +499,7 @@ fn withdrawable_tokens( source: Address, validator: Address, epoch: Option, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -528,7 +527,7 @@ fn rewards( ctx: RequestCtx<'_, D, H, V, T>, validator: Address, source: Option
, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -546,7 +545,7 @@ fn bonds_and_unbonds( ctx: RequestCtx<'_, D, H, V, T>, source: Option
, validator: Option
, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -563,7 +562,7 @@ where fn delegation_validators( ctx: RequestCtx<'_, D, H, V, T>, owner: Address, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -577,7 +576,7 @@ fn delegations( ctx: RequestCtx<'_, D, H, V, T>, owner: Address, epoch: Option, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -590,7 +589,7 @@ where fn validator_slashes( ctx: RequestCtx<'_, D, H, V, T>, validator: Address, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -602,7 +601,7 @@ where /// All slashes fn slashes( ctx: RequestCtx<'_, D, H, V, T>, -) -> storage_api::Result>> +) -> namada_storage::Result>> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -613,7 +612,7 @@ where /// Enqueued slashes fn enqueued_slashes( ctx: RequestCtx<'_, D, H, V, T>, -) -> storage_api::Result>>> +) -> namada_storage::Result>>> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -626,7 +625,7 @@ where fn validator_by_tm_addr( ctx: RequestCtx<'_, D, H, V, T>, tm_addr: String, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -640,7 +639,7 @@ where /// Native validator address by looking up the Tendermint address fn consensus_key_set( ctx: RequestCtx<'_, D, H, V, T>, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -652,7 +651,7 @@ where fn has_bonds( ctx: RequestCtx<'_, D, H, V, T>, source: Address, -) -> storage_api::Result +) -> namada_storage::Result where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, diff --git a/sdk/src/queries/vp/token.rs b/sdk/src/queries/vp/token.rs index 5e2e5aa95b..b885e4dc66 100644 --- a/sdk/src/queries/vp/token.rs +++ b/sdk/src/queries/vp/token.rs @@ -1,10 +1,9 @@ //! Token validity predicate queries -use namada_core::ledger::storage::{DBIter, StorageHasher, DB}; -use namada_core::ledger::storage_api; -use namada_core::ledger::storage_api::token::read_denom; use namada_core::types::address::Address; use namada_core::types::token; +use namada_state::{DBIter, StorageHasher, DB}; +use namada_token::read_denom; use crate::queries::RequestCtx; @@ -17,7 +16,7 @@ router! {TOKEN, fn denomination( ctx: RequestCtx<'_, D, H, V, T>, addr: Address, -) -> storage_api::Result> +) -> namada_storage::Result> where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, @@ -30,6 +29,7 @@ pub mod client_only_methods { use borsh::BorshDeserialize; use namada_core::types::address::Address; use namada_core::types::token; + use namada_token::storage_key::balance_key; use super::Token; use crate::queries::{Client, RPC}; @@ -45,7 +45,7 @@ pub mod client_only_methods { where CLIENT: Client + Sync, { - let balance_key = token::balance_key(token, owner); + let balance_key = balance_key(token, owner); let response = RPC .shell() .storage_value(client, None, None, false, &balance_key) diff --git a/sdk/src/rpc.rs b/sdk/src/rpc.rs index 2bb7192a89..9f58e24217 100644 --- a/sdk/src/rpc.rs +++ b/sdk/src/rpc.rs @@ -9,14 +9,7 @@ use borsh::BorshDeserialize; use masp_primitives::asset_type::AssetType; use masp_primitives::merkle_tree::MerklePath; use masp_primitives::sapling::Node; -use namada_core::ledger::governance::parameters::GovernanceParameters; -use namada_core::ledger::governance::storage::proposal::StorageProposal; -use namada_core::ledger::governance::utils::Vote; -use namada_core::ledger::ibc::storage::{ - ibc_denom_key, ibc_denom_key_prefix, is_ibc_denom_key, -}; -use namada_core::ledger::storage::LastBlock; -use namada_core::types::account::Account; +use namada_account::Account; use namada_core::types::address::{Address, InternalAddress}; use namada_core::types::hash::Hash; use namada_core::types::key::common; @@ -26,12 +19,19 @@ use namada_core::types::storage::{ use namada_core::types::token::{ Amount, DenominatedAmount, Denomination, MaspDenom, }; -use namada_core::types::transaction::{ResultCode, TxResult}; use namada_core::types::{storage, token}; +use namada_governance::parameters::GovernanceParameters; +use namada_governance::storage::proposal::StorageProposal; +use namada_governance::utils::Vote; +use namada_ibc::storage::{ + ibc_denom_key, ibc_denom_key_prefix, is_ibc_denom_key, +}; use namada_proof_of_stake::parameters::PosParams; use namada_proof_of_stake::types::{ BondsAndUnbondsDetails, CommissionPair, ValidatorMetaData, ValidatorState, }; +use namada_state::LastBlock; +use namada_tx::data::{ResultCode, TxResult}; use serde::Serialize; use crate::args::InputAmount; @@ -40,7 +40,6 @@ use crate::error::{EncodingError, Error, QueryError, TxError}; use crate::events::Event; use crate::internal_macros::echo_error; use crate::io::Io; -use crate::proto::Tx; use crate::queries::vp::pos::EnrichedBondsAndUnbondsDetails; use crate::queries::{Client, RPC}; use crate::tendermint::block::Height; @@ -48,7 +47,7 @@ use crate::tendermint::merkle::proof::ProofOps; use crate::tendermint_rpc::error::Error as TError; use crate::tendermint_rpc::query::Query; use crate::tendermint_rpc::Order; -use crate::{display_line, edisplay_line, error, Namada}; +use crate::{display_line, edisplay_line, error, Namada, Tx}; /// Query the status of a given transaction. /// @@ -484,7 +483,7 @@ pub async fn query_tx_events( pub async fn dry_run_tx( context: &N, tx_bytes: Vec, -) -> Result { +) -> Result { let (data, height, prove) = (Some(tx_bytes), None, false); let result = convert_response::( RPC.shell() diff --git a/sdk/src/signing.rs b/sdk/src/signing.rs index 38aec72d4b..23ed003bdd 100644 --- a/sdk/src/signing.rs +++ b/sdk/src/signing.rs @@ -10,26 +10,29 @@ use masp_primitives::asset_type::AssetType; use masp_primitives::transaction::components::sapling::fees::{ InputView, OutputView, }; -use namada_core::ledger::parameters::storage as parameter_storage; -use namada_core::proto::SignatureIndex; -use namada_core::types::account::AccountPublicKeysMap; +use namada_account::AccountPublicKeysMap; use namada_core::types::address::{ masp_tx_key, Address, ImplicitAddress, InternalAddress, MASP, }; use namada_core::types::key::*; use namada_core::types::masp::{ExtendedViewingKey, PaymentAddress}; +use namada_core::types::sign::SignatureIndex; use namada_core::types::storage::Epoch; use namada_core::types::token; use namada_core::types::token::Transfer; // use namada_core::types::storage::Key; use namada_core::types::token::{Amount, DenominatedAmount, MaspDenom}; -use namada_core::types::transaction::account::{InitAccount, UpdateAccount}; -use namada_core::types::transaction::governance::{ - InitProposalData, VoteProposalData, +use namada_governance::storage::proposal::{ + InitProposalData, ProposalType, VoteProposalData, }; -use namada_core::types::transaction::pgf::UpdateStewardCommission; -use namada_core::types::transaction::pos::BecomeValidator; -use namada_core::types::transaction::{pos, Fee}; +use namada_governance::storage::vote::{StorageProposalVote, VoteType}; +use namada_parameters::storage as parameter_storage; +use namada_token::storage_key::balance_key; +use namada_tx::data::account::{InitAccount, UpdateAccount}; +use namada_tx::data::pgf::UpdateStewardCommission; +use namada_tx::data::pos::BecomeValidator; +use namada_tx::data::{pos, Fee}; +use namada_tx::{MaspBuilder, Section, Tx}; use prost::Message; use rand::rngs::OsRng; use serde::{Deserialize, Serialize}; @@ -38,17 +41,12 @@ use tokio::sync::RwLock; use super::masp::{ShieldedContext, ShieldedTransfer}; use crate::args::SdkTypes; -use crate::core::ledger::governance::storage::proposal::ProposalType; -use crate::core::ledger::governance::storage::vote::{ - StorageProposalVote, VoteType, -}; use crate::core::types::eth_bridge_pool::PendingTransfer; use crate::error::{EncodingError, Error, TxError}; use crate::ibc::apps::transfer::types::msgs::transfer::MsgTransfer; use crate::ibc::primitives::proto::Any; use crate::io::*; use crate::masp::make_asset_type; -use crate::proto::{MaspBuilder, Section, Tx}; use crate::rpc::validate_amount; use crate::tx::{ TX_BECOME_VALIDATOR_WASM, TX_BOND_WASM, TX_BRIDGE_POOL_WASM, @@ -509,8 +507,7 @@ pub async fn wrap_tx( token, }) if token == args.fee_token && source == fee_payer_address => balance, _ => { - let balance_key = - token::balance_key(&args.fee_token, &fee_payer_address); + let balance_key = balance_key(&args.fee_token, &fee_payer_address); rpc::query_storage_value::<_, token::Amount>( context.client(), diff --git a/sdk/src/tx.rs b/sdk/src/tx.rs index de0474615b..63efb8b086 100644 --- a/sdk/src/tx.rs +++ b/sdk/src/tx.rs @@ -24,14 +24,6 @@ use namada_core::ibc::core::channel::types::timeout::TimeoutHeight; use namada_core::ibc::core::client::types::Height as IbcHeight; use namada_core::ibc::core::host::types::identifiers::{ChannelId, PortId}; use namada_core::ibc::primitives::{Msg, Timestamp as IbcTimestamp}; -use namada_core::ledger::governance::cli::onchain::{ - DefaultProposal, OnChainProposal, PgfFundingProposal, PgfStewardProposal, - ProposalVote, -}; -use namada_core::ledger::governance::storage::proposal::ProposalType; -use namada_core::ledger::governance::storage::vote::StorageProposalVote; -use namada_core::ledger::ibc::storage::channel_key; -use namada_core::ledger::pgf::cli::steward::Commission; use namada_core::types::address::{Address, InternalAddress, MASP}; use namada_core::types::dec::Dec; use namada_core::types::hash::Hash; @@ -41,15 +33,24 @@ use namada_core::types::masp::{TransferSource, TransferTarget}; use namada_core::types::storage::Epoch; use namada_core::types::time::DateTimeUtc; use namada_core::types::token::MaspDenom; -use namada_core::types::transaction::account::{InitAccount, UpdateAccount}; -use namada_core::types::transaction::governance::{ - InitProposalData, VoteProposalData, -}; -use namada_core::types::transaction::pgf::UpdateStewardCommission; -use namada_core::types::transaction::{pos, ResultCode, TxResult}; use namada_core::types::{storage, token}; +use namada_governance::cli::onchain::{ + DefaultProposal, OnChainProposal, PgfFundingProposal, PgfStewardProposal, + ProposalVote, +}; +use namada_governance::pgf::cli::steward::Commission; +use namada_governance::storage::proposal::{ + InitProposalData, ProposalType, VoteProposalData, +}; +use namada_governance::storage::vote::StorageProposalVote; +use namada_ibc::storage::channel_key; use namada_proof_of_stake::parameters::PosParams; use namada_proof_of_stake::types::{CommissionPair, ValidatorState}; +use namada_token::storage_key::balance_key; +use namada_tx::data::account::{InitAccount, UpdateAccount}; +use namada_tx::data::pgf::UpdateStewardCommission; +use namada_tx::data::{pos, ResultCode, TxResult}; +use namada_tx::{MaspBuilder, Tx}; use crate::args::{self, InputAmount}; use crate::control_flow::time; @@ -57,7 +58,6 @@ use crate::error::{EncodingError, Error, QueryError, Result, TxError}; use crate::io::Io; use crate::masp::TransferErr::Build; use crate::masp::{make_asset_type, ShieldedContext, ShieldedTransfer}; -use crate::proto::{MaspBuilder, Tx}; use crate::queries::Client; use crate::rpc::{ self, query_wasm_code_hash, validate_amount, InnerTxResult, @@ -1716,7 +1716,7 @@ pub async fn build_bond( // Check bond's source (source for delegation or validator for self-bonds) // balance let bond_source = source.as_ref().unwrap_or(&validator); - let balance_key = token::balance_key(native_token, bond_source); + let balance_key = balance_key(native_token, bond_source); // TODO Should we state the same error message for the native token? let post_balance = check_balance_too_low_err( @@ -2015,7 +2015,7 @@ pub async fn build_ibc_transfer( } // Check source balance - let balance_key = token::balance_key(&args.token, &source); + let balance_key = balance_key(&args.token, &source); let post_balance = check_balance_too_low_err( &args.token, @@ -2307,7 +2307,7 @@ pub async fn build_transfer( // Check that the target address exists on chain target_exists_or_err(target.clone(), args.tx.force, context).await?; // Check source balance - let balance_key = token::balance_key(&args.token, &source); + let balance_key = balance_key(&args.token, &source); // validate the amount given let validated_amount = @@ -2657,7 +2657,7 @@ pub async fn gen_ibc_shielded_transfer( let prefixed_denom = ibc_denom .parse() .map_err(|_| Error::Other(format!("Invalid IBC denom: {ibc_denom}")))?; - let token = namada_core::ledger::ibc::received_ibc_token( + let token = namada_ibc::received_ibc_token( &prefixed_denom, &src_port_id, &src_channel_id, diff --git a/state/src/lib.rs b/state/src/lib.rs index 94d195b4bf..84d0a5ab16 100644 --- a/state/src/lib.rs +++ b/state/src/lib.rs @@ -33,11 +33,10 @@ use namada_gas::{ MEMORY_ACCESS_GAS_PER_BYTE, STORAGE_ACCESS_GAS_PER_BYTE, STORAGE_WRITE_GAS_PER_BYTE, }; -use namada_merkle_tree::{ - Error as MerkleTreeError, MembershipProof, MerkleRoot, -}; +use namada_merkle_tree::{Error as MerkleTreeError, MerkleRoot}; pub use namada_merkle_tree::{ - MerkleTree, MerkleTreeStoresRead, MerkleTreeStoresWrite, StoreType, + MembershipProof, MerkleTree, MerkleTreeStoresRead, MerkleTreeStoresWrite, + StoreRef, StoreType, }; use namada_parameters::{self, EpochDuration, Parameters}; use thiserror::Error;