def test_serialize_inv_message(self):
     inv_message = InvMessage([Invitem(INV_TX, Uint256.from_hexstr("f6eea3dd4f6536350344a535e37a4178170bba18b871a424d696e196d4d3b555")),
                               Invitem(INV_BLOCK, Uint256.from_hexstr("0000000040a24e14497879bdd67db948cf30edc5d0a5833e8cb2736582157b49"))])
     serialized_msg = MessageSerializer(MAIN).serialize(inv_message)
     self.assertEquals(hexstr(serialized_msg), "f9beb4d9696e76000000000000000000490000008be920f5020100000055b5d3d496e196d624a471b818ba0b1778417ae335a544033536654fdda3eef602000000497b15826573b28c3e83a5d0c5ed30cf48b97dd6bd797849144ea24000000000")
     serialized_msg = MessageSerializer(TESTNET).serialize(inv_message)
     self.assertEquals(hexstr(serialized_msg), "fabfb5da696e76000000000000000000490000008be920f5020100000055b5d3d496e196d624a471b818ba0b1778417ae335a544033536654fdda3eef602000000497b15826573b28c3e83a5d0c5ed30cf48b97dd6bd797849144ea24000000000")
Example #2
0
    def test_WalletFile_1(self):
        
        io = IoHandle.using_stringio()
        wallet = WalletFile.new(io)
        wallet.start_tx()
        wallet.outpoints[1]= OutpointIndex(12, 
                                 Uint256.from_hexstr("2af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f"),
                                 3,
                                 OutpointIndex.PUBKEY_HASH,
                                 4,
                                 PubKeyOutpoint(PublicKey.from_hexstr("022af4cc9ec3358354345c91691031a1fcdbe9a9064197521814e8a20fe018eb5f"), 
                                                                is_pubkey_hash=True))
        wallet.end_tx()
        wallet.commit()
        wallet.start_tx()
        wallet.outpoints[1] = OutpointIndex(12, 
                                 Uint256.from_hexstr("2af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f"),
                                 3,
                                 OutpointIndex.PUBKEY_HASH,
                                 4,
                                 PubKeyOutpoint(PublicKey.from_hexstr("022af4cc9ec3358354345c91691031a1fcdbe9a9064197521814e8a20fe018eb5f"), 
                                                                is_pubkey_hash=True))
        wallet.end_tx()
        wallet.commit()

        #with open(r"c:\local\tmp\wallet-test.wlt", "wb") as wlt:
        #    wlt.write(io.iohandle.getvalue())
        io.seek(0, SEEK_SET)
        wallet2 = WalletFile.load(io, len(io.iohandle.getvalue()))
        
        print wallet2.fileheader
        print wallet2.outpoints
 def test_transaction_handle(self):
     with self.assertRaises(TransactionNotFound):
         self.database1.get_transaction_handle(
             Uint256.from_hexstr(
                 "07c17eafb870acf0fece060b814ff71fd36a7df0f0a3a7e359c2c61b3b34c3e1"
             ))
     handle1 = self.database1.get_transaction_handle(
         Uint256.from_hexstr(
             "cebbc8d7d3550ca6df92eba4f41b93dc55f35b8199bb14dc3d0a95f9bd0e2dbd"
         ))
     assert isinstance(handle1.get_transaction(), Tx)
     self.assertEquals(
         str(handle1.get_block_hash()),
         "001f9c93fece90e2e1f729bb9c2b04ba59432592f8ebdc7d117146c74f7c833a")
     self.assertEquals(handle1.output_count(), 7)
     self.assertEquals(handle1.is_output_spent(0), False)
     self.assertEquals(handle1.is_output_spent(2), True)
     self.assertEquals(
         str(handle1.get_spending_transaction_hash(2)),
         "53bb1c14b4c6156d7352ee471fb7697736f4696accf5392e0f1830e38143f667")
     handle1.mark_unspent(2)
     self.assertEquals(handle1.is_output_spent(2), False)
     handle1.mark_spent(
         0,
         Uint256.from_hexstr(
             "13bb1c14b4c6156d7352ee471fb7697736f4696accf5392e0f1830e38143f667"
         ))
     self.assertEquals(handle1.is_output_spent(2), False)
     self.assertEquals(handle1.is_output_spent(0), True)
     self.assertEquals(
         str(handle1.get_spending_transaction_hash(0)),
         "13bb1c14b4c6156d7352ee471fb7697736f4696accf5392e0f1830e38143f667")
Example #4
0
 def test_invitem_serialize(self):
     blockitem = Invitem(INV_BLOCK, Uint256.from_hexstr("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008"))
     txitem = Invitem(INV_TX, Uint256.from_hexstr("84eb3cf3a391a0a0b70e05a3a54d8385f7dcb3809aaf274d392622205b27f288"))
     self.assertEquals(hexstr(InvitemSerializer().serialize(blockitem)), 
                       "0200000008b067b31dc139ee8e7a76a4f2cfcca477c4c06e1ef89f4ae308951907000000")
     self.assertEquals(hexstr(InvitemSerializer().serialize(txitem)), 
                       "0100000088f2275b202226394d27af9a80b3dcf785834da5a3050eb7a0a091a3f33ceb84")
Example #5
0
    def test_sign_transaction(self):
        tx = Tx(version=1, 
                in_list=[TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("d2a42ebcb98b598ddcb6d430ce9061dba76804a97f7c1413dd3faef744f909a8"),index=0), 
                   script=Script(instructions=[]), 
                   sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("2be8e319be1d15c1ba54708bdd7969b638e7e6fa2154819136e363ea6d33664a"),index=1), 
                   script=Script(instructions=[]), 
                   sequence=4294967295)], 
                out_list=[TxOut(value=3315075843, 
                    script=Script(instructions=[Instruction(OP_DUP),Instruction(OP_HASH160),Instruction(20,  decodehexstr("297c5a2ee31a1ab721115722d83f8654ca21d5df")),Instruction(OP_EQUALVERIFY),Instruction(OP_CHECKSIG)])),TxOut(value=2971972133, 
                    script=Script(instructions=[Instruction(OP_DUP),Instruction(OP_HASH160),Instruction(20,  decodehexstr("7d5feab86e31e8fc99d8e735d56226de9043e5fc")),Instruction(OP_EQUALVERIFY),Instruction(OP_CHECKSIG)])),TxOut(value=1046301823, 
                    script=Script(instructions=[Instruction(OP_DUP),Instruction(OP_HASH160),Instruction(20,  decodehexstr("fd91232a2fa0c389fa0188efde26c8a6165f4c50")),Instruction(OP_EQUALVERIFY),Instruction(OP_CHECKSIG)]))], 
                locktime=0)

        outscript0 = Script(instructions=[Instruction(33,  decodehexstr("03409fe679bdff9e801692c999b86d0c47b62dc02cdd10591ee70ca8056cd05023")),Instruction(OP_CHECKSIG)])
        outscript1 = Script(instructions=[Instruction(OP_DUP),Instruction(OP_HASH160),Instruction(20,  decodehexstr("5fb7fdb3d1ab0f3fec90b38417cca8ab736b10c6")),Instruction(OP_EQUALVERIFY),Instruction(OP_CHECKSIG)])

        # Sign TX_PUBKEY 
        sign_transaction(tx, 
                         [TxOut(None, outscript0), TxOut(None, outscript1)],
                         [decodehexstr("f006b27418527b1c400bbc434a3f22ee57c376bd4819cfe2a1162682788ae714"),
                          decodehexstr("c693115901c2840badd1e404706a4866a90d3afa16a542c1a3d0de9aad0875fe")])

        vm = TxValidationVM()
        valid, reason = vm.validate(tx, 0, outscript0, tx.in_list[0].script)
        if not valid:
            raise Exception(reason)
        valid, reason = vm.validate(tx, 1, outscript1, tx.in_list[1].script)
        if not valid:
            raise Exception(reason)
Example #6
0
 def test_blocklocator_deserialize(self):
     loc, cursor = BlockLocatorSerializer().deserialize(
         decodehexstr(
             "0100000005a329e1166037b2ea0cfbef5060c011c1cbbd37ad047a47b62d3dae020000000070bdb41302a622800ddfb2b3ebdd937fdca812ec8a7ab90ef250410700000000398052b24b2cc45ef953222e23880d25c3df95a913e72e9b015b34250000000066739a04b15f117929b581f6fe0ba2906bc4323829400f949086bb7d0000000008b067b31dc139ee8e7a76a4f2cfcca477c4c06e1ef89f4ae308951907000000"
         ))
     self.assertEquals(
         loc,
         BlockLocator(
             version=1,
             blockhashlist=[
                 Uint256.from_hexstr(
                     "0000000002ae3d2db6477a04ad37bdcbc111c06050effb0ceab2376016e129a3"
                 ),
                 Uint256.from_hexstr(
                     "00000000074150f20eb97a8aec12a8dc7f93ddebb3b2df0d8022a60213b4bd70"
                 ),
                 Uint256.from_hexstr(
                     "0000000025345b019b2ee713a995dfc3250d88232e2253f95ec42c4bb2528039"
                 ),
                 Uint256.from_hexstr(
                     "000000007dbb8690940f40293832c46b90a20bfef681b52979115fb1049a7366"
                 ),
                 Uint256.from_hexstr(
                     "00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008"
                 )
             ]))
Example #7
0
 def test_deserialize_getdata_message(self):
     serialized_getdata = decodehexstr("030100000098a23359c17ca2678e2039c8ff9081b18c4913749c9a081ac3f62958f09fa4720100000055b5d3d496e196d624a471b818ba0b1778417ae335a544033536654fdda3eef602000000497b15826573b28c3e83a5d0c5ed30cf48b97dd6bd797849144ea24000000000")
     getdata_msg, _ = GetdataMessageSerializer().deserialize(serialized_getdata)
     expected_msg = GetdataMessage([Invitem(INV_TX, Uint256.from_hexstr("72a49ff05829f6c31a089a9c7413498cb18190ffc839208e67a27cc15933a298")),
                                   Invitem(INV_TX, Uint256.from_hexstr("f6eea3dd4f6536350344a535e37a4178170bba18b871a424d696e196d4d3b555")),
                                   Invitem(INV_BLOCK, Uint256.from_hexstr("0000000040a24e14497879bdd67db948cf30edc5d0a5833e8cb2736582157b49"))])
     self.assertEquals(getdata_msg, expected_msg)
Example #8
0
 def test_get_block_handle(self):
     with self.assertRaises(BlockNotFound):
         self.database1.get_block_handle(Uint256.from_hexstr("041f9c93fece90e2e1f729bb9c2b04ba59432592f8ebdc7d117146c74f7c833a"))
     handle1 = self.database1.get_block_handle(Uint256.from_hexstr("001f9c93fece90e2e1f729bb9c2b04ba59432592f8ebdc7d117146c74f7c833a"))
     self.assertEquals(handle1.get_height(), 4)
     self.assertEquals(handle1.get_hash(), Uint256.from_hexstr("001f9c93fece90e2e1f729bb9c2b04ba59432592f8ebdc7d117146c74f7c833a"))
     assert isinstance(handle1.get_block(), Block)
     assert isinstance(handle1.get_blockheader(), BlockHeader)
Example #9
0
 def test_blocklocator_deserialize(self):
     loc, cursor = BlockLocatorSerializer().deserialize(decodehexstr("0100000005a329e1166037b2ea0cfbef5060c011c1cbbd37ad047a47b62d3dae020000000070bdb41302a622800ddfb2b3ebdd937fdca812ec8a7ab90ef250410700000000398052b24b2cc45ef953222e23880d25c3df95a913e72e9b015b34250000000066739a04b15f117929b581f6fe0ba2906bc4323829400f949086bb7d0000000008b067b31dc139ee8e7a76a4f2cfcca477c4c06e1ef89f4ae308951907000000"))
     self.assertEquals(loc, BlockLocator(version=1,
                                         blockhashlist=[Uint256.from_hexstr("0000000002ae3d2db6477a04ad37bdcbc111c06050effb0ceab2376016e129a3"),
                                                        Uint256.from_hexstr("00000000074150f20eb97a8aec12a8dc7f93ddebb3b2df0d8022a60213b4bd70"),
                                                        Uint256.from_hexstr("0000000025345b019b2ee713a995dfc3250d88232e2253f95ec42c4bb2528039"),
                                                        Uint256.from_hexstr("000000007dbb8690940f40293832c46b90a20bfef681b52979115fb1049a7366"),
                                                        Uint256.from_hexstr("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008")]))
Example #10
0
 def test_blockheader_serialize(self):
     h = BlockHeader(version=1, 
                     hash_prev=Uint256.from_hexstr("1e4baab89f3a3251818c31bc87f6a33b4a5a88ef76673e2cc77ab2127b7afded"), #hash_prev
                     hash_merkle=Uint256.from_hexstr("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"), #merkle
                     time=1237006505,
                     bits=486605799, 
                     nonce=2083236893) 
     self.assertEquals(hexstr(BlockheaderSerializer().serialize(h)), "01000000edfd7a7b12b27ac72c3e6776ef885a4a3ba3f687bc318c8151323a9fb8aa4b1e3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4aa938bb49e703011d1dac2b7c") 
 def test_contains_transaction(self):
     self.assertTrue(
         self.database1.contains_transaction(
             Uint256.from_hexstr(
                 "a87f530f2174f6c12945831e731a6fc99f699f1539cf14f36357b66d267b75a8"
             )))
     self.assertFalse(
         self.database1.contains_transaction(
             Uint256.from_hexstr(
                 "07c17eafb870acf0fece060b814ff71fd36a7df0f0a3a7e359c2c61b3b34c3e1"
             )))
Example #12
0
 def test_mine_genesis_block(self):
     """ Mine the unitnet GENESIS block """
     time_source = MockTimeSource(time=1356446436)
     miner = BitcoinMiner()
     block, template = miner.mine_block(hash_prev=Uint256.from_hexstr("0000000000000000000000000000000000000000000000000000000000000000"), 
                                 block_height=0,
                                 time_source=time_source, 
                                 difficulty_bits=524287999, 
                                 transactions=[], 
                                 coinbase_txout_list=[TxOut(5000000000, Script([push_data_instruction(decodehexstr("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f")),Instruction(OP_CHECKSIG)]))],
                                 coinbase_flags=["/P2SH/", "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"])
     self.assertEquals(block.blockheader.nonce, 1260)
     self.assertEquals(block.blockheader.hash_merkle, Uint256.from_hexstr("cf7ac9a3b387cf5e9fc14e03e2a5bbfc16d1ba00d2af6c96869ab4da949bd240"))
     self.assertEquals(hash_block(block), Uint256.from_hexstr("003ee3cf880906caa5662f10d4b4fb1c86c1853230dee8a7b8a62f434c73da5f"))
 def test_next_in_mainchain(self):
     self.assertEquals(
         self.database1.get_next_in_mainchain(
             Uint256.from_hexstr(
                 "003ee3cf880906caa5662f10d4b4fb1c86c1853230dee8a7b8a62f434c73da5f"
             )),
         Uint256.from_hexstr(
             "000cdbffc59b95168c34e5f1853075376308c05c53a1a53425d7f1ca9cab7073"
         ))
     self.assertIs(
         self.database1.get_next_in_mainchain(
             Uint256.from_hexstr(
                 "002afdfc8ed8111fa00c98bb7b94c34e02a52c57ba971a5fd29935d68fa1060b"
             )), None)
Example #14
0
 def test_serialize_getblocks_message(self):
     getblocks_msg = GetblocksMessage(BlockLocator(32200,
                                                   [Uint256.from_hexstr("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f")]), 
                                      Uint256.zero())
     
     serialized_msg = GetblocksMessageSerializer().serialize(getblocks_msg)
     self.assertEquals(hexstr(serialized_msg), "c87d0000016fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d61900000000000000000000000000000000000000000000000000000000000000000000000000")
Example #15
0
 def test_txin_serialize(self):
     txin = TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("17c5cb687ba453ab65e12cdc0d8721c70ab4678665eb200c50cb9f1e3207090e"), index=0), 
                            script=Script([Instruction(72, decodehexstr("3045022100ab2dc8932ca1d26f4cdac1feae09020a60ccc4d17b14e5fc5b21f3ab8c3a9cee022040a7208c172d19a19902280d66201c7fe2c3d8b2df7e23cc4e5b70fd52ecba2c01")),
                                           Instruction(65, decodehexstr("04b77dd1f3a21cb3d067a7e76982a609d7310f8692f5d61346f3225323c425604a0c12862755335c49e392673106adfc5dfdee1e4d367f10353e8911fac687db3e"))]), 
                            sequence=TxIn.NSEQUENCE_FINAL)
     self.assertEquals(hexstr(TxinSerializer().serialize(txin)), 
                       "0e0907321e9fcb500c20eb658667b40ac721870ddc2ce165ab53a47b68cbc517000000008b483045022100ab2dc8932ca1d26f4cdac1feae09020a60ccc4d17b14e5fc5b21f3ab8c3a9cee022040a7208c172d19a19902280d66201c7fe2c3d8b2df7e23cc4e5b70fd52ecba2c014104b77dd1f3a21cb3d067a7e76982a609d7310f8692f5d61346f3225323c425604a0c12862755335c49e392673106adfc5dfdee1e4d367f10353e8911fac687db3effffffff")
Example #16
0
 def test_blockheader_serialize(self):
     h = BlockHeader(
         version=1,
         hash_prev=Uint256.from_hexstr(
             "1e4baab89f3a3251818c31bc87f6a33b4a5a88ef76673e2cc77ab2127b7afded"
         ),  #hash_prev
         hash_merkle=Uint256.from_hexstr(
             "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
         ),  #merkle
         time=1237006505,
         bits=486605799,
         nonce=2083236893)
     self.assertEquals(
         hexstr(BlockheaderSerializer().serialize(h)),
         "01000000edfd7a7b12b27ac72c3e6776ef885a4a3ba3f687bc318c8151323a9fb8aa4b1e3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4aa938bb49e703011d1dac2b7c"
     )
Example #17
0
    def test_mine_block(self):
        """ Mine a block changing both nonce and extra_nonce"""
        def nonce_changer(template):
            if template.nonce >= 20:
                template.set_extra_nonce(template.extra_nonce + 1)
                template.set_nonce(0)
            else:
                template.set_nonce(template.nonce + 1)

        time_source = MockTimeSource(time=1356446436)
        miner = BitcoinMiner()
        block, template = miner.mine_block(
            hash_prev=Uint256.from_hexstr(
                "0000000000000000000000000000000000000000000000000000000000000000"
            ),
            block_height=0,
            time_source=time_source,
            difficulty_bits=524287999,
            transactions=[],
            coinbase_txout_list=[
                TxOut(
                    5000000000,
                    Script([
                        Instruction(
                            OP_PUSHDATA,
                            decodehexstr(
                                "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"
                            )),
                        Instruction(OP_CHECKSIG)
                    ]))
            ],
            nonce_changer=nonce_changer)
        self.assertEquals(block.blockheader.nonce, 8)
        self.assertEquals(template.nonce, 8)
        self.assertEquals(template.extra_nonce, 14)
        self.assertEquals(
            block.blockheader.hash_merkle,
            Uint256.from_hexstr(
                "ca839450c8702d6768d1803bb6d99c6d059a56240933e5bf72cb2936f6c9e211"
            ))
        self.assertEquals(
            hash_block(block),
            Uint256.from_hexstr(
                "003c7a06c7efe128cb3bea692e1a485f7400f3670df7986c020083e9b10e295d"
            ))
Example #18
0
 def test_outpoint_serialize(self):
     self.assertEquals(
         hexstr(OutpointSerializer().serialize(
             Outpoint(hash=Uint256.from_hexstr(
                 "17c5cb687ba453ab65e12cdc0d8721c70ab4678665eb200c50cb9f1e3207090e"
             ),
                      index=0))),
         "0e0907321e9fcb500c20eb658667b40ac721870ddc2ce165ab53a47b68cbc51700000000"
     )
 def test_pop_append_block(self):
     self.assertTrue(
         self.database1.contains_transaction(
             Uint256.from_hexstr(
                 "53bb1c14b4c6156d7352ee471fb7697736f4696accf5392e0f1830e38143f667"
             )))
     block = self.database1.pop_block()
     self.assertFalse(
         self.database1.contains_transaction(
             Uint256.from_hexstr(
                 "53bb1c14b4c6156d7352ee471fb7697736f4696accf5392e0f1830e38143f667"
             )))
     self.database1.append_block(block)
     self.assertTrue(
         self.database1.contains_transaction(
             Uint256.from_hexstr(
                 "53bb1c14b4c6156d7352ee471fb7697736f4696accf5392e0f1830e38143f667"
             )))
Example #20
0
 def test_deserialize_tx_message(self):
     # TX 1 from block 398 on testnet 3
     serialized_tx_message = decodehexstr("010000000328ce10c7189026866bcfc1d06b278981ddf21ec0e364e28e294365b5c328cd43000000006c493046022100b918951cc55fbb285168004de7eab21e702e89dc43c167ba0fc1b09273e29cf5022100f95c24b6c740e2306a45bea1e7a0c8f2032c9d4da4d8d1cc6b5c4166d1fabfe50121033b2dd6fe53611ef3d112b7098a8999f48bf27c7bf94bd045439d87a9ec11fca3fffffffffc4f1ed498c5f31fe90b10389f12566a3350a5080db1dba1f01f8834e5813ca900000000484730440220161ee27efad282e8c984051418fcc2bca6854f3f5d4e24031b950bcd7853943a02202b5566c72aeaff2295db82c79d52d88dbe9450e01c6c951d5d0148c290f6cbbe01fffffffffc5eecfa90d46aeeda36bb1a2f2da61e4f9be81253033ae55625d00acb13ef35000000004a493046022100f7d996bc39ef00b217014ee3e7f8b49ed714fcce2fe970a2ada2b9a87a741c2d022100c55a6089c2b23ec87c5063513c6c8abfc14c913f8ab69cf4ebed6a58c220946901ffffffff0340f1f23a000000001976a914f069756ffd9d331119e5430268437aed14210afb88ac00f2052a0100000017a914290bba32a49315789a030bb40b0047f8fb90ff668700f2052a0100000017a9141d9ca71efa36d814424ea6ca1437e67287aebe348700000000")
     tx_message, _ = TxMessageSerializer().deserialize(serialized_tx_message)
     expected_message = TxMessage(Tx(version=1, 
             in_list=[TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("43cd28c3b56543298ee264e3c01ef2dd8189276bd0c1cf6b86269018c710ce28"),index=0), 
                script=Script(instructions=[Instruction(73,  decodehexstr("3046022100b918951cc55fbb285168004de7eab21e702e89dc43c167ba0fc1b09273e29cf5022100f95c24b6c740e2306a45bea1e7a0c8f2032c9d4da4d8d1cc6b5c4166d1fabfe501")),Instruction(33,  decodehexstr("033b2dd6fe53611ef3d112b7098a8999f48bf27c7bf94bd045439d87a9ec11fca3"))]), 
                sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("a93c81e534881ff0a1dbb10d08a550336a56129f38100be91ff3c598d41e4ffc"),index=0), 
                script=Script(instructions=[Instruction(71,  decodehexstr("30440220161ee27efad282e8c984051418fcc2bca6854f3f5d4e24031b950bcd7853943a02202b5566c72aeaff2295db82c79d52d88dbe9450e01c6c951d5d0148c290f6cbbe01"))]), 
                sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("35ef13cb0ad02556e53a035312e89b4f1ea62d2f1abb36daee6ad490faec5efc"),index=0), 
                script=Script(instructions=[Instruction(73,  decodehexstr("3046022100f7d996bc39ef00b217014ee3e7f8b49ed714fcce2fe970a2ada2b9a87a741c2d022100c55a6089c2b23ec87c5063513c6c8abfc14c913f8ab69cf4ebed6a58c220946901"))]), 
                sequence=4294967295)], 
             out_list=[TxOut(value=989000000, 
                 script=Script(instructions=[Instruction(OP_DUP),Instruction(OP_HASH160),Instruction(20,  decodehexstr("f069756ffd9d331119e5430268437aed14210afb")),Instruction(OP_EQUALVERIFY),Instruction(OP_CHECKSIG)])),TxOut(value=5000000000, 
                 script=Script(instructions=[Instruction(OP_HASH160),Instruction(20,  decodehexstr("290bba32a49315789a030bb40b0047f8fb90ff66")),Instruction(OP_EQUAL)])),TxOut(value=5000000000, 
                 script=Script(instructions=[Instruction(OP_HASH160),Instruction(20,  decodehexstr("1d9ca71efa36d814424ea6ca1437e67287aebe34")),Instruction(OP_EQUAL)]))], 
             locktime=0))
     self.assertEquals(tx_message, expected_message)
Example #21
0
 def test_transaction_handle(self):
     with self.assertRaises(TransactionNotFound):
         self.database1.get_transaction_handle(Uint256.from_hexstr("07c17eafb870acf0fece060b814ff71fd36a7df0f0a3a7e359c2c61b3b34c3e1"))
     handle1 = self.database1.get_transaction_handle(Uint256.from_hexstr("cebbc8d7d3550ca6df92eba4f41b93dc55f35b8199bb14dc3d0a95f9bd0e2dbd"))
     assert isinstance(handle1.get_transaction(), Tx)
     self.assertEquals(str(handle1.get_block_hash()), "001f9c93fece90e2e1f729bb9c2b04ba59432592f8ebdc7d117146c74f7c833a")
     self.assertEquals(handle1.output_count(), 7)
     self.assertEquals(handle1.is_output_spent(0), False)
     self.assertEquals(handle1.is_output_spent(2), True)
     self.assertEquals(str(handle1.get_spending_transaction_hash(2)), 
                       "53bb1c14b4c6156d7352ee471fb7697736f4696accf5392e0f1830e38143f667")
     handle1.mark_unspent(2)
     self.assertEquals(handle1.is_output_spent(2), False)
     handle1.mark_spent(0, Uint256.from_hexstr("13bb1c14b4c6156d7352ee471fb7697736f4696accf5392e0f1830e38143f667"))
     self.assertEquals(handle1.is_output_spent(2), False)
     self.assertEquals(handle1.is_output_spent(0), True)
     self.assertEquals(str(handle1.get_spending_transaction_hash(0)), 
                       "13bb1c14b4c6156d7352ee471fb7697736f4696accf5392e0f1830e38143f667")
 def test_get_block_handle(self):
     with self.assertRaises(BlockNotFound):
         self.database1.get_block_handle(
             Uint256.from_hexstr(
                 "041f9c93fece90e2e1f729bb9c2b04ba59432592f8ebdc7d117146c74f7c833a"
             ))
     handle1 = self.database1.get_block_handle(
         Uint256.from_hexstr(
             "001f9c93fece90e2e1f729bb9c2b04ba59432592f8ebdc7d117146c74f7c833a"
         ))
     self.assertEquals(handle1.get_height(), 4)
     self.assertEquals(
         handle1.get_hash(),
         Uint256.from_hexstr(
             "001f9c93fece90e2e1f729bb9c2b04ba59432592f8ebdc7d117146c74f7c833a"
         ))
     assert isinstance(handle1.get_block(), Block)
     assert isinstance(handle1.get_blockheader(), BlockHeader)
 def test_deserialize_inv_message(self):
     serialized_inv_message = decodehexstr(
         "f9beb4d9696e76000000000000000000490000008be920f5020100000055b5d3d496e196d624a471b818ba0b1778417ae335a544033536654fdda3eef602000000497b15826573b28c3e83a5d0c5ed30cf48b97dd6bd797849144ea24000000000"
     )
     inv_message, _ = MessageSerializer(MAIN).deserialize(
         serialized_inv_message)
     expected_message = InvMessage([
         Invitem(
             INV_TX,
             Uint256.from_hexstr(
                 "f6eea3dd4f6536350344a535e37a4178170bba18b871a424d696e196d4d3b555"
             )),
         Invitem(
             INV_BLOCK,
             Uint256.from_hexstr(
                 "0000000040a24e14497879bdd67db948cf30edc5d0a5833e8cb2736582157b49"
             ))
     ])
     self.assertEquals(inv_message, expected_message)
Example #24
0
 def test_invitem_serialize(self):
     blockitem = Invitem(
         INV_BLOCK,
         Uint256.from_hexstr(
             "00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008"
         ))
     txitem = Invitem(
         INV_TX,
         Uint256.from_hexstr(
             "84eb3cf3a391a0a0b70e05a3a54d8385f7dcb3809aaf274d392622205b27f288"
         ))
     self.assertEquals(
         hexstr(InvitemSerializer().serialize(blockitem)),
         "0200000008b067b31dc139ee8e7a76a4f2cfcca477c4c06e1ef89f4ae308951907000000"
     )
     self.assertEquals(
         hexstr(InvitemSerializer().serialize(txitem)),
         "0100000088f2275b202226394d27af9a80b3dcf785834da5a3050eb7a0a091a3f33ceb84"
     )
Example #25
0
 def test_deserialize_block_message(self):
     #block 22 on testnet 3
     serialized_block_msg= decodehexstr("0100000073379e3ff3dffd006e0090e52ac571a9a309490a23e64d15f8af291a0000000051f1c5b2b7c8f980e7715b4d3ce0180f99c44a16fc9c00ede2f5984b8d7cc22d16ed494dffff001d0082467f0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0f0416ed494d02fa00062f503253482fffffffff0100f2052a01000000232103b787920594cb47fbfccee915befae40ac2e2b295224460eee075ad0ada4c0c54ac00000000")
     
     block_msg, _ = BlockMessageSerializer().deserialize(serialized_block_msg)
     expected_block_msg = BlockMessage(Block(blockheader=BlockHeader(version=1, 
                       hash_prev=Uint256.from_hexstr("000000001a29aff8154de6230a4909a3a971c52ae590006e00fddff33f9e3773"), 
                       hash_merkle=Uint256.from_hexstr("2dc27c8d4b98f5e2ed009cfc164ac4990f18e03c4d5b71e780f9c8b7b2c5f151"), 
                       time=1296690454,
                       bits=486604799,
                       nonce=2135327232), 
                 transactions=[Tx(version=1, 
                     in_list=[TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("0000000000000000000000000000000000000000000000000000000000000000"),index=4294967295), 
                        script=Script(instructions=[Instruction(4,  decodehexstr("16ed494d")),Instruction(2,  decodehexstr("fa00")),Instruction(6,  decodehexstr("2f503253482f"))]), 
                        sequence=4294967295)], 
                     out_list=[TxOut(value=5000000000, 
                         script=Script(instructions=[Instruction(33,  decodehexstr("03b787920594cb47fbfccee915befae40ac2e2b295224460eee075ad0ada4c0c54")),Instruction(OP_CHECKSIG)]))], 
                     locktime=0)]))
     self.assertEquals(block_msg, expected_block_msg)
Example #26
0
 def test_uint256_deserialize(self):
     uint256, _ = Uint256Serializer().deserialize(
         decodehexstr(
             "6a921ac1ae5e23610d07d2b2a9377fbc3c3bb233e900aa1a5bc40f5562a19d0d"
         ))
     self.assertEquals(
         uint256,
         Uint256.from_hexstr(
             "0d9da162550fc45b1aaa00e933b23b3cbc7f37a9b2d2070d61235eaec11a926a"
         ))
Example #27
0
    def test_serialize_outpoint_index(self):
        outpoint = OutpointIndex(12, 
                                 Uint256.from_hexstr("2af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f"),
                                 3,
                                 OutpointIndex.PUBKEY_HASH,
                                 4,
                                 PubKeyOutpoint(PublicKey.from_hexstr("022af4cc9ec3358354345c91691031a1fcdbe9a9064197521814e8a20fe018eb5f"), 
                                                                is_pubkey_hash=True))
        serialized = OutpointIndexSerializer.serialize(outpoint)

        self.assertEquals(hexstr(serialized), 
                          "0000000c2af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f030200000004022af4cc9ec3358354345c91691031a1fcdbe9a9064197521814e8a20fe018eb5f")
Example #28
0
 def test_tx_deserialize(self):
     tx, _ = TxSerializer().deserialize(
         decodehexstr(
             "01000000010e0907321e9fcb500c20eb658667b40ac721870ddc2ce165ab53a47b68cbc517000000008b483045022100ab2dc8932ca1d26f4cdac1feae09020a60ccc4d17b14e5fc5b21f3ab8c3a9cee022040a7208c172d19a19902280d66201c7fe2c3d8b2df7e23cc4e5b70fd52ecba2c014104b77dd1f3a21cb3d067a7e76982a609d7310f8692f5d61346f3225323c425604a0c12862755335c49e392673106adfc5dfdee1e4d367f10353e8911fac687db3effffffff02802385d1050000001976a9144d8b17fbce571614be89df4bd872de892a47984488ac00f2052a010000001976a914fadad27c40adbe230f5e3c04d44a29297508483188ac00000000"
         ))
     tx_expected = Tx(
         version=1,
         in_list=[
             TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr(
                 "17c5cb687ba453ab65e12cdc0d8721c70ab4678665eb200c50cb9f1e3207090e"
             ),
                                           index=0),
                  script=Script([
                      Instruction(
                          72,
                          decodehexstr(
                              "3045022100ab2dc8932ca1d26f4cdac1feae09020a60ccc4d17b14e5fc5b21f3ab8c3a9cee022040a7208c172d19a19902280d66201c7fe2c3d8b2df7e23cc4e5b70fd52ecba2c01"
                          )),
                      Instruction(
                          65,
                          decodehexstr(
                              "04b77dd1f3a21cb3d067a7e76982a609d7310f8692f5d61346f3225323c425604a0c12862755335c49e392673106adfc5dfdee1e4d367f10353e8911fac687db3e"
                          ))
                  ]),
                  sequence=TxIn.NSEQUENCE_FINAL)
         ],
         out_list=[
             TxOut(value=24990000000,
                   script=Script([
                       Instruction(OP_DUP),
                       Instruction(OP_HASH160),
                       Instruction(
                           20,
                           decodehexstr(
                               "4d8b17fbce571614be89df4bd872de892a479844")),
                       Instruction(OP_EQUALVERIFY),
                       Instruction(OP_CHECKSIG)
                   ])),
             TxOut(value=5000000000,
                   script=Script([
                       Instruction(OP_DUP),
                       Instruction(OP_HASH160),
                       Instruction(
                           20,
                           decodehexstr(
                               "fadad27c40adbe230f5e3c04d44a292975084831")),
                       Instruction(OP_EQUALVERIFY),
                       Instruction(OP_CHECKSIG)
                   ]))
         ],
         locktime=0)
     self.assertEquals(tx, tx_expected)
Example #29
0
 def test_mine_block(self):
     """ Mine a block changing both nonce and extra_nonce"""
     def nonce_changer(template):
         if template.nonce >= 20:
             template.set_extra_nonce(template.extra_nonce + 1)
             template.set_nonce(0)
         else:
             template.set_nonce(template.nonce + 1)
     time_source = MockTimeSource(time=1356446436)
     miner = BitcoinMiner()
     block, template = miner.mine_block(hash_prev=Uint256.from_hexstr("0000000000000000000000000000000000000000000000000000000000000000"), 
                                        block_height=0,
                                        time_source=time_source, 
                                        difficulty_bits=524287999, 
                                        transactions=[], 
                                        coinbase_txout_list=[TxOut(5000000000, Script([Instruction(OP_PUSHDATA, decodehexstr("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f")),Instruction(OP_CHECKSIG)]))],
                                        nonce_changer=nonce_changer)
     self.assertEquals(block.blockheader.nonce, 8)
     self.assertEquals(template.nonce, 8)
     self.assertEquals(template.extra_nonce, 14)
     self.assertEquals(block.blockheader.hash_merkle, Uint256.from_hexstr("ca839450c8702d6768d1803bb6d99c6d059a56240933e5bf72cb2936f6c9e211"))
     self.assertEquals(hash_block(block), Uint256.from_hexstr("003c7a06c7efe128cb3bea692e1a485f7400f3670df7986c020083e9b10e295d"))
Example #30
0
 def test_serialize_tx_message(self):
     # TX 1 from block 389 on testnet 3
     tx_message = TxMessage(Tx(version=1, 
                             in_list=[TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("f519f238c54e20bb418bb4513ce75484546d198200a901be55152e12cfa82652"),index=1), 
                                script=Script(instructions=[Instruction(73,  decodehexstr("3046022100b96e2fd2015bb3fe22c23c712c3ac4a8636d4a78df7d669babd64eaba314c236022100f402d7e3392d1770ce2be0c823eab0122bb83ee0bd65f5de54a1feb53e452eed01")),Instruction(65,  decodehexstr("04c4bee5e6dbb5c1651437cb4386c1515c7776c64535077204c6f24f05a37d04a32bc78beb2193b53b104c9954c44b0ce168bc78efd5f1e1c7db9d6c21b3016599"))]), 
                                sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("d748009c88abacfbd8d0dafb5552f0700a16f9a35ff41583988d9f70618c1971"),index=0), 
                                script=Script(instructions=[Instruction(72,  decodehexstr("304502210092e96f4185fc1bb74b4d9c258219dc5ffc71afb43e73ec0e78bdd91bafbe386e022019fc5b3d9602005b61f5dc75e7bd4dde1c19a0700c0a7958503528014d39019101")),Instruction(33,  decodehexstr("02274eae01d391bbec32d4b60e24d5d24f9cc23ca8da6708cf6c062381bfa71006"))]), 
                                sequence=4294967295)], 
                             out_list=[TxOut(value=5000000000, 
                                 script=Script(instructions=[Instruction(OP_DUP),Instruction(OP_HASH160),Instruction(20,  decodehexstr("dbf89509176a975e41d04cc0af24cfc8de4394a9")),Instruction(OP_EQUALVERIFY),Instruction(OP_CHECKSIG)]))], 
                             locktime=0))
     serialized_msg = TxMessageSerializer().serialize(tx_message)
     self.assertEquals(hexstr(serialized_msg), "01000000025226a8cf122e1555be01a90082196d548454e73c51b48b41bb204ec538f219f5010000008c493046022100b96e2fd2015bb3fe22c23c712c3ac4a8636d4a78df7d669babd64eaba314c236022100f402d7e3392d1770ce2be0c823eab0122bb83ee0bd65f5de54a1feb53e452eed014104c4bee5e6dbb5c1651437cb4386c1515c7776c64535077204c6f24f05a37d04a32bc78beb2193b53b104c9954c44b0ce168bc78efd5f1e1c7db9d6c21b3016599ffffffff71198c61709f8d988315f45fa3f9160a70f05255fbdad0d8fbacab889c0048d7000000006b48304502210092e96f4185fc1bb74b4d9c258219dc5ffc71afb43e73ec0e78bdd91bafbe386e022019fc5b3d9602005b61f5dc75e7bd4dde1c19a0700c0a7958503528014d390191012102274eae01d391bbec32d4b60e24d5d24f9cc23ca8da6708cf6c062381bfa71006ffffffff0100f2052a010000001976a914dbf89509176a975e41d04cc0af24cfc8de4394a988ac00000000")
Example #31
0
 def test_mine_genesis_block(self):
     """ Mine the unitnet GENESIS block """
     time_source = MockTimeSource(time=1356446436)
     miner = BitcoinMiner()
     block, template = miner.mine_block(
         hash_prev=Uint256.from_hexstr(
             "0000000000000000000000000000000000000000000000000000000000000000"
         ),
         block_height=0,
         time_source=time_source,
         difficulty_bits=524287999,
         transactions=[],
         coinbase_txout_list=[
             TxOut(
                 5000000000,
                 Script([
                     push_data_instruction(
                         decodehexstr(
                             "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"
                         )),
                     Instruction(OP_CHECKSIG)
                 ]))
         ],
         coinbase_flags=[
             "/P2SH/",
             "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks"
         ])
     self.assertEquals(block.blockheader.nonce, 1260)
     self.assertEquals(
         block.blockheader.hash_merkle,
         Uint256.from_hexstr(
             "cf7ac9a3b387cf5e9fc14e03e2a5bbfc16d1ba00d2af6c96869ab4da949bd240"
         ))
     self.assertEquals(
         hash_block(block),
         Uint256.from_hexstr(
             "003ee3cf880906caa5662f10d4b4fb1c86c1853230dee8a7b8a62f434c73da5f"
         ))
Example #32
0
 def test_block_deserialize(self):
     blk, _ = BlockSerializer().deserialize(decodehexstr("01000000a3a71e679426f6cd46a27441ac5021a5bf75b2168b6e14811508ec0f000000006a921ac1ae5e23610d07d2b2a9377fbc3c3bb233e900aa1a5bc40f5562a19d0dafaa8d4d7ffa0f1cef18524c0201000000010000000000000000000000000000000000000000000000000000000000000000ffffffff07047ffa0f1c014effffffff018076242a010000004341049cc3cae30927c40598032044b9e9e25f4739b0d7ade62803f5e9cf075debc817e6d29f42c70d0a1beb1c904eaaa50ef885b011f9fbaa16ef288a7ad193e11567ac0000000001000000010e0907321e9fcb500c20eb658667b40ac721870ddc2ce165ab53a47b68cbc517000000008b483045022100ab2dc8932ca1d26f4cdac1feae09020a60ccc4d17b14e5fc5b21f3ab8c3a9cee022040a7208c172d19a19902280d66201c7fe2c3d8b2df7e23cc4e5b70fd52ecba2c014104b77dd1f3a21cb3d067a7e76982a609d7310f8692f5d61346f3225323c425604a0c12862755335c49e392673106adfc5dfdee1e4d367f10353e8911fac687db3effffffff02802385d1050000001976a9144d8b17fbce571614be89df4bd872de892a47984488ac00f2052a010000001976a914fadad27c40adbe230f5e3c04d44a29297508483188ac00000000"))
     
     blockheader = BlockHeader(version=1,
                               hash_prev=Uint256.from_hexstr("000000000fec081581146e8b16b275bfa52150ac4174a246cdf62694671ea7a3"),
                               hash_merkle=Uint256.from_hexstr("0d9da162550fc45b1aaa00e933b23b3cbc7f37a9b2d2070d61235eaec11a926a"), 
                               time=1301129903, 
                               bits=470809215, 
                               nonce=1280448751)
     tx1 = Tx(version=1, 
              in_list=[TxIn(previous_output=Outpoint.null(), 
                            script=Script([Instruction(4, decodehexstr("7ffa0f1c")),
                                            Instruction(1, decodehexstr("4e"))]), 
                            sequence=TxIn.NSEQUENCE_FINAL )],
              out_list=[TxOut(value=5002000000, 
                              script=Script([Instruction(65, decodehexstr("049cc3cae30927c40598032044b9e9e25f4739b0d7ade62803f5e9cf075debc817e6d29f42c70d0a1beb1c904eaaa50ef885b011f9fbaa16ef288a7ad193e11567")), 
                                             Instruction(OP_CHECKSIG)]))],
              locktime=0)
     tx2 = Tx(version=1, 
              in_list=[TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("17c5cb687ba453ab65e12cdc0d8721c70ab4678665eb200c50cb9f1e3207090e"), index=0), 
                            script=Script([Instruction(72, decodehexstr("3045022100ab2dc8932ca1d26f4cdac1feae09020a60ccc4d17b14e5fc5b21f3ab8c3a9cee022040a7208c172d19a19902280d66201c7fe2c3d8b2df7e23cc4e5b70fd52ecba2c01")),
                                           Instruction(65, decodehexstr("04b77dd1f3a21cb3d067a7e76982a609d7310f8692f5d61346f3225323c425604a0c12862755335c49e392673106adfc5dfdee1e4d367f10353e8911fac687db3e"))]), 
                            sequence=TxIn.NSEQUENCE_FINAL )],
              out_list=[TxOut(value=24990000000, 
                              script=Script([Instruction(OP_DUP),
                                             Instruction(OP_HASH160),
                                             Instruction(20, decodehexstr("4d8b17fbce571614be89df4bd872de892a479844")), 
                                             Instruction(OP_EQUALVERIFY),
                                             Instruction(OP_CHECKSIG)])),
                        TxOut(value=5000000000, 
                              script=Script([Instruction(OP_DUP),
                                             Instruction(OP_HASH160),
                                             Instruction(20, decodehexstr("fadad27c40adbe230f5e3c04d44a292975084831")), 
                                             Instruction(OP_EQUALVERIFY),
                                             Instruction(OP_CHECKSIG)]))],
              locktime=0)
     self.assertEquals(blk, Block(blockheader, [tx1, tx2]))
Example #33
0
    def test_WalletFile_1(self):

        io = IoHandle.using_stringio()
        wallet = WalletFile.new(io)
        wallet.start_tx()
        wallet.outpoints[1] = OutpointIndex(
            12,
            Uint256.from_hexstr(
                "2af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f"
            ), 3, OutpointIndex.PUBKEY_HASH, 4,
            PubKeyOutpoint(PublicKey.from_hexstr(
                "022af4cc9ec3358354345c91691031a1fcdbe9a9064197521814e8a20fe018eb5f"
            ),
                           is_pubkey_hash=True))
        wallet.end_tx()
        wallet.commit()
        wallet.start_tx()
        wallet.outpoints[1] = OutpointIndex(
            12,
            Uint256.from_hexstr(
                "2af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f"
            ), 3, OutpointIndex.PUBKEY_HASH, 4,
            PubKeyOutpoint(PublicKey.from_hexstr(
                "022af4cc9ec3358354345c91691031a1fcdbe9a9064197521814e8a20fe018eb5f"
            ),
                           is_pubkey_hash=True))
        wallet.end_tx()
        wallet.commit()

        #with open(r"c:\local\tmp\wallet-test.wlt", "wb") as wlt:
        #    wlt.write(io.iohandle.getvalue())
        io.seek(0, SEEK_SET)
        wallet2 = WalletFile.load(io, len(io.iohandle.getvalue()))

        print wallet2.fileheader
        print wallet2.outpoints
    def test_serialize_outpoint_index(self):
        outpoint = OutpointIndex(
            12,
            Uint256.from_hexstr(
                "2af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f"
            ), 3, OutpointIndex.PUBKEY_HASH, 4,
            PubKeyOutpoint(PublicKey.from_hexstr(
                "022af4cc9ec3358354345c91691031a1fcdbe9a9064197521814e8a20fe018eb5f"
            ),
                           is_pubkey_hash=True))
        serialized = OutpointIndexSerializer.serialize(outpoint)

        self.assertEquals(
            hexstr(serialized),
            "0000000c2af4cc9ec3358354345c91694031a1fcdbe9a9064197521814e8a20fe018eb5f030200000004022af4cc9ec3358354345c91691031a1fcdbe9a9064197521814e8a20fe018eb5f"
        )
Example #35
0
 def test_merkletx_serialize(self):
     # This is tx 37 of block 429 on testnet3
     merkle_tx = MerkleTx(
              Tx(version=1, 
                 in_list=[TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("88c844570a227fe89d82e4e20d41576b95df8aa790a799bf7114dbed83b788b0"),index=0), 
                    script=Script(instructions=[Instruction(72,  decodehexstr("3045022100813a4dfdfda02946bf9fddc59ffd0b8d2feaa618518a3015fd5e65dd88a0d4480220137b25ea7531e103405bfe1617cb92f524e88c86e66a79c1e3c62558d019528201")),Instruction(33,  decodehexstr("03cf163e38520a7b390305528eca2fa1c620f0da225a044017fd92b30067875dc8"))]), 
                    sequence=4294967295)], 
                 out_list=[TxOut(value=4899704976, 
                      script=Script(instructions=[Instruction(OP_DUP),Instruction(OP_HASH160),Instruction(20,  decodehexstr("10170e3f7c3b0c93d2e07e90e307d3fb21811702")),Instruction(OP_EQUALVERIFY),Instruction(OP_CHECKSIG)])),TxOut(value=887733, 
                     script=Script(instructions=[Instruction(OP_HASH160),Instruction(20,  decodehexstr("184cd0a38ac3b1357d07179553788375a9e8a3b8")),Instruction(OP_EQUAL)]))], 
                 locktime=0),
              blockhash=Uint256.from_hexstr("00000000e080223655db52d2c35a37f6aa17a3f2efefa6794fd9831374cff09f"),
              merkle_branch=[Uint256.from_hexstr("88c844570a227fe89d82e4e20d41576b95df8aa790a799bf7114dbed83b788b0"), 
                             Uint256.from_hexstr("225dd6a6857be59dbf2d72d4d5cca1325053dd66a9c3a35a16c51de04a1b0d03"), 
                             Uint256.from_hexstr("74f79002e7c2cbbf40581aa56d8037cb32844d34ae049629a757b6ff709a10fa"),
                             Uint256.from_hexstr("02099d8b6bf46c3f87ccc922dec8c18a9dc420e17ebc672030145bd8ee33ab34"), 
                             Uint256.from_hexstr("15b202c47b1ad2638c4ea260611839be7cdf15e13e6de50861f41e46a5e9f8cf"), 
                             Uint256.from_hexstr("007e2166afda37ce696e971ac530a7cc22e183b37acf57c79cb0ee21a9de2179"), 
                             Uint256.from_hexstr("a7d06d9452a65fae2662ae63c9b450ba4ce22dfab76d22624a95d97d294421d4")],
              nindex=37)
     self.assertEquals(hexstr(MerkleTxSerializer().serialize(merkle_tx)), 
                       "0100000001b088b783eddb1471bf99a790a78adf956b57410de2e4829de87f220a5744c888000000006b483045022100813a4dfdfda02946bf9fddc59ffd0b8d2feaa618518a3015fd5e65dd88a0d4480220137b25ea7531e103405bfe1617cb92f524e88c86e66a79c1e3c62558d0195282012103cf163e38520a7b390305528eca2fa1c620f0da225a044017fd92b30067875dc8ffffffff0290900b24010000001976a91410170e3f7c3b0c93d2e07e90e307d3fb2181170288acb58b0d000000000017a914184cd0a38ac3b1357d07179553788375a9e8a3b887000000009ff0cf741383d94f79a6efeff2a317aaf6375ac3d252db55362280e00000000007b088b783eddb1471bf99a790a78adf956b57410de2e4829de87f220a5744c888030d1b4ae01dc5165aa3c3a966dd535032a1ccd5d4722dbf9de57b85a6d65d22fa109a70ffb657a7299604ae344d8432cb37806da51a5840bfcbc2e70290f77434ab33eed85b14302067bc7ee120c49d8ac1c8de22c9cc873f6cf46b8b9d0902cff8e9a5461ef46108e56d3ee115df7cbe39186160a24e8c63d21a7bc402b2157921dea921eeb09cc757cf7ab383e122cca730c51a976e69ce37daaf66217e00d42144297dd9954a62226db7fa2de24cba50b4c963ae6226ae5fa652946dd0a725000000")                    
Example #36
0
 def test_blockheader_template(self):
     """ Change nonce and extra_nonce in a blockheader_template """
     template = BlockheaderTemplate(
         Uint256.from_hexstr(
             "0009d8ab497a46a0d6a2b9b302993bd26613b145695d986be50e0b6e68c5b524"
         ),
         1,  # version 2 blocks see BIP-34
         [
             TxOut(
                 5000000000,
                 Script([
                     Instruction(
                         OP_PUSHDATA,
                         decodehexstr(
                             "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"
                         )),
                     Instruction(OP_CHECKSIG)
                 ]))
         ],
         [],
         time=1356447036,
         bits=524287999,
         nonce=0,
         extra_nonce=0,
         coinbase_flags=["/P2SH/"])
     self.assertEquals(
         hexstr(template.get_serialized()),
         "0200000024b5c5686e0b0ee56b985d6945b11366d23b9902b3b9a2d6a0467a49abd80900ad7af2ede803ff129e66775d56153a7a649721e524eecad69a437ecdc01e29343cbdd950ffff3f1f00000000"
     )
     template.set_nonce(8)
     self.assertEquals(
         hexstr(template.get_serialized()),
         "0200000024b5c5686e0b0ee56b985d6945b11366d23b9902b3b9a2d6a0467a49abd80900ad7af2ede803ff129e66775d56153a7a649721e524eecad69a437ecdc01e29343cbdd950ffff3f1f08000000"
     )
     template.set_nonce(492498294)
     self.assertEquals(
         hexstr(template.get_serialized()),
         "0200000024b5c5686e0b0ee56b985d6945b11366d23b9902b3b9a2d6a0467a49abd80900ad7af2ede803ff129e66775d56153a7a649721e524eecad69a437ecdc01e29343cbdd950ffff3f1f76ed5a1d"
     )
     template.set_extra_nonce(2)
     template.set_nonce(0)
     self.assertEquals(
         hexstr(template.get_serialized()),
         "0200000024b5c5686e0b0ee56b985d6945b11366d23b9902b3b9a2d6a0467a49abd80900e1cc38b530e20307a310a57a6e2e22985ce2e292bfc73b28a723dd77f8e8f0ca3cbdd950ffff3f1f00000000"
     )
Example #37
0
 def test_blockheader_template(self):
     """ Change nonce and extra_nonce in a blockheader_template """
     template = BlockheaderTemplate(Uint256.from_hexstr("0009d8ab497a46a0d6a2b9b302993bd26613b145695d986be50e0b6e68c5b524"), 
                                    1, # version 2 blocks see BIP-34
                                    [TxOut(5000000000, Script([Instruction(OP_PUSHDATA, decodehexstr("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f")),Instruction(OP_CHECKSIG)]))], 
                                    [], 
                                    time=1356447036, 
                                    bits=524287999,
                                    nonce=0,
                                    extra_nonce=0,
                                    coinbase_flags=["/P2SH/"])
     self.assertEquals(hexstr(template.get_serialized()), "0200000024b5c5686e0b0ee56b985d6945b11366d23b9902b3b9a2d6a0467a49abd80900ad7af2ede803ff129e66775d56153a7a649721e524eecad69a437ecdc01e29343cbdd950ffff3f1f00000000")
     template.set_nonce(8)
     self.assertEquals(hexstr(template.get_serialized()), "0200000024b5c5686e0b0ee56b985d6945b11366d23b9902b3b9a2d6a0467a49abd80900ad7af2ede803ff129e66775d56153a7a649721e524eecad69a437ecdc01e29343cbdd950ffff3f1f08000000")
     template.set_nonce(492498294)
     self.assertEquals(hexstr(template.get_serialized()), "0200000024b5c5686e0b0ee56b985d6945b11366d23b9902b3b9a2d6a0467a49abd80900ad7af2ede803ff129e66775d56153a7a649721e524eecad69a437ecdc01e29343cbdd950ffff3f1f76ed5a1d")
     template.set_extra_nonce(2)
     template.set_nonce(0)
     self.assertEquals(hexstr(template.get_serialized()), "0200000024b5c5686e0b0ee56b985d6945b11366d23b9902b3b9a2d6a0467a49abd80900e1cc38b530e20307a310a57a6e2e22985ce2e292bfc73b28a723dd77f8e8f0ca3cbdd950ffff3f1f00000000")
Example #38
0
 def test_tx_serialize(self):
     tx = Tx(version=1, 
              in_list=[TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("17c5cb687ba453ab65e12cdc0d8721c70ab4678665eb200c50cb9f1e3207090e"), index=0), 
                            script=Script([Instruction(72, decodehexstr("3045022100ab2dc8932ca1d26f4cdac1feae09020a60ccc4d17b14e5fc5b21f3ab8c3a9cee022040a7208c172d19a19902280d66201c7fe2c3d8b2df7e23cc4e5b70fd52ecba2c01")),
                                           Instruction(65, decodehexstr("04b77dd1f3a21cb3d067a7e76982a609d7310f8692f5d61346f3225323c425604a0c12862755335c49e392673106adfc5dfdee1e4d367f10353e8911fac687db3e"))]), 
                            sequence=TxIn.NSEQUENCE_FINAL )],
              out_list=[TxOut(value=24990000000, 
                              script=Script([Instruction(OP_DUP),
                                             Instruction(OP_HASH160),
                                             Instruction(20, decodehexstr("4d8b17fbce571614be89df4bd872de892a479844")), 
                                             Instruction(OP_EQUALVERIFY),
                                             Instruction(OP_CHECKSIG)])),
                        TxOut(value=5000000000, 
                              script=Script([Instruction(OP_DUP),
                                             Instruction(OP_HASH160),
                                             Instruction(20, decodehexstr("fadad27c40adbe230f5e3c04d44a292975084831")), 
                                             Instruction(OP_EQUALVERIFY),
                                             Instruction(OP_CHECKSIG)]))],
              locktime=0)                    
     self.assertEquals(hexstr(TxSerializer().serialize(tx)), "01000000010e0907321e9fcb500c20eb658667b40ac721870ddc2ce165ab53a47b68cbc517000000008b483045022100ab2dc8932ca1d26f4cdac1feae09020a60ccc4d17b14e5fc5b21f3ab8c3a9cee022040a7208c172d19a19902280d66201c7fe2c3d8b2df7e23cc4e5b70fd52ecba2c014104b77dd1f3a21cb3d067a7e76982a609d7310f8692f5d61346f3225323c425604a0c12862755335c49e392673106adfc5dfdee1e4d367f10353e8911fac687db3effffffff02802385d1050000001976a9144d8b17fbce571614be89df4bd872de892a47984488ac00f2052a010000001976a914fadad27c40adbe230f5e3c04d44a29297508483188ac00000000")
Example #39
0
 def test_txin_serialize(self):
     txin = TxIn(
         previous_output=Outpoint(hash=Uint256.from_hexstr(
             "17c5cb687ba453ab65e12cdc0d8721c70ab4678665eb200c50cb9f1e3207090e"
         ),
                                  index=0),
         script=Script([
             Instruction(
                 72,
                 decodehexstr(
                     "3045022100ab2dc8932ca1d26f4cdac1feae09020a60ccc4d17b14e5fc5b21f3ab8c3a9cee022040a7208c172d19a19902280d66201c7fe2c3d8b2df7e23cc4e5b70fd52ecba2c01"
                 )),
             Instruction(
                 65,
                 decodehexstr(
                     "04b77dd1f3a21cb3d067a7e76982a609d7310f8692f5d61346f3225323c425604a0c12862755335c49e392673106adfc5dfdee1e4d367f10353e8911fac687db3e"
                 ))
         ]),
         sequence=TxIn.NSEQUENCE_FINAL)
     self.assertEquals(
         hexstr(TxinSerializer().serialize(txin)),
         "0e0907321e9fcb500c20eb658667b40ac721870ddc2ce165ab53a47b68cbc517000000008b483045022100ab2dc8932ca1d26f4cdac1feae09020a60ccc4d17b14e5fc5b21f3ab8c3a9cee022040a7208c172d19a19902280d66201c7fe2c3d8b2df7e23cc4e5b70fd52ecba2c014104b77dd1f3a21cb3d067a7e76982a609d7310f8692f5d61346f3225323c425604a0c12862755335c49e392673106adfc5dfdee1e4d367f10353e8911fac687db3effffffff"
     )
Example #40
0
 def test_contains_transaction(self):
     self.assertTrue(self.database1.contains_transaction(Uint256.from_hexstr("a87f530f2174f6c12945831e731a6fc99f699f1539cf14f36357b66d267b75a8")))
     self.assertFalse(self.database1.contains_transaction(Uint256.from_hexstr("07c17eafb870acf0fece060b814ff71fd36a7df0f0a3a7e359c2c61b3b34c3e1")))
Example #41
0
 def test_serialize_block_message(self):
     #block 381 on testnet 3 (first block with exactly 2 transactions)
     block_msg = BlockMessage(
                         Block(blockheader=BlockHeader(version=1, 
                               hash_prev=Uint256.from_hexstr("00000000d2a17cbe6e38439f60111911c2cca0a551ccfac41a7efa659048b9c5"), 
                               hash_merkle=Uint256.from_hexstr("83c4a9e0d7b0bc6be667bf916e3d3dea5949c235e3db841d44a8a222bb3bdba0"), 
                               time=1296728938,
                               bits=486604799,
                               nonce=1712527364), 
                         transactions=[
                 Tx(version=1, 
                     in_list=[TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("0000000000000000000000000000000000000000000000000000000000000000"),index=4294967295), 
                        script=Script(instructions=[Instruction(4,  decodehexstr("6a834a4d")),Instruction(1,  decodehexstr("7e")),Instruction(6,  decodehexstr("2f503253482f"))]), 
                        sequence=4294967295)], 
                     out_list=[TxOut(value=5000000000, 
                         script=Script(instructions=[Instruction(33,  decodehexstr("03dac3fb8de40965f42fb4afb3baa07d3304bc2aa28cfc25f12b52f1523681451d")),Instruction(OP_CHECKSIG)]))], 
                     locktime=0),
                 Tx(version=1, 
                     in_list=[TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("6749762ae220c10705556799dcec9bb6a54a7b881eb4b961323a3363b00db518"),index=0), 
                        script=Script(instructions=[Instruction(73,  decodehexstr("3046022100e49de3c89180769db346145cdda48323ddecc2af0041293432528767b18407650221009f7878deb054e4f9c0e6aecbe6de15f5d829041c11f7952d33e96c76ada1258b01"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("c04c413576307737f3ad48efe5d509ebc883e1d04822b3a2eccf6a80a4482932"),index=0), 
                        script=Script(instructions=[Instruction(73,  decodehexstr("3046022100ba88d34e4d4fd85ab5e4d77cb74f71c87a24235bcbe39cf4334633f70ff27233022100b5aa1b96bab59457d3d837473de1e4f9f89ba3ee39964463952271c5b4140fa001"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("72d4fc43ac576a4b2f1f35e1b310a2d83a1012a36fdc7813ec237646950233cf"),index=0), 
                        script=Script(instructions=[Instruction(73,  decodehexstr("3046022100b21560dfda52352c4416c1e48496659ea3d29e4e25706a991986864210bc759e0221009c1e45af6e2eba0883a862442d85a2b48c3395e35a4276f535cd70d45a971c7401"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("2d34482568c53b9831ef765280f59fd151c3f8ec09f88867f6b85d974d0fedee"),index=0), 
                        script=Script(instructions=[Instruction(72,  decodehexstr("3045022100e02cc0b4bf8a126807b1577819944c1bb13e8f4028cf7df0a0729013d511b071022010a1bcdefca334588939f9fe40e0d8607588191684fce0f46180a139305b8b4001"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("a5dd9470792c9ad6fda110d4b19c9f2b2b07eb96d239530a0e1ec0b12f0aacc8"),index=0), 
                        script=Script(instructions=[Instruction(72,  decodehexstr("3045022016ba8f50d7f30be7e4a68c3d50368d577e2ef6c8b60842725ae636b2985776fc022100bb39d47d1955ffca47920d743bcd6f05b31ea2bf3dc7ede225eb4c901126b48901"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("1b24cec4ce0519df028af441934f161c3fdbc6bbf611d33ff39e0b68f03cb0f1"),index=0), 
                        script=Script(instructions=[Instruction(72,  decodehexstr("304502201dbbfabc47f6da84ceedbc92b792d4a8ef632f0bddf7ebfad5ca21f3731f450502210098751ccf37fd97ff82446486d4c1d62860c2080a1128ea5ddb0d30bfde3cd7a801"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("ed97bd0230c4fc9e53e6acd280a873db5639a087ff5874fe80a674c08a89e61f"),index=0), 
                        script=Script(instructions=[Instruction(73,  decodehexstr("3046022100f8a83fadb06af9c0cc730f17ae47fe7a09cada9eae623b8dd86bf365ef0e20480221009a10b073b2a8b313d975f801213efdf12b94141d7b6a8e98de3b0c67ee1cef4c01"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("a45f9a24d946feda1b6c2e571ba941ac09155f4d6a59733586e9cf13025cd86f"),index=0), 
                        script=Script(instructions=[Instruction(73,  decodehexstr("3046022100f3e98f3e76cc0f533b0e1cccd82650b704e31e3e7e62bf81bb474cf2add58ebf022100f77003eec814a3336cc305b8461cf3ccb19b1f18f06f66208ed31c3e468466ed01"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("dd6e072eb7e092acac3826c1d346218c188d70789504fc16795e51a656a0939e"),index=0), 
                        script=Script(instructions=[Instruction(73,  decodehexstr("30460221008ee8d7348aed82a8d074753ab4c8dbdd28a668da821269c4cd0c5c253738cab7022100b06a0208d60af1be6303dd883fd05f964a42f7de317761641ec1158944f52b6b01"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("d3d98f948569afdd86421523a954854773346ebb36d8747d375dcdd8737bcc0e"),index=0), 
                        script=Script(instructions=[Instruction(72,  decodehexstr("30450221008159ed783bc717ff5a6502cd87a8d8144fae74c6fc6943a5a38da7170203cb3802207e31577a576bc01510cb2280f918a371f63eee44cd2b4490c0994d261787916e01"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("5cc0a6a52aa841918915d039f0045a321afba69f241824ab52442d0a9f6e9678"),index=0), 
                        script=Script(instructions=[Instruction(71,  decodehexstr("304402206655b13198e413ac8f1aa8926d4617560758cf8b5045afdfc9116da0873ed89802205db55cf3f398467bfc6997f68c881e5f2a7225293ebbd2af40d15df6de4ef87701"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("7c2703dfb6b2c74d07c3f54a7f1b6484d07d7d7f30fbe2fe1570debe6b09f269"),index=0), 
                        script=Script(instructions=[Instruction(73,  decodehexstr("3046022100c9199296673a1beae598a6d2348ef13ad1b9f15eebaa825d2282adf017cbb5f0022100b54934e40ff0194a53dcaa9d017c36a93dbb53aa45fe21ab93b07fbb58570d5501"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("3083cb9808088da30888073f5ac952c3a02ba54239736bc32ed63fd446b1113c"),index=0), 
                        script=Script(instructions=[Instruction(71,  decodehexstr("3044022004c64773b9e6a17cfca7ff583be650104c0538940289b2da8f8bebbd32e486b302200174d8f0938a0f9eeab4c4b137581e032f06d4740e3b0ad9d0423a0a8de65af101"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("763c1bef6943e02d9c0696ebe183922e26575c489def07a9b989faad373cac59"),index=0), 
                        script=Script(instructions=[Instruction(72,  decodehexstr("30450220306f3ac72de9dbeb1ec139e4e89cc3b3b9bcb63747bf0e165fcfc773f3669832022100c00a16800f16bf1c71ac6c2989b42d974b0ec2f3e3671325fb2cae52a1c569d801"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("b77bfe8240e197a3c004e3144613ab29cc5cbd6df382abe586d98d81eeecbbb4"),index=0), 
                        script=Script(instructions=[Instruction(73,  decodehexstr("3046022100ed68e0303052b41ffd80c1e905cee5547e92422d43b73e473a615e4a47146bb5022100ecab3f92c62477350753b4efea19d608fcce15b1b2c38fbe905e9d1f9ad7631f01"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("8404eec9135a198ff37ff2f3b605f34deb68b354c1e8a60d98c8e19aacbb4675"),index=0), 
                        script=Script(instructions=[Instruction(72,  decodehexstr("304502202288566af2b68b6982d1244e293ea3d7c156a425329b7f61b272e4deec317bea022100d9739976b442d35c32830cb2c105e0d7275f7efaa99eaeea4b24a553267a31fc01"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("77b6bab82fa6183f1a83b70551e22b7a55240b479f0872af9d34bae5d15458d1"),index=0), 
                        script=Script(instructions=[Instruction(72,  decodehexstr("304502206e3a23075e0248ea8cabc7c875b4cfd9f036c1c4f358a00ec152fc96d1cb6cf8022100d34c018815f63c65f5364061369382b31d579cd6d8a4afe9ec1f03ba66d7717801"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("7e9ece75efbb59dfb38e4245fa19474336636db25385606adec1c2317f6a68df"),index=0), 
                        script=Script(instructions=[Instruction(72,  decodehexstr("304502200a22a24a8f817a2f24d3f8c2670f3cb25cd389ce25e0d45eeb0aea08563c5c9802210081ff14edb230a44e5b52e35f573676096a937fc27cc830b153b229b92cac75c101"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("27b2f3eafa9e5696eb76a8960c95502e727b640f344d031aa3c5991ba9fe26d2"),index=0), 
                        script=Script(instructions=[Instruction(73,  decodehexstr("30460221009684e60a7fd61362d0dad79858044aa4a7b878b3f0bd432e384fe4c7e6c90bde0221009883e4f739cffe574bac5bed0a4e69708433973a2490d9415d303614fc31be4701"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("718f8928d46e07dfad7ce17e4747ef23536f83699859480002dc38a40ec640f6"),index=0), 
                        script=Script(instructions=[Instruction(72,  decodehexstr("30450220028eb7617dc161a282512c81975d41a1594c05f34cb26fb759682bf784da7071022100a0913abea7229b3c465a4fa32dc861f72ef684e8dd3f19aac5f0f74ea39c03cf01"))]), 
                        sequence=4294967295),TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("cc61baf9815306f8da8f9de105023fde0ddc49269d8ac67a6f3c88b1492a9dd5"),index=0), 
                        script=Script(instructions=[Instruction(73,  decodehexstr("30460221009f5b27dfd397423a04cab52ee6e8215e290e9666309f0f59f5bc5f6c207d3639022100f5a79133db2cc786140aeee0bf7c8a81adca6071928e8210f1c9f0c653e2f04201"))]), 
                        sequence=4294967295)], 
                     out_list=[TxOut(value=4989000000, 
                         script=Script(instructions=[Instruction(OP_DUP),Instruction(OP_HASH160),Instruction(20,  decodehexstr("944a7d4b3a8d3a5ecf19dfdfd8dcc18c6f1487dd")),Instruction(OP_EQUALVERIFY),Instruction(OP_CHECKSIG)])),TxOut(value=100011000000, 
                         script=Script(instructions=[Instruction(OP_DUP),Instruction(OP_HASH160),Instruction(20,  decodehexstr("32040178c5cf81cb200ab99af1131f187745b515")),Instruction(OP_EQUALVERIFY),Instruction(OP_CHECKSIG)]))], 
                     locktime=0)]))
     serialized_msg = BlockMessageSerializer().serialize(block_msg)
     self.assertEquals(hexstr(serialized_msg),
                       "01000000c5b9489065fa7e1ac4facc51a5a0ccc2111911609f43386ebe7ca1d200000000a0db3bbb22a2a8441d84dbe335c24959ea3d3d6e91bf67e66bbcb0d7e0a9c4836a834a4dffff001d041813660201000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0e046a834a4d017e062f503253482fffffffff0100f2052a01000000232103dac3fb8de40965f42fb4afb3baa07d3304bc2aa28cfc25f12b52f1523681451dac00000000010000001518b50db063333a3261b9b41e887b4aa5b69becdc9967550507c120e22a764967000000004a493046022100e49de3c89180769db346145cdda48323ddecc2af0041293432528767b18407650221009f7878deb054e4f9c0e6aecbe6de15f5d829041c11f7952d33e96c76ada1258b01ffffffff322948a4806acfeca2b32248d0e183c8eb09d5e5ef48adf33777307635414cc0000000004a493046022100ba88d34e4d4fd85ab5e4d77cb74f71c87a24235bcbe39cf4334633f70ff27233022100b5aa1b96bab59457d3d837473de1e4f9f89ba3ee39964463952271c5b4140fa001ffffffffcf330295467623ec1378dc6fa312103ad8a210b3e1351f2f4b6a57ac43fcd472000000004a493046022100b21560dfda52352c4416c1e48496659ea3d29e4e25706a991986864210bc759e0221009c1e45af6e2eba0883a862442d85a2b48c3395e35a4276f535cd70d45a971c7401ffffffffeeed0f4d975db8f66788f809ecf8c351d19ff5805276ef31983bc5682548342d0000000049483045022100e02cc0b4bf8a126807b1577819944c1bb13e8f4028cf7df0a0729013d511b071022010a1bcdefca334588939f9fe40e0d8607588191684fce0f46180a139305b8b4001ffffffffc8ac0a2fb1c01e0e0a5339d296eb072b2b9f9cb1d410a1fdd69a2c797094dda50000000049483045022016ba8f50d7f30be7e4a68c3d50368d577e2ef6c8b60842725ae636b2985776fc022100bb39d47d1955ffca47920d743bcd6f05b31ea2bf3dc7ede225eb4c901126b48901fffffffff1b03cf0680b9ef33fd311f6bbc6db3f1c164f9341f48a02df1905cec4ce241b000000004948304502201dbbfabc47f6da84ceedbc92b792d4a8ef632f0bddf7ebfad5ca21f3731f450502210098751ccf37fd97ff82446486d4c1d62860c2080a1128ea5ddb0d30bfde3cd7a801ffffffff1fe6898ac074a680fe7458ff87a03956db73a880d2ace6539efcc43002bd97ed000000004a493046022100f8a83fadb06af9c0cc730f17ae47fe7a09cada9eae623b8dd86bf365ef0e20480221009a10b073b2a8b313d975f801213efdf12b94141d7b6a8e98de3b0c67ee1cef4c01ffffffff6fd85c0213cfe9863573596a4d5f1509ac41a91b572e6c1bdafe46d9249a5fa4000000004a493046022100f3e98f3e76cc0f533b0e1cccd82650b704e31e3e7e62bf81bb474cf2add58ebf022100f77003eec814a3336cc305b8461cf3ccb19b1f18f06f66208ed31c3e468466ed01ffffffff9e93a056a6515e7916fc049578708d188c2146d3c12638acac92e0b72e076edd000000004a4930460221008ee8d7348aed82a8d074753ab4c8dbdd28a668da821269c4cd0c5c253738cab7022100b06a0208d60af1be6303dd883fd05f964a42f7de317761641ec1158944f52b6b01ffffffff0ecc7b73d8cd5d377d74d836bb6e3473478554a923154286ddaf6985948fd9d300000000494830450221008159ed783bc717ff5a6502cd87a8d8144fae74c6fc6943a5a38da7170203cb3802207e31577a576bc01510cb2280f918a371f63eee44cd2b4490c0994d261787916e01ffffffff78966e9f0a2d4452ab2418249fa6fb1a325a04f039d015899141a82aa5a6c05c000000004847304402206655b13198e413ac8f1aa8926d4617560758cf8b5045afdfc9116da0873ed89802205db55cf3f398467bfc6997f68c881e5f2a7225293ebbd2af40d15df6de4ef87701ffffffff69f2096bbede7015fee2fb307f7d7dd084641b7f4af5c3074dc7b2b6df03277c000000004a493046022100c9199296673a1beae598a6d2348ef13ad1b9f15eebaa825d2282adf017cbb5f0022100b54934e40ff0194a53dcaa9d017c36a93dbb53aa45fe21ab93b07fbb58570d5501ffffffff3c11b146d43fd62ec36b733942a52ba0c352c95a3f078808a38d080898cb83300000000048473044022004c64773b9e6a17cfca7ff583be650104c0538940289b2da8f8bebbd32e486b302200174d8f0938a0f9eeab4c4b137581e032f06d4740e3b0ad9d0423a0a8de65af101ffffffff59ac3c37adfa89b9a907ef9d485c57262e9283e1eb96069c2de04369ef1b3c7600000000494830450220306f3ac72de9dbeb1ec139e4e89cc3b3b9bcb63747bf0e165fcfc773f3669832022100c00a16800f16bf1c71ac6c2989b42d974b0ec2f3e3671325fb2cae52a1c569d801ffffffffb4bbecee818dd986e5ab82f36dbd5ccc29ab134614e304c0a397e14082fe7bb7000000004a493046022100ed68e0303052b41ffd80c1e905cee5547e92422d43b73e473a615e4a47146bb5022100ecab3f92c62477350753b4efea19d608fcce15b1b2c38fbe905e9d1f9ad7631f01ffffffff7546bbac9ae1c8980da6e8c154b368eb4df305b6f3f27ff38f195a13c9ee0484000000004948304502202288566af2b68b6982d1244e293ea3d7c156a425329b7f61b272e4deec317bea022100d9739976b442d35c32830cb2c105e0d7275f7efaa99eaeea4b24a553267a31fc01ffffffffd15854d1e5ba349daf72089f470b24557a2be25105b7831a3f18a62fb8bab677000000004948304502206e3a23075e0248ea8cabc7c875b4cfd9f036c1c4f358a00ec152fc96d1cb6cf8022100d34c018815f63c65f5364061369382b31d579cd6d8a4afe9ec1f03ba66d7717801ffffffffdf686a7f31c2c1de6a608553b26d6336434719fa45428eb3df59bbef75ce9e7e000000004948304502200a22a24a8f817a2f24d3f8c2670f3cb25cd389ce25e0d45eeb0aea08563c5c9802210081ff14edb230a44e5b52e35f573676096a937fc27cc830b153b229b92cac75c101ffffffffd226fea91b99c5a31a034d340f647b722e50950c96a876eb96569efaeaf3b227000000004a4930460221009684e60a7fd61362d0dad79858044aa4a7b878b3f0bd432e384fe4c7e6c90bde0221009883e4f739cffe574bac5bed0a4e69708433973a2490d9415d303614fc31be4701fffffffff640c60ea438dc020048599869836f5323ef47477ee17caddf076ed428898f7100000000494830450220028eb7617dc161a282512c81975d41a1594c05f34cb26fb759682bf784da7071022100a0913abea7229b3c465a4fa32dc861f72ef684e8dd3f19aac5f0f74ea39c03cf01ffffffffd59d2a49b1883c6f7ac68a9d2649dc0dde3f0205e19d8fdaf8065381f9ba61cc000000004a4930460221009f5b27dfd397423a04cab52ee6e8215e290e9666309f0f59f5bc5f6c207d3639022100f5a79133db2cc786140aeee0bf7c8a81adca6071928e8210f1c9f0c653e2f04201ffffffff0240195e29010000001976a914944a7d4b3a8d3a5ecf19dfdfd8dcc18c6f1487dd88acc0c01e49170000001976a91432040178c5cf81cb200ab99af1131f187745b51588ac00000000")
Example #42
0
from coinpy.model.protocol.structures.tx import Tx
from coinpy.model.protocol.structures.outpoint import Outpoint
from coinpy.model.scripts.instruction import Instruction
from coinpy.model.scripts.opcodes import OP_PUSHDATA, OP_CHECKSIG, OP_0
from coinpy.tools.hex import decodehexstr
from coinpy.model.scripts.script import Script
from coinpy.model.protocol.structures.tx_out import TxOut
from coinpy.model.protocol.runmode import MAIN, TESTNET, TESTNET3, UNITNET
from coinpy.lib.vm.script.push_data import push_bignum_instruction,\
    push_data_instruction
from coinpy.lib.transactions.merkle_tree import compute_merkle_root
from coinpy.lib.serialization.scripts.serialize import ScriptSerializer

GENESIS_MAIN =  Block(
    BlockHeader(1, 
                Uint256.from_hexstr("0000000000000000000000000000000000000000000000000000000000000000"), #hash_prev
                Uint256.from_hexstr("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"), #merkle
                1231006505,  #time
                486604799,   #bits
                2083236893), #nonce
    [Tx(1, #version
        [TxIn(Outpoint(Uint256.from_hexstr("0000000000000000000000000000000000000000000000000000000000000000"), 4294967295),     
                Script([push_bignum_instruction(486604799), #bits
                        push_bignum_instruction(4), #extra_nonce
                        push_data_instruction("The Times 03/Jan/2009 Chancellor on brink of second bailout for banks")]), #script
                4294967295) ], #inlist
        [TxOut(5000000000, #value
                Script([push_data_instruction(decodehexstr("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f")),Instruction(OP_CHECKSIG)]))],
                0) #locktime         
     ])
Example #43
0
from coinpy.model.protocol.structures.tx import Tx
from coinpy.model.protocol.structures.outpoint import Outpoint
from coinpy.model.protocol.structures.tx_in import TxIn
from coinpy.model.protocol.structures.uint256 import Uint256
from coinpy.tools.hex import decodehexstr
from coinpy.model.scripts.instruction import Instruction
from coinpy.model.scripts.opcodes import OP_0, OP_CHECKSIG, OP_DUP,\
    OP_EQUALVERIFY, OP_HASH160
from coinpy.model.protocol.structures.blockheader import BlockHeader
from coinpy.model.protocol.structures.block import Block
from coinpy.model.scripts.script import Script
from coinpy.model.protocol.structures.tx_out import TxOut
from coinpy.lib.blocks.hash_block import hash_block

blockchain_5blocks_unitnet = [Block(blockheader=BlockHeader(version=2, 
                          hash_prev=Uint256.from_hexstr("0000000000000000000000000000000000000000000000000000000000000000"), 
                          hash_merkle=Uint256.from_hexstr("cf7ac9a3b387cf5e9fc14e03e2a5bbfc16d1ba00d2af6c96869ab4da949bd240"), 
                          time=1356446436,
                          bits=524287999,
                          nonce=1260), 
                    transactions=[Tx(version=1, 
                in_list=[TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("0000000000000000000000000000000000000000000000000000000000000000"),index=4294967295), 
                   script=Script(instructions=[Instruction(OP_0),Instruction(OP_0),Instruction(6,  decodehexstr("2f503253482f")),Instruction(69,  decodehexstr("5468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73"))]), 
                   sequence=4294967295)], 
                out_list=[TxOut(value=5000000000, 
                    script=Script(instructions=[Instruction(65,  decodehexstr("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f")),Instruction(OP_CHECKSIG)]))], 
                locktime=0)]),
Block(blockheader=BlockHeader(version=2, 
                          hash_prev=Uint256.from_hexstr("003ee3cf880906caa5662f10d4b4fb1c86c1853230dee8a7b8a62f434c73da5f"), 
                          hash_merkle=Uint256.from_hexstr("ef4bfb7cdb962b4d04e3828e4e0a4c09322ae065fa34c2c81ef7d0e0273ec5eb"), 
                          time=1356447036,
Example #44
0
 def test_next_get_genesis(self):
     self.assertEquals(self.database1.get_genesis_hash(),
                       Uint256.from_hexstr("003ee3cf880906caa5662f10d4b4fb1c86c1853230dee8a7b8a62f434c73da5f"))
Example #45
0
 def test_pop_append_block(self):
     self.assertTrue(self.database1.contains_transaction(Uint256.from_hexstr("53bb1c14b4c6156d7352ee471fb7697736f4696accf5392e0f1830e38143f667")))
     block = self.database1.pop_block()
     self.assertFalse(self.database1.contains_transaction(Uint256.from_hexstr("53bb1c14b4c6156d7352ee471fb7697736f4696accf5392e0f1830e38143f667")))
     self.database1.append_block(block)
     self.assertTrue(self.database1.contains_transaction(Uint256.from_hexstr("53bb1c14b4c6156d7352ee471fb7697736f4696accf5392e0f1830e38143f667")))
Example #46
0
    from coinpy.tools.hex import decodehexstr
    from coinpy.model.scripts.instruction import Instruction
    from coinpy.model.scripts.opcodes import OP_CHECKSIG
    from coinpy.model.scripts.opcodes import OP_PUSHDATA
    from coinpy.model.scripts.script import Script
    import struct
    from coinpy.tools.hex import hexstr

    print hexstr(struct.pack("<I", 213566))
    print uint256_difficulty(524287999)
    time_source = SystemTimeSource()
    miner = BitcoinMiner()

    block = miner.mine_block(
        hash_prev=Uint256.from_hexstr(
            "0000000000000000000000000000000000000000000000000000000000000000"
        ),
        block_height=0,
        time_source=time_source,
        difficulty_bits=524287999,
        transactions=[],
        coinbase_txout_list=[
            TxOut(
                5000000000,
                Script([
                    Instruction(
                        OP_PUSHDATA,
                        decodehexstr(
                            "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"
                        )),
                    Instruction(OP_CHECKSIG)
 def test_next_get_genesis(self):
     self.assertEquals(
         self.database1.get_genesis_hash(),
         Uint256.from_hexstr(
             "003ee3cf880906caa5662f10d4b4fb1c86c1853230dee8a7b8a62f434c73da5f"
         ))
 def test_next_get_best_hash(self):
     self.assertEquals(
         self.database1.get_best_hash(),
         Uint256.from_hexstr(
             "002afdfc8ed8111fa00c98bb7b94c34e02a52c57ba971a5fd29935d68fa1060b"
         ))
Example #49
0
    def test_merkletx_deserialize(self):
        # This is tx 37 of block 429 on testnet3
        merkle_tx_data = "0100000001b088b783eddb1471bf99a790a78adf956b57410de2e4829de87f220a5744c888000000006b483045022100813a4dfdfda02946bf9fddc59ffd0b8d2feaa618518a3015fd5e65dd88a0d4480220137b25ea7531e103405bfe1617cb92f524e88c86e66a79c1e3c62558d0195282012103cf163e38520a7b390305528eca2fa1c620f0da225a044017fd92b30067875dc8ffffffff0290900b24010000001976a91410170e3f7c3b0c93d2e07e90e307d3fb2181170288acb58b0d000000000017a914184cd0a38ac3b1357d07179553788375a9e8a3b887000000009ff0cf741383d94f79a6efeff2a317aaf6375ac3d252db55362280e00000000007b088b783eddb1471bf99a790a78adf956b57410de2e4829de87f220a5744c888030d1b4ae01dc5165aa3c3a966dd535032a1ccd5d4722dbf9de57b85a6d65d22fa109a70ffb657a7299604ae344d8432cb37806da51a5840bfcbc2e70290f77434ab33eed85b14302067bc7ee120c49d8ac1c8de22c9cc873f6cf46b8b9d0902cff8e9a5461ef46108e56d3ee115df7cbe39186160a24e8c63d21a7bc402b2157921dea921eeb09cc757cf7ab383e122cca730c51a976e69ce37daaf66217e00d42144297dd9954a62226db7fa2de24cba50b4c963ae6226ae5fa652946dd0a725000000"
        expected_merkle_tx = MerkleTx(
            Tx(version=1,
               in_list=[
                   TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr(
                       "88c844570a227fe89d82e4e20d41576b95df8aa790a799bf7114dbed83b788b0"
                   ),
                                                 index=0),
                        script=Script(instructions=[
                            Instruction(
                                72,
                                decodehexstr(
                                    "3045022100813a4dfdfda02946bf9fddc59ffd0b8d2feaa618518a3015fd5e65dd88a0d4480220137b25ea7531e103405bfe1617cb92f524e88c86e66a79c1e3c62558d019528201"
                                )),
                            Instruction(
                                33,
                                decodehexstr(
                                    "03cf163e38520a7b390305528eca2fa1c620f0da225a044017fd92b30067875dc8"
                                ))
                        ]),
                        sequence=4294967295)
               ],
               out_list=[
                   TxOut(value=4899704976,
                         script=Script(instructions=[
                             Instruction(OP_DUP),
                             Instruction(OP_HASH160),
                             Instruction(
                                 20,
                                 decodehexstr(
                                     "10170e3f7c3b0c93d2e07e90e307d3fb21811702"
                                 )),
                             Instruction(OP_EQUALVERIFY),
                             Instruction(OP_CHECKSIG)
                         ])),
                   TxOut(value=887733,
                         script=Script(instructions=[
                             Instruction(OP_HASH160),
                             Instruction(
                                 20,
                                 decodehexstr(
                                     "184cd0a38ac3b1357d07179553788375a9e8a3b8"
                                 )),
                             Instruction(OP_EQUAL)
                         ]))
               ],
               locktime=0),
            blockhash=Uint256.from_hexstr(
                "00000000e080223655db52d2c35a37f6aa17a3f2efefa6794fd9831374cff09f"
            ),
            merkle_branch=[
                Uint256.from_hexstr(
                    "88c844570a227fe89d82e4e20d41576b95df8aa790a799bf7114dbed83b788b0"
                ),
                Uint256.from_hexstr(
                    "225dd6a6857be59dbf2d72d4d5cca1325053dd66a9c3a35a16c51de04a1b0d03"
                ),
                Uint256.from_hexstr(
                    "74f79002e7c2cbbf40581aa56d8037cb32844d34ae049629a757b6ff709a10fa"
                ),
                Uint256.from_hexstr(
                    "02099d8b6bf46c3f87ccc922dec8c18a9dc420e17ebc672030145bd8ee33ab34"
                ),
                Uint256.from_hexstr(
                    "15b202c47b1ad2638c4ea260611839be7cdf15e13e6de50861f41e46a5e9f8cf"
                ),
                Uint256.from_hexstr(
                    "007e2166afda37ce696e971ac530a7cc22e183b37acf57c79cb0ee21a9de2179"
                ),
                Uint256.from_hexstr(
                    "a7d06d9452a65fae2662ae63c9b450ba4ce22dfab76d22624a95d97d294421d4"
                )
            ],
            nindex=37)

        self.assertEquals(
            MerkleTxSerializer().deserialize(decodehexstr(merkle_tx_data))[0],
            expected_merkle_tx)
Example #50
0
 def test_deserialize_getheaders_message(self):
     serialized_getheaders = decodehexstr("c87d0000016fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d619000000000098a23359c17ca2678e2039c8ff9081b18c4913749c9a081ac3f62958f09fa472")
     getheaders_message, _ = GetheadersMessageSerializer().deserialize(serialized_getheaders)
     expected_message = GetheadersMessage(BlockLocator(32200, [Uint256.from_hexstr("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f")]), 
                                           Uint256.from_hexstr("72a49ff05829f6c31a089a9c7413498cb18190ffc839208e67a27cc15933a298"))
     self.assertEquals(getheaders_message, expected_message)
Example #51
0
 def test_next_in_mainchain(self):
     self.assertEquals(self.database1.get_next_in_mainchain(Uint256.from_hexstr("003ee3cf880906caa5662f10d4b4fb1c86c1853230dee8a7b8a62f434c73da5f")),
                       Uint256.from_hexstr("000cdbffc59b95168c34e5f1853075376308c05c53a1a53425d7f1ca9cab7073"))
     self.assertIs(self.database1.get_next_in_mainchain(Uint256.from_hexstr("002afdfc8ed8111fa00c98bb7b94c34e02a52c57ba971a5fd29935d68fa1060b")),
                   None)
Example #52
0
 def test_deserialize_inv_message(self):
     serialized_inv_message = decodehexstr("020100000055b5d3d496e196d624a471b818ba0b1778417ae335a544033536654fdda3eef602000000497b15826573b28c3e83a5d0c5ed30cf48b97dd6bd797849144ea24000000000")
     inv_message, _ = InvMessageSerializer().deserialize(serialized_inv_message)
     expected_message = InvMessage([Invitem(INV_TX, Uint256.from_hexstr("f6eea3dd4f6536350344a535e37a4178170bba18b871a424d696e196d4d3b555")),
                                    Invitem(INV_BLOCK, Uint256.from_hexstr("0000000040a24e14497879bdd67db948cf30edc5d0a5833e8cb2736582157b49"))])
     self.assertEquals(inv_message, expected_message)
Example #53
0
 def test_next_get_best_hash(self):
     self.assertEquals(self.database1.get_best_hash(),
                       Uint256.from_hexstr("002afdfc8ed8111fa00c98bb7b94c34e02a52c57ba971a5fd29935d68fa1060b"))
Example #54
0
 def test_block_serialize(self):
     blockheader = BlockHeader(
         version=1,
         hash_prev=Uint256.from_hexstr(
             "000000000fec081581146e8b16b275bfa52150ac4174a246cdf62694671ea7a3"
         ),
         hash_merkle=Uint256.from_hexstr(
             "0d9da162550fc45b1aaa00e933b23b3cbc7f37a9b2d2070d61235eaec11a926a"
         ),
         time=1301129903,
         bits=470809215,
         nonce=1280448751)
     tx1 = Tx(
         version=1,
         in_list=[
             TxIn(previous_output=Outpoint.null(),
                  script=Script([
                      Instruction(4, decodehexstr("7ffa0f1c")),
                      Instruction(1, decodehexstr("4e"))
                  ]),
                  sequence=TxIn.NSEQUENCE_FINAL)
         ],
         out_list=[
             TxOut(
                 value=5002000000,
                 script=Script([
                     Instruction(
                         65,
                         decodehexstr(
                             "049cc3cae30927c40598032044b9e9e25f4739b0d7ade62803f5e9cf075debc817e6d29f42c70d0a1beb1c904eaaa50ef885b011f9fbaa16ef288a7ad193e11567"
                         )),
                     Instruction(OP_CHECKSIG)
                 ]))
         ],
         locktime=0)
     tx2 = Tx(
         version=1,
         in_list=[
             TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr(
                 "17c5cb687ba453ab65e12cdc0d8721c70ab4678665eb200c50cb9f1e3207090e"
             ),
                                           index=0),
                  script=Script([
                      Instruction(
                          72,
                          decodehexstr(
                              "3045022100ab2dc8932ca1d26f4cdac1feae09020a60ccc4d17b14e5fc5b21f3ab8c3a9cee022040a7208c172d19a19902280d66201c7fe2c3d8b2df7e23cc4e5b70fd52ecba2c01"
                          )),
                      Instruction(
                          65,
                          decodehexstr(
                              "04b77dd1f3a21cb3d067a7e76982a609d7310f8692f5d61346f3225323c425604a0c12862755335c49e392673106adfc5dfdee1e4d367f10353e8911fac687db3e"
                          ))
                  ]),
                  sequence=TxIn.NSEQUENCE_FINAL)
         ],
         out_list=[
             TxOut(value=24990000000,
                   script=Script([
                       Instruction(OP_DUP),
                       Instruction(OP_HASH160),
                       Instruction(
                           20,
                           decodehexstr(
                               "4d8b17fbce571614be89df4bd872de892a479844")),
                       Instruction(OP_EQUALVERIFY),
                       Instruction(OP_CHECKSIG)
                   ])),
             TxOut(value=5000000000,
                   script=Script([
                       Instruction(OP_DUP),
                       Instruction(OP_HASH160),
                       Instruction(
                           20,
                           decodehexstr(
                               "fadad27c40adbe230f5e3c04d44a292975084831")),
                       Instruction(OP_EQUALVERIFY),
                       Instruction(OP_CHECKSIG)
                   ]))
         ],
         locktime=0)
     blk = Block(blockheader, [tx1, tx2])
     data = BlockSerializer().serialize(blk)
     self.assertEquals(
         data,
         decodehexstr(
             "01000000a3a71e679426f6cd46a27441ac5021a5bf75b2168b6e14811508ec0f000000006a921ac1ae5e23610d07d2b2a9377fbc3c3bb233e900aa1a5bc40f5562a19d0dafaa8d4d7ffa0f1cef18524c0201000000010000000000000000000000000000000000000000000000000000000000000000ffffffff07047ffa0f1c014effffffff018076242a010000004341049cc3cae30927c40598032044b9e9e25f4739b0d7ade62803f5e9cf075debc817e6d29f42c70d0a1beb1c904eaaa50ef885b011f9fbaa16ef288a7ad193e11567ac0000000001000000010e0907321e9fcb500c20eb658667b40ac721870ddc2ce165ab53a47b68cbc517000000008b483045022100ab2dc8932ca1d26f4cdac1feae09020a60ccc4d17b14e5fc5b21f3ab8c3a9cee022040a7208c172d19a19902280d66201c7fe2c3d8b2df7e23cc4e5b70fd52ecba2c014104b77dd1f3a21cb3d067a7e76982a609d7310f8692f5d61346f3225323c425604a0c12862755335c49e392673106adfc5dfdee1e4d367f10353e8911fac687db3effffffff02802385d1050000001976a9144d8b17fbce571614be89df4bd872de892a47984488ac00f2052a010000001976a914fadad27c40adbe230f5e3c04d44a29297508483188ac00000000"
         ))
Example #55
0
from coinpy.model.protocol.structures.uint256 import Uint256
from coinpy.model.protocol.runmode import TESTNET, MAIN, TESTNET3

BLOCKCHAIN_CHECKPOINTS_MAIN = \
{ 11111 :  Uint256.from_hexstr("0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d"),
    33333 :  Uint256.from_hexstr("000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6"),
    68555 :  Uint256.from_hexstr("00000000001e1b4903550a0b96e9a9405c8a95f387162e4944e8d9fbe501cd6a"),
    70567 :  Uint256.from_hexstr("00000000006a49b14bcf27462068f1264c961f11fa2e0eddd2be0791e1d4124a"),
    74000 :  Uint256.from_hexstr("0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20"),
    105000 :  Uint256.from_hexstr("00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97"),
    118000 :  Uint256.from_hexstr("000000000000774a7f8a7a12dc906ddb9e17e75d684f15e00f8767f9e8f36553"),
    134444 :  Uint256.from_hexstr("00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe"),
    140700 :  Uint256.from_hexstr("000000000000033b512028abb90e1626d8b346fd0ed598ac0a3c371138dce2bd")}

BLOCKCHAIN_CHECKPOINTS = {
    MAIN: BLOCKCHAIN_CHECKPOINTS_MAIN,
    TESTNET: {},
    TESTNET3: {}
}


def verify_checkpoints(runmode, height, hash):
    checkpoints = BLOCKCHAIN_CHECKPOINTS[runmode]
    if (height in checkpoints):
        return (hash == checkpoints[height])
    return True


def get_checkpoint(runmode, height):
    checkpoints = BLOCKCHAIN_CHECKPOINTS[runmode]
    return (checkpoints[height])
Example #56
0
if __name__ == '__main__':
    """db = DBBlockChain(MAIN, directory=".")
    if not db.exists():
        print "Creating database"
        db.create(GENESIS)
    else:
        print "Opening database"
        db.open()
    
        version
        hashBestChain"""
    db = DBBlockChain(MAIN, directory="../../data")
    db.open()
    from coinpy.model.protocol.structures.uint256 import Uint256
    print db.indexdb.hashbestchain()
    print db.contains_block(Uint256.from_hexstr("00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048"))
    print db.contains_block(Uint256.from_hexstr("00000000139a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048"))
    it = db.get_block_iterator(Uint256.from_hexstr("000000000000029b4b03122dc75e22952e574ded1ba7caef1fd81c1d11f08e73"))
    print it.get_block()
    print db.indexdb.hashbestchain()
    print db.get_block_iterator(db.indexdb.hashbestchain())
    
    #
    print db.contains_transaction(Uint256.from_hexstr("f8780c27a0af1eb62968a5ab20417f706706f3fa7316775ae0f59850bb757c72"))
    print db.get_transaction_iterator(Uint256.from_hexstr("f8780c27a0af1eb62968a5ab20417f706706f3fa7316775ae0f59850bb757c72"))
    it = db.get_transaction_iterator(Uint256.from_hexstr("f8780c27a0af1eb62968a5ab20417f706706f3fa7316775ae0f59850bb757c72"))
    
    print db.get_block_iterator(db.indexdb.hashbestchain()).get_block()
    #db.addblock("hello")
    #db.load_owner_transactions(owner1)
    #print db.load_txindex(Uint256.from_hexstr("00004b78031f6f406c23cb7d1d0990d56f39107febe8c982a5f75a87254143ea"))