Beispiel #1
0
 def _spend_max_forward_swap(self):
     self.update_tx('!')
     if self.tx:
         amount = self.tx.output_value_for_address(ln_dummy_address())
         max_amt = self.swap_manager.get_max_amount()
         if amount > max_amt:
             amount = max_amt
             self.update_tx(amount)
         if self.tx:
             amount = self.tx.output_value_for_address(ln_dummy_address())
             assert amount <= max_amt
             self.send_amount_e.setAmount(amount)
Beispiel #2
0
 def _spend_max_forward_swap(self):
     self.update_tx('!')
     if self.tx:
         amount = self.tx.output_value_for_address(ln_dummy_address())
         max_amt = self.swap_manager.get_max_amount()
         if amount > max_amt:
             amount = max_amt
             self.update_tx(amount)
         if self.tx:
             amount = self.tx.output_value_for_address(ln_dummy_address())
             assert amount <= max_amt
             # TODO: limit onchain amount if lightning cannot receive this much
             self.send_amount_e.setAmount(amount)
Beispiel #3
0
 def _spend_max_forward_swap(self):
     self._update_tx('!')
     if self.tx:
         amount = self.tx.output_value_for_address(ln_dummy_address())
         max_swap_amt = self.swap_manager.get_max_amount()
         max_recv_amt = int(self.lnworker.num_sats_can_receive())
         max_amt = min(max_swap_amt, max_recv_amt)
         if amount > max_amt:
             amount = max_amt
             self._update_tx(amount)
         if self.tx:
             amount = self.tx.output_value_for_address(ln_dummy_address())
             assert amount <= max_amt
             self.send_amount_e.setAmount(amount)
Beispiel #4
0
 def _spend_max_forward_swap(self):
     self._update_tx('!')
     if self.tx:
         amount = self.tx.output_value_for_address(ln_dummy_address())
         max_swap_amt = self.swap_manager.get_max_amount()
         max_recv_amt_ln = int(self.swap_manager.num_sats_can_receive())
         max_recv_amt_oc = self.swap_manager.get_send_amount(
             max_recv_amt_ln, is_reverse=False) or float('inf')
         max_amt = int(min(max_swap_amt, max_recv_amt_oc))
         if amount > max_amt:
             amount = max_amt
             self._update_tx(amount)
         if self.tx:
             amount = self.tx.output_value_for_address(ln_dummy_address())
             assert amount <= max_amt
             self.send_amount_e.setAmount(amount)
Beispiel #5
0
 def update_swap_slider(self):
     """Sets the minimal and maximal amount that can be swapped for the swap
     slider."""
     # tx is updated again afterwards with send_amount in case of normal swap
     # this is just to estimate the maximal spendable onchain amount for HTLC
     self.update_tx('!')
     try:
         max_onchain_spend = self.tx.output_value_for_address(
             ln_dummy_address())
     except AttributeError:  # happens if there are no utxos
         max_onchain_spend = 0
     reverse = int(
         min(self.lnworker.num_sats_can_send(),
             self.swap_manager.get_max_amount()))
     max_recv_amt_ln = int(self.swap_manager.num_sats_can_receive())
     max_recv_amt_oc = self.swap_manager.get_send_amount(
         max_recv_amt_ln, is_reverse=False) or float('inf')
     forward = int(
         min(
             max_recv_amt_oc,
             # maximally supported swap amount by provider
             self.swap_manager.get_max_amount(),
             max_onchain_spend))
     # we expect range to adjust the value of the swap slider to be in the
     # correct range, i.e., to correct an overflow when reducing the limits
     self.ids.swap_slider.range = (-reverse, forward)
Beispiel #6
0
 def do_open_channel(self, funding_tx, conn_str, password):
     # read funding_sat from tx; converts '!' to int value
     funding_sat = funding_tx.output_value_for_address(ln_dummy_address())
     lnworker = self.app.wallet.lnworker
     try:
         chan, funding_tx = lnworker.open_channel(
             connect_str=conn_str,
             funding_tx=funding_tx,
             funding_sat=funding_sat,
             push_amt_sat=0,
             password=password)
     except Exception as e:
         self.app.logger.exception("Problem opening channel")
         self.app.show_error(_('Problem opening channel: ') + '\n' + repr(e))
         return
     # TODO: it would be nice to show this before broadcasting
     if chan.has_onchain_backup():
         self.maybe_show_funding_tx(chan, funding_tx)
     else:
         title = _('Save backup')
         help_text = _(messages.MSG_CREATED_NON_RECOVERABLE_CHANNEL)
         data = lnworker.export_channel_backup(chan.channel_id)
         popup = QRDialog(
             title, data,
             show_text=False,
             text_for_clipboard=data,
             help_text=help_text,
             close_button_text=_('OK'),
             on_close=lambda: self.maybe_show_funding_tx(chan, funding_tx))
         popup.open()
 def do_open_channel(self, funding_tx, conn_str, password):
     # read funding_sat from tx; converts '!' to int value
     funding_sat = funding_tx.output_value_for_address(ln_dummy_address())
     lnworker = self.app.wallet.lnworker
     try:
         chan, funding_tx = lnworker.open_channel(connect_str=conn_str,
                                                  funding_tx=funding_tx,
                                                  funding_sat=funding_sat,
                                                  push_amt_sat=0,
                                                  password=password)
     except Exception as e:
         self.app.logger.exception("Problem opening channel")
         self.app.show_error(
             _('Problem opening channel: ') + '\n' + repr(e))
         return
     n = chan.constraints.funding_txn_minimum_depth
     message = '\n'.join([
         _('Channel established.'),
         _('Remote peer ID') + ':' + chan.node_id.hex(),
         _('This channel will be usable after {} confirmations').format(n)
     ])
     if not funding_tx.is_complete():
         message += '\n\n' + _(
             'Please sign and broadcast the funding transaction')
     self.app.show_info(message)
     if not funding_tx.is_complete():
         self.app.tx_dialog(funding_tx)
Beispiel #8
0
    def init_swap_slider_range(self):
        lnworker = self._wallet.wallet.lnworker
        swap_manager = lnworker.swap_manager
        asyncio.run(swap_manager.get_pairs())
        """Sets the minimal and maximal amount that can be swapped for the swap
        slider."""
        # tx is updated again afterwards with send_amount in case of normal swap
        # this is just to estimate the maximal spendable onchain amount for HTLC
        self.update_tx('!')
        try:
            max_onchain_spend = self._tx.output_value_for_address(
                ln_dummy_address())
        except AttributeError:  # happens if there are no utxos
            max_onchain_spend = 0
        reverse = int(
            min(lnworker.num_sats_can_send(), swap_manager.get_max_amount()))
        max_recv_amt_ln = int(swap_manager.num_sats_can_receive())
        max_recv_amt_oc = swap_manager.get_send_amount(
            max_recv_amt_ln, is_reverse=False) or float('inf')
        forward = int(
            min(
                max_recv_amt_oc,
                # maximally supported swap amount by provider
                swap_manager.get_max_amount(),
                max_onchain_spend))
        # we expect range to adjust the value of the swap slider to be in the
        # correct range, i.e., to correct an overflow when reducing the limits
        self._logger.debug(f'Slider range {-reverse} - {forward}')
        self.rangeMin = -reverse
        self.rangeMax = forward

        self.swap_slider_moved()
Beispiel #9
0
 def update_tx(self, onchain_amount):
     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()
     self.tx = self.window.wallet.make_unsigned_transaction(
         coins=coins,
         outputs=outputs)
Beispiel #10
0
 def update_tx(self, onchain_amount):
     if onchain_amount is None:
         self.tx = None
         self.ok_button.setEnabled(False)
         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
         self.ok_button.setEnabled(False)
Beispiel #11
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
Beispiel #12
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
Beispiel #13
0
    def do_open_channel(self, funding_tx, conn_str, password):
        self._logger.debug('opening channel')
        # read funding_sat from tx; converts '!' to int value
        funding_sat = funding_tx.output_value_for_address(ln_dummy_address())
        lnworker = self._wallet.wallet.lnworker
        try:
            chan, funding_tx = lnworker.open_channel(connect_str=conn_str,
                                                     funding_tx=funding_tx,
                                                     funding_sat=funding_sat,
                                                     push_amt_sat=0,
                                                     password=password)
        except Exception as e:
            self._logger.exception("Problem opening channel")
            self.channelOpenError.emit(
                _('Problem opening channel: ') + '\n' + repr(e))
            return

        self._logger.debug('opening channel succeeded')
        self.channelOpenSuccess.emit(chan.channel_id.hex(),
                                     chan.has_onchain_backup())
 def do_open_channel(self, funding_tx, conn_str, password):
     # read funding_sat from tx; converts '!' to int value
     funding_sat = funding_tx.output_value_for_address(ln_dummy_address())
     lnworker = self.app.wallet.lnworker
     try:
         chan, funding_tx = lnworker.open_channel(connect_str=conn_str,
                                                  funding_tx=funding_tx,
                                                  funding_sat=funding_sat,
                                                  push_amt_sat=0,
                                                  password=password)
     except Exception as e:
         self.app.logger.exception("Problem opening channel")
         self.app.show_error(
             _('Problem opening channel: ') + '\n' + repr(e))
         return
     # TODO: it would be nice to show this before broadcasting
     if lnworker.has_recoverable_channels():
         self.maybe_show_funding_tx(chan, funding_tx)
     else:
         title = _('Save backup')
         help_text = ' '.join([
             _('Your wallet does not have recoverable channels.'),
             _('Please save this channel backup on another device.'),
             _('It may be imported in another Electrum wallet with the same seed.'
               )
         ])
         data = lnworker.export_channel_backup(chan.channel_id)
         popup = QRDialog(
             title,
             data,
             show_text=False,
             text_for_clipboard=data,
             help_text=help_text,
             close_button_text=_('OK'),
             on_close=lambda: self.maybe_show_funding_tx(chan, funding_tx))
         popup.open()