func (s *Service) FetchAccount(ctx context.Context, path string) (e2wtypes.Wallet, e2wtypes.Account, error) {
	walletName, accountName, err := e2wallet.WalletAndAccountNames(path)
	if err != nil {
		log.Warn().Msg("Invalid path")
		return nil, nil, errors.Wrap(err, "invalid path")
	}
	wallet, exists := s.wallets[walletName]
	if !exists {
		return nil, nil, errors.New("failed to find wallet")
	}
	walletAccounts, exists := s.walletAccounts[walletName]
	if exists {
		account, exists := walletAccounts[accountName]
		if exists {
			return wallet, account, nil
		}
	}
	s.rwMu.RLock()
	defer s.rwMu.RUnlock()
	walletAccounts, exists = s.rwWalletAccounts[walletName]
	if exists {
		account, exists := walletAccounts[accountName]
		if exists {
			return wallet, account, nil
		}
	}
	return nil, nil, errors.New("failed to find account")
}
FetchAccount fetches the account given its name.
package mem
import (
	"context"
	"encoding/json"
	"fmt"
	"sync"
	"github.com/attestantio/dirk/services/metrics"
	"github.com/google/uuid"
	"github.com/pkg/errors"
	"github.com/rs/zerolog"
	zerologger "github.com/rs/zerolog/log"
	"github.com/wealdtech/go-bytesutil"
	e2wallet "github.com/wealdtech/go-eth2-wallet"
	distributed "github.com/wealdtech/go-eth2-wallet-distributed"
	hd "github.com/wealdtech/go-eth2-wallet-hd/v2"
	nd "github.com/wealdtech/go-eth2-wallet-nd/v2"
	e2wtypes "github.com/wealdtech/go-eth2-wallet-types/v2"
)
type Service struct {
	monitor        metrics.FetcherMonitor
	pubKeyPaths    map[[48]byte]string
	wallets        map[string]e2wtypes.Wallet
	walletAccounts map[string]map[string]e2wtypes.Account
	rwPubKeyPaths    map[[48]byte]string
	rwWalletAccounts map[string]map[string]e2wtypes.Account
	rwMu             sync.RWMutex
}
var log zerolog.Logger
func New(ctx context.Context, params ...Parameter) (*Service, error) {
	parameters, err := parseAndCheckParameters(params...)
	if err != nil {
		return nil, errors.Wrap(err, "problem with parameters")
	}
	log = zerologger.With().Str("service", "fetcher").Str("impl", "mem").Logger()
	if parameters.logLevel != log.GetLevel() {
		log = log.Level(parameters.logLevel)
	}
	wallets, walletAccounts, pubKeyPaths, err := populateCaches(ctx, parameters.stores, parameters.encryptor)
	if err != nil {
		return nil, errors.Wrap(err, "failed to populate caches")
	}
	s := &Service{
		monitor:          parameters.monitor,
		pubKeyPaths:      pubKeyPaths,
		wallets:          wallets,
		walletAccounts:   walletAccounts,
		rwPubKeyPaths:    make(map[[48]byte]string),
		rwWalletAccounts: make(map[string]map[string]e2wtypes.Account),
	}
	return s, nil
}
func (s *Service) FetchWallet(ctx context.Context, path string) (e2wtypes.Wallet, error) {
	walletName, _, err := e2wallet.WalletAndAccountNames(path)
	if err != nil {
		log.Warn().Msg("Invalid path")
		return nil, errors.Wrap(err, "invalid path")
	}
	wallet, exists := s.wallets[walletName]
	if exists {
		log.Trace().Str("wallet", walletName).Msg("Wallet found in cache")
		return wallet, nil
	}
	log.Trace().Str("wallet", walletName).Msg("Wallet not found in cache")
	return nil, errors.New("wallet not found")
}