LN invoice expiry param & use it for ctx timeout
This commit is contained in:
parent
5564bd95c3
commit
b3ac9e0a6c
4 changed files with 16 additions and 2 deletions
|
|
@ -32,3 +32,4 @@ sed -i "s/[(]'FEE_LIMIT_PERCENT'[^)]*[)]/(\'FEE_LIMIT_PERCENT\', \'0.5\')/" sql/
|
|||
sed -i "s/[(]'FUNCTION_LNURLW'[^)]*[)]/(\'FUNCTION_LNURLW\', \'ENABLE\')/" sql/settings.sql
|
||||
sed -i "s/[(]'FUNCTION_LNURLP'[^)]*[)]/(\'FUNCTION_LNURLP\', \'DISABLE\')/" sql/settings.sql
|
||||
sed -i "s/[(]'FUNCTION_EMAIL'[^)]*[)]/(\'FUNCTION_EMAIL\', \'DISABLE\')/" sql/settings.sql
|
||||
sed -i "s/[(]'LN_INVOICE_EXPIRY_SEC'[^)]*[)]/(\'LN_INVOICE_EXPIRY_SEC\', \'3600\')/" sql/settings.sql
|
||||
|
|
|
|||
|
|
@ -34,3 +34,4 @@ Here are the descriptions of values available to use in the `settings` table:
|
|||
| FUNCTION_INTERNAL_API | DISABLE | system level switch for activating the internal API |
|
||||
| SENDGRID_API_KEY | | User API Key from SendGrid.com |
|
||||
| SENDGRID_EMAIL_SENDER | | Single Sender email address verified by SendGrid |
|
||||
| LN_INVOICE_EXPIRY_SEC | 3600 | LN invoice's expiry time in seconds |
|
||||
|
|
|
|||
15
lnd/lnd.go
15
lnd/lnd.go
|
|
@ -81,6 +81,10 @@ func Add_invoice(amount_sat int64, metadata string) (payment_request string, r_h
|
|||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
ln_invoice_expiry, err := strconv.ParseInt(db.Get_setting("LN_INVOICE_EXPIRY_SEC"), 10, 64)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
||||
dh := sha256.Sum256([]byte(metadata))
|
||||
|
||||
|
|
@ -98,6 +102,7 @@ func Add_invoice(amount_sat int64, metadata string) (payment_request string, r_h
|
|||
result, err := l_client.AddInvoice(ctx, &lnrpc.Invoice{
|
||||
Value: amount_sat,
|
||||
DescriptionHash: dh[:],
|
||||
Expiry: ln_invoice_expiry,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
|
@ -120,6 +125,11 @@ func Monitor_invoice_state(r_hash []byte) {
|
|||
log.Warn(err)
|
||||
return
|
||||
}
|
||||
ln_invoice_expiry, err := strconv.Atoi(db.Get_setting("LN_INVOICE_EXPIRY_SEC"))
|
||||
if err != nil {
|
||||
log.Warn(err)
|
||||
return
|
||||
}
|
||||
|
||||
connection := getGrpcConn(
|
||||
db.Get_setting("LN_HOST"),
|
||||
|
|
@ -129,7 +139,7 @@ func Monitor_invoice_state(r_hash []byte) {
|
|||
|
||||
i_client := invoicesrpc.NewInvoicesClient(connection)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(ln_invoice_expiry) * time.Second)
|
||||
defer cancel()
|
||||
|
||||
stream, err := i_client.SubscribeSingleInvoice(ctx, &invoicesrpc.SubscribeSingleInvoiceRequest{
|
||||
|
|
@ -228,10 +238,11 @@ func PayInvoice(card_payment_id int, invoice string) {
|
|||
|
||||
bolt11, _ := decodepay.Decodepay(invoice)
|
||||
invoice_msats := bolt11.MSatoshi
|
||||
invoice_expiry := bolt11.Expiry
|
||||
|
||||
fee_limit_product := int64((fee_limit_percent / 100) * (float64(invoice_msats) / 1000))
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(invoice_expiry) * time.Second)
|
||||
defer cancel()
|
||||
|
||||
stream, err := r_client.SendPaymentV2(ctx, &routerrpc.SendPaymentRequest{
|
||||
|
|
|
|||
|
|
@ -31,3 +31,4 @@ INSERT INTO settings (name, value) VALUES ('LNDHUB_URL', '');
|
|||
INSERT INTO settings (name, value) VALUES ('FUNCTION_INTERNAL_API', '');
|
||||
INSERT INTO settings (name, value) VALUES ('SENDGRID_API_KEY', '');
|
||||
INSERT INTO settings (name, value) VALUES ('SENDGRID_EMAIL_SENDER', '');
|
||||
INSERT INTO settings (name, value) VALUES ('LN_INVOICE_EXPIRY_SEC', '3600');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue