From 663acfda3a013ab0f9fc0524ef23f8497152460f Mon Sep 17 00:00:00 2001 From: bruwbird Date: Thu, 3 Oct 2024 11:00:48 +0900 Subject: [PATCH] clightning: compatibility issue with v24.11 Resolves a compatibility issue with clightning v24.11 and later versions where the allow-deprecated-apis option may be nested within a configs object in the configuration file. Now correctly parses the configuration to determine if deprecated APIs are allowed, ensuring compatibility with both older and newer clightning versions. --- clightning/config.go | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/clightning/config.go b/clightning/config.go index 616e9b85..4d2c20e2 100644 --- a/clightning/config.go +++ b/clightning/config.go @@ -99,6 +99,28 @@ func SetPeerswapPaths(plugin *glightning.Plugin) Processor { } } +type AllowDeprecatedAPIs struct { + ValueBool bool `json:"value_bool"` + Source string `json:"source"` +} +type Configs struct { + AllowDeprecatedAPIs *AllowDeprecatedAPIs `json:"allow-deprecated-apis,omitempty"` +} +type ClnConfig struct { + AllowDeprecatedApis bool `json:"allow-deprecated-apis,omitempty"` + Configs *Configs `json:"configs,omitempty"` +} + +func (c *ClnConfig) AllowDeprecatedAPIs() bool { + if c.AllowDeprecatedApis { + return c.AllowDeprecatedApis + } + if c.Configs != nil && c.Configs.AllowDeprecatedAPIs != nil { + return c.Configs.AllowDeprecatedAPIs.ValueBool + } + return false +} + // CheckForDeprecatedApiConfig tries to detect if allow-deprecated-apis is false // in the CLN config. If it is set false, we print a warning and exit because // deprecated CLN API fields might break PeerSwap. @@ -112,17 +134,15 @@ func CheckForDeprecatedApiConfig(client *ClightningClient) Processor { if err != nil { return nil, err } - var ClnConfig struct { - AllowDeprecatedApis bool `json:"allow-deprecated-apis,omitempty"` - } - err = json.Unmarshal(data, &ClnConfig) + co := &ClnConfig{} + err = json.Unmarshal(data, co) if err != nil { return nil, err } - if !ClnConfig.AllowDeprecatedApis { + if !co.AllowDeprecatedAPIs() { log.Infof("WARNING: allow-deprecated-apis=false detected in CLN config. Exiting. More info: https://github.com/ElementsProject/peerswap/issues/232") time.Sleep(1 * time.Second) - os.Exit(1) + client.Plugin.Stop() } return c, nil }