Skip to content

Commit dd0d9bc

Browse files
committed
Merges the two dry-run args into a single one
1 parent 1e39180 commit dd0d9bc

File tree

8 files changed

+34
-35
lines changed

8 files changed

+34
-35
lines changed

crates/apps_lib/src/cli.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7816,7 +7816,6 @@ pub mod args {
78167816

78177817
Ok(Tx::<SdkTypes> {
78187818
dry_run: self.dry_run,
7819-
dry_run_wrapper: self.dry_run_wrapper,
78207819
dump_tx: self.dump_tx,
78217820
dump_wrapper_tx: self.dump_wrapper_tx,
78227821
output_folder: self.output_folder,
@@ -7967,8 +7966,13 @@ pub mod args {
79677966
}
79687967

79697968
fn parse(matches: &ArgMatches) -> Self {
7970-
let dry_run = DRY_RUN_TX.parse(matches);
7971-
let dry_run_wrapper = DRY_RUN_WRAPPER_TX.parse(matches);
7969+
let dry_run = if DRY_RUN_TX.parse(matches) {
7970+
Some(DryRun::Inner)
7971+
} else if DRY_RUN_WRAPPER_TX.parse(matches) {
7972+
Some(DryRun::Wrapper)
7973+
} else {
7974+
None
7975+
};
79727976
let dump_tx = DUMP_TX.parse(matches);
79737977
let dump_wrapper_tx = DUMP_WRAPPER_TX.parse(matches);
79747978
let force = FORCE.parse(matches);
@@ -8003,7 +8007,6 @@ pub mod args {
80038007
let device_transport = DEVICE_TRANSPORT.parse(matches);
80048008
Self {
80058009
dry_run,
8006-
dry_run_wrapper,
80078010
dump_tx,
80088011
dump_wrapper_tx,
80098012
force,

crates/apps_lib/src/cli/client.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ impl CliApi {
3737
client.wait_until_node_is_synced(&io).await?;
3838
let args = args.to_sdk(&mut ctx)?;
3939
let namada = ctx.to_sdk(client, io);
40-
let dry_run =
41-
args.tx.dry_run || args.tx.dry_run_wrapper;
40+
let dry_run = args.tx.dry_run.is_some();
4241
tx::submit_custom(&namada, args).await?;
4342
if !dry_run {
4443
namada
@@ -193,8 +192,7 @@ impl CliApi {
193192
client.wait_until_node_is_synced(&io).await?;
194193
let args = args.to_sdk(&mut ctx)?;
195194
let namada = ctx.to_sdk(client, io);
196-
let dry_run =
197-
args.tx.dry_run || args.tx.dry_run_wrapper;
195+
let dry_run = args.tx.dry_run.is_some();
198196
tx::submit_init_account(&namada, args).await?;
199197
if !dry_run {
200198
namada

crates/apps_lib/src/client/tx.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ pub async fn submit_change_consensus_key(
491491
let wrapper_hash = tx.wrapper_hash();
492492
let resp = namada.submit(tx, &args.tx).await?;
493493

494-
if !(args.tx.dry_run || args.tx.dry_run_wrapper) {
494+
if args.tx.dry_run.is_none() {
495495
if resp
496496
.is_applied_and_valid(wrapper_hash.as_ref(), &cmt)
497497
.is_some()
@@ -689,7 +689,7 @@ pub async fn submit_become_validator(
689689
let wrapper_hash = tx.wrapper_hash();
690690
let resp = namada.submit(tx, &args.tx).await?;
691691

692-
if args.tx.dry_run || args.tx.dry_run_wrapper {
692+
if args.tx.dry_run.is_some() {
693693
display_line!(
694694
namada.io(),
695695
"Transaction dry run. No key or addresses have been saved."
@@ -815,7 +815,7 @@ pub async fn submit_init_validator(
815815
)
816816
.await?;
817817

818-
if tx_args.dry_run || tx_args.dry_run_wrapper {
818+
if tx_args.dry_run.is_some() {
819819
eprintln!(
820820
"Cannot proceed to become validator in dry-run as no account has \
821821
been created"
@@ -1794,7 +1794,7 @@ where
17941794
let wrapper_hash = tx.wrapper_hash();
17951795
let resp = namada.submit(tx, &args.tx).await?;
17961796

1797-
if !(args.tx.dry_run || args.tx.dry_run_wrapper)
1797+
if args.tx.dry_run.is_none()
17981798
&& resp
17991799
.is_applied_and_valid(wrapper_hash.as_ref(), &cmt)
18001800
.is_some()

crates/apps_lib/src/config/genesis/transactions.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ fn get_tx_args(use_device: bool) -> TxArgs {
7777
use std::str::FromStr;
7878

7979
TxArgs {
80-
dry_run: false,
81-
dry_run_wrapper: false,
80+
dry_run: None,
8281
dump_tx: false,
8382
dump_wrapper_tx: false,
8483
output_folder: None,

crates/sdk/src/args.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,14 +2622,20 @@ impl TxExpiration {
26222622
}
26232623
}
26242624

2625+
/// Argument for dry-runs
2626+
#[derive(Clone, Debug)]
2627+
pub enum DryRun {
2628+
/// Request a dry run of the inner transaction(s) only
2629+
Inner,
2630+
/// Request a dry run of both the inner transaction(s) and the wrapper
2631+
Wrapper,
2632+
}
2633+
26252634
/// Common transaction arguments
26262635
#[derive(Clone, Debug)]
26272636
pub struct Tx<C: NamadaTypes = SdkTypes> {
2628-
// FIXME: should these two be mutually exclusive? Yes
2629-
/// Simulate applying the transaction
2630-
pub dry_run: bool,
2631-
/// Simulate applying both the wrapper and inner transactions
2632-
pub dry_run_wrapper: bool,
2637+
/// Simulate applying the transaction (possibly the wrapper too)
2638+
pub dry_run: Option<DryRun>,
26332639
/// Dump the raw transaction bytes to file
26342640
// FIXME: should these two be mutually exclusive? Yes
26352641
// FIXME: can we use dump tx to avoid wrapping the tx instead of the extra
@@ -2714,16 +2720,9 @@ pub trait TxBuilder<C: NamadaTypes>: Sized {
27142720
where
27152721
F: FnOnce(Tx<C>) -> Tx<C>;
27162722
/// Simulate applying the transaction
2717-
fn dry_run(self, dry_run: bool) -> Self {
2723+
fn dry_run(self, dry_run: Option<DryRun>) -> Self {
27182724
self.tx(|x| Tx { dry_run, ..x })
27192725
}
2720-
/// Simulate applying both the wrapper and inner transactions
2721-
fn dry_run_wrapper(self, dry_run_wrapper: bool) -> Self {
2722-
self.tx(|x| Tx {
2723-
dry_run_wrapper,
2724-
..x
2725-
})
2726-
}
27272726
/// Dump the transaction bytes to file
27282727
fn dump_tx(self, dump_tx: bool) -> Self {
27292728
self.tx(|x| Tx { dump_tx, ..x })

crates/sdk/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ pub trait Namada: NamadaIo {
124124
/// Make a tx builder using no arguments
125125
fn tx_builder(&self) -> args::Tx {
126126
args::Tx {
127-
dry_run: false,
128-
dry_run_wrapper: false,
127+
dry_run: None,
129128
dump_tx: false,
130129
dump_wrapper_tx: false,
131130
output_folder: None,
@@ -708,8 +707,7 @@ where
708707
io,
709708
native_token: native_token.clone(),
710709
prototype: args::Tx {
711-
dry_run: false,
712-
dry_run_wrapper: false,
710+
dry_run: None,
713711
dump_tx: false,
714712
dump_wrapper_tx: false,
715713
output_folder: None,

crates/sdk/src/signing.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,8 +2474,7 @@ mod test_signing {
24742474

24752475
fn arbitrary_args() -> args::Tx {
24762476
args::Tx {
2477-
dry_run: false,
2478-
dry_run_wrapper: false,
2477+
dry_run: None,
24792478
dump_tx: false,
24802479
dump_wrapper_tx: false,
24812480
output_folder: None,

crates/sdk/src/tx.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ pub async fn prepare_tx(
242242
fee_amount: DenominatedAmount,
243243
fee_payer: common::PublicKey,
244244
) -> Result<()> {
245-
if args.dry_run || args.dump_tx {
245+
if matches!(args.dry_run, Some(args::DryRun::Inner)) || args.dump_tx {
246246
Ok(())
247247
} else {
248248
signing::wrap_tx(tx, args, fee_amount, fee_payer).await
@@ -266,7 +266,7 @@ pub async fn process_tx(
266266
// let request_body = request.into_json();
267267
// println!("HTTP request body: {}", request_body);
268268

269-
if args.dry_run || args.dry_run_wrapper {
269+
if args.dry_run.is_some() {
270270
expect_dry_broadcast(TxBroadcastData::DryRun(tx), context).await
271271
} else {
272272
// We use this to determine when the wrapper tx makes it on-chain
@@ -3538,6 +3538,9 @@ where
35383538
fee_payer,
35393539
}) = wrap_args
35403540
{
3541+
// FIXME: if wrap_args is provided we wrap it but within prepare_tx we
3542+
// avoid wrapping it if a dry-run or dump is requested so maybe there's
3543+
// a way to avoid the wrap_it argument
35413544
prepare_tx(tx_args, &mut tx, fee_amount, fee_payer).await?;
35423545
}
35433546

0 commit comments

Comments
 (0)