def test_mining_one_block_one_miner(self):
     # block chain size is set to 5
     miner_node = Miner()
     user_node1 = Client()
     user_node2 = Client()
     user_node3 = Client()
     tx1 = user_node1.generate_tx(
         [(user_node2.public_key, 5)],
         user_node1.get_random_input().get_transaction_hash(), 1)
     miner_node.add_transaction(tx1)
     tx2 = user_node1.generate_tx(
         [(user_node3.public_key, 5)],
         user_node1.get_random_input().get_transaction_hash(), 1)
     miner_node.add_transaction(tx2)
     tx3 = user_node2.generate_tx(
         [(user_node3.public_key, 5)],
         user_node2.get_random_input().get_transaction_hash(), 1)
     miner_node.add_transaction(tx3)
     tx4 = user_node2.generate_tx(
         [(user_node1.public_key, 5)],
         user_node2.get_random_input().get_transaction_hash(), 1)
     miner_node.add_transaction(tx4)
     tx5 = user_node3.generate_tx(
         [(user_node1.public_key, 5)],
         user_node3.get_random_input().get_transaction_hash(), 1)
     miner_node.add_transaction(tx5)
     self.assertTrue(miner_node.is_mining())
コード例 #2
0
ファイル: chainmanager.py プロジェクト: ckeenan/pyethereum
    def new_miner(self):
        "new miner is initialized if HEAD is updated"
        # prepare uncles
        uncles = set(self.get_uncles(self.head))
        ineligible = set()  # hashes
        blk = self.head
        for i in range(8):
            for u in blk.uncles:  # assuming uncle headers
                u = utils.sha3(rlp.encode(u))
                if u in self:
                    uncles.discard(self.get(u))
            if blk.has_parent():
                blk = blk.get_parent()

        miner = Miner(self.head, uncles, self.config.get('wallet', 'coinbase'))
        if self.miner:
            for tx in self.miner.get_transactions():
                miner.add_transaction(tx)
        self.miner = miner
コード例 #3
0
    def new_miner(self):
        "new miner is initialized if HEAD is updated"
        # prepare uncles
        uncles = set(self.get_uncles(self.head))
        ineligible = set()  # hashes
        blk = self.head
        for i in range(8):
            for u in blk.uncles:  # assuming uncle headers
                u = utils.sha3(rlp.encode(u))
                if u in self:
                    uncles.discard(self.get(u))
            if blk.has_parent():
                blk = blk.get_parent()

        miner = Miner(self.head, uncles, self.config.get('wallet', 'coinbase'))
        if self.miner:
            for tx in self.miner.get_transactions():
                miner.add_transaction(tx)
        self.miner = miner
コード例 #4
0
ファイル: chainmanager.py プロジェクト: csbitcoin/pyethereum
    def new_miner(self):
        "new miner is initialized if HEAD is updated"
        # prepare uncles
        uncles = set(self.get_uncles(self.head))
#        logger.debug('%d uncles for next block %r', len(uncles), uncles)
        ineligible = set() # hashes
        blk = self.head
        for i in range(8):
            for u in blk.uncles: # assuming uncle headres
                u = utils.sha3(rlp.encode(u))
                if u in self:
#                    logger.debug('ineligible uncle %r', u.encode('hex'))
                    uncles.discard(self.get(u))
            if blk.has_parent():
                blk = blk.get_parent()
#        logger.debug('%d uncles after filtering %r', len(uncles), uncles)

        miner = Miner(self.head, uncles, self.config.get('wallet', 'coinbase'))
        if self.miner:
            for tx in self.miner.get_transactions():
                miner.add_transaction(tx)
        self.miner = miner
コード例 #5
0
ファイル: chainmanager.py プロジェクト: CJentzsch/pyethereum
    def new_miner(self):
        "new miner is initialized if HEAD is updated"
        # prepare uncles
        uncles = set(self.get_uncles(self.head))
        #        logger.debug('%d uncles for next block %r', len(uncles), uncles)
        ineligible = set()  # hashes
        blk = self.head
        for i in range(8):
            for u in blk.uncles:  # assuming uncle headres
                u = utils.sha3(rlp.encode(u))
                if u in self:
                    #                    logger.debug('ineligible uncle %r', u.encode('hex'))
                    uncles.discard(self.get(u))
            if blk.has_parent():
                blk = blk.get_parent()


#        logger.debug('%d uncles after filtering %r', len(uncles), uncles)

        miner = Miner(self.head, uncles, self.config.get('wallet', 'coinbase'))
        if self.miner:
            for tx in self.miner.get_transactions():
                miner.add_transaction(tx)
        self.miner = miner