Skip to content

Commit 1aa3a28

Browse files
fix(client/v2): *big.Int unmarshal (backport #21853) (#22174)
Co-authored-by: Julien Robert <[email protected]>
1 parent 3ecd143 commit 1aa3a28

File tree

4 files changed

+66
-6
lines changed

4 files changed

+66
-6
lines changed

client/v2/CHANGELOG.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,24 @@ Ref: https://keepachangelog.com/en/1.0.0/
4545

4646
### Improvements
4747

48-
* [#21712](https://github.com/cosmos/cosmos-sdk/pull/21712) Marshal `type` field as proto message url in queries instead of amino name.
48+
* [#21936](https://github.com/cosmos/cosmos-sdk/pull/21936) Print possible enum values in error message after an invalid input was provided.
4949

5050
### API Breaking Changes
5151

5252
* [#17709](https://github.com/cosmos/cosmos-sdk/pull/17709) Address codecs have been removed from `autocli.AppOptions` and `flag.Builder`. Instead client/v2 uses the address codecs present in the context (introduced in [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503)).
5353

5454
### Bug Fixes
5555

56+
* [#21853](https://github.com/cosmos/cosmos-sdk/pull/21853) Fix `*big.Int` unmarshalling in txs.
57+
58+
## [v2.0.0-beta.5] - 2024-09-18
59+
60+
### Improvements
61+
62+
* [#21712](https://github.com/cosmos/cosmos-sdk/pull/21712) Marshal `type` field as proto message url in queries instead of amino name.
63+
64+
### Bug Fixes
65+
5666
* [#20964](https://github.com/cosmos/cosmos-sdk/pull/20964) Fix `GetNodeHomeDirectory` helper in `client/v2/helpers` to respect the `(PREFIX)_HOME` environment variable.
5767

5868
## [v2.0.0-beta.3] - 2024-07-15

client/v2/autocli/flag/builder.go

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const (
2626
ValidatorAddressStringScalarType = "cosmos.ValidatorAddressString"
2727
ConsensusAddressStringScalarType = "cosmos.ConsensusAddressString"
2828
PubkeyScalarType = "cosmos.Pubkey"
29+
DecScalarType = "cosmos.Dec"
2930
)
3031

3132
// Builder manages options for building pflag flags for protobuf messages.
@@ -67,6 +68,7 @@ func (b *Builder) init() {
6768
b.scalarFlagTypes[ValidatorAddressStringScalarType] = validatorAddressStringType{}
6869
b.scalarFlagTypes[ConsensusAddressStringScalarType] = consensusAddressStringType{}
6970
b.scalarFlagTypes[PubkeyScalarType] = pubkeyType{}
71+
b.scalarFlagTypes[DecScalarType] = decType{}
7072
}
7173
}
7274

client/v2/autocli/flag/legacy_dec.go

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package flag
2+
3+
import (
4+
"context"
5+
6+
"google.golang.org/protobuf/reflect/protoreflect"
7+
8+
"cosmossdk.io/math"
9+
)
10+
11+
type decType struct{}
12+
13+
func (a decType) NewValue(_ *context.Context, _ *Builder) Value {
14+
return &decValue{}
15+
}
16+
17+
func (a decType) DefaultValue() string {
18+
return "0"
19+
}
20+
21+
type decValue struct {
22+
value string
23+
}
24+
25+
func (a decValue) Get(protoreflect.Value) (protoreflect.Value, error) {
26+
return protoreflect.ValueOf(a.value), nil
27+
}
28+
29+
func (a decValue) String() string {
30+
return a.value
31+
}
32+
33+
func (a *decValue) Set(s string) error {
34+
dec, err := math.LegacyNewDecFromStr(s)
35+
if err != nil {
36+
return err
37+
}
38+
39+
// we need to convert from float representation to non-float representation using default precision
40+
// 0.5 -> 500000000000000000
41+
a.value = dec.BigInt().String()
42+
43+
return nil
44+
}
45+
46+
func (a decValue) Type() string {
47+
return "cosmos.Dec"
48+
}

x/auth/tx/builder.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ var marshalOption = proto.MarshalOptions{
112112
func (w *builder) getTx() (*gogoTxWrapper, error) {
113113
anyMsgs, err := msgsV1toAnyV2(w.msgs)
114114
if err != nil {
115-
return nil, err
115+
return nil, fmt.Errorf("unable to convert messages: %w", err)
116116
}
117117
body := &txv1beta1.TxBody{
118118
Messages: anyMsgs,
@@ -136,12 +136,12 @@ func (w *builder) getTx() (*gogoTxWrapper, error) {
136136

137137
bodyBytes, err := marshalOption.Marshal(body)
138138
if err != nil {
139-
return nil, err
139+
return nil, fmt.Errorf("unable to marshal body: %w", err)
140140
}
141141

142142
authInfoBytes, err := marshalOption.Marshal(authInfo)
143143
if err != nil {
144-
return nil, err
144+
return nil, fmt.Errorf("unable to marshal auth info: %w", err)
145145
}
146146

147147
txRawBytes, err := marshalOption.Marshal(&txv1beta1.TxRaw{
@@ -150,12 +150,12 @@ func (w *builder) getTx() (*gogoTxWrapper, error) {
150150
Signatures: w.signatures,
151151
})
152152
if err != nil {
153-
return nil, err
153+
return nil, fmt.Errorf("unable to marshal tx raw: %w", err)
154154
}
155155

156156
decodedTx, err := w.decoder.Decode(txRawBytes)
157157
if err != nil {
158-
return nil, err
158+
return nil, fmt.Errorf("unable to decode tx: %w", err)
159159
}
160160

161161
return newWrapperFromDecodedTx(w.addressCodec, w.codec, decodedTx)

0 commit comments

Comments
 (0)