예제 #1
0
    def get_receipt_by_index(self,
                             block_number: BlockNumber,
                             receipt_index: int) -> ReceiptAPI:
        try:
            block_header = self.get_canonical_block_header_by_number(block_number)
        except HeaderNotFound:
            raise ReceiptNotFound(f"Block {block_number} is not in the canonical chain")

        receipt_db = HexaryTrie(db=self.db, root_hash=block_header.receipt_root)
        receipt_key = rlp.encode(receipt_index)
        receipt_data = receipt_db[receipt_key]
        if receipt_data != b'':
            return rlp.decode(receipt_data, sedes=Receipt)
        else:
            raise ReceiptNotFound(
                f"Receipt with index {receipt_index} not found in block"
            )
예제 #2
0
파일: chain.py 프로젝트: nairobi222/py-evm
    def get_receipt_by_index(self,
                             block_number: BlockNumber,
                             receipt_index: int) -> Receipt:
        """
        Returns the Receipt of the transaction at specified index
        for the block header obtained by the specified block number
        """
        try:
            block_header = self.get_canonical_block_header_by_number(block_number)
        except HeaderNotFound:
            raise ReceiptNotFound("Block {} is not in the canonical chain".format(block_number))

        receipt_db = HexaryTrie(db=self.db, root_hash=block_header.receipt_root)
        receipt_key = rlp.encode(receipt_index)
        if receipt_key in receipt_db:
            receipt_data = receipt_db[receipt_key]
            return rlp.decode(receipt_data, sedes=Receipt)
        else:
            raise ReceiptNotFound(
                "Receipt with index {} not found in block".format(receipt_index))