Skip to content

Commit

Permalink
[ioctl] node reward unclaimed support name query (#4150)
Browse files Browse the repository at this point in the history
Co-authored-by: dustinxie <dahuaxie@gmail.com>
  • Loading branch information
millken and dustinxie committed Mar 8, 2024
1 parent bbe637a commit 55baf52
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
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

0 comments on commit 55baf52

Please sign in to comment.