44 lines
989 B
Go
44 lines
989 B
Go
package plugin
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
json "github.com/mitchellh/mapstructure"
|
|
|
|
"github.com/vincenzopalazzo/cln4go/client"
|
|
"github.com/vincenzopalazzo/cln4go/plugin"
|
|
)
|
|
|
|
type State struct {
|
|
rpc *client.UnixRPC
|
|
}
|
|
|
|
func (self *State) Rpc(method string, args map[string]any) (map[string]any, error) {
|
|
return client.Call[map[string]any, map[string]any](self.rpc, method, args)
|
|
}
|
|
|
|
func OnShutdown(plugin *plugin.Plugin[*State], request map[string]any) {
|
|
os.Exit(0)
|
|
}
|
|
|
|
func OnInit(plugin *plugin.Plugin[*State], conf map[string]any) map[string]any {
|
|
clnConf := struct {
|
|
LightningDir string `mapstructure:"lightning-dir"`
|
|
RpcFile string `mapstructure:"rpc-file"`
|
|
}{}
|
|
if err := json.Decode(conf, &clnConf); err != nil {
|
|
return map[string]any{
|
|
"disable": err,
|
|
}
|
|
}
|
|
rpc, err := client.NewUnix(fmt.Sprintf("%s/%s", clnConf.LightningDir, clnConf.RpcFile))
|
|
if err != nil {
|
|
return map[string]any{
|
|
"disable": err,
|
|
}
|
|
}
|
|
plugin.State.rpc = rpc
|
|
return map[string]any{}
|
|
}
|