diff --git a/cmd/lotus-wallet/main.go b/cmd/lotus-wallet/main.go index d51175c0d..91f23d092 100644 --- a/cmd/lotus-wallet/main.go +++ b/cmd/lotus-wallet/main.go @@ -283,7 +283,7 @@ func openRepo(cctx *cli.Context) (repo.LockedRepo, types.KeyStore, error) { } } - lr, err := r.Lock(repo.WalletRepoType{}) + lr, err := r.Lock(repo.Wallet) if err != nil { return nil, nil, err } diff --git a/node/repo/fsrepo.go b/node/repo/fsrepo.go index e5f8918ab..ef91c650b 100644 --- a/node/repo/fsrepo.go +++ b/node/repo/fsrepo.go @@ -50,7 +50,7 @@ func NewRepoTypeFromString(t string) RepoType { case "Worker": return Worker case "Wallet": - return WalletRepoType{} + return Wallet default: panic("unknown RepoType") } @@ -113,21 +113,19 @@ func (f worker) Config() interface{} { return &struct{}{} } -type WalletRepoType struct { +var Wallet wallet + +type wallet struct { } -func (f WalletRepoType) Type() string { +func (f wallet) Type() string { return "Wallet" } -func (f WalletRepoType) Config() interface{} { +func (f wallet) Config() interface{} { return &struct{}{} } -func defConfForType(t RepoType) interface{} { - return t.Config() -} - var log = logging.Logger("repo") var ErrRepoExists = xerrors.New("repo exists") @@ -209,7 +207,7 @@ func (fsr *FsRepo) initConfig(t RepoType) error { return err } - comm, err := config.ConfigComment(defConfForType(t)) + comm, err := config.ConfigComment(t.Config()) if err != nil { return xerrors.Errorf("comment: %w", err) } @@ -450,7 +448,7 @@ func (fsr *fsLockedRepo) Config() (interface{}, error) { } func (fsr *fsLockedRepo) loadConfigFromDisk() (interface{}, error) { - return config.FromFile(fsr.configPath, defConfForType(fsr.repoType)) + return config.FromFile(fsr.configPath, fsr.repoType.Config()) } func (fsr *fsLockedRepo) SetConfig(c func(interface{})) error { diff --git a/node/repo/memrepo.go b/node/repo/memrepo.go index 9feef684a..a8e2d020f 100644 --- a/node/repo/memrepo.go +++ b/node/repo/memrepo.go @@ -36,9 +36,6 @@ type MemRepo struct { keystore map[string]types.KeyInfo blockstore blockstore.Blockstore - // given a repo type, produce the default config - configF func(t RepoType) interface{} - // holds the current config value config struct { sync.Mutex @@ -144,7 +141,6 @@ var _ Repo = &MemRepo{} // MemRepoOptions contains options for memory repo type MemRepoOptions struct { Ds datastore.Datastore - ConfigF func(RepoType) interface{} KeyStore map[string]types.KeyInfo } @@ -155,9 +151,6 @@ func NewMemory(opts *MemRepoOptions) *MemRepo { if opts == nil { opts = &MemRepoOptions{} } - if opts.ConfigF == nil { - opts.ConfigF = defConfForType - } if opts.Ds == nil { opts.Ds = dssync.MutexWrap(datastore.NewMapDatastore()) } @@ -169,7 +162,6 @@ func NewMemory(opts *MemRepoOptions) *MemRepo { repoLock: make(chan struct{}, 1), blockstore: blockstore.WrapIDStore(blockstore.NewMemorySync()), datastore: opts.Ds, - configF: opts.ConfigF, keystore: opts.KeyStore, } } @@ -284,7 +276,7 @@ func (lmem *lockedMemRepo) Config() (interface{}, error) { defer lmem.mem.config.Unlock() if lmem.mem.config.val == nil { - lmem.mem.config.val = lmem.mem.configF(lmem.t) + lmem.mem.config.val = lmem.t.Config() } return lmem.mem.config.val, nil @@ -299,7 +291,7 @@ func (lmem *lockedMemRepo) SetConfig(c func(interface{})) error { defer lmem.mem.config.Unlock() if lmem.mem.config.val == nil { - lmem.mem.config.val = lmem.mem.configF(lmem.t) + lmem.mem.config.val = lmem.t.Config() } c(lmem.mem.config.val)