OSDN Git Service

add issue program error (#1281)
[bytom/bytom.git] / cmd / bytomcli / commands / asset.go
old mode 100755 (executable)
new mode 100644 (file)
index 8f14147..16cc2c3
@@ -7,6 +7,7 @@ import (
        "github.com/spf13/cobra"
        jww "github.com/spf13/jwalterweatherman"
 
+       "encoding/hex"
        "github.com/bytom/crypto/ed25519/chainkd"
        "github.com/bytom/util"
 )
@@ -14,10 +15,8 @@ import (
 func init() {
        createAssetCmd.PersistentFlags().IntVarP(&assetQuorum, "quorom", "q", 1, "quorum must be greater than 0 and less than or equal to the number of signers")
        createAssetCmd.PersistentFlags().StringVarP(&assetToken, "access", "a", "", "access token")
-       createAssetCmd.PersistentFlags().StringVarP(&assetTags, "tags", "t", "", "tags")
        createAssetCmd.PersistentFlags().StringVarP(&assetDefiniton, "definition", "d", "", "definition for the asset")
-
-       updateAssetTagsCmd.PersistentFlags().StringVarP(&assetUpdateTags, "tags", "t", "", "tags to add, delete or update")
+       createAssetCmd.PersistentFlags().StringVarP(&issuanceProgram, "issueprogram", "i", "", "issue program for the asset")
 
        listAssetsCmd.PersistentFlags().StringVar(&assetID, "id", "", "ID of asset")
 }
@@ -26,15 +25,14 @@ var (
        assetID         = ""
        assetQuorum     = 1
        assetToken      = ""
-       assetTags       = ""
        assetDefiniton  = ""
-       assetUpdateTags = ""
+       issuanceProgram = ""
 )
 
 var createAssetCmd = &cobra.Command{
        Use:   "create-asset <alias> <xpub(s)>",
        Short: "Create an asset",
-       Args:  cobra.MinimumNArgs(2),
+       Args:  cobra.RangeArgs(1, 5),
        Run: func(cmd *cobra.Command, args []string) {
 
                var ins assetIns
@@ -52,15 +50,6 @@ var createAssetCmd = &cobra.Command{
                ins.Alias = args[0]
                ins.AccessToken = assetToken
 
-               if len(assetTags) != 0 {
-                       tags := strings.Split(assetTags, ":")
-                       if len(tags) != 2 {
-                               jww.ERROR.Println("Invalid tags")
-                               os.Exit(util.ErrLocalExe)
-                       }
-                       ins.Tags = map[string]interface{}{tags[0]: tags[1]}
-               }
-
                if len(assetDefiniton) != 0 {
                        definition := strings.Split(assetDefiniton, ":")
                        if len(definition) != 2 {
@@ -70,6 +59,15 @@ var createAssetCmd = &cobra.Command{
                        ins.Definition = map[string]interface{}{definition[0]: definition[1]}
                }
 
+               if issuanceProgram != "" {
+                       issueProg, err := hex.DecodeString(issuanceProgram)
+                       if err != nil {
+                               jww.ERROR.Println(err)
+                               os.Exit(util.ErrLocalExe)
+                       }
+                       ins.IssuanceProgram = issueProg
+               }
+
                data, exitCode := util.ClientCall("/create-asset", &ins)
                if exitCode != util.Success {
                        os.Exit(exitCode)
@@ -79,64 +77,51 @@ var createAssetCmd = &cobra.Command{
        },
 }
 
-var listAssetsCmd = &cobra.Command{
-       Use:   "list-assets",
-       Short: "List the existing assets",
-       Args:  cobra.NoArgs,
+var getAssetCmd = &cobra.Command{
+       Use:   "get-asset <assetID>",
+       Short: "get asset by assetID",
+       Args:  cobra.ExactArgs(1),
        Run: func(cmd *cobra.Command, args []string) {
                filter := struct {
                        ID string `json:"id"`
-               }{ID: assetID}
+               }{ID: args[0]}
 
-               data, exitCode := util.ClientCall("/list-assets", &filter)
+               data, exitCode := util.ClientCall("/get-asset", &filter)
                if exitCode != util.Success {
                        os.Exit(exitCode)
                }
 
-               printJSONList(data)
+               printJSON(data)
        },
 }
 
-var updateAssetTagsCmd = &cobra.Command{
-       Use:   "update-asset-tags <assetID|alias>",
-       Short: "Update the asset tags",
-       Args:  cobra.ExactArgs(1),
-       PreRun: func(cmd *cobra.Command, args []string) {
-               cmd.MarkFlagRequired("tags")
-       },
+var listAssetsCmd = &cobra.Command{
+       Use:   "list-assets",
+       Short: "List the existing assets",
+       Args:  cobra.NoArgs,
        Run: func(cmd *cobra.Command, args []string) {
-               var updateTag = struct {
-                       AssetInfo string                 `json:"asset_info"`
-                       Tags      map[string]interface{} `json:"tags"`
-               }{}
-
-               if len(assetUpdateTags) != 0 {
-                       tags := strings.Split(assetUpdateTags, ":")
-                       if len(tags) != 2 {
-                               jww.ERROR.Println("Invalid tags")
-                               os.Exit(util.ErrLocalExe)
-                       }
-                       updateTag.Tags = map[string]interface{}{tags[0]: tags[1]}
-               }
+               filter := struct {
+                       ID string `json:"id"`
+               }{ID: assetID}
 
-               updateTag.AssetInfo = args[0]
-               if _, exitCode := util.ClientCall("/update-asset-tags", &updateTag); exitCode != util.Success {
+               data, exitCode := util.ClientCall("/list-assets", &filter)
+               if exitCode != util.Success {
                        os.Exit(exitCode)
                }
 
-               jww.FEEDBACK.Println("Successfully update asset tags")
+               printJSONList(data)
        },
 }
 
 var updateAssetAliasCmd = &cobra.Command{
-       Use:   "update-asset-alias <oldAlias> <newAlias>",
+       Use:   "update-asset-alias <assetID> <newAlias>",
        Short: "Update the asset alias",
        Args:  cobra.ExactArgs(2),
        Run: func(cmd *cobra.Command, args []string) {
                var updateAlias = struct {
-                       OldAlias string `json:"old_alias"`
-                       NewAlias string `json:"new_alias"`
-               }{OldAlias: args[0], NewAlias: args[1]}
+                       ID       string `json:"id"`
+                       NewAlias string `json:"alias"`
+               }{ID: args[0], NewAlias: args[1]}
 
                if _, exitCode := util.ClientCall("/update-asset-alias", &updateAlias); exitCode != util.Success {
                        os.Exit(exitCode)