Skip to content

Commit 2afb7b4

Browse files
authored
[ioctl] deprecate 'ioctl stake' and display bucket index in action hash command (iotexproject#2165)
1 parent 6034b82 commit 2afb7b4

20 files changed

+83
-499
lines changed

action/protocol/staking/handlers.go

+17
Original file line numberDiff line numberDiff line change
@@ -720,3 +720,20 @@ func csmErrorToHandleError(caller string, err error) error {
720720
return err
721721
}
722722
}
723+
724+
// BucketIndexFromReceiptLog extracts bucket index from log
725+
func BucketIndexFromReceiptLog(log *iotextypes.Log) (uint64, bool) {
726+
if log == nil || len(log.Topics) < 2 {
727+
return 0, false
728+
}
729+
730+
switch hash.BytesToHash256(log.Topics[0]) {
731+
case hash.BytesToHash256([]byte(HandleCreateStake)), hash.BytesToHash256([]byte(HandleUnstake)),
732+
hash.BytesToHash256([]byte(HandleWithdrawStake)), hash.BytesToHash256([]byte(HandleChangeCandidate)),
733+
hash.BytesToHash256([]byte(HandleTransferStake)), hash.BytesToHash256([]byte(HandleDepositToStake)),
734+
hash.BytesToHash256([]byte(HandleRestake)), hash.BytesToHash256([]byte(HandleCandidateRegister)):
735+
return byteutil.BytesToUint64BigEndian(log.Topics[1][24:]), true
736+
default:
737+
return 0, false
738+
}
739+
}

ioctl/cmd/action/actionhash.go

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/iotexproject/iotex-proto/golang/iotexapi"
2626
"github.com/iotexproject/iotex-proto/golang/iotextypes"
2727

28+
"github.com/iotexproject/iotex-core/action/protocol/staking"
2829
"github.com/iotexproject/iotex-core/ioctl/cmd/alias"
2930
"github.com/iotexproject/iotex-core/ioctl/config"
3031
"github.com/iotexproject/iotex-core/ioctl/output"
@@ -241,6 +242,11 @@ func printReceiptProto(receipt *iotextypes.Receipt) string {
241242
result += fmt.Sprintf("\ncontractAddress: %s %s", receipt.ContractAddress,
242243
Match(receipt.ContractAddress, "address"))
243244
}
245+
if len(receipt.Logs) > 0 {
246+
if index, ok := staking.BucketIndexFromReceiptLog(receipt.Logs[0]); ok {
247+
result += fmt.Sprintf("\nbucket index: %d", index)
248+
}
249+
}
244250
return result
245251
}
246252

ioctl/cmd/action/stake.go

-131
This file was deleted.

ioctl/cmd/action/stake2.go

+17
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
package action
88

99
import (
10+
"math/big"
11+
1012
"github.com/spf13/cobra"
1113

1214
"github.com/iotexproject/iotex-core/ioctl/config"
15+
"github.com/iotexproject/iotex-core/ioctl/output"
16+
"github.com/iotexproject/iotex-core/ioctl/validator"
1317
)
1418

1519
// Multi-language support
@@ -53,3 +57,16 @@ func init() {
5357
Stake2Cmd.PersistentFlags().StringVar(&config.ReadConfig.Endpoint, "endpoint", config.ReadConfig.Endpoint, config.TranslateInLang(stake2FlagEndpointUsages, config.UILanguage))
5458
Stake2Cmd.PersistentFlags().BoolVar(&config.Insecure, "insecure", config.Insecure, config.TranslateInLang(stake2FlagInsecureUsages, config.UILanguage))
5559
}
60+
61+
func parseStakeDuration(stakeDurationString string) (*big.Int, error) {
62+
stakeDuration, ok := new(big.Int).SetString(stakeDurationString, 10)
63+
if !ok {
64+
return nil, output.NewError(output.ConvertError, "failed to convert stake duration", nil)
65+
}
66+
67+
if err := validator.ValidateStakeDuration(stakeDuration); err != nil {
68+
return nil, output.NewError(output.ValidationError, "invalid stake duration", err)
69+
}
70+
71+
return stakeDuration, nil
72+
}

ioctl/cmd/action/stake2Transfer.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ var (
2323
stake2TransferCmdUses = map[config.Language]string{
2424
config.English: "transfer (ALIAS|VOTE_ADDRESS) BUCKET_INDEX [DATA]" +
2525
" [-s SIGNER] [-n NONCE] [-l GAS_LIMIT] [-p GAS_PRICE] [-P PASSWORD] [-y]",
26-
config.Chinese: "transfer (别名|投票地址) 桶索引 [数据]" +
26+
config.Chinese: "transfer (别名|投票地址) 票索引 [数据]" +
2727
" [-s 签署人] [-n NONCE] [-l GAS限制] [-p GAS价格] [-P 密码] [-y]",
2828
}
2929

3030
stake2TransferCmdShorts = map[config.Language]string{
31-
config.English: "transfer transfers stake ownership on IoTeX blockchain",
32-
config.Chinese: "在区块链上转移质押",
31+
config.English: "Transfer bucket ownership on IoTeX blockchain",
32+
config.Chinese: "在IoTeX区块链上转移投票所有权",
3333
}
3434
)
3535

ioctl/cmd/action/stake2Withdraw.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ var (
2222
stake2WithDrawCmdUses = map[config.Language]string{
2323
config.English: "withdraw BUCKET_INDEX [DATA]" +
2424
" [-s SIGNER] [-n NONCE] [-l GAS_LIMIT] [-p GAS_PRICE] [-P PASSWORD] [-y]",
25-
config.Chinese: "withdraw 桶索引 [数据]" +
25+
config.Chinese: "withdraw 票索引 [数据]" +
2626
" [-s 签署人] [-n NONCE] [-l GAS限制] [-p GAS价格] [-P 密码] [-y]",
2727
}
2828
stake2WithDrawCmdShorts = map[config.Language]string{
29-
config.English: "Withdraw form bucket on IoTeX blockchain",
30-
config.Chinese: "在IoTeX区块链上撤回表单存储桶",
29+
config.English: "Withdraw bucket from IoTeX blockchain",
30+
config.Chinese: "提取IoTeX区块链上的投票",
3131
}
3232
)
3333

3434
// stake2WithdrawCmd represents the stake2 withdraw command
3535
var stake2WithdrawCmd = &cobra.Command{
36-
Use: config.TranslateInLang(withDrawCmdUses, config.UILanguage),
37-
Short: config.TranslateInLang(withDrawCmdShorts, config.UILanguage),
36+
Use: config.TranslateInLang(stake2WithDrawCmdUses, config.UILanguage),
37+
Short: config.TranslateInLang(stake2WithDrawCmdShorts, config.UILanguage),
3838
Args: cobra.RangeArgs(1, 2),
3939
RunE: func(cmd *cobra.Command, args []string) error {
4040
cmd.SilenceUsage = true

ioctl/cmd/action/stake2add.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ import (
2222
var (
2323
stake2AddCmdUses = map[config.Language]string{
2424
config.English: "add BUCKET_INDEX AMOUNT_IOTX [DATA]" +
25-
"[-s SIGNER] [-n NONCE] [-l GAS_LIMIT] [-p GAS_PRICE] [-P PASSWORD] [-y]",
26-
config.Chinese: "add 桶索引 IOTX数量 [数据]" +
27-
"[-s 签署人] [-n NONCE] [-l GAS限制] [-p GAS价格] [-P 密码] [-y]",
25+
" [-s SIGNER] [-n NONCE] [-l GAS_LIMIT] [-p GAS_PRICE] [-P PASSWORD] [-y]",
26+
config.Chinese: "add 票索引 IOTX数量 [数据]" +
27+
" [-s 签署人] [-n NONCE] [-l GAS限制] [-p GAS价格] [-P 密码] [-y]",
2828
}
2929

3030
stake2AddCmdShorts = map[config.Language]string{
31-
config.English: "add deposit to stake on IoTeX blockchain",
32-
config.Chinese: "在区块链上添加质押的存款",
31+
config.English: "Add IOTX to bucket on IoTeX blockchain",
32+
config.Chinese: "添加IOTX到IoTeX区块链上的投票",
3333
}
3434
)
3535

ioctl/cmd/action/stake2change.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import (
2222
var (
2323
stake2ChangeCmdUses = map[config.Language]string{
2424
config.English: "change CANDIDATE_NAME BUCKET_INDEX [DATA]" +
25-
"[-s SIGNER] [-n NONCE] [-l GAS_LIMIT] [-p GAS_PRICE] [-P PASSWORD] [-y]",
26-
config.Chinese: "change 候选人姓名 桶索引 [数据]" +
25+
" [-s SIGNER] [-n NONCE] [-l GAS_LIMIT] [-p GAS_PRICE] [-P PASSWORD] [-y]",
26+
config.Chinese: "change 候选人名字 票索引 [数据]" +
2727
" [-s 签署人] [-n NONCE] [-l GAS限制] [-p GAS价格] [-P 密码] [-y]",
2828
}
2929
stake2ChangeCmdShorts = map[config.Language]string{
3030
config.English: "Change stake candidate",
31-
config.Chinese: "改变质押候选人",
31+
config.Chinese: "在IoTeX区块链上改变投票候选人",
3232
}
3333
)
3434

ioctl/cmd/action/stake2create.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ import (
2121
// Multi-language support
2222
var (
2323
stake2CreateCmdUses = map[config.Language]string{
24-
config.English: "create AMOUNT_IOTX CANDIDATE_NAME STAKE_DURATION [DATA] [--auto-restake]",
25-
config.Chinese: "create IOTX数量 候选人姓名 权益持续时间 [数据] [--auto-restake]",
24+
config.English: "create AMOUNT_IOTX CANDIDATE_NAME STAKE_DURATION [DATA] [--auto-restake" +
25+
"] [-s SIGNER] [-n NONCE] [-l GAS_LIMIT] [-p GASP_RICE] [-P PASSWORD] [-y]",
26+
config.Chinese: "create IOTX数量 候选人名字 投票持续时间 [数据] [--auto-restake" +
27+
"] [-s 签署人] [-n NONCE] [-l GAS限制] [-p GAS价格] [-P 密码] [-y]",
2628
}
2729

2830
stake2CreateCmdShorts = map[config.Language]string{
29-
config.English: "create stake on IoTeX blockchain",
30-
config.Chinese: "在区块链上创建质押",
31+
config.English: "Create bucket on IoTeX blockchain",
32+
config.Chinese: "在IoTeX区块链上创建投票",
3133
}
3234
stake2CreateFlagAutoRestakeUsages = map[config.Language]string{
3335
config.English: "auto restake without power decay",
@@ -36,7 +38,8 @@ var (
3638
)
3739

3840
// stake2CreateCmd represents the stake2 create command
39-
var stake2CreateCmd = &cobra.Command{Use: config.TranslateInLang(stake2CreateCmdUses, config.UILanguage),
41+
var stake2CreateCmd = &cobra.Command{
42+
Use: config.TranslateInLang(stake2CreateCmdUses, config.UILanguage),
4043
Short: config.TranslateInLang(stake2CreateCmdShorts, config.UILanguage),
4144
Args: cobra.RangeArgs(3, 4),
4245
RunE: func(cmd *cobra.Command, args []string) error {

ioctl/cmd/action/stake2register.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ import (
2222
var (
2323
registerCmdUses = map[config.Language]string{
2424
config.English: "register NAME (ALIAS|OPERATO_ADDRESS) (ALIAS|REWARD_ADDRESS) (ALIAS|OWNER_ADDRESS) AMOUNT_IOTX STAKE_DURATION [DATA] [--auto-restake] [-s SIGNER] [-n NONCE] [-l GAS_LIMIT] [-p GAS_PRICE] [-P PASSWORD] [-y]",
25-
config.Chinese: "register 姓名 (别名|操作者地址)(别名|奖励地址)(别名|所有者地址)IOTX数量 质押持续时间 [数据] [--auto-restake] [-s 签署人] [-n NONCE] [-l GAS限制] [-p GAS价格] [-P 密码] [-y]",
25+
config.Chinese: "register 名字 (别名|操作者地址)(别名|奖励地址)(别名|所有者地址)IOTX数量 质押持续时间 [数据] [--auto-restake] [-s 签署人] [-n NONCE] [-l GAS限制] [-p GAS价格] [-P 密码] [-y]",
2626
}
2727

2828
registerCmdShorts = map[config.Language]string{
2929
config.English: "register a candidate",
30-
config.Chinese: "注册候选人",
30+
config.Chinese: "在IoTeX区块链上注册候选人",
3131
}
3232

3333
stake2FlagRegisterAutoRestakeUsages = map[config.Language]string{

ioctl/cmd/action/stake2release.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ import (
2020
// Multi-language support
2121
var (
2222
stake2ReleaseCmdUses = map[config.Language]string{
23-
config.English: "release BUCKET_INDEX [DATA] " +
23+
config.English: "release BUCKET_INDEX [DATA]" +
2424
" [-s SIGNER] [-n NONCE] [-l GAS_LIMIT] [-p GAS_PRICE] [-P PASSWORD] [-y]",
25-
config.Chinese: "release 桶索引 [数据] " +
25+
config.Chinese: "release 票索引 [数据]" +
2626
" [-s 签署人] [-n NONCE] [-l GAS限制] [-p GAS价格] [-P 密码] [-y]",
2727
}
2828
stake2ReleaseCmdShorts = map[config.Language]string{
2929
config.English: "Release bucket on IoTeX blockchain",
30-
config.Chinese: "释放IoTeX区块链上的存储桶",
30+
config.Chinese: "撤回IoTeX区块链上的投票",
3131
}
3232
)
3333

3434
// stake2ReleaseCmd represents the stake2 release command
3535
var stake2ReleaseCmd = &cobra.Command{
36-
Use: config.TranslateInLang(releaseCmdUses, config.UILanguage),
37-
Short: config.TranslateInLang(releaseCmdShorts, config.UILanguage),
36+
Use: config.TranslateInLang(stake2ReleaseCmdUses, config.UILanguage),
37+
Short: config.TranslateInLang(stake2ReleaseCmdShorts, config.UILanguage),
3838
Args: cobra.RangeArgs(1, 2),
3939
RunE: func(cmd *cobra.Command, args []string) error {
4040
cmd.SilenceUsage = true

ioctl/cmd/action/stake2renew.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ import (
2121
var (
2222
stake2RenewCmdUses = map[config.Language]string{
2323
config.English: "renew BUCKET_INDEX STAKE_DURATION [DATA] [--auto-restake]" +
24-
"[-s SIGNER] [-n NONCE] [-l GAS_LIMIT] [-p GAS_PRICE] [-P PASSWORD] [-y]",
25-
config.Chinese: "renew 桶索引 权益持续时间 [数据] [--auto-restake]" +
26-
"[-s 签署人] [-n NONCE] [-l GAS限制] [-p GAS价格] [-P 密码] [-y]",
24+
" [-s SIGNER] [-n NONCE] [-l GAS_LIMIT] [-p GAS_PRICE] [-P PASSWORD] [-y]",
25+
config.Chinese: "renew 票索引 投票持续时间 [数据] [--auto-restake]" +
26+
" [-s 签署人] [-n NONCE] [-l GAS限制] [-p GAS价格] [-P 密码] [-y]",
2727
}
2828

2929
stake2RenewCmdShorts = map[config.Language]string{
30-
config.English: "renew bucket on IoTeX blockchain",
31-
config.Chinese: "更新IoTeX区块链上的存储桶",
30+
config.English: "Renew bucket on IoTeX blockchain",
31+
config.Chinese: "更新IoTeX区块链上的投票",
3232
}
3333

3434
stake2RenewFlagAutoRestakeUsages = map[config.Language]string{
@@ -38,7 +38,8 @@ var (
3838
)
3939

4040
// stake2RenewCmd represents the stake2 renew command
41-
var stake2RenewCmd = &cobra.Command{Use: config.TranslateInLang(stake2RenewCmdUses, config.UILanguage),
41+
var stake2RenewCmd = &cobra.Command{
42+
Use: config.TranslateInLang(stake2RenewCmdUses, config.UILanguage),
4243
Short: config.TranslateInLang(stake2RenewCmdShorts, config.UILanguage),
4344
Args: cobra.RangeArgs(2, 3),
4445
RunE: func(cmd *cobra.Command, args []string) error {
@@ -49,7 +50,8 @@ var stake2RenewCmd = &cobra.Command{Use: config.TranslateInLang(stake2RenewCmdUs
4950

5051
func init() {
5152
registerWriteCommand(stake2RenewCmd)
52-
stake2RenewCmd.Flags().BoolVar(&stake2AutoRestake, "auto-restake", false, config.TranslateInLang(stake2RenewFlagAutoRestakeUsages, config.UILanguage))
53+
stake2RenewCmd.Flags().BoolVar(&stake2AutoRestake, "auto-restake", false,
54+
config.TranslateInLang(stake2RenewFlagAutoRestakeUsages, config.UILanguage))
5355
}
5456

5557
func stake2Renew(args []string) error {

0 commit comments

Comments
 (0)