Skip to content

Commit

Permalink
Problem: multisig account failed on threshold encode after send tx (#808
Browse files Browse the repository at this point in the history
)

* fix(x/tx): don't shadow Amino marshalling error messages (cosmos#19955)

* use directly instead of cast

---------

Co-authored-by: Antonio Pitasi <[email protected]>
  • Loading branch information
mmsqe and Pitasi authored Sep 27, 2024
1 parent 1675d17 commit c2a1e06
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
4 changes: 4 additions & 0 deletions x/tx/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 4 additions & 14 deletions x/tx/signing/aminojson/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions x/tx/signing/aminojson/json_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,20 @@ 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{}
if err := json.Indent(indentBuf, buf.Bytes(), "", enc.indent); err != nil {
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 {
Expand Down

0 comments on commit c2a1e06

Please sign in to comment.