8 "github.com/spf13/cobra"
9 jww "github.com/spf13/jwalterweatherman"
11 "github.com/bytom/crypto/ed25519/chainkd"
15 createAccountCmd.PersistentFlags().IntVarP(&accountQuorum, "quorom", "q", 1, "quorum must be greater than 0 and less than or equal to the number of signers")
16 createAccountCmd.PersistentFlags().StringVarP(&accountToken, "access", "a", "", "access token")
17 createAccountCmd.PersistentFlags().StringVarP(&accountTags, "tags", "t", "", "tags")
19 updateAccountTagsCmd.PersistentFlags().StringVarP(&accountUpdateTags, "tags", "t", "", "tags to add, delete or update")
21 listAccountsCmd.PersistentFlags().StringVar(&accountID, "id", "", "ID of account")
23 listUnspentOutputsCmd.PersistentFlags().StringVar(&outputID, "id", "", "ID of unspent output")
31 accountUpdateTags = ""
35 var createAccountCmd = &cobra.Command{
36 Use: "create-account <alias> <xpub(s)>",
37 Short: "Create an account",
38 Args: cobra.MinimumNArgs(2),
39 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)
48 ins.RootXPubs = append(ins.RootXPubs, xpub)
51 ins.Quorum = accountQuorum
53 if len(accountTags) != 0 {
54 tags := strings.Split(accountTags, ":")
56 jww.ERROR.Println("Invalid tags")
59 ins.Tags = map[string]interface{}{tags[0]: tags[1]}
62 ins.AccessToken = accountToken
64 data, exitCode := clientCall("/create-account", &ins)
65 if exitCode != Success {
73 var listAccountsCmd = &cobra.Command{
75 Short: "List the existing accounts",
77 Run: func(cmd *cobra.Command, args []string) {
82 data, exitCode := clientCall("/list-accounts", &filter)
83 if exitCode != Success {
91 var deleteAccountCmd = &cobra.Command{
92 Use: "delete-account <accountID|alias>",
93 Short: "Delete the existing account",
94 Args: cobra.ExactArgs(1),
95 Run: func(cmd *cobra.Command, args []string) {
96 accountInfo := &struct {
97 AccountInfo string `json:"account_info"`
98 }{AccountInfo: args[0]}
100 if _, exitCode := clientCall("/delete-account", accountInfo); exitCode != Success {
104 jww.FEEDBACK.Println("Successfully delete account")
108 var updateAccountTagsCmd = &cobra.Command{
109 Use: "update-account-tags <accountID|alias>",
110 Short: "Update the account tags",
111 Args: cobra.ExactArgs(1),
112 PreRun: func(cmd *cobra.Command, args []string) {
113 cmd.MarkFlagRequired("tags")
115 Run: func(cmd *cobra.Command, args []string) {
116 var updateTag = struct {
117 AccountInfo string `json:"account_info"`
118 Tags map[string]interface{} `json:"tags"`
121 if len(accountUpdateTags) != 0 {
122 tags := strings.Split(accountUpdateTags, ":")
124 jww.ERROR.Println("Invalid tags")
127 updateTag.Tags = map[string]interface{}{tags[0]: tags[1]}
130 updateTag.AccountInfo = args[0]
132 if _, exitCode := clientCall("/update-account-tags", &updateTag); exitCode != Success {
136 jww.FEEDBACK.Println("Successfully update account tags")
140 var createAccountReceiverCmd = &cobra.Command{
141 Use: "create-account-receiver <accountID | alias>",
142 Short: "Create an account receiver control program",
143 Args: cobra.ExactArgs(1),
144 Run: func(cmd *cobra.Command, args []string) {
146 AccountInfo string `json:"account_info"`
147 ExpiresAt time.Time `json:"expires_at,omitempty"`
148 }{AccountInfo: args[0]}
150 data, exitCode := clientCall("/create-account-receiver", &ins)
151 if exitCode != Success {
159 var createAccountAddressCmd = &cobra.Command{
160 Use: "create-account-address <accountID | alias>",
161 Short: "Create an account address",
162 Args: cobra.ExactArgs(1),
163 Run: func(cmd *cobra.Command, args []string) {
165 AccountInfo string `json:"account_info"`
166 ExpiresAt time.Time `json:"expires_at,omitempty"`
167 }{AccountInfo: args[0]}
169 data, exitCode := clientCall("/create-account-address", &ins)
170 if exitCode != Success {
178 var listBalancesCmd = &cobra.Command{
179 Use: "list-balances",
180 Short: "List the accounts balances",
182 Run: func(cmd *cobra.Command, args []string) {
183 data, exitCode := clientCall("/list-balances")
184 if exitCode != Success {
192 var listUnspentOutputsCmd = &cobra.Command{
193 Use: "list-unspent-outputs",
194 Short: "List the accounts unspent outputs",
196 Run: func(cmd *cobra.Command, args []string) {
198 ID string `json:"id"`
201 data, exitCode := clientCall("/list-unspent-outputs", &filter)
202 if exitCode != Success {