mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-21 15:54:25 +01:00
Put directly the pem in the json configuration
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
package itest
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
@@ -48,12 +49,11 @@ func NewLndLspdNode(h *lntest.TestHarness, m *lntest.Miner, name string) LspNode
|
||||
}
|
||||
|
||||
lightningNode := lntest.NewLndNode(h, m, name, args...)
|
||||
lnd := fmt.Sprintf(
|
||||
`{ "address": "%s", "cert": "%s", "macaroon": "%x" }`,
|
||||
lightningNode.GrpcHost(),
|
||||
base64.StdEncoding.EncodeToString(lightningNode.TlsCert()),
|
||||
lightningNode.Macaroon(),
|
||||
)
|
||||
j, _ := json.Marshal(map[string]string{
|
||||
"address": lightningNode.GrpcHost(),
|
||||
"cert": lightningNode.TlsCert(),
|
||||
"macaroon": hex.EncodeToString(lightningNode.Macaroon())})
|
||||
lnd := string(j)
|
||||
lspBase, err := newLspd(h, name, &lnd, nil)
|
||||
if err != nil {
|
||||
h.T.Fatalf("failed to initialize lspd")
|
||||
@@ -113,12 +113,11 @@ func (c *LndLspNode) Start() {
|
||||
split := strings.Split(string(scriptFile), "\n")
|
||||
for i, s := range split {
|
||||
if strings.HasPrefix(s, "export NODES") {
|
||||
ext := fmt.Sprintf(
|
||||
`"lnd": { "address": "%s", "cert": "%s", "macaroon": "%x" }}]'`,
|
||||
c.lightningNode.GrpcHost(),
|
||||
base64.StdEncoding.EncodeToString(c.lightningNode.TlsCert()),
|
||||
c.lightningNode.Macaroon(),
|
||||
)
|
||||
j, _ := json.Marshal(map[string]string{
|
||||
"address": c.lightningNode.GrpcHost(),
|
||||
"cert": c.lightningNode.TlsCert(),
|
||||
"macaroon": hex.EncodeToString(c.lightningNode.Macaroon())})
|
||||
ext := fmt.Sprintf(`"lnd": %s}]`, string(j))
|
||||
start, _, _ := strings.Cut(s, `"lnd"`)
|
||||
|
||||
split[i] = start + ext
|
||||
|
||||
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"log"
|
||||
@@ -26,19 +25,14 @@ type LndClient struct {
|
||||
}
|
||||
|
||||
func NewLndClient(conf *LndConfig) (*LndClient, error) {
|
||||
cert, err := base64.StdEncoding.DecodeString(conf.Cert)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to decode cert: %w", err)
|
||||
}
|
||||
|
||||
_, err = hex.DecodeString(conf.Macaroon)
|
||||
_, err := hex.DecodeString(conf.Macaroon)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to decode macaroon: %w", err)
|
||||
}
|
||||
|
||||
// Creds file to connect to LND gRPC
|
||||
cp := x509.NewCertPool()
|
||||
if !cp.AppendCertsFromPEM(cert) {
|
||||
if !cp.AppendCertsFromPEM([]byte(conf.Cert)) {
|
||||
return nil, fmt.Errorf("credentials: failed to append certificates")
|
||||
}
|
||||
creds := credentials.NewClientTLSFromCert(cp, "")
|
||||
|
||||
Reference in New Issue
Block a user