File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,13 +20,16 @@ var createCmd = &cobra.Command{
2020 Args : cobra .MaximumNArgs (1 ),
2121 Run : func (_ * cobra.Command , args []string ) {
2222 cfg := config .Global ()
23- name := "account-1"
24- if len (args ) > 0 {
23+
24+ var name string
25+ switch len (args ) {
26+ case 0 :
27+ name = generateAccountName (cfg )
28+ default :
2529 name = args [0 ]
30+ checkAccountExists (cfg , name )
2631 }
2732
28- checkAccountExists (cfg , name )
29-
3033 af , err := wallet .Load (accKind )
3134 cobra .CheckErr (err )
3235
@@ -50,6 +53,19 @@ var createCmd = &cobra.Command{
5053 },
5154}
5255
56+ func generateAccountName (cfg * config.Config ) string {
57+ for i := 1 ; ; i ++ {
58+ name := fmt .Sprintf ("account_%d" , i )
59+ if _ , ok := cfg .Wallet .All [name ]; ok {
60+ continue
61+ }
62+ if _ , ok := cfg .AddressBook .All [name ]; ok {
63+ continue
64+ }
65+ return name
66+ }
67+ }
68+
5369func checkAccountExists (cfg * config.Config , name string ) {
5470 if _ , exists := cfg .Wallet .All [name ]; exists {
5571 cobra .CheckErr (fmt .Errorf ("account '%s' already exists in the wallet" , name ))
You can’t perform that action at this time.
0 commit comments