lotus/node/repo/importmgr/store.go

55 lines
1.1 KiB
Go
Raw Normal View History

2020-07-06 23:39:30 +00:00
package importmgr
import (
"github.com/ipfs/go-blockservice"
"github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/namespace"
"github.com/ipfs/go-filestore"
blockstore "github.com/ipfs/go-ipfs-blockstore"
offline "github.com/ipfs/go-ipfs-exchange-offline"
ipld "github.com/ipfs/go-ipld-format"
"github.com/ipfs/go-merkledag"
)
type Store struct {
ds datastore.Batching
fm *filestore.FileManager
Fstore *filestore.Filestore
Bstore blockstore.Blockstore
bsvc blockservice.BlockService
DAG ipld.DAGService
}
func openStore(ds datastore.Batching) (*Store, error) {
blocks := namespace.Wrap(ds, datastore.NewKey("blocks"))
bs := blockstore.NewBlockstore(blocks)
fm := filestore.NewFileManager(ds, "/")
fm.AllowFiles = true
fstore := filestore.NewFilestore(bs, fm)
ibs := blockstore.NewIdStore(fstore)
bsvc := blockservice.New(ibs, offline.Exchange(ibs))
dag := merkledag.NewDAGService(bsvc)
return &Store{
2020-07-07 09:38:22 +00:00
ds: ds,
2020-07-06 23:39:30 +00:00
fm: fm,
Fstore: fstore,
Bstore: ibs,
2020-07-07 09:38:22 +00:00
bsvc: bsvc,
DAG: dag,
2020-07-06 23:39:30 +00:00
}, nil
}
func (s *Store) Close() error {
return s.bsvc.Close()
}