Skip to content

Commit

Permalink
Merge pull request #4 from bruno-kakele/add-account-by-index
Browse files Browse the repository at this point in the history
Makes it possible to add an account to a wallet based on its index.
  • Loading branch information
bruno-viva authored Jan 3, 2022
2 parents 272ec69 + 8579e1b commit bcfe332
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
15 changes: 10 additions & 5 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions cmd/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit bcfe332

Please sign in to comment.