1
0
This commit is contained in:
ThomasV
2020-04-11 12:02:38 +02:00
parent 7a11c05916
commit 312ef15cd6
5 changed files with 32 additions and 22 deletions

View File

@@ -13,6 +13,8 @@ from .bitcoin import hash160_to_b58_address, b58_address_to_hash160
from .segwit_addr import bech32_encode, bech32_decode, CHARSET
from . import constants
from . import ecc
from .util import PR_TYPE_LN
from .bitcoin import COIN
# BOLT #11:
@@ -307,6 +309,11 @@ class LnAddr(object):
class LnDecodeException(Exception): pass
class SerializableKey:
def __init__(self, pubkey):
self.pubkey = pubkey
def serialize(self):
return self.pubkey.get_public_key_bytes(True)
def lndecode(invoice: str, *, verbose=False, expected_hrp=None) -> LnAddr:
if expected_hrp is None:
@@ -460,11 +467,22 @@ def lndecode(invoice: str, *, verbose=False, expected_hrp=None) -> LnAddr:
return addr
class SerializableKey:
def __init__(self, pubkey):
self.pubkey = pubkey
def serialize(self):
return self.pubkey.get_public_key_bytes(True)
def parse_lightning_invoice(invoice):
lnaddr = lndecode(invoice, expected_hrp=constants.net.SEGWIT_HRP)
amount = int(lnaddr.amount * COIN) if lnaddr.amount else None
return {
'type': PR_TYPE_LN,
'invoice': invoice,
'amount': amount,
'message': lnaddr.get_description(),
'time': lnaddr.date,
'exp': lnaddr.get_expiry(),
'pubkey': lnaddr.pubkey.serialize().hex(),
'rhash': lnaddr.paymenthash.hex(),
}
if __name__ == '__main__':
# run using