Add FEE_LIMIT_PERCENT setting

This commit is contained in:
Anders Magnusson 2022-11-18 00:11:02 +01:00
parent 5de205c4d4
commit 9cb751e066
No known key found for this signature in database
GPG key ID: 13F914B79EB2CCF7
3 changed files with 20 additions and 2 deletions

View file

@ -12,6 +12,7 @@ import (
"time"
"crypto/sha256"
decodepay "github.com/fiatjaf/ln-decodepay"
lnrpc "github.com/lightningnetwork/lnd/lnrpc"
invoicesrpc "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
routerrpc "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
@ -216,6 +217,21 @@ func pay_invoice(card_payment_id int, invoice string) {
return
}
fee_limit_percent_str := os.Getenv("FEE_LIMIT_PERCENT")
fee_limit_percent, err := strconv.ParseFloat(fee_limit_percent_str, 64)
if err != nil {
log.WithFields(log.Fields{"card_payment_id": card_payment_id}).Warn(err)
return
}
bolt11, _ := decodepay.Decodepay(invoice)
invoice_msats := bolt11.MSatoshi
fee_limit_product := int64((fee_limit_percent / 100) * (float64(invoice_msats) / 1000))
if fee_limit_product > fee_limit_sat {
fee_limit_sat = fee_limit_product
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()