You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
980 B
34 lines
980 B
package shardchain
|
|
|
|
import (
|
|
"fmt"
|
|
"path"
|
|
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
|
)
|
|
|
|
// DBFactory is a blockchain database factory.
|
|
type DBFactory interface {
|
|
// NewChainDB returns a new database for the blockchain for
|
|
// given shard.
|
|
NewChainDB(shardID uint32) (ethdb.Database, error)
|
|
}
|
|
|
|
// LDBFactory is a LDB-backed blockchain database factory.
|
|
type LDBFactory struct {
|
|
RootDir string // directory in which to put shard databases in.
|
|
}
|
|
|
|
// NewChainDB returns a new LDB for the blockchain for given shard.
|
|
func (f *LDBFactory) NewChainDB(shardID uint32) (ethdb.Database, error) {
|
|
dir := path.Join(f.RootDir, fmt.Sprintf("harmony_db_%d", shardID))
|
|
return ethdb.NewLDBDatabase(dir, 128, 64)
|
|
}
|
|
|
|
// MemDBFactory is a memory-backed blockchain database factory.
|
|
type MemDBFactory struct{}
|
|
|
|
// NewChainDB returns a new memDB for the blockchain for given shard.
|
|
func (f *MemDBFactory) NewChainDB(shardID uint32) (ethdb.Database, error) {
|
|
return ethdb.NewMemDatabase(), nil
|
|
}
|
|
|