diff --git a/x/tx/CHANGELOG.md b/x/tx/CHANGELOG.md index 1ddbcc1631b1..eaa2e851e820 100644 --- a/x/tx/CHANGELOG.md +++ b/x/tx/CHANGELOG.md @@ -35,6 +35,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#276](https://github.com/crypto-org-chain/cosmos-sdk/pull/276) Support bytes in automatic signer getters. +### Bug Fixes + +* [#19955](https://github.com/cosmos/cosmos-sdk/pull/19955) Don't shadow Amino marshalling error messages + ## v0.13.1 ### Features diff --git a/x/tx/signing/aminojson/encoder.go b/x/tx/signing/aminojson/encoder.go index 07a7c8ea0792..90ac7d5d0167 100644 --- a/x/tx/signing/aminojson/encoder.go +++ b/x/tx/signing/aminojson/encoder.go @@ -10,7 +10,6 @@ import ( "google.golang.org/protobuf/reflect/protoreflect" authapi "cosmossdk.io/api/cosmos/auth/v1beta1" - "cosmossdk.io/api/cosmos/crypto/multisig" "cosmossdk.io/math" ) @@ -143,24 +142,15 @@ func moduleAccountEncoder(_ *Encoder, msg protoreflect.Message, w io.Writer) err // also see: // https://github.com/cosmos/cosmos-sdk/blob/b49f948b36bc991db5be431607b475633aed697e/proto/cosmos/crypto/multisig/keys.proto#L15/ func thresholdStringEncoder(enc *Encoder, msg protoreflect.Message, w io.Writer) error { - pk, ok := msg.Interface().(*multisig.LegacyAminoPubKey) - if !ok { - return errors.New("thresholdStringEncoder: msg not a multisig.LegacyAminoPubKey") - } - _, err := fmt.Fprintf(w, `{"threshold":"%d","pubkeys":`, pk.Threshold) + fields := msg.Descriptor().Fields() + thresholdField := fields.ByName("threshold") + threshold := msg.Get(thresholdField).Uint() + _, err := fmt.Fprintf(w, `{"threshold":"%d","pubkeys":`, threshold) if err != nil { return err } - - if len(pk.PublicKeys) == 0 { - _, err = io.WriteString(w, `[]}`) - return err - } - - fields := msg.Descriptor().Fields() pubkeysField := fields.ByName("public_keys") pubkeys := msg.Get(pubkeysField).List() - err = enc.marshalList(pubkeys, pubkeysField, w) if err != nil { return err diff --git a/x/tx/signing/aminojson/json_marshal.go b/x/tx/signing/aminojson/json_marshal.go index 800dfc7fd320..d4d1fc2b1151 100644 --- a/x/tx/signing/aminojson/json_marshal.go +++ b/x/tx/signing/aminojson/json_marshal.go @@ -162,6 +162,9 @@ func (enc Encoder) DefineTypeEncoding(typeURL string, encoder MessageEncoder) En func (enc Encoder) Marshal(message proto.Message) ([]byte, error) { buf := &bytes.Buffer{} err := enc.beginMarshal(message.ProtoReflect(), buf, false) + if err != nil { + return nil, err + } if enc.indent != "" { indentBuf := &bytes.Buffer{} @@ -169,10 +172,10 @@ func (enc Encoder) Marshal(message proto.Message) ([]byte, error) { return nil, err } - return indentBuf.Bytes(), err + return indentBuf.Bytes(), nil } - return buf.Bytes(), err + return buf.Bytes(), nil } func (enc Encoder) beginMarshal(msg protoreflect.Message, writer io.Writer, isAny bool) error {