Skip to content

Commit

Permalink
Merge pull request #321 from ElementsProject/cln-v24-11-compatibility
Browse files Browse the repository at this point in the history
clightning: compatibility issue with v24.11
  • Loading branch information
YusukeShimizu authored Oct 8, 2024
2 parents 73b33ed + 663acfd commit 513f0c6
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions clightning/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
Expand Down

0 comments on commit 513f0c6

Please sign in to comment.