From 722a15c2a2b244b48403709edb7517fcddf6fdc4 Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Fri, 26 Jul 2024 16:26:38 -0300 Subject: [PATCH] fix Signed-off-by: Ignacio Hagopian --- proof_json.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/proof_json.go b/proof_json.go index d9b99b8..7e1a572 100644 --- a/proof_json.go +++ b/proof_json.go @@ -29,6 +29,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "sort" ) // HexToPrefixedString turns a byte slice into its hex representation @@ -192,10 +193,14 @@ type stemStateDiffMarshaller struct { } func (ssd StemStateDiff) MarshalJSON() ([]byte, error) { - suffixes := make([]byte, len(ssd.Updates)) + suffixes := make([]byte, 0, len(ssd.Updates)+len(ssd.Inserts)) for i := range ssd.Updates { - suffixes[i] = ssd.Updates[i].Suffix + suffixes = append(suffixes, ssd.Updates[i].Suffix) } + for i := range ssd.Inserts { + suffixes = append(suffixes, ssd.Inserts[i].Suffix) + } + sort.Slice(suffixes, func(i, j int) bool { return suffixes[i] < suffixes[j] }) return json.Marshal(&stemStateDiffMarshaller{ Stem: HexToPrefixedString(ssd.Stem[:]), Suffixes: HexToPrefixedString(suffixes),