mirror of
https://github.com/aljazceru/plugins.git
synced 2025-12-22 15:44:20 +01:00
noise: Migrate noise over to poetry and add TLV support
TLV was removed in 0.12, so we should not be using it ourselves either.
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
flaky ~= 3.7.0
|
||||
@@ -1,3 +0,0 @@
|
||||
pyln-client>=0.8.0
|
||||
bitstring==3.1.6
|
||||
pyln-proto
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user