Skip to content

Commit

Permalink
Problem: no validator_address when query validator info
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Feb 2, 2024
1 parent c887e86 commit 4b7dbae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 20 additions & 2 deletions x/staking/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"encoding/json"
"fmt"
"strconv"
"strings"
Expand Down Expand Up @@ -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)
},
}

Expand Down

0 comments on commit 4b7dbae

Please sign in to comment.