Skip to content

Commit

Permalink
Merge ca0bc0e into 37d0d51
Browse files Browse the repository at this point in the history
  • Loading branch information
FroVolod authored Jun 17, 2021
2 parents 37d0d51 + ca0bc0e commit bbe9985
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Get the release version from the tag
# if: env.NEAR_CLI_VERSION == ''
run: |
echo "NEAR_CLI_VERSION=0.1.02" >> $GITHUB_ENV
echo "NEAR_CLI_VERSION=0.1.1" >> $GITHUB_ENV
echo "version is: ${{ env.NEAR_CLI_VERSION }}"
- name: Create GitHub release
Expand Down
10 changes: 10 additions & 0 deletions docs/GUIDE.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -1090,3 +1090,13 @@ This utility allows you to sign a previously generated and unsigned transaction
<img src="https://asciinema.org/a/HfsutLZKnWS8w1PnY1kGIUYid.png" width="836"/>
</a>
</details>

#### Deserializing the bytes from base64

It might be useful to view the contents of a serialized transaction (either signed or not).
Given a base64-encoded string, we should be able to view the human-readable representation.
<details><summary><i>Demonstration of the command in interactive mode</i></summary>
<a href="https://asciinema.org/a/Gtb4M13a8QW5VaVmfgBLEcq3X?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/Gtb4M13a8QW5VaVmfgBLEcq3X.png" width="836"/>
</a>
</details>
9 changes: 9 additions & 0 deletions docs/GUIDE.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -1090,3 +1090,12 @@ pyYc0jWocOZRXuNzrq150bLSIvARIE+fhf0ywxEr1kj/aObFoEPCuQYS5IN/oox5/BJGwoCHdWX+SxAA
<img src="https://asciinema.org/a/HfsutLZKnWS8w1PnY1kGIUYid.png" width="836"/>
</a>
</details>

#### Deserializing the bytes from base64

Данная утилита позволяет закодированную в Base64 транзакцию (подписанную или неподписанную) представить в удобочитаемом формате.
<details><summary><i>Демонстрация работы команды в интерактивном режиме</i></summary>
<a href="https://asciinema.org/a/Gtb4M13a8QW5VaVmfgBLEcq3X?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/Gtb4M13a8QW5VaVmfgBLEcq3X.png" width="836"/>
</a>
</details>
19 changes: 19 additions & 0 deletions src/commands/utils_command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use strum::{EnumDiscriminants, EnumIter, EnumMessage, IntoEnumIterator};
mod combine_transaction_subcommand_with_signature;
pub mod generate_keypair_subcommand;
mod sign_transaction_subcommand_with_secret_key;
mod view_serialized_transaction;

/// набор утилит-помощников
#[derive(Debug, Default, clap::Clap)]
Expand Down Expand Up @@ -35,6 +36,7 @@ impl Utils {

#[derive(Debug, clap::Clap)]
enum CliUtil {
/// It generates a random key pair
GenerateKeypair(self::generate_keypair_subcommand::CliGenerateKeypair),
/// Предоставьте данные для подписания данных с помощью privte key
SignTransactionSecretKey(
Expand All @@ -44,6 +46,8 @@ enum CliUtil {
CombineTransactionSignature(
self::combine_transaction_subcommand_with_signature::CliCombineTransactionSignature,
),
/// Using this module, you can view the contents of a serialized transaction (whether signed or not).
ViewSerializedTransaction(self::view_serialized_transaction::CliViewSerializedTransaction),
}

#[derive(Debug, EnumDiscriminants)]
Expand All @@ -59,6 +63,8 @@ pub enum Util {
CombineTransactionSignature(
self::combine_transaction_subcommand_with_signature::CombineTransactionSignature,
),
#[strum_discriminants(strum(message = "Deserializing the bytes from base64"))]
ViewSerializedTransaction(self::view_serialized_transaction::ViewSerializedTransaction),
}

impl From<CliUtil> for Util {
Expand All @@ -75,6 +81,13 @@ impl From<CliUtil> for Util {
self::combine_transaction_subcommand_with_signature::CombineTransactionSignature::from(cli_combine_transaction);
Util::CombineTransactionSignature(combine_transaction)
}
CliUtil::ViewSerializedTransaction(cli_view_serialized_transaction) => {
let view_serialized_transaction =
self::view_serialized_transaction::ViewSerializedTransaction::from(
cli_view_serialized_transaction,
);
Util::ViewSerializedTransaction(view_serialized_transaction)
}
}
}
}
Expand Down Expand Up @@ -103,6 +116,9 @@ impl Util {
UtilDiscriminants::CombineTransactionSignature => {
CliUtil::CombineTransactionSignature(Default::default())
}
UtilDiscriminants::ViewSerializedTransaction => {
CliUtil::ViewSerializedTransaction(Default::default())
}
};
Self::from(cli_util)
}
Expand All @@ -114,6 +130,9 @@ impl Util {
Self::CombineTransactionSignature(combine_transaction) => {
combine_transaction.process().await
}
Self::ViewSerializedTransaction(view_serialized_transaction) => {
view_serialized_transaction.process().await
}
}
}
}
51 changes: 51 additions & 0 deletions src/commands/utils_command/view_serialized_transaction/mod.rs
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(())
}
}

0 comments on commit bbe9985

Please sign in to comment.