Exemple #1
0
def make_receipt(transaction, block, _transaction_index, overrides=None):
    if overrides is None:
        overrides = {}

    gas_used = overrides.get('gas_used', 21000)
    yield 'gas_used', gas_used
    yield 'logs', overrides.get('logs', [])
    yield 'transaction_hash', overrides.get('transaction_hash', transaction.get('hash'))
    yield (
        'cumulative_gas_used',
        overrides.get('cumulative_gas_used', block.get('gas_used') + gas_used)
    )
    yield (
        'effective_gas_price',
        overrides.get('effective_gas_price', calculate_effective_gas_price(transaction, block))
    )
    yield (
        'type',
        overrides.get('type', transaction.get('type', extract_transaction_type(transaction)))
    )
    yield (
        'contract_address',
        overrides.get(
            'contract_address',
            generate_contract_address(transaction['from'], transaction['nonce'])
        )
    )
Exemple #2
0
def serialize_full_transaction(transaction, block, transaction_index,
                               is_pending):
    if is_pending:
        block_number = None
        block_hash = None
        transaction_index = None
    else:
        block_number = block['number']
        block_hash = block['hash']

    serialized_transaction = pipe(
        transaction, partial(assoc, key='block_number', value=block_number),
        partial(assoc, key='block_hash', value=block_hash),
        partial(assoc, key='transaction_index', value=transaction_index),
        partial(assoc, key='type',
                value=extract_transaction_type(transaction)))

    if 'gas_price' in transaction:
        return serialized_transaction
    else:
        # TODO: Sometime in 2022 the inclusion of gas_price may be removed from dynamic fee
        #  transactions and we can get rid of this behavior.
        #  https://github.com/ethereum/execution-specs/pull/251
        gas_price = (transaction['max_fee_per_gas'] if is_pending else
                     calculate_effective_gas_price(transaction, block))
        return assoc(serialized_transaction, 'gas_price', gas_price)
Exemple #3
0
    def _normalize_pending_transaction(pending_transaction):
        """
        Add the transaction type and, if a dynamic fee transaction, add gas_price =
        max_fee_per_gas as highlighted in the execution-specs link below.
        """
        _type = extract_transaction_type(pending_transaction)
        pending_transaction = assoc(pending_transaction, 'type', _type)

        # TODO: Sometime in 2022 the inclusion of gas_price may be removed from dynamic fee
        #  transactions and we can get rid of this behavior.
        #  https://github.com/ethereum/execution-specs/pull/251
        # add gas_price = max_fee_per_gas to pending dynamic fee transactions
        if _type == '0x2':
            pending_transaction = assoc(pending_transaction, 'gas_price',
                                        pending_transaction['max_fee_per_gas'])
        return pending_transaction
Exemple #4
0
def serialize_receipt(receipt, transaction, block, transaction_index,
                      is_pending):
    if is_pending:
        block_number = None
        block_hash = None
        transaction_index = None
    else:
        block_number = block['number']
        block_hash = block['hash']

    return pipe(
        receipt, partial(assoc, key='block_number', value=block_number),
        partial(assoc, key='block_hash', value=block_hash),
        partial(assoc, key='transaction_index', value=transaction_index),
        partial(assoc, key='state_root', value=b'\x00'),
        partial(assoc,
                key='effective_gas_price',
                value=(calculate_effective_gas_price(transaction, block))),
        partial(assoc, key='type',
                value=extract_transaction_type(transaction)))