Skip to content

Commit

Permalink
[gh-2473] fix issues arisen from comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Feliciss authored and feliciss committed Aug 22, 2024
1 parent d18acc2 commit e73b8a5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
26 changes: 7 additions & 19 deletions crates/rooch/src/commands/transaction/commands/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,10 @@ pub struct SignCommand {
#[clap(flatten)]
context: WalletContextOptions,

/// Read data from file, otherwise read transaction data hex from argument
#[clap(long, default_value = "false")]
read: bool,

/// File location for the file being read
#[clap(long)]
file_location: Option<String>,

/// Output result in command line, otherwise write to a file
#[clap(long, default_value = "false")]
output: bool,

/// File destination for the file being written
#[clap(long)]
file_destination: Option<String>,
Expand Down Expand Up @@ -83,7 +75,13 @@ impl CommandAction<Option<String>> for SignCommand {
));
}

if self.output {
if let Some(file_destination) = self.file_destination {
let mut file = File::create(file_destination)?;
file.write_all(&signed_tx.encode())?;
println!("Write signed tx data succeeded in the destination");

Ok(None)
} else {
let signed_tx_hex = hex::encode(signed_tx.encode());
if self.json {
Ok(Some(signed_tx_hex))
Expand All @@ -95,16 +93,6 @@ impl CommandAction<Option<String>> for SignCommand {

Ok(None)
}
} else if let Some(file_destination) = self.file_destination {
let mut file = File::create(file_destination)?;
file.write_all(&signed_tx.encode())?;
println!("Write signed tx data succeeded in the destination");

Ok(None)
} else {
return Err(RoochError::CommandArgumentError(
"Argument --output or --file-destination are not provided".to_owned(),
));
}
}
}
6 changes: 2 additions & 4 deletions crates/rooch/src/commands/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@

use crate::cli_types::CommandAction;
use crate::commands::transaction::commands::{
build::BuildCommand,
sign::SignCommand,
get_transactions_by_hash::GetTransactionsByHashCommand,
get_transactions_by_order::GetTransactionsByOrderCommand
build::BuildCommand, get_transactions_by_hash::GetTransactionsByHashCommand,
get_transactions_by_order::GetTransactionsByOrderCommand, sign::SignCommand,
};
use async_trait::async_trait;
use clap::{Parser, Subcommand};
Expand Down
3 changes: 2 additions & 1 deletion crates/testsuite/features/cmd.feature
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ Feature: Rooch CLI integration tests
Then cmd: "transaction get-transactions-by-order --cursor 0 --limit 1 --descending-order false"
Then cmd: "transaction get-transactions-by-hash --hashes {{$.transaction[-1].data[0].execution_info.tx_hash}}"
Then cmd: "transaction build --function rooch_framework::empty::empty --json"
Then cmd: "transaction sign --tx-hex {{$.transaction[-1]}} --output --json
Then assert: "'{{$.transaction[-1]}}' == '0ea3bb55c14aec8e074cd48c6a850526aa46965e176df53fadb433adeeeb56570000000000000000040000000000000000e1f5050000000001000000000000000000000000000000000000000000000000000000000000000305656d70747905656d7074790000'"
Then cmd: "transaction sign --tx-hex {{$.transaction[-1]}} --json
# alias tx for transaction
Then cmd: "tx get-transactions-by-order --cursor 1 --limit 2 --descending-order true"
Expand Down

0 comments on commit e73b8a5

Please sign in to comment.