cli-output: Add option sigverify status to `println_transaction()` output
This commit is contained in:
parent
22800054e6
commit
a2aea0ca33
|
@ -1614,6 +1614,37 @@ pub fn parse_sign_only_reply_string(reply: &str) -> SignOnly {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CliSignatureVerificationStatus {
|
||||
None,
|
||||
Pass,
|
||||
Fail,
|
||||
}
|
||||
|
||||
impl CliSignatureVerificationStatus {
|
||||
pub fn get(tx: &Transaction) -> Vec<Self> {
|
||||
tx.verify_with_results()
|
||||
.iter()
|
||||
.zip(&tx.signatures)
|
||||
.map(|(stat, sig)| match stat {
|
||||
true => CliSignatureVerificationStatus::Pass,
|
||||
false if sig == &Signature::default() => CliSignatureVerificationStatus::None,
|
||||
false => CliSignatureVerificationStatus::Fail,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for CliSignatureVerificationStatus {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
Self::None => write!(f, "none"),
|
||||
Self::Pass => write!(f, "pass"),
|
||||
Self::Fail => write!(f, "fail"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::cli_output::CliSignatureVerificationStatus;
|
||||
use console::style;
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
use solana_sdk::{
|
||||
|
@ -126,6 +127,7 @@ pub fn write_transaction<W: io::Write>(
|
|||
transaction: &Transaction,
|
||||
transaction_status: &Option<UiTransactionStatusMeta>,
|
||||
prefix: &str,
|
||||
sigverify_status: Option<&[CliSignatureVerificationStatus]>,
|
||||
) -> io::Result<()> {
|
||||
let message = &transaction.message;
|
||||
writeln!(
|
||||
|
@ -133,11 +135,24 @@ pub fn write_transaction<W: io::Write>(
|
|||
"{}Recent Blockhash: {:?}",
|
||||
prefix, message.recent_blockhash
|
||||
)?;
|
||||
for (signature_index, signature) in transaction.signatures.iter().enumerate() {
|
||||
let sigverify_statuses = if let Some(sigverify_status) = sigverify_status {
|
||||
sigverify_status
|
||||
.iter()
|
||||
.map(|s| format!(" ({})", s))
|
||||
.collect()
|
||||
} else {
|
||||
vec!["".to_string(); transaction.signatures.len()]
|
||||
};
|
||||
for (signature_index, (signature, sigverify_status)) in transaction
|
||||
.signatures
|
||||
.iter()
|
||||
.zip(&sigverify_statuses)
|
||||
.enumerate()
|
||||
{
|
||||
writeln!(
|
||||
w,
|
||||
"{}Signature {}: {:?}",
|
||||
prefix, signature_index, signature
|
||||
"{}Signature {}: {:?}{}",
|
||||
prefix, signature_index, signature, sigverify_status,
|
||||
)?;
|
||||
}
|
||||
writeln!(w, "{}{:?}", prefix, message.header)?;
|
||||
|
@ -258,9 +273,18 @@ pub fn println_transaction(
|
|||
transaction: &Transaction,
|
||||
transaction_status: &Option<UiTransactionStatusMeta>,
|
||||
prefix: &str,
|
||||
sigverify_status: Option<&[CliSignatureVerificationStatus]>,
|
||||
) {
|
||||
let mut w = Vec::new();
|
||||
if write_transaction(&mut w, transaction, transaction_status, prefix).is_ok() {
|
||||
if write_transaction(
|
||||
&mut w,
|
||||
transaction,
|
||||
transaction_status,
|
||||
prefix,
|
||||
sigverify_status,
|
||||
)
|
||||
.is_ok()
|
||||
{
|
||||
if let Ok(s) = String::from_utf8(w) {
|
||||
print!("{}", s);
|
||||
}
|
||||
|
|
|
@ -1011,6 +1011,7 @@ fn process_confirm(
|
|||
.expect("Successful decode"),
|
||||
&confirmed_transaction.transaction.meta,
|
||||
" ",
|
||||
None,
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
|
@ -1043,7 +1044,7 @@ fn process_confirm(
|
|||
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
fn process_decode_transaction(transaction: &Transaction) -> ProcessResult {
|
||||
println_transaction(transaction, &None, "");
|
||||
println_transaction(transaction, &None, "", None);
|
||||
Ok("".to_string())
|
||||
}
|
||||
|
||||
|
|
|
@ -967,6 +967,7 @@ pub fn process_get_block(
|
|||
&transaction_with_meta.transaction.decode().unwrap(),
|
||||
&transaction_with_meta.meta,
|
||||
" ",
|
||||
None,
|
||||
);
|
||||
}
|
||||
Ok("".to_string())
|
||||
|
@ -1838,6 +1839,7 @@ pub fn process_transaction_history(
|
|||
.expect("Successful decode"),
|
||||
&confirmed_transaction.transaction.meta,
|
||||
" ",
|
||||
None,
|
||||
);
|
||||
}
|
||||
Err(err) => println!(" Unable to get confirmed transaction details: {}", err),
|
||||
|
|
|
@ -69,6 +69,7 @@ async fn block(slot: Slot) -> Result<(), Box<dyn std::error::Error>> {
|
|||
&transaction_with_meta.transaction,
|
||||
&transaction_with_meta.meta.map(|meta| meta.into()),
|
||||
" ",
|
||||
None,
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
|
@ -104,6 +105,7 @@ async fn confirm(signature: &Signature, verbose: bool) -> Result<(), Box<dyn std
|
|||
&confirmed_transaction.transaction.transaction,
|
||||
&confirmed_transaction.transaction.meta.map(|m| m.into()),
|
||||
" ",
|
||||
None,
|
||||
);
|
||||
}
|
||||
Ok(None) => println!("Finalized transaction details not available"),
|
||||
|
@ -183,6 +185,7 @@ pub async fn transaction_history(
|
|||
&transaction_with_meta.transaction,
|
||||
&transaction_with_meta.meta.clone().map(|m| m.into()),
|
||||
" ",
|
||||
None,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,6 +122,7 @@ fn output_entry(
|
|||
&transaction,
|
||||
&transaction_status,
|
||||
" ",
|
||||
None,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -387,7 +387,7 @@ fn print_confirmed_tx(name: &str, confirmed_tx: ConfirmedTransaction) {
|
|||
let tx = confirmed_tx.transaction.transaction.clone();
|
||||
let encoded = confirmed_tx.encode(UiTransactionEncoding::JsonParsed);
|
||||
println!("EXECUTE {} (slot {})", name, encoded.slot);
|
||||
println_transaction(&tx, &encoded.transaction.meta, " ");
|
||||
println_transaction(&tx, &encoded.transaction.meta, " ", None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue