2019-07-09 17:50:48 +00:00
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
2019-07-18 14:01:39 +00:00
|
|
|
"errors"
|
|
|
|
|
2019-07-09 17:50:48 +00:00
|
|
|
"github.com/ipfs/go-datastore"
|
|
|
|
"github.com/libp2p/go-libp2p-core/crypto"
|
|
|
|
"github.com/multiformats/go-multiaddr"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-lotus/node/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-07-18 14:01:39 +00:00
|
|
|
ErrNoAPIEndpoint = errors.New("API not running (no endpoint)")
|
|
|
|
ErrRepoAlreadyLocked = errors.New("repo is already locked")
|
|
|
|
ErrClosedRepo = errors.New("repo is no longer open")
|
|
|
|
|
|
|
|
ErrKeyExists = errors.New("key already exists")
|
|
|
|
ErrKeyNotFound = errors.New("key not found")
|
2019-07-09 17:50:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Repo interface {
|
|
|
|
// APIEndpoint returns multiaddress for communication with Lotus API
|
|
|
|
APIEndpoint() (multiaddr.Multiaddr, error)
|
|
|
|
|
|
|
|
// Lock locks the repo for exclusive use.
|
|
|
|
Lock() (LockedRepo, error)
|
|
|
|
}
|
|
|
|
|
2019-07-18 14:01:39 +00:00
|
|
|
type KeyInfo struct {
|
|
|
|
Type string
|
|
|
|
PrivateKey []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
type KeyStore interface {
|
|
|
|
// List lists all the keys stored in the KeyStore
|
|
|
|
List() ([]string, error)
|
|
|
|
// Get gets a key out of keystore and returns KeyInfo coresponding to named key
|
|
|
|
Get(string) (KeyInfo, error)
|
|
|
|
// Put saves a key info under given name
|
|
|
|
Put(string, KeyInfo) error
|
|
|
|
// Delete removes a key from keystore
|
|
|
|
Delete(string) error
|
|
|
|
}
|
|
|
|
|
2019-07-09 17:50:48 +00:00
|
|
|
type LockedRepo interface {
|
|
|
|
// Close closes repo and removes lock.
|
|
|
|
Close() error
|
|
|
|
|
|
|
|
// Returns datastore defined in this repo.
|
2019-07-10 15:38:35 +00:00
|
|
|
Datastore(namespace string) (datastore.Batching, error)
|
2019-07-09 17:50:48 +00:00
|
|
|
|
|
|
|
// Returns config in this repo
|
|
|
|
Config() (*config.Root, error)
|
|
|
|
|
|
|
|
// Libp2pIdentity returns private key for libp2p indentity
|
|
|
|
Libp2pIdentity() (crypto.PrivKey, error)
|
|
|
|
|
2019-07-09 18:20:42 +00:00
|
|
|
// SetAPIEndpoint sets the endpoint of the current API
|
|
|
|
// so it can be read by API clients
|
2019-07-09 17:50:48 +00:00
|
|
|
SetAPIEndpoint(multiaddr.Multiaddr) error
|
|
|
|
|
2019-07-18 14:01:39 +00:00
|
|
|
// KeyStore returns store of private keys for Filecoin transactions
|
|
|
|
KeyStore() (KeyStore, error)
|
2019-07-12 09:59:18 +00:00
|
|
|
|
|
|
|
// Path returns absolute path of the repo (or empty string if in-memory)
|
|
|
|
Path() string
|
2019-07-09 17:50:48 +00:00
|
|
|
}
|