github.com/iotexproject/iotex-core@v1.14.1-rc1/ioctl/newcmd/action/actiondeposit.go (about) 1 // Copyright (c) 2022 IoTeX Foundation 2 // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability 3 // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. 4 // This source code is governed by Apache License 2.0 that can be found in the LICENSE file. 5 6 package action 7 8 import ( 9 "github.com/pkg/errors" 10 "github.com/spf13/cobra" 11 12 "github.com/iotexproject/iotex-core/action" 13 "github.com/iotexproject/iotex-core/ioctl" 14 "github.com/iotexproject/iotex-core/ioctl/config" 15 "github.com/iotexproject/iotex-core/ioctl/util" 16 ) 17 18 // Multi-language support 19 var ( 20 _depositCmdShorts = map[config.Language]string{ 21 config.English: "Deposit rewards to rewarding fund", 22 config.Chinese: "将奖励存入奖励基金", 23 } 24 _depositCmdUses = map[config.Language]string{ 25 config.English: "deposit AMOUNT_IOTX [DATA] [-s SIGNER] [-n NONCE] [-l GAS_LIMIT] [-p GAS_PRICE] [-P PASSWORD] [-y]", 26 config.Chinese: "deposit IOTX数量 [数据] [-s 签署人] [-n NONCE] [-l GAS限制] [-p GAS价格] [-P 密码] [-y]", 27 } 28 ) 29 30 // NewActionDepositCmd represents the action deposit command 31 func NewActionDepositCmd(client ioctl.Client) *cobra.Command { 32 use, _ := client.SelectTranslation(_depositCmdUses) 33 short, _ := client.SelectTranslation(_depositCmdShorts) 34 35 cmd := &cobra.Command{ 36 Use: use, 37 Short: short, 38 Args: cobra.RangeArgs(1, 2), 39 RunE: func(cmd *cobra.Command, args []string) error { 40 cmd.SilenceUsage = true 41 amount, err := util.StringToRau(args[0], util.IotxDecimalNum) 42 if err != nil { 43 return errors.Wrap(err, "invalid amount") 44 } 45 payload := make([]byte, 0) 46 if len(args) == 2 { 47 payload = []byte(args[1]) 48 } 49 gasPrice, signer, password, nonce, gasLimit, assumeYes, err := GetWriteCommandFlag(cmd) 50 if err != nil { 51 return err 52 } 53 sender, err := Signer(client, signer) 54 if err != nil { 55 return errors.Wrap(err, "failed to get signer address") 56 } 57 if gasLimit == 0 { 58 gasLimit = action.DepositToRewardingFundBaseGas + 59 action.DepositToRewardingFundGasPerByte*uint64(len(payload)) 60 } 61 gasPriceRau, err := gasPriceInRau(client, gasPrice) 62 if err != nil { 63 return errors.Wrap(err, "failed to get gasPriceRau") 64 } 65 nonce, err = checkNonce(client, nonce, sender) 66 if err != nil { 67 return errors.Wrap(err, "failed to get nonce") 68 } 69 act := (&action.DepositToRewardingFundBuilder{}).SetAmount(amount).SetData(payload).Build() 70 71 return SendAction( 72 client, 73 cmd, 74 (&action.EnvelopeBuilder{}).SetNonce(nonce). 75 SetGasPrice(gasPriceRau). 76 SetGasLimit(gasLimit). 77 SetAction(&act).Build(), 78 sender, 79 password, 80 nonce, 81 assumeYes, 82 ) 83 }, 84 } 85 RegisterWriteCommand(client, cmd) 86 return cmd 87 }