def from_header(cls, header: BlockHeaderAPI, chaindb: ChainDatabaseAPI) -> "FrontierBlock": """ Returns the block denoted by the given block header. :raise eth.exceptions.BlockNotFound: if transactions or uncle headers are missing """ if header.uncles_hash == EMPTY_UNCLE_HASH: uncles: Tuple[BlockHeader, ...] = () else: try: uncles = chaindb.get_block_uncles(header.uncles_hash) except HeaderNotFound as exc: raise BlockNotFound( f"Uncles not found in database for {header}: {exc}" ) from exc try: transactions = chaindb.get_block_transactions( header, cls.get_transaction_class()) except MissingTrieNode as exc: raise BlockNotFound( f"Transactions not found in database for {header}: {exc}" ) from exc return cls( header=header, transactions=transactions, uncles=uncles, )
def initialize_database(chain_config: Eth1ChainConfig, chaindb: ChainDatabaseAPI, base_db: AtomicDatabaseAPI) -> None: try: chaindb.get_canonical_head() except CanonicalHeadNotFound: chain_config.initialize_chain(base_db)
def is_database_initialized(chaindb: ChainDatabaseAPI) -> bool: try: chaindb.get_canonical_head() except CanonicalHeadNotFound: # empty chain database return False else: return True
def from_header(cls, header: BlockHeaderAPI, chaindb: ChainDatabaseAPI) -> "FrontierBlock": """ Returns the block denoted by the given block header. """ if header.uncles_hash == EMPTY_UNCLE_HASH: uncles: Tuple[BlockHeader, ...] = () else: uncles = chaindb.get_block_uncles(header.uncles_hash) transactions = chaindb.get_block_transactions(header, cls.get_transaction_class()) return cls( header=header, transactions=transactions, uncles=uncles, )
def get_receipts(self, chaindb: ChainDatabaseAPI) -> Tuple[ReceiptAPI, ...]: return chaindb.get_receipts(self.header, Receipt)
def get_block_header_by_hash(block_hash: Hash32, db: ChainDatabaseAPI) -> BlockHeaderAPI: """ Returns the header for the parent block. """ return db.get_block_header_by_hash(block_hash)