7 "github.com/spf13/cobra"
8 jww "github.com/spf13/jwalterweatherman"
10 "github.com/vapor/crypto/ed25519/chainkd"
11 "github.com/vapor/util"
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")
18 listAccountsCmd.PersistentFlags().StringVar(&accountID, "id", "", "account ID")
19 listAccountsCmd.PersistentFlags().StringVar(&accountAlias, "alias", "", "account alias")
21 listAddressesCmd.PersistentFlags().StringVar(&accountID, "id", "", "account ID")
22 listAddressesCmd.PersistentFlags().StringVar(&accountAlias, "alias", "", "account alias")
24 listUnspentOutputsCmd.PersistentFlags().StringVar(&outputID, "id", "", "ID of unspent output")
25 listUnspentOutputsCmd.PersistentFlags().BoolVar(&smartContract, "contract", false, "list smart contract unspent outputs")
37 var createAccountCmd = &cobra.Command{
38 Use: "create-account <alias> <xpub(s)>",
39 Short: "Create an account",
40 Args: cobra.MinimumNArgs(2),
41 Run: func(cmd *cobra.Command, args []string) {
44 for _, x := range args[1:] {
45 xpub := chainkd.XPub{}
46 if err := xpub.UnmarshalText([]byte(x)); err != nil {
47 jww.ERROR.Println(err)
48 os.Exit(util.ErrLocalExe)
50 ins.RootXPubs = append(ins.RootXPubs, xpub)
53 ins.Quorum = accountQuorum
55 ins.AccessToken = accountToken
57 data, exitCode := util.ClientCall("/create-account", &ins)
58 if exitCode != util.Success {
66 var listAccountsCmd = &cobra.Command{
68 Short: "List the existing accounts",
70 Run: func(cmd *cobra.Command, args []string) {
73 Alias string `json:"alias"`
74 }{ID: accountID, Alias: accountAlias}
76 data, exitCode := util.ClientCall("/list-accounts", &filter)
77 if exitCode != util.Success {
85 var deleteAccountCmd = &cobra.Command{
86 Use: "delete-account <accountID|alias>",
87 Short: "Delete the existing account",
88 Args: cobra.ExactArgs(1),
89 Run: func(cmd *cobra.Command, args []string) {
90 accountInfo := &struct {
91 AccountInfo string `json:"account_info"`
92 }{AccountInfo: args[0]}
94 if _, exitCode := util.ClientCall("/delete-account", accountInfo); exitCode != util.Success {
98 jww.FEEDBACK.Println("Successfully delete account")
102 var createAccountReceiverCmd = &cobra.Command{
103 Use: "create-account-receiver <accountAlias> [accountID]",
104 Short: "Create an account receiver",
105 Args: cobra.RangeArgs(1, 2),
106 Run: func(cmd *cobra.Command, args []string) {
108 AccountID string `json:"account_id"`
109 AccountAlias string `json:"account_alias"`
110 }{AccountAlias: args[0]}
113 ins.AccountID = args[1]
116 data, exitCode := util.ClientCall("/create-account-receiver", &ins)
117 if exitCode != util.Success {
125 var listAddressesCmd = &cobra.Command{
126 Use: "list-addresses",
127 Short: "List the account addresses",
129 Run: func(cmd *cobra.Command, args []string) {
131 AccountID string `json:"account_id"`
132 AccountAlias string `json:"account_alias"`
133 }{AccountID: accountID, AccountAlias: accountAlias}
135 data, exitCode := util.ClientCall("/list-addresses", &ins)
136 if exitCode != util.Success {
144 var validateAddressCmd = &cobra.Command{
145 Use: "validate-address <address>",
146 Short: "validate the account addresses",
147 Args: cobra.ExactArgs(1),
148 Run: func(cmd *cobra.Command, args []string) {
150 Address string `json:"address"`
153 data, exitCode := util.ClientCall("/validate-address", &ins)
154 if exitCode != util.Success {
162 var listPubKeysCmd = &cobra.Command{
163 Use: "list-pubkeys <accountInfo> [publicKey]",
164 Short: "list the account pubkeys",
165 Args: cobra.RangeArgs(1, 2),
166 Run: func(cmd *cobra.Command, args []string) {
168 AccountID string `json:"account_id"`
169 AccountAlias string `json:"account_alias"`
170 PublicKey string `json:"public_key"`
173 if len(args[0]) == 13 && strings.HasPrefix(args[0], "0") {
174 ins.AccountID = args[0]
176 ins.AccountAlias = args[0]
180 ins.PublicKey = args[1]
183 data, exitCode := util.ClientCall("/list-pubkeys", &ins)
184 if exitCode != util.Success {
192 var listBalancesCmd = &cobra.Command{
193 Use: "list-balances",
194 Short: "List the accounts balances",
196 Run: func(cmd *cobra.Command, args []string) {
197 data, exitCode := util.ClientCall("/list-balances")
198 if exitCode != util.Success {
206 var listUnspentOutputsCmd = &cobra.Command{
207 Use: "list-unspent-outputs",
208 Short: "List the accounts unspent outputs",
210 Run: func(cmd *cobra.Command, args []string) {
212 ID string `json:"id"`
213 SmartContract bool `json:"smart_contract"`
214 }{ID: outputID, SmartContract: smartContract}
216 data, exitCode := util.ClientCall("/list-unspent-outputs", &filter)
217 if exitCode != util.Success {