pub fn import_blocks<F, E, R>(
	mut config: FactoryFullConfiguration<F>,
	exit: E,
	mut input: R
) -> error::Result<()>
	where F: ServiceFactory, E: Future<Item=(),Error=()> + Send + 'static, R: Read,
{
	let client = new_client::<F>(&config)?;
	// FIXME #1134 this shouldn't need a mutable config.
	let queue = components::FullComponents::<F>::build_import_queue(&mut config, client.clone())?;

	let (wait_send, wait_recv) = std::sync::mpsc::channel();
	let wait_link = WaitLink::new(wait_send);
	queue.start(Box::new(wait_link))?;

	let (exit_send, exit_recv) = std::sync::mpsc::channel();
	::std::thread::spawn(move || {
		let _ = exit.wait();
		let _ = exit_send.send(());
	});

	let count: u64 = Decode::decode(&mut input).ok_or("Error reading file")?;
	info!("Importing {} blocks", count);
	let mut block_count = 0;
	for b in 0 .. count {
		if exit_recv.try_recv().is_ok() {
			break;
		}
		if let Some(signed) = SignedBlock::<F::Block>::decode(&mut input) {
			let (header, extrinsics) = signed.block.deconstruct();
			let hash = header.hash();
			let block  = message::BlockData::<F::Block> {
				hash: hash,
				justification: signed.justification,
				header: Some(header),
				body: Some(extrinsics),
				receipt: None,
				message_queue: None
			};
			// import queue handles verification and importing it into the client
			queue.import_blocks(BlockOrigin::File, vec![
				IncomingBlock::<F::Block>{
					hash: block.hash,
					header: block.header,
					body: block.body,
					justification: block.justification,
					origin: None,
				}
			]);
		} else {
			warn!("Error reading block data at {}.", b);
			break;
		}

		block_count = b;
		if b % 1000 == 0 {
			info!("#{}", b);
		}
	}

	let mut blocks_imported = 0;
	while blocks_imported < count {
		wait_recv.recv()
			.expect("Importing thread has panicked. Then the main process will die before this can be reached. qed.");
		blocks_imported += 1;
	}

	info!("Imported {} blocks. Best: #{}", block_count, client.info()?.chain.best_number);

	Ok(())
}
/// Import blocks from a binary stream.
Import blocks from a binary stream.
Import blocks from a binary stream .
pub fn import_blocks<F, E, R>(
	mut config: FactoryFullConfiguration<F>,
	exit: E,
	mut input: R
) -> error::Result<()>
	where F: ServiceFactory, E: Future<Item=(),Error=()> + Send + 'static, R: Read,
{
	let client = new_client::<F>(&config)?;
	// FIXME #1134 this shouldn't need a mutable config.
	let queue = components::FullComponents::<F>::build_import_queue(&mut config, client.clone())?;
	let (wait_send, wait_recv) = std::sync::mpsc::channel();
	let wait_link = WaitLink::new(wait_send);
	queue.start(Box::new(wait_link))?;
	let (exit_send, exit_recv) = std::sync::mpsc::channel();
	::std::thread::spawn(move || {
		let _ = exit.wait();
		let _ = exit_send.send(());
	});
	let count: u64 = Decode::decode(&mut input).ok_or("Error reading file")?;
	info!("Importing {} blocks", count);
	let mut block_count = 0;
	for b in 0 .. count {
		if exit_recv.try_recv().is_ok() {
			break;
		}
		if let Some(signed) = SignedBlock::<F::Block>::decode(&mut input) {
			let (header, extrinsics) = signed.block.deconstruct();
			let hash = header.hash();
			let block  = message::BlockData::<F::Block> {
				hash: hash,
				justification: signed.justification,
				header: Some(header),
				body: Some(extrinsics),
				receipt: None,
				message_queue: None
			};
			// import queue handles verification and importing it into the client
			queue.import_blocks(BlockOrigin::File, vec![
				IncomingBlock::<F::Block>{
					hash: block.hash,
					header: block.header,
					body: block.body,
					justification: block.justification,
					origin: None,
				}
			]);
		} else {
			warn!("Error reading block data at {}.", b);
			break;
		}
		block_count = b;
		if b % 1000 == 0 {
			info!("#{}", b);
		}
	}
	let mut blocks_imported = 0;
	while blocks_imported < count {
		wait_recv.recv()
			.expect("Importing thread has panicked. Then the main process will die before this can be reached. qed.");
		blocks_imported += 1;
	}
	info!("Imported {} blocks. Best: #{}", block_count, client.info()?.chain.best_number);
	Ok(())
}
pub fn import_blocks < F , E , R > ( mut config : FactoryFullConfiguration < F > , exit : E , mut input : R ) -> error :: Result < ( ) > where F : ServiceFactory , E : Future < Item = ( ) , Error = ( ) > + Send + ' static , R : Read , { let client = new_client :: < F > ( & config ) ? ; // FIXME #1134 this shouldn't need a mutable config. let queue = components :: FullComponents :: < F > :: build_import_queue ( & mut config , client . clone ( ) ) ? ; let ( wait_send , wait_recv ) = std :: sync :: mpsc :: channel ( ) ; let wait_link = WaitLink :: new ( wait_send ) ; queue . start ( Box :: new ( wait_link ) ) ? ; let ( exit_send , exit_recv ) = std :: sync :: mpsc :: channel ( ) ; :: std :: thread :: spawn ( move | | { let _ = exit . wait ( ) ; let _ = exit_send . send ( ( ) ) ; } ) ; let count : u64 = Decode :: decode ( & mut input ) . ok_or ( " " ) ? ; info ! ( " " count ) ; let mut block_count = 0 ; for b in 0 .. count { if exit_recv . try_recv ( ) . is_ok ( ) { break ; } if let Some ( signed ) = SignedBlock :: < F :: Block > :: decode ( & mut input ) { let ( header , extrinsics ) = signed . block . deconstruct ( ) ; let hash = header . hash ( ) ; let block = message :: BlockData :: < F :: Block > { hash : hash , justification : signed . justification , header : Some ( header ) , body : Some ( extrinsics ) , receipt : None , message_queue : None } ; // import queue handles verification and importing it into the client queue . import_blocks ( BlockOrigin :: File , vec ! [ IncomingBlock F Block { hash block hash header block header body block body justification block justification origin None } ] ) ; } else { warn ! ( " " b ) ; break ; } block_count = b ; if b % 1000 == 0 { info ! ( " " b ) ; } } let mut blocks_imported = 0 ; while blocks_imported < count { wait_recv . recv ( ) . expect ( " " ) ; blocks_imported += 1 ; } info ! ( " " block_count client info ( ) chain best_number ) ; Ok ( ( ) ) }
Import blocks from a binary stream.
Import blocks from a binary stream .
config
FactoryFullConfiguration<F>
exit
E
input
R
config
FactoryFullConfiguration<F>
exit
E
input
R