Use hex-encoded tls cert and macaroon

This commit is contained in:
ekzyis 2024-07-15 08:00:50 +02:00
parent 3957d4d774
commit db23fbb64a
1 changed files with 22 additions and 15 deletions

37
main.go
View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"encoding/hex"
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
@ -20,15 +21,16 @@ var (
func init() { func init() {
var ( var (
dbUrl string dbUrl string
lndAddress string lndAddress string
lndCert string lndCert string
lndMacaroonDir string tlsData []byte
lndNetwork string lndMacaroon string
db_ *db.DB lndNetwork string
lnd_ *lnd.LNDClient db_ *db.DB
ctx router.Context lnd_ *lnd.LNDClient
err error ctx router.Context
err error
) )
if err = env.Load(); err != nil { if err = env.Load(); err != nil {
@ -37,8 +39,8 @@ func init() {
flag.StringVar(&dbUrl, "DATABASE_URL", "delphi.market", "Public URL of website") flag.StringVar(&dbUrl, "DATABASE_URL", "delphi.market", "Public URL of website")
flag.StringVar(&lndAddress, "LND_ADDRESS", "localhost:10001", "LND gRPC server address") flag.StringVar(&lndAddress, "LND_ADDRESS", "localhost:10001", "LND gRPC server address")
flag.StringVar(&lndCert, "LND_CERT", "", "Path to LND TLS certificate") flag.StringVar(&lndCert, "LND_CERT", "", "LND TLS certificate in hex")
flag.StringVar(&lndMacaroonDir, "LND_MACAROON_DIR", "", "LND macaroon directory") flag.StringVar(&lndMacaroon, "LND_MACAROON", "", "LND macaroon in hex")
flag.StringVar(&lndNetwork, "LND_NETWORK", "regtest", "LND network") flag.StringVar(&lndNetwork, "LND_NETWORK", "regtest", "LND network")
env.Parse() env.Parse()
@ -52,11 +54,16 @@ func init() {
log.Fatalf("error connecting to database: %v", err) log.Fatalf("error connecting to database: %v", err)
} }
if tlsData, err = hex.DecodeString(lndCert); err != nil {
log.Printf("[warn] error decoding LND TLS certificate: %v\n", err)
}
if lnd_, err = lnd.New(&lnd.LNDConfig{ if lnd_, err = lnd.New(&lnd.LNDConfig{
LndAddress: lndAddress, LndAddress: lndAddress,
TLSPath: lndCert, CustomMacaroonHex: lndMacaroon,
MacaroonDir: lndMacaroonDir, TLSData: string(tlsData),
Network: lndclient.Network(lndNetwork), Network: lndclient.Network(lndNetwork),
Insecure: false,
}); err != nil { }); err != nil {
log.Printf("[warn] error connecting to LND: %v\n", err) log.Printf("[warn] error connecting to LND: %v\n", err)
lnd_ = nil lnd_ = nil