mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 05:17:22 +00:00
f75a8efc0d
* rem opts * rem more km opts * more removal of km opts * removal of km opts * definition of internal accounts store * refactor enable/disable * enable build * fix rpc * remove keymanageropts * fix imported tests * table driven tests for enable disable * table driven tests for disable * comprehensive tests for disable * tests complete for enable and disable * pass enable disable tests * clarify imported * fix deadlocks * imported tests pass * remove enable disable entrypoints * better derived text * deep source suggestions * gaz * tidy Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
77 lines
1.6 KiB
Go
77 lines
1.6 KiB
Go
package mock
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
"sync"
|
|
|
|
"github.com/prysmaticlabs/prysm/validator/keymanager"
|
|
)
|
|
|
|
// Wallet contains an in-memory, simulated wallet implementation.
|
|
type Wallet struct {
|
|
InnerAccountsDir string
|
|
Directories []string
|
|
Files map[string]map[string][]byte
|
|
EncryptedSeedFile []byte
|
|
AccountPasswords map[string]string
|
|
WalletPassword string
|
|
UnlockAccounts bool
|
|
lock sync.RWMutex
|
|
}
|
|
|
|
// AccountNames --
|
|
func (m *Wallet) AccountNames() ([]string, error) {
|
|
m.lock.RLock()
|
|
defer m.lock.RUnlock()
|
|
names := make([]string, 0)
|
|
for name := range m.AccountPasswords {
|
|
names = append(names, name)
|
|
}
|
|
return names, nil
|
|
}
|
|
|
|
// AccountsDir --
|
|
func (m *Wallet) AccountsDir() string {
|
|
return m.InnerAccountsDir
|
|
}
|
|
|
|
// Exists --
|
|
func (m *Wallet) Exists() (bool, error) {
|
|
return len(m.Directories) > 0, nil
|
|
}
|
|
|
|
// Password --
|
|
func (m *Wallet) Password() string {
|
|
return m.WalletPassword
|
|
}
|
|
|
|
// WriteFileAtPath --
|
|
func (m *Wallet) WriteFileAtPath(_ context.Context, pathName, fileName string, data []byte) error {
|
|
m.lock.Lock()
|
|
defer m.lock.Unlock()
|
|
if m.Files[pathName] == nil {
|
|
m.Files[pathName] = make(map[string][]byte)
|
|
}
|
|
m.Files[pathName][fileName] = data
|
|
return nil
|
|
}
|
|
|
|
// ReadFileAtPath --
|
|
func (m *Wallet) ReadFileAtPath(_ context.Context, pathName, fileName string) ([]byte, error) {
|
|
m.lock.RLock()
|
|
defer m.lock.RUnlock()
|
|
for f, v := range m.Files[pathName] {
|
|
if strings.Contains(fileName, f) {
|
|
return v, nil
|
|
}
|
|
}
|
|
return nil, errors.New("no files found")
|
|
}
|
|
|
|
// InitializeKeymanager --
|
|
func (m *Wallet) InitializeKeymanager(_ context.Context) (keymanager.IKeymanager, error) {
|
|
return nil, nil
|
|
}
|