diff options
| author | Roc Yu <rociiu0112@gmail.com> | 2019-08-08 17:23:40 +0800 | 
|---|---|---|
| committer | Péter Szilágyi <peterke@gmail.com> | 2019-08-08 17:23:40 +0800 | 
| commit | 17589aa75fdff7a90b2d783d7289df75f183c164 (patch) | |
| tree | ec2c2c08c91eb138b486e482470a75e9e254fc81 | |
| parent | 3e993ff64a9c2e9651fae11aaee55032cd6b0c3e (diff) | |
| download | go-tangerine-17589aa75fdff7a90b2d783d7289df75f183c164.tar.gz go-tangerine-17589aa75fdff7a90b2d783d7289df75f183c164.tar.zst go-tangerine-17589aa75fdff7a90b2d783d7289df75f183c164.zip | |
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
| -rw-r--r-- | accounts/manager.go | 15 | ||||
| -rw-r--r-- | internal/ethapi/api.go | 16 | 
2 files changed, 17 insertions, 14 deletions
| diff --git a/accounts/manager.go b/accounts/manager.go index 3cf3422e7..731d12ea3 100644 --- a/accounts/manager.go +++ b/accounts/manager.go @@ -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. diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index a00598f82..b67017a90 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -191,13 +191,7 @@ func NewPublicAccountAPI(am *accounts.Manager) *PublicAccountAPI {  // Accounts returns the collection of accounts this node manages  func (s *PublicAccountAPI) Accounts() []common.Address { -	addresses := make([]common.Address, 0) // return [] instead of nil if empty -	for _, wallet := range s.am.Wallets() { -		for _, account := range wallet.Accounts() { -			addresses = append(addresses, account.Address) -		} -	} -	return addresses +	return s.am.Accounts()  }  // PrivateAccountAPI provides an API to access accounts managed by this node. @@ -220,13 +214,7 @@ func NewPrivateAccountAPI(b Backend, nonceLock *AddrLocker) *PrivateAccountAPI {  // listAccounts will return a list of addresses for accounts this node manages.  func (s *PrivateAccountAPI) ListAccounts() []common.Address { -	addresses := make([]common.Address, 0) // return [] instead of nil if empty -	for _, wallet := range s.am.Wallets() { -		for _, account := range wallet.Accounts() { -			addresses = append(addresses, account.Address) -		} -	} -	return addresses +	return s.am.Accounts()  }  // rawWallet is a JSON representation of an accounts.Wallet interface, with its | 
