support multiple nodes simultaneously

This commit is contained in:
Jesse de Wit
2023-01-03 13:03:16 +01:00
parent 3a34400d95
commit 94ee938893
11 changed files with 329 additions and 191 deletions

View File

@@ -4,7 +4,7 @@ import (
"encoding/hex"
"fmt"
"log"
"os"
"path/filepath"
"github.com/breez/lspd/basetypes"
"github.com/btcsuite/btcd/chaincfg/chainhash"
@@ -24,15 +24,22 @@ var (
CLOSED_STATUSES = []string{"CLOSED"}
)
func NewClnClient() *ClnClient {
rpcFile := os.Getenv("CLN_SOCKET_NAME")
lightningDir := os.Getenv("CLN_SOCKET_DIR")
func NewClnClient(socketPath string) (*ClnClient, error) {
rpcFile := filepath.Base(socketPath)
if rpcFile == "" || rpcFile == "." {
return nil, fmt.Errorf("invalid socketPath '%s'", socketPath)
}
lightningDir := filepath.Dir(socketPath)
if lightningDir == "" || lightningDir == "." {
return nil, fmt.Errorf("invalid socketPath '%s'", socketPath)
}
client := glightning.NewLightning()
client.SetTimeout(60)
client.StartUp(rpcFile, lightningDir)
return &ClnClient{
client: client,
}
}, nil
}
func (c *ClnClient) GetInfo() (*GetInfoResult, error) {