From e6e45832efce5017ded0123d6e31cfe00ae75778 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 8 Oct 2024 08:23:18 +0200 Subject: [PATCH] revert marshal changes (fixed by #22161) --- client/v2/CHANGELOG.md | 1 - client/v2/autocli/query.go | 33 +-------------------------------- 2 files changed, 1 insertion(+), 33 deletions(-) diff --git a/client/v2/CHANGELOG.md b/client/v2/CHANGELOG.md index b49389327cc0..8bd7877b448a 100644 --- a/client/v2/CHANGELOG.md +++ b/client/v2/CHANGELOG.md @@ -56,7 +56,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes * [#21853](https://github.com/cosmos/cosmos-sdk/pull/21853) Fix `*big.Int` unmarshalling in txs. -* [#21853](https://github.com/cosmos/cosmos-sdk/pull/21853) Fix `*big.Int` marshalling in queries. ## [v2.0.0-beta.5] - 2024-09-18 diff --git a/client/v2/autocli/query.go b/client/v2/autocli/query.go index 790a94f8cb91..d308bcd7633a 100644 --- a/client/v2/autocli/query.go +++ b/client/v2/autocli/query.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "math/big" "strings" "time" @@ -172,7 +171,7 @@ func (b *Builder) BuildQueryMethodCommand(ctx context.Context, descriptor protor } func encoder(encoder aminojson.Encoder) aminojson.Encoder { - customEncoder := encoder.DefineTypeEncoding("google.protobuf.Duration", func(_ *aminojson.Encoder, msg protoreflect.Message, w io.Writer) error { + return encoder.DefineTypeEncoding("google.protobuf.Duration", func(_ *aminojson.Encoder, msg protoreflect.Message, w io.Writer) error { var ( secondsName protoreflect.Name = "seconds" nanosName protoreflect.Name = "nanos" @@ -232,34 +231,4 @@ func encoder(encoder aminojson.Encoder) aminojson.Encoder { _, err = fmt.Fprintf(w, `"%s"`, sdk.NewDecCoinFromDec(denom, amountDec)) // TODO(@julienrbrt): Eventually remove this SDK dependency return err }) - - customEncoder.DefineScalarEncoding("cosmos.Dec", func(_ *aminojson.Encoder, value protoreflect.Value, w io.Writer) error { - decStr := value.String() - if strings.Contains(decStr, "[") { // check if it's a bytes field (e.g mint inflation) - decStr = string(value.Bytes()) - } - - // If the decimal doesn't contain a point, we assume it's a value formatted using the legacy - // `math.Dec`. So we try to parse it as an integer and then convert it to a - // decimal. - if !strings.Contains(decStr, ".") { - parsedInt, ok := new(big.Int).SetString(decStr, 10) - if !ok { - return fmt.Errorf("invalid decimal: %s", decStr) - } - - // We assume the decimal has 18 digits of precision. - decStr = math.LegacyNewDecFromBigIntWithPrec(parsedInt, math.LegacyPrecision).String() - } - - formatted, err := math.FormatDec(decStr) - if err != nil { - return fmt.Errorf("cannot format decimal %s: %w", decStr, err) - } - - _, err = fmt.Fprintf(w, `"%s"`, formatted) - return err - }) - - return customEncoder }