Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: finish TODO of removing defunct sortJSON (backport #16401) #16489

Merged
merged 1 commit into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 1 addition & 22 deletions codec/proto_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package codec

import (
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"strings"
Expand Down Expand Up @@ -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,
Expand Down
23 changes: 1 addition & 22 deletions x/tx/signing/aminojson/aminojson.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package aminojson

import (
"context"
"encoding/json"
"fmt"

"google.golang.org/protobuf/reflect/protoregistry"
Expand Down Expand Up @@ -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)