lotus/node/modules/testing/storage.go

40 lines
957 B
Go
Raw Normal View History

2019-07-08 13:36:43 +00:00
package testing
import (
2019-07-16 16:02:51 +00:00
"context"
"github.com/ipfs/go-blockservice"
2019-07-08 13:36:43 +00:00
"github.com/ipfs/go-datastore"
dsync "github.com/ipfs/go-datastore/sync"
blockstore "github.com/ipfs/go-ipfs-blockstore"
2019-07-16 16:02:51 +00:00
offline "github.com/ipfs/go-ipfs-exchange-offline"
ipld "github.com/ipfs/go-ipld-format"
"github.com/ipfs/go-merkledag"
"go.uber.org/fx"
2019-07-08 13:36:43 +00:00
)
func MapBlockstore() blockstore.Blockstore {
// TODO: proper datastore
bds := dsync.MutexWrap(datastore.NewMapDatastore())
bs := blockstore.NewBlockstore(bds)
return blockstore.NewIdStore(bs)
}
func MapDatastore() datastore.Batching {
return dsync.MutexWrap(datastore.NewMapDatastore())
}
2019-07-16 16:02:51 +00:00
func MemoryClientDag(lc fx.Lifecycle) ipld.DAGService {
ibs := blockstore.NewBlockstore(datastore.NewMapDatastore())
bsvc := blockservice.New(ibs, offline.Exchange(ibs))
dag := merkledag.NewDAGService(bsvc)
lc.Append(fx.Hook{
OnStop: func(_ context.Context) error {
return bsvc.Close()
},
})
return dag
}