diff --git a/ethdb/badger_db.go b/ethdb/badger_db.go index 791695d09..d09955c70 100644 --- a/ethdb/badger_db.go +++ b/ethdb/badger_db.go @@ -189,7 +189,7 @@ func (db *BadgerDatabase) DeleteTimestamp(timestamp uint64) error { }) } -// GetS returns the value that was put into a given historical bucket for an exact timestamp. +// GetS returns the value that was recorded in a given historical bucket for an exact timestamp. func (db *BadgerDatabase) GetS(hBucket, key []byte, timestamp uint64) ([]byte, error) { composite, _ := dbutils.CompositeKeySuffix(key, timestamp) return db.Get(hBucket, composite) @@ -228,4 +228,13 @@ func (db *BadgerDatabase) GetAsOf(bucket, hBucket, key []byte, timestamp uint64) return dat, err } +// Has indicates whether a key exists in the database. +func (db *BadgerDatabase) Has(bucket, key []byte) (bool, error) { + _, err := db.Get(bucket, key) + if err == ErrKeyNotFound { + return false, nil + } + return err == nil, err +} + // TODO [Andrew] implement the full Database interface diff --git a/ethdb/bolt_db.go b/ethdb/bolt_db.go index 274436fbf..0a6373d76 100644 --- a/ethdb/bolt_db.go +++ b/ethdb/bolt_db.go @@ -182,7 +182,7 @@ func (db *BoltDatabase) Get(bucket, key []byte) ([]byte, error) { return dat, err } -// GetS returns the value that was put into a given historical bucket for an exact timestamp. +// GetS returns the value that was recorded in a given historical bucket for an exact timestamp. func (db *BoltDatabase) GetS(hBucket, key []byte, timestamp uint64) ([]byte, error) { composite, _ := dbutils.CompositeKeySuffix(key, timestamp) return db.Get(hBucket, composite) diff --git a/ethdb/interface.go b/ethdb/interface.go index 92356643e..4b552f7eb 100644 --- a/ethdb/interface.go +++ b/ethdb/interface.go @@ -42,7 +42,7 @@ type Getter interface { // Get returns the value for a given key if it's present. Get(bucket, key []byte) ([]byte, error) - // GetS returns the value that was put into a given historical bucket for an exact timestamp. + // GetS returns the value that was recorded in a given historical bucket for an exact timestamp. // timestamp == block number GetS(hBucket, key []byte, timestamp uint64) ([]byte, error) @@ -50,7 +50,9 @@ type Getter interface { // timestamp == block number GetAsOf(bucket, hBucket, key []byte, timestamp uint64) ([]byte, error) + // Has indicates whether a key exists in the database. Has(bucket, key []byte) (bool, error) + Walk(bucket, startkey []byte, fixedbits uint, walker func([]byte, []byte) (bool, error)) error MultiWalk(bucket []byte, startkeys [][]byte, fixedbits []uint, walker func(int, []byte, []byte) (bool, error)) error WalkAsOf(bucket, hBucket, startkey []byte, fixedbits uint, timestamp uint64, walker func([]byte, []byte) (bool, error)) error