diff --git a/noise/noise.py b/noise/noise.py index ecfad14..2b020bd 100755 --- a/noise/noise.py +++ b/noise/noise.py @@ -53,13 +53,25 @@ class Payment(object): def serialize_payload(n, blockheight): block, tx, out = n['channel'].split('x') - payload = hexlify(struct.pack( - "!cQQL", b'\x00', - int(block) << 40 | int(tx) << 16 | int(out), - int(n['amount_msat']), - blockheight + n['delay'])).decode('ASCII') - payload += "00" * 12 - return payload + scid = int(block) << 40 | int(tx) << 16 | int(out) + def minint(i): + if i < 2**8: + return struct.pack("!b", i) + elif i < 2**16: + return struct.pack('!H', i) + elif i < 2**32: + return struct.pack("!I", i) + else: + return struct.pack("!Q", i) + + amt = int(n['amount_msat']) + cltv = blockheight + n['delay'] + + payload = TlvPayload() + payload.add_field(2, minint(amt)) + payload.add_field(4, minint(cltv)) + payload.add_field(6, minint(scid)) + return payload.to_bytes().hex() def buildpath(plugin, node_id, payload, amt, exclusions): @@ -71,7 +83,7 @@ def buildpath(plugin, node_id, payload, amt, exclusions): for h, n in zip(route[:-1], route[1:]): # We tell the node h about the parameters to use for n (a.k.a. h + 1) hops.append({ - "type": "legacy", + "type": "tlv", "pubkey": h['id'], "payload": serialize_payload(n, blockheight) }) @@ -201,8 +213,11 @@ def on_htlc_accepted(onion, htlc, plugin, **kwargs): msg.verified = sigcheck['verified'] preimage = payload.get(TLV_KEYSEND_PREIMAGE) + print("YYY") + print(htlc) + print(onion) if preimage is not None: - msg.payment = Payment(preimage.value, htlc['amount']) + msg.payment = Payment(preimage.value, htlc['amount_msat']) res = { 'result': 'resolve', 'payment_key': hexlify(preimage.value).decode('ASCII') diff --git a/noise/requirements-dev.txt b/noise/requirements-dev.txt deleted file mode 100644 index dd26539..0000000 --- a/noise/requirements-dev.txt +++ /dev/null @@ -1 +0,0 @@ -flaky ~= 3.7.0 diff --git a/noise/requirements.txt b/noise/requirements.txt deleted file mode 100644 index f947c57..0000000 --- a/noise/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -pyln-client>=0.8.0 -bitstring==3.1.6 -pyln-proto diff --git a/noise/test_chat.py b/noise/test_chat.py index 28b429b..f50af4f 100644 --- a/noise/test_chat.py +++ b/noise/test_chat.py @@ -110,7 +110,7 @@ def test_msg_and_keysend(node_factory, executor): p = m['payment'] assert(p is not None) assert(p['payment_key'] is not None) - assert(p['amount'] == '10000msat') + assert(p['amount'] == 10000) # Check that l3 actually got the funds I sent it wait_for(lambda: l3.rpc.listpeers()['peers'][0]['channels'][0]['to_us_msat'] == amt)