7 "github.com/spf13/cobra"
8 jww "github.com/spf13/jwalterweatherman"
10 "github.com/bytom/crypto/ed25519/chainkd"
11 "github.com/bytom/util"
15 createAssetCmd.PersistentFlags().IntVarP(&assetQuorum, "quorom", "q", 1, "quorum must be greater than 0 and less than or equal to the number of signers")
16 createAssetCmd.PersistentFlags().StringVarP(&assetToken, "access", "a", "", "access token")
17 createAssetCmd.PersistentFlags().StringVarP(&assetTags, "tags", "t", "", "tags")
18 createAssetCmd.PersistentFlags().StringVarP(&assetDefiniton, "definition", "d", "", "definition for the asset")
20 updateAssetTagsCmd.PersistentFlags().StringVarP(&assetUpdateTags, "tags", "t", "", "tags to add, delete or update")
22 listAssetsCmd.PersistentFlags().StringVar(&assetID, "id", "", "ID of asset")
34 var createAssetCmd = &cobra.Command{
35 Use: "create-asset <alias> <xpub(s)>",
36 Short: "Create an asset",
37 Args: cobra.MinimumNArgs(2),
38 Run: func(cmd *cobra.Command, args []string) {
42 for _, x := range args[1:] {
43 xpub := chainkd.XPub{}
44 if err := xpub.UnmarshalText([]byte(x)); err != nil {
45 jww.ERROR.Println(err)
46 os.Exit(util.ErrLocalExe)
48 ins.RootXPubs = append(ins.RootXPubs, xpub)
51 ins.Quorum = assetQuorum
53 ins.AccessToken = assetToken
55 if len(assetTags) != 0 {
56 tags := strings.Split(assetTags, ":")
58 jww.ERROR.Println("Invalid tags")
59 os.Exit(util.ErrLocalExe)
61 ins.Tags = map[string]interface{}{tags[0]: tags[1]}
64 if len(assetDefiniton) != 0 {
65 definition := strings.Split(assetDefiniton, ":")
66 if len(definition) != 2 {
67 jww.ERROR.Println("Invalid definition")
68 os.Exit(util.ErrLocalExe)
70 ins.Definition = map[string]interface{}{definition[0]: definition[1]}
73 data, exitCode := util.ClientCall("/create-asset", &ins)
74 if exitCode != util.Success {
82 var listAssetsCmd = &cobra.Command{
84 Short: "List the existing assets",
86 Run: func(cmd *cobra.Command, args []string) {
91 data, exitCode := util.ClientCall("/list-assets", &filter)
92 if exitCode != util.Success {
100 var updateAssetTagsCmd = &cobra.Command{
101 Use: "update-asset-tags <assetID|alias>",
102 Short: "Update the asset tags",
103 Args: cobra.ExactArgs(1),
104 PreRun: func(cmd *cobra.Command, args []string) {
105 cmd.MarkFlagRequired("tags")
107 Run: func(cmd *cobra.Command, args []string) {
108 var updateTag = struct {
109 AssetInfo string `json:"asset_info"`
110 Tags map[string]interface{} `json:"tags"`
113 if len(assetUpdateTags) != 0 {
114 tags := strings.Split(assetUpdateTags, ":")
116 jww.ERROR.Println("Invalid tags")
117 os.Exit(util.ErrLocalExe)
119 updateTag.Tags = map[string]interface{}{tags[0]: tags[1]}
122 updateTag.AssetInfo = args[0]
123 if _, exitCode := util.ClientCall("/update-asset-tags", &updateTag); exitCode != util.Success {
127 jww.FEEDBACK.Println("Successfully update asset tags")