Esempio n. 1
0
 def get_script(self):
     return Script([
         Instruction(OP_DUP),
         Instruction(OP_HASH160),
         push_data_instruction(data=self.pubkey_hash),
         Instruction(OP_EQUALVERIFY),
         Instruction(OP_CHECKSIG)
     ])
Esempio n. 2
0
 def setUp(self):
     self.script1 = Script([
         Instruction(
             33,
             decodehexstr(
                 "02547b223d58eb5da7c7690748f70a3bab1509cb7578faac9032399f0b6bce31d6"
             )),
         Instruction(OP_CHECKSIG)
     ])
Esempio n. 3
0
def make_script_pubkeyhash(pubkey_hash):
    #Improve to take a BitcoinAddress?
    instructions = [
        Instruction(OP_DUP),
        Instruction(OP_HASH160),
        push_data_instruction(data=pubkey_hash),
        Instruction(OP_EQUALVERIFY),
        Instruction(OP_CHECKSIG)
    ]
    return Script(instructions)
Esempio n. 4
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)
Esempio n. 5
0
def push_data_instruction(data):
    l = len(data)
    if l == 0:
        return Instruction(OP_0)
    elif OP_PUSHDATA1_75_MIN <= l <= OP_PUSHDATA1_75_MAX:
        return Instruction(l, data)
    elif l < 0xff:
        return Instruction(OP_PUSHDATA1, data)
    elif l < 0xffff:
        return Instruction(OP_PUSHDATA2, data)
    return Instruction(OP_PUSHDATA4, data)
Esempio n. 6
0
 def test_varstr_script_serialize(self):
     script = Script([
         Instruction(OP_DUP),
         Instruction(OP_HASH160),
         Instruction(
             20, decodehexstr("fadad27c40adbe230f5e3c04d44a292975084831")),
         Instruction(OP_EQUALVERIFY),
         Instruction(OP_CHECKSIG)
     ])
     self.assertEquals(
         hexstr(VarstrScriptSerializer().serialize(script)),
         "1976a914fadad27c40adbe230f5e3c04d44a29297508483188ac")
Esempio n. 7
0
 def test_txout_serialize(self):
     txout = TxOut(
         value=24990000000,
         script=Script([
             Instruction(OP_DUP),
             Instruction(OP_HASH160),
             Instruction(
                 20,
                 decodehexstr("4d8b17fbce571614be89df4bd872de892a479844")),
             Instruction(OP_EQUALVERIFY),
             Instruction(OP_CHECKSIG)
         ]))
     self.assertEquals(
         hexstr(TxoutSerializer().serialize(txout)),
         "802385d1050000001976a9144d8b17fbce571614be89df4bd872de892a47984488ac"
     )
Esempio n. 8
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"
            ))
Esempio n. 9
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"
     )
Esempio n. 10
0
def parse_instruction(inst_str):
    serializer = InstructionSerializer()
    if re.match("^-?[0-9]+$", inst_str):
        i = int(inst_str)
        if (i == -1 or (1 <= i <= 16)):
            return serializer.serialize(Instruction(i + OP_1 - 1))
        else:
            return serializer.serialize(push_bignum_instruction(i))
        return serializer.serialize(push_bignum_instruction(i))
    if re.match("^'[^']*'$", inst_str):
        return serializer.serialize(push_data_instruction(str(inst_str[1:-1])))
    elif re.match("^0x[0-9A-Fa-f]+$", inst_str):
        return decodehexstr(inst_str[2:])
    elif inst_str in OPCODES_BY_NAME:
        return serializer.serialize(Instruction(OPCODES_BY_NAME[inst_str]))
    elif ("OP_" + inst_str) in OPCODES_BY_NAME:
        return serializer.serialize(
            Instruction(OPCODES_BY_NAME["OP_" + inst_str]))
    raise Exception("Wrong format: '" + inst_str + "'")
Esempio n. 11
0
 def setUp(self):
     self.script1 = Script([Instruction(OP_2),
                            Instruction(33, decodehexstr("02547b223d58eb5da7c7690748f70a3bab1509cb7578faac9032399f0b6bce31d6")),
                            Instruction(33, decodehexstr("c47a2dbbfb38f02205a3a72a37c68a8c068fe71a1351516f0f1fe7dd3c7afce38f")),
                            Instruction(33, decodehexstr("9f1de01000000fd45010047304402200983ab9c46fd1194e541c683828bbb92ce9")),
                            Instruction(OP_3),
                            Instruction(OP_CHECKMULTISIG)])
Esempio n. 12
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"
     )
Esempio n. 13
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"
         ))
Esempio n. 14
0
    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,
                          bits=524287999,
                          nonce=905), 
                    transactions=[Tx(version=1, 
                in_list=[TxIn(previous_output=Outpoint(hash=Uint256.from_hexstr("0000000000000000000000000000000000000000000000000000000000000000"),index=4294967295), 
                   script=Script(instructions=[Instruction(1,  decodehexstr("01")),Instruction(OP_0),Instruction(6,  decodehexstr("2f503253482f"))]), 
                   sequence=4294967295)], 
                out_list=[TxOut(value=5000000000, 
Esempio n. 15
0
 def deserialize(self, data, cursor=0):
     op = ord(data[cursor])
     if is_pushdata_with_param(op):
         return (self._deserialize_pushdata(data, cursor))
     return (Instruction(op), cursor + 1)
Esempio n. 16
0
def push_smallint(i):
    return Instruction(OP_1 + i - 1)
Esempio n. 17
0
    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)
                ]))
        ],
        coinbase_flags=[])
    print block
Esempio n. 18
0
 def _deserialize_pushdata_data(self, op, datalength, data, pos):
     if (len(data) < pos + datalength):
         raise MissingDataException("pushdata data required %d bytes remaining %d " % (datalength, len(data)-pos))
     return (Instruction(op, data[pos:pos+datalength]), pos+datalength)
Esempio n. 19
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"
         ))
Esempio n. 20
0
 def get_script(self):
     return Script([
         Instruction(OP_HASH160),
         push_data_instruction(data=self.hash),
         Instruction(OP_EQUAL)
     ])
Esempio n. 21
0
 def get_script(self):
     return Script([
         push_data_instruction(data=self.pubkey),
         Instruction(OP_CHECKSIG)
     ])
Esempio n. 22
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)
Esempio n. 23
0
def make_script_pubkey(pubkey):
    instructions = [
        push_data_instruction(data=pubkey),
        Instruction(OP_CHECKSIG)
    ]
    return Script(instructions)
Esempio n. 24
0
 def get_script(self):
     return Script(
         [push_smallint(self.m)] +
         [push_data_instruction(pubkey) for pubkey in self.public_keys] +
         [push_smallint(len(self.public_keys))] +
         [Instruction(OP_CHECKMULTISIG)])
Esempio n. 25
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)