From bf68c321f3c40a3181cac2fd0d6d27d3ea583bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Wed, 3 Jan 2024 11:55:00 +0000 Subject: [PATCH] tx_prelude: fix build --- Cargo.lock | 9 ++++++- tx_prelude/Cargo.toml | 18 +++++++++---- tx_prelude/src/account.rs | 4 +-- tx_prelude/src/ibc.rs | 21 +++++++++------- tx_prelude/src/key.rs | 2 +- tx_prelude/src/lib.rs | 43 +++++++++++++++++--------------- tx_prelude/src/pgf.rs | 10 +++++--- tx_prelude/src/proof_of_stake.rs | 2 +- tx_prelude/src/token.rs | 29 ++++++++++----------- 9 files changed, 82 insertions(+), 56 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2ab659eb327..fbe9be60938 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4723,11 +4723,18 @@ name = "namada_tx_prelude" version = "0.28.1" dependencies = [ "borsh", - "borsh-ext", "masp_primitives", + "namada_account", "namada_core", + "namada_governance", + "namada_ibc", "namada_macros", + "namada_parameters", "namada_proof_of_stake", + "namada_storage", + "namada_token", + "namada_tx", + "namada_tx_env", "namada_vm_env", "sha2 0.9.9", "thiserror", diff --git a/tx_prelude/Cargo.toml b/tx_prelude/Cargo.toml index c23d66530e8..f561dfdd3ee 100644 --- a/tx_prelude/Cargo.toml +++ b/tx_prelude/Cargo.toml @@ -16,12 +16,20 @@ version.workspace = true default = [] [dependencies] -namada_core = {path = "../core", default-features = false} -namada_macros = {path = "../macros"} -namada_proof_of_stake = {path = "../proof_of_stake", default-features = false} -namada_vm_env = {path = "../vm_env", default-features = false} +namada_account = { path = "../account" } +namada_core = { path = "../core", default-features = false } +namada_governance = { path = "../governance" } +namada_ibc = { path = "../ibc" } +namada_macros = { path = "../macros" } +namada_parameters = { path = "../parameters" } +namada_proof_of_stake = { path = "../proof_of_stake", default-features = false } +namada_storage = { path = "../storage" } +namada_token = { path = "../token" } +namada_tx = { path = "../tx" } +namada_tx_env = { path = "../tx_env" } +namada_vm_env = { path = "../vm_env", default-features = false } + borsh.workspace = true -borsh-ext.workspace = true masp_primitives.workspace = true sha2.workspace = true thiserror.workspace = true diff --git a/tx_prelude/src/account.rs b/tx_prelude/src/account.rs index da6c213601e..5054411a90d 100644 --- a/tx_prelude/src/account.rs +++ b/tx_prelude/src/account.rs @@ -1,4 +1,4 @@ -use namada_core::types::transaction::account::InitAccount; +use namada_tx::data::account::InitAccount; use super::*; @@ -7,7 +7,7 @@ pub fn init_account( owner: &Address, data: InitAccount, ) -> EnvResult
{ - storage_api::account::init_account_storage( + namada_account::init_account_storage( ctx, owner, &data.public_keys, diff --git a/tx_prelude/src/ibc.rs b/tx_prelude/src/ibc.rs index ebf97e7859a..45a6c6e4480 100644 --- a/tx_prelude/src/ibc.rs +++ b/tx_prelude/src/ibc.rs @@ -3,14 +3,14 @@ use std::cell::RefCell; use std::rc::Rc; -pub use namada_core::ledger::ibc::{ - IbcActions, IbcCommonContext, IbcStorageContext, ProofSpec, TransferModule, -}; -use namada_core::ledger::masp_utils; -use namada_core::ledger::tx_env::TxEnv; use namada_core::types::address::{Address, InternalAddress}; pub use namada_core::types::ibc::{IbcEvent, IbcShieldedTransfer}; use namada_core::types::token::DenominatedAmount; +pub use namada_ibc::{ + IbcActions, IbcCommonContext, IbcStorageContext, ProofSpec, TransferModule, +}; +use namada_token::denom_to_amount; +use namada_tx_env::TxEnv; use crate::token::{burn, mint, transfer}; use crate::{Ctx, Error}; @@ -53,12 +53,15 @@ impl IbcStorageContext for Ctx { &mut self, shielded: &IbcShieldedTransfer, ) -> Result<(), Error> { - masp_utils::handle_masp_tx( + namada_token::utils::handle_masp_tx( self, &shielded.transfer, &shielded.masp_tx, )?; - masp_utils::update_note_commitment_tree(self, &shielded.masp_tx) + namada_token::utils::update_note_commitment_tree( + self, + &shielded.masp_tx, + ) } fn mint_token( @@ -72,7 +75,7 @@ impl IbcStorageContext for Ctx { &Address::Internal(InternalAddress::Ibc), target, token, - amount.to_amount(token, self)?, + denom_to_amount(amount, token, self)?, ) } @@ -82,7 +85,7 @@ impl IbcStorageContext for Ctx { token: &Address, amount: DenominatedAmount, ) -> Result<(), Error> { - burn(self, target, token, amount.to_amount(token, self)?) + burn(self, target, token, denom_to_amount(amount, token, self)?) } fn log_string(&self, message: String) { diff --git a/tx_prelude/src/key.rs b/tx_prelude/src/key.rs index 32a6c2089d3..a273d25cc74 100644 --- a/tx_prelude/src/key.rs +++ b/tx_prelude/src/key.rs @@ -7,5 +7,5 @@ use super::*; /// Reveal a PK of an implicit account - the PK is written into the storage /// of the address derived from the PK. pub fn reveal_pk(ctx: &mut Ctx, pk: &common::PublicKey) -> EnvResult<()> { - storage_api::key::reveal_pk(ctx, pk) + namada_account::reveal_pk(ctx, pk) } diff --git a/tx_prelude/src/lib.rs b/tx_prelude/src/lib.rs index fbb6e03a788..e3a66487440 100644 --- a/tx_prelude/src/lib.rs +++ b/tx_prelude/src/lib.rs @@ -16,34 +16,33 @@ pub mod token; use core::slice; use std::marker::PhantomData; -pub use borsh::{BorshDeserialize, BorshSerialize}; -pub use borsh_ext; -use borsh_ext::BorshSerializeExt; use masp_primitives::transaction::Transaction; -pub use namada_core::ledger::governance::storage as gov_storage; -pub use namada_core::ledger::parameters::storage as parameters_storage; -pub use namada_core::ledger::storage::types::encode; -pub use namada_core::ledger::storage_api::{ - self, governance, iter_prefix, iter_prefix_bytes, Error, OptionExt, - ResultExt, StorageRead, StorageWrite, +pub use namada_core::borsh::{ + BorshDeserialize, BorshSerialize, BorshSerializeExt, }; -pub use namada_core::ledger::tx_env::TxEnv; -pub use namada_core::ledger::{eth_bridge, parameters}; -pub use namada_core::proto::{Section, Tx}; -use namada_core::types::account::AccountPublicKeysMap; +pub use namada_core::ledger::eth_bridge; pub use namada_core::types::address::Address; use namada_core::types::chain::CHAIN_ID_LENGTH; pub use namada_core::types::ethereum_events::EthAddress; use namada_core::types::internal::HostEnvResult; -use namada_core::types::key::common; +use namada_core::types::key::{common, AccountPublicKeysMap}; use namada_core::types::storage::TxIndex; pub use namada_core::types::storage::{ self, BlockHash, BlockHeight, Epoch, Header, BLOCK_HASH_LENGTH, }; -pub use namada_core::types::{eth_bridge_pool, *}; +pub use namada_core::types::{encode, eth_bridge_pool, *}; +pub use namada_governance::storage as gov_storage; pub use namada_macros::transaction; +pub use namada_parameters::storage as parameters_storage; +pub use namada_storage::{ + iter_prefix, iter_prefix_bytes, Error, OptionExt, ResultExt, StorageRead, + StorageWrite, +}; +pub use namada_tx::{Section, Tx}; +pub use namada_tx_env::TxEnv; use namada_vm_env::tx::*; use namada_vm_env::{read_from_buffer, read_key_val_bytes_from_buffer}; +pub use {namada_governance as governance, namada_parameters as parameters}; /// Log a string. The message will be printed at the `tracing::Level::Info`. pub fn log_string>(msg: T) { @@ -105,8 +104,8 @@ impl Ctx { } } -/// Result of `TxEnv`, `storage_api::StorageRead` or `storage_api::StorageWrite` -/// method call +/// Result of `TxEnv`, `namada_storage::StorageRead` or +/// `namada_storage::StorageWrite` method call pub type EnvResult = Result; /// Transaction result @@ -216,10 +215,14 @@ impl StorageRead for Ctx { )) } - fn get_tx_index(&self) -> Result { + fn get_tx_index(&self) -> Result { let tx_index = unsafe { namada_tx_get_tx_index() }; Ok(TxIndex(tx_index)) } + + fn get_pred_epochs(&self) -> namada_storage::Result { + todo!() + } } impl StorageWrite for Ctx { @@ -227,7 +230,7 @@ impl StorageWrite for Ctx { &mut self, key: &storage::Key, val: impl AsRef<[u8]>, - ) -> storage_api::Result<()> { + ) -> namada_storage::Result<()> { let key = key.to_string(); unsafe { namada_tx_write( @@ -240,7 +243,7 @@ impl StorageWrite for Ctx { Ok(()) } - fn delete(&mut self, key: &storage::Key) -> storage_api::Result<()> { + fn delete(&mut self, key: &storage::Key) -> namada_storage::Result<()> { let key = key.to_string(); unsafe { namada_tx_delete(key.as_ptr() as _, key.len() as _) }; Ok(()) diff --git a/tx_prelude/src/pgf.rs b/tx_prelude/src/pgf.rs index 43c19d352f2..ad154add2ef 100644 --- a/tx_prelude/src/pgf.rs +++ b/tx_prelude/src/pgf.rs @@ -1,4 +1,4 @@ -use namada_core::types::transaction::pgf::UpdateStewardCommission; +use namada_tx::data::pgf::UpdateStewardCommission; use super::*; @@ -6,13 +6,17 @@ pub fn update_steward_commission( ctx: &mut Ctx, data: UpdateStewardCommission, ) -> EnvResult<()> { - storage_api::pgf::update_commission(ctx, data.steward, data.commission)?; + namada_governance::pgf::storage::update_commission( + ctx, + data.steward, + data.commission, + )?; Ok(()) } pub fn remove_steward(ctx: &mut Ctx, data: &Address) -> EnvResult<()> { - storage_api::pgf::remove_steward(ctx, data)?; + namada_governance::pgf::storage::remove_steward(ctx, data)?; Ok(()) } diff --git a/tx_prelude/src/proof_of_stake.rs b/tx_prelude/src/proof_of_stake.rs index 3b7883361d0..9a598079f53 100644 --- a/tx_prelude/src/proof_of_stake.rs +++ b/tx_prelude/src/proof_of_stake.rs @@ -2,7 +2,6 @@ use namada_core::types::dec::Dec; use namada_core::types::key::common; -use namada_core::types::transaction::pos::BecomeValidator; use namada_core::types::{key, token}; pub use namada_proof_of_stake::parameters::PosParams; use namada_proof_of_stake::storage::read_pos_params; @@ -14,6 +13,7 @@ use namada_proof_of_stake::{ redelegate_tokens, unbond_tokens, unjail_validator, withdraw_tokens, }; pub use namada_proof_of_stake::{parameters, types}; +use namada_tx::data::pos::BecomeValidator; use super::*; diff --git a/tx_prelude/src/token.rs b/tx_prelude/src/token.rs index 50cdef6c4ed..331b4023061 100644 --- a/tx_prelude/src/token.rs +++ b/tx_prelude/src/token.rs @@ -1,9 +1,10 @@ -pub use namada_core::ledger::masp_utils; use namada_core::types::address::Address; -use namada_core::types::token; -pub use namada_core::types::token::*; +use namada_proof_of_stake::token::storage_key::{ + balance_key, minted_balance_key, minter_key, +}; +pub use namada_token::*; -use super::*; +use crate::{log_string, Ctx, StorageRead, StorageWrite, TxResult}; #[allow(clippy::too_many_arguments)] /// A token transfer that can be used in a transaction. @@ -14,10 +15,10 @@ pub fn transfer( token: &Address, amount: DenominatedAmount, ) -> TxResult { - let amount = amount.to_amount(token, ctx)?; + let amount = denom_to_amount(amount, token, ctx)?; if amount != Amount::default() && src != dest { - let src_key = token::balance_key(token, src); - let dest_key = token::balance_key(token, dest); + let src_key = balance_key(token, src); + let dest_key = balance_key(token, dest); let src_bal: Option = ctx.read(&src_key)?; let mut src_bal = src_bal.unwrap_or_else(|| { log_string(format!("src {} has no balance", src_key)); @@ -41,8 +42,8 @@ pub fn undenominated_transfer( amount: Amount, ) -> TxResult { if amount != Amount::default() && src != dest { - let src_key = token::balance_key(token, src); - let dest_key = token::balance_key(token, dest); + let src_key = balance_key(token, src); + let dest_key = balance_key(token, dest); let src_bal: Option = ctx.read(&src_key)?; let mut src_bal = src_bal.unwrap_or_else(|| { log_string(format!("src {} has no balance", src_key)); @@ -65,18 +66,18 @@ pub fn mint( token: &Address, amount: Amount, ) -> TxResult { - let target_key = token::balance_key(token, target); + let target_key = balance_key(token, target); let mut target_bal: Amount = ctx.read(&target_key)?.unwrap_or_default(); target_bal.receive(&amount); - let minted_key = token::minted_balance_key(token); + let minted_key = minted_balance_key(token); let mut minted_bal: Amount = ctx.read(&minted_key)?.unwrap_or_default(); minted_bal.receive(&amount); ctx.write(&target_key, target_bal)?; ctx.write(&minted_key, minted_bal)?; - let minter_key = token::minter_key(token); + let minter_key = minter_key(token); ctx.write(&minter_key, minter)?; Ok(()) @@ -89,12 +90,12 @@ pub fn burn( token: &Address, amount: Amount, ) -> TxResult { - let target_key = token::balance_key(token, target); + let target_key = balance_key(token, target); let mut target_bal: Amount = ctx.read(&target_key)?.unwrap_or_default(); target_bal.spend(&amount); // burn the minted amount - let minted_key = token::minted_balance_key(token); + let minted_key = minted_balance_key(token); let mut minted_bal: Amount = ctx.read(&minted_key)?.unwrap_or_default(); minted_bal.spend(&amount);