def _initialize_blockchain(self, genesis=None): log.info('Initializing new chain') if not genesis: genesis = blocks.genesis(self.env) log.info('new genesis', genesis_hash=genesis, difficulty=genesis.difficulty) self.index.add_block(genesis) self._store_block(genesis) assert genesis == blocks.get_block(self.env, genesis.hash) self._update_head(genesis) assert genesis.hash in self self.commit()
def _initialize_blockchain(self, genesis=None): log.info('Initializing new chain') if not genesis: genesis = blocks.genesis(self.blockchain, difficulty=blocks.GENESIS_DIFFICULTY) log.info('new genesis', genesis_hash=genesis, difficulty=genesis.difficulty) self.index.add_block(genesis) self._store_block(genesis) assert genesis == blocks.get_block(self.blockchain, genesis.hash) self._update_head(genesis) assert genesis.hash in self self.commit()
def test_mine_block_with_transaction2(db): k, v, k2, v2 = accounts() blk = mkquickgenesis({v: {"balance": utils.denoms.ether * 1}}, db) store_block(blk) tx = get_transaction() blk2 = mine_next_block(blk, coinbase=v, transactions=[tx]) assert tx in blk2.get_transactions() store_block(blk2) assert tx in blk2.get_transactions() assert blocks.get_block(env(blk2.db), blk2.hash) == blk2 assert tx.gasprice == 0 assert blk2.get_balance( v) == env(db).config['BLOCK_REWARD'] + blk.get_balance(v) - tx.value assert blk.state.db.db == blk2.state.db.db.db assert blk2.get_parent() == blk assert tx in blk2.get_transactions() assert tx not in blk.get_transactions()
def get(self, blockhash): assert is_string(blockhash) assert len(blockhash) == 32 return blocks.get_block(self.env, blockhash)
def head(self): if self.blockchain is None or 'HEAD' not in self.blockchain: self._initialize_blockchain() ptr = self.blockchain.get('HEAD') return blocks.get_block(self.env, ptr)
def get(self, blockhash): assert is_string(blockhash) assert len(blockhash) == 32 return blocks.get_block(self.blockchain, blockhash)
def head(self): if self.blockchain is None or 'HEAD' not in self.blockchain: self._initialize_blockchain() ptr = self.blockchain.get('HEAD') return blocks.get_block(self.blockchain, ptr)
def test_deserialize_commit(db): k, v, k2, v2 = accounts() blk = blocks.genesis(env(db)) db.put(blk.hash, rlp.encode(blk)) db.commit() assert blk == blocks.get_block(env(db), blk.hash)
def store_block(blk): blk.db.put(blk.hash, rlp.encode(blk)) assert blocks.get_block(env(blk.db), blk.hash) == blk
def test_deserialize(db): k, v, k2, v2 = accounts() blk = blocks.genesis(db) db.put(blk.hash, rlp.encode(blk)) assert blk == blocks.get_block(db, blk.hash)