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