1
0

LN invoices: support msat precision

fixes #6250
This commit is contained in:
SomberNight
2020-06-22 22:37:58 +02:00
parent 599797c966
commit d5f368c584
19 changed files with 260 additions and 135 deletions

View File

@@ -6,6 +6,7 @@ import time
from hashlib import sha256
from binascii import hexlify
from decimal import Decimal
from typing import Optional
import bitstring
@@ -33,7 +34,7 @@ def shorten_amount(amount):
break
return str(amount) + unit
def unshorten_amount(amount):
def unshorten_amount(amount) -> Decimal:
""" Given a shortened amount, convert it into a decimal
"""
# BOLT #11:
@@ -271,12 +272,20 @@ class LnAddr(object):
self.signature = None
self.pubkey = None
self.currency = constants.net.SEGWIT_HRP if currency is None else currency
self.amount = amount # in bitcoins
self.amount = amount # type: Optional[Decimal] # in bitcoins
self._min_final_cltv_expiry = 9
def get_amount_sat(self):
def get_amount_sat(self) -> Optional[Decimal]:
# note that this has msat resolution potentially
if self.amount is None:
return None
return self.amount * COIN
def get_amount_msat(self) -> Optional[int]:
if self.amount is None:
return None
return int(self.amount * COIN * 1000)
def __str__(self):
return "LnAddr[{}, amount={}{} tags=[{}]]".format(
hexlify(self.pubkey.serialize()).decode('utf-8') if self.pubkey else None,