mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
47 lines
No EOL
951 B
Go
47 lines
No EOL
951 B
Go
package eth
|
|
|
|
import (
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
|
"github.com/ethereum/go-ethereum/node"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
)
|
|
|
|
var Chaindb_global ethdb.Database
|
|
|
|
func SetChainDB(db ethdb.Database){
|
|
Chaindb_global = db
|
|
}
|
|
|
|
func chaindb(ctx *node.ServiceContext, config *Config) (ethdb.Database, error) {
|
|
fmt.Printf("CTX v+%", ctx)
|
|
if Chaindb_global != nil {
|
|
return Chaindb_global, nil
|
|
}
|
|
|
|
chainDb, err := CreateDB(ctx, config, "chaindata")
|
|
if err == nil {
|
|
SetChainDB(chainDb)
|
|
return Chaindb_global, nil
|
|
}
|
|
return nil, err
|
|
}
|
|
|
|
//(*ethdb.LDBDatabase, func())
|
|
func NewShyftTestLDB() {
|
|
dirname, err := ioutil.TempDir(os.TempDir(), "shyftdb_test_")
|
|
if err != nil {
|
|
panic("failed to create test file: " + err.Error())
|
|
}
|
|
db, err := ethdb.NewLDBDatabase(dirname, 0, 0)
|
|
if err != nil {
|
|
panic("failed to create test database: " + err.Error())
|
|
}
|
|
Chaindb_global = db
|
|
|
|
//return db, func() {
|
|
// db.Close()
|
|
// os.RemoveAll(dirname)
|
|
//}
|
|
} |