util.Satoshis: note that sometimes this actually has 'msat' precision

This commit is contained in:
SomberNight 2020-02-17 16:52:25 +01:00
parent a6302b3a12
commit 0723355a0f
No known key found for this signature in database
GPG key ID: B33B5F232C6271E9
2 changed files with 5 additions and 2 deletions

View file

@ -208,13 +208,15 @@ class Satoshis(object):
def __new__(cls, value):
self = super(Satoshis, cls).__new__(cls)
# note: 'value' sometimes has msat precision
self.value = value
return self
def __repr__(self):
return 'Satoshis(%d)'%self.value
return f'Satoshis({self.value})'
def __str__(self):
# note: precision is truncated to satoshis here
return format_satoshis(self.value)
def __eq__(self, other):

View file

@ -765,6 +765,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
value += item['bc_value'].value
if item.get('ln_value'):
value += item.get('ln_value').value
# note: 'value' and 'balance' has msat precision (as LN has msat precision)
item['value'] = Satoshis(value)
balance += value
item['balance'] = Satoshis(balance)
@ -2426,7 +2427,7 @@ class Wallet(object):
This class is actually a factory that will return a wallet of the correct
type when passed a WalletStorage instance."""
def __new__(self, db, storage: WalletStorage, *, config: SimpleConfig):
def __new__(self, db: 'WalletDB', storage: Optional[WalletStorage], *, config: SimpleConfig):
wallet_type = db.get('wallet_type')
WalletClass = Wallet.wallet_class(wallet_type)
wallet = WalletClass(db, storage, config=config)