From 5f1ce81fbc5e8f6f1bef31c5565fdcd250eca453 Mon Sep 17 00:00:00 2001
From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com>
Date: Tue, 24 Mar 2020 12:23:25 -0700
Subject: [PATCH] ledger tool now outputs transaction status information if
available (#9024) (#9026)
automerge
---
ledger-tool/src/main.rs | 66 ++++++++++++++++++++++++++++++++++++++++
ledger/src/blockstore.rs | 11 +++++++
2 files changed, 77 insertions(+)
diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs
index 609eb824b7..5662b1c720 100644
--- a/ledger-tool/src/main.rs
+++ b/ledger-tool/src/main.rs
@@ -21,6 +21,7 @@ use solana_sdk::{
use solana_vote_program::vote_state::VoteState;
use std::{
collections::{BTreeMap, HashMap, HashSet},
+ convert::TryInto,
ffi::OsStr,
fs::{self, File},
io::{self, stdout, Write},
@@ -108,14 +109,79 @@ fn output_slot(
println!(" Data: {:?}", instruction.data);
}
}
+ match blockstore.read_transaction_status((slot, transaction.signatures[0])) {
+ Ok(transaction_status) => {
+ if let Some(transaction_status) = transaction_status {
+ println!(
+ " Status: {}",
+ if transaction_status.status.is_ok() {
+ "Ok".into()
+ } else {
+ transaction_status.status.unwrap_err().to_string()
+ }
+ );
+ println!(" Fee: {}", transaction_status.fee);
+ assert_eq!(
+ transaction_status.pre_balances.len(),
+ transaction_status.post_balances.len()
+ );
+ for (i, (pre, post)) in transaction_status
+ .pre_balances
+ .iter()
+ .zip(transaction_status.post_balances.iter())
+ .enumerate()
+ {
+ if pre == post {
+ println!(
+ " Account {} balance: {} SOL",
+ i,
+ lamports_to_sol(*pre)
+ );
+ } else {
+ println!(
+ " Account {} balance: {} SOL -> {} SOL",
+ i,
+ lamports_to_sol(*pre),
+ lamports_to_sol(*post)
+ );
+ }
+ }
+ } else {
+ println!(" Status: Unavailable");
+ }
+ }
+ Err(err) => {
+ println!(" Status: {:?}", err);
+ }
+ }
}
}
LedgerOutputMethod::Json => {
+ // Note: transaction status is not output in JSON yet
serde_json::to_writer(stdout(), &entry).expect("serialize entry");
stdout().write_all(b",\n").expect("newline");
}
}
}
+
+ // Note: rewards are not output in JSON yet
+ if *method == LedgerOutputMethod::Print {
+ if let Ok(rewards) = blockstore.read_rewards(slot) {
+ if let Some(rewards) = rewards {
+ if !rewards.is_empty() {
+ println!(" Rewards:");
+ for reward in rewards {
+ println!(
+ " Account {}: {}{} SOL",
+ reward.pubkey,
+ if reward.lamports < 0 { '-' } else { ' ' },
+ lamports_to_sol(reward.lamports.abs().try_into().unwrap())
+ );
+ }
+ }
+ }
+ }
+ }
Ok(())
}
diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs
index d731eeb0a3..aad9f48c5e 100644
--- a/ledger/src/blockstore.rs
+++ b/ledger/src/blockstore.rs
@@ -1472,6 +1472,13 @@ impl Blockstore {
.collect()
}
+ pub fn read_transaction_status(
+ &self,
+ index: (Slot, Signature),
+ ) -> Result