From 9a32010387c8c87ac97d5ef1537503ad43522af1 Mon Sep 17 00:00:00 2001 From: Feliciss <10203-feliciss@users.noreply.0xacab.org> Date: Tue, 20 Aug 2024 22:23:42 +0900 Subject: [PATCH] [gh-2471] add hex output to build command. --- .../commands/transaction/commands/build.rs | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/crates/rooch/src/commands/transaction/commands/build.rs b/crates/rooch/src/commands/transaction/commands/build.rs index 7f22e77bac..c6d61081fe 100644 --- a/crates/rooch/src/commands/transaction/commands/build.rs +++ b/crates/rooch/src/commands/transaction/commands/build.rs @@ -9,7 +9,7 @@ use move_core_types::{ language_storage::{ModuleId, TypeTag}, }; use moveos_types::{move_types::FunctionId, transaction::MoveAction}; -use rooch_types::{error::RoochResult, transaction::RoochTransactionData}; +use rooch_types::error::RoochResult; /// Get transactions by order #[derive(Debug, clap::Parser)] @@ -34,11 +34,15 @@ pub struct BuildCommand { #[clap(flatten)] context: WalletContextOptions, + + /// Return command outputs in json format + #[clap(long, default_value = "false")] + json: bool, } #[async_trait] -impl CommandAction for BuildCommand { - async fn execute(self) -> RoochResult { +impl CommandAction> for BuildCommand { + async fn execute(self) -> RoochResult> { let context = self.context.build()?; let sender = context.resolve_address(self.tx_options.sender)?.into(); let max_gas_amount = self.tx_options.max_gas_amount; @@ -58,6 +62,17 @@ impl CommandAction for BuildCommand { let tx_data = context .build_tx_data(sender, action, max_gas_amount) .await?; - Ok(tx_data) + let tx_data_hex = hex::encode(tx_data.encode()); + + if self.json { + Ok(Some(tx_data_hex)) + } else { + println!( + "Build transaction succeeded with the transaction hex [{}]", + tx_data_hex + ); + + Ok(None) + } } }