File tree Expand file tree Collapse file tree 2 files changed +17
-14
lines changed Expand file tree Collapse file tree 2 files changed +17
-14
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import (
21
21
"sort"
22
22
"sync"
23
23
24
+ "github.com/ethereum/go-ethereum/common"
24
25
"github.com/ethereum/go-ethereum/event"
25
26
)
26
27
@@ -162,6 +163,20 @@ func (am *Manager) Wallet(url string) (Wallet, error) {
162
163
return nil , ErrUnknownWallet
163
164
}
164
165
166
+ // Accounts returns all account addresses of all wallets within the account manager
167
+ func (am * Manager ) Accounts () []common.Address {
168
+ am .lock .RLock ()
169
+ defer am .lock .RUnlock ()
170
+
171
+ addresses := make ([]common.Address , 0 ) // return [] instead of nil if empty
172
+ for _ , wallet := range am .wallets {
173
+ for _ , account := range wallet .Accounts () {
174
+ addresses = append (addresses , account .Address )
175
+ }
176
+ }
177
+ return addresses
178
+ }
179
+
165
180
// Find attempts to locate the wallet corresponding to a specific account. Since
166
181
// accounts can be dynamically added to and removed from wallets, this method has
167
182
// a linear runtime in the number of wallets.
Original file line number Diff line number Diff line change @@ -191,13 +191,7 @@ func NewPublicAccountAPI(am *accounts.Manager) *PublicAccountAPI {
191
191
192
192
// Accounts returns the collection of accounts this node manages
193
193
func (s * PublicAccountAPI ) Accounts () []common.Address {
194
- addresses := make ([]common.Address , 0 ) // return [] instead of nil if empty
195
- for _ , wallet := range s .am .Wallets () {
196
- for _ , account := range wallet .Accounts () {
197
- addresses = append (addresses , account .Address )
198
- }
199
- }
200
- return addresses
194
+ return s .am .Accounts ()
201
195
}
202
196
203
197
// PrivateAccountAPI provides an API to access accounts managed by this node.
@@ -220,13 +214,7 @@ func NewPrivateAccountAPI(b Backend, nonceLock *AddrLocker) *PrivateAccountAPI {
220
214
221
215
// listAccounts will return a list of addresses for accounts this node manages.
222
216
func (s * PrivateAccountAPI ) ListAccounts () []common.Address {
223
- addresses := make ([]common.Address , 0 ) // return [] instead of nil if empty
224
- for _ , wallet := range s .am .Wallets () {
225
- for _ , account := range wallet .Accounts () {
226
- addresses = append (addresses , account .Address )
227
- }
228
- }
229
- return addresses
217
+ return s .am .Accounts ()
230
218
}
231
219
232
220
// rawWallet is a JSON representation of an accounts.Wallet interface, with its
You can’t perform that action at this time.
0 commit comments