mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
lnworker: fix listchannels
This commit is contained in:
parent
578faeb91a
commit
a42c1067ab
2 changed files with 13 additions and 10 deletions
|
@ -22,6 +22,13 @@ from .lnutil import ScriptHtlc, SENT, RECEIVED, PaymentFailure, calc_onchain_fee
|
||||||
from .transaction import Transaction, TxOutput, construct_witness
|
from .transaction import Transaction, TxOutput, construct_witness
|
||||||
from .simple_config import SimpleConfig, FEERATE_FALLBACK_STATIC_FEE
|
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"])
|
RevokeAndAck = namedtuple("RevokeAndAck", ["per_commitment_secret", "next_per_commitment_point"])
|
||||||
|
|
||||||
|
@ -685,14 +692,7 @@ class Channel(PrintError):
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
namedtuples_to_dict = lambda v: {i: j._asdict() if isinstance(j, tuple) else j for i, j in v._asdict().items()}
|
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()}
|
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):
|
dumped = ChannelJsonEncoder().encode(serialized_channel)
|
||||||
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)
|
|
||||||
roundtripped = json.loads(dumped)
|
roundtripped = json.loads(dumped)
|
||||||
reconstructed = Channel(roundtripped)
|
reconstructed = Channel(roundtripped)
|
||||||
if reconstructed.to_save() != self.to_save():
|
if reconstructed.to_save() != self.to_save():
|
||||||
|
|
|
@ -6,6 +6,7 @@ import time
|
||||||
from typing import Optional, Sequence, Tuple, List, Dict, TYPE_CHECKING
|
from typing import Optional, Sequence, Tuple, List, Dict, TYPE_CHECKING
|
||||||
import threading
|
import threading
|
||||||
import socket
|
import socket
|
||||||
|
import json
|
||||||
|
|
||||||
import dns.resolver
|
import dns.resolver
|
||||||
import dns.exception
|
import dns.exception
|
||||||
|
@ -20,7 +21,7 @@ from .lntransport import LNResponderTransport
|
||||||
from .lnbase import Peer
|
from .lnbase import Peer
|
||||||
from .lnaddr import lnencode, LnAddr, lndecode
|
from .lnaddr import lnencode, LnAddr, lndecode
|
||||||
from .ecc import der_sig_from_sig_string
|
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,
|
from .lnutil import (Outpoint, calc_short_channel_id, LNPeerAddr,
|
||||||
get_compressed_pubkey_from_bech32, extract_nodeid,
|
get_compressed_pubkey_from_bech32, extract_nodeid,
|
||||||
PaymentFailure, split_host_port, ConnStringFormatError,
|
PaymentFailure, split_host_port, ConnStringFormatError,
|
||||||
|
@ -405,11 +406,13 @@ class LNWorker(PrintError):
|
||||||
self.wallet.storage.write()
|
self.wallet.storage.write()
|
||||||
|
|
||||||
def list_channels(self):
|
def list_channels(self):
|
||||||
|
encoder = ChannelJsonEncoder()
|
||||||
with self.lock:
|
with self.lock:
|
||||||
# we output the funding_outpoint instead of the channel_id because lnd uses channel_point (funding outpoint) to identify channels
|
# 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():
|
for channel_id, chan in self.channels.items():
|
||||||
yield {
|
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_id': bh2u(chan.short_channel_id),
|
||||||
'channel_point': chan.funding_outpoint.to_str(),
|
'channel_point': chan.funding_outpoint.to_str(),
|
||||||
'state': chan.get_state(),
|
'state': chan.get_state(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue