From 88d6c4af101ce4c2ca810a755025aaa19d5eb1ff Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 5 Dec 2024 23:39:37 +0800 Subject: [PATCH] lnrpc: sort `Invoice.HTLCs` based on `HtlcIndex` So the returned HTLCs are ordered. --- lnrpc/invoicesrpc/utils.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lnrpc/invoicesrpc/utils.go b/lnrpc/invoicesrpc/utils.go index 955ba6acf2..c9c44e383d 100644 --- a/lnrpc/invoicesrpc/utils.go +++ b/lnrpc/invoicesrpc/utils.go @@ -3,6 +3,7 @@ package invoicesrpc import ( "encoding/hex" "fmt" + "sort" "github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/chaincfg" @@ -160,6 +161,11 @@ func CreateRPCInvoice(invoice *invoices.Invoice, rpcHtlcs = append(rpcHtlcs, &rpcHtlc) } + // Perform an inplace sort of the HTLCs to ensure they are ordered. + sort.Slice(rpcHtlcs, func(i, j int) bool { + return rpcHtlcs[i].HtlcIndex < rpcHtlcs[j].HtlcIndex + }) + rpcInvoice := &lnrpc.Invoice{ Memo: string(invoice.Memo), RHash: rHash,