From 5e5b048f01ecdc9339dd95847340a5a23337dd92 Mon Sep 17 00:00:00 2001 From: Feliciss <10203-feliciss@users.noreply.0xacab.org> Date: Mon, 16 Sep 2024 20:27:50 +0900 Subject: [PATCH] [gh-2589] add signatories as file suffix. --- crates/rooch-types/src/transaction/rooch.rs | 4 ++++ .../src/commands/transaction/commands/mod.rs | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/rooch-types/src/transaction/rooch.rs b/crates/rooch-types/src/transaction/rooch.rs index e546d9546a..60c79977fc 100644 --- a/crates/rooch-types/src/transaction/rooch.rs +++ b/crates/rooch-types/src/transaction/rooch.rs @@ -118,6 +118,10 @@ impl PartiallySignedRoochTransaction { self.data.sender } + pub fn signators(&self) -> usize { + self.authenticators.len() + } + pub fn contains_authenticator(&self, authenticator: &BitcoinAuthenticator) -> bool { self.authenticators .iter() diff --git a/crates/rooch/src/commands/transaction/commands/mod.rs b/crates/rooch/src/commands/transaction/commands/mod.rs index a1b3891a03..02b34d9165 100644 --- a/crates/rooch/src/commands/transaction/commands/mod.rs +++ b/crates/rooch/src/commands/transaction/commands/mod.rs @@ -31,6 +31,14 @@ impl FileOutputData { } } + pub fn file_count_suffix(&self) -> usize { + match self { + FileOutputData::RoochTransactionData(_) => 1, + FileOutputData::SignedRoochTransaction(_) => 1, + FileOutputData::PartiallySignedRoochTransaction(data) => data.signators(), + } + } + pub fn file_suffix(&self) -> &str { match self { FileOutputData::RoochTransactionData(_) => "rtd", @@ -50,7 +58,12 @@ impl FileOutputData { pub fn default_output_file_path(&self) -> Result { let temp_dir = env::temp_dir(); let tx_hash = self.tx_hash(); - let file_name = format!("{}.{}", hex::encode(&tx_hash[..8]), self.file_suffix()); + let file_name = format!( + "{}.{}.{}", + hex::encode(&tx_hash[..8]), + self.file_count_suffix(), + self.file_suffix() + ); Ok(temp_dir.join(file_name)) } }