diff --git a/lightning.go b/lightning.go index d32931d..3417b97 100644 --- a/lightning.go +++ b/lightning.go @@ -32,7 +32,7 @@ func newCreds(bytes []byte) rpcCreds { return creds } -func getRouterClient(hostname string, port int, tlsFile, macaroonFile string) routerrpc.RouterClient { +func getGrpcConn(hostname string, port int, tlsFile, macaroonFile string) *grpc.ClientConn { macaroonBytes, err := ioutil.ReadFile(macaroonFile) if err != nil { log.Println("Cannot read macaroon file .. ", err) @@ -65,7 +65,7 @@ func getRouterClient(hostname string, port int, tlsFile, macaroonFile string) ro panic(err) } - return routerrpc.NewRouterClient(connection) + return connection } func pay_invoice(invoice string) (payment_status string, failure_reason string, return_err error) { @@ -87,12 +87,14 @@ func pay_invoice(invoice string) (payment_status string, failure_reason string, return } - r_client := getRouterClient( + connection := getGrpcConn( os.Getenv("LN_HOST"), ln_port, os.Getenv("LN_TLS_FILE"), os.Getenv("LN_MACAROON_FILE")) + r_client := routerrpc.NewRouterClient(connection) + fee_limit_sat_str := os.Getenv("FEE_LIMIT_SAT") fee_limit_sat, err := strconv.ParseInt(fee_limit_sat_str, 10, 64) if err != nil { @@ -127,5 +129,7 @@ func pay_invoice(invoice string) (payment_status string, failure_reason string, failure_reason = lnrpc.PaymentFailureReason_name[int32(update.FailureReason)] } + connection.Close() + return } diff --git a/main.go b/main.go index 4181894..7a7bb77 100644 --- a/main.go +++ b/main.go @@ -35,6 +35,7 @@ func lnurlp_response(w http.ResponseWriter, r *http.Request) { },).Info("lnurlp_response") // look up domain in env vars (HOST_DOMAIN) + env_host_domain := os.Getenv("HOST_DOMAIN") if r.Host != env_host_domain { log.Warn("wrong host domain")