From f6d1bfe45bf3709d7bad40bf563b5c09228622e3 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 14 Feb 2014 23:56:09 +0100 Subject: The great merge --- ethdb/database.go | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 ethdb/database.go (limited to 'ethdb/database.go') diff --git a/ethdb/database.go b/ethdb/database.go new file mode 100644 index 000000000..76e4b4e4d --- /dev/null +++ b/ethdb/database.go @@ -0,0 +1,64 @@ +package ethdb + +import ( + "fmt" + "github.com/ethereum/eth-go/ethutil" + "github.com/syndtr/goleveldb/leveldb" + "path" +) + +type LDBDatabase struct { + db *leveldb.DB +} + +func NewLDBDatabase() (*LDBDatabase, error) { + dbPath := path.Join(ethutil.Config.ExecPath, "database") + + // Open the db + db, err := leveldb.OpenFile(dbPath, nil) + if err != nil { + return nil, err + } + + database := &LDBDatabase{db: db} + + return database, nil +} + +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 *LDBDatabase) Get(key []byte) ([]byte, error) { + return db.db.Get(key, nil) +} + +func (db *LDBDatabase) LastKnownTD() []byte { + data, _ := db.db.Get([]byte("LastKnownTotalDifficulty"), nil) + + if len(data) == 0 { + data = []byte{0x0} + } + + return data +} + +func (db *LDBDatabase) Close() { + // Close the leveldb database + db.db.Close() +} + +func (db *LDBDatabase) Print() { + iter := db.db.NewIterator(nil) + for iter.Next() { + key := iter.Key() + value := iter.Value() + + fmt.Printf("%x(%d): ", key, len(key)) + node := ethutil.NewValueFromBytes(value) + fmt.Printf("%v\n", node) + } +} -- cgit From 55c1c220d07c37610c9aa61c583eccb3c8e3829e Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 24 Feb 2014 12:12:01 +0100 Subject: Added delete to database interfaces --- ethdb/database.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'ethdb/database.go') diff --git a/ethdb/database.go b/ethdb/database.go index 76e4b4e4d..1e987920d 100644 --- a/ethdb/database.go +++ b/ethdb/database.go @@ -36,6 +36,10 @@ func (db *LDBDatabase) Get(key []byte) ([]byte, error) { return db.db.Get(key, nil) } +func (db *LDBDatabase) Delete(key []byte) error { + return db.db.Delete(key, nil) +} + func (db *LDBDatabase) LastKnownTD() []byte { data, _ := db.db.Get([]byte("LastKnownTotalDifficulty"), nil) -- cgit From 4f4175a3e295272025d312c800f65fc1a143a9ca Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 25 Feb 2014 11:21:03 +0100 Subject: Addad db name for new ldb --- ethdb/database.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'ethdb/database.go') diff --git a/ethdb/database.go b/ethdb/database.go index 1e987920d..d1967f023 100644 --- a/ethdb/database.go +++ b/ethdb/database.go @@ -11,8 +11,8 @@ type LDBDatabase struct { db *leveldb.DB } -func NewLDBDatabase() (*LDBDatabase, error) { - dbPath := path.Join(ethutil.Config.ExecPath, "database") +func NewLDBDatabase(name string) (*LDBDatabase, error) { + dbPath := path.Join(ethutil.Config.ExecPath, name) // Open the db db, err := leveldb.OpenFile(dbPath, nil) @@ -40,6 +40,10 @@ func (db *LDBDatabase) Delete(key []byte) error { return db.db.Delete(key, nil) } +func (db *LDBDatabase) Db() *leveldb.DB { + return db.db +} + func (db *LDBDatabase) LastKnownTD() []byte { data, _ := db.db.Get([]byte("LastKnownTotalDifficulty"), nil) -- cgit From c9f3d1c00ba70016be4bb871f9ecd50d456c6985 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 28 Feb 2014 10:36:06 +0100 Subject: leveldb API changed for NewIterator. Fixes #20 --- ethdb/database.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'ethdb/database.go') diff --git a/ethdb/database.go b/ethdb/database.go index d1967f023..3dbff36de 100644 --- a/ethdb/database.go +++ b/ethdb/database.go @@ -54,13 +54,19 @@ func (db *LDBDatabase) LastKnownTD() []byte { return data } +func (db *LDBDatabase) GetKeys() []*ethutil.Key { + data, _ := db.Get([]byte("KeyRing")) + + return []*ethutil.Key{ethutil.NewKeyFromBytes(data)} +} + func (db *LDBDatabase) Close() { // Close the leveldb database db.db.Close() } func (db *LDBDatabase) Print() { - iter := db.db.NewIterator(nil) + iter := db.db.NewIterator(nil, nil) for iter.Next() { key := iter.Key() value := iter.Value() -- cgit From f4fa0d48cb10f925908062357be965c54370cba9 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 14 May 2014 13:54:40 +0200 Subject: Moved keyring to ethutil & removed old methods. Implements #20 --- ethdb/database.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'ethdb/database.go') diff --git a/ethdb/database.go b/ethdb/database.go index 3dbff36de..09e9d8c7d 100644 --- a/ethdb/database.go +++ b/ethdb/database.go @@ -54,11 +54,13 @@ func (db *LDBDatabase) LastKnownTD() []byte { return data } +/* func (db *LDBDatabase) GetKeys() []*ethutil.Key { data, _ := db.Get([]byte("KeyRing")) return []*ethutil.Key{ethutil.NewKeyFromBytes(data)} } +*/ func (db *LDBDatabase) Close() { // Close the leveldb database -- cgit From 962255b373a0c8d7c2459cb25aaaa0dc4e492ecf Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 23 Aug 2014 11:00:33 +0200 Subject: Removed old code --- ethdb/database.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'ethdb/database.go') diff --git a/ethdb/database.go b/ethdb/database.go index 09e9d8c7d..e4b069930 100644 --- a/ethdb/database.go +++ b/ethdb/database.go @@ -2,9 +2,10 @@ package ethdb import ( "fmt" + "path" + "github.com/ethereum/eth-go/ethutil" "github.com/syndtr/goleveldb/leveldb" - "path" ) type LDBDatabase struct { @@ -45,7 +46,7 @@ func (db *LDBDatabase) Db() *leveldb.DB { } func (db *LDBDatabase) LastKnownTD() []byte { - data, _ := db.db.Get([]byte("LastKnownTotalDifficulty"), nil) + data, _ := db.db.Get([]byte("LTD"), nil) if len(data) == 0 { data = []byte{0x0} @@ -54,14 +55,6 @@ func (db *LDBDatabase) LastKnownTD() []byte { return data } -/* -func (db *LDBDatabase) GetKeys() []*ethutil.Key { - data, _ := db.Get([]byte("KeyRing")) - - return []*ethutil.Key{ethutil.NewKeyFromBytes(data)} -} -*/ - func (db *LDBDatabase) Close() { // Close the leveldb database db.db.Close() -- cgit