Ejemplo n.º 1
0
 def read_invoice(self):
     address = str(self.address)
     if not address:
         self.app.show_error(
             _('Recipient not specified.') + ' ' +
             _('Please scan a Dash address or a payment request'))
         return
     if not self.amount:
         self.app.show_error(_('Please enter an amount'))
         return
     if self.is_max:
         amount = '!'
     else:
         try:
             amount = self.app.get_amount(self.amount)
         except:
             self.app.show_error(_('Invalid amount') + ':\n' + self.amount)
             return
     message = self.message
     if self.payment_request:
         outputs = self.payment_request.get_outputs()
     else:
         if not bitcoin.is_address(address):
             self.app.show_error(
                 _('Invalid Dash Address') + ':\n' + address)
             return
         outputs = [PartialTxOutput.from_address_and_value(address, amount)]
     return self.app.wallet.create_invoice(outputs=outputs,
                                           message=message,
                                           pr=self.payment_request,
                                           URI=self.parsed_URI)
Ejemplo n.º 2
0
 def parse_address_and_amount(self, line) -> PartialTxOutput:
     try:
         x, y = line.split(',')
     except ValueError:
         raise Exception("expected two comma-separated values: (address, amount)") from None
     scriptpubkey = self.parse_output(x)
     amount = self.parse_amount(y)
     return PartialTxOutput(scriptpubkey=scriptpubkey, value=amount)
Ejemplo n.º 3
0
    def get_outputs(self, is_max):
        if self.payto_scriptpubkey:
            if is_max:
                amount = '!'
            else:
                amount = self.amount_edit.get_amount()
            self.outputs = [PartialTxOutput(scriptpubkey=self.payto_scriptpubkey, value=amount)]

        return self.outputs[:]
Ejemplo n.º 4
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(outputs=[
                PartialTxOutput.from_address_and_value(self.str_recipient,
                                                       amount)
            ],
                                  password=password,
                                  fee=fee)
        except Exception as e:
            print(repr(e))
            return

        if self.str_description:
            self.wallet.set_label(tx.txid(), self.str_description)

        print(_("Please wait..."))
        try:
            coro = self.wallet.psman.broadcast_transaction(tx)
            self.network.run_from_another_thread(coro)
        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.'))