lnrpc: sort Invoice.HTLCs based on HtlcIndex

So the returned HTLCs are ordered.
This commit is contained in:
yyforyongyu committed 2024-12-07 09:54:46 +08:00
1 parent 366e48bced
commit 7374392abe
2 files changed
+11

No files matched your search

+7
View File
@@ -1,8 +1,10 @@
package invoicesrpc
import (
"cmp"
"encoding/hex"
"fmt"
"slices"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/chaincfg"
@@ -160,6 +162,11 @@ func CreateRPCInvoice(invoice *invoices.Invoice,
rpcHtlcs = append(rpcHtlcs, &rpcHtlc)
}
// Perform an inplace sort of the HTLCs to ensure they are ordered.
slices.SortFunc(rpcHtlcs, func(i, j *lnrpc.InvoiceHTLC) int {
return cmp.Compare(i.HtlcIndex, j.HtlcIndex)
})
rpcInvoice := &lnrpc.Invoice{
Memo: string(invoice.Memo),
RHash: rHash,