2013-12-30 00:54:50 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path"
|
|
|
|
"os/user"
|
|
|
|
"github.com/syndtr/goleveldb/leveldb"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2013-12-30 02:09:57 +02:00
|
|
|
type LDBDatabase struct {
|
2013-12-30 00:54:50 +02:00
|
|
|
db *leveldb.DB
|
|
|
|
trie *Trie
|
|
|
|
}
|
|
|
|
|
2013-12-30 02:09:57 +02:00
|
|
|
func NewLDBDatabase() (*LDBDatabase, error) {
|
2013-12-30 00:54:50 +02:00
|
|
|
// This will eventually have to be something like a resource folder.
|
|
|
|
// it works on my system for now. Probably won't work on Windows
|
|
|
|
usr, _ := user.Current()
|
|
|
|
dbPath := path.Join(usr.HomeDir, ".ethereum", "database")
|
|
|
|
|
|
|
|
// Open the db
|
|
|
|
db, err := leveldb.OpenFile(dbPath, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2013-12-30 02:09:57 +02:00
|
|
|
database := &LDBDatabase{db: db}
|
2013-12-30 00:54:50 +02:00
|
|
|
|
|
|
|
// Bootstrap database. Sets a few defaults; such as the last block
|
|
|
|
database.Bootstrap()
|
|
|
|
|
|
|
|
return database, nil
|
|
|
|
}
|
|
|
|
|
2013-12-30 02:09:57 +02:00
|
|
|
func (db *LDBDatabase) Bootstrap() error {
|
2014-01-01 04:07:49 +02:00
|
|
|
//db.trie = NewTrie(db)
|
2013-12-30 00:54:50 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-12-30 02:09:57 +02:00
|
|
|
func (db *LDBDatabase) Put(key []byte, value []byte) {
|
2013-12-30 00:54:50 +02:00
|
|
|
err := db.db.Put(key, value, nil)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error put", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-30 02:09:57 +02:00
|
|
|
func (db *LDBDatabase) Get(key []byte) ([]byte, error) {
|
2013-12-30 00:54:50 +02:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2013-12-30 02:09:57 +02:00
|
|
|
func (db *LDBDatabase) Close() {
|
|
|
|
// Close the leveldb database
|
|
|
|
db.db.Close()
|
2013-12-30 00:54:50 +02:00
|
|
|
}
|
|
|
|
|