separate grpc connection

This commit is contained in:
Peter Rounce 2022-09-14 15:31:51 +00:00
parent e16fca179b
commit 524367ec3c
2 changed files with 8 additions and 3 deletions

View file

@ -32,7 +32,7 @@ func newCreds(bytes []byte) rpcCreds {
return creds 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) macaroonBytes, err := ioutil.ReadFile(macaroonFile)
if err != nil { if err != nil {
log.Println("Cannot read macaroon file .. ", err) log.Println("Cannot read macaroon file .. ", err)
@ -65,7 +65,7 @@ func getRouterClient(hostname string, port int, tlsFile, macaroonFile string) ro
panic(err) panic(err)
} }
return routerrpc.NewRouterClient(connection) return connection
} }
func pay_invoice(invoice string) (payment_status string, failure_reason string, return_err error) { 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 return
} }
r_client := getRouterClient( connection := getGrpcConn(
os.Getenv("LN_HOST"), os.Getenv("LN_HOST"),
ln_port, ln_port,
os.Getenv("LN_TLS_FILE"), os.Getenv("LN_TLS_FILE"),
os.Getenv("LN_MACAROON_FILE")) os.Getenv("LN_MACAROON_FILE"))
r_client := routerrpc.NewRouterClient(connection)
fee_limit_sat_str := os.Getenv("FEE_LIMIT_SAT") fee_limit_sat_str := os.Getenv("FEE_LIMIT_SAT")
fee_limit_sat, err := strconv.ParseInt(fee_limit_sat_str, 10, 64) fee_limit_sat, err := strconv.ParseInt(fee_limit_sat_str, 10, 64)
if err != nil { 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)] failure_reason = lnrpc.PaymentFailureReason_name[int32(update.FailureReason)]
} }
connection.Close()
return return
} }

View file

@ -35,6 +35,7 @@ func lnurlp_response(w http.ResponseWriter, r *http.Request) {
},).Info("lnurlp_response") },).Info("lnurlp_response")
// look up domain in env vars (HOST_DOMAIN) // look up domain in env vars (HOST_DOMAIN)
env_host_domain := os.Getenv("HOST_DOMAIN") env_host_domain := os.Getenv("HOST_DOMAIN")
if r.Host != env_host_domain { if r.Host != env_host_domain {
log.Warn("wrong host domain") log.Warn("wrong host domain")