Janus
6 years ago
committed by
SomberNight
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
3 changed files with
18 additions and
5 deletions
-
electrum/gui/qt/channels_list.py
-
electrum/lnchan.py
-
electrum/tests/test_lnchan.py
|
|
@ -23,10 +23,19 @@ class ChannelsList(MyTreeWidget): |
|
|
|
self.status = QLabel('') |
|
|
|
|
|
|
|
def format_fields(self, chan): |
|
|
|
labels = {} |
|
|
|
for subject in (REMOTE, LOCAL): |
|
|
|
available = chan.available_to_spend(subject)//1000 |
|
|
|
label = self.parent.format_amount(available) |
|
|
|
bal_other = chan.balance(-subject)//1000 |
|
|
|
available_other = chan.available_to_spend(-subject)//1000 |
|
|
|
if bal_other != available_other: |
|
|
|
label += ' (+' + self.parent.format_amount(bal_other - available_other) + ')' |
|
|
|
labels[subject] = label |
|
|
|
return [ |
|
|
|
bh2u(chan.node_id), |
|
|
|
self.parent.format_amount(chan.balance(LOCAL)//1000), |
|
|
|
self.parent.format_amount(chan.balance(REMOTE)//1000), |
|
|
|
labels[LOCAL], |
|
|
|
labels[REMOTE], |
|
|
|
chan.get_state() |
|
|
|
] |
|
|
|
|
|
|
|
|
|
@ -155,11 +155,9 @@ class Channel(PrintError): |
|
|
|
return self._state |
|
|
|
|
|
|
|
def check_can_pay(self, amount_msat): |
|
|
|
# FIXME what about channel_reserve_satoshis? will the remote fail the channel if we go below? test. |
|
|
|
# FIXME what about tx fees |
|
|
|
if self.get_state() != 'OPEN': |
|
|
|
raise PaymentFailure('Channel not open') |
|
|
|
if self.balance(LOCAL) < amount_msat: |
|
|
|
if self.available_to_spend(LOCAL) < amount_msat: |
|
|
|
raise PaymentFailure('Not enough local balance') |
|
|
|
if len(self.htlcs(LOCAL, only_pending=True)) + 1 > self.config[REMOTE].max_accepted_htlcs: |
|
|
|
raise PaymentFailure('Too many HTLCs already in channel') |
|
|
@ -461,6 +459,11 @@ class Channel(PrintError): |
|
|
|
assert initial == self.config[subject].amount_msat |
|
|
|
return initial |
|
|
|
|
|
|
|
def available_to_spend(self, subject): |
|
|
|
# FIXME what about channel_reserve_satoshis? will the remote fail the channel if we go below? test. |
|
|
|
# FIXME what about tx fees |
|
|
|
return self.balance(subject) - htlcsum(self.htlcs(subject, only_pending=True)) |
|
|
|
|
|
|
|
def amounts(self): |
|
|
|
remote_settled= htlcsum(self.htlcs(REMOTE, False)) |
|
|
|
local_settled= htlcsum(self.htlcs(LOCAL, False)) |
|
|
|
|
|
@ -339,6 +339,7 @@ class TestDust(unittest.TestCase): |
|
|
|
aliceHtlcIndex = alice_channel.add_htlc(htlc) |
|
|
|
bobHtlcIndex = bob_channel.receive_htlc(htlc) |
|
|
|
force_state_transition(alice_channel, bob_channel) |
|
|
|
self.assertEqual(alice_channel.available_to_spend(LOCAL), alice_channel.balance(LOCAL) - htlc['amount_msat']) |
|
|
|
self.assertEqual(len(alice_channel.local_commitment.outputs()), 3) |
|
|
|
self.assertEqual(len(bob_channel.local_commitment.outputs()), 2) |
|
|
|
default_fee = calc_static_fee(0) |
|
|
|