Esempio n. 1
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. 2
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)
Esempio n. 3
0
def create_pubkeyhash_transaction(output_list, address, change_adress, amount,
                                  fee):
    amount_in = sum(txout.value for outpoint, txout in output_list)
    amount_change = int(amount_in - amount - fee)
    #assert amount_change > 0
    in_list = [
        TxIn(previous_output=outpoint, script=Script([]))
        for outpoint, txout in output_list
    ]
    out_list = [
        TxOut(value=amount, script=make_script_pubkeyhash(address)),
        TxOut(value=amount_change,
              script=make_script_pubkeyhash(change_adress))
    ]
    return Tx(version=1, in_list=in_list, out_list=out_list, locktime=0)
Esempio n. 4
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. 5
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. 6
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. 7
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. 8
0
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, 
                    script=Script(instructions=[Instruction(33,  decodehexstr("026c692c42022ebbd12019bbf50051e1640688ec0ae49044ddf3dc42693bcdf5bd")),Instruction(OP_CHECKSIG)]))], 
                locktime=0)]),
Block(blockheader=BlockHeader(version=2, 
Esempio n. 9
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. 10
0
 def deserialize(self, data, cursor=0):
     (value, script), cursor = self.TXOUT.deserialize(data, cursor)
     return (TxOut(value, script), cursor)
Esempio n. 11
0
def checksig(vm, sig_param, pubkey_param):
    transaction, inputindex, unspent_script = vm.checksig_data
    #Hash type is the last byte of the signature
    hash_type, sig = ord(sig_param[-1]), sig_param[:-1]

    # last 5 bits of hash_type : 1=SIGHASH_ALL,2=SIGHASH_NONE, 3=SIGHASH_SINGLE
    # SIGHASH_ANYONECANPAY = 0x80

    # For performance reasons no full copy is made of the transaction
    # although it would be simpler to read.
    # e.g. tx_tmp = copy.deepcopy(transaction)
    # The input scripts are saved and then restored.
    tx_tmp = Tx(transaction.version, [
        TxIn(txin.previous_output, txin.script, txin.sequence)
        for txin in transaction.in_list
    ], [TxOut(txout.value, txout.script) for txout in transaction.out_list],
                transaction.locktime)
    #Save input scripts to restore them later
    #inlist = transaction.in_list
    #outlist = transaction.out_list
    #inscripts = [txin.script for txin in transaction.in_list]
    #TODO: blank out ouputs depending of hash_type (SIGHASH_NONE, SIGHASH_SINGLE)
    if (hash_type & SIGHASH_MASK == SIGHASH_NONE):
        tx_tmp.out_list = []
    if (hash_type & SIGHASH_MASK == SIGHASH_SINGLE):
        if (inputindex > len(tx_tmp.out_list)):
            raise Exception(
                "OP_CHECKSIG: no corresponding output for input %d using SIGHASH_SINGLE "
                % (inputindex))
        #n-1 empty TxOuts + original Txout
        tx_tmp.out_list = [TxOut(-1, Script([])) for _ in range(inputindex)] + \
                          [tx_tmp.out_list[inputindex]]
    if (hash_type & SIGHASH_MASK == SIGHASH_SINGLE
            or hash_type & SIGHASH_MASK == SIGHASH_NONE):
        # let others update at will
        for i in range(len(tx_tmp.in_list)):
            if i != inputindex:
                tx_tmp.in_list[i].sequence = 0
    #blank out other inputs in case of SIGHASH_ANYONECANPAY
    if (hash_type & SIGHASH_ANYONECANPAY):
        tx_tmp.in_list = [tx_tmp.in_list[inputindex]]
        inputindex = 0
    #blank out input scripts
    for txin in tx_tmp.in_list:
        txin.script = Script([])
    #except the current one that is replaced by the signed part (e.g. from the last OP_CODESEPARATOR)
    # of current_script with signature push_data removed
    # note: only 'optimal' push_data instructions with the same signature are removed
    current_script = Script(
        filter(lambda instr: instr != push_data_instruction(sig_param),
               vm.current_script.signed_part().instructions))
    tx_tmp.in_list[inputindex].script = current_script
    #serialize and append hash type
    enctx = TxSerializer().serialize(tx_tmp) + chr(hash_type) + b"\x00\x00\x00"

    #print "enctx:", hexstr(enctx)
    #print "sig:", hexstr(sig)
    #print "pubkey:", hexstr(pubkey_param)

    #Get hash
    hash = doublesha256(enctx)
    #Verify
    key = KEY()
    key.set_pubkey(pubkey_param)
    #ECDSA_verify: 1 = OK, 0=NOK, -1=ERROR
    result = key.verify(hash, sig) == 1
    if not result:
        pass
    #Restore transaction scripts
    #for txin, script in zip(inlist,inscripts):
    #    txin.script = script
    #transaction.in_list = inlist
    return (result)
Esempio n. 12
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. 13
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"
         ))