mirror of
https://github.com/aljazceru/plugins.git
synced 2025-12-22 15:44:20 +01:00
noise: Add a Payment class for keysend payments
Suggested-by: Richard Bondi <@rsbondi>
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user