MCPcopy Create free account
hub / github.com/ElementsProject/lightning / pay_with_sendonion

Function pay_with_sendonion

tests/test_pay.py:7045–7084  ·  view source on GitHub ↗
(invoice, route, groupid, partid)

Source from the content-addressed store, hash-verified

7043 )
7044
7045 def pay_with_sendonion(invoice, route, groupid, partid):
7046 blockheight = l1.rpc.getinfo()["blockheight"]
7047 # Need to shift the parameters by one hop
7048 hops = []
7049 for h, n in zip(route[:-1], route[1:]):
7050 # We tell the node h about the parameters to use for n (a.k.a. h + 1)
7051 hops.append(
7052 {
7053 "pubkey": h["node_id_out"],
7054 "payload": serialize_payload_tlv(
7055 n["amount_out_msat"], n["cltv_out"], n["short_channel_id_dir"].rsplit("/", 1)[0], blockheight
7056 ).hex(),
7057 }
7058 )
7059 # The last hop has a special payload:
7060 hops.append(
7061 {
7062 "pubkey": route[-1]["node_id_out"],
7063 "payload": serialize_payload_final_tlv(
7064 route[-1]["amount_out_msat"],
7065 route[-1]["cltv_out"],
7066 invoice["amount_msat"],
7067 blockheight,
7068 invoice["payment_secret"],
7069 ).hex(),
7070 }
7071 )
7072 onion = l1.rpc.createonion(hops=hops, assocdata=invoice["payment_hash"])
7073 l1.rpc.call(
7074 "sendonion",
7075 {
7076 "onion": onion["onion"],
7077 "shared_secrets": onion["shared_secrets"],
7078 "first_hop": {"id": route[0]["node_id_out"], "amount_msat": route[0]["amount_out_msat"], "delay": route[0]["cltv_out"]},
7079 "payment_hash": invoice["payment_hash"],
7080 "total_amount_msat": invoice["amount_msat"],
7081 "groupid": groupid,
7082 "partid": partid,
7083 },
7084 )
7085
7086 pay_with_sendpay(inv, route2, 1, 1)
7087 pay_with_sendonion(inv, route8, 1, 2)

Callers 1

test_sendonion_sendpayFunction · 0.85

Calls 4

serialize_payload_tlvFunction · 0.90
getinfoMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected