def eth_getBlockByNumber(block_number, full_tx): block_number = format_block_number(block_number) #if block_number >= len( block = evm.blocks[block_number] return { "number": "0x" + int_to_hex(block.number), "hash": "0x" + encode_hex(block.hash), "parentHash": "0x" + encode_hex(block.prevhash), "nonce": "0x" + encode_hex(block.nonce), "sha3Uncles": "0x" + encode_hex(block.uncles_hash), # TODO logsBloom / padding "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "transactionsRoot": "0x" + encode_hex(block.tx_list_root), "stateRoot": "0x" + encode_hex(block.state_root), "miner": "0x" + encode_hex(block.coinbase), "difficulty": "0x" + int_to_hex(block.difficulty), # https://github.com/ethereum/pyethereum/issues/266 # "totalDifficulty": "0x" + int_to_hex(block.chain_difficulty()), "size": "0x" + int_to_hex(len(rlp.encode(block))), "extraData": "0x" + encode_hex(block.extra_data), "gasLimit": "0x" + int_to_hex(block.gas_limit), "gasUsed": "0x" + int_to_hex(block.gas_used), "timestamp": "0x" + int_to_hex(block.timestamp), "transactions": jsonTxs(block.get_transactions()) if full_tx else [encode_hex(tx) for tx in block.get_transaction_hashes()], "uncles": block.uncles }
def test_long(): state = s.snapshot() print 'Testing add_old' contract.add_recent(len(s.blocks) - 2) for i in range(len(s.blocks) - 2)[::-1]: header = s.blocks[i].header contract.add_old(rlp.encode(s.blocks[i + 1].header), i) print 'gas used', s.block.gas_used - (len(s.blocks) - 1) * TX_BASE_GAS print 'average:', s.block.gas_used / (len(s.blocks) - 1.) - TX_BASE_GAS check_storage() s.revert(state)
def test_long(): state = s.snapshot() print 'Testing add_old' contract.add_recent(len(s.blocks)-2) for i in range(len(s.blocks) - 2)[::-1]: header = s.blocks[i].header contract.add_old(rlp.encode(s.blocks[i+1].header), i) print 'gas used', s.block.gas_used - (len(s.blocks)-1) * TX_BASE_GAS print 'average:', s.block.gas_used / (len(s.blocks)-1.) - TX_BASE_GAS check_storage() s.revert(state)
def eth_getBlockByNumber(block_number, full_tx): block_number = format_block_number(block_number) block = evm.blocks[block_number] return { "number": "0x" + int_to_hex(block.number), "hash": "0x" + block.hash.encode('hex'), "parentHash": "0x" + block.prevhash.encode('hex'), "nonce": "0x" + block.nonce.encode('hex'), "sha3Uncles": "0x" + block.uncles_hash.encode('hex'), # TODO logsBloom / padding "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "transactionsRoot": "0x" + block.tx_list_root.encode('hex'), "stateRoot": "0x" + block.state_root.encode('hex'), "miner": "0x" + block.coinbase.encode('hex'), "difficulty": "0x" + int_to_hex(block.difficulty), # https://github.com/ethereum/pyethereum/issues/266 # "totalDifficulty": "0x" + int_to_hex(block.chain_difficulty()), "size": "0x" + int_to_hex(len(rlp.encode(block))), "extraData": "0x" + block.extra_data.encode('hex'), "gasLimit": "0x" + int_to_hex(block.gas_limit), "gasUsed": "0x" + int_to_hex(block.gas_used), "timestamp": "0x" + int_to_hex(block.timestamp), "transactions": block.get_transactions() if full_tx else block.get_transaction_hashes(), "uncles": block.uncles }