示例#1
0
def serialize_block(block, transaction_serialize_fn, is_pending):
    transactions = [
        transaction_serialize_fn(block, transaction, transaction_index,
                                 is_pending)
        for transaction_index, transaction in enumerate(block.transaction_list)
    ]

    return {
        "number": block.number,
        "hash": block.hash,
        "parent_hash": block.prevhash,
        "nonce": zpad(block.nonce, 8),
        "sha3_uncles": block.uncles_hash,
        "logs_bloom": block.bloom,
        "transactions_root": block.tx_list_root,
        "receipts_root": block.receipts_root,
        "state_root": block.state_root,
        "miner": block.coinbase,
        "difficulty": block.difficulty,
        "total_difficulty": block.chain_difficulty(),
        "size": len(rlp.encode(block)),
        "extra_data": zpad32(block.extra_data),
        "gas_limit": block.gas_limit,
        "gas_used": block.gas_used,
        "timestamp": block.timestamp,
        "transactions": transactions,
        "uncles": block.uncles,
    }
示例#2
0
def serialize_block(evm, block, transaction_serialize_fn, is_pending):
    transactions = [
        transaction_serialize_fn(block, transaction, transaction_index,
                                 is_pending) for transaction_index, transaction
        in enumerate(block.transactions if is_pyethereum21_available(
        ) else block.transaction_list)
    ]

    # NOTE: Hack to compute total difficulty for pyethereum 2.0
    #       As far as I could tell, this didn't really do anything in 1.6
    if hasattr(block, 'chain_difficulty'):
        total_difficulty = block.chain_difficulty()
    elif hasattr(evm, 'chain') and hasattr(evm.chain, 'get_score'):
        total_difficulty = evm.chain.get_score(block)
    else:
        raise Exception(
            'Invariant: failed to match pyethereum16 or pyethereum21 API')

    return {
        "number":
        block.number,
        "hash":
        block.hash,
        "parent_hash":
        block.prevhash,
        "nonce":
        zpad(encode_if_not_bytes(block.nonce), 8),
        "sha3_uncles":
        block.uncles_hash,
        "logs_bloom":
        block.bloom,
        "transactions_root":
        block.tx_list_root,
        "receipts_root":
        block.receipts_root,
        "state_root":
        block.state_root,
        "miner":
        block.coinbase
        if is_bytes(block.coinbase) else block.coinbase.encode(),
        "difficulty":
        block.difficulty,
        "total_difficulty":
        total_difficulty,
        "size":
        len(rlp.encode(block)),
        "extra_data":
        zpad32(encode_if_not_bytes(block.extra_data)),
        "gas_limit":
        block.gas_limit,
        "gas_used":
        block.gas_used,
        "timestamp":
        block.timestamp,
        "transactions":
        transactions,
        "uncles":
        block.uncles,
    }
示例#3
0
def _generate_dummy_address(idx):
    return to_canonical_address(
        decode_hex('0xabbacadaba') + zpad(int_to_big_endian(idx), 15))