Skip to content

Commit

Permalink
Combined the TxBuilder and Tx APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
murisi committed Aug 9, 2023
1 parent 39c0983 commit 893278c
Show file tree
Hide file tree
Showing 41 changed files with 448 additions and 646 deletions.
3 changes: 1 addition & 2 deletions apps/src/lib/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ impl<IO> CliApi<IO> {
args.clone(),
signing_data.gas_payer.clone(),
)
.await?
.unsigned_build();
.await?;

signing::generate_test_vector(
&client,
Expand Down
48 changes: 18 additions & 30 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,8 +73,7 @@ pub async fn submit_reveal_aux<C: namada::ledger::queries::Client + Sync>(
&public_key,
&signing_data.gas_payer,
)
.await?
.unsigned_build();
.await?;

signing::generate_test_vector(client, &mut ctx.wallet, &tx).await;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -419,8 +415,7 @@ where
#[cfg(not(feature = "mainnet"))]
false,
)
.await?
.unsigned_build();
.await?;

signing::generate_test_vector(client, &mut ctx.wallet, &tx).await;

Expand Down Expand Up @@ -645,7 +640,7 @@ pub async fn submit_transfer<C: Client + Sync>(
&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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) =
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -1171,8 +1164,7 @@ where
#[cfg(not(feature = "mainnet"))]
false,
)
.await?
.unsigned_build();
.await?;
signing::generate_test_vector(client, &mut ctx.wallet, &tx)
.await;

Expand Down Expand Up @@ -1300,8 +1292,7 @@ where

let mut tx =
tx::build_bond::<C>(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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 8 additions & 11 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -1222,15 +1221,15 @@ 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(),
info: "".into(),
},
};

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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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)
});
Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/node/ledger/shell/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}));
Expand Down
31 changes: 11 additions & 20 deletions apps/src/lib/node/ledger/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
})));
Expand All @@ -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::*;

Expand All @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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(),
Expand All @@ -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"),
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down
Loading

0 comments on commit 893278c

Please sign in to comment.