Skip to content

Commit

Permalink
feat: apply cronos x/tx (#210)
Browse files Browse the repository at this point in the history
* feat(x/tx): support bytes field as signer (cosmos#21850)

* Problem: multisig account failed on threshold encode after send tx   (cosmos#808)

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

* use directly instead of cast

---------

Co-authored-by: Antonio Pitasi <antonio@pitasi.dev>

* feat: Fix datarace

---------

Co-authored-by: mmsqe <mavis@crypto.com>
Co-authored-by: Antonio Pitasi <antonio@pitasi.dev>
  • Loading branch information
3 people authored Nov 6, 2024
1 parent 7ee3115 commit 3f9b5f9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 53 deletions.
4 changes: 2 additions & 2 deletions x/tx/internal/testpb/signers.proto
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ message DeeplyNestedRepeatedSigner {

message BadSigner {
option (cosmos.msg.v1.signer) = "signer";
bytes signer = 1;
int32 signer = 1;
}

message NoSignerOption {
Expand All @@ -107,4 +107,4 @@ message ValidatorSigner {
service TestSimpleSigner {
option (cosmos.msg.v1.service) = true;
rpc TestSimpleSigner(SimpleSigner) returns (SimpleSigner) {}
}
}
56 changes: 19 additions & 37 deletions x/tx/internal/testpb/signers.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 4 additions & 14 deletions x/tx/signing/aminojson/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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 @@ -166,24 +165,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
6 changes: 6 additions & 0 deletions x/tx/signing/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,19 @@ func (c *Context) makeGetSignersFunc(descriptor protoreflect.MessageDescriptor)
}
return arr, nil
}
case protoreflect.BytesKind:
fieldGetters[i] = func(msg proto.Message, arr [][]byte) ([][]byte, error) {
addrBz := msg.ProtoReflect().Get(field).Bytes()
return append(arr, addrBz), nil
}
default:
return nil, fmt.Errorf("unexpected field type %s for field %s in message %s", field.Kind(), fieldName, descriptor.FullName())
}
}

return func(message proto.Message) ([][]byte, error) {
var signers [][]byte
var err error
for _, getter := range fieldGetters {
signers, err = getter(message, signers)
if err != nil {
Expand Down

0 comments on commit 3f9b5f9

Please sign in to comment.