Пример #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_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)
Пример #2
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)
Пример #3
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()
Пример #4
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
Пример #5
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