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 19, 2024
1 parent f7a61eb commit bd581a7
Show file tree
Hide file tree
Showing 12 changed files with 273 additions and 42 deletions.
36 changes: 35 additions & 1 deletion crates/iota-json-rpc-types/src/iota_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use iota_types::{
base_types::{EpochId, IotaAddress, ObjectID, ObjectRef, SequenceNumber, TransactionDigest},
crypto::IotaSignature,
digests::{ConsensusCommitDigest, ObjectDigest, TransactionEventsDigest},
effects::{TransactionEffects, TransactionEffectsAPI, TransactionEvents},
effects::{self, TransactionEffects, TransactionEffectsAPI, TransactionEvents},
error::{ExecutionError, IotaError, IotaResult},
execution_status::ExecutionStatus,
gas::GasCostSummary,
Expand Down Expand Up @@ -198,6 +198,40 @@ impl IotaTransactionBlockResponseOptions {
pub fn only_digest(&self) -> bool {
self == &Self::default()
}

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: true,
show_raw_input: false,
}
}

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();
}

// 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,
"effects" => options.show_raw_effects = true,
_ => {}
}
}
options
}
}

#[serde_as]
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-json-rpc/src/transaction_execution_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl TransactionExecutionApi {
digest,
transaction,
raw_transaction,
effects: opts.show_effects.then_some(effects.effects.try_into()?),
effects: Some(effects.effects.try_into()?),
events,
object_changes,
balance_changes,
Expand Down
14 changes: 7 additions & 7 deletions crates/iota-sdk/src/wallet_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,13 @@ impl WalletContext {
pub async fn execute_transaction_must_succeed(
&self,
tx: Transaction,
response_opts: IotaTransactionBlockResponseOptions,
) -> IotaTransactionBlockResponse {
tracing::debug!("Executing transaction: {:?}", tx);
let response = self.execute_transaction_may_fail(tx).await.unwrap();
let response = self
.execute_transaction_may_fail(tx, response_opts)
.await
.unwrap();
assert!(
response.status_ok().unwrap(),
"Transaction failed: {:?}",
Expand All @@ -317,18 +321,14 @@ impl WalletContext {
pub async fn execute_transaction_may_fail(
&self,
tx: Transaction,
response_opts: IotaTransactionBlockResponseOptions,
) -> anyhow::Result<IotaTransactionBlockResponse> {
let client = self.get_client().await?;
Ok(client
.quorum_driver_api()
.execute_transaction_block(
tx,
IotaTransactionBlockResponseOptions::new()
.with_effects()
.with_input()
.with_events()
.with_object_changes()
.with_balance_changes(),
response_opts,
Some(iota_types::quorum_driver_types::ExecuteTransactionRequestType::WaitForLocalExecution),
)
.await?)
Expand Down
15 changes: 12 additions & 3 deletions crates/iota-surfer/src/surfer_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use std::{
};

use indexmap::IndexSet;
use iota_json_rpc_types::{IotaTransactionBlockEffects, IotaTransactionBlockEffectsAPI};
use iota_json_rpc_types::{
IotaTransactionBlockEffects, IotaTransactionBlockEffectsAPI,
IotaTransactionBlockResponseOptions,
};
use iota_move_build::BuildConfig;
use iota_protocol_config::ProtocolConfig;
use iota_types::{
Expand Down Expand Up @@ -174,7 +177,10 @@ impl SurferState {
match self
.cluster
.wallet
.execute_transaction_may_fail(tx.clone())
.execute_transaction_may_fail(
tx.clone(),
IotaTransactionBlockResponseOptions::default_profile(),
)
.await
{
Ok(effects) => break effects,
Expand Down Expand Up @@ -333,7 +339,10 @@ impl SurferState {
match self
.cluster
.wallet
.execute_transaction_may_fail(tx.clone())
.execute_transaction_may_fail(
tx.clone(),
IotaTransactionBlockResponseOptions::default_profile(),
)
.await
{
Ok(response) => {
Expand Down
49 changes: 41 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,12 @@ pub async fn publish_package(context: &WalletContext, path: PathBuf) -> ObjectRe
.publish(path)
.build(),
);
let resp = context.execute_transaction_must_succeed(txn).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 +547,12 @@ pub async fn publish_basics_package(context: &WalletContext) -> ObjectRef {
.publish_examples("basics")
.build(),
);
let resp = context.execute_transaction_must_succeed(txn).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 +570,10 @@ pub async fn publish_basics_package_and_make_counter(
.build(),
);
let resp = context
.execute_transaction_must_succeed(counter_creation_txn)
.execute_transaction_must_succeed(
counter_creation_txn,
IotaTransactionBlockResponseOptions::default_profile(),
)
.await;
let counter_ref = resp
.effects
Expand Down Expand Up @@ -599,7 +612,12 @@ pub async fn increment_counter(
.call_counter_increment(package_id, counter_id, initial_shared_version)
.build(),
);
context.execute_transaction_must_succeed(txn).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 +633,12 @@ pub async fn publish_nfts_package(
.publish_examples("nfts")
.build(),
);
let resp = context.execute_transaction_must_succeed(txn).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 +658,12 @@ pub async fn create_devnet_nft(
.call_nft_create(package_id)
.build(),
);
let resp = context.execute_transaction_must_succeed(txn).await;
let resp = context
.execute_transaction_must_succeed(
txn,
IotaTransactionBlockResponseOptions::default_profile(),
)
.await;

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

0 comments on commit bd581a7

Please sign in to comment.