diff --git a/noise/noise.py b/noise/noise.py index 0f47044..ac4e3e3 100755 --- a/noise/noise.py +++ b/noise/noise.py @@ -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') diff --git a/noise/test_chat.py b/noise/test_chat.py index 7f67d13..e7336c6 100644 --- a/noise/test_chat.py +++ b/noise/test_chat.py @@ -83,6 +83,10 @@ def test_msg_and_keysend(node_factory, executor): assert(m['sender'] == l1.info['id']) 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 wait_for(lambda: l3.rpc.listpeers()['peers'][0]['channels'][0]['msatoshi_to_us'] == amt)