예제 #1
0
파일: chain.py 프로젝트: Aireed/pyethereum
 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()
예제 #2
0
파일: chain.py 프로젝트: vaizguy/pyethereum
 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()
예제 #3
0
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()
예제 #4
0
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()
예제 #5
0
파일: chain.py 프로젝트: Aireed/pyethereum
 def get(self, blockhash):
     assert is_string(blockhash)
     assert len(blockhash) == 32
     return blocks.get_block(self.env, blockhash)
예제 #6
0
파일: chain.py 프로젝트: Aireed/pyethereum
 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)
예제 #7
0
파일: chain.py 프로젝트: vaizguy/pyethereum
 def get(self, blockhash):
     assert is_string(blockhash)
     assert len(blockhash) == 32
     return blocks.get_block(self.blockchain, blockhash)
예제 #8
0
파일: chain.py 프로젝트: vaizguy/pyethereum
 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)
예제 #9
0
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)
예제 #10
0
def store_block(blk):
    blk.db.put(blk.hash, rlp.encode(blk))
    assert blocks.get_block(env(blk.db), blk.hash) == blk
예제 #11
0
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)
예제 #12
0
def store_block(blk):
    blk.db.put(blk.hash, rlp.encode(blk))
    assert blocks.get_block(env(blk.db), blk.hash) == blk
예제 #13
0
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)
예제 #14
0
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)