URI: 
       tlnworker: fix listchannels - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit a42c1067abcdd1a610f3d26da804703055a34b1a
   DIR parent 578faeb91a7139252c75337c1e65bc5739a8ec3d
  HTML Author: Janus <ysangkok@gmail.com>
       Date:   Thu, 25 Oct 2018 00:22:42 +0200
       
       lnworker: fix listchannels
       
       Diffstat:
         M electrum/lnchan.py                  |      16 ++++++++--------
         M electrum/lnworker.py                |       7 +++++--
       
       2 files changed, 13 insertions(+), 10 deletions(-)
       ---
   DIR diff --git a/electrum/lnchan.py b/electrum/lnchan.py
       t@@ -22,6 +22,13 @@ from .lnutil import ScriptHtlc, SENT, RECEIVED, PaymentFailure, calc_onchain_fee
        from .transaction import Transaction, TxOutput, construct_witness
        from .simple_config import SimpleConfig, FEERATE_FALLBACK_STATIC_FEE
        
       +class ChannelJsonEncoder(json.JSONEncoder):
       +    def default(self, o):
       +        if isinstance(o, bytes):
       +            return binascii.hexlify(o).decode("ascii")
       +        if isinstance(o, RevocationStore):
       +            return o.serialize()
       +        return super(ChannelJsonEncoder, self)
        
        RevokeAndAck = namedtuple("RevokeAndAck", ["per_commitment_secret", "next_per_commitment_point"])
        
       t@@ -685,14 +692,7 @@ class Channel(PrintError):
            def serialize(self):
                namedtuples_to_dict = lambda v: {i: j._asdict() if isinstance(j, tuple) else j for i, j in v._asdict().items()}
                serialized_channel = {k: namedtuples_to_dict(v) if isinstance(v, tuple) else v for k, v in self.to_save().items()}
       -        class MyJsonEncoder(json.JSONEncoder):
       -            def default(self, o):
       -                if isinstance(o, bytes):
       -                    return binascii.hexlify(o).decode("ascii")
       -                if isinstance(o, RevocationStore):
       -                    return o.serialize()
       -                return super(MyJsonEncoder, self)
       -        dumped = MyJsonEncoder().encode(serialized_channel)
       +        dumped = ChannelJsonEncoder().encode(serialized_channel)
                roundtripped = json.loads(dumped)
                reconstructed = Channel(roundtripped)
                if reconstructed.to_save() != self.to_save():
   DIR diff --git a/electrum/lnworker.py b/electrum/lnworker.py
       t@@ -6,6 +6,7 @@ import time
        from typing import Optional, Sequence, Tuple, List, Dict, TYPE_CHECKING
        import threading
        import socket
       +import json
        
        import dns.resolver
        import dns.exception
       t@@ -20,7 +21,7 @@ from .lntransport import LNResponderTransport
        from .lnbase import Peer
        from .lnaddr import lnencode, LnAddr, lndecode
        from .ecc import der_sig_from_sig_string
       -from .lnchan import Channel
       +from .lnchan import Channel, ChannelJsonEncoder
        from .lnutil import (Outpoint, calc_short_channel_id, LNPeerAddr,
                             get_compressed_pubkey_from_bech32, extract_nodeid,
                             PaymentFailure, split_host_port, ConnStringFormatError,
       t@@ -405,11 +406,13 @@ class LNWorker(PrintError):
                self.wallet.storage.write()
        
            def list_channels(self):
       +        encoder = ChannelJsonEncoder()
                with self.lock:
                    # we output the funding_outpoint instead of the channel_id because lnd uses channel_point (funding outpoint) to identify channels
                    for channel_id, chan in self.channels.items():
                        yield {
       -                    'htlcs': chan.log[LOCAL],
       +                    'local_htlcs':  json.loads(encoder.encode(chan.log[LOCAL ])),
       +                    'remote_htlcs': json.loads(encoder.encode(chan.log[REMOTE])),
                            'channel_id': bh2u(chan.short_channel_id),
                            'channel_point': chan.funding_outpoint.to_str(),
                            'state': chan.get_state(),