From 893278c1c607ceeaff807a0f4e6e50df18cd8345 Mon Sep 17 00:00:00 2001 From: Murisi Tarusenga Date: Wed, 9 Aug 2023 12:49:26 +0200 Subject: [PATCH] Combined the TxBuilder and Tx APIs. --- apps/src/lib/cli/client.rs | 3 +- apps/src/lib/client/tx.rs | 48 ++--- .../lib/node/ledger/shell/finalize_block.rs | 19 +- apps/src/lib/node/ledger/shell/governance.rs | 2 +- apps/src/lib/node/ledger/shell/mod.rs | 31 +-- .../lib/node/ledger/shell/prepare_proposal.rs | 18 +- .../lib/node/ledger/shell/process_proposal.rs | 43 ++-- core/src/proto/types.rs | 126 ++++++++++- core/src/types/transaction/mod.rs | 14 +- core/src/types/transaction/protocol.rs | 4 +- core/src/types/transaction/wrapper.rs | 6 +- shared/src/ledger/eth_bridge/bridge_pool.rs | 6 +- shared/src/ledger/ibc/vp/mod.rs | 85 +++----- .../ethereum_bridge/bridge_pool_vp.rs | 43 ++-- .../ledger/native_vp/ethereum_bridge/vp.rs | 6 +- shared/src/ledger/native_vp/multitoken.rs | 2 +- shared/src/ledger/queries/shell.rs | 2 +- shared/src/ledger/signing.rs | 5 +- shared/src/ledger/tx.rs | 57 +++-- shared/src/types/tx.rs | 185 +---------------- shared/src/vm/wasm/run.rs | 56 +++-- tests/src/native_vp/eth_bridge_pool.rs | 7 +- tests/src/vm_host_env/mod.rs | 196 +++++++----------- tests/src/vm_host_env/tx.rs | 2 +- tests/src/vm_host_env/vp.rs | 2 +- wasm/checksums.json | 38 ++-- wasm/tx_template/src/lib.rs | 2 +- wasm/wasm_source/src/tx_bond.rs | 7 +- .../src/tx_change_validator_commission.rs | 7 +- wasm/wasm_source/src/tx_unbond.rs | 7 +- wasm/wasm_source/src/tx_withdraw.rs | 7 +- wasm/wasm_source/src/vp_implicit.rs | 20 +- wasm/wasm_source/src/vp_testnet_faucet.rs | 10 +- wasm/wasm_source/src/vp_user.rs | 14 +- wasm/wasm_source/src/vp_validator.rs | 14 +- wasm_for_tests/tx_memory_limit.wasm | Bin 443859 -> 443859 bytes wasm_for_tests/tx_read_storage_key.wasm | Bin 450355 -> 450355 bytes wasm_for_tests/tx_write.wasm | Bin 451511 -> 451511 bytes wasm_for_tests/vp_eval.wasm | Bin 492944 -> 492944 bytes wasm_for_tests/vp_memory_limit.wasm | Bin 468281 -> 468281 bytes wasm_for_tests/vp_read_storage_key.wasm | Bin 473569 -> 473569 bytes 41 files changed, 448 insertions(+), 646 deletions(-) diff --git a/apps/src/lib/cli/client.rs b/apps/src/lib/cli/client.rs index a27e94e7f3..cbd5b33ad1 100644 --- a/apps/src/lib/cli/client.rs +++ b/apps/src/lib/cli/client.rs @@ -254,8 +254,7 @@ impl CliApi { args.clone(), signing_data.gas_payer.clone(), ) - .await? - .unsigned_build(); + .await?; signing::generate_test_vector( &client, diff --git a/apps/src/lib/client/tx.rs b/apps/src/lib/client/tx.rs index 2cac2ce227..ddfd3ac4b7 100644 --- a/apps/src/lib/client/tx.rs +++ b/apps/src/lib/client/tx.rs @@ -26,7 +26,7 @@ use namada::types::storage::{Epoch, Key}; use namada::types::token; use namada::types::transaction::governance::{ProposalType, VoteProposalData}; use namada::types::transaction::pos::InitValidator; -use namada::types::tx::TxBuilder; +use namada::proto::Tx; use super::rpc; use crate::cli::context::WalletAddress; @@ -73,8 +73,7 @@ pub async fn submit_reveal_aux( &public_key, &signing_data.gas_payer, ) - .await? - .unsigned_build(); + .await?; signing::generate_test_vector(client, &mut ctx.wallet, &tx).await; @@ -110,8 +109,7 @@ where let mut tx = tx::build_custom(client, args.clone(), &signing_data.gas_payer) - .await? - .unsigned_build(); + .await?; signing::generate_test_vector(client, &mut ctx.wallet, &tx).await; @@ -146,8 +144,7 @@ where let mut tx = tx::build_update_account(client, args.clone(), &signing_data.gas_payer) - .await? - .unsigned_build(); + .await?; signing::generate_test_vector(client, &mut ctx.wallet, &tx).await; @@ -181,8 +178,7 @@ where let mut tx = tx::build_init_account(client, args.clone(), &signing_data.gas_payer) - .await? - .unsigned_build(); + .await?; signing::generate_test_vector(client, &mut ctx.wallet, &tx).await; @@ -380,7 +376,7 @@ where .unwrap(); let chain_id = tx_args.chain_id.clone().unwrap(); - let tx_builder = TxBuilder::new(chain_id, tx_args.expiration); + let tx_builder = Tx::new(chain_id, tx_args.expiration); let (tx_builder, extra_section_hash) = tx_builder.add_extra_section_from_hash(validator_vp_code_hash); @@ -419,8 +415,7 @@ where #[cfg(not(feature = "mainnet"))] false, ) - .await? - .unsigned_build(); + .await?; signing::generate_test_vector(client, &mut ctx.wallet, &tx).await; @@ -645,7 +640,7 @@ pub async fn submit_transfer( &signing_data.gas_payer, ) .await?; - let mut tx = tx_builder.unsigned_build(); + let mut tx = tx_builder; signing::generate_test_vector(client, &mut ctx.wallet, &tx).await; if args.tx.dump_tx { @@ -706,8 +701,7 @@ where let mut tx = tx::build_ibc_transfer(client, args.clone(), &signing_data.gas_payer) - .await? - .unsigned_build(); + .await?; signing::generate_test_vector(client, &mut ctx.wallet, &tx).await; if args.tx.dump_tx { @@ -867,7 +861,7 @@ where .await?; let chain_id = args.tx.chain_id.clone().unwrap(); - let tx_builder = TxBuilder::new(chain_id, args.tx.expiration); + let tx_builder = Tx::new(chain_id, args.tx.expiration); // Put any proposal content into an extra section let (tx_builder, extra_section_hash) = @@ -899,8 +893,7 @@ where #[cfg(not(feature = "mainnet"))] false, ) - .await? - .unsigned_build(); + .await?; signing::generate_test_vector(client, &mut ctx.wallet, &tx).await; if args.tx.dump_tx { @@ -1157,7 +1150,7 @@ where .await?; let chain_id = args.tx.chain_id.clone().unwrap(); - let tx_builder = TxBuilder::new(chain_id, args.tx.expiration); + let tx_builder = Tx::new(chain_id, args.tx.expiration); let tx_builder = tx_builder .add_code_from_hash(tx_code_hash) @@ -1171,8 +1164,7 @@ where #[cfg(not(feature = "mainnet"))] false, ) - .await? - .unsigned_build(); + .await?; signing::generate_test_vector(client, &mut ctx.wallet, &tx) .await; @@ -1300,8 +1292,7 @@ where let mut tx = tx::build_bond::(client, args.clone(), &signing_data.gas_payer) - .await? - .unsigned_build(); + .await?; signing::generate_test_vector(client, &mut ctx.wallet, &tx).await; if args.tx.dump_tx { @@ -1342,7 +1333,7 @@ where &signing_data.gas_payer, ) .await?; - let mut tx = tx_builder.unsigned_build(); + let mut tx = tx_builder; signing::generate_test_vector(client, &mut ctx.wallet, &tx).await; if args.tx.dump_tx { @@ -1380,8 +1371,7 @@ where let mut tx = tx::build_withdraw(client, args.clone(), &signing_data.gas_payer) - .await? - .unsigned_build(); + .await?; signing::generate_test_vector(client, &mut ctx.wallet, &tx).await; if args.tx.dump_tx { @@ -1419,8 +1409,7 @@ where args.clone(), &signing_data.gas_payer, ) - .await? - .unsigned_build(); + .await?; signing::generate_test_vector(client, &mut ctx.wallet, &tx).await; if args.tx.dump_tx { @@ -1460,8 +1449,7 @@ where args.clone(), &signing_data.gas_payer, ) - .await? - .unsigned_build(); + .await?; signing::generate_test_vector(client, &mut ctx.wallet, &tx).await; if args.tx.dump_tx { diff --git a/apps/src/lib/node/ledger/shell/finalize_block.rs b/apps/src/lib/node/ledger/shell/finalize_block.rs index 2f9de66859..f79e8c0f05 100644 --- a/apps/src/lib/node/ledger/shell/finalize_block.rs +++ b/apps/src/lib/node/ledger/shell/finalize_block.rs @@ -985,7 +985,6 @@ mod test_finalize_block { }; use namada::types::transaction::protocol::EthereumTxData; use namada::types::transaction::{Fee, WrapperTx, MIN_FEE_AMOUNT}; - use namada::types::tx::TxBuilder; use namada::types::uint::Uint; use namada::types::vote_extensions::ethereum_events; use namada_test_utils::TestWasms; @@ -1008,7 +1007,7 @@ mod test_finalize_block { keypair: &common::SecretKey, ) -> (Tx, ProcessedTx) { let mut wrapper_tx = - Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: MIN_FEE_AMOUNT, token: shell.wl_storage.storage.native_token.clone(), @@ -1048,7 +1047,7 @@ mod test_finalize_block { keypair: &common::SecretKey, ) -> ProcessedTx { let tx_code = TestWasms::TxNoOp.read_bytes(); - let mut outer_tx = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut outer_tx = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: MIN_FEE_AMOUNT, token: shell.wl_storage.storage.native_token.clone(), @@ -1156,7 +1155,7 @@ mod test_finalize_block { fn test_process_proposal_rejected_decrypted_tx() { let (mut shell, _, _, _) = setup(); let keypair = gen_keypair(); - let mut outer_tx = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut outer_tx = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Default::default(), token: shell.wl_storage.storage.native_token.clone(), @@ -1222,7 +1221,7 @@ mod test_finalize_block { pow_solution: None, }; let processed_tx = ProcessedTx { - tx: Tx::new(TxType::Decrypted(DecryptedTx::Undecryptable)) + tx: Tx::from_type(TxType::Decrypted(DecryptedTx::Undecryptable)) .to_bytes(), result: TxResult { code: ErrorCodes::Ok.into(), @@ -1230,7 +1229,7 @@ mod test_finalize_block { }, }; - let tx = Tx::new(TxType::Wrapper(Box::new(wrapper))); + let tx = Tx::from_type(TxType::Wrapper(Box::new(wrapper))); shell.enqueue_tx(tx); // check that correct error message is returned @@ -2190,7 +2189,7 @@ mod test_finalize_block { let tx_code = std::fs::read(wasm_path) .expect("Expected a file at given code path"); let mut wrapper_tx = - Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Amount::zero(), token: shell.wl_storage.storage.native_token.clone(), @@ -3514,11 +3513,9 @@ mod test_finalize_block { .wl_storage .write(&proposal_execution_key, 0u64) .expect("Test failed."); - let tx_builder = TxBuilder::new(shell.chain_id.clone(), None); - let tx = tx_builder + let tx = Tx::new(shell.chain_id.clone(), None) .add_code_from_hash(Hash::default()) - .add_data(0u64) - .signed_build(); + .add_data(0u64); let new_min_confirmations = MinimumConfirmations::from(unsafe { NonZeroU64::new_unchecked(42) }); diff --git a/apps/src/lib/node/ledger/shell/governance.rs b/apps/src/lib/node/ledger/shell/governance.rs index e488cbf2b8..3ab36679ac 100644 --- a/apps/src/lib/node/ledger/shell/governance.rs +++ b/apps/src/lib/node/ledger/shell/governance.rs @@ -149,7 +149,7 @@ where let proposal_code = shell.read_storage_key_bytes(&proposal_code_key); match proposal_code { Some(proposal_code) => { - let mut tx = Tx::new(TxType::Decrypted(DecryptedTx::Decrypted { + let mut tx = Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted { #[cfg(not(feature = "mainnet"))] has_valid_pow: false, })); diff --git a/apps/src/lib/node/ledger/shell/mod.rs b/apps/src/lib/node/ledger/shell/mod.rs index bc012738da..d4b105dee9 100644 --- a/apps/src/lib/node/ledger/shell/mod.rs +++ b/apps/src/lib/node/ledger/shell/mod.rs @@ -1890,7 +1890,7 @@ mod test_utils { .expect("begin_block failed"); let keypair = gen_keypair(); // enqueue a wrapper tx - let mut wrapper = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut wrapper = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Default::default(), token: native_token, @@ -2086,7 +2086,7 @@ mod abciplus_mempool_tests { ext }; let tx = { - let mut tx = Tx::new(TxType::Protocol(Box::new(ProtocolTx { + let mut tx = Tx::from_type(TxType::Protocol(Box::new(ProtocolTx { pk: protocol_key.ref_to(), tx: ProtocolTxType::BridgePoolVext, }))); @@ -2110,7 +2110,6 @@ mod test_mempool_validate { use namada::proof_of_stake::Epoch; use namada::proto::{Code, Data, Section, Signature, Tx}; use namada::types::transaction::{Fee, WrapperTx}; - use namada::types::tx::TxBuilder; use super::*; @@ -2122,7 +2121,7 @@ mod test_mempool_validate { let keypair = super::test_utils::gen_keypair(); let mut unsigned_wrapper = - Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: token::Amount::from_uint(100, 0) .expect("This can't fail"), @@ -2159,7 +2158,7 @@ mod test_mempool_validate { let keypair = super::test_utils::gen_keypair(); let mut invalid_wrapper = - Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: token::Amount::from_uint(100, 0) .expect("This can't fail"), @@ -2203,10 +2202,8 @@ mod test_mempool_validate { fn test_wrong_tx_type() { let (shell, _recv, _, _) = test_utils::setup(); - let tx_builder = TxBuilder::new(shell.chain_id.clone(), None); - let tx = tx_builder - .add_code("wasm_code".as_bytes().to_owned()) - .signed_build(); + let tx = Tx::new(shell.chain_id.clone(), None) + .add_code("wasm_code".as_bytes().to_owned()); let result = shell.mempool_validate( tx.to_bytes().as_ref(), @@ -2228,7 +2225,7 @@ mod test_mempool_validate { let keypair = super::test_utils::gen_keypair(); - let mut wrapper = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut wrapper = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: token::Amount::from_uint(100, 0) .expect("This can't fail"), @@ -2335,12 +2332,11 @@ mod test_mempool_validate { let keypair = super::test_utils::gen_keypair(); let wrong_chain_id = ChainId("Wrong chain id".to_string()); - let tx_builder = TxBuilder::new(wrong_chain_id.clone(), None); + let tx_builder = Tx::new(wrong_chain_id.clone(), None); let tx = tx_builder .add_code("wasm_code".as_bytes().to_owned()) .add_data("transaction data".as_bytes().to_owned()) - .add_gas_payer(keypair) - .signed_build(); + .sign_wrapper(keypair); let result = shell.mempool_validate( tx.to_bytes().as_ref(), @@ -2364,15 +2360,10 @@ mod test_mempool_validate { let keypair = super::test_utils::gen_keypair(); - let tx_builder = TxBuilder::new( - shell.chain_id.clone(), - Some(DateTimeUtc::default()), - ); - let tx = tx_builder + let tx = Tx::new(shell.chain_id.clone(), Some(DateTimeUtc::default())) .add_code("wasm_code".as_bytes().to_owned()) .add_data("transaction data".as_bytes().to_owned()) - .add_gas_payer(keypair) - .signed_build(); + .sign_wrapper(keypair); let result = shell.mempool_validate( tx.to_bytes().as_ref(), diff --git a/apps/src/lib/node/ledger/shell/prepare_proposal.rs b/apps/src/lib/node/ledger/shell/prepare_proposal.rs index e1e94be61e..c07f5a975b 100644 --- a/apps/src/lib/node/ledger/shell/prepare_proposal.rs +++ b/apps/src/lib/node/ledger/shell/prepare_proposal.rs @@ -543,7 +543,7 @@ mod test_prepare_proposal { #[test] fn test_prepare_proposal_rejects_non_wrapper_tx() { let (shell, _recv, _, _) = test_utils::setup(); - let mut tx = Tx::new(TxType::Decrypted(DecryptedTx::Decrypted { + let mut tx = Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted { has_valid_pow: true, })); tx.header.chain_id = shell.chain_id.clone(); @@ -562,7 +562,7 @@ mod test_prepare_proposal { let (shell, _recv, _, _) = test_utils::setup(); let keypair = gen_keypair(); // an unsigned wrapper will cause an error in processing - let mut wrapper = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut wrapper = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Default::default(), token: shell.wl_storage.storage.native_token.clone(), @@ -938,7 +938,7 @@ mod test_prepare_proposal { // create a request with two new wrappers from mempool and // two wrappers from the previous block to be decrypted for i in 0..2 { - let mut tx = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut tx = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Default::default(), token: shell.wl_storage.storage.native_token.clone(), @@ -1006,7 +1006,7 @@ mod test_prepare_proposal { let (mut shell, _recv, _, _) = test_utils::setup(); let keypair = crate::wallet::defaults::daewon_keypair(); - let mut wrapper = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut wrapper = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: 0.into(), token: shell.wl_storage.storage.native_token.clone(), @@ -1057,7 +1057,7 @@ mod test_prepare_proposal { let (shell, _recv, _, _) = test_utils::setup(); let keypair = crate::wallet::defaults::daewon_keypair(); - let mut wrapper = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut wrapper = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: 0.into(), token: shell.wl_storage.storage.native_token.clone(), @@ -1097,7 +1097,7 @@ mod test_prepare_proposal { let (mut shell, _recv, _, _) = test_utils::setup(); let keypair = crate::wallet::defaults::daewon_keypair(); - let mut wrapper = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut wrapper = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Amount::zero(), token: shell.wl_storage.storage.native_token.clone(), @@ -1149,7 +1149,7 @@ mod test_prepare_proposal { let keypair = crate::wallet::defaults::daewon_keypair(); let keypair_2 = crate::wallet::defaults::daewon_keypair(); - let mut wrapper = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut wrapper = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: 0.into(), token: shell.wl_storage.storage.native_token.clone(), @@ -1171,7 +1171,7 @@ mod test_prepare_proposal { ))); let mut new_wrapper = - Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: 0.into(), token: shell.wl_storage.storage.native_token.clone(), @@ -1212,7 +1212,7 @@ mod test_prepare_proposal { let keypair = gen_keypair(); let tx_time = DateTimeUtc::now(); let mut wrapper_tx = - Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: 0.into(), token: shell.wl_storage.storage.native_token.clone(), diff --git a/apps/src/lib/node/ledger/shell/process_proposal.rs b/apps/src/lib/node/ledger/shell/process_proposal.rs index 7777df4ef9..69f41cd5a2 100644 --- a/apps/src/lib/node/ledger/shell/process_proposal.rs +++ b/apps/src/lib/node/ledger/shell/process_proposal.rs @@ -964,7 +964,6 @@ mod test_process_proposal { use namada::types::token::Amount; use namada::types::transaction::protocol::EthereumTxData; use namada::types::transaction::{Fee, WrapperTx, MIN_FEE}; - use namada::types::tx::TxBuilder; #[cfg(feature = "abcipp")] use namada::types::vote_extensions::bridge_pool_roots::MultiSignedVext; #[cfg(feature = "abcipp")] @@ -1539,7 +1538,7 @@ mod test_process_proposal { let (mut shell, _recv, _, _) = test_utils::setup_at_height(3u64); let keypair = gen_keypair(); let public_key = keypair.ref_to(); - let mut outer_tx = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut outer_tx = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Default::default(), token: shell.wl_storage.storage.native_token.clone(), @@ -1589,7 +1588,7 @@ mod test_process_proposal { fn test_wrapper_bad_signature_rejected() { let (mut shell, _recv, _, _) = test_utils::setup_at_height(3u64); let keypair = gen_keypair(); - let mut outer_tx = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut outer_tx = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Amount::from_uint(100, 0).expect("Test failed"), token: shell.wl_storage.storage.native_token.clone(), @@ -1657,7 +1656,7 @@ mod test_process_proposal { ) .unwrap(); let keypair = gen_keypair(); - let mut outer_tx = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut outer_tx = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Amount::from_uint(1, 0).expect("Test failed"), token: shell.wl_storage.storage.native_token.clone(), @@ -1726,7 +1725,7 @@ mod test_process_proposal { ) .unwrap(); - let mut outer_tx = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut outer_tx = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Amount::native_whole(1_000_100), token: shell.wl_storage.storage.native_token.clone(), @@ -1779,7 +1778,7 @@ mod test_process_proposal { let mut txs = vec![]; for i in 0..3 { let mut outer_tx = - Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Amount::native_whole(i as u64), token: shell.wl_storage.storage.native_token.clone(), @@ -1857,7 +1856,7 @@ mod test_process_proposal { let (mut shell, _recv, _, _) = test_utils::setup_at_height(3u64); let keypair = gen_keypair(); - let mut tx = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut tx = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Default::default(), token: shell.wl_storage.storage.native_token.clone(), @@ -1909,7 +1908,7 @@ mod test_process_proposal { let (mut shell, _recv, _, _) = test_utils::setup_at_height(3u64); let keypair = crate::wallet::defaults::daewon_keypair(); - let mut tx = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut tx = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Default::default(), token: shell.wl_storage.storage.native_token.clone(), @@ -1966,7 +1965,7 @@ mod test_process_proposal { pow_solution: None, }; - let tx = Tx::new(TxType::Wrapper(Box::new(wrapper))); + let tx = Tx::from_type(TxType::Wrapper(Box::new(wrapper))); let mut decrypted = tx.clone(); decrypted.update_header(TxType::Decrypted(DecryptedTx::Undecryptable)); @@ -1994,7 +1993,7 @@ mod test_process_proposal { #[test] fn test_too_many_decrypted_txs() { let (mut shell, _recv, _, _) = test_utils::setup_at_height(3u64); - let mut tx = Tx::new(TxType::Decrypted(DecryptedTx::Decrypted { + let mut tx = Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted { #[cfg(not(feature = "mainnet"))] has_valid_pow: false, })); @@ -2030,12 +2029,10 @@ mod test_process_proposal { let keypair = crate::wallet::defaults::daewon_keypair(); - let tx_builder = TxBuilder::new(shell.chain_id.clone(), None); - let tx = tx_builder + let tx = Tx::new(shell.chain_id.clone(), None) .add_code("wasm_code".as_bytes().to_owned()) .add_data("transaction data".as_bytes().to_owned()) - .add_gas_payer(keypair) - .signed_build(); + .sign_wrapper(keypair); let response = { let request = ProcessProposal { @@ -2071,7 +2068,7 @@ mod test_process_proposal { let keypair = crate::wallet::defaults::daewon_keypair(); - let mut wrapper = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut wrapper = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Amount::zero(), token: shell.wl_storage.storage.native_token.clone(), @@ -2145,7 +2142,7 @@ mod test_process_proposal { ) .unwrap(); - let mut wrapper = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut wrapper = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Amount::zero(), token: shell.wl_storage.storage.native_token.clone(), @@ -2202,7 +2199,7 @@ mod test_process_proposal { let keypair = crate::wallet::defaults::daewon_keypair(); - let mut wrapper = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut wrapper = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Amount::zero(), token: shell.wl_storage.storage.native_token.clone(), @@ -2291,7 +2288,7 @@ mod test_process_proposal { ) .unwrap(); - let mut wrapper = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut wrapper = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Amount::zero(), token: shell.wl_storage.storage.native_token.clone(), @@ -2360,7 +2357,7 @@ mod test_process_proposal { let (mut shell, _recv, _, _) = test_utils::setup(); let keypair = crate::wallet::defaults::daewon_keypair(); - let mut wrapper = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut wrapper = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Amount::zero(), token: shell.wl_storage.storage.native_token.clone(), @@ -2422,7 +2419,7 @@ mod test_process_proposal { let keypair = crate::wallet::defaults::daewon_keypair(); let wrong_chain_id = ChainId("Wrong chain id".to_string()); - let mut wrapper = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut wrapper = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: token::Amount::zero(), token: shell.wl_storage.storage.native_token.clone(), @@ -2482,7 +2479,7 @@ mod test_process_proposal { let (mut shell, _recv, _, _) = test_utils::setup(); let keypair = crate::wallet::defaults::daewon_keypair(); - let mut wrapper = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut wrapper = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: token::Amount::zero(), token: shell.wl_storage.storage.native_token.clone(), @@ -2524,7 +2521,7 @@ mod test_process_proposal { let (mut shell, _recv, _, _) = test_utils::setup(); let keypair = crate::wallet::defaults::daewon_keypair(); - let mut wrapper = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut wrapper = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: token::Amount::zero(), token: shell.wl_storage.storage.native_token.clone(), @@ -2580,7 +2577,7 @@ mod test_process_proposal { fn test_include_only_protocol_txs() { let (mut shell, _recv, _, _) = test_utils::setup_at_height(1u64); let keypair = gen_keypair(); - let mut wrapper = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut wrapper = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: 0.into(), token: shell.wl_storage.storage.native_token.clone(), diff --git a/core/src/proto/types.rs b/core/src/proto/types.rs index 4fae2faf87..9008d2752c 100644 --- a/core/src/proto/types.rs +++ b/core/src/proto/types.rs @@ -22,6 +22,7 @@ use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use thiserror::Error; +use crate::ledger::testnet_pow; use super::generated::types; use crate::ledger::storage::{KeccakHasher, Sha256Hasher, StorageHasher}; #[cfg(any(feature = "tendermint", feature = "tendermint-abcipp"))] @@ -44,7 +45,7 @@ use crate::types::transaction::EllipticCurve; use crate::types::transaction::EncryptionKey; #[cfg(feature = "ferveo-tpke")] use crate::types::transaction::WrapperTxErr; -use crate::types::transaction::{hash_tx, DecryptedTx, TxType, WrapperTx}; +use crate::types::transaction::{hash_tx, DecryptedTx, TxType, WrapperTx, Fee, GasLimit}; #[derive(Error, Debug)] pub enum Error { @@ -1136,8 +1137,23 @@ impl TryFrom<&[u8]> for Tx { } impl Tx { + /// Initialize a new transaction builder + pub fn new(chain_id: ChainId, expiration: Option) -> Self { + Tx { + sections: vec![], + header: Header { + tx_type: TxType::Raw, + chain_id, + expiration, + timestamp: DateTimeUtc::now(), + code_hash: crate::types::hash::Hash::default(), + data_hash: crate::types::hash::Hash::default(), + }, + } + } + /// Create a transaction of the given type - pub fn new(header: TxType) -> Self { + pub fn from_type(header: TxType) -> Self { Tx { header: Header::new(header), sections: vec![], @@ -1511,6 +1527,112 @@ impl Tx { } filtered } + + /// Add an extra section to the tx builder by hash + pub fn add_extra_section_from_hash(mut self, hash: crate::types::hash::Hash) -> (Self, crate::types::hash::Hash) { + let sechash = self.add_section(Section::ExtraData(Code::from_hash(hash))).get_hash(); + (self, sechash) + } + + /// Add an extra section to the tx builder by code + pub fn add_extra_section(mut self, code: Vec) -> (Self, crate::types::hash::Hash) { + let sechash = self.add_section(Section::ExtraData(Code::new(code))).get_hash(); + (self, sechash) + } + + /// Add a masp tx section to the tx builder + pub fn add_masp_tx_section(mut self, tx: Transaction) -> (Self, crate::types::hash::Hash) { + let sechash = self.add_section(Section::MaspTx(tx)).get_hash(); + (self, sechash) + } + + /// Add a masp builder section to the tx builder + pub fn add_masp_builder(mut self, builder: MaspBuilder) -> Self { + let _sec = self.add_section(Section::MaspBuilder(builder)); + self + } + + /// Add wasm code to the tx builder from hash + pub fn add_code_from_hash(mut self, code_hash: crate::types::hash::Hash) -> Self { + self.set_code(Code::from_hash(code_hash)); + self + } + + /// Add wasm code to the tx builder + pub fn add_code(mut self, code: Vec) -> Self { + self.set_code(Code::new(code)); + self + } + + /// Add wasm data to the tx builder + pub fn add_data(mut self, data: impl BorshSerialize) -> Self { + let bytes = data.try_to_vec().expect("Encoding tx data shouldn't fail"); + self.set_data(Data::new(bytes)); + self + } + + /// Add wasm data already serialized to the tx builder + pub fn add_serialized_data(mut self, bytes: Vec) -> Self { + self.set_data(Data::new(bytes)); + self + } + + /// Add wrapper tx to the tx builder + pub fn add_wrapper( + mut self, + fee: Fee, + gas_payer: common::PublicKey, + epoch: Epoch, + gas_limit: GasLimit, + #[cfg(not(feature = "mainnet"))] requires_pow: Option< + testnet_pow::Solution, + >, + ) -> Self { + self.header.tx_type = TxType::Wrapper(Box::new(WrapperTx::new( + fee, + gas_payer, + epoch, + gas_limit, + #[cfg(not(feature = "mainnet"))] + requires_pow, + ))); + self + } + + /// Add fee payer keypair to the tx builder + pub fn sign_wrapper(mut self, keypair: common::SecretKey) -> Self { + self.protocol_filter(); + self.add_section(Section::Signature(Signature::new( + self.sechashes(), + &keypair, + ))); + self + } + + /// Add signing keys to the tx builder + pub fn sign_raw( + mut self, + keypairs: Vec, + account_public_keys_map: AccountPublicKeysMap, + ) -> Self { + self.protocol_filter(); + let hashes = self + .sections + .iter() + .filter_map(|section| match section { + Section::Data(_) | Section::Code(_) => { + Some(section.get_hash()) + } + _ => None, + }) + .collect(); + self.add_section(Section::SectionSignature(MultiSignature::new( + hashes, + &keypairs, + &account_public_keys_map, + ))); + self + } } #[cfg(any(feature = "tendermint", feature = "tendermint-abcipp"))] diff --git a/core/src/types/transaction/mod.rs b/core/src/types/transaction/mod.rs index 88ded1970d..3ae9e913e4 100644 --- a/core/src/types/transaction/mod.rs +++ b/core/src/types/transaction/mod.rs @@ -184,7 +184,7 @@ mod test_process_tx { /// data and returns an identical copy #[test] fn test_process_tx_raw_tx_no_data() { - let mut outer_tx = Tx::new(TxType::Raw); + let mut outer_tx = Tx::from_type(TxType::Raw); let code_sec = outer_tx .set_code(Code::new("wasm code".as_bytes().to_owned())) .clone(); @@ -202,7 +202,7 @@ mod test_process_tx { /// of the inner data #[test] fn test_process_tx_raw_tx_some_data() { - let mut tx = Tx::new(TxType::Raw); + let mut tx = Tx::from_type(TxType::Raw); let code_sec = tx .set_code(Code::new("wasm code".as_bytes().to_owned())) .clone(); @@ -224,7 +224,7 @@ mod test_process_tx { /// signed data and returns an identical copy of the inner data #[test] fn test_process_tx_raw_tx_some_signed_data() { - let mut tx = Tx::new(TxType::Raw); + let mut tx = Tx::from_type(TxType::Raw); let code_sec = tx .set_code(Code::new("wasm code".as_bytes().to_owned())) .clone(); @@ -252,7 +252,7 @@ mod test_process_tx { fn test_process_tx_wrapper_tx() { let keypair = gen_keypair(); // the signed tx - let mut tx = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut tx = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Amount::from_uint(10, 0).expect("Test failed"), token: nam(), @@ -287,7 +287,7 @@ mod test_process_tx { fn test_process_tx_wrapper_tx_unsigned() { let keypair = gen_keypair(); // the signed tx - let mut tx = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut tx = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Amount::from_uint(10, 0).expect("Test failed"), token: nam(), @@ -310,7 +310,7 @@ mod test_process_tx { #[test] fn test_process_tx_decrypted_unsigned() { use crate::proto::{Code, Data, Tx}; - let mut tx = Tx::new(TxType::Decrypted(DecryptedTx::Decrypted { + let mut tx = Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted { #[cfg(not(feature = "mainnet"))] has_valid_pow: false, })); @@ -350,7 +350,7 @@ fn test_process_tx_decrypted_signed() { } use crate::types::key::Signature as S; - let mut decrypted = Tx::new(TxType::Decrypted(DecryptedTx::Decrypted { + let mut decrypted = Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted { #[cfg(not(feature = "mainnet"))] has_valid_pow: false, })); diff --git a/core/src/types/transaction/protocol.rs b/core/src/types/transaction/protocol.rs index d546168bf4..aa9abe8cec 100644 --- a/core/src/types/transaction/protocol.rs +++ b/core/src/types/transaction/protocol.rs @@ -193,7 +193,7 @@ mod protocol_txs { ) -> Tx { let (tx_data, tx_type) = self.serialize(); let mut outer_tx = - Tx::new(TxType::Protocol(Box::new(ProtocolTx { + Tx::from_type(TxType::Protocol(Box::new(ProtocolTx { pk: signing_key.ref_to(), tx: tx_type, }))); @@ -323,7 +323,7 @@ mod protocol_txs { TX_NEW_DKG_KP_WASM, ); let mut outer_tx = - Tx::new(TxType::Protocol(Box::new(ProtocolTx { + Tx::from_type(TxType::Protocol(Box::new(ProtocolTx { pk: signing_key.ref_to(), tx: Self::NewDkgKeypair, }))); diff --git a/core/src/types/transaction/wrapper.rs b/core/src/types/transaction/wrapper.rs index 7b72c225eb..f428844031 100644 --- a/core/src/types/transaction/wrapper.rs +++ b/core/src/types/transaction/wrapper.rs @@ -371,7 +371,7 @@ pub mod wrapper_tx { fn test_encryption_round_trip() { let keypair = gen_keypair(); let mut wrapper = - Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Amount::from_uint(10, 0).expect("Test failed"), token: nam(), @@ -404,7 +404,7 @@ pub mod wrapper_tx { fn test_decryption_invalid_hash() { let keypair = gen_keypair(); let mut wrapper = - Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Amount::from_uint(10, 0).expect("Test failed"), token: nam(), @@ -439,7 +439,7 @@ pub mod wrapper_tx { fn test_malleability_attack_detection() { let keypair = gen_keypair(); // the signed tx - let mut tx = Tx::new(TxType::Wrapper(Box::new(WrapperTx::new( + let mut tx = Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new( Fee { amount: Amount::from_uint(10, 0).expect("Test failed"), token: nam(), diff --git a/shared/src/ledger/eth_bridge/bridge_pool.rs b/shared/src/ledger/eth_bridge/bridge_pool.rs index 867881c1fb..81c9850914 100644 --- a/shared/src/ledger/eth_bridge/bridge_pool.rs +++ b/shared/src/ledger/eth_bridge/bridge_pool.rs @@ -31,7 +31,7 @@ use crate::types::eth_bridge_pool::{ }; use crate::types::keccak::KeccakHash; use crate::types::token::{Amount, DenominatedAmount}; -use crate::types::tx::TxBuilder; +use crate::proto::Tx; use crate::types::voting_power::FractionalVotingPower; /// Craft a transaction that adds a transfer to the Ethereum bridge pool. @@ -48,7 +48,7 @@ pub async fn build_bridge_pool_tx( code_path, }: args::EthereumBridgePool, gas_payer: common::PublicKey, -) -> Result { +) -> Result { let DenominatedAmount { amount, .. } = validate_amount(client, amount, &BRIDGE_ADDRESS, tx.force) .await @@ -73,7 +73,7 @@ pub async fn build_bridge_pool_tx( .unwrap(); let chain_id = tx.chain_id.clone().unwrap(); - let tx_builder = TxBuilder::new(chain_id, tx.expiration); + let tx_builder = Tx::new(chain_id, tx.expiration); let tx_builder = tx_builder .add_code_from_hash(tx_code_hash) diff --git a/shared/src/ledger/ibc/vp/mod.rs b/shared/src/ledger/ibc/vp/mod.rs index 32e138f912..51fca0bf5a 100644 --- a/shared/src/ledger/ibc/vp/mod.rs +++ b/shared/src/ledger/ibc/vp/mod.rs @@ -395,7 +395,6 @@ mod tests { use crate::types::time::DurationSecs; use crate::types::token::{balance_key, Amount}; use crate::types::transaction::TxType; - use crate::types::tx::TxBuilder; use crate::vm::wasm; const ADDRESS: Address = Address::Internal(InternalAddress::Ibc); @@ -756,7 +755,7 @@ mod tests { wasm::compilation_cache::common::testing::cache(); let verifiers = BTreeSet::new(); - let mut outer_tx = Tx::new(TxType::Raw); + let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = wl_storage.storage.chain_id.clone(); outer_tx.set_code(Code::new(tx_code)); outer_tx.set_data(Data::new(tx_data)); @@ -830,13 +829,10 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = - TxBuilder::new(wl_storage.storage.chain_id.clone(), None); - let tx = tx_builder + let tx = Tx::new(wl_storage.storage.chain_id.clone(), None) .add_code(tx_code) .add_serialized_data(tx_data) - .add_gas_payer(keypair_1()) - .signed_build(); + .sign_wrapper(keypair_1()); let gas_meter = VpGasMeter::new(0); let (vp_wasm_cache, _vp_cache_dir) = @@ -967,13 +963,10 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = - TxBuilder::new(wl_storage.storage.chain_id.clone(), None); - let tx = tx_builder + let tx = Tx::new(wl_storage.storage.chain_id.clone(), None) .add_code(tx_code) .add_serialized_data(tx_data) - .add_gas_payer(keypair_1()) - .signed_build(); + .sign_wrapper(keypair_1()); let gas_meter = VpGasMeter::new(0); let (vp_wasm_cache, _vp_cache_dir) = @@ -1074,7 +1067,7 @@ mod tests { let tx_code = vec![]; let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let mut outer_tx = Tx::new(TxType::Raw); + let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = wl_storage.storage.chain_id.clone(); outer_tx.set_code(Code::new(tx_code)); outer_tx.set_data(Data::new(tx_data)); @@ -1170,13 +1163,10 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = - TxBuilder::new(wl_storage.storage.chain_id.clone(), None); - let tx = tx_builder + let tx = Tx::new(wl_storage.storage.chain_id.clone(), None) .add_code(tx_code) .add_serialized_data(tx_data) - .add_gas_payer(keypair_1()) - .signed_build(); + .sign_wrapper(keypair_1()); let gas_meter = VpGasMeter::new(0); let (vp_wasm_cache, _vp_cache_dir) = @@ -1298,13 +1288,10 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = - TxBuilder::new(wl_storage.storage.chain_id.clone(), None); - let tx = tx_builder + let tx = Tx::new(wl_storage.storage.chain_id.clone(), None) .add_code(tx_code) .add_serialized_data(tx_data) - .add_gas_payer(keypair_1()) - .signed_build(); + .sign_wrapper(keypair_1()); let gas_meter = VpGasMeter::new(0); let (vp_wasm_cache, _vp_cache_dir) = @@ -1406,7 +1393,7 @@ mod tests { let tx_index = TxIndex::default(); let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let mut outer_tx = Tx::new(TxType::Raw); + let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = wl_storage.storage.chain_id.clone(); outer_tx.set_code(Code::new(tx_code)); outer_tx.set_data(Data::new(tx_data)); @@ -1491,7 +1478,7 @@ mod tests { let tx_index = TxIndex::default(); let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let mut outer_tx = Tx::new(TxType::Raw); + let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = wl_storage.storage.chain_id.clone(); outer_tx.set_code(Code::new(tx_code)); outer_tx.set_data(Data::new(tx_data)); @@ -1612,7 +1599,7 @@ mod tests { let tx_code = vec![]; let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let mut outer_tx = Tx::new(TxType::Raw); + let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = wl_storage.storage.chain_id.clone(); outer_tx.set_code(Code::new(tx_code)); outer_tx.set_data(Data::new(tx_data)); @@ -1734,7 +1721,7 @@ mod tests { let tx_code = vec![]; let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let mut outer_tx = Tx::new(TxType::Raw); + let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = wl_storage.storage.chain_id.clone(); outer_tx.set_code(Code::new(tx_code)); outer_tx.set_data(Data::new(tx_data)); @@ -1840,7 +1827,7 @@ mod tests { let tx_code = vec![]; let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let mut outer_tx = Tx::new(TxType::Raw); + let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = wl_storage.storage.chain_id.clone(); outer_tx.set_code(Code::new(tx_code)); outer_tx.set_data(Data::new(tx_data)); @@ -1945,13 +1932,10 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = - TxBuilder::new(wl_storage.storage.chain_id.clone(), None); - let tx = tx_builder + let tx = Tx::new(wl_storage.storage.chain_id.clone(), None) .add_code(tx_code) .add_serialized_data(tx_data) - .add_gas_payer(keypair_1()) - .signed_build(); + .sign_wrapper(keypair_1()); let gas_meter = VpGasMeter::new(0); let (vp_wasm_cache, _vp_cache_dir) = @@ -2083,13 +2067,10 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = - TxBuilder::new(wl_storage.storage.chain_id.clone(), None); - let tx = tx_builder + let tx = Tx::new(wl_storage.storage.chain_id.clone(), None) .add_code(tx_code) .add_serialized_data(tx_data) - .add_gas_payer(keypair_1()) - .signed_build(); + .sign_wrapper(keypair_1()); let gas_meter = VpGasMeter::new(0); let (vp_wasm_cache, _vp_cache_dir) = @@ -2259,13 +2240,10 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = - TxBuilder::new(wl_storage.storage.chain_id.clone(), None); - let tx = tx_builder + let tx = Tx::new(wl_storage.storage.chain_id.clone(), None) .add_code(tx_code) .add_serialized_data(tx_data) - .add_gas_payer(keypair_1()) - .signed_build(); + .sign_wrapper(keypair_1()); let gas_meter = VpGasMeter::new(0); let (vp_wasm_cache, _vp_cache_dir) = @@ -2404,13 +2382,10 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = - TxBuilder::new(wl_storage.storage.chain_id.clone(), None); - let tx = tx_builder + let tx = Tx::new(wl_storage.storage.chain_id.clone(), None) .add_code(tx_code) .add_serialized_data(tx_data) - .add_gas_payer(keypair_1()) - .signed_build(); + .sign_wrapper(keypair_1()); let gas_meter = VpGasMeter::new(0); let (vp_wasm_cache, _vp_cache_dir) = @@ -2554,13 +2529,10 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = - TxBuilder::new(wl_storage.storage.chain_id.clone(), None); - let tx = tx_builder + let tx = Tx::new(wl_storage.storage.chain_id.clone(), None) .add_code(tx_code) .add_serialized_data(tx_data) - .add_gas_payer(keypair_1()) - .signed_build(); + .sign_wrapper(keypair_1()); let gas_meter = VpGasMeter::new(0); let (vp_wasm_cache, _vp_cache_dir) = @@ -2704,13 +2676,10 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = - TxBuilder::new(wl_storage.storage.chain_id.clone(), None); - let tx = tx_builder + let tx = Tx::new(wl_storage.storage.chain_id.clone(), None) .add_code(tx_code) .add_serialized_data(tx_data) - .add_gas_payer(keypair_1()) - .signed_build(); + .sign_wrapper(keypair_1()); let gas_meter = VpGasMeter::new(0); let (vp_wasm_cache, _vp_cache_dir) = diff --git a/shared/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs b/shared/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs index 075c9e38f1..6bcc0d058f 100644 --- a/shared/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs +++ b/shared/src/ledger/native_vp/ethereum_bridge/bridge_pool_vp.rs @@ -363,7 +363,6 @@ mod test_bridge_pool_vp { use crate::types::hash::Hash; use crate::types::storage::TxIndex; use crate::types::transaction::TxType; - use crate::types::tx::TxBuilder; use crate::vm::wasm::VpCache; use crate::vm::WasmCacheRwAccess; @@ -568,7 +567,7 @@ mod test_bridge_pool_vp { { // setup let mut wl_storage = setup_storage(); - let tx = Tx::new(TxType::Raw); + let tx = Tx::from_type(TxType::Raw); // the transfer to be added to the pool let transfer = PendingTransfer { @@ -624,9 +623,8 @@ mod test_bridge_pool_vp { ), }; - let tx_builder = - TxBuilder::new(wl_storage.storage.chain_id.clone(), None); - let tx = tx_builder.add_data(transfer).signed_build(); + let tx = Tx::new(wl_storage.storage.chain_id.clone(), None) + .add_data(transfer); let res = vp.validate_tx(&tx, &keys_changed, &verifiers); match expect { @@ -908,7 +906,7 @@ mod test_bridge_pool_vp { fn test_adding_transfer_twice_fails() { // setup let mut wl_storage = setup_storage(); - let tx = Tx::new(TxType::Raw); + let tx = Tx::from_type(TxType::Raw); // the transfer to be added to the pool let transfer = initial_pool(); @@ -963,9 +961,8 @@ mod test_bridge_pool_vp { ), }; - let tx_builder = - TxBuilder::new(wl_storage.storage.chain_id.clone(), None); - let tx = tx_builder.add_data(transfer).signed_build(); + let tx = Tx::new(wl_storage.storage.chain_id.clone(), None) + .add_data(transfer); let res = vp.validate_tx(&tx, &keys_changed, &verifiers); assert!(!res.expect("Test failed")); @@ -977,7 +974,7 @@ mod test_bridge_pool_vp { fn test_zero_gas_fees_rejected() { // setup let mut wl_storage = setup_storage(); - let tx = Tx::new(TxType::Raw); + let tx = Tx::from_type(TxType::Raw); // the transfer to be added to the pool let transfer = PendingTransfer { @@ -1026,9 +1023,8 @@ mod test_bridge_pool_vp { ), }; - let tx_builder = - TxBuilder::new(wl_storage.storage.chain_id.clone(), None); - let tx = tx_builder.add_data(transfer).signed_build(); + let tx = Tx::new(wl_storage.storage.chain_id.clone(), None) + .add_data(transfer); let res = vp .validate_tx(&tx, &keys_changed, &verifiers) @@ -1044,7 +1040,7 @@ mod test_bridge_pool_vp { let mut wl_storage = setup_storage(); let eb_account_key = balance_key(&nam(), &Address::Internal(InternalAddress::EthBridge)); - let tx = Tx::new(TxType::Raw); + let tx = Tx::from_type(TxType::Raw); // the transfer to be added to the pool let transfer = PendingTransfer { @@ -1113,9 +1109,8 @@ mod test_bridge_pool_vp { ), }; - let tx_builder = - TxBuilder::new(wl_storage.storage.chain_id.clone(), None); - let tx = tx_builder.add_data(transfer).signed_build(); + let tx = Tx::new(wl_storage.storage.chain_id.clone(), None) + .add_data(transfer); let res = vp .validate_tx(&tx, &keys_changed, &verifiers) @@ -1130,7 +1125,7 @@ mod test_bridge_pool_vp { fn test_reject_mint_wnam() { // setup let mut wl_storage = setup_storage(); - let tx = Tx::new(TxType::Raw); + let tx = Tx::from_type(TxType::Raw); let eb_account_key = balance_key(&nam(), &Address::Internal(InternalAddress::EthBridge)); @@ -1201,9 +1196,8 @@ mod test_bridge_pool_vp { ), }; - let tx_builder = - TxBuilder::new(wl_storage.storage.chain_id.clone(), None); - let tx = tx_builder.add_data(transfer).signed_build(); + let tx = Tx::new(wl_storage.storage.chain_id.clone(), None) + .add_data(transfer); let res = vp .validate_tx(&tx, &keys_changed, &verifiers) @@ -1239,7 +1233,7 @@ mod test_bridge_pool_vp { ) .expect("Test failed"); wl_storage.write_log.commit_tx(); - let tx = Tx::new(TxType::Raw); + let tx = Tx::from_type(TxType::Raw); // the transfer to be added to the pool let transfer = PendingTransfer { @@ -1316,9 +1310,8 @@ mod test_bridge_pool_vp { ), }; - let tx_builder = - TxBuilder::new(wl_storage.storage.chain_id.clone(), None); - let tx = tx_builder.add_data(transfer).signed_build(); + let tx = Tx::new(wl_storage.storage.chain_id.clone(), None) + .add_data(transfer); let res = vp .validate_tx(&tx, &keys_changed, &verifiers) diff --git a/shared/src/ledger/native_vp/ethereum_bridge/vp.rs b/shared/src/ledger/native_vp/ethereum_bridge/vp.rs index f2b0f5245e..b07af36766 100644 --- a/shared/src/ledger/native_vp/ethereum_bridge/vp.rs +++ b/shared/src/ledger/native_vp/ethereum_bridge/vp.rs @@ -590,7 +590,7 @@ mod tests { let verifiers = BTreeSet::from([BRIDGE_POOL_ADDRESS]); // set up the VP - let tx = Tx::new(TxType::Raw); + let tx = Tx::from_type(TxType::Raw); let vp = EthBridge { ctx: setup_ctx( &tx, @@ -640,7 +640,7 @@ mod tests { let verifiers = BTreeSet::from([BRIDGE_POOL_ADDRESS]); // set up the VP - let tx = Tx::new(TxType::Raw); + let tx = Tx::from_type(TxType::Raw); let vp = EthBridge { ctx: setup_ctx( &tx, @@ -693,7 +693,7 @@ mod tests { let verifiers = BTreeSet::from([]); // set up the VP - let tx = Tx::new(TxType::Raw); + let tx = Tx::from_type(TxType::Raw); let vp = EthBridge { ctx: setup_ctx( &tx, diff --git a/shared/src/ledger/native_vp/multitoken.rs b/shared/src/ledger/native_vp/multitoken.rs index a932714240..b109e754ec 100644 --- a/shared/src/ledger/native_vp/multitoken.rs +++ b/shared/src/ledger/native_vp/multitoken.rs @@ -166,7 +166,7 @@ mod tests { fn dummy_tx(wl_storage: &TestWlStorage) -> Tx { let tx_code = vec![]; let tx_data = vec![]; - let mut tx = Tx::new(TxType::Raw); + let mut tx = Tx::from_type(TxType::Raw); tx.header.chain_id = wl_storage.storage.chain_id.clone(); tx.set_code(Code::new(tx_code)); tx.set_data(Data::new(tx_data)); diff --git a/shared/src/ledger/queries/shell.rs b/shared/src/ledger/queries/shell.rs index 38fb7ca61a..3637d7e33b 100644 --- a/shared/src/ledger/queries/shell.rs +++ b/shared/src/ledger/queries/shell.rs @@ -539,7 +539,7 @@ mod test { assert_eq!(current_epoch, read_epoch); // Request dry run tx - let mut outer_tx = Tx::new(TxType::Decrypted(DecryptedTx::Decrypted { + let mut outer_tx = Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted { #[cfg(not(feature = "mainnet"))] // To be able to dry-run testnet faucet withdrawal, pretend // that we got a valid PoW diff --git a/shared/src/ledger/signing.rs b/shared/src/ledger/signing.rs index fb2b3f8088..717f2ed51f 100644 --- a/shared/src/ledger/signing.rs +++ b/shared/src/ledger/signing.rs @@ -47,7 +47,6 @@ use crate::types::transaction::governance::{ }; use crate::types::transaction::pos::InitValidator; use crate::types::transaction::{Fee, TxType}; -use crate::types::tx::TxBuilder; #[cfg(feature = "std")] /// Env. var specifying where to store signing test vectors @@ -360,12 +359,12 @@ pub async fn update_pow_challenge( /// progress on chain. pub async fn wrap_tx( client: &C, - tx_builder: TxBuilder, + tx_builder: Tx, args: &args::Tx, epoch: Epoch, gas_payer: common::PublicKey, #[cfg(not(feature = "mainnet"))] requires_pow: bool, -) -> TxBuilder { +) -> Tx { #[cfg(not(feature = "mainnet"))] let (pow_solution, fee) = solve_pow_challenge(client, args, &gas_payer, requires_pow).await; diff --git a/shared/src/ledger/tx.rs b/shared/src/ledger/tx.rs index fea06b9cbb..e7b2e24691 100644 --- a/shared/src/ledger/tx.rs +++ b/shared/src/ledger/tx.rs @@ -51,7 +51,6 @@ use crate::types::storage::Epoch; use crate::types::time::DateTimeUtc; use crate::types::transaction::account::{InitAccount, UpdateAccount}; use crate::types::transaction::{pos, TxType}; -use crate::types::tx::TxBuilder; use crate::types::{storage, token}; use crate::vm; use crate::vm::WasmValidationError; @@ -282,10 +281,10 @@ pub fn dump_tx(args: &args::Tx, tx: Tx) { pub async fn prepare_tx( client: &C, args: &args::Tx, - tx_builder: TxBuilder, + tx_builder: Tx, gas_payer: common::PublicKey, #[cfg(not(feature = "mainnet"))] requires_pow: bool, -) -> Result { +) -> Result { let tx_builder = if args.dry_run { tx_builder } else { @@ -393,7 +392,7 @@ pub async fn build_reveal_pk( address: &Address, public_key: &common::PublicKey, gas_payer: &common::PublicKey, -) -> Result { +) -> Result { println!( "Submitting a tx to reveal the public key for address {address}..." ); @@ -406,16 +405,15 @@ pub async fn build_reveal_pk( .unwrap(); let chain_id = args.chain_id.clone().unwrap(); - let tx_builder = TxBuilder::new(chain_id, args.expiration); - let tx_builder = tx_builder + let tx = Tx::new(chain_id, args.expiration) .add_code_from_hash(tx_code_hash) .add_data(public_key); prepare_tx::( client, args, - tx_builder, + tx, gas_payer.clone(), #[cfg(not(feature = "mainnet"))] false, @@ -627,7 +625,7 @@ pub async fn build_validator_commission_change< tx_code_path, }: args::CommissionRateChange, gas_payer: &common::PublicKey, -) -> Result { +) -> Result { let epoch = rpc::query_epoch(client).await; let tx_code_hash = @@ -690,7 +688,7 @@ pub async fn build_validator_commission_change< }; let chain_id = tx.chain_id.clone().unwrap(); - let tx_builder = TxBuilder::new(chain_id, tx.expiration); + let tx_builder = Tx::new(chain_id, tx.expiration); let tx_builder = tx_builder.add_code_from_hash(tx_code_hash).add_data(data); @@ -716,7 +714,7 @@ pub async fn build_unjail_validator< tx_code_path, }: args::TxUnjailValidator, gas_payer: &common::PublicKey, -) -> Result { +) -> Result { if !rpc::is_validator(client, &validator).await { eprintln!("The given address {} is not a validator.", &validator); if !tx.force { @@ -776,9 +774,7 @@ pub async fn build_unjail_validator< .map_err(Error::EncodeTxFailure)?; let chain_id = tx.chain_id.clone().unwrap(); - let tx_builder = TxBuilder::new(chain_id, tx.expiration); - - let tx_builder = tx_builder + let tx_builder = Tx::new(chain_id, tx.expiration) .add_code_from_hash(tx_code_hash) .add_data(validator.clone()); @@ -803,7 +799,7 @@ pub async fn build_withdraw( tx_code_path, }: args::Withdraw, gas_payer: &common::PublicKey, -) -> Result { +) -> Result { let epoch = rpc::query_epoch(client).await; let validator = @@ -847,9 +843,8 @@ pub async fn build_withdraw( let data = pos::Withdraw { validator, source }; let chain_id = tx.chain_id.clone().unwrap(); - let tx_builder = TxBuilder::new(chain_id, tx.expiration); - - let tx_builder = tx_builder.add_code_from_hash(tx_code_hash).add_data(data); + let tx_builder = Tx::new(chain_id, tx.expiration) + .add_code_from_hash(tx_code_hash).add_data(data); prepare_tx::( client, @@ -877,7 +872,7 @@ pub async fn build_unbond< tx_code_path, }: args::Unbond, gas_payer: &common::PublicKey, -) -> Result<(TxBuilder, Option<(Epoch, token::Amount)>), Error> { +) -> Result<(Tx, Option<(Epoch, token::Amount)>), Error> { let source = source.clone(); // Check the source's current bond amount let bond_source = source.clone().unwrap_or_else(|| validator.clone()); @@ -933,7 +928,7 @@ pub async fn build_unbond< }; let chain_id = tx.chain_id.clone().unwrap(); - let tx_builder = TxBuilder::new(chain_id, tx.expiration); + let tx_builder = Tx::new(chain_id, tx.expiration); let tx_builder = tx_builder.add_code_from_hash(tx_code_hash).add_data(data); @@ -1024,7 +1019,7 @@ pub async fn build_bond( tx_code_path, }: args::Bond, gas_payer: &common::PublicKey, -) -> Result { +) -> Result { let validator = known_validator_or_err(validator.clone(), tx.force, client).await?; @@ -1064,7 +1059,7 @@ pub async fn build_bond( }; let chain_id = tx.chain_id.clone().unwrap(); - let tx_builder = TxBuilder::new(chain_id, tx.expiration); + let tx_builder = Tx::new(chain_id, tx.expiration); let tx_builder = tx_builder.add_code_from_hash(tx_code_hash).add_data(data); @@ -1125,7 +1120,7 @@ pub async fn build_ibc_transfer( tx_code_path, }: args::TxIbcTransfer, gas_payer: &common::PublicKey, -) -> Result { +) -> Result { // Check that the source address exists on chain let source = source_exists_or_err(source.clone(), tx.force, client).await?; // We cannot check the receiver @@ -1195,7 +1190,7 @@ pub async fn build_ibc_transfer( let chain_id = tx.chain_id.clone().unwrap(); - let tx_builder = TxBuilder::new(chain_id, tx.expiration); + let tx_builder = Tx::new(chain_id, tx.expiration); let tx_builder = tx_builder .add_code_from_hash(tx_code_hash) .add_serialized_data(data); @@ -1293,7 +1288,7 @@ pub async fn build_transfer< shielded: &mut ShieldedContext, mut args: args::TxTransfer, gas_payer: &common::PublicKey, -) -> Result<(TxBuilder, Option), Error> { +) -> Result<(Tx, Option), Error> { let source = args.source.effective_address(); let target = args.target.effective_address(); let token = args.token.clone(); @@ -1380,7 +1375,7 @@ pub async fn build_transfer< }?; let chain_id = args.tx.chain_id.clone().unwrap(); - let tx_builder = TxBuilder::new(chain_id, args.tx.expiration); + let tx_builder = Tx::new(chain_id, args.tx.expiration); // Add the MASP Transaction and its Builder to facilitate validation let (tx_builder, masp_hash, shielded_tx_epoch) = @@ -1453,7 +1448,7 @@ pub async fn build_init_account( threshold, }: args::TxInitAccount, gas_payer: &common::PublicKey, -) -> Result { +) -> Result { let vp_code_hash = query_wasm_code_hash(client, vp_code_path.to_str().unwrap()) .await @@ -1476,7 +1471,7 @@ pub async fn build_init_account( }; let chain_id = tx.chain_id.clone().unwrap(); - let tx_builder = TxBuilder::new(chain_id, tx.expiration); + let tx_builder = Tx::new(chain_id, tx.expiration); let (tx_builder, extra_section_hash) = tx_builder.add_extra_section_from_hash(vp_code_hash); @@ -1512,7 +1507,7 @@ pub async fn build_update_account( threshold, }: args::TxUpdateAccount, gas_payer: &common::PublicKey, -) -> Result { +) -> Result { let addr = if let Some(account) = rpc::get_account_info(client, &addr).await { account.address @@ -1539,7 +1534,7 @@ pub async fn build_update_account( .unwrap(); let chain_id = tx.chain_id.clone().unwrap(); - let tx_builder = TxBuilder::new(chain_id, tx.expiration); + let tx_builder = Tx::new(chain_id, tx.expiration); let (tx_builder, extra_section_hash) = match vp_code_hash { Some(vp_code_hash) => { @@ -1580,14 +1575,14 @@ pub async fn build_custom( owner: _, }: args::TxCustom, gas_payer: &common::PublicKey, -) -> Result { +) -> Result { let tx_code_hash = query_wasm_code_hash(client, code_path.to_str().unwrap()) .await .unwrap(); let chain_id = tx.chain_id.clone().unwrap(); - let mut tx_builder = TxBuilder::new(chain_id, tx.expiration); + let mut tx_builder = Tx::new(chain_id, tx.expiration); tx_builder = tx_builder.add_code_from_hash(tx_code_hash); diff --git a/shared/src/types/tx.rs b/shared/src/types/tx.rs index a28da9c770..bf4df1b79c 100644 --- a/shared/src/types/tx.rs +++ b/shared/src/types/tx.rs @@ -1,17 +1,12 @@ //! Helper structures to build transactions - -use borsh::BorshSerialize; -use masp_primitives::transaction::Transaction; -use namada_core::ledger::testnet_pow; use namada_core::proto::{ - Code, Data, MaspBuilder, MultiSignature, Section, Signature, Tx, + MultiSignature, Section, Signature, Tx, }; use namada_core::types::account::AccountPublicKeysMap; use namada_core::types::chain::ChainId; use namada_core::types::hash::Hash; use namada_core::types::key::common; -use namada_core::types::storage::Epoch; -use namada_core::types::transaction::{Fee, GasLimit, TxType, WrapperTx}; +use namada_core::types::transaction::{TxType, WrapperTx}; use crate::types::time::DateTimeUtc; @@ -26,179 +21,3 @@ pub struct TxBuilder { signing_keys: Vec, account_public_keys_map: Option, } - -impl TxBuilder { - /// Initialize a new transaction builder - pub fn new(chain_id: ChainId, expiration: Option) -> Self { - Self { - chain_id, - expiration, - sections: vec![], - wrapper: None, - gas_payer: None, - signing_keys: vec![], - account_public_keys_map: None, - } - } - - /// Add an extra section to the tx builder by hash - pub fn add_extra_section_from_hash(mut self, hash: Hash) -> (Self, Hash) { - let sec = self._add_section(Section::ExtraData(Code::from_hash(hash))); - (self, sec.get_hash()) - } - - /// Add an extra section to the tx builder by code - pub fn add_extra_section(mut self, code: Vec) -> (Self, Hash) { - let sec = self._add_section(Section::ExtraData(Code::new(code))); - (self, sec.get_hash()) - } - - /// Add a masp tx section to the tx builder - pub fn add_masp_tx_section(mut self, tx: Transaction) -> (Self, Hash) { - let sec = self._add_section(Section::MaspTx(tx)); - (self, sec.get_hash()) - } - - /// Add a masp builder section to the tx builder - pub fn add_masp_builder(mut self, builder: MaspBuilder) -> Self { - let _sec = self._add_section(Section::MaspBuilder(builder)); - self - } - - /// Add wasm code to the tx builder from hash - pub fn add_code_from_hash(mut self, code_hash: Hash) -> Self { - self._add_section(Section::Code(Code::from_hash(code_hash))); - self - } - - /// Add wasm code to the tx builder - pub fn add_code(mut self, code: Vec) -> Self { - self._add_section(Section::Code(Code::new(code))); - self - } - - /// Add wasm data to the tx builder - pub fn add_data(mut self, data: impl BorshSerialize) -> Self { - let bytes = data.try_to_vec().expect("Encoding tx data shouldn't fail"); - self._add_section(Section::Data(Data::new(bytes))); - self - } - - /// Add wasm data already serialized to the tx builder - pub fn add_serialized_data(mut self, bytes: Vec) -> Self { - self._add_section(Section::Data(Data::new(bytes))); - self - } - - /// Add wrapper tx to the tx builder - pub fn add_wrapper( - mut self, - fee: Fee, - gas_payer: common::PublicKey, - epoch: Epoch, - gas_limit: GasLimit, - #[cfg(not(feature = "mainnet"))] requires_pow: Option< - testnet_pow::Solution, - >, - ) -> Self { - self.wrapper = Some(WrapperTx::new( - fee, - gas_payer, - epoch, - gas_limit, - #[cfg(not(feature = "mainnet"))] - requires_pow, - )); - self - } - - /// Add fee payer keypair to the tx builder - pub fn add_gas_payer(mut self, keypair: common::SecretKey) -> Self { - self.gas_payer = Some(keypair); - self - } - - /// Add signing keys to the tx builder - pub fn add_signing_keys( - mut self, - keypairs: Vec, - account_public_keys_map: AccountPublicKeysMap, - ) -> Self { - self.signing_keys = keypairs; - self.account_public_keys_map = Some(account_public_keys_map); - self - } - - /// Generate the corresponding tx - pub fn unsigned_build(self) -> Tx { - let mut tx = Tx::new(TxType::Raw); - tx.header.chain_id = self.chain_id; - tx.header.expiration = self.expiration; - - for section in self.sections.clone() { - tx.add_section(section); - } - - for section in self.sections { - match section { - Section::Data(_) => tx.set_data_sechash(section.get_hash()), - Section::Code(_) => tx.set_code_sechash(section.get_hash()), - _ => continue, - } - } - if let Some(wrapper) = self.wrapper { - tx.update_header(TxType::Wrapper(Box::new(wrapper))); - } - - tx - } - - /// Generate the corresponding tx - pub fn signed_build(self) -> Tx { - let account_public_keys_map = self.account_public_keys_map.clone(); - let gas_payer = self.gas_payer.clone(); - let signing_keys = self.signing_keys.clone(); - let mut tx = self.unsigned_build(); - - tx.protocol_filter(); - - if let Some(account_public_keys_map) = account_public_keys_map { - let hashes = tx - .sections - .iter() - .filter_map(|section| match section { - Section::Data(_) | Section::Code(_) => { - Some(section.get_hash()) - } - _ => None, - }) - .collect(); - tx.add_section(Section::SectionSignature(MultiSignature::new( - hashes, - &signing_keys, - &account_public_keys_map, - ))); - } - - if let Some(keypair) = gas_payer { - let mut sections_hashes = tx - .sections - .iter() - .map(|section| section.get_hash()) - .collect::>(); - sections_hashes.push(tx.header_hash()); - tx.add_section(Section::Signature(Signature::new( - sections_hashes, - &keypair, - ))); - } - - tx - } - - /// Internal method to add a section to the builder - fn _add_section(&mut self, section: Section) -> Section { - self.sections.push(section); - self.sections.last().unwrap().clone() - } -} diff --git a/shared/src/vm/wasm/run.rs b/shared/src/vm/wasm/run.rs index 0dc6842282..c869c358ea 100644 --- a/shared/src/vm/wasm/run.rs +++ b/shared/src/vm/wasm/run.rs @@ -482,7 +482,6 @@ mod tests { use crate::proto::{Code, Data}; use crate::types::hash::Hash; use crate::types::transaction::TxType; - use crate::types::tx::TxBuilder; use crate::types::validity_predicate::EvalVp; use crate::vm::wasm; @@ -552,7 +551,7 @@ mod tests { wasm::compilation_cache::common::testing::cache(); let (mut tx_cache, _) = wasm::compilation_cache::common::testing::cache(); - let mut outer_tx = Tx::new(TxType::Raw); + let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.set_code(Code::new(tx_code.clone())); outer_tx.set_data(Data::new(tx_data)); let result = tx( @@ -569,7 +568,7 @@ mod tests { // Allocating `2^24` (16 MiB) should be above the memory limit and // should fail let tx_data = 2_usize.pow(24).try_to_vec().unwrap(); - let mut outer_tx = Tx::new(TxType::Raw); + let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.set_code(Code::new(tx_code)); outer_tx.set_data(Data::new(tx_data)); let error = tx( @@ -619,20 +618,18 @@ mod tests { // shouldn't fail let input = 2_usize.pow(23).try_to_vec().unwrap(); - let tx_builder = TxBuilder::new(storage.chain_id.clone(), None); - let tx = tx_builder + let tx = Tx::new(storage.chain_id.clone(), None) .add_code(vec![]) - .add_serialized_data(input) - .signed_build(); + .add_serialized_data(input); let eval_vp = EvalVp { vp_code_hash: limit_code_hash, input: tx, }; - let tx_builder = TxBuilder::new(storage.chain_id.clone(), None); - let outer_tx = - tx_builder.add_code(vec![]).add_data(eval_vp).signed_build(); + let outer_tx = Tx::new(storage.chain_id.clone(), None) + .add_code(vec![]) + .add_data(eval_vp); let (vp_cache, _) = wasm::compilation_cache::common::testing::cache(); // When the `eval`ed VP doesn't run out of memory, it should return @@ -657,17 +654,18 @@ mod tests { // Allocating `2^24` (16 MiB) should be above the memory limit and // should fail let input = 2_usize.pow(24).try_to_vec().unwrap(); - let tx_builder = TxBuilder::new(storage.chain_id.clone(), None); - let tx = tx_builder.add_code(vec![]).add_data(input).signed_build(); + let tx = Tx::new(storage.chain_id.clone(), None) + .add_code(vec![]) + .add_data(input); let eval_vp = EvalVp { vp_code_hash: limit_code_hash, input: tx, }; - let tx_builder = TxBuilder::new(storage.chain_id.clone(), None); - let outer_tx = - tx_builder.add_code(vec![]).add_data(eval_vp).signed_build(); + let outer_tx = Tx::new(storage.chain_id.clone(), None) + .add_code(vec![]) + .add_data(eval_vp); // When the `eval`ed VP runs out of memory, its result should be // `false`, hence we should also get back `false` from the VP that @@ -716,7 +714,7 @@ mod tests { // Allocating `2^23` (8 MiB) should be below the memory limit and // shouldn't fail let tx_data = 2_usize.pow(23).try_to_vec().unwrap(); - let mut outer_tx = Tx::new(TxType::Raw); + let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = storage.chain_id.clone(); outer_tx.set_data(Data::new(tx_data)); outer_tx.set_code(Code::new(vec![])); @@ -740,7 +738,7 @@ mod tests { // Allocating `2^24` (16 MiB) should be above the memory limit and // should fail let tx_data = 2_usize.pow(24).try_to_vec().unwrap(); - let mut outer_tx = Tx::new(TxType::Raw); + let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = storage.chain_id.clone(); outer_tx.set_data(Data::new(tx_data)); let error = vp( @@ -788,7 +786,7 @@ mod tests { wasm::compilation_cache::common::testing::cache(); let (mut tx_cache, _) = wasm::compilation_cache::common::testing::cache(); - let mut outer_tx = Tx::new(TxType::Raw); + let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.set_code(Code::new(tx_no_op)); outer_tx.set_data(Data::new(tx_data)); let result = tx( @@ -844,7 +842,7 @@ mod tests { // limit and should fail let len = 2_usize.pow(24); let tx_data: Vec = vec![6_u8; len]; - let mut outer_tx = Tx::new(TxType::Raw); + let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = storage.chain_id.clone(); outer_tx.set_data(Data::new(tx_data)); outer_tx.set_code(Code::new(vec![])); @@ -916,7 +914,7 @@ mod tests { wasm::compilation_cache::common::testing::cache(); let (mut tx_cache, _) = wasm::compilation_cache::common::testing::cache(); - let mut outer_tx = Tx::new(TxType::Raw); + let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.set_code(Code::new(tx_read_key)); outer_tx.set_data(Data::new(tx_data)); let error = tx( @@ -964,7 +962,7 @@ mod tests { // Borsh. storage.write(&key, value.try_to_vec().unwrap()).unwrap(); let tx_data = key.try_to_vec().unwrap(); - let mut outer_tx = Tx::new(TxType::Raw); + let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.header.chain_id = storage.chain_id.clone(); outer_tx.set_data(Data::new(tx_data)); outer_tx.set_code(Code::new(vec![])); @@ -1028,20 +1026,18 @@ mod tests { storage.write(&key, value.try_to_vec().unwrap()).unwrap(); let input = 2_usize.pow(23).try_to_vec().unwrap(); - let tx_builder = TxBuilder::new(storage.chain_id.clone(), None); - let tx = tx_builder + let tx = Tx::new(storage.chain_id.clone(), None) .add_code(vec![]) - .add_serialized_data(input) - .signed_build(); + .add_serialized_data(input); let eval_vp = EvalVp { vp_code_hash: read_code_hash, input: tx, }; - let tx_builder = TxBuilder::new(storage.chain_id.clone(), None); - let outer_tx = - tx_builder.add_code(vec![]).add_data(eval_vp).signed_build(); + let outer_tx = Tx::new(storage.chain_id.clone(), None) + .add_code(vec![]) + .add_data(eval_vp); let (vp_cache, _) = wasm::compilation_cache::common::testing::cache(); let passed = vp( @@ -1112,7 +1108,7 @@ mod tests { let key = Key::wasm_code(&code_hash); write_log.write(&key, tx_code).unwrap(); - let mut outer_tx = Tx::new(TxType::Raw); + let mut outer_tx = Tx::from_type(TxType::Raw); outer_tx.set_code(Code::from_hash(code_hash)); outer_tx.set_data(Data::new(tx_data)); @@ -1156,7 +1152,7 @@ mod tests { ) .expect("unexpected error converting wat2wasm").into_owned(); - let outer_tx = Tx::new(TxType::Raw); + let outer_tx = Tx::from_type(TxType::Raw); let tx_index = TxIndex::default(); let mut storage = TestStorage::default(); let addr = storage.address_gen.generate_address("rng seed"); diff --git a/tests/src/native_vp/eth_bridge_pool.rs b/tests/src/native_vp/eth_bridge_pool.rs index 630485e674..afd87f8e9e 100644 --- a/tests/src/native_vp/eth_bridge_pool.rs +++ b/tests/src/native_vp/eth_bridge_pool.rs @@ -17,7 +17,6 @@ mod test_bridge_pool_vp { use namada::types::ethereum_events::EthAddress; use namada::types::key::{common, ed25519, SecretKey}; use namada::types::token::Amount; - use namada::types::tx::TxBuilder; use namada_apps::wallet::defaults::{albert_address, bertha_address}; use namada_apps::wasm_loader; @@ -109,12 +108,10 @@ mod test_bridge_pool_vp { let wasm_code = wasm_loader::read_wasm_or_exit(wasm_dir(), ADD_TRANSFER_WASM); - let tx_builder = TxBuilder::new(ChainId::default(), None); - tx_builder + Tx::new(ChainId::default(), None) .add_code(wasm_code) .add_serialized_data(data) - .add_gas_payer(keypair.clone()) - .signed_build() + .sign_wrapper(keypair.clone()) } #[test] diff --git a/tests/src/vm_host_env/mod.rs b/tests/src/vm_host_env/mod.rs index 828ee20456..a6dcc81314 100644 --- a/tests/src/vm_host_env/mod.rs +++ b/tests/src/vm_host_env/mod.rs @@ -29,10 +29,10 @@ mod tests { use namada::ledger::tx_env::TxEnv; use namada::types::hash::Hash; use namada::types::key::*; + use namada::proto::Tx; use namada::types::storage::{self, BlockHash, BlockHeight, Key, KeySeg}; use namada::types::time::DateTimeUtc; use namada::types::token::{self, Amount}; - use namada::types::tx::TxBuilder; use namada::types::{address, key}; use namada_core::ledger::ibc::context::transfer_mod::testing::DummyTransferModule; use namada_core::ledger::ibc::Error as IbcActionError; @@ -461,13 +461,11 @@ mod tests { let pks_map = AccountPublicKeysMap::from_iter(vec![pk.clone()]); let signed_tx_data = vp_host_env::with(|env| { let chain_id = env.wl_storage.storage.chain_id.clone(); - let tx_builder = TxBuilder::new(chain_id, expiration); - let tx = tx_builder + let tx = Tx::new(chain_id, expiration) .add_code(code.clone()) .add_serialized_data(data.to_vec()) - .add_gas_payer(keypair.clone()) - .add_signing_keys(keypairs.clone(), pks_map.clone()) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); env.tx = tx; env.tx.clone() @@ -559,13 +557,11 @@ mod tests { key::testing::keypair_1().ref_to(), ]); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(input_data.clone()) - .add_gas_payer(keypair.clone()) - .add_signing_keys(keypairs.clone(), pks_map.clone()) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); let result = vp::CTX.eval(empty_code, tx).unwrap(); assert!(!result); @@ -577,13 +573,11 @@ mod tests { let key = Key::wasm_code(&code_hash); env.wl_storage.storage.write(&key, code.clone()).unwrap(); }); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code_from_hash(code_hash) .add_serialized_data(input_data.clone()) - .add_gas_payer(keypair.clone()) - .add_signing_keys(keypairs.clone(), pks_map.clone()) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); let result = vp::CTX.eval(code_hash, tx).unwrap(); assert!(result); @@ -596,13 +590,11 @@ mod tests { let key = Key::wasm_code(&code_hash); env.wl_storage.storage.write(&key, code.clone()).unwrap(); }); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code_from_hash(code_hash) - .add_serialized_data(input_data) - .add_gas_payer(keypair) - .add_signing_keys(keypairs, pks_map) - .signed_build(); + .add_serialized_data(input_data.clone()) + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); let result = vp::CTX.eval(code_hash, tx).unwrap(); assert!(!result); } @@ -623,13 +615,11 @@ mod tests { let msg = ibc::msg_create_client(); let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair.clone()) - .add_signing_keys(keypairs.clone(), pks_map.clone()) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // create a client with the message tx_host_env::ibc::ibc_actions(tx::ctx()) @@ -659,13 +649,11 @@ mod tests { let msg = ibc::msg_update_client(client_id); let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair) - .add_signing_keys(keypairs, pks_map) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // update the client with the message tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) @@ -704,13 +692,11 @@ mod tests { let msg = ibc::msg_connection_open_init(client_id); let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair.clone()) - .add_signing_keys(keypairs.clone(), pks_map.clone()) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // init a connection with the message tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) @@ -739,13 +725,11 @@ mod tests { let msg = ibc::msg_connection_open_ack(conn_id, client_state); let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair) - .add_signing_keys(keypairs, pks_map) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // open the connection with the message tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) @@ -785,13 +769,11 @@ mod tests { let msg = ibc::msg_connection_open_try(client_id, client_state); let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair.clone()) - .add_signing_keys(keypairs.clone(), pks_map.clone()) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // open try a connection with the message tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) @@ -820,13 +802,11 @@ mod tests { let msg = ibc::msg_connection_open_confirm(conn_id); let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair) - .add_signing_keys(keypairs, pks_map) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // open the connection with the mssage tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) @@ -868,13 +848,11 @@ mod tests { let msg = ibc::msg_channel_open_init(port_id.clone(), conn_id); let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair.clone()) - .add_signing_keys(keypairs.clone(), pks_map.clone()) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // init a channel with the message tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) @@ -903,13 +881,11 @@ mod tests { let msg = ibc::msg_channel_open_ack(port_id, channel_id); let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair) - .add_signing_keys(keypairs, pks_map) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // open the channle with the message tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) @@ -951,13 +927,11 @@ mod tests { let msg = ibc::msg_channel_open_try(port_id.clone(), conn_id); let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair.clone()) - .add_signing_keys(keypairs.clone(), pks_map.clone()) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // try open a channel with the message tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) @@ -987,13 +961,11 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair) - .add_signing_keys(keypairs, pks_map) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // open a channel with the message tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) @@ -1038,13 +1010,11 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair) - .add_signing_keys(keypairs, pks_map) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // close the channel with the message let mut actions = tx_host_env::ibc::ibc_actions(tx::ctx()); // the dummy module closes the channel @@ -1097,13 +1067,11 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair) - .add_signing_keys(keypairs, pks_map) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // close the channel with the message tx_host_env::ibc::ibc_actions(tx::ctx()) @@ -1153,13 +1121,11 @@ mod tests { .encode(&mut tx_data) .expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair.clone()) - .add_signing_keys(keypairs.clone(), pks_map.clone()) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // send the token and a packet with the data tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) @@ -1202,13 +1168,11 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair) - .add_signing_keys(keypairs, pks_map) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // ack the packet with the message tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) @@ -1289,13 +1253,11 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair) - .add_signing_keys(keypairs, pks_map) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // send the token and a packet with the data tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) @@ -1364,13 +1326,11 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair) - .add_signing_keys(keypairs, pks_map) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // receive a packet with the message tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) @@ -1461,13 +1421,11 @@ mod tests { let msg = ibc::msg_packet_recv(packet); let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair) - .add_signing_keys(keypairs, pks_map) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // receive a packet with the message tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) @@ -1562,13 +1520,11 @@ mod tests { let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair) - .add_signing_keys(keypairs, pks_map) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // receive a packet with the message tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) @@ -1664,13 +1620,11 @@ mod tests { let msg = ibc::msg_timeout(packet, ibc::Sequence::from(1)); let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair) - .add_signing_keys(keypairs, pks_map) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // timeout the packet tx_host_env::ibc::ibc_actions(tx::ctx()) @@ -1755,13 +1709,11 @@ mod tests { let msg = ibc::msg_timeout_on_close(packet, ibc::Sequence::from(1)); let mut tx_data = vec![]; msg.to_any().encode(&mut tx_data).expect("encoding failed"); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(vec![]) .add_serialized_data(tx_data.clone()) - .add_gas_payer(keypair) - .add_signing_keys(keypairs, pks_map) - .signed_build(); + .sign_raw(keypairs.clone(), pks_map.clone()) + .sign_wrapper(keypair.clone()); // timeout the packet tx_host_env::ibc::ibc_actions(tx::ctx()) diff --git a/tests/src/vm_host_env/tx.rs b/tests/src/vm_host_env/tx.rs index aad6510c89..a0e88ab802 100644 --- a/tests/src/vm_host_env/tx.rs +++ b/tests/src/vm_host_env/tx.rs @@ -68,7 +68,7 @@ impl Default for TestTxEnv { storage: TestStorage::default(), write_log: WriteLog::default(), }; - let mut tx = Tx::new(TxType::Raw); + let mut tx = Tx::from_type(TxType::Raw); tx.header.chain_id = wl_storage.storage.chain_id.clone(); Self { wl_storage, diff --git a/tests/src/vm_host_env/vp.rs b/tests/src/vm_host_env/vp.rs index 02561dbc9a..890d0681d8 100644 --- a/tests/src/vm_host_env/vp.rs +++ b/tests/src/vm_host_env/vp.rs @@ -69,7 +69,7 @@ impl Default for TestVpEnv { storage: TestStorage::default(), write_log: WriteLog::default(), }; - let mut tx = Tx::new(TxType::Raw); + let mut tx = Tx::from_type(TxType::Raw); tx.header.chain_id = wl_storage.storage.chain_id.clone(); Self { addr: address::testing::established_address_1(), diff --git a/wasm/checksums.json b/wasm/checksums.json index 299026d034..6be14fff95 100644 --- a/wasm/checksums.json +++ b/wasm/checksums.json @@ -1,21 +1,21 @@ { - "tx_bond.wasm": "tx_bond.6dab033347a4cf795766647c8d10c96fba846e175363ae7eafb7579086a0c6be.wasm", - "tx_bridge_pool.wasm": "tx_bridge_pool.2eb8571aa6ca038d9107d3ca9c239f2de21e8e1d1db433f3d02ae87bfc509716.wasm", - "tx_change_validator_commission.wasm": "tx_change_validator_commission.9e3f0ff2c6a63f564a820fb6daa2ca5963fee021807cb9e848040db3500b48d9.wasm", - "tx_ibc.wasm": "tx_ibc.b6f20875dc1752ddf1bde189664b1d9e35ace8df5eafc4164269b923013e1fa0.wasm", - "tx_init_account.wasm": "tx_init_account.91920a7c0522a5a67e54782da79d587ac11b644ee2396c7a20c445eefba782b4.wasm", - "tx_init_proposal.wasm": "tx_init_proposal.a0186249b967d875610e0fc12aaeddaab318c44070451fad32a1937b2ec166eb.wasm", - "tx_init_validator.wasm": "tx_init_validator.979953566037ace5a17153653050bd6bf1d7d81a49a261e4373396e2de2906b1.wasm", - "tx_reveal_pk.wasm": "tx_reveal_pk.b2cbf5efffe896224fd3bd4cd767551b51c797da9234956bc2f770c54a26c4d1.wasm", - "tx_transfer.wasm": "tx_transfer.03544c0c62de7c6df7acdf8fbde76f95b65b78259d762644c278bc16a429b7d7.wasm", - "tx_unbond.wasm": "tx_unbond.6564cd51796f0ed24cfee61639b6ceeb8c6ede7a6db01dabe32c9cf79b88fca5.wasm", - "tx_unjail_validator.wasm": "tx_unjail_validator.1a1f6088c5a9a2e4b639b2d9308ad68ad1cc24d599cc9233a1a3fc2d8996f667.wasm", - "tx_update_account.wasm": "tx_update_account.0d1225f015d5fde8e126f726404726ae6284a98a1a44de3e1cd647285d6d9e3e.wasm", - "tx_vote_proposal.wasm": "tx_vote_proposal.5254cb7f4d27066bd72a1542c2e2ff948149e15fefa93b9e1294800bb879fd9c.wasm", - "tx_withdraw.wasm": "tx_withdraw.64dcb178f9c79e870320de31d8aa29fad9696d8e96a1e5f68ce100343699ef17.wasm", - "vp_implicit.wasm": "vp_implicit.fe3e96ce941b0873f634c0fa4cec8a63a7027004118ae24afb3e8b7fa566301e.wasm", - "vp_masp.wasm": "vp_masp.7f383c7e1bdeed7cb6cfb482b859a2a4720c42dceda320872aa4977767c23fdb.wasm", - "vp_testnet_faucet.wasm": "vp_testnet_faucet.f202991ef774da0e5c3742a6e830fd03e16a7cbac63ae34307d7bb64976fe1de.wasm", - "vp_user.wasm": "vp_user.494711cec127cd9c77817f47673bc0bc18259a363b91b2e661fd0b427b3e8746.wasm", - "vp_validator.wasm": "vp_validator.02c4bdebf2217b8386e16c43f2cdd20d285296f35e712eb5325341a8bbf3a00d.wasm" + "tx_bond.wasm": "tx_bond.5687f128a774d34499756b741d9cf198ca105c026789559fc63a2db5e8f91592.wasm", + "tx_bridge_pool.wasm": "tx_bridge_pool.fb7cc5e64b963cd0422332339345925d63b7a068c9b547e23dfa7d5782ad83bc.wasm", + "tx_change_validator_commission.wasm": "tx_change_validator_commission.687eb4dba5a58596a7cffd2ffad9f59b13a618632b0fde69b8cc2a1e53f37c00.wasm", + "tx_ibc.wasm": "tx_ibc.bf505c58c2f83ec14b4af0102449bd58e11beb6f016aff736a3b540291fe9984.wasm", + "tx_init_account.wasm": "tx_init_account.001ee5754a34e5e2a178d018ab344d07f08834168f2393467497c44888bce0b6.wasm", + "tx_init_proposal.wasm": "tx_init_proposal.51530777fcffca49fc01748b85863b9e74eb4e654aae92770ab9b2ce4245286e.wasm", + "tx_init_validator.wasm": "tx_init_validator.5844c8b293d28498d82f1a4cc30c81112af226bac603507ab4c043669e82d81e.wasm", + "tx_reveal_pk.wasm": "tx_reveal_pk.a7469a53a55a14388ba9e886ca13b9cd629a0b65edc1a62a9ee878f73778a5b5.wasm", + "tx_transfer.wasm": "tx_transfer.bc7ff539877a8e00550db0faf0201763c3cd1f60245685f17cc5cb96d325ce42.wasm", + "tx_unbond.wasm": "tx_unbond.ee69928f76d2f85779b9c84cdba6fc04c4978d7a7f561c9874190b9fb2a5cc1e.wasm", + "tx_unjail_validator.wasm": "tx_unjail_validator.77d6c7372a5844c839b8a21d2eb058eacba09e2d7e0c006c4742b9f6c9d25711.wasm", + "tx_update_account.wasm": "tx_update_account.ea4d5421a5df7515b4a100a7316b399026574f5e94dc7b39d31bb06e50db76f7.wasm", + "tx_vote_proposal.wasm": "tx_vote_proposal.f82f44c1221e2c28d8adcee33bcab5fd80ff2dbdadb29cbc413db2dacda4672d.wasm", + "tx_withdraw.wasm": "tx_withdraw.56265eaeba53110c1e6320f4cf8d6cc78c10c5b134314dd4f343e3c6f8961e30.wasm", + "vp_implicit.wasm": "vp_implicit.67db110ac9d8a77bbead6343b405a7a1e4cc287e97411f1ed0b15e056cfe6e12.wasm", + "vp_masp.wasm": "vp_masp.c5248d56284544b2ebbeab3efede8e5177aabfc45efdd421f08a3f13951e2b94.wasm", + "vp_testnet_faucet.wasm": "vp_testnet_faucet.bb156478826ff8013e12bd15e247e5c9395f236f227f3828ba49bf4cefe6c886.wasm", + "vp_user.wasm": "vp_user.496d2fce07599ab0922f73ad1c3be83f99a791f5f35558d56d3ac57b77465915.wasm", + "vp_validator.wasm": "vp_validator.6a57799cfc59796a43a6ca1ebb9b5e5ef550eca953efa5efd8ea2ac4281da896.wasm" } \ No newline at end of file diff --git a/wasm/tx_template/src/lib.rs b/wasm/tx_template/src/lib.rs index 4a14783325..5b0f8fb501 100644 --- a/wasm/tx_template/src/lib.rs +++ b/wasm/tx_template/src/lib.rs @@ -19,7 +19,7 @@ mod tests { // The environment must be initialized first tx_host_env::init(); - let tx = Tx::new(TxType::Raw); + let tx = Tx::from_type(TxType::Raw); apply_tx(ctx(), tx).unwrap(); let env = tx_host_env::take(); diff --git a/wasm/wasm_source/src/tx_bond.rs b/wasm/wasm_source/src/tx_bond.rs index ac5b413fd9..7c233ed11a 100644 --- a/wasm/wasm_source/src/tx_bond.rs +++ b/wasm/wasm_source/src/tx_bond.rs @@ -24,7 +24,6 @@ mod tests { }; use namada::types::dec::Dec; use namada::types::storage::Epoch; - use namada::types::tx::TxBuilder; use namada_tests::log::test; use namada_tests::native_vp::pos::init_pos; use namada_tests::native_vp::TestNativeVpEnv; @@ -108,12 +107,10 @@ mod tests { let tx_code = vec![]; let tx_data = bond.try_to_vec().unwrap(); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(tx_code) .add_serialized_data(tx_data) - .add_gas_payer(key) - .signed_build(); + .sign_wrapper(key); let signed_tx = tx; diff --git a/wasm/wasm_source/src/tx_change_validator_commission.rs b/wasm/wasm_source/src/tx_change_validator_commission.rs index 16d5e0b6b2..ce0c79406a 100644 --- a/wasm/wasm_source/src/tx_change_validator_commission.rs +++ b/wasm/wasm_source/src/tx_change_validator_commission.rs @@ -23,7 +23,6 @@ mod tests { use namada::proof_of_stake::validator_commission_rate_handle; use namada::types::dec::{Dec, POS_DECIMAL_PRECISION}; use namada::types::storage::Epoch; - use namada::types::tx::TxBuilder; use namada_tests::log::test; use namada_tests::native_vp::pos::init_pos; use namada_tests::native_vp::TestNativeVpEnv; @@ -87,12 +86,10 @@ mod tests { let tx_code = vec![]; let tx_data = commission_change.try_to_vec().unwrap(); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(tx_code) .add_serialized_data(tx_data) - .add_gas_payer(key) - .signed_build(); + .sign_wrapper(key); let signed_tx = tx; diff --git a/wasm/wasm_source/src/tx_unbond.rs b/wasm/wasm_source/src/tx_unbond.rs index d1b8e1d277..250438b1f8 100644 --- a/wasm/wasm_source/src/tx_unbond.rs +++ b/wasm/wasm_source/src/tx_unbond.rs @@ -25,7 +25,6 @@ mod tests { }; use namada::types::dec::Dec; use namada::types::storage::Epoch; - use namada::types::tx::TxBuilder; use namada_tests::log::test; use namada_tests::native_vp::pos::init_pos; use namada_tests::native_vp::TestNativeVpEnv; @@ -127,12 +126,10 @@ mod tests { let tx_code = vec![]; let tx_data = unbond.try_to_vec().unwrap(); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(tx_code) .add_serialized_data(tx_data) - .add_gas_payer(key) - .signed_build(); + .sign_wrapper(key); let signed_tx = tx; let unbond_src = unbond diff --git a/wasm/wasm_source/src/tx_withdraw.rs b/wasm/wasm_source/src/tx_withdraw.rs index b8af8c4e49..1203dd4c22 100644 --- a/wasm/wasm_source/src/tx_withdraw.rs +++ b/wasm/wasm_source/src/tx_withdraw.rs @@ -24,7 +24,6 @@ mod tests { use namada::proof_of_stake::unbond_handle; use namada::types::dec::Dec; use namada::types::storage::Epoch; - use namada::types::tx::TxBuilder; use namada_tests::log::test; use namada_tests::native_vp::pos::init_pos; use namada_tests::native_vp::TestNativeVpEnv; @@ -171,12 +170,10 @@ mod tests { let tx_code = vec![]; let tx_data = withdraw.try_to_vec().unwrap(); - let tx_builder = TxBuilder::new(ChainId::default(), None); - let tx = tx_builder + let tx = Tx::new(ChainId::default(), None) .add_code(tx_code) .add_serialized_data(tx_data) - .add_gas_payer(key) - .signed_build(); + .ssign_wrapper(key); let signed_tx = tx; // Read data before we apply tx: diff --git a/wasm/wasm_source/src/vp_implicit.rs b/wasm/wasm_source/src/vp_implicit.rs index 3eaa7ad056..7b8e02692e 100644 --- a/wasm/wasm_source/src/vp_implicit.rs +++ b/wasm/wasm_source/src/vp_implicit.rs @@ -207,7 +207,7 @@ mod tests { /// Test that no-op transaction (i.e. no storage modifications) accepted. #[test] fn test_no_op_transaction() { - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let addr: Address = address::testing::established_address_1(); let keys_changed: BTreeSet = BTreeSet::default(); @@ -241,7 +241,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -268,7 +268,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -309,7 +309,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -369,7 +369,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::fom_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -448,7 +448,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -602,7 +602,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -741,7 +741,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -797,7 +797,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -880,7 +880,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); diff --git a/wasm/wasm_source/src/vp_testnet_faucet.rs b/wasm/wasm_source/src/vp_testnet_faucet.rs index 8436bf9707..f41909f0c5 100644 --- a/wasm/wasm_source/src/vp_testnet_faucet.rs +++ b/wasm/wasm_source/src/vp_testnet_faucet.rs @@ -129,7 +129,7 @@ mod tests { /// Test that no-op transaction (i.e. no storage modifications) accepted. #[test] fn test_no_op_transaction() { - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let addr: Address = address::testing::established_address_1(); let keys_changed: BTreeSet = BTreeSet::default(); @@ -183,7 +183,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -220,7 +220,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -334,7 +334,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -395,7 +395,7 @@ mod tests { let mut vp_env = vp_host_env::take(); // This is set by the protocol when the wrapper tx has a valid PoW vp_env.has_valid_pow = true; - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(solution_bytes)); tx_data.set_code(Code::new(vec![])); tx_data.add_section(Section::Signature(Signature::new(vec![*tx_data.data_sechash(), *tx_data.code_sechash()], &target_key))); diff --git a/wasm/wasm_source/src/vp_user.rs b/wasm/wasm_source/src/vp_user.rs index 895c845336..301210f194 100644 --- a/wasm/wasm_source/src/vp_user.rs +++ b/wasm/wasm_source/src/vp_user.rs @@ -196,7 +196,7 @@ mod tests { /// Test that no-op transaction (i.e. no storage modifications) accepted. #[test] fn test_no_op_transaction() { - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let addr: Address = address::testing::established_address_1(); let keys_changed: BTreeSet = BTreeSet::default(); @@ -256,7 +256,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -314,7 +314,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -463,7 +463,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -609,7 +609,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -665,7 +665,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -748,7 +748,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); tx_data.set_code(Code::new(vec![])); let keys_changed: BTreeSet = diff --git a/wasm/wasm_source/src/vp_validator.rs b/wasm/wasm_source/src/vp_validator.rs index 7d16d84380..77afb1cb38 100644 --- a/wasm/wasm_source/src/vp_validator.rs +++ b/wasm/wasm_source/src/vp_validator.rs @@ -203,7 +203,7 @@ mod tests { /// Test that no-op transaction (i.e. no storage modifications) accepted. #[test] fn test_no_op_transaction() { - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let addr: Address = address::testing::established_address_1(); let keys_changed: BTreeSet = BTreeSet::default(); @@ -263,7 +263,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -321,7 +321,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -476,7 +476,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -626,7 +626,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -682,7 +682,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); @@ -766,7 +766,7 @@ mod tests { }); let vp_env = vp_host_env::take(); - let mut tx_data = Tx::new(TxType::Raw); + let mut tx_data = Tx::from_type(TxType::Raw); tx_data.set_data(Data::new(vec![])); let keys_changed: BTreeSet = vp_env.all_touched_storage_keys(); diff --git a/wasm_for_tests/tx_memory_limit.wasm b/wasm_for_tests/tx_memory_limit.wasm index 0186d91ea13d8a9c28901875e431445ddc1257ab..1eb11aee377f7781ce9edc181abf05ab9469e850 100755 GIT binary patch delta 851 zcmZutTSyd85Z!ZU_T}2L*5-nbb|pwd@uv?fER~EDqQ{2>MU;IQS+NDthh<4^TAD}? z9ehL&2%;hisoM*JBA=zEnM6T_SsF^QTT)QbT_NeC3-_KmXJ+mkW}qf`8K0byr!hqz~ z!fR+zE$j*%vat>+=+Fo2&~Np3BH+uzcDIArYO}{UoXQnYX(~7RrDLD;D zMW^1{05=RxX~c4L%YDIO?nJCzRyV-+|GcTb(1ia?bvCyakdHbOu^S_F-h{zpv26+at1-5TPL2yWni$X?HtTi zy6qgHMk;*_}o{37#aIRO|;!b)Aa&hps=) z0qI*tHeK_MiU~b3@t#TyjEqpG92%i5=+P#w1bX$3k2DNd9|G3AKxx45>C@}S=rm6& z^NjLif~pz45(?8j<0CghU9osp?=rUf>xX#^1NtdAfzYo(-tJV&>*PLHc1i^XrT aSV9XumUM$v!V%6wYE^cGb#}xm{eJ*9g(S=X delta 863 zcmZutTS$~a6#lPfyiaTAV4SEa3S3{f)>0-;V3>JfpMgN#3$TsDOZa>;Z95Qm!ueabn6~WQwE>y zMNr|9eB6%`iA3SiD-R$Cvg80fvO9_bJeC_#l;E-EgZKiI@-2oTgYxQhXMrruNmdhyZ;$^E|EqcdFYP zVM6KlMsnqoxKm}vOv=zx7V=k;a|?JKU3Vr)xD`|NiewIvu1MlG(1lgACyaiHoFJ#{ ztprQq08RQ!bx*!ghr1GCSn$)X}$e zivK9NM#&kaBa9AdPS8y}&}HNFAO&4AAKZ_JlB#$F-TJfQ48lV_#mO5Ky7W#ryOCQ1 z2daLr94l;Z%~sPbTiKS^)Kp<_nGJ8JRAzFQX>fUfx0~K{fUg2+G92Wf>0ILcNOsx%WHYg?Q$LcxKHLWLWCg zfdZ7W6qFzK{&zSN7~AbN&fyKVRWVvcNEJC~lB8?SBCbi{A@)z==EKY)uFH`l90}ai zZ51rQE#0@01w9(!ahO$u0d~GUwYyIT&#}MWRmm(g%9%=jg?V3nj4ur8^5cAFXi*i5 zRqy-o{JBia_Ib*4lchT##l0rqPSQ`@);Ps%+?Ii-_|SJ3fE6Knhbm z=5j*vn(W@u88vJ}lkTWt4w@wOJkw!lsFqXEtP5*7&alI^4E?t`wT^jaqgBGe##&v+ zQMjWk>KWFb>Nwr3{JT?B|EJSve2Xq}se$&3f5fnk2xsYu^~oIip#0Nc3zwMbGcWN9 z(W28D7)FZ>Y2ahvuHY&=9eFf^afO85H`{mzp}Uh=iDW2XIeB^R(MXn zSL8+9R{1fH2kgJfV53wlV7ZNZdPpG~%-=5y*_?(peRi3d)vk9eXD9B<$`$OV3^i(R zIl7wDh&Jh5%K)U`bY6x$FJPXM&YN7}gDdk}SWOwflaG~tzmA#7fy{S{Jh-j8&w3_I z-j4NLZlccKz|+uMiy6`3VlL5HC5*_iVs0XONu-1ai43{4nFYS2$&>8u4EdzzZg%;V z4s_Qy5(vqwDeO}6Jwf{f9*A14KBgcjUpA`GK(oBvq{`s?6(JZcDOI|p)ZSuz-%IV> z0OC5Q%)X1bd?>RQZ{Qom_Bx^18Yhf_u|3WROp9H2h6ba`vLcpc)s1njp$4O|E+-E; N(a~^ZG<-jv{setQ7uNs) delta 855 zcmZuvSx8i27`^BG_s(cq+|V{hotvQr(MCZFy-Xo3q(nja5N+y2Mv;X@W!VBMJ!Lih z5mXPEM2i_(ACj1*)#TKe^-vEj4;2+HL_rIM^@~_9J)Q3?e0=bo#@0Y%YoOr?Qf;M_ zrJ$4_mKmV{b?6h$Ck%Lli+GRe`)XNLOGqu5JzMF7f%VW5jyb>?yc1ZU&9=87~ zIY!yIi~DV~>z{jh6*oopF`A59diMc7!fjnp!?%datb-h(3^nRd*%aYi;+9<1On^Rl zmVw@d47nv9+zx&7EMw-LnseOH2Pu+ro<{*!PpW68?!3UTzSvAp7S^+zdSX3;@~(l~ zi4+Mpa-Od*8I-POruigV$45%-^(P%_C{4Z6##esTHEV>%2L$AGE+-S65}3=3UYtIk znM6zq7H}f;(ghr(kK}PCuIYz)oQJzQBfl49O+LTFi|c?Ube^^b_}VO94mXo;)ky0|#+^X*n~{rMs3hZrF(x9F4e?uHqmV zx_dQqabE{kafTg7vR~J);IRMuCXGT)HK+CzGRLr$g`8{_w-z&9Hxx1tZT(Jm(LblG zh-XYVvzY4)>@V(j)+5#*UmWfi)AgyaDN9@itYHf?yW!d6tl?QIWX~ChB+m{FH!lo5 zwn{v@-STp+seq|O%R0Vwr0F;}_>d~2YI&N{6Qf;+R#BVOmqfVoZHM{_+?S6#RW*El zb*L(@P`bRr-eYn-7510}+|i?}?M~d0&((JER=z`|#z~88cG8g*Ip9pdoJgB9c5tP# dte|CCP19U!tij62FJ~%ps;0n^De(P%`UhCSAcFt^ diff --git a/wasm_for_tests/tx_write.wasm b/wasm_for_tests/tx_write.wasm index 506754c3426cac4c4b43f577851706c525731e2e..f5c32fcb636d50a12b52fdb4d2f7766a81433a1b 100755 GIT binary patch delta 764 zcmZ{gTS$~a6vy{J-}!bGch@a5aaY|hC0(-eLJ>$*LXk!kNKn*+LeYanWkrF|lhj5x z1B26}6(*UG33Bq1CO#;c7Ot-AJqgM%unSQ^xs3%u4-L%x=70X@%$ynN^+~U<$)OUA z-vb5=!=@Jph-$p5*}3}@y6^>yh+?`bq9mg5b2(-toQTFN7?7&lNL8A*?;=fMke}9} zm<#IRmZW>g0LR{gn~UnP8AE)b9>o}v7xnlCUD9_SZ#4Pg1H97mMk6YXl~b@B0p(m} zw+zd(wDqLNdIrR5fp+24 z-EHvx*F4sNP2AtPRL=b!=+UTtg0C9EPHgA99lxE=ov77sd)|pm?X-8HMITu46eoZY zne9dc^p9Na!J~ML2e*Wvr;;rpBPClF_fn%mm>-l-3c}J?LZiT_)b67>)3~!|ZOuo2 z5=YM{lRxBAOwEGd@sIM=lv$=E#?TQ15w47*qZ+eubmI@!ORbX*0AupqMXwPz4$CaG z$}PWVT;9ghP5K+j)RBuT=rUo9mnBoX?qMLAo;fkWw=yY$Nv_DEcbJkx0rDD{l(X4X zsxTqpbrb`Eom!z<>|BvU2{NN7-H=NMsniai%#~4{lE8KvHF$bG`Ihcfg`RQ?o^hre z>es!#%%S6m$ktrSRUEgG{Bk{?&MTzy$$UzaH5;i?Ax-KwQI%7oJ1Oem(~9;R9OL3{ zrMz-((fDD=wZpW!LA?jRcbQ%ubeSp0;CYvsgCh31&FsXWVYB&dHrs{*k1bnsNxOK# VWhU_{x6aNAR=Z89cH09ZzW{vn1=aun delta 764 zcmZ{gTS!$=5Qg`^)@+aB*{5ycg`*y~m(;LQ!H~41Q;HXQH+m6@dax+!QHUN)g)UeW ztOt8gOeGUCp(gd@B_Sir!0Rz@NfCuXP=pd*S_btNi{YDpX3eab#lx{Y9NXyrxPxLIhEdpM9gtn7sgD?tN5o_)(GoH8s<5>8y;wRs0T$@P}u?GX*Jjb z?|+kL1ISe)eOu*fB!D4}`e#_tsOv+aY7YF#{OCiY-tBcCQgx=cACGmz3j;V0Eb!7G z+M$2s`Vby%!$e)dIJ5~a7?*JwQiWP-PzW#Is-QKg;wz|}2eTij z=cdydcP-kh_FHrUW32sJV4Rb;(FcT2z%l(!rITP!a6|;%p?{H79qEjutAuft@1r{on)RRmKMQS}vT>g8K4Zm|HNu(H# za12|&EBtn)1A9XK^3#YO^2K2~r{~*ugt7!;)lwn(_(~C766#bDC9qRMRRZzcP)5~m zUO!0Fl6~d0>Eh!XvP1Y5;m{rik)gSzE%nVZ Uqt!)^zMWcE?=iXF6Oump8{kp<(EtDd diff --git a/wasm_for_tests/vp_eval.wasm b/wasm_for_tests/vp_eval.wasm index be1fef116177778390b02e17489e465a2567ea22..3df4fddabc6e93e69f656ea14507b64209f49b24 100755 GIT binary patch delta 1306 zcmZuxeN2^Q6o1cop6A{RT=4QC5+is8l^gPbP{myfC z&eK?z*jSes@I#y-f*;s~0ASY;AZ#FI(|K5g%e9^8>qO9tQa-)f!0F);S)8V;^<*qmr-DtYe zFokQ7yeF_9E@<%?9tIeq>d*1_q+u{)J+LRjA*8a|LmeR)X5}!E8@;X(YCMV4Fibm| zF%^cjuNfnNkDeCX3>WFfDSTQEgVRp?n{nCy$NBG}7R=|X4z%JbJ}qy>92lYMc1)nk zR@_P{?G`uP{tuqlh8+wow4s;!TZ7@3+aIM>a7X{`m* z1Q^x+4x9t{PQTZQx0Se2m`=CKaD_g-5pxm7=-MVc0poPwdCncDGB0M5^5UB?uG#+( zU_#&Bj6XuyB$&!$mYa#LNj?7}9+&?hD;cRN#Ci!6w4?~nv({7*jyd5H9eabdr)b{} zyaUtvwGwC11U1N7i?*bAb^7SePxdZ}*NfJs7^2JmBtUiU7}37Xr5 zS(X-hT;(RXCMj|^PI9U9yKx^^Sy+a5qP4RIQ|+{N18x`O2ycS?c%7Gz4}`vZ7PsAp zE85#Fj`-P5y(%v_;i7IRmBk^<^7CG~*J76zyNz$MvqB~+zCulvEU;SVOb@aWVTw?K5R#JxhXA@8hK_V7Z>)0i~=WZu^-6~$cl&`)zs20I6qNpXH zmQhSVB|r+T38*Y6pq&A=I?^W$Bgrs~!916-nyrsc22{REl~z(^pW5!r?p8Xx+g5V* EFZoofr2qf` delta 1272 zcmZ`&eN2^Q6o1cop6A{Ra@iFOi1@fd0`X0fH#4+bXv9DRAsFiq^rkN2L;Ry@wxF2k zMl+g@qi&X__yO83B|d%x7ZUsggwU~CMPG9x>0|YWj#cZtm!Ez|wnK!Jf*(VG5Ed}l1Pi|)cJ;tCoNMa9?HvfZ1FZc$!=kxj4}+Iwd!hRG&%O6T_37MK5(>4A9aBoPt4})QArY7|_o);mZgY^oQHf1~fyMVb(&oqsj@6e#+j1 z*TC1d7i;+vb$f9tRLAee38BkRVxm?Zt)PEcti&3B`!=sxTH5M#%L3_Ex{Os z%XBygUw|I^H3x6eFF6=YKP<(k;XK7IWBv-g>IePlGQ10X>VzAAVx;$u;X2h6;ZyAWy$U1$H+ZZFUGznXd7P}pxDZC#R$~;E z6=NX<%+f>u(F2?_xEgcmaIrr>tK?q(+a*}U|Kz(OOyH!M`+@vYp8BxvD#gzbMya+O zqhM6Gl=IYhik=F*r8KqRyEgsX87#RAXLW9u*wM~7{F3Ysg6sM{kE{q_;rv`JtIa7& zbBY#L#F`ozqqs=pCYfh7BNj7a=g9aL`Ho*tekO>S%B^yf{5G5wFE1a+Qu7vPqg%X8BO27Jn&ALf|6pye+?l zi@Ii7`T|*8X?NsCxS~I}BhOn{O%?yhSe9n@8!A&mFLg?FfV&kaWiDKG5E(5u2}o>xUd9A$Y`20Tw|yeegGvoMTU!!Y_5 fIgAv>X4>ynE|nn7L-prW+4jsXr8B!Ml{fwcLZPA~ diff --git a/wasm_for_tests/vp_memory_limit.wasm b/wasm_for_tests/vp_memory_limit.wasm index 689b87e2f88967fcca791e6781c47eb6ebea9588..dcabdf19cafe139ad3e9eb7406468de4749ab744 100755 GIT binary patch delta 1050 zcmZ{gZERCz6vyxRKhN#DxXpI5p|f>&APm;Tm>`tMd}(095@zf$5?=z0DY7;WzmR2# zOVp|LCB`*l9u-W?y0sgy048`GBi+D4w=ysi;}kVRAQ>b^`9zHR!KWpNeDHob=l?tB zp7VdsXwEm9^Bo+f3QH9}QbbBwic}G4-J7OE?&bOt?W4=o+kpU`?oJ?<07(MyE|(|X zK^Qb9{qMn_j}!0X9?(&q{Q!-8dmLrFq6a_lk{*-!QYrs~@ipk$1nv@M|aglDDBF7Fn z5vSTSC80*_(*KghhMaH0yP76B+Ke$XyLJO6ODM-zH=A9jcybG_(6oHsg1eNFhE~dj z=dliylfa8`lRWzfMoArZ74vuy6;fZ1Y9&h#V~2}8^6?l3AzfXVQM_zB?#^#U$P;nM zGsRDD$0=icQ5)Kg=Ur{sN1TbGnm0wUjkmO;S}sP>1-e68+VK%+p8WYT8eRD&M_M~j z<&q~~!{0@GdKES*c9-%uX{zdd^>>%d1aVEt!)bgrNM~fWRee`XUisoBb&V(^BRkY9 zwpm@bQ*~cI#{CgTn`3;rQ=Kau%#}A;YRIP@>h+tX#4{DE>r_(Lsn`3A>5e{KP9^41 z{?Jt`;&{!gN_Xoad5CpJ-NMCichODcGqY>@b*p_V>PhL1^Nr)nY5joPIP_=rQWMr@ z_4@pcvU-K`nssHN@9l_F8M-sNpvDaPF{itAe$aJpTuS6?T~$s;_|0GRPjp1KUeJHF z)33ZKYzMIryg6)F@u9FikJjv}|&0;g7oLzZLMEsYR#7k?LlTG8Ys24GY z(^*n59i($BYxNU!S4iN>MPRX(uG%bPg{!UJ1O;ikmdbP7ChRnDW1im4Zf9c^meCuBi*h;Gv=uWYUrQ z&%=ge*ZWXt*su*t--Kg@ZL&uAv$L4g0uOefL2J9)g?=K7z1_&;&(C2$pXrCKp6$jV z@XBuFt8dQZAm}0WLN6*^i<9~4Qa`*d6*+^OLd{0-j~g=^c<)D)!S;{jQM0934T>q( zTI42T;X34juJiK&R8o}R58xMW4ZiqgiB*k?npI$ptQ3*j6I7d`VVJo!bmID9(LbP(X1t zu?4dxP4d~D$fX-Rv=h_1Iu^tuG^rv%q>?U&t58l;9NC4nx^iBG_kWwe??NeO)+Ao% zt<_kqcOI!m9d8dUAZz!1l*4;><% zGfk?$YH$U4(`3t4Mz&8lvLc0++0x0@f7H2Ugl$;UYUX8a5p9{iSMaN;x=x_MMHwpj zGM5AeM1~FwHb;VMa!ZMOTxC)HoVj*zFV-WD`A@y zO}d)I(It{>jkFav3su}Kx8-OXHFe5#O4c^Zb^g?P(zMS~K9m>Lb1X;216*nDaWA19 zy}RJNtTi7*C;Mb5ODmp_%BMV9VQx%5rb9(cZqw&Z#pKf>O`l73Zkb^_)5)&)73f9Z z$7PF5EL!ARr3%kTZ#s?hdq2q^Xk6{PBmZuo-*`{ZEQJsJYS8p@Bxq((1&;?!e_E?B qjC{i|3ZJnIzmBbpDznrql7^AaC;es?4{S2a+B&OD)mi1bF#9i1FK+Ar diff --git a/wasm_for_tests/vp_read_storage_key.wasm b/wasm_for_tests/vp_read_storage_key.wasm index c1c6ae7f1b8219a5083f6361c9deff3f8f103cc5..953c2e36071ac6f7cf80f449a8e08dd6613d24bb 100755 GIT binary patch delta 1096 zcmZvae@xVM7{~8gu z+IA?{&^h5;Ppw?5gFG=5|A^0+hmJT!IY1dE%ds4*SUTHcEN6dEeePQD>TfcjMLVHBiw;s{oN&hx#a*uuqa$mXrB_<^5m)lqpHHc~(D zZNnD&j?ZO88ByFPeethj_*pCe^f7Mfbb#@`$Q>oiu^O%-yCp0$9hxh%%s#dKGdMv5 zyyG~EXh7{dj&XyMToXe9UF1*e`V_IxRYZO1i{}4m>TB@yE89D5J=<$S9}xcJ8ra%Q6F z`E_3P?k3a;y26u{ctgwe%_!r&n^8+wl#ZK;hSZKKz1Br3vJAf!v64afd=CY76%1p}!Q&h8iulCoj-FkY zuWqczoKS%aP#ttliocg6> zaoN?=Auo!Du+n(3V*xGFBkrD&zsZLXYvfb;-^$N(wM&(fPiUD+$rtpfvSC>vJoBSG z{$+2i%+_5RuS)SimmG}_j?0oIl;E?!$Vp15Bh#{HEqPRBu5qY}?(*19qkjD}N9U($+-mhl5*@qSXQlF3xdRv!H7$Ys+P= za{P2!jYivvElPIP`G+^OB~PY|kRM*Wz~#<1R--w#Vr9A_T&q7^Jr_!H>!0_W^Eu}^ z=e%d%*@f)ch3u18C{0QsgiVkT4zg*N1d-_ci~61RIf~E~D()Oc5%o9EqkSHv=7DIj z_|WO;Jhd@PJ#!W}1Yi9Ub>g($#ZP~MG}ZAga)lZ=gfk?lsZI~;kQCot~sQlFW>`tljLjC z@G{Tim}I!3W}*(KmH*7{)vb5rD%+c%W+wU zX^&u^NWVaqqX6zTc1u`h(lzs3=9oHC0VimjBipft##MYfE*ZHKWM%kix7R78VRxiB zT}ZW1fU@N0VRMoPD=|qE+);%Bnowt|^oBZ&R->Ha?0pjV$q8~hxTgvk|DV^@*PlWO z=hfj(?N`@e15NVVb;#x;HF%5zfkmEKyUatiIIc^50hIH6&0>0gU^$%#pi-Z#s0R7E zYFpjEnI^pecHkUniU)Qgo2JyvPOS#5j?e2cXQUY3JyRWrE@CdS@ENb z%)Xa|zGz(ixknrz`;t0T`zzx26NLR#~UzN9lS?6_abVnT^Ru^{92@vP7)BIclZ<_T712-DPiFivM)+Y1Dd2 z7OtWwpZY=0P*lA)C;QfusmjxhLtE)*PShJEl*g{1v7WZ@y+NZetxec$xi*{a>rJMu cP}^keVNcM=;Ete?P5JGSprIl``-X4-25&fcbN~PV