Beispiel #1
0
    def test_payto(self, mock_save_db):
        wallet = restore_wallet_from_text(
            'disagree rug lemon bean unaware square alone beach tennis exhibit fix mimic',
            gap_limit=2,
            path='if_this_exists_mocking_failed_648151893',
            config=self.config)['wallet']
        # bootstrap wallet
        funding_tx = Transaction(
            '0200000000010165806607dd458280cb57bf64a16cf4be85d053145227b98c28932e953076b8e20000000000fdffffff02ac150700000000001600147e3ddfe6232e448a8390f3073c7a3b2044fd17eb102908000000000016001427fbe3707bc57e5bb63d6f15733ec88626d8188a02473044022049ce9efbab88808720aa563e2d9bc40226389ab459c4390ea3e89465665d593502206c1c7c30a2f640af1e463e5107ee4cfc0ee22664cfae3f2606a95303b54cdef80121026269e54d06f7070c1f967eb2874ba60de550dfc327a945c98eb773672d9411fd77181e00'
        )
        funding_txid = funding_tx.txid()
        self.assertEqual(
            'ede61d39e501d65ccf34e6300da439419c43393f793bb9a8a4b06b2d0d80a8a0',
            funding_txid)
        wallet.receive_tx_callback(funding_txid, funding_tx,
                                   TX_HEIGHT_UNCONFIRMED)

        cmds = Commands(config=self.config)
        tx_str = cmds._run(
            'payto', (),
            destination="tmona1qsfcddwf7yytl62e3catwv8hpl2hs9e367y8w6h",
            amount="0.00123456",
            feerate=50,
            locktime=1972344,
            wallet=wallet)

        tx = tx_from_any(tx_str)
        self.assertEqual(2, len(tx.outputs()))
        txout = TxOutput.from_address_and_value(
            "tmona1qsfcddwf7yytl62e3catwv8hpl2hs9e367y8w6h", 123456)
        self.assertTrue(txout in tx.outputs())
        self.assertEqual(
            "02000000000101a0a8800d2d6bb0a4a8b93b793f39439c4139a40d30e634cf5cd601e5391de6ed0100000000fdffffff0240e20100000000001600148270d6b93e2117fd2b31c756e61ee1faaf02e63a462b060000000000160014a5103285eb519f826520a9f7d3227e1eaa7ec5f80247304402204b2c53c5bf044955591b9f283f71d37e1d604b98105b697d2588a390ebabe35b0220351669747903759e483fa601ffd8a9a3be9d772cdabd88e6154076b97492f8d5012103001b55f19541faaf7e6d57dd1bdb9fdc37725fc500e12f2418cc11e0aed4154978181e00",
            tx_str)
Beispiel #2
0
    def test_paytomany_multiple_max_spends(self, mock_save_db):
        wallet = restore_wallet_from_text(
            'kit virtual quantum festival fortune inform ladder saddle filter soldier start ghost',
            gap_limit=2,
            path='if_this_exists_mocking_failed_648151893',
            config=self.config)['wallet']
        # bootstrap wallet
        funding_tx = Transaction(
            '02000000000101f59876b1c65bbe3e182ccc7ea7224fe397bb9b70aadcbbf4f4074c75c8a074840000000000fdffffff021f351f00000000001600144eec851dd980cc36af1f629a32325f511604d6af56732d000000000016001439267bc7f3e3fabeae3bc3f73880de22d8b01ba50247304402207eac5f639806a00878488d58ca651d690292145bca5511531845ae21fab309d102207162708bd344840cc1bacff1092e426eb8484f83f5c068ba4ca579813de324540121020e0798c267ff06ee8b838cd465f3cfa6c843a122a04917364ce000c29ca205cae5f31f00'
        )
        funding_txid = funding_tx.txid()
        self.assertEqual(
            'e8e977bd9c857d84ec1b8f154ae2ee5dfa49fffb7688942a586196c1ad15de15',
            funding_txid)
        wallet.receive_tx_callback(funding_txid, funding_tx,
                                   TX_HEIGHT_UNCONFIRMED)

        cmds = Commands(config=self.config)
        tx_str = cmds._run(
            'paytomany', (),
            outputs=[["tmona1qk3g0t9pw5wctkzz7gh6k3ljfuukn729svsm6f3", 0.002],
                     ["tmona1qr7evucrllljtryam6y2k3ntmlptq208p7el3kl", "2!"],
                     ["tmona1qs3msqp0n0qade2haanjw2dkaa5lm77vw6kxpnl", 0.003],
                     ["tmona1qar4ye43tdfj6y5n3yndp9adhs2wuz2v0cxlagh", "3!"]],
            fee="0.00005000",
            locktime=2094054,
            wallet=wallet)

        tx = tx_from_any(tx_str)
        self.assertEqual(4, len(tx.outputs()))
        self.assertEqual(
            "0200000000010115de15adc19661582a948876fbff49fa5deee24a158f1bec847d859cbd77e9e80100000000fdffffff04400d030000000000160014b450f5942ea3b0bb085e45f568fe49e72d3f28b0e09304000000000016001484770005f3783adcaafdece4e536dded3fbf798e12190f00000000001600141fb2ce607fffe4b193bbd11568cd7bf856053ce19ca5160000000000160014e8ea4cd62b6a65a2527124da12f5b7829dc1298f02473044022079570c62352d7c462ee50851d27f829f7ea5757d258b6b38a6b377a4910ba597022056653f1b15a9693ba790e89ebac60e33b7a1d8357e05cd3d7ecc1ae00e9ab4a8012102eed460ead0cbaa71ad52b70899acf4ea12682ab237207b045c5cf9c6d11c2bcfe6f31f00",
            tx_str)
Beispiel #3
0
    def on_receive(self, keyhash, message):
        self.logger.info(f"signal arrived for {keyhash}")
        for key, _hash, window in self.keys:
            if _hash == keyhash:
                break
        else:
            self.logger.info("keyhash not found")
            return

        wallet = window.wallet
        if isinstance(wallet.keystore, keystore.Hardware_KeyStore):
            window.show_warning(
                _('An encrypted transaction was retrieved from cosigning pool.'
                  ) + '\n' +
                _('However, hardware wallets do not support message decryption, '
                  'which makes them not compatible with the current design of cosigner pool.'
                  ))
            return
        elif wallet.has_keystore_encryption():
            password = window.password_dialog(
                _('An encrypted transaction was retrieved from cosigning pool.'
                  ) + '\n' + _('Please enter your password to decrypt it.'))
            if not password:
                return
        else:
            password = None
            if not window.question(
                    _("An encrypted transaction was retrieved from cosigning pool."
                      ) + '\n' + _("Do you want to open it now?")):
                return

        xprv = wallet.keystore.get_master_private_key(password)
        if not xprv:
            return
        try:
            privkey = BIP32Node.from_xkey(xprv).eckey
            message = privkey.decrypt_message(message)
        except Exception as e:
            self.logger.exception('')
            window.show_error(_('Error decrypting message') + ':\n' + repr(e))
            return

        self.listener.clear(keyhash)
        try:
            tx = tx_from_any(message)
        except SerializationError as e:
            window.show_error(
                _("Electrum was unable to deserialize the transaction:") +
                "\n" + str(e))
            return
        show_transaction(tx, parent=window, prompt_if_unsaved=True)
 def do_paste(self):
     data = self.app._clipboard.paste().strip()
     if not data:
         self.app.show_info(_("Clipboard is empty"))
         return
     # try to decode as transaction
     try:
         tx = tx_from_any(data)
         tx.deserialize()
     except:
         tx = None
     if tx:
         self.app.tx_dialog(tx)
         return
     # try to decode as URI/address
     bolt11_invoice = maybe_extract_bolt11_invoice(data)
     if bolt11_invoice is not None:
         self.set_ln_invoice(bolt11_invoice)
     else:
         self.set_URI(data)