Skip to content

Commit

Permalink
Switch builder API from ownership to references.
Browse files Browse the repository at this point in the history
  • Loading branch information
murisi committed Aug 10, 2023
1 parent 893278c commit a1e1d45
Show file tree
Hide file tree
Showing 33 changed files with 715 additions and 744 deletions.
14 changes: 8 additions & 6 deletions apps/src/bin/namada-client/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,28 +236,30 @@ pub async fn main() -> Result<()> {
)
.await?;

let tx_builder = bridge_pool::build_bridge_pool_tx(
let tx = bridge_pool::build_bridge_pool_tx(
&client,
args.clone(),
signing_data.gas_payer.clone(),
)
.await?;
.await?;

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

if args.tx.dump_tx {
dump_tx(&args.tx, tx_builder);
dump_tx(&args.tx, tx);
} else {
let tx_builder = signing::sign_tx(
signing::sign_tx(
&mut ctx.wallet,
&tx_args,
tx_builder,
&mut tx,
signing_data,
)?;

sdk_tx::process_tx(
&client,
&mut ctx.wallet,
&tx_args,
tx_builder,
tx,
)
.await?;
}
Expand Down
64 changes: 25 additions & 39 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use namada::ledger::signing::find_pk;
use namada::ledger::wallet::{Wallet, WalletUtils};
use namada::ledger::{masp, pos, signing, tx};
use namada::proof_of_stake::parameters::PosParams;
use namada::proto::Tx;
use namada::types::address::{Address, ImplicitAddress};
use namada::types::dec::Dec;
use namada::types::governance::{
Expand All @@ -26,7 +27,6 @@ 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::proto::Tx;

use super::rpc;
use crate::cli::context::WalletAddress;
Expand Down Expand Up @@ -108,8 +108,7 @@ where
submit_reveal_aux(client, ctx, args.tx.clone(), &args.owner).await?;

let mut tx =
tx::build_custom(client, args.clone(), &signing_data.gas_payer)
.await?;
tx::build_custom(client, args.clone(), &signing_data.gas_payer).await?;

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

Expand Down Expand Up @@ -376,10 +375,9 @@ where
.unwrap();

let chain_id = tx_args.chain_id.clone().unwrap();
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);
let mut tx = Tx::new(chain_id, tx_args.expiration);
let extra_section_hash =
tx.add_extra_section_from_hash(validator_vp_code_hash);

let data = InitValidator {
account_keys,
Expand All @@ -396,7 +394,7 @@ where
validator_vp_code_hash: extra_section_hash,
};

let tx_builder = tx_builder.add_code_from_hash(tx_code_hash).add_data(data);
tx.add_code_from_hash(tx_code_hash).add_data(data);

let signing_data = signing::aux_signing_data(
client,
Expand All @@ -407,15 +405,15 @@ where
)
.await?;

let mut tx = tx::prepare_tx(
tx::prepare_tx(
client,
&tx_args,
tx_builder,
&mut tx,
signing_data.gas_payer.clone(),
#[cfg(not(feature = "mainnet"))]
false,
)
.await?;
.await;

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

Expand Down Expand Up @@ -633,14 +631,13 @@ pub async fn submit_transfer<C: Client + Sync>(
.await?;

let arg = args.clone();
let (tx_builder, tx_epoch) = tx::build_transfer(
let (mut tx, tx_epoch) = tx::build_transfer(
client,
&mut ctx.shielded,
arg,
&signing_data.gas_payer,
)
.await?;
let mut tx = tx_builder;
signing::generate_test_vector(client, &mut ctx.wallet, &tx).await;

if args.tx.dump_tx {
Expand Down Expand Up @@ -861,46 +858,39 @@ where
.await?;

let chain_id = args.tx.chain_id.clone().unwrap();
let tx_builder = Tx::new(chain_id, args.tx.expiration);
let mut tx = Tx::new(chain_id, args.tx.expiration);

// Put any proposal content into an extra section
let (tx_builder, extra_section_hash) =
tx_builder.add_extra_section(init_proposal_content);
let extra_section_hash = tx.add_extra_section(init_proposal_content).1;
init_proposal_data.content = extra_section_hash;

// Put any proposal code into an extra section
let tx_builder = if let Some(init_proposal_code) = init_proposal_code {
let (tx_builder, extra_section_hash) =
tx_builder.add_extra_section(init_proposal_code);
if let Some(init_proposal_code) = init_proposal_code {
let extra_section_hash = tx.add_extra_section(init_proposal_code).1;
init_proposal_data.r#type =
ProposalType::Default(Some(extra_section_hash));
tx_builder
} else {
tx_builder
};
}

let tx_builder = tx_builder
.add_code_from_hash(tx_code_hash)
tx.add_code_from_hash(tx_code_hash)
.add_data(init_proposal_data);

submit_reveal_aux(client, &mut ctx, args.tx.clone(), &signer).await?;

let mut tx = tx::prepare_tx(
tx::prepare_tx(
client,
&args.tx,
tx_builder,
&mut tx,
signing_data.gas_payer.clone(),
#[cfg(not(feature = "mainnet"))]
false,
)
.await?;
.await;
signing::generate_test_vector(client, &mut ctx.wallet, &tx).await;

if args.tx.dump_tx {
tx::dump_tx(&args.tx, tx);
} else {
signing::sign_tx(&mut ctx.wallet, &args.tx, &mut tx, signing_data);

tx::process_tx(client, &mut ctx.wallet, &args.tx, tx).await?;
}

Expand Down Expand Up @@ -1150,21 +1140,18 @@ where
.await?;

let chain_id = args.tx.chain_id.clone().unwrap();
let tx_builder = Tx::new(chain_id, args.tx.expiration);
let mut tx = Tx::new(chain_id, args.tx.expiration);
tx.add_code_from_hash(tx_code_hash).add_data(tx_data);

let tx_builder = tx_builder
.add_code_from_hash(tx_code_hash)
.add_data(tx_data);

let mut tx = tx::prepare_tx(
tx::prepare_tx(
client,
&args.tx,
tx_builder,
&mut tx,
signing_data.gas_payer.clone(),
#[cfg(not(feature = "mainnet"))]
false,
)
.await?;
.await;
signing::generate_test_vector(client, &mut ctx.wallet, &tx)
.await;

Expand Down Expand Up @@ -1326,14 +1313,13 @@ where
)
.await?;

let (tx_builder, latest_withdrawal_pre) = tx::build_unbond(
let (mut tx, latest_withdrawal_pre) = tx::build_unbond(
client,
&mut ctx.wallet,
args.clone(),
&signing_data.gas_payer,
)
.await?;
let mut tx = tx_builder;
signing::generate_test_vector(client, &mut ctx.wallet, &tx).await;

if args.tx.dump_tx {
Expand Down
51 changes: 26 additions & 25 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,17 +1047,18 @@ mod test_finalize_block {
keypair: &common::SecretKey,
) -> ProcessedTx {
let tx_code = TestWasms::TxNoOp.read_bytes();
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(),
},
keypair.ref_to(),
Epoch(0),
Default::default(),
#[cfg(not(feature = "mainnet"))]
None,
))));
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(),
},
keypair.ref_to(),
Epoch(0),
Default::default(),
#[cfg(not(feature = "mainnet"))]
None,
))));
outer_tx.header.chain_id = shell.chain_id.clone();
outer_tx.set_code(Code::new(tx_code));
outer_tx.set_data(Data::new(
Expand Down Expand Up @@ -1155,17 +1156,18 @@ mod test_finalize_block {
fn test_process_proposal_rejected_decrypted_tx() {
let (mut shell, _, _, _) = setup();
let keypair = gen_keypair();
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(),
},
keypair.ref_to(),
Epoch(0),
Default::default(),
#[cfg(not(feature = "mainnet"))]
None,
))));
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(),
},
keypair.ref_to(),
Epoch(0),
Default::default(),
#[cfg(not(feature = "mainnet"))]
None,
))));
outer_tx.header.chain_id = shell.chain_id.clone();
outer_tx.set_code(Code::new("wasm_code".as_bytes().to_owned()));
outer_tx.set_data(Data::new(
Expand Down Expand Up @@ -3513,9 +3515,8 @@ mod test_finalize_block {
.wl_storage
.write(&proposal_execution_key, 0u64)
.expect("Test failed.");
let tx = Tx::new(shell.chain_id.clone(), None)
.add_code_from_hash(Hash::default())
.add_data(0u64);
let mut tx = Tx::new(shell.chain_id.clone(), None);
tx.add_code_from_hash(Hash::default()).add_data(0u64);
let new_min_confirmations = MinimumConfirmations::from(unsafe {
NonZeroU64::new_unchecked(42)
});
Expand Down
9 changes: 5 additions & 4 deletions apps/src/lib/node/ledger/shell/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ where
let proposal_code = shell.read_storage_key_bytes(&proposal_code_key);
match proposal_code {
Some(proposal_code) => {
let mut tx = Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted {
#[cfg(not(feature = "mainnet"))]
has_valid_pow: false,
}));
let mut tx =
Tx::from_type(TxType::Decrypted(DecryptedTx::Decrypted {
#[cfg(not(feature = "mainnet"))]
has_valid_pow: false,
}));
tx.header.chain_id = shell.chain_id.clone();
tx.set_data(Data::new(encode(&id)));
tx.set_code(Code::new(proposal_code));
Expand Down
Loading

0 comments on commit a1e1d45

Please sign in to comment.