pub fn export_blocks<F, E, W>(
	config: FactoryFullConfiguration<F>,
	exit: E,
	mut output: W,
	from: FactoryBlockNumber<F>,
	to: Option<FactoryBlockNumber<F>>,
	json: bool
) -> error::Result<()>
	where
	F: ServiceFactory,
	E: Future<Item=(),Error=()> + Send + 'static,
	W: Write,
{
	let client = new_client::<F>(&config)?;
	let mut block = from;

	let last = match to {
		Some(v) if v == As::sa(0) => As::sa(1),
		Some(v) => v,
		None => client.info()?.chain.best_number,
	};

	if last < block {
		return Err("Invalid block range specified".into());
	}

	let (exit_send, exit_recv) = std::sync::mpsc::channel();
	::std::thread::spawn(move || {
		let _ = exit.wait();
		let _ = exit_send.send(());
	});
	info!("Exporting blocks from #{} to #{}", block, last);
	if !json {
		let last_: u64 = last.as_();
		let block_: u64 = block.as_();
		let len: u64 = last_ - block_ + 1;
		output.write(&len.encode())?;
	}

	loop {
		if exit_recv.try_recv().is_ok() {
			break;
		}
		match client.block(&BlockId::number(block))? {
			Some(block) => {
				if json {
					serde_json::to_writer(&mut output, &block)
						.map_err(|e| format!("Error writing JSON: {}", e))?;
				} else {
					output.write(&block.encode())?;
				}
			},
			None => break,
		}
		if block.as_() % 10000 == 0 {
			info!("#{}", block);
		}
		if block == last {
			break;
		}
		block += As::sa(1);
	}
	Ok(())
}
/// Export a range of blocks to a binary stream.
Export a range of blocks to a binary stream.
Export a range of blocks to a binary stream .
pub fn export_blocks<F, E, W>(
	config: FactoryFullConfiguration<F>,
	exit: E,
	mut output: W,
	from: FactoryBlockNumber<F>,
	to: Option<FactoryBlockNumber<F>>,
	json: bool
) -> error::Result<()>
	where
	F: ServiceFactory,
	E: Future<Item=(),Error=()> + Send + 'static,
	W: Write,
{
	let client = new_client::<F>(&config)?;
	let mut block = from;
	let last = match to {
		Some(v) if v == As::sa(0) => As::sa(1),
		Some(v) => v,
		None => client.info()?.chain.best_number,
	};
	if last < block {
		return Err("Invalid block range specified".into());
	}
	let (exit_send, exit_recv) = std::sync::mpsc::channel();
	::std::thread::spawn(move || {
		let _ = exit.wait();
		let _ = exit_send.send(());
	});
	info!("Exporting blocks from #{} to #{}", block, last);
	if !json {
		let last_: u64 = last.as_();
		let block_: u64 = block.as_();
		let len: u64 = last_ - block_ + 1;
		output.write(&len.encode())?;
	}
	loop {
		if exit_recv.try_recv().is_ok() {
			break;
		}
		match client.block(&BlockId::number(block))? {
			Some(block) => {
				if json {
					serde_json::to_writer(&mut output, &block)
						.map_err(|e| format!("Error writing JSON: {}", e))?;
				} else {
					output.write(&block.encode())?;
				}
			},
			None => break,
		}
		if block.as_() % 10000 == 0 {
			info!("#{}", block);
		}
		if block == last {
			break;
		}
		block += As::sa(1);
	}
	Ok(())
}
pub fn export_blocks < F , E , W > ( config : FactoryFullConfiguration < F > , exit : E , mut output : W , from : FactoryBlockNumber < F > , to : Option < FactoryBlockNumber < F > > , json : bool ) -> error :: Result < ( ) > where F : ServiceFactory , E : Future < Item = ( ) , Error = ( ) > + Send + ' static , W : Write , { let client = new_client :: < F > ( & config ) ? ; let mut block = from ; let last = match to { Some ( v ) if v == As :: sa ( 0 ) => As :: sa ( 1 ) , Some ( v ) => v , None => client . info ( ) ? . chain . best_number , } ; if last < block { return Err ( " " . into ( ) ) ; } let ( exit_send , exit_recv ) = std :: sync :: mpsc :: channel ( ) ; :: std :: thread :: spawn ( move | | { let _ = exit . wait ( ) ; let _ = exit_send . send ( ( ) ) ; } ) ; info ! ( " " block last ) ; if ! json { let last_ : u64 = last . as_ ( ) ; let block_ : u64 = block . as_ ( ) ; let len : u64 = last_ - block_ + 1 ; output . write ( & len . encode ( ) ) ? ; } loop { if exit_recv . try_recv ( ) . is_ok ( ) { break ; } match client . block ( & BlockId :: number ( block ) ) ? { Some ( block ) => { if json { serde_json :: to_writer ( & mut output , & block ) . map_err ( | e | format ! ( " " e ) ) ? ; } else { output . write ( & block . encode ( ) ) ? ; } } , None => break , } if block . as_ ( ) % 10000 == 0 { info ! ( " " block ) ; } if block == last { break ; } block += As :: sa ( 1 ) ; } Ok ( ( ) ) }
Export a range of blocks to a binary stream.
Export a range of blocks to a binary stream .
config
FactoryFullConfiguration<F>
exit
E
output
W
from
FactoryBlockNumber<F>
to
Option<FactoryBlockNumber<F>>
json
bool
config
FactoryFullConfiguration<F>
exit
E
output
W
from
FactoryBlockNumber<F>
to
Option<FactoryBlockNumber<F>>
json
bool