Ejemplo n.º 1
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.º 2
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.º 3
0
    def do_send(self):
        if not is_address(self.str_recipient):
            print(_('Invalid DeepOnion 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:
            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.'))
Ejemplo n.º 4
0
 def update_tx(self, onchain_amount: Union[int, str]):
     """Updates the transaction associated with a forward swap."""
     if onchain_amount is None:
         self.tx = None
         self.ids.ok_button.disabled = True
         return
     outputs = [PartialTxOutput.from_address_and_value(ln_dummy_address(), onchain_amount)]
     coins = self.app.wallet.get_spendable_coins(None)
     try:
         self.tx = self.app.wallet.make_unsigned_transaction(
             coins=coins,
             outputs=outputs)
     except (NotEnoughFunds, NoDynamicFeeEstimates):
         self.tx = None
         self.ids.ok_button.disabled = True
Ejemplo n.º 5
0
 def _update_tx(self, onchain_amount):
     """Updates self.tx. No other side-effects."""
     if self.is_reverse:
         return
     if onchain_amount is None:
         self.tx = None
         return
     outputs = [
         PartialTxOutput.from_address_and_value(ln_dummy_address(),
                                                onchain_amount)
     ]
     coins = self.window.get_coins()
     try:
         self.tx = self.window.wallet.make_unsigned_transaction(
             coins=coins, outputs=outputs)
     except (NotEnoughFunds, NoDynamicFeeEstimates) as e:
         self.tx = None
Ejemplo n.º 6
0
 def read_invoice(self):
     address = str(self.address)
     if not address:
         self.app.show_error(
             _('Recipient not specified.') + ' ' +
             _('Please scan a DeepOnion 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.is_lightning:
         return LNInvoice.from_bech32(address)
     else:  # on-chain
         if self.payment_request:
             outputs = self.payment_request.get_outputs()
         else:
             if not bitcoin.is_address(address):
                 self.app.show_error(
                     _('Invalid DeepOnion 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)