diff --git a/client/v2/autocli/flag/builder.go b/client/v2/autocli/flag/builder.go index 6ff325c53bdb..bdd42634dd35 100644 --- a/client/v2/autocli/flag/builder.go +++ b/client/v2/autocli/flag/builder.go @@ -26,6 +26,7 @@ const ( ValidatorAddressStringScalarType = "cosmos.ValidatorAddressString" ConsensusAddressStringScalarType = "cosmos.ConsensusAddressString" PubkeyScalarType = "cosmos.Pubkey" + DecScalarType = "cosmos.Dec" ) // Builder manages options for building pflag flags for protobuf messages. @@ -67,6 +68,7 @@ func (b *Builder) init() { b.scalarFlagTypes[ValidatorAddressStringScalarType] = validatorAddressStringType{} b.scalarFlagTypes[ConsensusAddressStringScalarType] = consensusAddressStringType{} b.scalarFlagTypes[PubkeyScalarType] = pubkeyType{} + b.scalarFlagTypes[DecScalarType] = decType{} } } diff --git a/client/v2/autocli/flag/legacy_dec.go b/client/v2/autocli/flag/legacy_dec.go new file mode 100644 index 000000000000..3b51505938a1 --- /dev/null +++ b/client/v2/autocli/flag/legacy_dec.go @@ -0,0 +1,44 @@ +package flag + +import ( + "context" + + "cosmossdk.io/math" + "google.golang.org/protobuf/reflect/protoreflect" +) + +type decType struct{} + +func (a decType) NewValue(_ *context.Context, _ *Builder) Value { + return &decValue{} +} + +func (a decType) DefaultValue() string { + return "0" +} + +type decValue struct { + value string +} + +func (a decValue) Get(protoreflect.Value) (protoreflect.Value, error) { + return protoreflect.ValueOf(a.value), nil +} + +func (a decValue) String() string { + return a.value +} + +func (a *decValue) Set(s string) error { + dec, err := math.LegacyNewDecFromStr(s) + if err != nil { + return err + } + a.value = dec.String() + + return nil +} + +func (a decValue) Type() string { + return "cosmos.Dec" +} diff --git a/x/auth/tx/builder.go b/x/auth/tx/builder.go index 423bca3a0870..2b1c866e8e0a 100644 --- a/x/auth/tx/builder.go +++ b/x/auth/tx/builder.go @@ -112,7 +112,7 @@ var marshalOption = proto.MarshalOptions{ func (w *builder) getTx() (*gogoTxWrapper, error) { anyMsgs, err := msgsV1toAnyV2(w.msgs) if err != nil { - return nil, err + return nil, fmt.Errorf("unable to convert messages: %w", err) } body := &txv1beta1.TxBody{ Messages: anyMsgs, @@ -136,12 +136,12 @@ func (w *builder) getTx() (*gogoTxWrapper, error) { bodyBytes, err := marshalOption.Marshal(body) if err != nil { - return nil, err + return nil, fmt.Errorf("unable to marshal body: %w", err) } authInfoBytes, err := marshalOption.Marshal(authInfo) if err != nil { - return nil, err + return nil, fmt.Errorf("unable to marshal auth info: %w", err) } txRawBytes, err := marshalOption.Marshal(&txv1beta1.TxRaw{ @@ -150,12 +150,12 @@ func (w *builder) getTx() (*gogoTxWrapper, error) { Signatures: w.signatures, }) if err != nil { - return nil, err + return nil, fmt.Errorf("unable to marshal tx raw: %w", err) } decodedTx, err := w.decoder.Decode(txRawBytes) if err != nil { - return nil, err + return nil, fmt.Errorf("unable to decode tx: %w", err) } return newWrapperFromDecodedTx(w.addressCodec, w.codec, decodedTx) diff --git a/x/tx/decode/decode.go b/x/tx/decode/decode.go index 994d54cf488b..bf4f3a54f31f 100644 --- a/x/tx/decode/decode.go +++ b/x/tx/decode/decode.go @@ -84,7 +84,7 @@ func (d *Decoder) Decode(txBytes []byte) (*DecodedTx, error) { err = proto.Unmarshal(txBytes, &raw) if err != nil { - return nil, err + return nil, errorsmod.Wrap(ErrTxDecode, err.Error()) } var body v1beta1.TxBody @@ -136,7 +136,7 @@ func (d *Decoder) Decode(txBytes []byte) (*DecodedTx, error) { dynamicMsg := dynamicpb.NewMessageType(msgDesc.(protoreflect.MessageDescriptor)).New().Interface() err = anyMsg.UnmarshalTo(dynamicMsg) if err != nil { - return nil, err + return nil, errorsmod.Wrap(ErrTxDecode, fmt.Sprintf("cannot unmarshal Any message: %v", err)) } dynamicMsgs = append(dynamicMsgs, dynamicMsg) @@ -148,7 +148,7 @@ func (d *Decoder) Decode(txBytes []byte) (*DecodedTx, error) { msg := reflect.New(gogoType.Elem()).Interface().(gogoproto.Message) err = d.codec.Unmarshal(anyMsg.Value, msg) if err != nil { - return nil, err + return nil, errorsmod.Wrap(ErrTxDecode, err.Error()) } msgs = append(msgs, msg)