lndconnect: add clnrest

This commit is contained in:
Erik Arvstedt 2024-10-10 12:13:17 +02:00
parent 87b929bc99
commit daa3bfbae3
No known key found for this signature in database
GPG key ID: 33312B944DD97846
9 changed files with 171 additions and 29 deletions

View file

@ -18,6 +18,14 @@ makeTestVM {
nix-bitcoin.generateSecrets = true;
nix-bitcoin.operator.enable = true;
services.clightning = {
enable = true;
plugins.clnrest = {
enable = true;
lnconnect.enable = true;
};
};
services.clightning-rest = {
enable = true;
lndconnect.enable = true;
@ -51,16 +59,19 @@ makeTestVM {
def parse_lndconnect_url(url):
u = Url.urlparse(url)
data = {'host': u.hostname, 'port': u.port}
queries = Url.parse_qs(u.query)
macaroon = queries['macaroon'][0]
is_clightning = url.startswith("c-lightning-rest")
if url.startswith("clnrest"):
data['rune'] = queries['rune'][0]
else:
macaroon = queries['macaroon'][0]
if url.startswith("c-lightning-rest"):
data['macaroon_hex'] = macaroon
else:
# lnd
data['macaroon_hex'] = base64.urlsafe_b64decode(macaroon + '===').hex().upper()
return SimpleNamespace(
host = u.hostname,
port = u.port,
macaroon_hex =
macaroon if is_clightning else base64.urlsafe_b64decode(macaroon + '===').hex().upper()
)
return SimpleNamespace(**data)
client.start()
server.connect()
@ -92,6 +103,16 @@ makeTestVM {
f"-X GET https://{api.host}:{api.port}/v1/getinfo"
)
with subtest("lnconnect-clnrest-wg"):
server.wait_for_unit("clightning.service")
lndconnect_url = server.succeed("runuser -u operator -- lnconnect-clnrest-wg --url")
api = parse_lndconnect_url(lndconnect_url)
# Make clnrest API call
client.succeed(
f"curl -fsS --max-time 3 --insecure --header 'rune: {api.rune}' "
f"-X POST https://{api.host}:{api.port}/v1/getinfo"
)
with subtest("lndconnect-clightning-wg"):
server.wait_for_unit("clightning-rest.service")
lndconnect_url = server.succeed("runuser -u operator -- lndconnect-clightning-wg --url")