コード例 #1
0
    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,
        )
コード例 #2
0
ファイル: initialization.py プロジェクト: wschwab/trinity
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)
コード例 #3
0
ファイル: initialization.py プロジェクト: wschwab/trinity
def is_database_initialized(chaindb: ChainDatabaseAPI) -> bool:
    try:
        chaindb.get_canonical_head()
    except CanonicalHeadNotFound:
        # empty chain database
        return False
    else:
        return True
コード例 #4
0
ファイル: blocks.py プロジェクト: ygdmxy/py-evm
    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,
        )
コード例 #5
0
 def get_receipts(self,
                  chaindb: ChainDatabaseAPI) -> Tuple[ReceiptAPI, ...]:
     return chaindb.get_receipts(self.header, Receipt)
コード例 #6
0
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)