From 039a3e484c9ae1ec27c65dde0f955c3580f44431 Mon Sep 17 00:00:00 2001 From: brenzi Date: Wed, 16 Oct 2024 11:27:34 +0200 Subject: [PATCH] allow hex output for gst-shard and get-fingerprint (#1615) --- .../trusted_base_cli/commands/get_fingerprint.rs | 9 ++++++++- cli/src/trusted_base_cli/commands/get_shard.rs | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/cli/src/trusted_base_cli/commands/get_fingerprint.rs b/cli/src/trusted_base_cli/commands/get_fingerprint.rs index d8a6ac3471..57d5e82290 100644 --- a/cli/src/trusted_base_cli/commands/get_fingerprint.rs +++ b/cli/src/trusted_base_cli/commands/get_fingerprint.rs @@ -28,7 +28,11 @@ use itp_utils::FromHexPrefixed; use log::*; #[derive(Parser)] -pub struct GetFingerprintCommand {} +pub struct GetFingerprintCommand { + /// also print as hex + #[clap(short = 'x', long = "hex")] + hex: bool, +} impl GetFingerprintCommand { pub(crate) fn run(&self, cli: &Cli, _trusted_args: &TrustedCli) -> CliResult { @@ -59,6 +63,9 @@ impl GetFingerprintCommand { })?; let fingerprint_b58 = fingerprint.encode().to_base58(); println!("{}", fingerprint_b58); + if self.hex { + println!("0x{}", hex::encode(fingerprint.encode())); + } Ok(CliResultOk::FingerprintBase58 { fingerprints: vec![fingerprint_b58] }) } } diff --git a/cli/src/trusted_base_cli/commands/get_shard.rs b/cli/src/trusted_base_cli/commands/get_shard.rs index d10f5d1e62..837ff45b8d 100644 --- a/cli/src/trusted_base_cli/commands/get_shard.rs +++ b/cli/src/trusted_base_cli/commands/get_shard.rs @@ -32,7 +32,14 @@ use log::*; use sp_core::H256; #[derive(Parser)] -pub struct GetShardCommand {} +pub struct GetShardCommand { + /// also print as hex + #[clap(short = 'x', long = "hex")] + hex: bool, + /// also print as ASCII + #[clap(short = 'a', long = "ascii")] + ascii: bool, +} impl GetShardCommand { pub(crate) fn run(&self, cli: &Cli, _trusted_args: &TrustedCli) -> CliResult { @@ -62,6 +69,12 @@ impl GetShardCommand { CliError::WorkerRpcApi { msg: err.to_string() } })?; println!("{}", shard.encode().to_base58()); + if self.hex { + println!("0x{}", hex::encode(shard)); + } + if self.ascii { + println!("{}", String::from_utf8_lossy(&shard.encode())); + } Ok(CliResultOk::H256 { hash: shard }) } }