github.com/iotexproject/iotex-core@v1.14.1-rc1/ioctl/newcmd/alias/alias.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 alias 7 8 import ( 9 "github.com/ethereum/go-ethereum/common" 10 "github.com/iotexproject/iotex-address/address" 11 "github.com/spf13/cobra" 12 13 "github.com/iotexproject/iotex-core/ioctl" 14 "github.com/iotexproject/iotex-core/ioctl/config" 15 "github.com/iotexproject/iotex-core/pkg/util/addrutil" 16 ) 17 18 // Multi-language support 19 var ( 20 _aliasCmdShorts = map[config.Language]string{ 21 config.English: "Manage aliases of IoTeX addresses", 22 config.Chinese: "管理IoTeX的地址别名", 23 } 24 ) 25 26 // NewAliasCmd represents the alias command 27 func NewAliasCmd(client ioctl.Client) *cobra.Command { 28 aliasShorts, _ := client.SelectTranslation(_aliasCmdShorts) 29 30 ac := &cobra.Command{ 31 Use: "alias", 32 Short: aliasShorts, 33 } 34 35 ac.AddCommand(NewAliasImport(client)) 36 ac.AddCommand(NewAliasExport(client)) 37 ac.AddCommand(NewAliasRemove(client)) 38 39 return ac 40 } 41 42 // IOAddress returns the address in IoTeX address format 43 func IOAddress(client ioctl.Client, in string) (address.Address, error) { 44 addr, err := client.Address(in) 45 if err != nil { 46 return nil, err 47 } 48 return address.FromString(addr) 49 } 50 51 // EtherAddress returns the address in ether format 52 func EtherAddress(client ioctl.Client, in string) (common.Address, error) { 53 addr, err := client.Address(in) 54 if err != nil { 55 return common.Address{}, err 56 } 57 return addrutil.IoAddrToEvmAddr(addr) 58 }