github.com/iotexproject/iotex-core@v1.14.1-rc1/ioctl/newcmd/did/did.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  	"strings"
    10  
    11  	"github.com/ethereum/go-ethereum/accounts/abi"
    12  	"github.com/spf13/cobra"
    13  
    14  	"github.com/iotexproject/iotex-core/ioctl"
    15  	"github.com/iotexproject/iotex-core/ioctl/config"
    16  )
    17  
    18  // Multi-language support
    19  var (
    20  	_dIDCmdShorts = map[config.Language]string{
    21  		config.English: "Manage Decentralized Identity of IoTeX blockchain",
    22  		config.Chinese: "管理IoTeX区块链上的去中心化数字身份",
    23  	}
    24  	// _didABI is the interface of the abi encoding of did
    25  	_didABI abi.ABI
    26  	err     error
    27  )
    28  
    29  const (
    30  	_registerDIDName   = "registerDID"
    31  	_getHashName       = "getHash"
    32  	_getURIName        = "getURI"
    33  	_updateDIDName     = "updateDID"
    34  	_deregisterDIDName = "deregisterDID"
    35  	// DIDABI is the did abi
    36  	DIDABI = `[{"constant": false,"inputs": [],"name": "deregisterDID","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"},{"constant": true,"inputs": [{"internalType": "bytes","name": "did","type": "bytes"}],"name": "getHash","outputs": [{"internalType": "bytes32","name": "","type": "bytes32"}],"payable": false,"stateMutability": "view","type": "function"},   {"constant": true,"inputs": [{"internalType": "bytes","name": "did","type": "bytes"}],"name": "getURI","outputs": [{"internalType": "bytes","name": "","type": "bytes"}],"payable": false,"stateMutability": "view","type": "function"},{"constant": false,"inputs": [{"internalType": "bytes32","name": "h","type": "bytes32"},{"internalType": "bytes","name": "uri","type": "bytes"}],"name": "registerDID","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"},{"constant": false,"inputs": [{"internalType": "bytes32","name": "h","type": "bytes32"},{"internalType": "bytes","name": "uri","type": "bytes"}],"name": "updateDID","outputs": [],"payable": false,"stateMutability": "nonpayable","type": "function"}]`
    37  )
    38  
    39  func init() {
    40  	_didABI, err = abi.JSON(strings.NewReader(DIDABI))
    41  	if err != nil {
    42  		panic(err)
    43  	}
    44  }
    45  
    46  // NewDidCmd represents the did command
    47  func NewDidCmd(client ioctl.Client) *cobra.Command {
    48  	short, _ := client.SelectTranslation(_dIDCmdShorts)
    49  	cmd := &cobra.Command{
    50  		Use:   "did",
    51  		Short: short,
    52  	}
    53  	cmd.AddCommand(NewDidRegisterCmd(client))
    54  	client.SetEndpointWithFlag(cmd.PersistentFlags().StringVar)
    55  	client.SetInsecureWithFlag(cmd.PersistentFlags().BoolVar)
    56  	return cmd
    57  }