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,
|
"sender": self.sender,
|
||||||
"body": self.body,
|
"body": self.body,
|
||||||
"signature": hexlify(self.signature).decode('ASCII'),
|
"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,
|
"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):
|
def serialize_payload(n, blockheight):
|
||||||
block, tx, out = n['channel'].split('x')
|
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)
|
preimage = payload.get(TLV_KEYSEND_PREIMAGE)
|
||||||
if preimage is not None:
|
if preimage is not None:
|
||||||
|
msg.payment = Payment(preimage.value, htlc['amount'])
|
||||||
res = {
|
res = {
|
||||||
'result': 'resolve',
|
'result': 'resolve',
|
||||||
'payment_key': hexlify(preimage.value).decode('ASCII')
|
'payment_key': hexlify(preimage.value).decode('ASCII')
|
||||||
|
|||||||
@@ -83,6 +83,10 @@ def test_msg_and_keysend(node_factory, executor):
|
|||||||
|
|
||||||
assert(m['sender'] == l1.info['id'])
|
assert(m['sender'] == l1.info['id'])
|
||||||
assert(m['verified'] == True)
|
assert(m['verified'] == True)
|
||||||
|
p = m['payment']
|
||||||
|
assert(p is not None)
|
||||||
|
assert(p['payment_key'] is not None)
|
||||||
|
assert(p['amount'] == '10000msat')
|
||||||
|
|
||||||
# Check that l3 actually got the funds I sent it
|
# Check that l3 actually got the funds I sent it
|
||||||
wait_for(lambda: l3.rpc.listpeers()['peers'][0]['channels'][0]['msatoshi_to_us'] == amt)
|
wait_for(lambda: l3.rpc.listpeers()['peers'][0]['channels'][0]['msatoshi_to_us'] == amt)
|
||||||
|
|||||||
Reference in New Issue
Block a user