Skip to content

Commit

Permalink
[rooch-networkgh-2471] add hex output to build command.
Browse files Browse the repository at this point in the history
  • Loading branch information
Feliciss committed Aug 20, 2024
1 parent 2976af9 commit 995841d
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions crates/rooch/src/commands/transaction/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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<RoochTransactionData> for BuildCommand {
async fn execute(self) -> RoochResult<RoochTransactionData> {
impl CommandAction<Option<String>> for BuildCommand {
async fn execute(self) -> RoochResult<Option<String>> {
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;
Expand All @@ -58,6 +62,17 @@ impl CommandAction<RoochTransactionData> 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)
}
}
}

0 comments on commit 995841d

Please sign in to comment.