accounts, internal/ethapi: use common Accounts method (#18428)

* accounts/mananger, internal/ethapi/api: Add new function AllAccounts on account manager to remove the duplication code on getting all wallets accounts

* Rename to Accounts

* Rename to AllAccounts
This commit is contained in:
Roc Yu
2019-08-08 17:23:40 +08:00
committed by Péter Szilágyi
parent 3e993ff64a
commit 17589aa75f
2 changed files with 17 additions and 14 deletions

View File

@ -21,6 +21,7 @@ import (
"sort"
"sync"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/event"
)
@ -162,6 +163,20 @@ func (am *Manager) Wallet(url string) (Wallet, error) {
return nil, ErrUnknownWallet
}
// Accounts returns all account addresses of all wallets within the account manager
func (am *Manager) Accounts() []common.Address {
am.lock.RLock()
defer am.lock.RUnlock()
addresses := make([]common.Address, 0) // return [] instead of nil if empty
for _, wallet := range am.wallets {
for _, account := range wallet.Accounts() {
addresses = append(addresses, account.Address)
}
}
return addresses
}
// Find attempts to locate the wallet corresponding to a specific account. Since
// accounts can be dynamically added to and removed from wallets, this method has
// a linear runtime in the number of wallets.