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

@ -103,6 +103,7 @@ let
nix-bitcoin.onionServices.lnd.public = true;
tests.lndconnect-onion-lnd = with cfg.lnd.lndconnect; enable && onion;
tests.lnconnect-onion-clnrest = with cfg.clightning.plugins.clnrest.lnconnect; enable && onion;
tests.lndconnect-onion-clightning = with cfg.clightning-rest.lndconnect; enable && onion;
tests.lightning-loop = cfg.lightning-loop.enable;
@ -195,6 +196,10 @@ let
encrypt = true;
local.directory = "/var/backup/clightning";
};
services.clightning.plugins.clnrest = {
enable = true;
lnconnect = { enable = true; onion = true; };
};
test.features.clightningPlugins = true;
services.rtl.enable = true;
services.clightning-rest.enable = true;

View file

@ -179,6 +179,11 @@ def _():
assert_running("lnd")
assert_matches("runuser -u operator -- lndconnect --url", ".onion")
@test("lnconnect-onion-clnrest")
def _():
assert_running("clightning")
assert_matches("runuser -u operator -- lnconnect-clnrest --url", ".onion")
@test("lndconnect-onion-clightning")
def _():
assert_running("clightning-rest")

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")