Skip to content

Commit fce1fce

Browse files
GeorgeTsagkguggero
authored andcommitted
rpcserver: refactor validateInvoiceAmount
We move the validation around in preparation for the next commit that adds more logic. The diff will be smaller and focused on the important change thanks to this move.
1 parent 387d50f commit fce1fce

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

rpcserver.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7898,17 +7898,6 @@ func (r *rpcServer) AddInvoice(ctx context.Context,
78987898
func validateInvoiceAmount(acceptedQuote *rfqrpc.PeerAcceptedBuyQuote,
78997899
requestAssetAmount uint64) (lnwire.MilliSatoshi, error) {
79007900

7901-
// If the invoice is for an asset unit amount smaller than the minimal
7902-
// transportable amount, we'll return an error, as it wouldn't be
7903-
// payable by the network.
7904-
if acceptedQuote.MinTransportableUnits > requestAssetAmount {
7905-
return 0, fmt.Errorf("cannot create invoice over %d asset "+
7906-
"units, as the minimal transportable amount is %d "+
7907-
"units with the current rate of %v units/BTC",
7908-
requestAssetAmount, acceptedQuote.MinTransportableUnits,
7909-
acceptedQuote.AskAssetRate)
7910-
}
7911-
79127901
// Now that we have the accepted quote, we know the amount in Satoshi
79137902
// that we need to pay. We can now update the invoice with this amount.
79147903
//
@@ -7929,6 +7918,17 @@ func validateInvoiceAmount(acceptedQuote *rfqrpc.PeerAcceptedBuyQuote,
79297918
assetAmount, *askAssetRate,
79307919
)
79317920

7921+
// If the invoice is for an asset unit amount smaller than the minimal
7922+
// transportable amount, we'll return an error, as it wouldn't be
7923+
// payable by the network.
7924+
if acceptedQuote.MinTransportableUnits > requestAssetAmount {
7925+
return 0, fmt.Errorf("cannot create invoice for %d asset "+
7926+
"units, as the minimal transportable amount is %d "+
7927+
"units with the current rate of %v units/BTC",
7928+
requestAssetAmount, acceptedQuote.MinTransportableUnits,
7929+
acceptedQuote.AskAssetRate)
7930+
}
7931+
79327932
return newInvoiceAmtMsat, nil
79337933
}
79347934

0 commit comments

Comments
 (0)