Skip to content

Commit

Permalink
decode-transaction now supports binary64
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Aug 16, 2020
1 parent 0bfa237 commit fb79087
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
28 changes: 23 additions & 5 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
validator_info::*,
vote::*,
};
use clap::{App, AppSettings, Arg, ArgMatches, SubCommand};
use clap::{App, AppSettings, Arg, ArgMatches, SubCommand, value_t_or_exit};
use log::*;
use num_traits::FromPrimitive;
use serde_json::{self, json, Value};
Expand Down Expand Up @@ -821,8 +821,16 @@ pub fn parse_command(
_ => Err(CliError::BadParameter("Invalid signature".to_string())),
},
("decode-transaction", Some(matches)) => {
let blob = value_t_or_exit!(matches, "transaction", String);
let encoding = match matches.value_of("encoding").unwrap() {
"binary" => UiTransactionEncoding::Binary,
"binary64" => UiTransactionEncoding::Binary64,
_ => unreachable!()
};

let encoded_transaction = EncodedTransaction::Binary(
matches.value_of("base58_transaction").unwrap().to_string(),
blob,
encoding,
);
if let Some(transaction) = encoded_transaction.decode() {
Ok(CliCommandInfo {
Expand Down Expand Up @@ -2155,12 +2163,22 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, '
SubCommand::with_name("decode-transaction")
.about("Decode a base-58 binary transaction")
.arg(
Arg::with_name("base58_transaction")
Arg::with_name("transaction")
.index(1)
.value_name("BASE58_TRANSACTION")
.value_name("TRANSACTION")
.takes_value(true)
.required(true)
.help("transaction to decode"),
)
.arg(
Arg::with_name("encoding")
.index(2)
.value_name("ENCODING")
.possible_values(&["binary", "binary64"]) // Subset of `UiTransactionEncoding` enum
.default_value("binary")
.takes_value(true)
.required(true)
.help("The transaction to decode"),
.help("transaction encoding"),
),
)
.subcommand(
Expand Down
19 changes: 10 additions & 9 deletions transaction-status/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,16 @@ impl EncodedTransaction {
.into_vec()
.ok()
.and_then(|bytes| bincode::deserialize(&bytes).ok()),
EncodedTransaction::Binary(blob, encoding) => {
if *encoding == UiTransactionEncoding::Binary64 {
base64::decode(blob)
.ok()
.and_then(|bytes| bincode::deserialize(&bytes).ok())
} else {
None
}
}
EncodedTransaction::Binary(blob, encoding) => match *encoding {
UiTransactionEncoding::Binary64 => base64::decode(blob)
.ok()
.and_then(|bytes| bincode::deserialize(&bytes).ok()),
UiTransactionEncoding::Binary => bs58::decode(blob)
.into_vec()
.ok()
.and_then(|bytes| bincode::deserialize(&bytes).ok()),
UiTransactionEncoding::Json | UiTransactionEncoding::JsonParsed => None,
},
}
}
}
Expand Down

0 comments on commit fb79087

Please sign in to comment.