Skip to content

Commit

Permalink
Renamed some data structures.
Browse files Browse the repository at this point in the history
  • Loading branch information
murisi committed Jul 1, 2024
1 parent ddded01 commit 6110726
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 61 deletions.
4 changes: 2 additions & 2 deletions crates/benches/host_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use namada::core::account::AccountPublicKeysMap;
use namada::core::address;
use namada::core::collections::{HashMap, HashSet};
use namada::ledger::storage::DB;
use namada::token::{Amount, Transfer, TransferData};
use namada::token::{Amount, Transfer, TransparentTransfer};
use namada::tx::Authorization;
use namada::vm::wasm::TxCache;
use namada_apps_lib::wallet::defaults;
Expand All @@ -17,7 +17,7 @@ use namada_node::bench_utils::{
// transaction
fn tx_section_signature_validation(c: &mut Criterion) {
let shell = BenchShell::default();
let transfer_data = Transfer::transparent(vec![TransferData {
let transfer_data = Transfer::transparent(vec![TransparentTransfer {
source: defaults::albert_address(),
target: defaults::bertha_address(),
token: address::testing::nam(),
Expand Down
4 changes: 2 additions & 2 deletions crates/benches/native_vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use namada::sdk::masp_primitives::merkle_tree::CommitmentTree;
use namada::sdk::masp_primitives::transaction::Transaction;
use namada::sdk::masp_proofs::sapling::SaplingVerificationContextInner;
use namada::state::{Epoch, StorageRead, StorageWrite, TxIndex};
use namada::token::{Amount, Transfer, TransferData};
use namada::token::{Amount, Transfer, TransparentTransfer};
use namada::tx::{BatchedTx, Code, Section, Tx};
use namada_apps_lib::wallet::defaults;
use namada_node::bench_utils::{
Expand Down Expand Up @@ -475,7 +475,7 @@ fn vp_multitoken(c: &mut Criterion) {

let transfer = shell.generate_tx(
TX_TRANSFER_WASM,
Transfer::transparent(vec![TransferData {
Transfer::transparent(vec![TransparentTransfer {
source: defaults::albert_address(),
target: defaults::bertha_address(),
token: address::testing::nam(),
Expand Down
4 changes: 2 additions & 2 deletions crates/benches/process_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use namada::core::address;
use namada::core::key::RefTo;
use namada::core::storage::BlockHeight;
use namada::core::time::DateTimeUtc;
use namada::token::{Amount, DenominatedAmount, Transfer, TransferData};
use namada::token::{Amount, DenominatedAmount, Transfer, TransparentTransfer};
use namada::tx::data::{Fee, WrapperTx};
use namada::tx::Authorization;
use namada_apps_lib::wallet::defaults;
Expand All @@ -19,7 +19,7 @@ fn process_tx(c: &mut Criterion) {

let mut batched_tx = shell.generate_tx(
TX_TRANSFER_WASM,
Transfer::transparent(vec![TransferData {
Transfer::transparent(vec![TransparentTransfer {
source: defaults::albert_address(),
target: defaults::bertha_address(),
token: address::testing::nam(),
Expand Down
15 changes: 9 additions & 6 deletions crates/light_sdk/src/transaction/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use namada_sdk::address::Address;
use namada_sdk::hash::Hash;
use namada_sdk::key::common;
use namada_sdk::token::transaction::Transaction;
use namada_sdk::token::TransferData;
use namada_sdk::token::TransparentTransfer;
pub use namada_sdk::token::{DenominatedAmount, Transfer};
use namada_sdk::tx::data::GasLimit;
use namada_sdk::tx::{Authorization, Tx, TxError, TX_TRANSFER_WASM};
Expand All @@ -16,9 +16,12 @@ pub struct TransferBuilder(Tx);

impl TransferBuilder {
/// Build a transparent transfer transaction from the given parameters
pub fn transparent(transfers: Vec<TransferData>, args: GlobalArgs) -> Self {
pub fn transparent(
transfers: Vec<TransparentTransfer>,
args: GlobalArgs,
) -> Self {
let data = namada_sdk::token::Transfer {
data: transfers,
transparent: transfers,
shielded_section_hash: None,
};

Expand All @@ -36,7 +39,7 @@ impl TransferBuilder {
args: GlobalArgs,
) -> Self {
let data = namada_sdk::token::Transfer {
data: vec![],
transparent: vec![],
shielded_section_hash: Some(shielded_section_hash),
};

Expand All @@ -49,13 +52,13 @@ impl TransferBuilder {

/// Build a MASP transfer transaction from the given parameters
pub fn masp(
transfers: Vec<TransferData>,
transfers: Vec<TransparentTransfer>,
shielded_section_hash: Hash,
transaction: Transaction,
args: GlobalArgs,
) -> Self {
let data = namada_sdk::token::Transfer {
data: transfers,
transparent: transfers,
shielded_section_hash: Some(shielded_section_hash),
};

Expand Down
12 changes: 7 additions & 5 deletions crates/node/src/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ use namada::ledger::queries::{
};
use namada::masp::MaspTxRefs;
use namada::state::StorageRead;
use namada::token::{Amount, DenominatedAmount, Transfer, TransferData};
use namada::token::{Amount, DenominatedAmount, Transfer, TransparentTransfer};
use namada::tx::data::pos::Bond;
use namada::tx::data::{
BatchResults, BatchedTxResult, Fee, TxResult, VpsResult,
Expand Down Expand Up @@ -1114,7 +1114,7 @@ impl BenchShieldedCtx {
namada.client().generate_tx(
TX_TRANSFER_WASM,
Transfer {
data: vec![],
transparent: vec![],
shielded_section_hash: Some(shielded_section_hash),
},
Some(shielded),
Expand All @@ -1125,7 +1125,7 @@ impl BenchShieldedCtx {
namada.client().generate_tx(
TX_TRANSFER_WASM,
Transfer {
data: vec![TransferData {
transparent: vec![TransparentTransfer {
source: source.effective_address(),
target: MASP,
token: address::testing::nam(),
Expand All @@ -1141,7 +1141,7 @@ impl BenchShieldedCtx {
namada.client().generate_tx(
TX_TRANSFER_WASM,
Transfer {
data: vec![TransferData {
transparent: vec![TransparentTransfer {
source: MASP,
target: target.effective_address(),
token: address::testing::nam(),
Expand Down Expand Up @@ -1216,7 +1216,9 @@ impl BenchShieldedCtx {
Transfer::deserialize(&mut tx.tx.data(&tx.cmt).unwrap().as_slice())
.unwrap();
let transfer = Transfer {
data: vec![vectorized_transfer.data.first().unwrap().to_owned()],
transparent: vec![
vectorized_transfer.transparent.first().unwrap().to_owned(),
],
shielded_section_hash: Some(
vectorized_transfer.shielded_section_hash.unwrap(),
),
Expand Down
2 changes: 1 addition & 1 deletion crates/sdk/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ impl TxShieldedTransfer {
}
}

/// Shielded transfer-specific arguments
/// Shielding transfer-specific arguments
#[derive(Clone, Debug)]
pub struct TxShieldingTransferData<C: NamadaTypes = SdkTypes> {
/// Transfer source spending key
Expand Down
20 changes: 10 additions & 10 deletions crates/sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ pub mod testing {
use ripemd::Digest as RipemdDigest;
use sha2::Digest;
use token::testing::arb_vectorized_transparent_transfer;
use token::TransferData;
use token::TransparentTransfer;

use super::*;
use crate::account::tests::{arb_init_account, arb_update_account};
Expand Down Expand Up @@ -1108,8 +1108,8 @@ pub mod testing {
code_hash in arb_hash(),
(masp_tx_type, (shielded_transfer, asset_types, build_params)) in prop_oneof![
(Just(MaspTxType::Shielded), arb_shielded_transfer(0..MAX_ASSETS)),
(Just(MaspTxType::Shielding), arb_shielding_transfer(encode_address(&transfers.data.first().unwrap().source), 1)),
(Just(MaspTxType::Unshielding), arb_deshielding_transfer(encode_address(&transfers.data.first().unwrap().target), 1)),
(Just(MaspTxType::Shielding), arb_shielding_transfer(encode_address(&transfers.transparent.first().unwrap().source), 1)),
(Just(MaspTxType::Unshielding), arb_deshielding_transfer(encode_address(&transfers.transparent.first().unwrap().target), 1)),
],
transfers in Just(transfers),
) -> (Tx, TxData) {
Expand All @@ -1122,7 +1122,7 @@ pub mod testing {
MaspTxType::Shielded => {
tx.add_code_from_hash(code_hash, Some(TX_TRANSFER_WASM.to_owned()));
let data = Transfer {
data: vec![],
transparent: vec![],
shielded_section_hash: Some(shielded_section_hash),
};
tx.add_data(data.clone());
Expand All @@ -1137,16 +1137,16 @@ pub mod testing {
decoded.denom,
);
tx.add_code_from_hash(code_hash, Some(TX_TRANSFER_WASM.to_owned()));
let data = transfers.data.into_iter().map(|transfer|
TransferData{
let transparent = transfers.transparent.into_iter().map(|transfer|
TransparentTransfer{
source: transfer.source,
token: token.clone(),
amount,
target: MASP,
}
).collect();
let data = Transfer{
data,
transparent,
shielded_section_hash: Some(shielded_section_hash),
};
tx.add_data(data.clone());
Expand All @@ -1161,15 +1161,15 @@ pub mod testing {
decoded.denom,
);
tx.add_code_from_hash(code_hash, Some(TX_TRANSFER_WASM.to_owned()));
let data = transfers.data.into_iter().map(|transfer|
TransferData{
let transparent = transfers.transparent.into_iter().map(|transfer|
TransparentTransfer{
target: transfer.target,
token: token.clone(),
amount,
source: MASP,
}
).collect();
let data = Transfer{data, shielded_section_hash: Some(shielded_section_hash) };
let data = Transfer{transparent, shielded_section_hash: Some(shielded_section_hash) };
tx.add_data(data.clone());
TxData::MaspTransfer(data, (build_params, build_param_bytes))
},
Expand Down
8 changes: 4 additions & 4 deletions crates/sdk/src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,15 +711,15 @@ struct TokenTransfer<'a>(&'a token::Transfer);
impl TokenTransfer<'_> {
fn sources(&self) -> Vec<&Address> {
self.0
.data
.transparent
.iter()
.map(|transfer| &transfer.source)
.collect()
}

fn targets(&self) -> Vec<&Address> {
self.0
.data
.transparent
.iter()
.map(|transfer| &transfer.target)
.collect()
Expand All @@ -733,7 +733,7 @@ impl TokenTransfer<'_> {

match address {
TransferSide::Source(source) => {
for transfer in &self.0.data {
for transfer in &self.0.transparent {
if source == &transfer.source {
Self::update_token_amount_map(
&mut map,
Expand All @@ -744,7 +744,7 @@ impl TokenTransfer<'_> {
}
}
TransferSide::Target(target) => {
for transfer in &self.0.data {
for transfer in &self.0.transparent {
if target == &transfer.target {
Self::update_token_amount_map(
&mut map,
Expand Down
20 changes: 10 additions & 10 deletions crates/sdk/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use namada_tx::data::{pos, BatchedTxResult, ResultCode, TxResult};
pub use namada_tx::{Authorization, *};
use num_traits::Zero;
use rand_core::{OsRng, RngCore};
use token::TransferData;
use token::TransparentTransfer;

use crate::args::{
TxShieldedTransferData, TxShieldingTransferData, TxTransparentTransferData,
Expand Down Expand Up @@ -2571,7 +2571,7 @@ pub async fn build_ibc_transfer(
let masp_tx_hash =
tx.add_masp_tx_section(shielded_transfer.masp_tx.clone()).1;
let transfer = token::Transfer {
data: vec![TransferData {
transparent: vec![TransparentTransfer {
// The token will be escrowed to IBC address
source: source.clone(),
target: MASP,
Expand Down Expand Up @@ -2913,7 +2913,7 @@ pub async fn build_transparent_transfer<N: Namada>(
}

// Construct the corresponding transparent Transfer object
let transfer_data = token::TransferData {
let transfer_data = token::TransparentTransfer {
source: source.to_owned(),
target: target.to_owned(),
token: token.to_owned(),
Expand All @@ -2924,7 +2924,7 @@ pub async fn build_transparent_transfer<N: Namada>(
}
// Construct the corresponding transparent Transfer object
let transfer = token::Transfer {
data: transfers,
transparent: transfers,
shielded_section_hash: None,
};

Expand Down Expand Up @@ -3015,7 +3015,7 @@ pub async fn build_shielded_transfer<N: Namada>(

// Construct the tx data with a placeholder shielded section hash
let data = token::Transfer {
data: vec![],
transparent: vec![],
shielded_section_hash: None,
};
let tx = build_pow_flag(
Expand Down Expand Up @@ -3099,7 +3099,7 @@ pub async fn build_shielding_transfer<N: Namada>(
amount: validated_amount,
});

data.push(token::TransferData {
data.push(token::TransparentTransfer {
source: source.to_owned(),
target: MASP,
token: token.to_owned(),
Expand Down Expand Up @@ -3147,7 +3147,7 @@ pub async fn build_shielding_transfer<N: Namada>(

// Construct the tx data with a placeholder shielded section hash
let data = token::Transfer {
data,
transparent: data,
shielded_section_hash: None,
};

Expand Down Expand Up @@ -3196,7 +3196,7 @@ pub async fn build_unshielding_transfer<N: Namada>(
amount: validated_amount,
});

data.push(token::TransferData {
data.push(token::TransparentTransfer {
source: MASP,
target: target.to_owned(),
token: token.to_owned(),
Expand Down Expand Up @@ -3245,7 +3245,7 @@ pub async fn build_unshielding_transfer<N: Namada>(

// Construct the tx data with a placeholder shielded section hash
let data = token::Transfer {
data,
transparent: data,
shielded_section_hash: None,
};

Expand Down Expand Up @@ -3631,7 +3631,7 @@ pub async fn gen_ibc_shielding_transfer<N: Namada>(
let masp_tx_hash =
Section::MaspTx(shielded_transfer.masp_tx.clone()).get_hash();
let transfer = token::Transfer {
data: vec![TransferData {
transparent: vec![TransparentTransfer {
source: source.clone(),
target: MASP,
token: token.clone(),
Expand Down
21 changes: 11 additions & 10 deletions crates/tests/src/integration/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,17 @@ fn ledger_txs_and_queries() -> Result<()> {
let validator_one_rpc = "http://127.0.0.1:26567";

let (node, _services) = setup::setup()?;
let transfer = token::Transfer::transparent(vec![token::TransferData {
source: defaults::bertha_address(),
target: defaults::albert_address(),
token: node.native_token(),
amount: token::DenominatedAmount::new(
token::Amount::native_whole(10),
token::NATIVE_MAX_DECIMAL_PLACES.into(),
),
}])
.serialize_to_vec();
let transfer =
token::Transfer::transparent(vec![token::TransparentTransfer {
source: defaults::bertha_address(),
target: defaults::albert_address(),
token: node.native_token(),
amount: token::DenominatedAmount::new(
token::Amount::native_whole(10),
token::NATIVE_MAX_DECIMAL_PLACES.into(),
),
}])
.serialize_to_vec();
let tx_data_path = node.test_dir.path().join("tx.data");
std::fs::write(&tx_data_path, transfer).unwrap();
let tx_data_path = tx_data_path.to_string_lossy();
Expand Down
Loading

0 comments on commit 6110726

Please sign in to comment.