From 6a15ebadad8002fca7e30887698d555fae98009f Mon Sep 17 00:00:00 2001 From: daywalker90 Date: Mon, 8 Jun 2026 16:20:51 +0200 Subject: [PATCH] feat: generate CLN invoice preimage ourselves to support sub-wallets (#2412) --- apps/apps_service.go | 5 ++-- apps/tests/apps_service_test.go | 2 +- lnclient/cln/cln.go | 26 ++++++++++++++++--- .../create_connection_controller_test.go | 2 +- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/apps/apps_service.go b/apps/apps_service.go index f36e2125..62c53b98 100644 --- a/apps/apps_service.go +++ b/apps/apps_service.go @@ -59,9 +59,10 @@ func (svc *appsService) CreateApp(name string, pubkey string, maxAmountSat uint6 if backendType != config.LDKBackendType && backendType != config.LNDBackendType && backendType != config.PhoenixBackendType && - backendType != config.BarkBackendType { + backendType != config.BarkBackendType && + backendType != config.CLNBackendType { return nil, "", fmt.Errorf( - "sub-wallets are currently not supported on your node backend. Try LDK or LND") + "sub-wallets are currently not supported on your node backend. Try LDK, LND, PHOENIX, BARK, or CLN") } } diff --git a/apps/tests/apps_service_test.go b/apps/tests/apps_service_test.go index ee4a413d..c4690fa0 100644 --- a/apps/tests/apps_service_test.go +++ b/apps/tests/apps_service_test.go @@ -54,5 +54,5 @@ func TestHandleCreateApp_IsolatedUnsupportedBackendType(t *testing.T) { assert.Nil(t, app) assert.Equal(t, "", secretKey) require.Error(t, err) - assert.Equal(t, "sub-wallets are currently not supported on your node backend. Try LDK or LND", err.Error()) + assert.Equal(t, "sub-wallets are currently not supported on your node backend. Try LDK, LND, PHOENIX, BARK, or CLN", err.Error()) } diff --git a/lnclient/cln/cln.go b/lnclient/cln/cln.go index 3cd39812..708cfac3 100644 --- a/lnclient/cln/cln.go +++ b/lnclient/cln/cln.go @@ -2,6 +2,7 @@ package cln import ( "context" + crand "crypto/rand" "crypto/sha256" "crypto/tls" "crypto/x509" @@ -9,7 +10,7 @@ import ( "errors" "fmt" "math" - "math/rand" + mrand "math/rand" "os" "path/filepath" "regexp" @@ -680,7 +681,7 @@ func (c *CLNService) subscribeOpenHoldInvoices(ctx context.Context) { backoff := min(baseBackoff*time.Duration(1<