mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-28 14:40:51 +02:00
lnrpc: extract fee limit calculation
This commit is contained in:
30
lnrpc/marshall_utils.go
Normal file
30
lnrpc/marshall_utils.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package lnrpc
|
||||
|
||||
import (
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
// CalculateFeeLimit returns the fee limit in millisatoshis. If a percentage
|
||||
// based fee limit has been requested, we'll factor in the ratio provided with
|
||||
// the amount of the payment.
|
||||
func CalculateFeeLimit(feeLimit *FeeLimit,
|
||||
amount lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
||||
|
||||
switch feeLimit.GetLimit().(type) {
|
||||
|
||||
case *FeeLimit_Fixed:
|
||||
return lnwire.NewMSatFromSatoshis(
|
||||
btcutil.Amount(feeLimit.GetFixed()),
|
||||
)
|
||||
|
||||
case *FeeLimit_Percent:
|
||||
return amount * lnwire.MilliSatoshi(feeLimit.GetPercent()) / 100
|
||||
|
||||
default:
|
||||
// If a fee limit was not specified, we'll use the payment's
|
||||
// amount as an upper bound in order to avoid payment attempts
|
||||
// from incurring fees higher than the payment amount itself.
|
||||
return amount
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user