2019-08-09 21:41:50 +00:00
|
|
|
package wallet
|
|
|
|
|
|
|
|
import (
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2019-08-09 21:41:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type MemKeyStore struct {
|
|
|
|
m map[string]types.KeyInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMemKeyStore() *MemKeyStore {
|
|
|
|
return &MemKeyStore{
|
|
|
|
make(map[string]types.KeyInfo),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// List lists all the keys stored in the KeyStore
|
|
|
|
func (mks *MemKeyStore) List() ([]string, error) {
|
|
|
|
var out []string
|
|
|
|
for k := range mks.m {
|
|
|
|
out = append(out, k)
|
|
|
|
}
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get gets a key out of keystore and returns KeyInfo corresponding to named key
|
|
|
|
func (mks *MemKeyStore) Get(k string) (types.KeyInfo, error) {
|
|
|
|
ki, ok := mks.m[k]
|
|
|
|
if !ok {
|
2019-10-17 10:18:40 +00:00
|
|
|
return types.KeyInfo{}, types.ErrKeyInfoNotFound
|
2019-08-09 21:41:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ki, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put saves a key info under given name
|
|
|
|
func (mks *MemKeyStore) Put(k string, ki types.KeyInfo) error {
|
|
|
|
mks.m[k] = ki
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete removes a key from keystore
|
|
|
|
func (mks *MemKeyStore) Delete(k string) error {
|
|
|
|
delete(mks.m, k)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ (types.KeyStore) = (*MemKeyStore)(nil)
|