Пример #1
0
    async def getTransactionReceipt(self,
                                    transaction_hash: Hash32) -> RpcReceiptResponse:

        try:
            tx_block_number, tx_index = await self.chain.coro_get_canonical_transaction_index(
                transaction_hash,
            )
        except TransactionNotFound as exc:
            raise RpcError(
                f"Transaction {encode_hex(transaction_hash)} is not in the canonical chain"
            ) from exc

        try:
            block_header = await self.chain.coro_get_canonical_block_header_by_number(
                tx_block_number
            )
        except HeaderNotFound as exc:
            raise RpcError(
                f"Block {tx_block_number} is not in the canonical chain"
            ) from exc

        try:
            transaction = await self.chain.coro_get_canonical_transaction_by_index(
                tx_block_number,
                tx_index
            )
        except TransactionNotFound as exc:
            raise RpcError(
                f"Transaction {encode_hex(transaction_hash)} is not in the canonical chain"
            ) from exc

        if transaction.hash != transaction_hash:
            raise RpcError(
                f"Unexpected transaction {encode_hex(transaction.hash)} at index {tx_index}"
            )

        receipt = await self.chain.coro_get_transaction_receipt_by_index(
            tx_block_number,
            tx_index
        )

        if tx_index > 0:
            previous_receipt = await self.chain.coro_get_transaction_receipt_by_index(
                tx_block_number,
                tx_index - 1
            )
            # The receipt only tells us the cumulative gas that was used. To find the gas used by
            # the transaction alone we have to get the previous receipt and calculate the
            # difference.
            tx_gas_used = receipt.gas_used - previous_receipt.gas_used
        else:
            tx_gas_used = receipt.gas_used

        return to_receipt_response(receipt, transaction, tx_index, block_header, tx_gas_used)
Пример #2
0
    async def sendRawTransaction(self,
                                 transaction: SignedTransactionAPI) -> HexStr:

        validator = DefaultTransactionValidator.from_network_id(
            self.chain,
            self.trinity_config.network_id,
        )

        try:
            validator.validate(transaction)
        except ValidationError as err:
            raise RpcError(err) from err
        else:
            await self.event_bus.broadcast(SendLocalTransaction(transaction))
            return encode_hex(transaction.hash)
Пример #3
0
    async def sendRawTransaction(self, transaction_bytes: bytes) -> HexStr:

        serialized_txn = rlp.decode(transaction_bytes)
        # TODO on pyevm upgrade, switch to:
        # transaction_builder = self.chain.get_vm().get_transaction_builder()
        # transaction = transaction_builder.decode(transaction_bytes)

        validator = DefaultTransactionValidator.from_network_id(
            self.chain,
            self.trinity_config.network_id,
        )

        try:
            transaction = validator.validate(serialized_txn)
        except ValidationError as err:
            raise RpcError(err) from err
        else:
            await self.event_bus.broadcast(SendLocalTransaction(transaction))
            return encode_hex(transaction.hash)