pub fn read_meta<Block>(db: &KeyValueDB, col_meta: Option<u32>, col_header: Option<u32>) -> Result<
	Meta<<<Block as BlockT>::Header as HeaderT>::Number, Block::Hash>,
	client::error::Error,
>
	where
		Block: BlockT,
{
	let genesis_hash: Block::Hash = match db.get(col_meta, meta_keys::GENESIS_HASH).map_err(db_err)? {
		Some(h) => match Decode::decode(&mut &h[..]) {
			Some(h) => h,
			None => return Err(client::error::ErrorKind::Backend("Error decoding genesis hash".into()).into()),
		},
		None => return Ok(Meta {
			best_hash: Default::default(),
			best_number: Zero::zero(),
			finalized_hash: Default::default(),
			finalized_number: Zero::zero(),
			genesis_hash: Default::default(),
		}),
	};

	let load_meta_block = |desc, key| -> Result<_, client::error::Error> {
		if let Some(Some(header)) = db.get(col_meta, key).and_then(|id|
			match id {
				Some(id) => db.get(col_header, &id).map(|h| h.map(|b| Block::Header::decode(&mut &b[..]))),
				None => Ok(None),
			}).map_err(db_err)?
		{
			let hash = header.hash();
			debug!("DB Opened blockchain db, fetched {} = {:?} ({})", desc, hash, header.number());
			Ok((hash, *header.number()))
		} else {
			Ok((genesis_hash.clone(), Zero::zero()))
		}
	};

	let (best_hash, best_number) = load_meta_block("best", meta_keys::BEST_BLOCK)?;
	let (finalized_hash, finalized_number) = load_meta_block("final", meta_keys::FINALIZED_BLOCK)?;

	Ok(Meta {
		best_hash,
		best_number,
		finalized_hash,
		finalized_number,
		genesis_hash,
	})
}
/// Read meta from the database.
Read meta from the database.
Read meta from the database .
pub fn read_meta<Block>(db: &KeyValueDB, col_meta: Option<u32>, col_header: Option<u32>) -> Result<
	Meta<<<Block as BlockT>::Header as HeaderT>::Number, Block::Hash>,
	client::error::Error,
>
	where
		Block: BlockT,
{
	let genesis_hash: Block::Hash = match db.get(col_meta, meta_keys::GENESIS_HASH).map_err(db_err)? {
		Some(h) => match Decode::decode(&mut &h[..]) {
			Some(h) => h,
			None => return Err(client::error::ErrorKind::Backend("Error decoding genesis hash".into()).into()),
		},
		None => return Ok(Meta {
			best_hash: Default::default(),
			best_number: Zero::zero(),
			finalized_hash: Default::default(),
			finalized_number: Zero::zero(),
			genesis_hash: Default::default(),
		}),
	};
	let load_meta_block = |desc, key| -> Result<_, client::error::Error> {
		if let Some(Some(header)) = db.get(col_meta, key).and_then(|id|
			match id {
				Some(id) => db.get(col_header, &id).map(|h| h.map(|b| Block::Header::decode(&mut &b[..]))),
				None => Ok(None),
			}).map_err(db_err)?
		{
			let hash = header.hash();
			debug!("DB Opened blockchain db, fetched {} = {:?} ({})", desc, hash, header.number());
			Ok((hash, *header.number()))
		} else {
			Ok((genesis_hash.clone(), Zero::zero()))
		}
	};
	let (best_hash, best_number) = load_meta_block("best", meta_keys::BEST_BLOCK)?;
	let (finalized_hash, finalized_number) = load_meta_block("final", meta_keys::FINALIZED_BLOCK)?;
	Ok(Meta {
		best_hash,
		best_number,
		finalized_hash,
		finalized_number,
		genesis_hash,
	})
}
pub fn read_meta < Block > ( db : & KeyValueDB , col_meta : Option < u32 > , col_header : Option < u32 > ) -> Result < Meta < < < Block as BlockT > :: Header as HeaderT > :: Number , Block :: Hash > , client :: error :: Error , > where Block : BlockT , { let genesis_hash : Block :: Hash = match db . get ( col_meta , meta_keys :: GENESIS_HASH ) . map_err ( db_err ) ? { Some ( h ) => match Decode :: decode ( & mut & h [ .. ] ) { Some ( h ) => h , None => return Err ( client :: error :: ErrorKind :: Backend ( " " . into ( ) ) . into ( ) ) , } , None => return Ok ( Meta { best_hash : Default :: default ( ) , best_number : Zero :: zero ( ) , finalized_hash : Default :: default ( ) , finalized_number : Zero :: zero ( ) , genesis_hash : Default :: default ( ) , } ) , } ; let load_meta_block = | desc , key | -> Result < _ , client :: error :: Error > { if let Some ( Some ( header ) ) = db . get ( col_meta , key ) . and_then ( | id | match id { Some ( id ) => db . get ( col_header , & id ) . map ( | h | h . map ( | b | Block :: Header :: decode ( & mut & b [ .. ] ) ) ) , None => Ok ( None ) , } ) . map_err ( db_err ) ? { let hash = header . hash ( ) ; debug ! ( " " desc hash header number ( ) ) ; Ok ( ( hash , * header . number ( ) ) ) } else { Ok ( ( genesis_hash . clone ( ) , Zero :: zero ( ) ) ) } } ; let ( best_hash , best_number ) = load_meta_block ( " " , meta_keys :: BEST_BLOCK ) ? ; let ( finalized_hash , finalized_number ) = load_meta_block ( " " , meta_keys :: FINALIZED_BLOCK ) ? ; Ok ( Meta { best_hash , best_number , finalized_hash , finalized_number , genesis_hash , } ) }
Read meta from the database.
Read meta from the database .
db
&KeyValueDB
col_meta
Option<u32>
col_header
Option<u32>
db
&KeyValueDB
col_meta
Option<u32>
col_header
Option<u32>