From 4b7dbae075a8105cae877694da921df87ad40229 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 2 Feb 2024 23:24:05 +0800 Subject: [PATCH] Problem: no validator_address when query validator info --- CHANGELOG.md | 1 + x/staking/client/cli/query.go | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e428c6fb1ed4..d90c2d2684f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (client/tx) [#18852](https://github.com/cosmos/cosmos-sdk/pull/18852) Add `WithFromName` to tx factory. * (types) [#18875](https://github.com/cosmos/cosmos-sdk/pull/18875) Speedup coins.Sort() if len(coins) <= 1 * (testutil) [#18930](https://github.com/cosmos/cosmos-sdk/pull/18930) Add NodeURI for clientCtx. +* (cli) [#](https://github.com/cosmos/cosmos-sdk/pull/) Add validator_address when query validator info. ## [v0.47.7](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.7) - 2023-12-20 diff --git a/x/staking/client/cli/query.go b/x/staking/client/cli/query.go index 0982296161e4..2955f805626b 100644 --- a/x/staking/client/cli/query.go +++ b/x/staking/client/cli/query.go @@ -1,6 +1,7 @@ package cli import ( + "encoding/json" "fmt" "strconv" "strings" @@ -78,8 +79,25 @@ $ %s query staking validator %s1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj if err != nil { return err } - - return clientCtx.PrintProto(&res.Validator) + bytes, err := clientCtx.Codec.MarshalJSON(&res.Validator) + if err != nil { + return err + } + var data map[string]interface{} + err = json.Unmarshal(bytes, &data) + if err != nil { + return err + } + valAddr, err := sdk.ValAddressFromBech32(res.Validator.OperatorAddress) + if err != nil { + return err + } + data["validator_address"] = sdk.AccAddress(valAddr).String() + bytes, err = json.Marshal(data) + if err != nil { + return err + } + return clientCtx.PrintBytes(bytes) }, }