Chain

ChainDB

class eth.db.chain.ChainDB(db: eth.abc.AtomicDatabaseAPI)
add_receipt(block_header: eth.abc.BlockHeaderAPI, index_key: int, receipt: eth.abc.ReceiptAPI) → NewType.<locals>.new_type

Add the given receipt to the provided block header.

Return the updated receipts_root for updated block header.

add_transaction(block_header: eth.abc.BlockHeaderAPI, index_key: int, transaction: eth.abc.SignedTransactionAPI) → NewType.<locals>.new_type

Add the given transaction to the provided block header.

Return the updated transactions_root for updated block header.

exists(key: bytes) → bool

Return True if the given key exists in the database.

get(key: bytes) → bytes

Return the value for the given key or a KeyError if it doesn’t exist in the database.

get_block_transaction_hashes(block_header: eth.abc.BlockHeaderAPI) → Tuple[NewType.<locals>.new_type, ...]

Returns an iterable of the transaction hashes from the block specified by the given block header.

get_block_transactions(header: eth.abc.BlockHeaderAPI, transaction_decoder: Type[eth.abc.TransactionDecoderAPI]) → Tuple[eth.abc.SignedTransactionAPI, ...]

Return an iterable of transactions for the block speficied by the given block header.

get_block_uncles(uncles_hash: NewType.<locals>.new_type) → Tuple[eth.abc.BlockHeaderAPI, ...]

Return an iterable of uncle headers specified by the given uncles_hash

get_receipt_by_index(block_number: NewType.<locals>.new_type, receipt_index: int, receipt_decoder: Type[eth.abc.ReceiptDecoderAPI]) → eth.abc.ReceiptAPI

Return the receipt of the transaction at specified index for the block header obtained by the specified block number

get_receipts(header: eth.abc.BlockHeaderAPI, receipt_decoder: Type[eth.abc.ReceiptDecoderAPI]) → Iterable[eth.abc.ReceiptAPI]

Return a tuple of receipts for the block specified by the given block header.

get_transaction_by_index(block_number: NewType.<locals>.new_type, transaction_index: int, transaction_decoder: Type[eth.abc.TransactionDecoderAPI]) → eth.abc.SignedTransactionAPI

Return the transaction at the specified transaction_index from the block specified by block_number from the canonical chain.

Raise TransactionNotFound if no block with that block_number exists.

get_transaction_index(transaction_hash: NewType.<locals>.new_type) → Tuple[NewType.<locals>.new_type, int]

Return a 2-tuple of (block_number, transaction_index) indicating which block the given transaction can be found in and at what index in the block transactions.

Raise TransactionNotFound if the transaction_hash is not found in the canonical chain.

persist_block(block: eth.abc.BlockAPI, genesis_parent_hash: NewType.<locals>.new_type = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') → Tuple[Tuple[NewType.<locals>.new_type, ...], Tuple[NewType.<locals>.new_type, ...]]

Persist the given block’s header and uncles.

Parameters:
  • block – the block that gets persisted
  • genesis_parent_hashoptional parent hash of the header that is treated as genesis. Providing a genesis_parent_hash allows storage of blocks that aren’t (yet) connected back to the true genesis header.

Warning

This API assumes all block transactions have been persisted already. Use eth.abc.ChainDatabaseAPI.persist_unexecuted_block() to persist blocks that were not executed.

persist_trie_data_dict(trie_data_dict: Dict[NewType.<locals>.new_type, bytes]) → None

Store raw trie data to db from a dict

persist_uncles(uncles: Tuple[eth.abc.BlockHeaderAPI]) → NewType.<locals>.new_type

Persist the list of uncles to the database.

Return the uncles hash.

persist_unexecuted_block(block: eth.abc.BlockAPI, receipts: Tuple[eth.abc.ReceiptAPI, ...], genesis_parent_hash: NewType.<locals>.new_type = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') → Tuple[Tuple[NewType.<locals>.new_type, ...], Tuple[NewType.<locals>.new_type, ...]]

Persist the given block’s header, uncles, transactions, and receipts. Does not validate if state transitions are valid.

Parameters:
  • block – the block that gets persisted
  • receipts – the receipts for the given block
  • genesis_parent_hashoptional parent hash of the header that is treated as genesis. Providing a genesis_parent_hash allows storage of blocks that aren’t (yet) connected back to the true genesis header.

This API should be used to persist blocks that the EVM does not execute but which it stores to make them available. It ensures to persist receipts and transactions which eth.abc.ChainDatabaseAPI.persist_block() in contrast assumes to be persisted separately.