pub fn init(
		db_root: String,
		adapter: Arc<ChainAdapter>,
		genesis: Block,
		pow_verifier: fn(&BlockHeader, u32) -> bool,
	) -> Result<Chain, Error> {
		let chain_store = store::ChainKVStore::new(db_root.clone())?;

		// check if we have a head in store, otherwise the genesis block is it
		let head = match chain_store.head() {
			Ok(tip) => tip,
			Err(NotFoundErr) => {
				let tip = Tip::new(genesis.hash());
				chain_store.save_block(&genesis)?;
				chain_store.setup_height(&genesis.header, &tip)?;

				// saving a new tip based on genesis
				chain_store.save_head(&tip)?;
				info!(
					LOGGER,
					"Saved genesis block: {:?}, nonce: {:?}, pow: {:?}",
					genesis.hash(),
					genesis.header.nonce,
					genesis.header.pow,
				);
				tip
			}
			Err(e) => return Err(Error::StoreErr(e, "chain init load head".to_owned())),
		};

		// make sure sync_head is available for later use
		let _ = match chain_store.get_sync_head() {
			Ok(tip) => tip,
			Err(NotFoundErr) => {
				let tip = chain_store.head().unwrap();
				chain_store.save_sync_head(&tip)?;
				tip
			},
			Err(e) => return Err(Error::StoreErr(e, "chain init sync head".to_owned())),
		};

		info!(
			LOGGER,
			"Chain init: {:?}",
			head,
		);

		let store = Arc::new(chain_store);
		let sumtrees = sumtree::SumTrees::open(db_root, store.clone())?;

		Ok(Chain {
			store: store,
			adapter: adapter,
			head: Arc::new(Mutex::new(head)),
			orphans: Arc::new(Mutex::new(VecDeque::with_capacity(MAX_ORPHANS + 1))),
			sumtrees: Arc::new(RwLock::new(sumtrees)),
			pow_verifier: pow_verifier,
		})
	}
/// Initializes the blockchain and returns a new Chain instance. Does a check
/// on the current chain head to make sure it exists and creates one based
/// on the genesis block if necessary.
Initializes the blockchain and returns a new Chain instance. Does a check
on the current chain head to make sure it exists and creates one based
on the genesis block if necessary.
Initializes the blockchain and returns a new Chain instance . Does a check on the current chain head to make sure it exists and creates one based on the genesis block if necessary .
pub fn init(
		db_root: String,
		adapter: Arc<ChainAdapter>,
		genesis: Block,
		pow_verifier: fn(&BlockHeader, u32) -> bool,
	) -> Result<Chain, Error> {
		let chain_store = store::ChainKVStore::new(db_root.clone())?;
		// check if we have a head in store, otherwise the genesis block is it
		let head = match chain_store.head() {
			Ok(tip) => tip,
			Err(NotFoundErr) => {
				let tip = Tip::new(genesis.hash());
				chain_store.save_block(&genesis)?;
				chain_store.setup_height(&genesis.header, &tip)?;
				// saving a new tip based on genesis
				chain_store.save_head(&tip)?;
				info!(
					LOGGER,
					"Saved genesis block: {:?}, nonce: {:?}, pow: {:?}",
					genesis.hash(),
					genesis.header.nonce,
					genesis.header.pow,
				);
				tip
			}
			Err(e) => return Err(Error::StoreErr(e, "chain init load head".to_owned())),
		};
		// make sure sync_head is available for later use
		let _ = match chain_store.get_sync_head() {
			Ok(tip) => tip,
			Err(NotFoundErr) => {
				let tip = chain_store.head().unwrap();
				chain_store.save_sync_head(&tip)?;
				tip
			},
			Err(e) => return Err(Error::StoreErr(e, "chain init sync head".to_owned())),
		};
		info!(
			LOGGER,
			"Chain init: {:?}",
			head,
		);
		let store = Arc::new(chain_store);
		let sumtrees = sumtree::SumTrees::open(db_root, store.clone())?;
		Ok(Chain {
			store: store,
			adapter: adapter,
			head: Arc::new(Mutex::new(head)),
			orphans: Arc::new(Mutex::new(VecDeque::with_capacity(MAX_ORPHANS + 1))),
			sumtrees: Arc::new(RwLock::new(sumtrees)),
			pow_verifier: pow_verifier,
		})
	}
pub fn init ( db_root : String , adapter : Arc < ChainAdapter > , genesis : Block , pow_verifier : fn ( & BlockHeader , u32 ) -> bool , ) -> Result < Chain , Error > { let chain_store = store :: ChainKVStore :: new ( db_root . clone ( ) ) ? ; // check if we have a head in store, otherwise the genesis block is it let head = match chain_store . head ( ) { Ok ( tip ) => tip , Err ( NotFoundErr ) => { let tip = Tip :: new ( genesis . hash ( ) ) ; chain_store . save_block ( & genesis ) ? ; chain_store . setup_height ( & genesis . header , & tip ) ? ; // saving a new tip based on genesis chain_store . save_head ( & tip ) ? ; info ! ( LOGGER " " genesis hash ( ) genesis header nonce genesis header pow ) ; tip } Err ( e ) => return Err ( Error :: StoreErr ( e , " " . to_owned ( ) ) ) , } ; // make sure sync_head is available for later use let _ = match chain_store . get_sync_head ( ) { Ok ( tip ) => tip , Err ( NotFoundErr ) => { let tip = chain_store . head ( ) . unwrap ( ) ; chain_store . save_sync_head ( & tip ) ? ; tip } , Err ( e ) => return Err ( Error :: StoreErr ( e , " " . to_owned ( ) ) ) , } ; info ! ( LOGGER " " head ) ; let store = Arc :: new ( chain_store ) ; let sumtrees = sumtree :: SumTrees :: open ( db_root , store . clone ( ) ) ? ; Ok ( Chain { store : store , adapter : adapter , head : Arc :: new ( Mutex :: new ( head ) ) , orphans : Arc :: new ( Mutex :: new ( VecDeque :: with_capacity ( MAX_ORPHANS + 1 ) ) ) , sumtrees : Arc :: new ( RwLock :: new ( sumtrees ) ) , pow_verifier : pow_verifier , } ) }
Initializes the blockchain and returns a new Chain instance.
Initializes the blockchain and returns a new Chain instance .
db_root
String
adapter
Arc<ChainAdapter>
genesis
Block
pow_verifier
fn(&BlockHeader, u32) -> bool