コード例 #1
0
    def test_create_and_sign(self):
        collateral_pub = '038ae57bd0fa5b45640e771614ec571c7326a2266c78bb444f1971c85188411ba1'  # 1Feczj12KEioQTrXhd4zUUdmijxzwXfdcE
        delegate_pub = '02526201c87c1b4630aabbd04572eec3e2545e442503e57e60880fafcc1f684dbc'  # 1NLwcP3gVQPZHUdjKVrU9J4v4jRSYsB4Dj
        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 = '5K4hm916sRw93k9eoSf4XfHvUmi4ZyEpfMMT7yprvWPhTCc7wcJ'
        delegate_wif = '5HsgYSCySd34BySFqo1CDaYHJVdHy1yqBXk3dGy9ABB3B4Pos3T'
        announce.last_ping.sign(delegate_wif, bfh(delegate_pub), 1461858375)
        sig = announce.sign(collateral_wif, 1461858375)

        address = '1Feczj12KEioQTrXhd4zUUdmijxzwXfdcE'
        self.assertTrue(announce.verify(address))
        self.assertTrue(
            ecc.verify_message_with_address(address, sig,
                                            announce.serialize_for_sig()))
コード例 #2
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))
コード例 #3
0
    def save_current_masternode(self, as_new=False):
        """Save the masternode that is being viewed.

        If as_new is True, a new masternode will be created.
        """
        delegate_privkey = str(self.masternode_editor.delegate_key_edit.text())
        if not delegate_privkey:
            self.show_warning(_('Delegate private key is empty.'),
                              title=_('Warning'))
            return

        try:
            delegate_pubkey = self.manager.import_masternode_delegate(
                delegate_privkey)
        except Exception:
            # Show an error if the private key is invalid and not an empty string.
            if delegate_privkey:
                self.show_warning(_('Ignoring invalid delegate private key.'),
                                  title=_('Warning'))
            delegate_pubkey = ''

        alias = str(self.masternode_editor.alias_edit.text())
        # Construct a new masternode.
        if as_new:
            kwargs = self.masternode_editor.get_masternode_args()
            kwargs['delegate_key'] = delegate_pubkey
            del kwargs['vin']
            self.mapper.revert()
            self.masternodes_widget.add_masternode(
                MasternodeAnnounce(**kwargs))
        else:
            self.mapper.submit()
        self.manager.save()
        self.masternodes_widget.select_masternode(alias)
コード例 #4
0
    def test_hash(self):
        announce = MasternodeAnnounce.deserialize(raw_announce)

        expected_hash = 'a8a3dc1782191f28f613c8971709a57ee58a4d0d7a11138804f89a0b088d67d1'
        msg = announce.serialize_for_sig()

        h = sha256d(ecc.msg_magic(msg))
        h = bitcoin.hash_encode(h)
        self.assertEqual(expected_hash, h)
コード例 #5
0
    def test_hash(self):
        announce = MasternodeAnnounce.deserialize(raw_announce_70210)

        expected_hash = '5f69e59f5ea327be16e649fb6c72ed02e39ef9dae8ecb27d222419e94dcd89b7'
        msg = announce.serialize_for_sig()

        h = sha256d(ecc.msg_magic(msg))
        h = bitcoin.hash_encode(h)
        self.assertEqual(expected_hash, h)
コード例 #6
0
    def __init__(self, manager, parent):
        super(MasternodeDialog, self).__init__(parent)
        Logger.__init__(self)
        self.gui = parent
        self.manager = manager
        self.setWindowTitle(_('Masternode Manager'))

        self.waiting_dialog = None
        self.create_layout()
        # Create a default masternode if none are present.
        if len(self.manager.masternodes) == 0:
            self.masternodes_widget.add_masternode(
                MasternodeAnnounce(alias='default'), save=False)
        self.masternodes_widget.view.selectRow(0)

        mn_list = self.gui.dip3_tab.mn_list
        if mn_list:
            mn_list.register_callback(self.on_mn_list_diff_updated,
                                      ['mn-list-diff-updated'])
        self.diff_updated.connect(self.on_diff_updated)
コード例 #7
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)
コード例 #8
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)
コード例 #9
0
    def test_serialization(self):
        announce = MasternodeAnnounce.deserialize(raw_announce)

        self.assertEqual(
            '27c7c43cfde0943d2397b9fd5106d0a1f6927074a5fa6dfcf7fe50a2cb6b8d10',
            announce.vin['prevout_hash'])
        self.assertEqual(0, announce.vin['prevout_n'])
        self.assertEqual('', announce.vin['scriptSig'])
        self.assertEqual(0xffffffff, announce.vin['sequence'])

        self.assertEqual('192.168.1.101:19999', str(announce.addr))

        self.assertEqual(
            '02d3879cdf9afcc59c42d8d858e44ba0e3d51df7792c6c0bbb6dd5e9de41f5580e',
            announce.collateral_key)
        self.assertEqual(
            '04431873cf0a6ae3f6903e72ed915f0e21029e59c1c279358f98e3d4136250c774a4b14bbd8a1ffb800c85310a8379869f05a24a6b99ce3d79f6194881ed7091d6',
            announce.delegate_key)
        self.assertEqual(
            'H6vjQtcmZ4riE5xeVocIAxEfnOAMDfi0jU06p+8MlflWeSO7U9zns6HqaUERq7+Vb4T/FxmSLgjb0FMPyiPOFEQ=',
            base64.b64encode(announce.sig).decode('utf-8'))
        self.assertEqual(1460397824, announce.sig_time)
        self.assertEqual(70103, announce.protocol_version)

        self.assertEqual(
            '27c7c43cfde0943d2397b9fd5106d0a1f6927074a5fa6dfcf7fe50a2cb6b8d10',
            announce.last_ping.vin['prevout_hash'])
        self.assertEqual(0, announce.last_ping.vin['prevout_n'])
        self.assertEqual('', announce.last_ping.vin['scriptSig'])
        self.assertEqual(0xffffffff, announce.last_ping.vin['sequence'])
        self.assertEqual(
            '0000009784f43ea4c4158631a7b638f452e3ed8783eeac00d995e860de12e69f',
            announce.last_ping.block_hash)
        self.assertEqual(1460397824, announce.last_ping.sig_time)
        self.assertEqual(
            'G1xOVjKTYrg9/LuqcDl8jEnLfmnt+FsOgjLSeYtxluxwUDYGndyREm35jbT2dVsuwBV3ykF9+qLpCgOCvWZ+QQ0=',
            base64.b64encode(announce.last_ping.sig).decode('utf-8'))

        self.assertEqual(raw_announce, announce.serialize())
コード例 #10
0
    def test_serialization(self):
        announce = MasternodeAnnounce.deserialize(raw_announce_70210)

        self.assertEqual(
            '54db7eb00977d96b8f0a78fec4689f0a2d9ac0792676790a32265d4b0c82a3d0',
            announce.vin['prevout_hash'])
        self.assertEqual(1, announce.vin['prevout_n'])
        self.assertEqual('', announce.vin['scriptSig'])
        self.assertEqual(0xffffffff, announce.vin['sequence'])

        self.assertEqual('178.151.192.107:19999', str(announce.addr))

        self.assertEqual(
            '0221088c51bef8c9c891b385fa1e8a78b016f01db41741aea7e43e67a7415ab7be',
            announce.collateral_key)
        self.assertEqual(
            '042379a871a10ae6bf06e756262f69d7f0ce9b8b562f223bde964db573fb7d0f1e219c246a4b3a6133c5cec136d83f4049df51321ba2cb01d676cc3982c7e24d1f',
            announce.delegate_key)
        self.assertEqual(
            'ICj1/mZo5pqUMlYFghCA9BeTAsDpu4fnVzUnPmMHRTSUPtSbNPeUokmH1Q4hfp9JCOt+RypYFc1QlCuaa5P/hWc=',
            base64.b64encode(announce.sig).decode('utf-8'))
        self.assertEqual(1530021571, announce.sig_time)
        self.assertEqual(70210, announce.protocol_version)

        self.assertEqual(
            '54db7eb00977d96b8f0a78fec4689f0a2d9ac0792676790a32265d4b0c82a3d0',
            announce.last_ping.vin['prevout_hash'])
        self.assertEqual(1, announce.last_ping.vin['prevout_n'])
        self.assertEqual('', announce.last_ping.vin['scriptSig'])
        self.assertEqual(0xffffffff, announce.last_ping.vin['sequence'])
        self.assertEqual(
            '00000000004eeaf1ee1a0b0bd957ed3d905052efad13d05e3f6aa756ceb2cbd8',
            announce.last_ping.block_hash)
        self.assertEqual(1530021570, announce.last_ping.sig_time)
        self.assertEqual(
            'HEajdRdRbdZNWe47RIvIr4mT8p3Q4Zg2YCEuhk4owmLPXyIiOmBP/FA8Q8m/dwv0SO/ibAB3ORlE49ls3Cri9gk=',
            base64.b64encode(announce.last_ping.sig).decode('utf-8'))

        self.assertEqual(raw_announce_70210, announce.serialize())
コード例 #11
0
 def test_get_hash(self):
     announce = MasternodeAnnounce.deserialize(raw_announce)
     expected = 'ef3fe643adc638044b32879bc644a0fb1ebe6ca75281368184c891da9c07986b'
     self.assertEqual(expected, announce.get_hash())
コード例 #12
0
    def test_verify(self):
        announce = MasternodeAnnounce.deserialize(raw_announce_70210)
        message = announce.serialize_for_sig()

        pk = bitcoin.public_key_to_p2pkh(bfh(announce.collateral_key))
        self.assertTrue(announce.verify())
コード例 #13
0
 def test_get_hash(self):
     announce = MasternodeAnnounce.deserialize(raw_announce_70210)
     expected = '154f19205294c3c1077d0f34473673998b6f6139209110705cee10d66e7d73af'
     self.assertEqual(expected, announce.get_hash())