URI: 
       tencapsulate get_routing_info in lnaddr - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 4febbcdc2dd772c8e8465bdeee31bd436650a4a3
   DIR parent 0c933945131a014420553b99c276c790dd099278
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Sun,  7 Feb 2021 12:21:00 +0100
       
       encapsulate get_routing_info in lnaddr
       
       Diffstat:
         M electrum/lnaddr.py                  |      11 +++++++++++
         M electrum/lnworker.py                |       9 +--------
       
       2 files changed, 12 insertions(+), 8 deletions(-)
       ---
   DIR diff --git a/electrum/lnaddr.py b/electrum/lnaddr.py
       t@@ -8,6 +8,7 @@ from binascii import hexlify
        from decimal import Decimal
        from typing import Optional
        
       +import random
        import bitstring
        
        from .bitcoin import hash160_to_b58_address, b58_address_to_hash160
       t@@ -282,6 +283,16 @@ class LnAddr(object):
                    return None
                return self.amount * COIN
        
       +    def get_routing_info(self, tag):
       +        # note: tag will be 't' for trampoline
       +        r_tags = list(filter(lambda x: x[0] == tag, self.tags))
       +        # strip the tag type, it's implicitly 'r' now
       +        r_tags = list(map(lambda x: x[1], r_tags))
       +        # if there are multiple hints, we will use the first one that works,
       +        # from a random permutation
       +        random.shuffle(r_tags)
       +        return r_tags
       +
            def get_amount_msat(self) -> Optional[int]:
                if self.amount is None:
                    return None
   DIR diff --git a/electrum/lnworker.py b/electrum/lnworker.py
       t@@ -1144,15 +1144,8 @@ class LNWallet(LNWorker):
                # TODO: return multiples routes if we know that a single one will not work
                # initially, try with less htlcs
                invoice_pubkey = decoded_invoice.pubkey.serialize()
       -        # use 'r' field from invoice
       +        r_tags = decoded_invoice.get_routing_info('r')
                route = None  # type: Optional[LNPaymentRoute]
       -        # only want 'r' tags
       -        r_tags = list(filter(lambda x: x[0] == 'r', decoded_invoice.tags))
       -        # strip the tag type, it's implicitly 'r' now
       -        r_tags = list(map(lambda x: x[1], r_tags))
       -        # if there are multiple hints, we will use the first one that works,
       -        # from a random permutation
       -        random.shuffle(r_tags)
                channels = list(self.channels.values())
                scid_to_my_channels = {chan.short_channel_id: chan for chan in channels
                                       if chan.short_channel_id is not None}