electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 9451ca9568b2b1f966dbf5784258e29e656b629e
parent 238fb46d878149b03ffc7e4b530cee0a22d8ebd2
Author: ThomasV <thomasv@electrum.org>
Date:   Thu, 20 Feb 2020 10:30:30 +0100

move list_channels to commands.py

Diffstat:
Melectrum/commands.py | 18+++++++++++++++++-
Melectrum/lnworker.py | 19+------------------
2 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/electrum/commands.py b/electrum/commands.py @@ -956,7 +956,23 @@ class Commands: @command('w') async def list_channels(self, wallet: Abstract_Wallet = None): - return list(wallet.lnworker.list_channels()) + # we output the funding_outpoint instead of the channel_id because lnd uses channel_point (funding outpoint) to identify channels + from .lnutil import LOCAL, REMOTE, format_short_channel_id + encoder = util.MyEncoder() + l = list(wallet.lnworker.channels.items()) + return [ + { + 'local_htlcs': json.loads(encoder.encode(chan.hm.log[LOCAL])), + 'remote_htlcs': json.loads(encoder.encode(chan.hm.log[REMOTE])), + 'channel_id': format_short_channel_id(chan.short_channel_id) if chan.short_channel_id else None, + 'full_channel_id': bh2u(chan.channel_id), + 'channel_point': chan.funding_outpoint.to_str(), + 'state': chan.get_state().name, + 'remote_pubkey': bh2u(chan.node_id), + 'local_balance': chan.balance(LOCAL)//1000, + 'remote_balance': chan.balance(REMOTE)//1000, + } for channel_id, chan in l + ] @command('wn') async def dumpgraph(self, wallet: Abstract_Wallet = None): diff --git a/electrum/lnworker.py b/electrum/lnworker.py @@ -51,7 +51,7 @@ from .lnutil import (Outpoint, LNPeerAddr, generate_keypair, LnKeyFamily, LOCAL, REMOTE, UnknownPaymentHash, MIN_FINAL_CLTV_EXPIRY_FOR_INVOICE, NUM_MAX_EDGES_IN_PAYMENT_PATH, SENT, RECEIVED, HTLCOwner, - UpdateAddHtlc, Direction, LnLocalFeatures, format_short_channel_id, + UpdateAddHtlc, Direction, LnLocalFeatures, ShortChannelID, PaymentAttemptLog, PaymentAttemptFailureDetails) from .lnutil import ln_dummy_address from .transaction import PartialTxOutput, PartialTransaction, PartialTxInput @@ -1171,23 +1171,6 @@ class LNWallet(LNWorker): with self.lock: return Decimal(max(chan.available_to_spend(REMOTE) if chan.is_open() else 0 for chan in self.channels.values()))/1000 - def list_channels(self): - encoder = MyEncoder() - 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 { - 'local_htlcs': json.loads(encoder.encode(chan.hm.log[LOCAL])), - 'remote_htlcs': json.loads(encoder.encode(chan.hm.log[REMOTE])), - 'channel_id': format_short_channel_id(chan.short_channel_id) if chan.short_channel_id else None, - 'full_channel_id': bh2u(chan.channel_id), - 'channel_point': chan.funding_outpoint.to_str(), - 'state': chan.get_state().name, - 'remote_pubkey': bh2u(chan.node_id), - 'local_balance': chan.balance(LOCAL)//1000, - 'remote_balance': chan.balance(REMOTE)//1000, - } - async def close_channel(self, chan_id): chan = self.channels[chan_id] peer = self.peers[chan.node_id]