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> { + self.transaction_status_cf.get(index) + } + pub fn write_transaction_status( &self, index: (Slot, Signature), @@ -1480,6 +1487,10 @@ impl Blockstore { self.transaction_status_cf.put(index, status) } + pub fn read_rewards(&self, index: Slot) -> Result> { + self.rewards_cf.get(index) + } + pub fn write_rewards(&self, index: Slot, rewards: RpcRewards) -> Result<()> { self.rewards_cf.put(index, &rewards) }