lnworker: rename can_send to num_sats_can_send

This commit is contained in:
SomberNight 2020-03-26 07:00:15 +01:00
parent 5c8455d00b
commit 79d202485e
No known key found for this signature in database
GPG key ID: B33B5F232C6271E9
5 changed files with 25 additions and 12 deletions

View file

@ -105,7 +105,7 @@ class InvoiceDialog(Factory.Popup):
self.status_color = pr_color[self.status] self.status_color = pr_color[self.status]
self.can_pay = self.status in [PR_UNPAID, PR_FAILED] self.can_pay = self.status in [PR_UNPAID, PR_FAILED]
if self.can_pay and self.is_lightning and self.app.wallet.lnworker: if self.can_pay and self.is_lightning and self.app.wallet.lnworker:
if self.amount and self.amount > self.app.wallet.lnworker.can_send(): if self.amount and self.amount > self.app.wallet.lnworker.num_sats_can_send():
self.warning = _('Warning') + ': ' + _('This amount exceeds the maximum you can currently send with your channels') self.warning = _('Warning') + ': ' + _('This amount exceeds the maximum you can currently send with your channels')
def on_dismiss(self): def on_dismiss(self):

View file

@ -1,14 +1,21 @@
import asyncio import asyncio
import binascii import binascii
from typing import TYPE_CHECKING
from kivy.lang import Builder from kivy.lang import Builder
from kivy.factory import Factory from kivy.factory import Factory
from kivy.uix.popup import Popup from kivy.uix.popup import Popup
from kivy.clock import Clock from kivy.clock import Clock
from electrum.util import bh2u from electrum.util import bh2u
from electrum.lnutil import LOCAL, REMOTE, format_short_channel_id from electrum.lnutil import LOCAL, REMOTE, format_short_channel_id
from electrum.gui.kivy.i18n import _ from electrum.gui.kivy.i18n import _
from .question import Question from .question import Question
if TYPE_CHECKING:
from ...main_window import ElectrumWindow
Builder.load_string(r''' Builder.load_string(r'''
<LightningChannelItem@CardItem> <LightningChannelItem@CardItem>
details: {} details: {}
@ -267,7 +274,7 @@ class ChannelDetailsPopup(Popup):
class LightningChannelsDialog(Factory.Popup): class LightningChannelsDialog(Factory.Popup):
def __init__(self, app): def __init__(self, app: 'ElectrumWindow'):
super(LightningChannelsDialog, self).__init__() super(LightningChannelsDialog, self).__init__()
self.clocks = [] self.clocks = []
self.app = app self.app = app
@ -321,5 +328,5 @@ class LightningChannelsDialog(Factory.Popup):
def update_can_send(self): def update_can_send(self):
lnworker = self.app.wallet.lnworker lnworker = self.app.wallet.lnworker
self.can_send = self.app.format_amount_and_units(lnworker.can_send()) self.can_send = self.app.format_amount_and_units(lnworker.num_sats_can_send())
self.can_receive = self.app.format_amount_and_units(lnworker.can_receive()) self.can_receive = self.app.format_amount_and_units(lnworker.num_sats_can_receive())

View file

@ -1,3 +1,5 @@
from typing import TYPE_CHECKING
from kivy.factory import Factory from kivy.factory import Factory
from kivy.lang import Builder from kivy.lang import Builder
from kivy.core.clipboard import Clipboard from kivy.core.clipboard import Clipboard
@ -8,6 +10,9 @@ from electrum.gui.kivy.i18n import _
from electrum.util import pr_tooltips, pr_color, get_request_status from electrum.util import pr_tooltips, pr_color, get_request_status
from electrum.util import PR_UNKNOWN, PR_UNPAID, PR_FAILED, PR_TYPE_LN from electrum.util import PR_UNKNOWN, PR_UNPAID, PR_FAILED, PR_TYPE_LN
if TYPE_CHECKING:
from ...main_window import ElectrumWindow
Builder.load_string(''' Builder.load_string('''
<RequestDialog@Popup> <RequestDialog@Popup>
@ -84,7 +89,7 @@ class RequestDialog(Factory.Popup):
def __init__(self, title, data, key, *, is_lightning=False): def __init__(self, title, data, key, *, is_lightning=False):
self.status = PR_UNKNOWN self.status = PR_UNKNOWN
Factory.Popup.__init__(self) Factory.Popup.__init__(self)
self.app = App.get_running_app() self.app = App.get_running_app() # type: ElectrumWindow
self.title = title self.title = title
self.data = data self.data = data
self.key = key self.key = key
@ -107,7 +112,7 @@ class RequestDialog(Factory.Popup):
self.status, self.status_str = get_request_status(req) self.status, self.status_str = get_request_status(req)
self.status_color = pr_color[self.status] self.status_color = pr_color[self.status]
if self.status == PR_UNPAID and self.is_lightning and self.app.wallet.lnworker: if self.status == PR_UNPAID and self.is_lightning and self.app.wallet.lnworker:
if self.amount and self.amount > self.app.wallet.lnworker.can_receive(): if self.amount and self.amount > self.app.wallet.lnworker.num_sats_can_receive():
self.warning = _('Warning') + ': ' + _('This amount exceeds the maximum you can currently receive with your channels') self.warning = _('Warning') + ': ' + _('This amount exceeds the maximum you can currently receive with your channels')
def on_dismiss(self): def on_dismiss(self):

View file

@ -14,6 +14,7 @@ from electrum.i18n import _
from electrum.lnchannel import Channel, peer_states from electrum.lnchannel import Channel, peer_states
from electrum.wallet import Abstract_Wallet from electrum.wallet import Abstract_Wallet
from electrum.lnutil import LOCAL, REMOTE, format_short_channel_id, LN_MAX_FUNDING_SAT from electrum.lnutil import LOCAL, REMOTE, format_short_channel_id, LN_MAX_FUNDING_SAT
from electrum.lnworker import LNWallet
from .util import (MyTreeView, WindowModalDialog, Buttons, OkButton, CancelButton, from .util import (MyTreeView, WindowModalDialog, Buttons, OkButton, CancelButton,
EnterButton, WaitingDialog, MONOSPACE_FONT, ColorScheme) EnterButton, WaitingDialog, MONOSPACE_FONT, ColorScheme)
@ -224,10 +225,10 @@ class ChannelsList(MyTreeView):
item.setBackground(self._default_item_bg_brush) item.setBackground(self._default_item_bg_brush)
item.setToolTip("") item.setToolTip("")
def update_can_send(self, lnworker): def update_can_send(self, lnworker: LNWallet):
msg = _('Can send') + ' ' + self.parent.format_amount(lnworker.can_send())\ msg = _('Can send') + ' ' + self.parent.format_amount(lnworker.num_sats_can_send())\
+ ' ' + self.parent.base_unit() + '; '\ + ' ' + self.parent.base_unit() + '; '\
+ _('can receive') + ' ' + self.parent.format_amount(lnworker.can_receive())\ + _('can receive') + ' ' + self.parent.format_amount(lnworker.num_sats_can_receive())\
+ ' ' + self.parent.base_unit() + ' ' + self.parent.base_unit()
self.can_send_label.setText(msg) self.can_send_label.setText(msg)

View file

@ -7,7 +7,7 @@ import os
from decimal import Decimal from decimal import Decimal
import random import random
import time import time
from typing import Optional, Sequence, Tuple, List, Dict, TYPE_CHECKING, NamedTuple from typing import Optional, Sequence, Tuple, List, Dict, TYPE_CHECKING, NamedTuple, Union
import threading import threading
import socket import socket
import json import json
@ -1314,11 +1314,11 @@ class LNWallet(LNWorker):
with self.lock: with self.lock:
return Decimal(sum(chan.balance(LOCAL) if not chan.is_closed() else 0 for chan in self.channels.values()))/1000 return Decimal(sum(chan.balance(LOCAL) if not chan.is_closed() else 0 for chan in self.channels.values()))/1000
def can_send(self): def num_sats_can_send(self) -> Union[Decimal, int]:
with self.lock: with self.lock:
return Decimal(max(chan.available_to_spend(LOCAL) if chan.is_open() else 0 for chan in self.channels.values()))/1000 if self.channels else 0 return Decimal(max(chan.available_to_spend(LOCAL) if chan.is_open() else 0 for chan in self.channels.values()))/1000 if self.channels else 0
def can_receive(self): def num_sats_can_receive(self) -> Union[Decimal, int]:
with self.lock: with self.lock:
return Decimal(max(chan.available_to_spend(REMOTE) if chan.is_open() else 0 for chan in self.channels.values()))/1000 if self.channels else 0 return Decimal(max(chan.available_to_spend(REMOTE) if chan.is_open() else 0 for chan in self.channels.values()))/1000 if self.channels else 0