Skip to content

Commit

Permalink
lnrpc: sort Invoice.HTLCs based on HtlcIndex
Browse files Browse the repository at this point in the history
So the returned HTLCs are ordered.
  • Loading branch information
yyforyongyu committed Dec 6, 2024
1 parent 86e3345 commit 88d6c4a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lnrpc/invoicesrpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package invoicesrpc
import (
"encoding/hex"
"fmt"
"sort"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/chaincfg"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 88d6c4a

Please sign in to comment.