URI: 
       tswaps: store fee_preimage - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit c8506eaa3944d0cdd9f5d6dfb1a33bc06aa44d75
   DIR parent 540dd73f3ba9d5109984c218ff7aa87154a765d7
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Fri, 12 Jun 2020 10:07:36 +0200
       
       swaps: store fee_preimage
       
       Diffstat:
         M electrum/lnworker.py                |       2 ++
         M electrum/submarine_swaps.py         |      12 +++++++++++-
         M electrum/wallet.py                  |       4 ++--
       
       3 files changed, 15 insertions(+), 3 deletions(-)
       ---
   DIR diff --git a/electrum/lnworker.py b/electrum/lnworker.py
       t@@ -632,6 +632,8 @@ class LNWallet(LNWorker):
                    }
                    # add txid to merge item with onchain item
                    swap = self.swap_manager.get_swap(payment_hash)
       +            if swap is None:
       +                swap = self.swap_manager.get_swap_by_prepay(payment_hash)
                    if swap:
                        if swap.is_reverse:
                            item['txid'] = swap.spending_txid
   DIR diff --git a/electrum/submarine_swaps.py b/electrum/submarine_swaps.py
       t@@ -68,6 +68,7 @@ class SwapData(StoredObject):
            lightning_amount = attr.ib(type=int)
            redeem_script = attr.ib(type=bytes, converter=hex_to_bytes)
            preimage = attr.ib(type=bytes, converter=hex_to_bytes)
       +    fee_preimage = attr.ib(type=bytes, converter=hex_to_bytes)
            privkey = attr.ib(type=bytes, converter=hex_to_bytes)
            lockup_address = attr.ib(type=str)
            funding_txid = attr.ib(type=str)
       t@@ -108,6 +109,7 @@ class SwapManager(Logger):
                self.lnworker = wallet.lnworker
                self.lnwatcher = self.wallet.lnworker.lnwatcher
                self.swaps = self.wallet.db.get_dict('submarine_swaps')
       +        self.prepayments = {}
                for swap in self.swaps.values():
                    if swap.is_redeemed:
                        continue
       t@@ -154,6 +156,11 @@ class SwapManager(Logger):
            def get_swap(self, payment_hash):
                return self.swaps.get(payment_hash.hex())
        
       +    def get_swap_by_prepay(self, prepay_payment_hash):
       +        payment_hash = self.prepayments.get(prepay_payment_hash)
       +        if payment_hash:
       +            return self.swaps.get(payment_hash.hex())
       +
            def add_lnwatcher_callback(self, swap):
                callback = lambda: self._claim_swap(swap)
                self.lnwatcher.add_callback(swap.lockup_address, callback)
       t@@ -275,6 +282,9 @@ class SwapManager(Logger):
                if fee_invoice:
                    fee_lnaddr = self.lnworker._check_invoice(fee_invoice)
                    invoice_amount += fee_lnaddr.get_amount_sat()
       +            fee_preimage = fee_lnaddr.paymenthash
       +        else:
       +            fee_preimage = None
                assert int(invoice_amount) == amount_sat, (invoice_amount, amount_sat)
                # save swap data to wallet file
                swap = SwapData(
       t@@ -282,7 +292,7 @@ class SwapManager(Logger):
                    locktime = locktime,
                    privkey = privkey,
                    preimage = preimage,
       -            # save the rhash of the mining fee invoice
       +            fee_preimage = fee_preimage,
                    lockup_address = lockup_address,
                    onchain_amount = onchain_amount,
                    lightning_amount = amount_sat,
   DIR diff --git a/electrum/wallet.py b/electrum/wallet.py
       t@@ -840,8 +840,8 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
                    if txid and txid in transactions_tmp:
                        item = transactions_tmp[txid]
                        item['label'] = tx_item['label']
       -                item['type'] = tx_item['type']
       -                item['ln_value'] = Satoshis(ln_value)
       +                item['type'] = tx_item['type']   # fixme: do we need this?
       +                item['ln_value'] = Satoshis(ln_value)  # fixme: we need to add value
                        item['amount_msat'] = tx_item['amount_msat']
                    else:
                        tx_item['lightning'] = True