mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
5569a68452
* Value assigned to a variable is never read before being overwritten * The result of append is not used anywhere * Suspicious assignment of range-loop vars detected * Unused method receiver detected * Revert "Auxiliary commit to revert individual files from 54edcb445484a2e5d79612e19af8e949b8861253" This reverts commit bbd1e1beabf7b0c5cfc4f514dcc820062ad6c063. * Method modifies receiver * Fix test * Duplicate imports detected * Incorrectly formatted error string * Types of function parameters can be combined * One more "Unused method receiver detected" * Unused parameter detected in function
78 lines
1.7 KiB
Go
78 lines
1.7 KiB
Go
package mock
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"strings"
|
|
"sync"
|
|
|
|
"github.com/prysmaticlabs/prysm/validator/accounts/iface"
|
|
"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 (w *Wallet) AccountNames() ([]string, error) {
|
|
w.lock.RLock()
|
|
defer w.lock.RUnlock()
|
|
names := make([]string, 0)
|
|
for name := range w.AccountPasswords {
|
|
names = append(names, name)
|
|
}
|
|
return names, nil
|
|
}
|
|
|
|
// AccountsDir --
|
|
func (w *Wallet) AccountsDir() string {
|
|
return w.InnerAccountsDir
|
|
}
|
|
|
|
// Exists --
|
|
func (w *Wallet) Exists() (bool, error) {
|
|
return len(w.Directories) > 0, nil
|
|
}
|
|
|
|
// Password --
|
|
func (w *Wallet) Password() string {
|
|
return w.WalletPassword
|
|
}
|
|
|
|
// WriteFileAtPath --
|
|
func (w *Wallet) WriteFileAtPath(_ context.Context, pathName, fileName string, data []byte) error {
|
|
w.lock.Lock()
|
|
defer w.lock.Unlock()
|
|
if w.Files[pathName] == nil {
|
|
w.Files[pathName] = make(map[string][]byte)
|
|
}
|
|
w.Files[pathName][fileName] = data
|
|
return nil
|
|
}
|
|
|
|
// ReadFileAtPath --
|
|
func (w *Wallet) ReadFileAtPath(_ context.Context, pathName, fileName string) ([]byte, error) {
|
|
w.lock.RLock()
|
|
defer w.lock.RUnlock()
|
|
for f, v := range w.Files[pathName] {
|
|
if strings.Contains(fileName, f) {
|
|
return v, nil
|
|
}
|
|
}
|
|
return nil, errors.New("no files found")
|
|
}
|
|
|
|
// InitializeKeymanager --
|
|
func (_ *Wallet) InitializeKeymanager(_ context.Context, _ iface.InitKeymanagerConfig) (keymanager.IKeymanager, error) {
|
|
return nil, nil
|
|
}
|