-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/commands/utils_command/view_serialized_transaction/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use dialoguer::Input; | ||
use near_primitives::borsh::BorshDeserialize; | ||
|
||
/// Using this utility, you can view the contents of a serialized transaction (signed or not). | ||
#[derive(Debug, Default, clap::Clap)] | ||
pub struct CliViewSerializedTransaction { | ||
transaction: Option<String>, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct ViewSerializedTransaction { | ||
transaction: String, | ||
} | ||
|
||
impl From<CliViewSerializedTransaction> for ViewSerializedTransaction { | ||
fn from(item: CliViewSerializedTransaction) -> Self { | ||
let transaction: String = match item.transaction { | ||
Some(transaction) => transaction, | ||
None => ViewSerializedTransaction::input_transaction(), | ||
}; | ||
Self { transaction } | ||
} | ||
} | ||
|
||
impl ViewSerializedTransaction { | ||
fn input_transaction() -> String { | ||
Input::new() | ||
.with_prompt("Enter the hash of the transaction") | ||
.interact_text() | ||
.unwrap() | ||
} | ||
|
||
pub async fn process(self) -> crate::CliResult { | ||
let serialize_from_base64 = | ||
near_primitives::serialize::from_base64(&self.transaction).unwrap(); | ||
match near_primitives::transaction::Transaction::try_from_slice(&serialize_from_base64) { | ||
Ok(transaction) => println!("\n{:#?}", &transaction), | ||
Err(_) => { | ||
match near_primitives::transaction::SignedTransaction::try_from_slice( | ||
&serialize_from_base64, | ||
) { | ||
Ok(signed_transaction) => println!("\n{:#?}", signed_transaction), | ||
Err(err) => { | ||
println!("\nError: Base64 transaction sequence is invalid: {}", err) | ||
} | ||
} | ||
} | ||
}; | ||
Ok(()) | ||
} | ||
} |