lightning address receive works
This commit is contained in:
parent
524367ec3c
commit
27be212010
2 changed files with 67 additions and 9 deletions
43
lightning.go
43
lightning.go
|
|
@ -6,10 +6,11 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
"crypto/sha256"
|
||||
|
||||
lnrpc "github.com/lightningnetwork/lnd/lnrpc"
|
||||
routerrpc "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
||||
|
|
@ -68,6 +69,38 @@ func getGrpcConn(hostname string, port int, tlsFile, macaroonFile string) *grpc.
|
|||
return connection
|
||||
}
|
||||
|
||||
func add_invoice(amount_sat int64, metadata string) (payment_request string, return_err error) {
|
||||
|
||||
ln_port, err := strconv.Atoi(os.Getenv("LN_PORT"))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
dh := sha256.Sum256([]byte(metadata))
|
||||
|
||||
connection := getGrpcConn(
|
||||
os.Getenv("LN_HOST"),
|
||||
ln_port,
|
||||
os.Getenv("LN_TLS_FILE"),
|
||||
os.Getenv("LN_MACAROON_FILE"))
|
||||
|
||||
l_client := lnrpc.NewLightningClient(connection)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
result, err := l_client.AddInvoice(ctx, &lnrpc.Invoice {
|
||||
Value: amount_sat,
|
||||
DescriptionHash: dh[:],
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return result.PaymentRequest, nil
|
||||
}
|
||||
|
||||
func pay_invoice(invoice string) (payment_status string, failure_reason string, return_err error) {
|
||||
|
||||
payment_status = ""
|
||||
|
|
@ -76,9 +109,6 @@ func pay_invoice(invoice string) (payment_status string, failure_reason string,
|
|||
|
||||
// SendPaymentV2
|
||||
|
||||
ctx2, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// get node parameters from environment variables
|
||||
|
||||
ln_port, err := strconv.Atoi(os.Getenv("LN_PORT"))
|
||||
|
|
@ -102,7 +132,10 @@ func pay_invoice(invoice string) (payment_status string, failure_reason string,
|
|||
return
|
||||
}
|
||||
|
||||
stream, err := r_client.SendPaymentV2(ctx2, &routerrpc.SendPaymentRequest{
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
stream, err := r_client.SendPaymentV2(ctx, &routerrpc.SendPaymentRequest{
|
||||
PaymentRequest: invoice,
|
||||
NoInflightUpdates: true,
|
||||
TimeoutSeconds: 30,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue