def initialize_database(chain_config: ChainConfig, chaindb: AsyncChainDB, base_db: BaseAtomicDB) -> None: try: chaindb.get_canonical_head() except CanonicalHeadNotFound: chain_config.initialize_chain(base_db)
def is_database_initialized(chaindb: AsyncChainDB) -> bool: try: chaindb.get_canonical_head() except CanonicalHeadNotFound: # empty chain database return False else: return True
def initialize_database(chain_config: ChainConfig, chaindb: AsyncChainDB) -> None: try: chaindb.get_canonical_head() except CanonicalHeadNotFound: if chain_config.network_id == ROPSTEN_NETWORK_ID: # We're starting with a fresh DB. chaindb.persist_header(ROPSTEN_GENESIS_HEADER) elif chain_config.network_id == MAINNET_NETWORK_ID: chaindb.persist_header(MAINNET_GENESIS_HEADER) else: # TODO: add genesis data to ChainConfig and if it's present, use it # here to initialize the chain. raise NotImplementedError( "Only the mainnet and ropsten chains are currently supported")