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 to_block(self, env, parent=None): """Convert the transient block to a :class:`ethereum.blocks.Block`""" return Block(self.header, self.transaction_list, self.uncles, env=env, parent=parent)
def __init__(self): env = Env(DB()) header = BlockHeader(difficulty=DIFFICULTY) self.head_candidate = Block(header, env=env)