Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ioctl]node reward unclaimed support name query #4150

Merged
merged 8 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions ioctl/cmd/node/nodedelegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,20 @@ func getAllStakingCandidates(chainClient iotexapi.APIServiceClient) (candidateLi
}
return
}

func getCandidateRewardAddressByAddressOrName(cli iotexapi.APIServiceClient, name string) (string, error) {
address, err1 := util.Address(name)
if err1 == nil {
return address, nil
}
cl, err := getAllStakingCandidates(cli)
if err != nil {
return "", err
}
for _, candidate := range cl.Candidates {
if candidate.Name == name {
return candidate.RewardAddress, nil
}
}
return "", err1
}
14 changes: 8 additions & 6 deletions ioctl/cmd/node/nodereward.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
// Multi-language support
var (
_rewardCmdUses = map[config.Language]string{
config.English: "reward unclaimed|pool [ALIAS|DELEGATE_ADDRESS]",
config.Chinese: "reward 未支取|奖金池 [别名|委托地址]",
config.English: "reward unclaimed|pool [ALIAS|REWARD_ADDRESS|NAME]",
config.Chinese: "reward 未支取|奖金池 [别名|奖励地址|名称]",
}
_rewardCmdShorts = map[config.Language]string{
config.English: "Query rewards",
Expand Down Expand Up @@ -155,16 +155,18 @@ func rewardPool() error {
}

func reward(arg string) error {
address, err := util.Address(arg)
if err != nil {
return output.NewError(output.AddressError, "failed to get address", err)
}
conn, err := util.ConnectToEndpoint(config.ReadConfig.SecureConnect && !config.Insecure)
if err != nil {
return output.NewError(output.NetworkError, "failed to connect to endpoint", err)
}
defer conn.Close()
cli := iotexapi.NewAPIServiceClient(conn)

address, err := getCandidateRewardAddressByAddressOrName(cli, arg)
if err != nil {
return output.NewError(output.AddressError, "failed to get address", err)
}

ctx := context.Background()

jwtMD, err := util.JwtAuth()
Expand Down
Loading