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):
|
def serialize_payload(n, blockheight):
|
||||||
block, tx, out = n['channel'].split('x')
|
block, tx, out = n['channel'].split('x')
|
||||||
payload = hexlify(struct.pack(
|
scid = int(block) << 40 | int(tx) << 16 | int(out)
|
||||||
"!cQQL", b'\x00',
|
def minint(i):
|
||||||
int(block) << 40 | int(tx) << 16 | int(out),
|
if i < 2**8:
|
||||||
int(n['amount_msat']),
|
return struct.pack("!b", i)
|
||||||
blockheight + n['delay'])).decode('ASCII')
|
elif i < 2**16:
|
||||||
payload += "00" * 12
|
return struct.pack('!H', i)
|
||||||
return payload
|
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):
|
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:]):
|
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)
|
# We tell the node h about the parameters to use for n (a.k.a. h + 1)
|
||||||
hops.append({
|
hops.append({
|
||||||
"type": "legacy",
|
"type": "tlv",
|
||||||
"pubkey": h['id'],
|
"pubkey": h['id'],
|
||||||
"payload": serialize_payload(n, blockheight)
|
"payload": serialize_payload(n, blockheight)
|
||||||
})
|
})
|
||||||
@@ -201,8 +213,11 @@ def on_htlc_accepted(onion, htlc, plugin, **kwargs):
|
|||||||
msg.verified = sigcheck['verified']
|
msg.verified = sigcheck['verified']
|
||||||
|
|
||||||
preimage = payload.get(TLV_KEYSEND_PREIMAGE)
|
preimage = payload.get(TLV_KEYSEND_PREIMAGE)
|
||||||
|
print("YYY")
|
||||||
|
print(htlc)
|
||||||
|
print(onion)
|
||||||
if preimage is not None:
|
if preimage is not None:
|
||||||
msg.payment = Payment(preimage.value, htlc['amount'])
|
msg.payment = Payment(preimage.value, htlc['amount_msat'])
|
||||||
res = {
|
res = {
|
||||||
'result': 'resolve',
|
'result': 'resolve',
|
||||||
'payment_key': hexlify(preimage.value).decode('ASCII')
|
'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']
|
p = m['payment']
|
||||||
assert(p is not None)
|
assert(p is not None)
|
||||||
assert(p['payment_key'] 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
|
# Check that l3 actually got the funds I sent it
|
||||||
wait_for(lambda: l3.rpc.listpeers()['peers'][0]['channels'][0]['to_us_msat'] == amt)
|
wait_for(lambda: l3.rpc.listpeers()['peers'][0]['channels'][0]['to_us_msat'] == amt)
|
||||||
|
|||||||
Reference in New Issue
Block a user