noise: Add a Payment class for keysend payments

Suggested-by: Richard Bondi <@rsbondi>
This commit is contained in:
Christian Decker
2020-01-25 15:19:49 +01:00
parent 41aeed024d
commit 3290e4e456
2 changed files with 18 additions and 1 deletions

View File

@@ -37,10 +37,22 @@ class Message(object):
"sender": self.sender,
"body": self.body,
"signature": hexlify(self.signature).decode('ASCII'),
"payment": self.payment,
"payment": self.payment.to_dict() if self.payment is not None else None,
"verified": self.verified,
}
class Payment(object):
def __init__(self, payment_key, amount):
self.payment_key = payment_key
self.amount = amount
def to_dict(self):
return {
"payment_key": hexlify(self.payment_key).decode('ASCII'),
"payment_hash": hashlib.sha256(self.payment_key).hexdigest(),
"amount": self.amount,
}
def serialize_payload(n, blockheight):
block, tx, out = n['channel'].split('x')
@@ -182,6 +194,7 @@ def on_htlc_accepted(onion, htlc, plugin, **kwargs):
preimage = payload.get(TLV_KEYSEND_PREIMAGE)
if preimage is not None:
msg.payment = Payment(preimage.value, htlc['amount'])
res = {
'result': 'resolve',
'payment_key': hexlify(preimage.value).decode('ASCII')