当前位置: 首页>>代码示例>>Python>>正文


Python blocktools.create_coinbase函数代码示例

本文整理汇总了Python中test_framework.blocktools.create_coinbase函数的典型用法代码示例。如果您正苦于以下问题:Python create_coinbase函数的具体用法?Python create_coinbase怎么用?Python create_coinbase使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了create_coinbase函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_test_instance

    def generate_test_instance(self, pubkeystring, scriptsigstring):
        scriptpubkey = ParseScript(pubkeystring)
        scriptsig = ParseScript(scriptsigstring)

        test = TestInstance(sync_every_block=False)
        test_build = TestBuilder()
        test_build.create_credit_tx(scriptpubkey)
        test_build.create_spend_tx(scriptsig)
        test_build.rehash()

        block = create_block(self.tip, test_build.tx1, self.block_time)
        self.block_time += 1
        block.solve()
        self.tip = block.sha256
        test.blocks_and_transactions = [[block, True]]

        for i in xrange(100):
            block = create_block(self.tip, create_coinbase(), self.block_time)
            self.block_time += 1
            block.solve()
            self.tip = block.sha256
            test.blocks_and_transactions.append([block, True])

        block = create_block(self.tip, create_coinbase(), self.block_time)
        self.block_time += 1
        block.vtx.append(test_build.tx2)
        block.hashMerkleRoot = block.calc_merkle_root()
        block.rehash()
        block.solve()
        test.blocks_and_transactions.append([block, None])
        return test   
开发者ID:Whiteblock,项目名称:zcash,代码行数:31,代码来源:script_test.py

示例2: run_test

    def run_test(self):

        # First, quick check that CSV is ACTIVE at genesis
        assert_equal(self.nodes[0].getblockcount(), 0)
        assert_equal(get_bip9_status(self.nodes[0], 'csv')['status'], 'active')

        self.nodes[0].add_p2p_connection(P2PInterface())

        self.nodeaddress = self.nodes[0].getnewaddress()

        self.log.info("Test that blocks past the genesis block must be at least version 4")

        # Create a v3 block
        tip = self.nodes[0].getbestblockhash()
        block_time = self.nodes[0].getblockheader(tip)['mediantime'] + 1
        block = create_block(int(tip, 16), create_coinbase(1), block_time)
        block.nVersion = 3
        block.solve()

        # The best block should not have changed, because...
        assert_equal(self.nodes[0].getbestblockhash(), tip)

        # ... we rejected it because it is v3
        with self.nodes[0].assert_debug_log(expected_msgs=['{}, bad-version(0x00000003)'.format(block.hash)]):
            # Send it to the node
            self.nodes[0].p2p.send_and_ping(msg_block(block))

        self.log.info("Test that a version 4 block with a valid-according-to-CLTV transaction is accepted")

        # Generate 100 blocks so that first coinbase matures
        generated_blocks = self.nodes[0].generate(100)
        spendable_coinbase_txid = self.nodes[0].getblock(generated_blocks[0])['tx'][0]
        coinbase_value = self.nodes[0].decoderawtransaction(self.nodes[0].gettransaction(spendable_coinbase_txid)["hex"])["vout"][0]["value"]
        tip = generated_blocks[-1]

        # Construct a v4 block
        block_time = self.nodes[0].getblockheader(tip)['mediantime'] + 1
        block = create_block(int(tip, 16), create_coinbase(len(generated_blocks) + 1), block_time)
        block.nVersion = 4

        # Create a CLTV transaction
        spendtx = create_transaction(self.nodes[0], spendable_coinbase_txid,
                self.nodeaddress, amount=1.0, fee=coinbase_value-1)
        spendtx = cltv_validate(self.nodes[0], spendtx, 1)
        spendtx.rehash()

        # Add the CLTV transaction and prepare for sending
        block.vtx.append(spendtx)
        block.hashMerkleRoot = block.calc_merkle_root()
        block.solve()

        # Send block and check that it becomes new best block
        self.nodes[0].p2p.send_and_ping(msg_block(block))
        assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.sha256)
开发者ID:ElementsProject,项目名称:elements,代码行数:54,代码来源:feature_block_v4.py

示例3: get_tests

    def get_tests(self):
        self.tip = int ("0x" + self.nodes[0].getbestblockhash() + "L", 0)
        self.block_time = 1333230000  # before the BIP16 switchover

        '''
        Create a new block with an anyone-can-spend coinbase
        '''
        block = create_block(self.tip, create_coinbase(), self.block_time)
        self.block_time += 1
        block.solve()
        self.tip = block.sha256
        yield TestInstance(objects=[[block, True]])

        '''
        Build out to 100 blocks total, maturing the coinbase.
        '''
        test = TestInstance(objects=[], sync_every_block=False, sync_every_tx=False)
        for i in xrange(100):
            b = create_block(self.tip, create_coinbase(), self.block_time)
            b.solve()
            test.blocks_and_transactions.append([b, True])
            self.tip = b.sha256
            self.block_time += 1
        yield test
 
        ''' Iterate through script tests. '''
        counter = 0
        for script_test in self.scripts.get_records():
            ''' Reset the blockchain to genesis block + 100 blocks. '''
            if self.nodes[0].getblockcount() > 101:
                self.nodes[0].invalidateblock(self.nodes[0].getblockhash(102))
                self.nodes[1].invalidateblock(self.nodes[1].getblockhash(102))

            self.tip = int ("0x" + self.nodes[0].getbestblockhash() + "L", 0)

            [scriptsig, scriptpubkey, flags] = script_test[0:3]
            flags = ParseScriptFlags(flags)

            # We can use block time to determine whether the nodes should be
            # enforcing BIP16.
            #
            # We intentionally let the block time grow by 1 each time.
            # This forces the block hashes to differ between tests, so that
            # a call to invalidateblock doesn't interfere with a later test.
            if (flags & SCRIPT_VERIFY_P2SH):
                self.block_time = 1333238400 + counter # Advance to enforcing BIP16
            else:
                self.block_time = 1333230000 + counter # Before the BIP16 switchover

            print "Script test: [%s]" % script_test

            yield self.generate_test_instance(scriptpubkey, scriptsig)
            counter += 1
开发者ID:Whiteblock,项目名称:zcash,代码行数:53,代码来源:script_test.py

示例4: get_tests

    def get_tests(self):
        self.coinbase_blocks = self.nodes[0].generate(1)
        self.nodes[0].generate(100)
        self.tip = int ("0x" + self.nodes[0].getbestblockhash() + "L", 0)
        self.nodeaddress = self.nodes[0].getnewaddress()

        '''Check that the rules are enforced.'''
        for valid in (True, False):
            spendtx = self.create_transaction(self.nodes[0],
                                              self.coinbase_blocks[0],
                                              self.nodeaddress, 1.0)
            if not valid:
                self.invalidate_transaction(spendtx)
                spendtx.rehash()

            gbt = self.nodes[0].getblocktemplate()
            self.block_time = gbt["mintime"] + 1
            self.block_bits = int("0x" + gbt["bits"], 0)

            block = create_block(self.tip, create_coinbase(101),
                                 self.block_time, self.block_bits)
            block.nVersion = 4
            block.vtx.append(spendtx)
            block.hashMerkleRoot = block.calc_merkle_root()
            block.rehash()
            block.solve()
            self.block_time += 1
            self.tip = block.sha256
            yield TestInstance([[block, valid]])
开发者ID:Whiteblock,项目名称:zcash,代码行数:29,代码来源:bip65-cltv-p2p.py

示例5: solve_and_send_block

 def solve_and_send_block(prevhash, height, time):
     b = create_block(prevhash, create_coinbase(height), time)
     b.nVersion = 0x20000000
     b.solve()
     node.p2p.send_message(msg_block(b))
     node.p2p.sync_with_ping()
     return b
开发者ID:thrasher-,项目名称:litecoin,代码行数:7,代码来源:rpc_blockchain.py

示例6: build_block_on_tip

 def build_block_on_tip(self, node):
     height = node.getblockcount()
     tip = node.getbestblockhash()
     mtp = node.getblockheader(tip)["mediantime"]
     block = create_block(int(tip, 16), create_coinbase(height + 1), mtp + 1)
     block.solve()
     return block
开发者ID:narula,项目名称:bitcoin,代码行数:7,代码来源:p2p-compactblocks.py

示例7: run_test

    def run_test(self):
        # Add p2p connection to node0
        node = self.nodes[0]  # convenience reference to the node
        node.add_p2p_connection(P2PDataStore())

        network_thread_start()
        node.p2p.wait_for_verack()

        best_block = self.nodes[0].getbestblockhash()
        tip = int(best_block, 16)
        best_block_time = self.nodes[0].getblock(best_block)['time']
        block_time = best_block_time + 1

        self.log.info("Create a new block with an anyone-can-spend coinbase.")
        height = 1
        block = create_block(tip, create_coinbase(height), block_time)
        block.solve()
        # Save the coinbase for later
        block1 = block
        tip = block.sha256
        node.p2p.send_blocks_and_test([block], node, success=True)

        self.log.info("Mature the block.")
        self.nodes[0].generate(100)

        # b'\x64' is OP_NOTIF
        # Transaction will be rejected with code 16 (REJECT_INVALID)
        tx1 = create_transaction(block1.vtx[0], 0, b'\x64', 50 * COIN - 12000)
        node.p2p.send_txs_and_test([tx1], node, success=False, reject_code=16, reject_reason=b'mandatory-script-verify-flag-failed (Invalid OP_IF construction)')

        # Verify valid transaction
        tx1 = create_transaction(block1.vtx[0], 0, b'', 50 * COIN - 12000)
        node.p2p.send_txs_and_test([tx1], node, success=True)
开发者ID:OrangeMan110,项目名称:bitcoin,代码行数:33,代码来源:p2p_invalid_tx.py

示例8: build_block_on_tip

 def build_block_on_tip(self):
     height = self.nodes[0].getblockcount()
     tip = self.nodes[0].getbestblockhash()
     mtp = self.nodes[0].getblockheader(tip)['mediantime']
     block = create_block(int(tip, 16), create_coinbase(height + 1), mtp + 1)
     block.solve()
     return block
开发者ID:MarcoFalke,项目名称:bitcoin,代码行数:7,代码来源:p2p-compactblocks.py

示例9: run_test

    def run_test(self):
        node = self.nodes[0]  # alias

        node.add_p2p_connection(P2PStoreTxInvs())

        self.log.info("Create a new transaction and wait until it's broadcast")
        txid = int(node.sendtoaddress(node.getnewaddress(), 1), 16)

        # Can take a few seconds due to transaction trickling
        wait_until(lambda: node.p2p.tx_invs_received[txid] >= 1, lock=mininode_lock)

        # Add a second peer since txs aren't rebroadcast to the same peer (see filterInventoryKnown)
        node.add_p2p_connection(P2PStoreTxInvs())

        self.log.info("Create a block")
        # Create and submit a block without the transaction.
        # Transactions are only rebroadcast if there has been a block at least five minutes
        # after the last time we tried to broadcast. Use mocktime and give an extra minute to be sure.
        block_time = int(time.time()) + 6 * 60
        node.setmocktime(block_time)
        block = create_block(int(node.getbestblockhash(), 16), create_coinbase(node.getblockchaininfo()['blocks']), block_time)
        block.nVersion = 3
        block.rehash()
        block.solve()
        node.submitblock(ToHex(block))

        # Transaction should not be rebroadcast
        node.p2ps[1].sync_with_ping()
        assert_equal(node.p2ps[1].tx_invs_received[txid], 0)

        self.log.info("Transaction should be rebroadcast after 30 minutes")
        # Use mocktime and give an extra 5 minutes to be sure.
        rebroadcast_time = int(time.time()) + 41 * 60
        node.setmocktime(rebroadcast_time)
        wait_until(lambda: node.p2ps[1].tx_invs_received[txid] >= 1, lock=mininode_lock)
开发者ID:chaincoin,项目名称:chaincoin,代码行数:35,代码来源:wallet_resendwallettransactions.py

示例10: create_credit_tx

 def create_credit_tx(self, scriptPubKey):
     # self.tx1 is a coinbase transaction, modeled after the one created by script_tests.cpp
     # This allows us to reuse signatures created in the unit test framework.
     self.tx1 = create_coinbase()                 # this has a bip34 scriptsig,
     self.tx1.vin[0].scriptSig = CScript([0, 0])  # but this matches the unit tests
     self.tx1.vout[0].nValue = 0
     self.tx1.vout[0].scriptPubKey = scriptPubKey
     self.tx1.rehash()
开发者ID:Whiteblock,项目名称:zcash,代码行数:8,代码来源:script_test.py

示例11: create_test_block

 def create_test_block(self, txs, version = 536870912):
     block = create_block(self.tip, create_coinbase(self.tipheight + 1), self.last_block_time + 600)
     block.nVersion = version
     block.vtx.extend(txs)
     block.hashMerkleRoot = block.calc_merkle_root()
     block.rehash()
     block.solve()
     return block
开发者ID:admxjx,项目名称:bitcoin,代码行数:8,代码来源:bip68-112-113-p2p.py

示例12: build_block_on_tip

 def build_block_on_tip(self):
     height = self.nodes[0].getblockcount()
     tip = self.nodes[0].getbestblockhash()
     mtp = self.nodes[0].getblockheader(tip)['mediantime']
     block = create_block(int(tip, 16), create_coinbase(absoluteHeight = height + 1), mtp + 1)
     if XT_TWEAKS:
         block.nVersion = 4
     block.solve()
     return block
开发者ID:dagurval,项目名称:bitcoinxt,代码行数:9,代码来源:p2p-compactblocks.py

示例13: build_block_on_tip

 def build_block_on_tip(self, node, segwit=False):
     height = node.getblockcount()
     tip = node.getbestblockhash()
     mtp = node.getblockheader(tip)['mediantime']
     block = create_block(int(tip, 16), create_coinbase(height + 1), mtp + 1)
     block.nVersion = 4
     if segwit:
         add_witness_commitment(block)
     block.solve()
     return block
开发者ID:Flowdalic,项目名称:bitcoin,代码行数:10,代码来源:p2p_compactblocks.py

示例14: generate_blocks

 def generate_blocks(self, number, version, test_blocks = []):
     for i in xrange(number):
         block = create_block(self.tip, create_coinbase(absoluteHeight=self.height), self.last_block_time + 1)
         block.nVersion = version
         block.rehash()
         block.solve()
         test_blocks.append([block, True])
         self.last_block_time += 1
         self.tip = block.sha256
         self.height += 1
     return test_blocks
开发者ID:KrzysiekJ,项目名称:bitcoinxt,代码行数:11,代码来源:bip9-softforks.py

示例15: generate_blocks

 def generate_blocks(self, number, version, error = None):
     for i in range(number):
         block = create_block(self.tip, create_coinbase(self.height), self.last_block_time + 1)
         block.nVersion = version
         block.rehash()
         block.solve()
         assert_equal(self.nodes[0].submitblock(bytes_to_hex_str(block.serialize())), error)
         if (error == None):
             self.last_block_time += 1
             self.tip = block.sha256
             self.height += 1
开发者ID:mpatc,项目名称:bitcoin,代码行数:11,代码来源:bip91.py


注:本文中的test_framework.blocktools.create_coinbase函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。