def __init__(self, block_data, newblock_timestamp=0): self.newblock_timestamp = newblock_timestamp self.header = BlockHeader.deserialize(block_data[0]) self.transaction_list = rlp.sedes.CountableList( Transaction).deserialize(block_data[1]) self.uncles = rlp.sedes.CountableList(BlockHeader).deserialize( block_data[2])
def new_block(block, use_parent=True): """Create a new block based on a parent block. The block will not include any transactions and will not be finalized. """ parent = block.get_parent() header = BlockHeader(prevhash=parent.hash, uncles_hash=utils.sha3(rlp.encode([])), coinbase=block.coinbase, state_root=parent.state_root if use_parent else block.state_root, tx_list_root=trie.BLANK_ROOT, receipts_root=trie.BLANK_ROOT, bloom=0, difficulty=block.difficulty, mixhash='', number=parent.number + 1, gas_limit=block.gas_limit, gas_used=0, timestamp=block.timestamp, extra_data=block.extra_data, nonce=b'') block = Block(header, [], [], env=parent.env if use_parent else block.env, parent=parent, making=True) block.ancestor_hashes = [parent.hash] + parent.ancestor_hashes block.log_listeners = parent.log_listeners return block
def decode_payload(cls, rlp_data): # fn = 'blocks.fromthewire.hex.rlp' # open(fn, 'a').write(rlp_data.encode('hex') + '\n') # convert to dict blockheaders = [] for blockheader in rlp.decode_lazy(rlp_data): blockheaders.append(BlockHeader(blockheader)) return blockheaders
def test_export(): # requires a chain with at least 5 blocks assert subprocess.call('pyethapp export', shell=True) != 0 assert subprocess.call('pyethapp export --from -1 -', shell=True) != 0 assert subprocess.call('pyethapp export --to -3 -', shell=True) != 0 assert subprocess.call('pyethapp export --from 4 --to 2 -', shell=True) != 0 result = subprocess.Popen('pyethapp export --from 2 --to 4 -', shell=True, stdout=subprocess.PIPE) result.wait() assert result.returncode == 0 s = result.stdout.read() headers = [] end = 0 while end < len(s): item, end = rlp.codec.consume_item(s, end) headers.append(BlockHeader.deserialize(item[0])) assert [header.number for header in headers] == [2, 3, 4]
def __init__(self, block_data): self.header = BlockHeader.deserialize(block_data[0]) self.transaction_list = block_data[1] self.uncles = block_data[2]
def __init__(self, block_data, newblock_timestamp=0): self.newblock_timestamp = newblock_timestamp self.header = BlockHeader.deserialize(block_data[0]) self.transaction_list = rlp.sedes.CountableList(Transaction).deserialize(block_data[1]) self.uncles = rlp.sedes.CountableList(BlockHeader).deserialize(block_data[2])
def __init__(self): env = Env(DB()) header = BlockHeader(difficulty=DIFFICULTY) self.head_candidate = Block(header, env=env)