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

Make JSONMarshaler methods require proto.Message #7054

Merged
merged 27 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
97c59de
Make JSONMarshaler require proto.Message
blushi Aug 13, 2020
8f43ba6
Use &msg with MarshalJSON
blushi Aug 13, 2020
b6dd69b
Use *LegacyAmino in queriers instead of JSONMarshaler
blushi Aug 13, 2020
3af5055
Revert ABCIMessageLogs String() and coins tests
blushi Aug 13, 2020
282cc28
Use LegacyAmino in client/debug and fix subspace tests
blushi Aug 13, 2020
f572cd3
Merge branch 'master' into marie/6982-json-marshaler-proto
blushi Aug 13, 2020
3f68d9a
Use LegacyAmino in all legacy queriers and adapt simulation
blushi Aug 14, 2020
8ed3b64
Merge branch 'master' into marie/6982-json-marshaler-proto
blushi Aug 14, 2020
2d452d4
Make AminoCodec implement Marshaler and some godoc fixes
blushi Aug 14, 2020
fa96cfe
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into ma…
aaronc Aug 17, 2020
28db5ea
Test fixes
aaronc Aug 17, 2020
2b65f5a
Remove unrelevant comment
blushi Aug 19, 2020
48103b9
Merge branch 'master' into marie/6982-json-marshaler-proto
blushi Aug 19, 2020
b4da972
Use TxConfig.TxJSONEncoder
blushi Aug 19, 2020
ecc133a
Use encoding/json in genutil cli migrate/validate genesis cmds
blushi Aug 19, 2020
7e6d09d
Address simulation related comments
blushi Aug 19, 2020
abfdd22
Use JSONMarshaler in cli tests
blushi Aug 19, 2020
a3e394e
Use proto.Message as respType in cli tests
blushi Aug 20, 2020
e5f88e1
Merge branch 'master' into marie/6982-json-marshaler-proto
blushi Aug 20, 2020
7665df4
Use tmjson for tm GenesisDoc
blushi Aug 24, 2020
8ab0066
Merge branch 'master' into marie/6982-json-marshaler-proto
blushi Aug 24, 2020
12754cd
Update types/module/simulation.go
blushi Aug 25, 2020
17ea317
Update types/module/module_test.go
blushi Aug 25, 2020
4121810
Add godoc comments
blushi Aug 26, 2020
4aa1d08
Remove unused InsertKeyJSON
blushi Aug 26, 2020
5060ae3
Merge branch 'master' into marie/6982-json-marshaler-proto
blushi Aug 26, 2020
0cff5ca
Fix tests
blushi Aug 26, 2020
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: 13 additions & 10 deletions client/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (ctx Context) WithJSONMarshaler(m codec.JSONMarshaler) Context {
return ctx
}

// WithCodec returns a copy of the context with an updated codec.
// WithLegacyAmino returns a copy of the context with an updated LegacyAmino codec.
// TODO: Deprecated (remove).
func (ctx Context) WithLegacyAmino(cdc *codec.LegacyAmino) Context {
ctx.LegacyAmino = cdc
Expand Down Expand Up @@ -212,27 +212,30 @@ func (ctx Context) PrintString(str string) error {
// either text or json. If text, toPrint will be YAML encoded. Otherwise, toPrint
// will be JSON encoded using ctx.JSONMarshaler. An error is returned upon failure.
func (ctx Context) PrintOutput(toPrint proto.Message) error {
return ctx.printOutput(toPrint)
// always serialize JSON initially because proto json can't be directly YAML encoded
out, err := ctx.JSONMarshaler.MarshalJSON(toPrint)
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
return ctx.printOutput(out)
aaronc marked this conversation as resolved.
Show resolved Hide resolved
}

// PrintOutputLegacy is a variant of PrintOutput that doesn't require a proto type
// and uses amino JSON encoding. It will be removed in the near future!
func (ctx Context) PrintOutputLegacy(toPrint interface{}) error {
return ctx.WithJSONMarshaler(ctx.LegacyAmino).printOutput(toPrint)
}

func (ctx Context) printOutput(toPrint interface{}) error {
// always serialize JSON initially because proto json can't be directly YAML encoded
out, err := ctx.JSONMarshaler.MarshalJSON(toPrint)
out, err := ctx.LegacyAmino.MarshalJSON(toPrint)
if err != nil {
return err
}
return ctx.printOutput(out)
}

func (ctx Context) printOutput(out []byte) error {
if ctx.OutputFormat == "text" {
// handle text format by decoding and re-encoding JSON as YAML
var j interface{}

err = json.Unmarshal(out, &j)
err := json.Unmarshal(out, &j)
if err != nil {
return err
}
Expand All @@ -248,7 +251,7 @@ func (ctx Context) printOutput(toPrint interface{}) error {
writer = os.Stdout
}

_, err = writer.Write(out)
_, err := writer.Write(out)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions client/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ x: "10"
// amino
//
amino := testdata.NewTestAmino()
ctx = ctx.WithJSONMarshaler(codec.NewAminoCodec(&codec.LegacyAmino{Amino: amino}))
ctx = ctx.WithLegacyAmino(&codec.LegacyAmino{Amino: amino})

// json
buf = &bytes.Buffer{}
ctx = ctx.WithOutput(buf)
ctx.OutputFormat = "json"
err = ctx.PrintOutput(hasAnimal)
err = ctx.PrintOutputLegacy(hasAnimal)
require.NoError(t, err)
require.Equal(t,
`{"type":"testdata/HasAnimal","value":{"animal":{"type":"testdata/Dog","value":{"size":"big","name":"Spot"}},"x":"10"}}
Expand All @@ -87,7 +87,7 @@ x: "10"
buf = &bytes.Buffer{}
ctx = ctx.WithOutput(buf)
ctx.OutputFormat = "text"
err = ctx.PrintOutput(hasAnimal)
err = ctx.PrintOutputLegacy(hasAnimal)
require.NoError(t, err)
require.Equal(t,
`type: testdata/HasAnimal
Expand Down
2 changes: 1 addition & 1 deletion client/debug/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ $ %s debug pubkey cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg
return fmt.Errorf("invalid pubkey type; expected ED25519")
}

pubKeyJSONBytes, err := clientCtx.JSONMarshaler.MarshalJSON(edPK)
pubKeyJSONBytes, err := clientCtx.LegacyAmino.MarshalJSON(edPK)
if err != nil {
return err
}
Expand Down
10 changes: 8 additions & 2 deletions client/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"github.com/gogo/protobuf/jsonpb"
"github.com/gogo/protobuf/proto"
"github.com/spf13/pflag"
"github.com/tendermint/tendermint/crypto"

Expand Down Expand Up @@ -100,15 +101,20 @@ func BroadcastTx(clientCtx client.Context, txf Factory, msgs ...sdk.Msg) error {
}

if !clientCtx.SkipConfirm {
out, err := clientCtx.JSONMarshaler.MarshalJSON(tx)
msg, ok := tx.(proto.Message)
if !ok {
return fmt.Errorf("can't proto marshal %T", tx)
}

out, err := clientCtx.JSONMarshaler.MarshalJSON(msg)
blushi marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}

_, _ = fmt.Fprintf(os.Stderr, "%s\n\n", out)

buf := bufio.NewReader(os.Stdin)
ok, err := input.GetConfirmation("confirm transaction before signing and broadcasting", buf, os.Stderr)
ok, err = input.GetConfirmation("confirm transaction before signing and broadcasting", buf, os.Stderr)

if err != nil || !ok {
_, _ = fmt.Fprintf(os.Stderr, "%s\n", "cancelled transaction")
Expand Down
12 changes: 5 additions & 7 deletions codec/amino.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ import (
"github.com/cosmos/cosmos-sdk/codec/types"
)

// deprecated: Codec defines a wrapper for an Amino codec that properly handles protobuf
// deprecated: LegacyAmino defines a wrapper for an Amino codec that properly handles protobuf
// types with Any's
type LegacyAmino struct {
Amino *amino.Codec
}

var _ JSONMarshaler = &LegacyAmino{}

func (cdc *LegacyAmino) Seal() {
cdc.Amino.Seal()
}
Expand All @@ -43,8 +41,8 @@ func RegisterEvidences(cdc *LegacyAmino) {
// MarshalJSONIndent provides a utility for indented JSON encoding of an object
// via an Amino codec. It returns an error if it cannot serialize or indent as
// JSON.
func MarshalJSONIndent(m JSONMarshaler, obj interface{}) ([]byte, error) {
bz, err := m.MarshalJSON(obj)
func MarshalJSONIndent(cdc *LegacyAmino, obj interface{}) ([]byte, error) {
bz, err := cdc.MarshalJSON(obj)
if err != nil {
return nil, err
}
Expand All @@ -58,8 +56,8 @@ func MarshalJSONIndent(m JSONMarshaler, obj interface{}) ([]byte, error) {
}

// MustMarshalJSONIndent executes MarshalJSONIndent except it panics upon failure.
func MustMarshalJSONIndent(m JSONMarshaler, obj interface{}) []byte {
bz, err := MarshalJSONIndent(m, obj)
func MustMarshalJSONIndent(cdc *LegacyAmino, obj interface{}) []byte {
bz, err := MarshalJSONIndent(cdc, obj)
if err != nil {
panic(fmt.Sprintf("failed to marshal JSON: %s", err))
}
Expand Down
18 changes: 18 additions & 0 deletions codec/amino_codec.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package codec

import "github.com/gogo/protobuf/proto"

// AminoCodec defines a codec that utilizes Codec for both binary and JSON
// encoding.
type AminoCodec struct {
Expand Down Expand Up @@ -43,3 +45,19 @@ func (ac *AminoCodec) UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshale
func (ac *AminoCodec) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) {
ac.LegacyAmino.MustUnmarshalBinaryLengthPrefixed(bz, ptr)
}

func (ac *AminoCodec) MarshalJSON(o proto.Message) ([]byte, error) {
blushi marked this conversation as resolved.
Show resolved Hide resolved
return ac.LegacyAmino.MarshalJSON(o)
}

func (ac *AminoCodec) MustMarshalJSON(o proto.Message) []byte {
return ac.LegacyAmino.MustMarshalJSON(o)
}

func (ac *AminoCodec) UnmarshalJSON(bz []byte, ptr proto.Message) error {
return ac.LegacyAmino.UnmarshalJSON(bz, ptr)
}

func (ac *AminoCodec) MustUnmarshalJSON(bz []byte, ptr proto.Message) {
ac.LegacyAmino.MustUnmarshalJSON(bz, ptr)
}
6 changes: 3 additions & 3 deletions codec/amino_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestAminoCodec(t *testing.T) {

testCases := []struct {
name string
codec codec.Marshaler
codec *codec.AminoCodec
input codec.ProtoMarshaler
recv codec.ProtoMarshaler
marshalErr bool
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestAminoCodecMarshalJSONIndent(t *testing.T) {

if tc.marshalErr {
require.Error(t, err)
require.Panics(t, func() { codec.MustMarshalJSONIndent(cdc, tc.input) })
require.Panics(t, func() { codec.MustMarshalJSONIndent(cdc.LegacyAmino, tc.input) })
return
}

Expand All @@ -184,7 +184,7 @@ func TestAminoCodecMarshalJSONIndent(t *testing.T) {
require.Equal(t, bz, []byte(tc.wantJSON))

var bz2 []byte
require.NotPanics(t, func() { bz2 = codec.MustMarshalJSONIndent(cdc, tc.input) })
require.NotPanics(t, func() { bz2 = codec.MustMarshalJSONIndent(cdc.LegacyAmino, tc.input) })
require.Equal(t, bz2, []byte(tc.wantJSON))
})
}
Expand Down
10 changes: 5 additions & 5 deletions codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type (
// Marshaler defines the interface module codecs must implement in order to support
// backwards compatibility with Amino while allowing custom Protobuf-based
// serialization. Note, Amino can still be used without any dependency on
// Protobuf. There are three typical implementations that fulfill this contract:
// Protobuf. There are two typical implementations that fulfill this contract:
//
// 1. AminoCodec: Provides full Amino serialization compatibility.
// 2. ProtoCodec: Provides full Protobuf serialization compatibility.
Expand All @@ -36,11 +36,11 @@ type (
}

JSONMarshaler interface {
MarshalJSON(o interface{}) ([]byte, error)
MustMarshalJSON(o interface{}) []byte
MarshalJSON(o proto.Message) ([]byte, error)
MustMarshalJSON(o proto.Message) []byte

UnmarshalJSON(bz []byte, ptr interface{}) error
MustUnmarshalJSON(bz []byte, ptr interface{})
UnmarshalJSON(bz []byte, ptr proto.Message) error
MustUnmarshalJSON(bz []byte, ptr proto.Message)
}

// ProtoMarshaler defines an interface a type must implement as protocol buffer
Expand Down
9 changes: 5 additions & 4 deletions codec/proto_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec/types"

"github.com/gogo/protobuf/jsonpb"
"github.com/gogo/protobuf/proto"
)

// ProtoCodec defines a codec that utilizes Protobuf for both binary and JSON
Expand Down Expand Up @@ -95,7 +96,7 @@ func (pc *ProtoCodec) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMars
}
}

func (pc *ProtoCodec) MarshalJSON(o interface{}) ([]byte, error) {
func (pc *ProtoCodec) MarshalJSON(o proto.Message) ([]byte, error) {
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
m, ok := o.(ProtoMarshaler)
if !ok {
return nil, fmt.Errorf("cannot protobuf JSON encode unsupported type: %T", o)
Expand All @@ -104,7 +105,7 @@ func (pc *ProtoCodec) MarshalJSON(o interface{}) ([]byte, error) {
return ProtoMarshalJSON(m)
}

func (pc *ProtoCodec) MustMarshalJSON(o interface{}) []byte {
func (pc *ProtoCodec) MustMarshalJSON(o proto.Message) []byte {
bz, err := pc.MarshalJSON(o)
if err != nil {
panic(err)
Expand All @@ -113,7 +114,7 @@ func (pc *ProtoCodec) MustMarshalJSON(o interface{}) []byte {
return bz
}

func (pc *ProtoCodec) UnmarshalJSON(bz []byte, ptr interface{}) error {
func (pc *ProtoCodec) UnmarshalJSON(bz []byte, ptr proto.Message) error {
m, ok := ptr.(ProtoMarshaler)
if !ok {
return fmt.Errorf("cannot protobuf JSON decode unsupported type: %T", ptr)
Expand All @@ -127,7 +128,7 @@ func (pc *ProtoCodec) UnmarshalJSON(bz []byte, ptr interface{}) error {
return types.UnpackInterfaces(ptr, pc.anyUnpacker)
}

func (pc *ProtoCodec) MustUnmarshalJSON(bz []byte, ptr interface{}) {
func (pc *ProtoCodec) MustUnmarshalJSON(bz []byte, ptr proto.Message) {
if err := pc.UnmarshalJSON(bz, ptr); err != nil {
panic(err)
}
Expand Down
20 changes: 0 additions & 20 deletions codec/proto_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,6 @@ func TestProtoCodec(t *testing.T) {
}
}

func TestProtoCodecMarshalAnyNonProtoErrors(t *testing.T) {
cdc := codec.NewProtoCodec(createTestInterfaceRegistry())

input := "this one that one"
_, err := cdc.MarshalJSON(input)
require.Error(t, err)
require.Equal(t, err, errors.New("cannot protobuf JSON encode unsupported type: string"))

require.Panics(t, func() { cdc.MustMarshalJSON(input) })
}

func TestProtoCodecUnmarshalAnyNonProtoErrors(t *testing.T) {
cdc := codec.NewProtoCodec(createTestInterfaceRegistry())

recv := new(int)
err := cdc.UnmarshalJSON([]byte("foo"), recv)
require.Error(t, err)
require.Equal(t, err, errors.New("cannot protobuf JSON decode unsupported type: *int"))
}

type lyingProtoMarshaler struct {
codec.ProtoMarshaler
falseSize int
Expand Down
10 changes: 0 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4er
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
github.com/golang/mock v1.4.3 h1:GV+pQPG/EUUbkh47niozDcADz6go/dUwhVzdUQHIVRw=
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -237,8 +235,6 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.14.6 h1:8ERzHx8aj1Sc47mu9n/AksaKCSWrMchFtkdrS4BIj5o=
github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4GkDEdKCRJduHpTxT3/jcw=
github.com/grpc-ecosystem/grpc-gateway v1.14.7 h1:Nk5kuHrnWUTf/0GL1a/vchH/om9Ap2/HnVna+jYZgTY=
github.com/grpc-ecosystem/grpc-gateway v1.14.7/go.mod h1:oYZKL012gGh6LMyg/xA7Q2yq6j8bu0wa+9w14EEthWU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
Expand Down Expand Up @@ -432,8 +428,6 @@ github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt2
github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4=
github.com/prometheus/common v0.10.0 h1:RyRA7RzGXQZiW+tGMr7sxa85G1z0yOpM1qq5c8lNawc=
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
github.com/prometheus/common v0.11.1 h1:0ZISXCMRuCZcxF77aT1BXY5m74mX2vrGYl1dSwBI0Jo=
github.com/prometheus/common v0.11.1/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
github.com/prometheus/common v0.12.0 h1:mj4ewtVukAfkS37JU7IXPJPr7zwLEjwgWO6nZo8ROvk=
github.com/prometheus/common v0.12.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
Expand Down Expand Up @@ -661,7 +655,6 @@ golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
Expand Down Expand Up @@ -736,7 +729,6 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60=
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
google.golang.org/grpc v1.31.0 h1:T7P4R73V3SSDPhH7WW7ATbfViLtmamH0DKrP3f9AuDI=
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
Expand Down Expand Up @@ -785,7 +777,5 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
1 change: 0 additions & 1 deletion server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ func startInProcess(ctx *Context, legacyAminoCdc *codec.LegacyAmino, appCreator
clientCtx := client.Context{}.
WithHomeDir(home).
WithChainID(genDoc.ChainID).
WithJSONMarshaler(legacyAminoCdc).
// amino is needed here for backwards compatibility of REST routes
WithLegacyAmino(legacyAminoCdc).
WithClient(local.New(tmNode))
Expand Down
6 changes: 3 additions & 3 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ func AddCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreator type
//
// NOTE: The ordering of the keys returned as the resulting JSON message is
// non-deterministic, so the client should not rely on key ordering.
func InsertKeyJSON(cdc codec.JSONMarshaler, baseJSON []byte, key string, value json.RawMessage) ([]byte, error) {
func InsertKeyJSON(legacyAminoCdc *codec.LegacyAmino, baseJSON []byte, key string, value json.RawMessage) ([]byte, error) {
blushi marked this conversation as resolved.
Show resolved Hide resolved
var jsonMap map[string]json.RawMessage

if err := cdc.UnmarshalJSON(baseJSON, &jsonMap); err != nil {
if err := legacyAminoCdc.UnmarshalJSON(baseJSON, &jsonMap); err != nil {
blushi marked this conversation as resolved.
Show resolved Hide resolved
return nil, err
}

jsonMap[key] = value
bz, err := codec.MarshalJSONIndent(cdc, jsonMap)
bz, err := codec.MarshalJSONIndent(legacyAminoCdc, jsonMap)
blushi marked this conversation as resolved.
Show resolved Hide resolved

return json.RawMessage(bz), err
}
Expand Down
Loading