accounts/keystore,manager finish reworking manager to support db backed keystore

This commit is contained in:
Huiyi Li 2020-04-06 14:57:59 -07:00
parent 276e13dc01
commit e152c25668
3 changed files with 15 additions and 10 deletions

View file

@ -138,3 +138,12 @@ func NewKeyStoreDB(path string, scryptN, scryptP int) (KeyStore, error) {
ks := &keyStoreDB{storage: storage, unlocked: make(map[common.Address]*unlocked)}
return ks, nil
}
// NewKeyStoreWalletDB creates a new wallet based on the account
// this is only used for creating a db based wallet in AccountManager
func NewKeyStoreWalletDB(acc accounts.Account, ks KeyStore) accounts.Wallet {
return &keystoreWalletDB{
account: acc,
keystore: ks.(*keyStoreDB),
}
}

View file

@ -58,7 +58,7 @@ func NewManager(config *Config, backends ...accounts.Backend) *Manager {
for _, backend := range backends {
// if we are using db backed keystore, it doesn't make sense to cache the potential millions of keys in our memory
if reflect.TypeOf(backend) != keystore.DBKeyStoreType {
wallets = backend.Wallets()
wallets = merge(wallets, backend.Wallets()...)
}
}
// Subscribe to wallet notifications from all backends
@ -214,13 +214,11 @@ func (am *Manager) Find(account accounts.Account) (accounts.Wallet, error) {
dbBackends := am.Backends(keystore.DBKeyStoreType)
if len(dbBackends) == 1 {
dbKeyStore, _ := dbBackends[0].(keystore.KeyStore)
// TODO here
dbKeyStore.Accounts()
return nil, nil
// acc, err := dbKeyStore.Find(account)
// if err == nil {
// return &keystore.keystoreWalletDB{}, nil
// }
acc, err := dbKeyStore.Find(account)
if err == nil {
wallet := keystore.NewKeyStoreWalletDB(acc, dbKeyStore)
return wallet, nil
}
}
for _, wallet := range am.wallets {

View file

@ -394,12 +394,10 @@ func (api *SignerAPI) startUSBListener() {
// multiple accounts.
func (api *SignerAPI) List(ctx context.Context) ([]common.Address, error) {
var accs []accounts.Account
log.Error(fmt.Sprint(len(api.am.Wallets())))
for _, wallet := range api.am.Wallets() {
log.Error(fmt.Sprint(len(wallet.Accounts())))
accs = append(accs, wallet.Accounts()...)
}
log.Error(fmt.Sprint(len(accs)))
result, err := api.UI.ApproveListing(&ListRequest{Accounts: accs, Meta: MetadataFromContext(ctx)})
if err != nil {
return nil, err