Ejemplo n.º 1
0
    def test_version_bytes(self):
        xprv_headers_b58 = {
            'standard': 'tprv',
        }
        xpub_headers_b58 = {
            'standard': 'tpub',
        }
        for xtype, xkey_header_bytes in constants.net.XPRV_HEADERS.items():
            xkey_header_bytes = bfh("%08x" % xkey_header_bytes)
            xkey_bytes = xkey_header_bytes + bytes([0] * 74)
            xkey_b58 = EncodeBase58Check(xkey_bytes)
            self.assertTrue(xkey_b58.startswith(xprv_headers_b58[xtype]))

            xkey_bytes = xkey_header_bytes + bytes([255] * 74)
            xkey_b58 = EncodeBase58Check(xkey_bytes)
            self.assertTrue(xkey_b58.startswith(xprv_headers_b58[xtype]))

        for xtype, xkey_header_bytes in constants.net.XPUB_HEADERS.items():
            xkey_header_bytes = bfh("%08x" % xkey_header_bytes)
            xkey_bytes = xkey_header_bytes + bytes([0] * 74)
            xkey_b58 = EncodeBase58Check(xkey_bytes)
            self.assertTrue(xkey_b58.startswith(xpub_headers_b58[xtype]))

            xkey_bytes = xkey_header_bytes + bytes([255] * 74)
            xkey_b58 = EncodeBase58Check(xkey_bytes)
            self.assertTrue(xkey_b58.startswith(xpub_headers_b58[xtype]))
Ejemplo n.º 2
0
 def test_axe_tx_pro_up_serv_tx(self):
     tx = transaction.Transaction(PRO_UP_SERV_TX)
     deser = tx.deserialize()
     assert deser['version'] == 3
     assert deser['tx_type'] == 2
     extra = deser['extra_payload']
     assert (str(extra))
     assert extra.version == 1
     assert len(extra.proTxHash) == 32
     assert extra.proTxHash == bfh(
         '3c6dca244f49f19d3f09889753ffff1fec5bb8f9f5bd5bc09dabd999da21198f')
     assert extra.ipAddress == '95.183.53.128'
     assert extra.port == 10001
     assert extra.scriptOperatorPayout == bfh(
         '76a91421851058431a7d722e8e8dd9509e7f2b8e7042ec88ac')
     assert len(extra.inputsHash) == 32
     assert extra.inputsHash == bfh(
         'efcfe3d578914bb48c6bd71b3459d384e4237446d521c9e2c6'
         'b6fcf019b5aafc')
     assert len(extra.payloadSig) == 96
     assert extra.payloadSig == bfh(
         '99443fe14f644cfa47086e8897cf7b546a67723d4a8ec5353a82f962a96e'
         'c3cea328343b647aace2897d6eddd0b8c8ee0f2e56f6733aed2e9f0006ca'
         'afa6fc21c18a013c619d6e37af8d2f0985e3b769abc38ffa60e46c365a38'
         'd9fa0d44fd62')
     ser = tx.serialize()
     assert ser == PRO_UP_SERV_TX
Ejemplo n.º 3
0
 def test_axe_tx_sub_tx_reset_key(self):
     tx = transaction.Transaction(SUB_TX_RESET_KEY)
     deser = tx.deserialize()
     assert deser['version'] == 3
     assert deser['tx_type'] == 10
     extra = deser['extra_payload']
     assert (str(extra))
     assert extra.version == 1
     assert len(extra.regTxHash) == 32
     assert extra.regTxHash == bfh(
         'd384e42374e8abfeffffff01570b000000a40100b67ffbbd095de31ea3844675')
     assert len(extra.hashPrevSubTx) == 32
     assert extra.hashPrevSubTx == bfh(
         'af3e98e9601210293360bf2a2e810673412bc6e8e0e358f3fb7bdbe9a667b3d0')
     assert extra.creditFee == 1000
     assert len(extra.newPubKey) == 48
     assert extra.newPubKey == bfh(
         '601210293360bf2a2e810673412bc6e8e0e358f3fb7bdbe9a667b3d0103f7'
         '61caf3e98e9601210293360bf2a2e810673')
     assert len(extra.payloadSig) == 96
     assert extra.payloadSig == bfh(
         '412bc6e8e0e358f3fb7bdbe9a667b3d0103f761caf3e98e9601210293360b'
         'f2a2e810673412bc6e8e0e358f3fb7bdbe9a667b3d0103f761caf3e98e960'
         '1210293360bf2a2e810673412bc6e8e0e358f3fb7bdbe9a667b3d0103f761'
         'cabcdefab')
     ser = tx.serialize()
     assert ser == SUB_TX_RESET_KEY
Ejemplo n.º 4
0
 def test_verify_fail_f_tx_even(self):
     """Raise if inner node of merkle branch is valid tx. ('even' fake leaf position)"""
     # last 32 bytes of T encoded as hash
     fake_branch_node = hash_encode(bfh(VALID_64_BYTE_TX[64:]))
     fake_mbranch = [fake_branch_node] + MERKLE_BRANCH
     # first 32 bytes of T encoded as hash
     f_tx_hash = hash_encode(bfh(VALID_64_BYTE_TX[:64]))
     with self.assertRaises(InnerNodeOfSpvProofIsValidTx):
         SPV.hash_merkle_root(fake_mbranch, f_tx_hash, 6)
Ejemplo n.º 5
0
 def parse_script(self, x):
     script = ''
     for word in x.split():
         if word[0:3] == 'OP_':
             opcode_int = opcodes[word]
             assert opcode_int < 256  # opcode is single-byte
             script += bitcoin.int_to_hex(opcode_int)
         else:
             bfh(word)  # to test it is hex data
             script += push_script(word)
     return script
Ejemplo n.º 6
0
    def test_verify(self):
        announce = MasternodeAnnounce.deserialize(raw_announce)
        message = announce.serialize_for_sig()

        pk = bitcoin.public_key_to_p2pkh(bfh(announce.collateral_key))
        self.assertTrue(announce.verify())

        raw = '7ca6564432d0e0920b811887e1f9077a92924c83564e6ea8ea874fc8843ccd2b0000000000ffffffff00000000000000000000ffffc0a801014e1f410411e2638aeb4584ff2e027b6ee20e05655ff05583185b1d87188185d6955534fe02ad35caabb5e6e9ce8747ba73fdccccd2369feb9a6f2b0bdee93378e7c8f1c0410411e2638aeb4584ff2e027b6ee20e05655ff05583185b1d87188185d6955534fe02ad35caabb5e6e9ce8747ba73fdccccd2369feb9a6f2b0bdee93378e7c8f1c0411bab132617d8e6a0e3b5434c91a5a64ff13a9cfadc6c178a47b87691f13a26e7440c08660e488ddf927bba1bf04c1ec196370452a30fd3381ea8ba27d627f9d4468be80e5700000000d71101007ca6564432d0e0920b811887e1f9077a92924c83564e6ea8ea874fc8843ccd2b0000000000ffffffffd75eb4fa0cb71dd2e99d7b242784a5601c5c86d7c1cf0362a3391575070000008be80e5700000000411b6d5985008e0821c936fafc192f31963141ae2fab837e84bb9f12422711c1952d5750f9a781c89117a6f4576edc1149a1bf211e7151c5c88cf3252e2d83cb154a0000000000000000'
        announce = MasternodeAnnounce.deserialize(raw)
        msg = announce.serialize_for_sig()

        pk = bitcoin.public_key_to_p2pkh(bfh(announce.collateral_key))
        self.assertTrue(announce.verify(pk))
Ejemplo n.º 7
0
 def parse_script(self, x):
     from electrum_axe.transaction import opcodes, push_script
     script = ''
     for word in x.split():
         if word[0:3] == 'OP_':
             assert word in opcodes.lookup
             opcode_int = opcodes.lookup[word]
             assert opcode_int < 256  # opcode is single-byte
             script += bitcoin.int_to_hex(opcode_int)
         else:
             bfh(word)  # to test it is hex data
             script += push_script(word)
     return script
Ejemplo n.º 8
0
 def f(x_pubkey):
     if is_xpubkey(x_pubkey):
         xpub, s = parse_xpubkey(x_pubkey)
     else:
         xpub = xpub_from_pubkey(0, bfh(x_pubkey))
         s = []
     return self._make_node_path(xpub, s)
Ejemplo n.º 9
0
 def get_noise_map(cls, versioned_seed: VersionedSeed) -> Dict[Tuple[int, int], int]:
     """Returns a map from (x,y) coordinate to pixel value 0/1, to be used as rawnoise."""
     w, h = cls.SIZE
     version  = versioned_seed.version
     hex_seed = versioned_seed.seed
     checksum = versioned_seed.checksum
     noise_map = {}
     if version == '0':
         random.seed(int(hex_seed, 16))
         for x in range(w):
             for y in range(h):
                 noise_map[(x, y)] = random.randint(0, 1)
     elif version == '1':
         prng_seed = bfh(hex_seed + version + checksum)
         drbg = DRBG(prng_seed)
         num_noise_bytes = 1929  # ~ w*h
         noise_array = bin(int.from_bytes(drbg.generate(num_noise_bytes), 'big'))[2:]
         # there's an approx 1/1024 chance that the generated number is 'too small'
         # and we would get IndexError below. easiest backwards compat fix:
         noise_array += '0' * (w * h - len(noise_array))
         i = 0
         for x in range(w):
             for y in range(h):
                 noise_map[(x, y)] = int(noise_array[i])
                 i += 1
     else:
         raise Exception(f"unexpected revealer version: {version}")
     return noise_map
Ejemplo n.º 10
0
    def do_send(self, tx):
        def on_success(result):
            window.show_message(
                _("Your transaction was sent to the cosigning pool.") + '\n' +
                _("Open your cosigner wallet to retrieve it."))

        def on_failure(exc_info):
            e = exc_info[1]
            try:
                self.logger.error("on_failure", exc_info=exc_info)
            except OSError:
                pass
            window.show_error(
                _("Failed to send transaction to cosigning pool") + ':\n' +
                str(e))

        for window, xpub, K, _hash in self.cosigner_list:
            if not self.cosigner_can_sign(tx, xpub):
                continue
            # construct message
            raw_tx_bytes = bfh(str(tx))
            public_key = ecc.ECPubkey(K)
            message = public_key.encrypt_message(raw_tx_bytes).decode('ascii')
            # send message
            task = lambda: server.put(_hash, message)
            msg = _('Sending transaction to cosigning pool...')
            WaitingDialog(window, msg, task, on_success, on_failure)
Ejemplo n.º 11
0
    def test_create_and_sign(self):
        collateral_pub = '0218864d879997fefbb2846e54ac4db0df99029b91cd12be32312d7e0da45029a8'  # PUFpXCipFhCM1n3CvY1pdJnsuBYGXopNoZ
        delegate_pub = '0329e04e958045a2866e59d13423772e16551cc1bedc50adb0e10b33ae28146cfc'  # P9h6zCz253jmc4TvqgKPRNpkx5qELdNWWT
        protocol_version = 70103

        ip = '0.0.0.0'
        port = 20000
        addr = NetworkAddress(ip=ip, port=port)

        vin = {
            'prevout_hash': '00' * 32,
            'prevout_n': 0,
            'scriptSig': '',
            'sequence': 0xffffffff
        }

        last_ping = MasternodePing(vin=vin, block_hash='ff' * 32)

        announce = MasternodeAnnounce(vin=vin,
                                      addr=addr,
                                      collateral_key=collateral_pub,
                                      delegate_key=delegate_pub,
                                      protocol_version=protocol_version,
                                      last_ping=last_ping)

        collateral_wif = 'XDL8kYsDheEviC7EYMNbo3Myy1txzKyfhZFZBaYUSPDPm9BZZae8'
        delegate_wif = 'XFsDL1FgC4VWQWZQu1NZAs5ri1rUP8mu1CviQYBbXedBTK37uppF'
        announce.last_ping.sign(delegate_wif, bfh(delegate_pub), 1461858375)
        sig = announce.sign(collateral_wif, 1461858375)

        address = 'PUFpXCipFhCM1n3CvY1pdJnsuBYGXopNoZ'
        self.assertTrue(announce.verify(address))
        self.assertTrue(
            ecc.verify_message_with_address(address, sig,
                                            announce.serialize_for_sig()))
Ejemplo n.º 12
0
 def show_qr(self):
     text = bfh(str(self.tx))
     text = base_encode(text, base=43)
     try:
         self.main_window.show_qrcode(text, 'Transaction', parent=self)
     except Exception as e:
         self.show_message(str(e))
Ejemplo n.º 13
0
 def test_base58(self):
     data_hex = '0cd394bef396200774544c58a5be0189f3ceb6a41c8da023b099ce547dd4d8071ed6ed647259fba8c26382edbf5165dfd2404e7a8885d88437db16947a116e451a5d1325e3fd075f9d370120d2ab537af69f32e74fc0ba53aaaa637752964b3ac95cfea7'
     data_bytes = bfh(data_hex)
     data_base58 = base_encode(data_bytes, 58)
     self.assertEqual("VuvZ2K5UEcXCVcogny7NH4Evd9UfeYipsTdWuU4jLDhyaESijKtrGWZTFzVZJPjaoC9jFBs3SFtarhDhQhAxkXosUD8PmUb5UXW1tafcoPiCp8jHy7Fe2CUPXAbYuMvAyrkocbe6",
                      data_base58)
     self.assertEqual(data_bytes,
                      base_decode(data_base58, None, 58))
Ejemplo n.º 14
0
 def test_axe_tx_cb_tx_v2(self):
     tx = transaction.Transaction(CB_TX_V2)
     deser = tx.deserialize()
     assert deser['version'] == 3
     assert deser['tx_type'] == 5
     extra = deser['extra_payload']
     assert (str(extra))
     assert extra.version == 2
     assert extra.height == 264132
     assert len(extra.merkleRootMNList) == 32
     assert extra.merkleRootMNList == bfh(
         '76629a6e42fb519188f65889fd3ac0201be87aa227462b5643e8bb2ec1d7a82a')
     assert len(extra.merkleRootQuorums) == 32
     assert extra.merkleRootQuorums == bfh(
         '76629a6e42fb519188f65889fd3ac0201be87aa227462b5643e8bb2ec1d7a82a')
     ser = tx.serialize()
     assert ser == CB_TX_V2
Ejemplo n.º 15
0
 def test_base43(self):
     tx_hex = "020000000001021cd0e96f9ca202e017ca3465e3c13373c0df3a4cdd91c1fd02ea42a1a65d2a410000000000fdffffff757da7cf8322e5063785e2d8ada74702d2648fa2add2d533ba83c52eb110df690200000000fdffffff02d07e010000000000160014b544c86eaf95e3bb3b6d2cabb12ab40fc59cad9ca086010000000000232102ce0d066fbfcf150a5a1bbc4f312cd2eb080e8d8a47e5f2ce1a63b23215e54fb5ac02483045022100a9856bf10a950810abceeabc9a86e6ba533e130686e3d7863971b9377e7c658a0220288a69ef2b958a7c2ecfa376841d4a13817ed24fa9a0e0a6b9cb48e6439794c701210324e291735f83ff8de47301b12034950b80fa4724926a34d67e413d8ff8817c53024830450221008f885978f7af746679200ed55fe2e86c1303620824721f95cc41eb7965a3dfcf02207872082ac4a3c433d41a203e6d685a459e70e551904904711626ac899238c20a0121023d4c9deae1aacf3f822dd97a28deaec7d4e4ff97be746d124a63d20e582f5b290a971600"
     tx_bytes = bfh(tx_hex)
     tx_base43 = base_encode(tx_bytes, 43)
     self.assertEqual("3E2DH7.J3PKVZJ3RCOXQVS3Y./6-WE.75DDU0K58-0N1FRL565N8ZH-DG1Z.1IGWTE5HK8F7PWH5P8+V3XGZZ6GQBPHNDE+RD8CAQVV1/6PQEMJIZTGPMIJ93B8P$QX+Y2R:TGT9QW8S89U4N2.+FUT8VG+34USI/N/JJ3CE*KLSW:REE8T5Y*9:U6515JIUR$6TODLYHSDE3B5DAF:5TF7V*VAL3G40WBOM0DO2+CFKTTM$G-SO:8U0EW:M8V:4*R9ZDX$B1IRBP9PLMDK8H801PNTFB4$HL1+/U3F61P$4N:UAO88:N5D+J:HI4YR8IM:3A7K1YZ9VMRC/47$6GGW5JEL1N690TDQ4XW+TWHD:V.1.630QK*JN/.EITVU80YS3.8LWKO:2STLWZAVHUXFHQ..NZ0:.J/FTZM.KYDXIE1VBY7/:PHZMQ$.JZQ2.XT32440X/HM+UY/7QP4I+HTD9.DUSY-8R6HDR-B8/PF2NP7I2-MRW9VPW3U9.S0LQ.*221F8KVMD5ANJXZJ8WV4UFZ4R.$-NXVE+-FAL:WFERGU+WHJTHAP",
                      tx_base43)
     self.assertEqual(tx_bytes,
                      base_decode(tx_base43, None, 43))
Ejemplo n.º 16
0
 def test_base58check(self):
     data_hex = '0cd394bef396200774544c58a5be0189f3ceb6a41c8da023b099ce547dd4d8071ed6ed647259fba8c26382edbf5165dfd2404e7a8885d88437db16947a116e451a5d1325e3fd075f9d370120d2ab537af69f32e74fc0ba53aaaa637752964b3ac95cfea7'
     data_bytes = bfh(data_hex)
     data_base58check = EncodeBase58Check(data_bytes)
     self.assertEqual("4GCCJsjHqFbHxWbFBvRg35cSeNLHKeNqkXqFHW87zRmz6iP1dJU9Tk2KHZkoKj45jzVsSV4ZbQ8GpPwko6V3Z7cRfux3zJhUw7TZB6Kpa8Vdya8cMuUtL5Ry3CLtMetaY42u52X7Ey6MAH",
                      data_base58check)
     self.assertEqual(data_bytes,
                      DecodeBase58Check(data_base58check))
Ejemplo n.º 17
0
 def show_qr(self):
     from electrum_axe.bitcoin import base_encode, bfh
     raw_tx = str(self.tx)
     text = bfh(raw_tx)
     text = base_encode(text, base=43)
     self.app.qr_dialog(_("Raw Transaction"),
                        text,
                        text_for_clipboard=raw_tx)
Ejemplo n.º 18
0
 def f(x_pubkey):
     if is_xpubkey(x_pubkey):
         xpub, s = parse_xpubkey(x_pubkey)
     else:
         xpub = xpub_from_pubkey(0, bfh(x_pubkey))
         s = []
     node = self.ckd_public.deserialize(xpub)
     return self.types.HDNodePathType(node=node,
                                      address_n=s)
Ejemplo n.º 19
0
    def data(self, index, role = Qt.DisplayRole):
        data = None
        if not index.isValid():
            return QVariant(data)
        if role not in [Qt.DisplayRole, Qt.EditRole, Qt.ToolTipRole, Qt.FontRole, Qt.BackgroundRole]:
            return None

        mn = self.masternodes[index.row()]
        i = index.column()

        if i == self.ALIAS:
            data = mn.alias
        elif i == self.STATUS:
            status = self.manager.masternode_statuses.get(mn.get_collateral_str())
            data = masternode_status(status)
            if role == Qt.BackgroundRole:
                data = QBrush(QColor(ENABLED_MASTERNODE_BG)) if data[0] else None
            # Return the long description for data widget mappers.
            elif role == Qt.EditRole:
                data = data[2]
            else:
                data = data[1]
        elif i == self.VIN:
            txid = mn.vin.get('prevout_hash', '')
            out_n = str(mn.vin.get('prevout_n', ''))
            addr = mn.vin.get('address', '')
            value = str(mn.vin.get('value', ''))
            scriptsig = mn.vin.get('scriptSig', '')
            if role == Qt.EditRole:
                data = ':'.join([txid, out_n, addr, value, scriptsig])
            elif role == Qt.FontRole:
                data = util.MONOSPACE_FONT
            else:
                if all(attr for attr in [txid, out_n, addr]):
                    data = '%s:%s' % (txid, out_n)
                else:
                    data = ''
        elif i == self.COLLATERAL:
            data = mn.collateral_key
            if role in [Qt.EditRole, Qt.DisplayRole, Qt.ToolTipRole] and data:
                data = bitcoin.public_key_to_p2pkh(bfh(data))
            elif role == Qt.FontRole:
                data = util.MONOSPACE_FONT
        elif i == self.DELEGATE:
            data = mn.delegate_key
            if role in [Qt.EditRole, Qt.DisplayRole, Qt.ToolTipRole] and data:
                data = self.manager.get_delegate_privkey(data)
            elif role == Qt.FontRole:
                data = util.MONOSPACE_FONT
        elif i == self.ADDR:
            data = ''
            if mn.addr.ip:
                data = str(mn.addr)
        elif i == self.PROTOCOL_VERSION:
            data = mn.protocol_version

        return QVariant(data)
Ejemplo n.º 20
0
 def show_qr(self):
     text = bfh(str(self.tx))
     text = base_encode(text, base=43)
     try:
         self.main_window.show_qrcode(text, 'Transaction', parent=self)
     except qrcode.exceptions.DataOverflowError:
         self.show_error(_('Failed to display QR code.') + '\n' +
                         _('Transaction is too large in size.'))
     except Exception as e:
         self.show_error(_('Failed to display QR code.') + '\n' + str(e))
Ejemplo n.º 21
0
def trezor_validate_op_return_output_and_get_data(output: TxOutput) -> bytes:
    if output.type != TYPE_SCRIPT:
        raise Exception("Unexpected output type: {}".format(output.type))
    script = bfh(output.address)
    if not (script[0] == opcodes.OP_RETURN and
            script[1] == len(script) - 2 and script[1] <= 75):
        raise UserFacingException(_("Only OP_RETURN scripts, with one constant push, are supported."))
    if output.value != 0:
        raise UserFacingException(_("Amount for OP_RETURN output must be zero."))
    return script[2:]
Ejemplo n.º 22
0
 def test_axe_tx_sub_tx_register(self):
     tx = transaction.Transaction(SUB_TX_REGISTER)
     deser = tx.deserialize()
     assert deser['version'] == 3
     assert deser['tx_type'] == 8
     extra = deser['extra_payload']
     assert extra.version == 1
     assert extra.userName == b'abc'
     assert len(extra.pubKey) == 48
     assert extra.pubKey == bfh(
         '8e7042ec88acefcfe3d578914bb48c6bd71b3459d384e42374e8abfeffff'
         'ff01570b0000000000001976a91490c5ce9d')
     assert len(extra.payloadSig) == 96
     assert extra.payloadSig == bfh(
         '8bc992a88ac00000000a40100b67ffbbd095de31ea38446754e8abfeffff'
         'ff01570b0000000000001976a91490c5ce9d8bc992a88ac00000000a4010'
         '0b67ffbbd095de31ea38446754e8abfeffffff01570b0000000000001976'
         'a91490c5ce9d')
     ser = tx.serialize()
     assert ser == SUB_TX_REGISTER
Ejemplo n.º 23
0
    def test_serialize_protocol_version_70210(self):
        announce = MasternodeAnnounce.deserialize(raw_announce_70210)
        msg = announce.serialize_for_sig()
        expected = to_bytes(''.join([
            '178.151.192.107:19999',
            '1530021571',
            bitcoin.hash_encode(
                bitcoin.hash_160(
                    bfh('0221088c51bef8c9c891b385fa1e8a78b016f01db41741aea7e43e67a7415ab7be'
                        ))),
            bitcoin.hash_encode(
                bitcoin.hash_160(
                    bfh('042379a871a10ae6bf06e756262f69d7f0ce9b8b562f223bde964db573fb7d0f1e219c246a4b3a6133c5cec136d83f4049df51321ba2cb01d676cc3982c7e24d1f'
                        ))),
            '70210',
        ]))
        print('7' * 50, expected)
        print('8' * 50, msg)

        self.assertEqual(expected, msg)
Ejemplo n.º 24
0
    def tx_inputs(self, tx, xpub_path, for_sig=False):
        inputs = []
        for txin in tx.inputs():
            txinputtype = TxInputType()
            if txin['type'] == 'coinbase':
                prev_hash = b"\x00" * 32
                prev_index = 0xffffffff  # signed int -1
            else:
                if for_sig:
                    x_pubkeys = txin['x_pubkeys']
                    xpubs = [parse_xpubkey(x) for x in x_pubkeys]
                    multisig = self._make_multisig(txin.get('num_sig'), xpubs,
                                                   txin.get('signatures'))
                    script_type = self.get_trezor_input_script_type(
                        txin['type'])
                    txinputtype = TxInputType(script_type=script_type,
                                              multisig=multisig)
                    # find which key is mine
                    for xpub, deriv in xpubs:
                        if xpub in xpub_path:
                            xpub_n = parse_path(xpub_path[xpub])
                            txinputtype.address_n = xpub_n + deriv
                            break

                prev_hash = bfh(txin['prevout_hash'])
                prev_index = txin['prevout_n']

            if 'value' in txin:
                txinputtype.amount = txin['value']
            txinputtype.prev_hash = prev_hash
            txinputtype.prev_index = prev_index

            if txin.get('scriptSig') is not None:
                script_sig = bfh(txin['scriptSig'])
                txinputtype.script_sig = script_sig

            txinputtype.sequence = txin.get('sequence', 0xffffffff - 1)

            inputs.append(txinputtype)

        return inputs
Ejemplo n.º 25
0
 def electrum_tx_to_txtype(self, tx):
     t = self.types.TransactionType()
     d = deserialize(tx.raw)
     t.version = d['version']
     t.lock_time = d['lockTime']
     inputs = self.tx_inputs(tx)
     t.inputs.extend(inputs)
     for vout in d['outputs']:
         o = t.bin_outputs.add()
         o.amount = vout['value']
         o.script_pubkey = bfh(vout['scriptPubKey'])
     return t
Ejemplo n.º 26
0
 def test_axe_tx_sub_tx_topup(self):
     tx = transaction.Transaction(SUB_TX_TOPUP)
     deser = tx.deserialize()
     assert deser['version'] == 3
     assert deser['tx_type'] == 9
     extra = deser['extra_payload']
     assert extra.version == 1
     assert len(extra.regTxHash) == 32
     assert extra.regTxHash == bfh(
         'd384e42374e8abfeffffff01570b000000a40100b67ffbbd095de31ea3844675')
     ser = tx.serialize()
     assert ser == SUB_TX_TOPUP
Ejemplo n.º 27
0
 def test_axe_tx_pro_up_reg_tx(self):
     tx = transaction.Transaction(PRO_UP_REG_TX)
     deser = tx.deserialize()
     assert deser['version'] == 3
     assert deser['tx_type'] == 3
     extra = deser['extra_payload']
     assert (str(extra))
     assert extra.version == 1
     assert len(extra.proTxHash) == 32
     assert extra.proTxHash == bfh(
         'aeb817f94b8e699b58130a53d2fbe98d5519c2abe3b15e6f36c9abeb32e4dcce')
     assert extra.mode == 0
     assert len(extra.PubKeyOperator) == 48
     assert extra.PubKeyOperator == bfh(
         '1061eb559a64427ad239830742ef59591cdbbdffda7d3f5e7a2d95b9607a'
         'd80e389191e44c59ea5987b85e6d0e3eb527')
     assert len(extra.KeyIdVoting) == 20
     assert extra.KeyIdVoting == bfh(
         'b9e198fa7a745913c9278ec993d4472a95dac425')
     assert extra.scriptPayout == bfh(
         '76a914eebbacffff3a55437803e0efb68a7d591e0409d188ac')
     assert len(extra.inputsHash) == 32
     assert extra.inputsHash == bfh(
         '0eb0067e6ccdd2acb96e7279113702218f3f0ab6f2287e14c11c5be6f2051d5a')
     assert extra.payloadSig == bfh(
         '20cb00124d838b02207097048cb668244cd79df825eb2d4d211fd2c4604c1'
         '8b30e1ae9bb654787144d16856676efff180889f05b5c9121a483b4ae3f0e'
         'a0ff3faf')
     ser = tx.serialize()
     assert ser == PRO_UP_REG_TX
Ejemplo n.º 28
0
 def test_axe_tx_sub_tx_close_account(self):
     tx = transaction.Transaction(SUB_TX_CLOSE_ACCOUNT)
     deser = tx.deserialize()
     assert deser['version'] == 3
     assert deser['tx_type'] == 11
     extra = deser['extra_payload']
     assert extra.version == 1
     assert len(extra.regTxHash) == 32
     assert extra.regTxHash == bfh(
         'd384e42374e8abfeffffff01570b000000a40100b67ffbbd095de31ea3844675')
     assert len(extra.hashPrevSubTx) == 32
     assert extra.hashPrevSubTx == bfh(
         'af3e98e9601210293360bf2a2e810673412bc6e8e0e358f3fb7bdbe9a12bc6e8')
     assert extra.creditFee == 1000
     assert len(extra.payloadSig) == 96
     assert extra.payloadSig == bfh(
         'a62bc6e8e0e358f3fb7bdbe9a667b3d0103f761caf3e98e9601210293360b'
         'f2a2e810673412bc6e8e0e358f3fb7bdbe9a667b3d0103f761caf3e98e960'
         '1210293360bf2a2e810673412bc6e8e0e358f3fb7bdbe9a667b3d0103f761'
         'cabcdefab')
     ser = tx.serialize()
     assert ser == SUB_TX_CLOSE_ACCOUNT
Ejemplo n.º 29
0
    def test_serialize_protocol_version_70201(self):
        raw = '08108933d948aed6a107cd01e7862ed61ef9bf14e87da0a14e8d17791e9f9c570100000000ffffffff00000000000000000000ffff7f0000014e1f210269e1abb1ffe231ea045068272a06f0fae231d11b11a54225867d89267faa4e23210269e1abb1ffe231ea045068272a06f0fae231d11b11a54225867d89267faa4e234120b8bc547ce2471125eddfdfd5af30ea1e892e750acfe2896b241097b7f21442a61da073d47c885535769bf215eb3e97eca692d868db1bfb9dee469a1ece5acb92a1945457000000003912010008108933d948aed6a107cd01e7862ed61ef9bf14e87da0a14e8d17791e9f9c570100000000ffffffffefc894d8431c1774a19aeb732ea7fc56925b740ed80486f30424109a05000000a1945457000000004120818f17742e6644359c8b9a91e56b595615bd2c593de713304435dcfd07ceb6a815559fd3b2f05f531d9b9918b22b8748491c3f36cb25e8397ff950f74030444f0000000000000000'
        announce = MasternodeAnnounce.deserialize(raw)
        announce.sig_time = 1465161129
        msg = announce.serialize_for_sig()
        expected = to_bytes(''.join([
            '127.0.0.1:19999',
            '1465161129',
            bitcoin.hash_encode(
                bitcoin.hash_160(
                    bfh('0269e1abb1ffe231ea045068272a06f0fae231d11b11a54225867d89267faa4e23'
                        ))),
            bitcoin.hash_encode(
                bitcoin.hash_160(
                    bfh('0269e1abb1ffe231ea045068272a06f0fae231d11b11a54225867d89267faa4e23'
                        ))),
            '70201',
        ]))
        print('7' * 50, expected)
        print('8' * 50, msg)

        self.assertEqual(expected, msg)
Ejemplo n.º 30
0
 def test_axe_tx_pro_up_rev_tx(self):
     tx = transaction.Transaction(PRO_UP_REV_TX)
     deser = tx.deserialize()
     assert deser['version'] == 3
     assert deser['tx_type'] == 4
     extra = deser['extra_payload']
     assert extra.version == 1
     assert len(extra.proTxHash) == 32
     assert extra.proTxHash == bfh(
         'b67ffbbd095de31ea38446754b6bf251287936d2881d58b7c4efae0b54c75e9f')
     assert extra.reason == 0
     assert len(extra.inputsHash) == 32
     assert extra.inputsHash == bfh(
         'eb073521b60306717f1d4feb3e9022f886b97bf981137684716a7d3d7e45b7fe')
     assert len(extra.payloadSig) == 96
     assert extra.payloadSig == bfh(
         '83f4bb5530f7c5954e8b1ad50a74a9e1d65dcdcbe4acb8cbe3671abc7911'
         'e8c3954856c4da7e5fd242f2e4f5546f08d90849245bc593d1605654e1a9'
         '9cd0a79e9729799742c48d4920044666ad25a85fd093559c43e4900e634c'
         '371b9b8d89ba')
     ser = tx.serialize()
     assert ser == PRO_UP_REV_TX