Move replaying ledger out of accountant

This commit is contained in:
Greg Fitzgerald
2018-04-02 14:51:38 -06:00
parent 2b788d06b7
commit daadae7987
2 changed files with 29 additions and 37 deletions

View File

@@ -2,6 +2,8 @@ extern crate serde_json;
extern crate solana;
use solana::accountant::Accountant;
use solana::event::Event;
use solana::entry::Entry;
use solana::historian::Historian;
use solana::accountant_skel::AccountantSkel;
use std::io::{self, stdout, BufRead};
@@ -11,11 +13,35 @@ use std::sync::{Arc, Mutex};
fn main() {
let addr = "127.0.0.1:8000";
let stdin = io::stdin();
let entries = stdin
let mut entries = stdin
.lock()
.lines()
.map(|line| serde_json::from_str(&line.unwrap()).unwrap());
let (acc, last_id) = Accountant::new_from_entries(entries);
// The first item in the ledger is required to be an entry with zero num_hashes,
// which implies its id can be used as the ledger's seed.
entries.next().unwrap();
// The second item in the ledger is a special transaction where the to and from
// fields are the same. That entry should be treated as a deposit, not a
// transfer to oneself.
let entry1: Entry = entries.next().unwrap();
let deposit = if let Event::Transaction(ref tr) = entry1.events[0] {
tr.plan.final_payment()
} else {
None
};
let mut acc = Accountant::new_from_deposit(&deposit.unwrap());
let mut last_id = entry1.id;
for entry in entries {
last_id = entry.id;
for event in entry.events {
acc.process_verified_event(&event).unwrap();
}
}
let historian = Historian::new(&last_id, Some(1000));
let exit = Arc::new(AtomicBool::new(false));
let skel = Arc::new(Mutex::new(AccountantSkel::new(