Add new line after writing block to hex file. (#10984)

* add new line after writing block to hex file.

* refactor for testability

* correct import

* better error reporting, code formatting

* multiline imports

* docs

* better docs, move type to common types, merge ImportBlocks and ExportBlocks

* tabs over spaces

* correct test imports

* Apply suggestions from code review

Co-Authored-By: David <dvdplm@gmail.com>

* correct typo

* fixed test import
This commit is contained in:
Seun LanLege
2019-09-09 12:46:05 +01:00
committed by David
parent 53e590f54b
commit 80f0e4b58f
8 changed files with 391 additions and 179 deletions

View File

@@ -55,6 +55,7 @@ use trace::{
localized::LocalizedTrace,
VMTrace,
};
use common_types::data_format::DataFormat;
use vm::{LastHashes, Schedule};
use common_types::snapshot::Progress;
@@ -510,3 +511,29 @@ pub trait ChainNotify: Send + Sync {
// does nothing by default
}
}
/// Provides a method for importing/exporting blocks
pub trait ImportExportBlocks {
/// Export blocks to destination, with the given from, to and format argument.
/// destination could be a file or stdout.
/// If the format is hex, each block is written on a new line.
/// For binary exports, all block data is written to the same line.
fn export_blocks<'a>(
&self,
destination: Box<dyn std::io::Write + 'a>,
from: BlockId,
to: BlockId,
format: Option<DataFormat>
) -> Result<(), String>;
/// Import blocks from destination, with the given format argument
/// Source could be a file or stdout.
/// For hex format imports, it attempts to read the blocks on a line by line basis.
/// For binary format imports, reads the 8 byte RLP header in order to decode the block
/// length to be read.
fn import_blocks<'a>(
&self,
source: Box<dyn std::io::Read + 'a>,
format: Option<DataFormat>
) -> Result<(), String>;
}