github.com/iotexproject/iotex-core@v1.14.1-rc1/ioctl/newcmd/did/didderegister.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 did 7 8 import ( 9 "math/big" 10 11 "github.com/pkg/errors" 12 "github.com/spf13/cobra" 13 14 "github.com/iotexproject/iotex-core/ioctl" 15 "github.com/iotexproject/iotex-core/ioctl/config" 16 "github.com/iotexproject/iotex-core/ioctl/newcmd/action" 17 ) 18 19 // Multi-language support 20 var ( 21 _deregisterCmdUses = map[config.Language]string{ 22 config.English: "deregister (CONTRACT_ADDRESS|ALIAS) [-s SIGNER] [-n NONCE] [-l GAS_LIMIT] [-p GAS_PRICE] [-P PASSWORD] [-y]", 23 config.Chinese: "deregister (合约地址|别名) IOTX数量 [-s 签署人] [-n NONCE] [-l GAS限制] [-P GAS价格] [-P 密码] [-y]", 24 } 25 _deregisterCmdShorts = map[config.Language]string{ 26 config.English: "Deregister DID on IoTeX blockchain", 27 config.Chinese: "在IoTeX链上注销DID", 28 } 29 ) 30 31 // NewDeregisterCmd represents the contract invoke deregister command 32 func NewDeregisterCmd(client ioctl.Client) *cobra.Command { 33 use, _ := client.SelectTranslation(_deregisterCmdUses) 34 short, _ := client.SelectTranslation(_deregisterCmdShorts) 35 36 cmd := &cobra.Command{ 37 Use: use, 38 Short: short, 39 Args: cobra.ExactArgs(1), 40 RunE: func(cmd *cobra.Command, args []string) error { 41 cmd.SilenceUsage = true 42 contract, err := client.Address(args[0]) 43 if err != nil { 44 return errors.Wrap(err, "failed to get contract address") 45 } 46 bytecode, err := _didABI.Pack(_deregisterDIDName) 47 if err != nil { 48 return errors.Wrap(err, "invalid bytecode") 49 } 50 gasPrice, signer, password, nonce, gasLimit, assumeYes, err := action.GetWriteCommandFlag(cmd) 51 if err != nil { 52 return err 53 } 54 return action.Execute(client, cmd, contract, big.NewInt(0), bytecode, gasPrice, signer, password, nonce, gasLimit, assumeYes) 55 }, 56 } 57 action.RegisterWriteCommand(client, cmd) 58 return cmd 59 }