7 "github.com/spf13/cobra"
8 jww "github.com/spf13/jwalterweatherman"
11 "github.com/bytom/vapor/crypto/ed25519/chainkd"
12 "github.com/bytom/vapor/util"
16 createAssetCmd.PersistentFlags().IntVarP(&assetQuorum, "quorom", "q", 1, "quorum must be greater than 0 and less than or equal to the number of signers")
17 createAssetCmd.PersistentFlags().StringVarP(&assetToken, "access", "a", "", "access token")
18 createAssetCmd.PersistentFlags().StringVarP(&assetDefiniton, "definition", "d", "", "definition for the asset")
19 createAssetCmd.PersistentFlags().StringVarP(&issuanceProgram, "issueprogram", "i", "", "issue program for the asset")
21 listAssetsCmd.PersistentFlags().StringVar(&assetID, "id", "", "ID of asset")
32 var createAssetCmd = &cobra.Command{
33 Use: "create-asset <alias> <xpub(s)>",
34 Short: "Create an asset",
35 Args: cobra.RangeArgs(1, 5),
36 Run: func(cmd *cobra.Command, args []string) {
40 for _, x := range args[1:] {
41 xpub := chainkd.XPub{}
42 if err := xpub.UnmarshalText([]byte(x)); err != nil {
43 jww.ERROR.Println(err)
44 os.Exit(util.ErrLocalExe)
46 ins.RootXPubs = append(ins.RootXPubs, xpub)
49 ins.Quorum = assetQuorum
51 ins.AccessToken = assetToken
53 if len(assetDefiniton) != 0 {
54 definition := strings.Split(assetDefiniton, ":")
55 if len(definition) != 2 {
56 jww.ERROR.Println("Invalid definition")
57 os.Exit(util.ErrLocalExe)
59 ins.Definition = map[string]interface{}{definition[0]: definition[1]}
62 if issuanceProgram != "" {
63 issueProg, err := hex.DecodeString(issuanceProgram)
65 jww.ERROR.Println(err)
66 os.Exit(util.ErrLocalExe)
68 ins.IssuanceProgram = issueProg
71 data, exitCode := util.ClientCall("/create-asset", &ins)
72 if exitCode != util.Success {
80 var getAssetCmd = &cobra.Command{
81 Use: "get-asset <assetID>",
82 Short: "get asset by assetID",
83 Args: cobra.ExactArgs(1),
84 Run: func(cmd *cobra.Command, args []string) {
89 data, exitCode := util.ClientCall("/get-asset", &filter)
90 if exitCode != util.Success {
98 var listAssetsCmd = &cobra.Command{
100 Short: "List the existing assets",
102 Run: func(cmd *cobra.Command, args []string) {
104 ID string `json:"id"`
107 data, exitCode := util.ClientCall("/list-assets", &filter)
108 if exitCode != util.Success {
116 var updateAssetAliasCmd = &cobra.Command{
117 Use: "update-asset-alias <assetID> <newAlias>",
118 Short: "Update the asset alias",
119 Args: cobra.ExactArgs(2),
120 Run: func(cmd *cobra.Command, args []string) {
121 var updateAlias = struct {
122 ID string `json:"id"`
123 NewAlias string `json:"alias"`
124 }{ID: args[0], NewAlias: args[1]}
126 if _, exitCode := util.ClientCall("/update-asset-alias", &updateAlias); exitCode != util.Success {
130 jww.FEEDBACK.Println("Successfully update asset alias")