Beispiel #1
0
def _make_frontier_receipt(vm_state, transaction, computation):
    # Reusable for other forks

    logs = [
        Log(address, topics, data)
        for address, topics, data
        in computation.get_log_entries()
    ]

    gas_remaining = computation.get_gas_remaining()
    gas_refund = computation.get_gas_refund()
    tx_gas_used = (
        transaction.gas - gas_remaining
    ) - min(
        gas_refund,
        (transaction.gas - gas_remaining) // 2,
    )

    gas_used = vm_state.block_header.gas_used + tx_gas_used

    receipt = Receipt(
        state_root=vm_state.block_header.state_root,
        gas_used=gas_used,
        logs=logs,
    )

    return receipt
Beispiel #2
0
def hash_log_entries(log_entries):
    """
    Helper function for computing the RLP hash of the logs from transaction
    execution.
    """
    from evm.rlp.logs import Log
    logs = [Log(*entry) for entry in log_entries]
    encoded_logs = rlp.encode(logs)
    logs_hash = keccak(encoded_logs)
    return logs_hash
Beispiel #3
0
    def add_transaction(self, transaction, computation):
        logs = [
            Log(address, topics, data)
            for address, topics, data
            in computation.get_log_entries()
        ]

        if computation.error:
            tx_gas_used = transaction.gas
        else:
            gas_remaining = computation.get_gas_remaining()
            gas_refund = computation.get_gas_refund()
            tx_gas_used = (
                transaction.gas - gas_remaining
            ) - min(
                gas_refund,
                (transaction.gas - gas_remaining) // 2,
            )

        gas_used = self.header.gas_used + tx_gas_used

        receipt = Receipt(
            state_root=computation.state_db.root_hash,
            gas_used=gas_used,
            logs=logs,
        )

        transaction_idx = len(self.transactions)

        index_key = rlp.encode(transaction_idx, sedes=rlp.sedes.big_endian_int)

        self.transactions.append(transaction)

        self.transaction_db[index_key] = rlp.encode(transaction)
        self.receipt_db[index_key] = rlp.encode(receipt)

        self.bloom_filter |= receipt.bloom

        self.header.transaction_root = self.transaction_db.root_hash
        self.header.state_root = computation.state_db.root_hash
        self.header.receipt_root = self.receipt_db.root_hash
        self.header.bloom = int(self.bloom_filter)
        self.header.gas_used = gas_used

        return self
Beispiel #4
0
    def make_receipt(self, transaction, computation):
        logs = [
            Log(address, topics, data)
            for address, topics, data in computation.get_log_entries()
        ]

        gas_remaining = computation.get_gas_remaining()
        gas_refund = computation.get_gas_refund()
        tx_gas_used = (transaction.gas - gas_remaining) - min(
            gas_refund,
            (transaction.gas - gas_remaining) // 2,
        )

        gas_used = self.header.gas_used + tx_gas_used

        receipt = Receipt(
            state_root=self.header.state_root,
            gas_used=gas_used,
            logs=logs,
        )
        return receipt