From 8579e1be264422f05f7a021bb192ea8b293e56db Mon Sep 17 00:00:00 2001 From: bruno Date: Mon, 3 Jan 2022 14:51:16 -0800 Subject: [PATCH] Makes it possible to add an account to a wallet based on its index. --- cmd/add.go | 15 ++++++++++----- cmd/root.go | 1 + cmd/wallet.go | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cmd/add.go b/cmd/add.go index fddb527..cad9614 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -19,12 +19,17 @@ var addCmd = &cobra.Command{ wi := wallets[walletIndex] wi.init() var a *wallet.Account - for { - var err error - a, err = wi.w.NewAccount(nil) + var err error + if (walletAccountIndex > 0) { + a, err = wi.w.NewAccount(&walletAccountIndex) fatalIf(err) - if _, ok := wi.Accounts[a.Address()]; !ok { - break + } else { + for { + a, err = wi.w.NewAccount(nil) + fatalIf(err) + if _, ok := wi.Accounts[a.Address()]; !ok { + break + } } } wi.Accounts[a.Address()] = a.Index() diff --git a/cmd/root.go b/cmd/root.go index d856bff..65f374d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -45,6 +45,7 @@ func init() { rootCmd.PersistentFlags().StringVarP(&walletAccount, "account", "a", "", "Account to operate on") rootCmd.PersistentFlags().StringVarP(&rpcURL, "rpc", "r", "https://mynano.ninja/api/node", "RPC endpoint URL") rootCmd.PersistentFlags().StringVarP(&rpcWorkURL, "rpc-work", "s", "http://[::1]:7076", "RPC endpoint URL for work generation") + rootCmd.PersistentFlags().Uint32VarP(&walletAccountIndex, "account_index", "i", 0, "Index of the account within the wallet to use. Not all operations support it yet") } // initConfig reads in config file and ENV variables if set. diff --git a/cmd/wallet.go b/cmd/wallet.go index df963ba..b1eee4e 100644 --- a/cmd/wallet.go +++ b/cmd/wallet.go @@ -20,6 +20,7 @@ type walletInfo struct { var wallets []*walletInfo var walletIndex int var walletAccount string +var walletAccountIndex uint32 func initWallets() { v := viper.GetStringMap("wallets")