Skip to content

Commit

Permalink
Loop over entire ledger
Browse files Browse the repository at this point in the history
  • Loading branch information
publish-docs.sh committed May 28, 2020
1 parent 323be6b commit 6d5be35
Showing 1 changed file with 63 additions and 7 deletions.
70 changes: 63 additions & 7 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ use serde::{
Deserialize,
};

use base64;

#[derive(PartialEq)]
enum LedgerOutputMethod {
Print,
Expand Down Expand Up @@ -100,10 +98,10 @@ fn output_slot_to_csv(
for entry in entries {
for transaction in entry.transactions {
// Skip any vote transactions
// let program_pubkey = transaction
// .message
// .account_keys[transaction.message.instructions[0].program_id_index as usize];
// if program_pubkey == solana_vote_program::id() { continue; }
let program_pubkey = transaction
.message
.account_keys[transaction.message.instructions[0].program_id_index as usize];
if program_pubkey == solana_vote_program::id() { continue; }

let transaction_status: Option<RpcTransactionStatusMeta> = blockstore
.read_transaction_status((transaction.signatures[0], slot))
Expand Down Expand Up @@ -161,7 +159,8 @@ fn build_instruction_info(
// solana_vote_program::vote_instruction::VoteInstruction,
// >(&instruction.data)
// {
// instruction_info.program_instruction = Some(std::str::from_utf8(&vote_instruction).unwrap().to_string());
// instruction_info.program_instruction =
// Some(std::str::from_utf8(&vote_instruction).unwrap().to_string());
// }
// }

Expand Down Expand Up @@ -293,6 +292,42 @@ fn output_slot(
output_slot_rewards(blockstore, slot, method)
}

fn output_ledger_to_csv(blockstore: &Blockstore,
ledger_path: &PathBuf,
starting_slot: Slot,
txn_csv_file: String,
instruction_csv_file: String) {
let rooted_slot_iterator =
RootedSlotIterator::new(starting_slot, &blockstore).unwrap_or_else(|err| {
eprintln!(
"Failed to load entries starting from slot {}: {:?}",
starting_slot, err
);
exit(1);
});

let mut txn_wtr = csv::WriterBuilder::new()
.has_headers(false)
.flexible(true)
.from_path(txn_csv_file)
.unwrap();
let mut instruction_wtr = csv::WriterBuilder::new()
.has_headers(false)
.flexible(true)
.from_path(instruction_csv_file)
.unwrap();

for (slot, slot_meta) in rooted_slot_iterator {
output_slot_to_csv(
blockstore,
slot,
&mut txn_wtr,
&mut instruction_wtr,
ledger_path,
);
}
}

fn output_ledger(blockstore: Blockstore, starting_slot: Slot, method: LedgerOutputMethod) {
let rooted_slot_iterator =
RootedSlotIterator::new(starting_slot, &blockstore).unwrap_or_else(|err| {
Expand Down Expand Up @@ -795,6 +830,13 @@ fn main() {
.about("Print the ledger")
.arg(&starting_slot_arg)
)
.subcommand(
SubCommand::with_name("print-csv")
.about("Write the ledger to CSV files")
.arg(&starting_slot_arg)
.arg(&txn_csv_file_arg)
.arg(&instruction_csv_file_arg)
)
.subcommand(
SubCommand::with_name("slot")
.about("Print the contents of one or more slots")
Expand Down Expand Up @@ -1011,6 +1053,20 @@ fn main() {
LedgerOutputMethod::Print,
);
}
("print-csv", Some(arg_matches)) => {
let starting_slot = value_t_or_exit!(arg_matches, "starting_slot", Slot);
let txn_csv_file = value_t_or_exit!(arg_matches, "txn_csv_file", String);
let instruction_csv_file = value_t_or_exit!(arg_matches, "instruction_csv_file", String);
let blockstore = open_blockstore(&ledger_path);
output_ledger_to_csv(
&blockstore,
&ledger_path,
starting_slot,
txn_csv_file,
instruction_csv_file,
);
}

("genesis", Some(_arg_matches)) => {
println!("{}", open_genesis_config(&ledger_path));
}
Expand Down

0 comments on commit 6d5be35

Please sign in to comment.