diff --git a/crates/iota/src/client_commands.rs b/crates/iota/src/client_commands.rs index f0dfd52b394..18ab44ef24a 100644 --- a/crates/iota/src/client_commands.rs +++ b/crates/iota/src/client_commands.rs @@ -658,7 +658,7 @@ pub struct Opts { /// The fields are: effects, input, events, object_changes, /// balance_changes. #[clap(long, required = false, value_delimiter = ',', num_args = 0.., value_parser = parse_emit_option)] - pub emit: HashSet, + pub emit: Option>, } /// Global options with gas @@ -683,7 +683,7 @@ impl Opts { dry_run: false, serialize_unsigned_transaction: false, serialize_signed_transaction: false, - emit: HashSet::new(), + emit: None, } } /// Uses the passed gas_budget for the gas budget variable, sets dry run to @@ -695,7 +695,7 @@ impl Opts { dry_run: true, serialize_unsigned_transaction: false, serialize_signed_transaction: false, - emit: HashSet::new(), + emit: None, } } @@ -708,7 +708,7 @@ impl Opts { dry_run: false, serialize_unsigned_transaction: false, serialize_signed_transaction: false, - emit, + emit: Some(emit), } } } @@ -3011,23 +3011,28 @@ pub(crate) async fn prerender_clever_errors( } } -fn opts_from_cli(opts: HashSet) -> IotaTransactionBlockResponseOptions { - if opts.is_empty() { - IotaTransactionBlockResponseOptions::new() - .with_effects() - .with_input() - .with_events() - .with_object_changes() - .with_balance_changes() - } else { - IotaTransactionBlockResponseOptions { - show_input: opts.contains(&EmitOption::Input), - show_events: opts.contains(&EmitOption::Events), - show_object_changes: opts.contains(&EmitOption::ObjectChanges), - show_balance_changes: opts.contains(&EmitOption::BalanceChanges), - show_effects: opts.contains(&EmitOption::Effects), - show_raw_effects: false, - show_raw_input: false, +fn opts_from_cli(opts: Option>) -> IotaTransactionBlockResponseOptions { + match opts { + None => { + // If `opts` is None, use default settings + IotaTransactionBlockResponseOptions::new() + .with_effects() + .with_input() + .with_events() + .with_object_changes() + .with_balance_changes() + } + Some(options) => { + // If `opts` has a `HashSet`, use its contents to customize settings + IotaTransactionBlockResponseOptions { + show_input: options.contains(&EmitOption::Input), + show_events: options.contains(&EmitOption::Events), + show_object_changes: options.contains(&EmitOption::ObjectChanges), + show_balance_changes: options.contains(&EmitOption::BalanceChanges), + show_effects: options.contains(&EmitOption::Effects), + show_raw_effects: false, + show_raw_input: false, + } } } } diff --git a/crates/iota/src/client_ptb/ptb.rs b/crates/iota/src/client_ptb/ptb.rs index b8c87ba9796..1c9ebe72803 100644 --- a/crates/iota/src/client_ptb/ptb.rs +++ b/crates/iota/src/client_ptb/ptb.rs @@ -2,8 +2,6 @@ // Modifications Copyright (c) 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use std::collections::HashSet; - use anyhow::{Error, anyhow, ensure}; use clap::{Args, ValueHint, arg}; use iota_json_rpc_types::{IotaExecutionStatus, IotaTransactionBlockEffectsAPI}; @@ -156,7 +154,7 @@ impl PTB { gas_budget: program_metadata.gas_budget.map(|x| x.value), serialize_unsigned_transaction: program_metadata.serialize_unsigned_set, serialize_signed_transaction: program_metadata.serialize_signed_set, - emit: HashSet::new(), + emit: None, }, }; diff --git a/crates/iota/tests/cli_tests.rs b/crates/iota/tests/cli_tests.rs index ff3d2922d45..c5e6845a23f 100644 --- a/crates/iota/tests/cli_tests.rs +++ b/crates/iota/tests/cli_tests.rs @@ -2976,7 +2976,7 @@ async fn test_serialize_tx() -> Result<(), anyhow::Error> { dry_run: false, serialize_unsigned_transaction: true, serialize_signed_transaction: false, - emit: HashSet::new(), + emit: None, }, } .execute(context) @@ -2991,7 +2991,7 @@ async fn test_serialize_tx() -> Result<(), anyhow::Error> { dry_run: false, serialize_unsigned_transaction: false, serialize_signed_transaction: true, - emit: HashSet::new(), + emit: None, }, } .execute(context) @@ -3007,7 +3007,7 @@ async fn test_serialize_tx() -> Result<(), anyhow::Error> { dry_run: false, serialize_unsigned_transaction: false, serialize_signed_transaction: true, - emit: HashSet::new(), + emit: None, }, } .execute(context) @@ -3859,7 +3859,7 @@ async fn test_gas_estimation() -> Result<(), anyhow::Error> { dry_run: false, serialize_unsigned_transaction: false, serialize_signed_transaction: false, - emit: HashSet::new(), + emit: None, }, } .execute(context)