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 listAssetsCmd.PersistentFlags().StringVar(&assetID, "id", "", "ID of asset")
31 var createAssetCmd = &cobra.Command{
32 Use: "create-asset <alias> <xpub(s)>",
33 Short: "Create an asset",
34 Args: cobra.MinimumNArgs(2),
35 Run: func(cmd *cobra.Command, args []string) {
39 for _, x := range args[1:] {
40 xpub := chainkd.XPub{}
41 if err := xpub.UnmarshalText([]byte(x)); err != nil {
42 jww.ERROR.Println(err)
43 os.Exit(util.ErrLocalExe)
45 ins.RootXPubs = append(ins.RootXPubs, xpub)
48 ins.Quorum = assetQuorum
50 ins.AccessToken = assetToken
52 if len(assetDefiniton) != 0 {
53 definition := strings.Split(assetDefiniton, ":")
54 if len(definition) != 2 {
55 jww.ERROR.Println("Invalid definition")
56 os.Exit(util.ErrLocalExe)
58 ins.Definition = map[string]interface{}{definition[0]: definition[1]}
61 data, exitCode := util.ClientCall("/create-asset", &ins)
62 if exitCode != util.Success {
70 var listAssetsCmd = &cobra.Command{
72 Short: "List the existing assets",
74 Run: func(cmd *cobra.Command, args []string) {
79 data, exitCode := util.ClientCall("/list-assets", &filter)
80 if exitCode != util.Success {
88 var updateAssetAliasCmd = &cobra.Command{
89 Use: "update-asset-alias <oldAlias> <newAlias>",
90 Short: "Update the asset alias",
91 Args: cobra.ExactArgs(2),
92 Run: func(cmd *cobra.Command, args []string) {
93 var updateAlias = struct {
94 OldAlias string `json:"old_alias"`
95 NewAlias string `json:"new_alias"`
96 }{OldAlias: args[0], NewAlias: args[1]}
98 if _, exitCode := util.ClientCall("/update-asset-alias", &updateAlias); exitCode != util.Success {
102 jww.FEEDBACK.Println("Successfully update asset alias")