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']) ) )
def serialize_transaction_receipt(block, transaction, transaction_index, is_pending): receipt = block.receipts[transaction_index] if transaction.to == b'': contract_addr = to_canonical_address(generate_contract_address( transaction.sender, transaction.nonce, )) else: contract_addr = None if transaction_index == 0: origin_gas = 0 else: origin_gas = receipt.gas_used - block.receipts[transaction_index - 1].gas_used return { "transaction_hash": transaction.hash, "transaction_index": None if is_pending else transaction_index, "block_number": None if is_pending else block.number, "block_hash": None if is_pending else block.hash, "cumulative_gas_used": receipt.gas_used, "gas_used": receipt.gas_used - origin_gas, "contract_address": contract_addr, "logs": [ serialize_log(block, transaction, transaction_index, log, log_index, is_pending) for log_index, log in enumerate(receipt.logs) ], }
def make_receipt(transaction, block, transaction_index, overrides=None): if overrides is None: overrides = {} if 'gas_used' in overrides: gas_used = overrides['gas_used'] else: gas_used = 21000 yield 'gas_used', gas_used if 'cumulative_gas_used' in overrides: yield 'cumulative_gas_used', overrides['cumulative_gas_used'] else: yield 'cumulative_gas_used', block['gas_used'] + gas_used if 'contract_address' in overrides: yield 'contract_address', overrides['contract_address'] else: contract_address = generate_contract_address(transaction['from'], transaction['nonce']) yield 'contract_address', contract_address if 'logs' in overrides: yield 'logs', overrides['logs'] else: yield 'logs', [] if 'transaction_hash' in overrides: yield 'transaction_hash', overrides['transaction_hash'] else: yield 'transaction_hash', transaction['hash']
def serialize_transaction_receipt(block, receipts, transaction, transaction_index, is_pending): receipt = receipts[transaction_index] _txn_type = _extract_transaction_type(transaction) state_root = receipt.state_root if transaction.to == b'': contract_addr = generate_contract_address( transaction.sender, transaction.nonce, ) else: contract_addr = None if transaction_index == 0: origin_gas = 0 else: origin_gas = receipts[transaction_index - 1].gas_used return { "block_hash": None if is_pending else block.hash, "block_number": None if is_pending else block.number, "contract_address": contract_addr, "cumulative_gas_used": receipt.gas_used, "effective_gas_price": _calculate_effective_gas_price(transaction, block, _txn_type), "from": transaction.sender, "gas_used": receipt.gas_used - origin_gas, "logs": [ serialize_log(block, transaction, transaction_index, log, log_index, is_pending) for log_index, log in enumerate(receipt.logs) ], 'state_root': state_root, "status": to_int(state_root), "to": transaction.to, "transaction_hash": transaction.hash, "transaction_index": None if is_pending else transaction_index, 'type': _txn_type, }