2016-09-27 13:51:08 +00:00
|
|
|
package status
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ethereum/go-ethereum/accounts"
|
2017-02-27 12:40:42 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2016-09-27 13:51:08 +00:00
|
|
|
)
|
|
|
|
|
2017-05-01 11:09:48 +00:00
|
|
|
// AccountManager abstracts both internal account manager and extra filter status backend requires
|
2016-09-27 13:51:08 +00:00
|
|
|
type AccountManager struct {
|
|
|
|
am *accounts.Manager
|
|
|
|
accountsFilterHandler AccountsFilterHandler
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewAccountManager creates a new AccountManager
|
|
|
|
func NewAccountManager(am *accounts.Manager) *AccountManager {
|
|
|
|
return &AccountManager{
|
|
|
|
am: am,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-01 11:09:48 +00:00
|
|
|
// AccountsFilterHandler function to filter out accounts list
|
2017-02-27 12:40:42 +00:00
|
|
|
type AccountsFilterHandler func([]common.Address) []common.Address
|
2016-09-27 13:51:08 +00:00
|
|
|
|
2017-02-27 12:40:42 +00:00
|
|
|
// Accounts returns accounts' addresses of currently logged in user.
|
2016-09-27 13:51:08 +00:00
|
|
|
// Since status supports HD keys, the following list is returned:
|
|
|
|
// [addressCDK#1, addressCKD#2->Child1, addressCKD#2->Child2, .. addressCKD#2->ChildN]
|
2017-02-27 12:40:42 +00:00
|
|
|
func (d *AccountManager) Accounts() []common.Address {
|
|
|
|
var addresses []common.Address
|
|
|
|
for _, wallet := range d.am.Wallets() {
|
|
|
|
for _, account := range wallet.Accounts() {
|
|
|
|
addresses = append(addresses, account.Address)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-27 13:51:08 +00:00
|
|
|
if d.accountsFilterHandler != nil {
|
2017-02-27 12:40:42 +00:00
|
|
|
return d.accountsFilterHandler(addresses)
|
2016-09-27 13:51:08 +00:00
|
|
|
}
|
|
|
|
|
2017-02-27 12:40:42 +00:00
|
|
|
return addresses
|
2016-09-27 13:51:08 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 11:09:48 +00:00
|
|
|
// SetAccountsFilterHandler sets filtering function for accounts list
|
2016-09-27 13:51:08 +00:00
|
|
|
func (d *AccountManager) SetAccountsFilterHandler(fn AccountsFilterHandler) {
|
|
|
|
d.accountsFilterHandler = fn
|
|
|
|
}
|