Added delete to database interfaces

This commit is contained in:
obscuren 2014-02-24 12:12:01 +01:00
parent 5971c82094
commit 55c1c220d0
3 changed files with 11 additions and 0 deletions

View File

@ -36,6 +36,10 @@ func (db *LDBDatabase) Get(key []byte) ([]byte, error) {
return db.db.Get(key, nil) return db.db.Get(key, nil)
} }
func (db *LDBDatabase) Delete(key []byte) error {
return db.db.Delete(key, nil)
}
func (db *LDBDatabase) LastKnownTD() []byte { func (db *LDBDatabase) LastKnownTD() []byte {
data, _ := db.db.Get([]byte("LastKnownTotalDifficulty"), nil) data, _ := db.db.Get([]byte("LastKnownTotalDifficulty"), nil)

View File

@ -26,6 +26,12 @@ func (db *MemDatabase) Get(key []byte) ([]byte, error) {
return db.db[string(key)], nil return db.db[string(key)], nil
} }
func (db *MemDatabase) Delete(key []byte) error {
delete(db.db, string(key))
return nil
}
func (db *MemDatabase) Print() { func (db *MemDatabase) Print() {
for key, val := range db.db { for key, val := range db.db {
fmt.Printf("%x(%d): ", key, len(key)) fmt.Printf("%x(%d): ", key, len(key))

View File

@ -4,6 +4,7 @@ package ethutil
type Database interface { type Database interface {
Put(key []byte, value []byte) Put(key []byte, value []byte)
Get(key []byte) ([]byte, error) Get(key []byte) ([]byte, error)
Delete(key []byte) error
LastKnownTD() []byte LastKnownTD() []byte
Close() Close()
Print() Print()