mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-10-10 01:12:56 +02:00
lnrpc: extract fee limit calculation
This commit is contained in:
25
rpcserver.go
25
rpcserver.go
@@ -2908,27 +2908,6 @@ type rpcPaymentRequest struct {
|
||||
route *route.Route
|
||||
}
|
||||
|
||||
// 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 *lnrpc.FeeLimit,
|
||||
amount lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
||||
|
||||
switch feeLimit.GetLimit().(type) {
|
||||
case *lnrpc.FeeLimit_Fixed:
|
||||
return lnwire.NewMSatFromSatoshis(
|
||||
btcutil.Amount(feeLimit.GetFixed()),
|
||||
)
|
||||
case *lnrpc.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
|
||||
}
|
||||
}
|
||||
|
||||
// SendPayment dispatches a bi-directional streaming RPC for sending payments
|
||||
// through the Lightning Network. A single RPC invocation creates a persistent
|
||||
// bi-directional stream allowing clients to rapidly send payments through the
|
||||
@@ -3114,7 +3093,7 @@ func extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPaymentIntent, error
|
||||
}
|
||||
|
||||
// Calculate the fee limit that should be used for this payment.
|
||||
payIntent.feeLimit = calculateFeeLimit(
|
||||
payIntent.feeLimit = lnrpc.CalculateFeeLimit(
|
||||
rpcPayReq.FeeLimit, payIntent.msat,
|
||||
)
|
||||
|
||||
@@ -3154,7 +3133,7 @@ func extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPaymentIntent, error
|
||||
)
|
||||
|
||||
// Calculate the fee limit that should be used for this payment.
|
||||
payIntent.feeLimit = calculateFeeLimit(
|
||||
payIntent.feeLimit = lnrpc.CalculateFeeLimit(
|
||||
rpcPayReq.FeeLimit, payIntent.msat,
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user