예제 #1
0
 def get_max_amount(self):
     from electrum_dash.transaction import TxOutput
     if run_hook('abort_send', self):
         return ''
     inputs = self.wallet.get_spendable_coins(None, self.electrum_config)
     if not inputs:
         return ''
     addr = str(
         self.send_screen.screen.address) or self.wallet.dummy_address()
     outputs = [TxOutput(TYPE_ADDRESS, addr, '!')]
     try:
         tx = self.wallet.make_unsigned_transaction(inputs, outputs,
                                                    self.electrum_config)
     except NoDynamicFeeEstimates as e:
         Clock.schedule_once(
             lambda dt, bound_e=e: self.show_error(str(bound_e)))
         return ''
     except NotEnoughFunds:
         return ''
     except InternalAddressCorruption as e:
         self.show_error(str(e))
         send_exception_to_crash_reporter(e)
         return ''
     amount = tx.output_value()
     __, x_fee_amount = run_hook('get_tx_extra_fee', self.wallet,
                                 tx) or (None, 0)
     amount_after_all_fees = amount - x_fee_amount
     return format_satoshis_plain(amount_after_all_fees,
                                  self.decimal_point())
    def test_payto(self, mock_save_db):
        wallet = restore_wallet_from_text('ignore hospital shallow unit river glue battle chat pet option position icon',
                                          gap_limit=2,
                                          path='if_this_exists_mocking_failed_648151893',
                                          config=self.config)['wallet']
        # bootstrap wallet
        funding_tx = Transaction('0200000001688b4db66baaae1dde4a59aaccc1282757db5b192033a8d41718cd9e3949f7d2050000006a47304402203f8fca0aa5ef38d20e275d3c7cf191ce56e5f12e351ffa12f0a667440374ef7a0220206ef46cf234a35b7f4e3f062c99a118966403f9e788ec870d93114dd20081fa01210211db4efc20880c5b57cfa947550a7f337c99adf5c11999de380e2e4e196eebcefeffffff02ac150700000000001976a914eb9fad52a0664d10798fdcc0c4776ef07d910d7788acbc2b0800000000001976a914a9262375de5f7a2c81e0d28f3c6ab42e594627e888acea0e0800')
        funding_txid = funding_tx.txid()
        self.assertEqual('2304741a3b690d5c52bac443792e9ec6af535b527c562899b36e72e8c4e3bf4f', funding_txid)
        wallet.receive_tx_callback(funding_txid, funding_tx, TX_HEIGHT_UNCONFIRMED)

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

        tx = tx_from_any(tx_str)
        self.assertEqual(2, len(tx.outputs()))
        txout = TxOutput.from_address_and_value("yR41Y7aXsoYCSugFhXJ2DU5asRtW1rpzV3", 123456)
        self.assertTrue(txout in tx.outputs())
        self.assertEqual("02000000014fbfe3c4e8726eb39928567c525b53afc69e2e7943c4ba525c0d693b1a740423000000006a4730440220234aa5fe38e0d99013fb1427a0998560f513b26c37a1e53540da5b9b7859c0540220316735a04e115941b3f62e54f7f30473bf44c483eef335e702d542b8d6e81f3e0121025837acda77e6b2295e03c50c356057e3f2ec8d6c498ba9351618ee913510daa3feffffff0240e20100000000001976a91433ed429c95e392a27f1194b400b07cff5167284588ac8a320500000000001976a9144ee5b85791f50a4270ad7277ff307fd66f7254e188ac78181e00",
                         tx_str)
        assert  tx_from_any(tx_str).is_complete()
예제 #3
0
 def do_send(self):
     if self.screen.is_pr:
         if self.payment_request.has_expired():
             self.app.show_error(_('Payment request has expired'))
             return
         outputs = self.payment_request.get_outputs()
     else:
         address = str(self.screen.address)
         if not address:
             self.app.show_error(
                 _('Recipient not specified.') + ' ' +
                 _('Please scan a PACGlobal address or a payment request'))
             return
         if not bitcoin.is_address(address):
             self.app.show_error(
                 _('Invalid PACGlobal Address') + ':\n' + address)
             return
         try:
             amount = self.app.get_amount(self.screen.amount)
         except:
             self.app.show_error(
                 _('Invalid amount') + ':\n' + self.screen.amount)
             return
         outputs = [TxOutput(bitcoin.TYPE_ADDRESS, address, amount)]
     message = self.screen.message
     amount = sum(map(lambda x: x[2], outputs))
     self._do_send(amount, message, outputs)
예제 #4
0
    def get_outputs(self, is_max):
        if self.payto_address:
            if is_max:
                amount = '!'
            else:
                amount = self.amount_edit.get_amount()

            _type, addr = self.payto_address
            self.outputs = [TxOutput(_type, addr, amount)]

        return self.outputs[:]
예제 #5
0
    def do_send(self):
        if not is_address(self.str_recipient):
            print(_('Invalid Dash address'))
            return
        try:
            amount = int(Decimal(self.str_amount) * COIN)
        except Exception:
            print(_('Invalid Amount'))
            return
        try:
            fee = int(Decimal(self.str_fee) * COIN)
        except Exception:
            print(_('Invalid Fee'))
            return

        if self.wallet.has_password():
            password = self.password_dialog()
            if not password:
                return
        else:
            password = None

        c = ""
        while c != "y":
            c = input("ok to send (y/n)?")
            if c == "n": return

        try:
            tx = self.wallet.mktx(
                [TxOutput(TYPE_ADDRESS, self.str_recipient, amount)], password,
                self.config, fee)
        except Exception as e:
            print(str(e))
            return

        if self.str_description:
            self.wallet.labels[tx.txid()] = self.str_description

        print(_("Please wait..."))
        status, msg = self.network.broadcast_transaction(tx)

        if status:
            print(_('Payment sent.'))
            #self.do_clear()
            #self.update_contacts_tab()
        else:
            display_msg = _(
                'The server returned an error when broadcasting the transaction.'
            )
            display_msg += '\n' + repr(e)
            print(display_msg)
예제 #6
0
    def do_send(self):
        if not is_address(self.str_recipient):
            print(_('Invalid PACGlobal address'))
            return
        try:
            amount = int(Decimal(self.str_amount) * COIN)
        except Exception:
            print(_('Invalid Amount'))
            return
        try:
            fee = int(Decimal(self.str_fee) * COIN)
        except Exception:
            print(_('Invalid Fee'))
            return

        if self.wallet.has_password():
            password = self.password_dialog()
            if not password:
                return
        else:
            password = None

        c = ""
        while c != "y":
            c = input("ok to send (y/n)?")
            if c == "n": return

        try:
            tx = self.wallet.mktx(
                [TxOutput(TYPE_ADDRESS, self.str_recipient, amount)], password,
                self.config, fee)
        except Exception as e:
            print(str(e))
            return

        if self.str_description:
            self.wallet.labels[tx.txid()] = self.str_description

        print(_("Please wait..."))
        try:
            self.network.run_from_another_thread(
                self.network.broadcast_transaction(tx))
        except TxBroadcastError as e:
            msg = e.get_message_for_gui()
            print(msg)
        except BestEffortRequestFailed as e:
            msg = repr(e)
            print(msg)
        else:
            print(_('Payment sent.'))
예제 #7
0
    def do_send(self):
        if not is_address(self.str_recipient):
            self.show_message(_('Invalid Dash address'))
            return
        try:
            amount = int(Decimal(self.str_amount) * COIN)
        except Exception:
            self.show_message(_('Invalid Amount'))
            return
        try:
            fee = int(Decimal(self.str_fee) * COIN)
        except Exception:
            self.show_message(_('Invalid Fee'))
            return

        if self.wallet.has_password():
            password = self.password_dialog()
            if not password:
                return
        else:
            password = None
        try:
            tx = self.wallet.mktx(
                [TxOutput(TYPE_ADDRESS, self.str_recipient, amount)], password,
                self.config, fee)
        except Exception as e:
            self.show_message(str(e))
            return

        if self.str_description:
            self.wallet.labels[tx.txid()] = self.str_description

        self.show_message(_("Please wait..."), getchar=False)
        try:
            self.network.run_from_another_thread(
                self.network.broadcast_transaction(tx))
        except TxBroadcastError as e:
            msg = e.get_message_for_gui()
            self.show_message(msg)
        except BestEffortRequestFailed as e:
            msg = repr(e)
            self.show_message(msg)
        else:
            self.show_message(_('Payment sent.'))
            self.do_clear()
예제 #8
0
    def do_send(self):
        if not is_address(self.str_recipient):
            self.show_message(_('Invalid Dash address'))
            return
        try:
            amount = int(Decimal(self.str_amount) * COIN)
        except Exception:
            self.show_message(_('Invalid Amount'))
            return
        try:
            fee = int(Decimal(self.str_fee) * COIN)
        except Exception:
            self.show_message(_('Invalid Fee'))
            return

        if self.wallet.has_password():
            password = self.password_dialog()
            if not password:
                return
        else:
            password = None
        try:
            tx = self.wallet.mktx([TxOutput(TYPE_ADDRESS, self.str_recipient, amount)],
                                  password, self.config, fee)
        except Exception as e:
            self.show_message(str(e))
            return

        if self.str_description:
            self.wallet.labels[tx.txid()] = self.str_description

        self.show_message(_("Please wait..."), getchar=False)
        status, msg = self.network.broadcast_transaction(tx)

        if status:
            self.show_message(_('Payment sent.'))
            self.do_clear()
            #self.update_contacts_tab()
        else:
            self.show_message(_('Error'))
예제 #9
0
 def parse_address_and_amount(self, line):
     x, y = line.split(',')
     out_type, out = self.parse_output(x)
     amount = self.parse_amount(y)
     return TxOutput(out_type, out, amount)