2018-06-05 21:28:57 +00:00
|
|
|
// Package database provides several constructs including a simple in-memory database.
|
|
|
|
// This should not be used for production, but would be a helpful interim
|
|
|
|
// solution for development.
|
2018-05-22 18:36:55 +00:00
|
|
|
package database
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
|
|
|
)
|
|
|
|
|
2018-05-24 23:14:52 +00:00
|
|
|
// ShardBackend defines an interface for a shardDB's necessary method
|
|
|
|
// signatures.
|
|
|
|
type ShardBackend interface {
|
2018-05-25 00:03:24 +00:00
|
|
|
Get(k []byte) ([]byte, error)
|
|
|
|
Has(k []byte) (bool, error)
|
|
|
|
Put(k []byte, val []byte) error
|
|
|
|
Delete(k []byte) error
|
2018-05-24 23:14:52 +00:00
|
|
|
}
|
|
|
|
|
2018-05-22 18:49:59 +00:00
|
|
|
// NewShardDB initializes a shardDB that writes to local disk.
|
2018-05-25 00:03:24 +00:00
|
|
|
func NewShardDB(dataDir string, name string) (ShardBackend, error) {
|
2018-05-22 18:36:55 +00:00
|
|
|
// Uses default cache and handles values.
|
2018-05-25 15:06:39 +00:00
|
|
|
// TODO: allow these arguments to be set based on cli context.
|
2018-05-24 23:36:20 +00:00
|
|
|
return ethdb.NewLDBDatabase(filepath.Join(dataDir, name), 16, 16)
|
2018-05-22 18:36:55 +00:00
|
|
|
}
|