Chain
ChainDB
- class eth.db.chain.ChainDB(db: AtomicDatabaseAPI)
- add_receipt(block_header: BlockHeaderAPI, index_key: int, receipt: ReceiptAPI) Hash32
Add the given receipt to the provided block header.
Return the updated receipts_root for updated block header.
- add_transaction(block_header: BlockHeaderAPI, index_key: int, transaction: SignedTransactionAPI) Hash32
Add the given transaction to the provided block header.
Return the updated transactions_root for updated block header.
- 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: BlockHeaderAPI) Tuple[Hash32, ...]
Returns an iterable of the transaction hashes from the block specified by the given block header.
- get_block_transactions(header: BlockHeaderAPI, transaction_decoder: Type[TransactionDecoderAPI]) Tuple[SignedTransactionAPI, ...]
Return an iterable of transactions for the block speficied by the given block header.
- get_block_uncles(uncles_hash: Hash32) Tuple[BlockHeaderAPI, ...]
Return an iterable of uncle headers specified by the given
uncles_hash
- get_block_withdrawals(header: BlockHeaderAPI) Tuple[WithdrawalAPI, ...]
Return an iterable of withdrawals for the block specified by the given block header.
- get_receipt_by_index(block_number: BlockNumber, receipt_index: int, receipt_decoder: Type[ReceiptDecoderAPI]) ReceiptAPI
Return the receipt of the transaction at specified index for the block header obtained by the specified block number
- get_receipts(header: BlockHeaderAPI, receipt_decoder: Type[ReceiptDecoderAPI]) Iterable[ReceiptAPI]
Return a tuple of receipts for the block specified by the given block header.
- get_transaction_by_index(block_number: BlockNumber, transaction_index: int, transaction_decoder: Type[TransactionDecoderAPI]) 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 thatblock_number
exists.
- get_transaction_index(transaction_hash: Hash32) Tuple[BlockNumber, 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: BlockAPI, genesis_parent_hash: Hash32 = 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[Hash32, ...], Tuple[Hash32, ...]]
Persist the given block’s header and uncles.
- Parameters:
block – the block that gets persisted
genesis_parent_hash – optional 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[Hash32, bytes]) None
Store raw trie data to db from a dict
- persist_uncles(uncles: Tuple[BlockHeaderAPI]) Hash32
Persist the list of uncles to the database.
Return the uncles hash.
- persist_unexecuted_block(block: BlockAPI, receipts: Tuple[ReceiptAPI, ...], genesis_parent_hash: Hash32 = 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[Hash32, ...], Tuple[Hash32, ...]]
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_hash – optional 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.