From df0778984359bd7649a7f99616a86793cd27f662 Mon Sep 17 00:00:00 2001 From: julienrbrt Date: Thu, 3 Apr 2025 16:02:26 +0200 Subject: [PATCH] fix(client/v2): *big.Int unmarshal (cherry-pick #21853) (#24361) --- client/v2/CHANGELOG.md | 7 +++- client/v2/autocli/flag/builder.go | 2 ++ client/v2/autocli/flag/legacy_dec.go | 48 ++++++++++++++++++++++++++++ simapp/go.mod | 4 ++- simapp/go.sum | 6 ++-- tests/go.mod | 2 +- 6 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 client/v2/autocli/flag/legacy_dec.go diff --git a/client/v2/CHANGELOG.md b/client/v2/CHANGELOG.md index 300214f02b..86fa06c8e7 100644 --- a/client/v2/CHANGELOG.md +++ b/client/v2/CHANGELOG.md @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes * (cli) [#24330](https://github.com/cosmos/cosmos-sdk/pull/24330) Use the gogoproto merge registry as a file resolver instead of the interface registry. +* [#21853](https://github.com/cosmos/cosmos-sdk/pull/21853) Fix `*big.Int` unmarshalling in txs. ## [v2.0.0-beta.8] - 2025-01-29 @@ -66,10 +67,14 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements -* [#21712](https://github.com/cosmos/cosmos-sdk/pull/21712) Marshal `type` field as proto message url in queries instead of amino name. +* [#21936](https://github.com/cosmos/cosmos-sdk/pull/21936) Print possible enum values in error message after an invalid input was provided. ## [v2.0.0-beta.4] - 2024-07-16 +### Improvements + +* [#21712](https://github.com/cosmos/cosmos-sdk/pull/21712) Marshal `type` field as proto message url in queries instead of amino name. + ### Bug Fixes * [#20964](https://github.com/cosmos/cosmos-sdk/pull/20964) Fix `GetNodeHomeDirectory` helper in `client/v2/helpers` to respect the `(PREFIX)_HOME` environment variable. diff --git a/client/v2/autocli/flag/builder.go b/client/v2/autocli/flag/builder.go index 9c38441750..1235809608 100644 --- a/client/v2/autocli/flag/builder.go +++ b/client/v2/autocli/flag/builder.go @@ -28,6 +28,7 @@ const ( ValidatorAddressStringScalarType = "cosmos.ValidatorAddressString" ConsensusAddressStringScalarType = "cosmos.ConsensusAddressString" PubkeyScalarType = "cosmos.Pubkey" + DecScalarType = "cosmos.Dec" ) // Builder manages options for building pflag flags for protobuf messages. @@ -70,6 +71,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 0000000000..073afa94f1 --- /dev/null +++ b/client/v2/autocli/flag/legacy_dec.go @@ -0,0 +1,48 @@ +package flag + +import ( + "context" + + "google.golang.org/protobuf/reflect/protoreflect" + + "cosmossdk.io/math" +) + +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 + } + + // we need to convert from float representation to non-float representation using default precision + // 0.5 -> 500000000000000000 + a.value = dec.BigInt().String() + + return nil +} + +func (a decValue) Type() string { + return "cosmos.Dec" +} diff --git a/simapp/go.mod b/simapp/go.mod index 18a9994a0d..7912c2beaf 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -21,7 +21,7 @@ require ( github.com/cometbft/cometbft v0.38.17 github.com/cosmos/cosmos-db v1.1.1 // this version is not used as it is always replaced by the latest Cosmos SDK version - github.com/cosmos/cosmos-sdk v0.53.0-rc.1 + github.com/cosmos/cosmos-sdk v0.53.0-rc.2 github.com/cosmos/gogoproto v1.7.0 github.com/spf13/cast v1.7.1 github.com/spf13/cobra v1.9.1 @@ -218,6 +218,8 @@ require ( sigs.k8s.io/yaml v1.4.0 // indirect ) +replace cosmossdk.io/client/v2 => ../client/v2 + // Here are the short-lived replace from the SimApp // Replace here are pending PRs, or version to be tagged // replace ( diff --git a/simapp/go.sum b/simapp/go.sum index d82b5a3dd9..3ad78be0d7 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -616,8 +616,6 @@ cloud.google.com/go/workflows v1.9.0/go.mod h1:ZGkj1aFIOd9c8Gerkjjq7OW7I5+l6cSvT cloud.google.com/go/workflows v1.10.0/go.mod h1:fZ8LmRmZQWacon9UCX1r/g/DfAXx5VcPALq2CxzdePw= cosmossdk.io/api v0.9.0 h1:QYs9APeSlDNGbsBOBFjp3jXgGd4hnEPnnku3+W3tT4Y= cosmossdk.io/api v0.9.0/go.mod h1:pLkU/NSqYHWxyN7XftVt8iD7oldKJzqMZgzeiOmT2nk= -cosmossdk.io/client/v2 v2.0.0-beta.5.0.20241121152743-3dad36d9a29e h1:NqQEVIjRqSdsAfTI9uDRZ1oU/cQuCoAbUuIkndQM+Bo= -cosmossdk.io/client/v2 v2.0.0-beta.5.0.20241121152743-3dad36d9a29e/go.mod h1:4p0P6o0ro+FizakJUYS9SeM94RNbv0thLmkHRw5o5as= cosmossdk.io/collections v1.2.0 h1:IesfVG8G/+FYCMVMP01frS/Cw99Omk5vBh3cHbO01Gg= cosmossdk.io/collections v1.2.0/go.mod h1:4NkMoYw6qRA8fnSH/yn1D/MOutr8qyQnwsO50Mz9ItU= cosmossdk.io/core v0.11.3 h1:mei+MVDJOwIjIniaKelE3jPDqShCc/F4LkNNHh+4yfo= @@ -726,8 +724,8 @@ github.com/bits-and-blooms/bitset v1.22.0 h1:Tquv9S8+SGaS3EhyA+up3FXzmkhxPGjQQCk github.com/bits-and-blooms/bitset v1.22.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= -github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ= -github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= +github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= +github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= github.com/btcsuite/btcd/btcutil v1.1.6 h1:zFL2+c3Lb9gEgqKNzowKUPQNb8jV7v5Oaodi/AYFd6c= github.com/btcsuite/btcd/btcutil v1.1.6/go.mod h1:9dFymx8HpuLqBnsPELrImQeTQfKBQqzqGbbV3jK55aE= github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/FBatYVw= diff --git a/tests/go.mod b/tests/go.mod index 1e9c80486c..60f9503ef1 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -20,7 +20,7 @@ require ( github.com/cosmos/cosmos-db v1.1.1 github.com/cosmos/cosmos-proto v1.0.0-beta.5 // this version is not used as it is always replaced by the latest Cosmos SDK version - github.com/cosmos/cosmos-sdk v0.53.0-rc.1 + github.com/cosmos/cosmos-sdk v0.53.0-rc.2 github.com/cosmos/go-bip39 v1.0.0 github.com/cosmos/gogoproto v1.7.0 github.com/spf13/cobra v1.9.1