Skip to content

Commit

Permalink
add for query validators
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Feb 2, 2024
1 parent 4b7dbae commit 50978a2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +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.
* (cli) [#199](https://github.com/cosmos/cosmos-sdk/pull/199) 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
30 changes: 29 additions & 1 deletion x/staking/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)
Expand Down Expand Up @@ -140,7 +141,34 @@ $ %s query staking validators
return err
}

return clientCtx.PrintProto(result)
newResult := &struct {
Validators []interface{} `json:"validators"`
Pagination *query.PageResponse `json:"pagination,omitempty"`
}{make([]interface{}, 0, len(result.Validators)), result.Pagination}
for _, validator := range result.Validators {
validator := validator
bytes, err := clientCtx.Codec.MarshalJSON(&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(validator.OperatorAddress)
if err != nil {
return err
}
data["validator_address"] = sdk.AccAddress(valAddr).String()
newResult.Validators = append(newResult.Validators, data)
}

bytes, err := json.Marshal(newResult)
if err != nil {
return err
}
return clientCtx.PrintBytes(bytes)
},
}

Expand Down

0 comments on commit 50978a2

Please sign in to comment.