aboutsummaryrefslogtreecommitdiffstats
path: root/database.go
diff options
context:
space:
mode:
authorobscuren <obscuren@obscura.com>2013-12-30 08:09:57 +0800
committerobscuren <obscuren@obscura.com>2013-12-30 08:09:57 +0800
commitf17930eb4661721cd0e1b92765448c589441907b (patch)
tree35def5092a0d704feb0c20f1d29b94452ebfd09c /database.go
parenta926686445929d091c2d9e019b017600168e9e47 (diff)
downloadgo-tangerine-f17930eb4661721cd0e1b92765448c589441907b.tar
go-tangerine-f17930eb4661721cd0e1b92765448c589441907b.tar.gz
go-tangerine-f17930eb4661721cd0e1b92765448c589441907b.tar.bz2
go-tangerine-f17930eb4661721cd0e1b92765448c589441907b.tar.lz
go-tangerine-f17930eb4661721cd0e1b92765448c589441907b.tar.xz
go-tangerine-f17930eb4661721cd0e1b92765448c589441907b.tar.zst
go-tangerine-f17930eb4661721cd0e1b92765448c589441907b.zip
Split up db and trie and added interface
Diffstat (limited to 'database.go')
-rw-r--r--database.go56
1 files changed, 9 insertions, 47 deletions
diff --git a/database.go b/database.go
index f74c1dc7f..c056e70af 100644
--- a/database.go
+++ b/database.go
@@ -7,12 +7,12 @@ import (
"fmt"
)
-type Database struct {
+type LDBDatabase struct {
db *leveldb.DB
trie *Trie
}
-func NewDatabase() (*Database, error) {
+func NewLDBDatabase() (*LDBDatabase, error) {
// 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()
@@ -24,7 +24,7 @@ func NewDatabase() (*Database, error) {
return nil, err
}
- database := &Database{db: db}
+ database := &LDBDatabase{db: db}
// Bootstrap database. Sets a few defaults; such as the last block
database.Bootstrap()
@@ -32,63 +32,25 @@ func NewDatabase() (*Database, error) {
return database, nil
}
-func (db *Database) Bootstrap() error {
+func (db *LDBDatabase) Bootstrap() error {
db.trie = NewTrie(db)
return nil
}
-func (db *Database) Put(key []byte, value []byte) {
+func (db *LDBDatabase) Put(key []byte, value []byte) {
err := db.db.Put(key, value, nil)
if err != nil {
fmt.Println("Error put", err)
}
}
-func (db *Database) Close() {
- // Close the leveldb database
- db.db.Close()
-}
-
-type Trie struct {
- root string
- db *Database
-}
-
-func NewTrie(db *Database) *Trie {
- return &Trie{db: db, root: ""}
-}
-
-func (t *Trie) Update(key string, value string) {
- k := CompactHexDecode(key)
-
- t.root = t.UpdateState(t.root, k, value)
-}
-
-func (t *Trie) Get(key []byte) ([]byte, error) {
+func (db *LDBDatabase) Get(key []byte) ([]byte, error) {
return nil, nil
}
-// Inserts a new sate or delete a state based on the value
-func (t *Trie) UpdateState(node, key, value string) string {
- if value != "" {
- return t.InsertState(node, key, value)
- } else {
- // delete it
- }
-
- return ""
-}
-
-func (t *Trie) InsertState(node, key, value string) string {
- return ""
+func (db *LDBDatabase) Close() {
+ // Close the leveldb database
+ db.db.Close()
}
-func (t *Trie) Put(node []byte) []byte {
- enc := Encode(node)
- sha := Sha256Bin(enc)
-
- t.db.Put([]byte(sha), enc)
-
- return sha
-}