2013-12-29 22:54:50 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path"
|
|
|
|
"os/user"
|
|
|
|
"github.com/syndtr/goleveldb/leveldb"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2013-12-30 00:09:57 +00:00
|
|
|
type LDBDatabase struct {
|
2013-12-29 22:54:50 +00:00
|
|
|
db *leveldb.DB
|
|
|
|
trie *Trie
|
|
|
|
}
|
|
|
|
|
2013-12-30 00:09:57 +00:00
|
|
|
func NewLDBDatabase() (*LDBDatabase, error) {
|
2013-12-29 22:54:50 +00: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 00:09:57 +00:00
|
|
|
database := &LDBDatabase{db: db}
|
2013-12-29 22:54:50 +00:00
|
|
|
|
|
|
|
// Bootstrap database. Sets a few defaults; such as the last block
|
|
|
|
database.Bootstrap()
|
|
|
|
|
|
|
|
return database, nil
|
|
|
|
}
|
|
|
|
|
2013-12-30 00:09:57 +00:00
|
|
|
func (db *LDBDatabase) Bootstrap() error {
|
2014-01-01 02:07:49 +00:00
|
|
|
//db.trie = NewTrie(db)
|
2013-12-29 22:54:50 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-12-30 00:09:57 +00:00
|
|
|
func (db *LDBDatabase) Put(key []byte, value []byte) {
|
2013-12-29 22:54:50 +00:00
|
|
|
err := db.db.Put(key, value, nil)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error put", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-30 00:09:57 +00:00
|
|
|
func (db *LDBDatabase) Get(key []byte) ([]byte, error) {
|
2013-12-29 22:54:50 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2013-12-30 00:09:57 +00:00
|
|
|
func (db *LDBDatabase) Close() {
|
|
|
|
// Close the leveldb database
|
|
|
|
db.db.Close()
|
2013-12-29 22:54:50 +00:00
|
|
|
}
|
|
|
|
|