diff --git a/crates/rooch-rpc-api/src/jsonrpc_types/execute_tx_response.rs b/crates/rooch-rpc-api/src/jsonrpc_types/execute_tx_response.rs index b8354ea686..f91a8b20d3 100644 --- a/crates/rooch-rpc-api/src/jsonrpc_types/execute_tx_response.rs +++ b/crates/rooch-rpc-api/src/jsonrpc_types/execute_tx_response.rs @@ -5,6 +5,7 @@ use super::BytesView; use super::{HumanReadableDisplay, ModuleIdView, StateChangeSetView, StrView}; use crate::jsonrpc_types::event_view::EventView; use crate::jsonrpc_types::H256View; +use ethers::types::H256; use move_core_types::vm_status::{AbortLocation, KeptVMStatus}; use moveos_types::transaction::TransactionOutput; use moveos_types::transaction::{TransactionExecutionInfo, VMErrorInfo}; @@ -13,6 +14,7 @@ use rooch_types::transaction::{authenticator::Authenticator, TransactionSequence use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use std::str::FromStr; +use std::u64; pub type AbortLocationView = StrView; @@ -103,6 +105,22 @@ pub struct TransactionSequenceInfoView { pub tx_timestamp: StrView, } +impl TransactionSequenceInfoView { + fn new( + tx_order: u64, + tx_order_signature: Vec, + tx_accumulator_root: H256, + tx_timestamp: u64, + ) -> Self { + Self { + tx_order: StrView(tx_order), + tx_order_signature: tx_order_signature.into(), + tx_accumulator_root: tx_accumulator_root.into(), + tx_timestamp: StrView(tx_timestamp), + } + } +} + impl From for TransactionSequenceInfoView { fn from(transaction_sequence_info: TransactionSequenceInfo) -> Self { Self { @@ -123,6 +141,24 @@ pub struct TransactionExecutionInfoView { pub status: KeptVMStatusView, } +impl TransactionExecutionInfoView { + fn new( + tx_hash: H256, + state_root: H256, + event_root: H256, + gas_used: StrView, + status: KeptVMStatusView, + ) -> Self { + Self { + tx_hash: tx_hash.into(), + state_root: state_root.into(), + event_root: event_root.into(), + gas_used, + status, + } + } +} + impl From for TransactionExecutionInfoView { fn from(transaction_execution_info: TransactionExecutionInfo) -> Self { Self { @@ -211,6 +247,28 @@ impl ExecuteTransactionResponseView { } } +impl From for ExecuteTransactionResponseView { + fn from(response: DryRunTransactionResponseView) -> Self { + Self { + sequence_info: TransactionSequenceInfoView::new( + u64::MIN, + Vec::new(), + H256::random(), + u64::MIN, + ), + execution_info: TransactionExecutionInfoView::new( + H256::random(), + H256::random(), + H256::random(), + response.raw_output.gas_used, + response.raw_output.status.clone(), + ), + output: None, + error_info: Some(response), + } + } +} + impl From for ExecuteTransactionResponseView { fn from(response: ExecuteTransactionResponse) -> Self { Self { diff --git a/crates/rooch/src/commands/move_cli/commands/run_function.rs b/crates/rooch/src/commands/move_cli/commands/run_function.rs index 6748d1a87b..b677680f00 100644 --- a/crates/rooch/src/commands/move_cli/commands/run_function.rs +++ b/crates/rooch/src/commands/move_cli/commands/run_function.rs @@ -92,7 +92,11 @@ impl CommandAction for RunFunction { ) .await?; - let mut result = match (self.tx_options.authenticator, self.tx_options.session_key) { + if dry_run_result.raw_output.status != KeptVMStatusView::Executed { + return Ok(dry_run_result.into()); + }; + + let result = match (self.tx_options.authenticator, self.tx_options.session_key) { (Some(authenticator), _) => { let tx_data = context .build_tx_data(sender, action, max_gas_amount) @@ -163,10 +167,6 @@ impl CommandAction for RunFunction { } }; - if dry_run_result.raw_output.status != KeptVMStatusView::Executed { - result.error_info = Some(dry_run_result); - } - Ok(result) }