Clean up read_entries() and its usage
This commit is contained in:
parent
f6fe998ed4
commit
88a6fb86bf
|
@ -530,7 +530,7 @@ mod tests {
|
|||
use hash::hash;
|
||||
use ledger::next_entries;
|
||||
use signature::KeyPairUtil;
|
||||
use std::io::{BufRead, BufReader, Cursor, Seek, SeekFrom};
|
||||
use std::io::{BufReader, Cursor, Seek, SeekFrom};
|
||||
|
||||
#[test]
|
||||
fn test_two_payments_to_one_party() {
|
||||
|
@ -807,9 +807,7 @@ mod tests {
|
|||
file.seek(SeekFrom::Start(0)).unwrap();
|
||||
|
||||
let reader = BufReader::new(file);
|
||||
reader
|
||||
.lines()
|
||||
.map(|line| entry_writer::read_entry(line.unwrap()).unwrap())
|
||||
entry_writer::read_entries(reader).map(|x| x.unwrap())
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -49,15 +49,12 @@ impl<'a, W: Write> EntryWriter<'a, W> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn read_entry(s: String) -> io::Result<Entry> {
|
||||
serde_json::from_str(&s).map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
|
||||
pub fn read_entry(s: &str) -> io::Result<Entry> {
|
||||
serde_json::from_str(s).map_err(|e| Error::new(ErrorKind::Other, e.to_string()))
|
||||
}
|
||||
|
||||
// TODO: How to implement this without attaching the input's lifetime to the output?
|
||||
pub fn read_entries<'a, R: BufRead>(
|
||||
reader: &'a mut R,
|
||||
) -> impl Iterator<Item = io::Result<Entry>> + 'a {
|
||||
reader.lines().map(|s| read_entry(s?))
|
||||
pub fn read_entries<R: BufRead>(reader: R) -> impl Iterator<Item = io::Result<Entry>> {
|
||||
reader.lines().map(|s| read_entry(&s?))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -7,8 +7,8 @@ use ncp::Ncp;
|
|||
use packet::BlobRecycler;
|
||||
use rpu::Rpu;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::io::{sink, stdin, stdout, BufReader};
|
||||
use std::io::{Read, Write};
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
@ -44,23 +44,14 @@ impl FullNode {
|
|||
) -> FullNode {
|
||||
info!("creating bank...");
|
||||
let bank = Bank::default();
|
||||
let entry_height = match infile {
|
||||
InFile::Path(path) => {
|
||||
let f = File::open(path).unwrap();
|
||||
let mut r = BufReader::new(f);
|
||||
let entries =
|
||||
entry_writer::read_entries(&mut r).map(|e| e.expect("failed to parse entry"));
|
||||
info!("processing ledger...");
|
||||
bank.process_ledger(entries).expect("process_ledger")
|
||||
}
|
||||
InFile::StdIn => {
|
||||
let mut r = BufReader::new(stdin());
|
||||
let entries =
|
||||
entry_writer::read_entries(&mut r).map(|e| e.expect("failed to parse entry"));
|
||||
info!("processing ledger...");
|
||||
bank.process_ledger(entries).expect("process_ledger")
|
||||
}
|
||||
let infile: Box<Read> = match infile {
|
||||
InFile::Path(path) => Box::new(File::open(path).unwrap()),
|
||||
InFile::StdIn => Box::new(stdin()),
|
||||
};
|
||||
let reader = BufReader::new(infile);
|
||||
let entries = entry_writer::read_entries(reader).map(|e| e.expect("failed to parse entry"));
|
||||
info!("processing ledger...");
|
||||
let entry_height = bank.process_ledger(entries).expect("process_ledger");
|
||||
|
||||
// entry_height is the network-wide agreed height of the ledger.
|
||||
// initialize it from the input ledger
|
||||
|
|
Loading…
Reference in New Issue