Skip to content

Commit

Permalink
feat(devx): Add filter flag to Iota CLI
Browse files Browse the repository at this point in the history
Signed-off-by: salaheldinsoliman <[email protected]>
  • Loading branch information
salaheldinsoliman committed Sep 18, 2024
1 parent 12c488b commit f64c05b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 deletions.
43 changes: 29 additions & 14 deletions crates/iota-json-rpc-types/src/iota_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,23 +214,38 @@ impl IotaTransactionBlockResponseOptions {
self == &Self::default()
}

pub fn from_cli(mut self, opts: Vec<String>) -> Self {
if opts.contains(&"input".to_string()) {
self.show_input = true;
}
if opts.contains(&"effects".to_string()) {
self.show_effects = true;
}
if opts.contains(&"events".to_string()) {
self.show_events = true;
pub fn default_profile() -> Self {
Self {
show_input: true,
show_effects: true,
show_events: true,
show_object_changes: true,
show_balance_changes: true,
show_raw_effects: false,
show_raw_input: false,
}
if opts.contains(&"object_changes".to_string()) {
self.show_object_changes = true;
}

pub fn from_cli(opts: Vec<String>) -> Self {

// if no options are provided, return the default profile
if opts.is_empty() {
return Self::default_profile();
}
if opts.contains(&"balance_changes".to_string()) {
self.show_balance_changes = true;

// effects should be there by default
let mut options = IotaTransactionBlockResponseOptions::new().with_effects();

for opt in opts {
match opt.as_str() {
"input" => options.show_input = true,
"events" => options.show_events = true,
"object_changes" => options.show_object_changes = true,
"balance_changes" => options.show_balance_changes = true,
_ => {}
}
}
self
options
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/iota-sdk/src/wallet_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,10 @@ impl WalletContext {
pub async fn execute_transaction_must_succeed(
&self,
tx: Transaction,
opts: Vec<String>,
response_opts: IotaTransactionBlockResponseOptions,
) -> IotaTransactionBlockResponse {
tracing::debug!("Executing transaction: {:?}", tx);
let response = self.execute_transaction_may_fail(tx, Vec::new()).await.unwrap();
let response = self.execute_transaction_may_fail(tx, response_opts).await.unwrap();
assert!(
response.status_ok().unwrap(),
"Transaction failed: {:?}",
Expand All @@ -318,14 +318,14 @@ impl WalletContext {
pub async fn execute_transaction_may_fail(
&self,
tx: Transaction,
opts: Vec<String>,
response_opts: IotaTransactionBlockResponseOptions,
) -> anyhow::Result<IotaTransactionBlockResponse> {
let client = self.get_client().await?;
Ok(client
.quorum_driver_api()
.execute_transaction_block(
tx,
IotaTransactionBlockResponseOptions::new().from_cli(opts),
response_opts,
Some(iota_types::quorum_driver_types::ExecuteTransactionRequestType::WaitForLocalExecution),
)
.await?)
Expand Down
16 changes: 8 additions & 8 deletions crates/iota-test-transaction-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use iota_move_build::{BuildConfig, CompiledPackage};
use iota_sdk::{
rpc_types::{
get_new_package_obj_from_response, IotaTransactionBlockEffectsAPI,
IotaTransactionBlockResponse,
IotaTransactionBlockResponse, IotaTransactionBlockResponseOptions,
},
wallet_context::WalletContext,
};
Expand Down Expand Up @@ -528,7 +528,7 @@ pub async fn publish_package(context: &WalletContext, path: PathBuf) -> ObjectRe
.publish(path)
.build(),
);
let resp = context.execute_transaction_must_succeed(txn, Vec::new()).await;
let resp = context.execute_transaction_must_succeed(txn, IotaTransactionBlockResponseOptions::default_profile()).await;
get_new_package_obj_from_response(&resp).unwrap()
}

Expand All @@ -542,7 +542,7 @@ pub async fn publish_basics_package(context: &WalletContext) -> ObjectRef {
.publish_examples("basics")
.build(),
);
let resp = context.execute_transaction_must_succeed(txn, Vec::new()).await;
let resp = context.execute_transaction_must_succeed(txn, IotaTransactionBlockResponseOptions::default_profile()).await;
get_new_package_obj_from_response(&resp).unwrap()
}

Expand All @@ -560,7 +560,7 @@ pub async fn publish_basics_package_and_make_counter(
.build(),
);
let resp = context
.execute_transaction_must_succeed(counter_creation_txn, Vec::new())
.execute_transaction_must_succeed(counter_creation_txn, IotaTransactionBlockResponseOptions::default_profile())
.await;
let counter_ref = resp
.effects
Expand Down Expand Up @@ -599,7 +599,7 @@ pub async fn increment_counter(
.call_counter_increment(package_id, counter_id, initial_shared_version)
.build(),
);
context.execute_transaction_must_succeed(txn, Vec::new()).await
context.execute_transaction_must_succeed(txn, IotaTransactionBlockResponseOptions::default_profile()).await
}

/// Executes a transaction to publish the `nfts` package and returns the package
Expand All @@ -615,7 +615,7 @@ pub async fn publish_nfts_package(
.publish_examples("nfts")
.build(),
);
let resp = context.execute_transaction_must_succeed(txn, Vec::new()).await;
let resp = context.execute_transaction_must_succeed(txn, IotaTransactionBlockResponseOptions::default_profile()).await;
let package_id = get_new_package_obj_from_response(&resp).unwrap().0;
(package_id, gas_id, resp.digest)
}
Expand All @@ -635,7 +635,7 @@ pub async fn create_devnet_nft(
.call_nft_create(package_id)
.build(),
);
let resp = context.execute_transaction_must_succeed(txn, Vec::new()).await;
let resp = context.execute_transaction_must_succeed(txn, IotaTransactionBlockResponseOptions::default_profile()).await;

let object_id = resp
.effects
Expand Down Expand Up @@ -668,5 +668,5 @@ pub async fn delete_devnet_nft(
.call_nft_delete(package_id, nft_to_delete)
.build(),
);
context.execute_transaction_must_succeed(txn, Vec::new()).await
context.execute_transaction_must_succeed(txn, IotaTransactionBlockResponseOptions::default_profile()).await
}

0 comments on commit f64c05b

Please sign in to comment.