From 34d04924b93c14c4bb60006cbe8b5713bbbba5f8 Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Sat, 10 Jun 2023 01:49:11 -0700 Subject: [PATCH] chore: finish TODO of removing defunct sortJSON (#16401) (cherry picked from commit 3db9528efb5fec1cccdb4e6f084c24ed195951b1) --- codec/proto_codec.go | 23 +---------------------- x/tx/signing/aminojson/aminojson.go | 23 +---------------------- 2 files changed, 2 insertions(+), 44 deletions(-) diff --git a/codec/proto_codec.go b/codec/proto_codec.go index b66c0f348a0..ea8f2e2593e 100644 --- a/codec/proto_codec.go +++ b/codec/proto_codec.go @@ -2,7 +2,6 @@ package codec import ( "encoding/binary" - "encoding/json" "errors" "fmt" "strings" @@ -194,27 +193,7 @@ func (pc *ProtoCodec) MarshalAminoJSON(msg gogoproto.Message) ([]byte, error) { if err != nil { return nil, err } - jsonBytes, err := encoder.Marshal(protoMsg) - if err != nil { - return nil, err - } - // TODO: remove this sort once https://github.com/cosmos/cosmos-sdk/issues/2350#issuecomment-1542715157 lands - // the encoder should be rendering in lexical order - return sortJSON(jsonBytes) -} - -// sortJSON sorts the JSON keys of the given JSON encoded byte slice. -func sortJSON(toSortJSON []byte) ([]byte, error) { - var c interface{} - err := json.Unmarshal(toSortJSON, &c) - if err != nil { - return nil, err - } - js, err := json.Marshal(c) - if err != nil { - return nil, err - } - return js, nil + return encoder.Marshal(protoMsg) } // UnmarshalJSON implements JSONCodec.UnmarshalJSON method, diff --git a/x/tx/signing/aminojson/aminojson.go b/x/tx/signing/aminojson/aminojson.go index 6fc6e97e49b..5d4c3136f55 100644 --- a/x/tx/signing/aminojson/aminojson.go +++ b/x/tx/signing/aminojson/aminojson.go @@ -2,7 +2,6 @@ package aminojson import ( "context" - "encoding/json" "fmt" "google.golang.org/protobuf/reflect/protoregistry" @@ -111,27 +110,7 @@ func (h SignModeHandler) GetSignBytes(_ context.Context, signerData signing.Sign Tip: tip, } - bz, err := h.encoder.Marshal(signDoc) - if err != nil { - return nil, err - } - // TODO: remove this sort once https://github.com/cosmos/cosmos-sdk/issues/2350#issuecomment-1542715157 lands - // the encoder should be rendering fields in lexical order - return sortJSON(bz) -} - -// sortJSON sorts the JSON keys of the given JSON encoded byte slice. -func sortJSON(toSortJSON []byte) ([]byte, error) { - var c interface{} - err := json.Unmarshal(toSortJSON, &c) - if err != nil { - return nil, err - } - js, err := json.Marshal(c) - if err != nil { - return nil, err - } - return js, nil + return h.encoder.Marshal(signDoc) } var _ signing.SignModeHandler = (*SignModeHandler)(nil)