diff options
Diffstat (limited to 'ethdb/leveldb')
-rw-r--r-- | ethdb/leveldb/leveldb.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/ethdb/leveldb/leveldb.go b/ethdb/leveldb/leveldb.go index f730887d2..f437cb974 100644 --- a/ethdb/leveldb/leveldb.go +++ b/ethdb/leveldb/leveldb.go @@ -416,3 +416,32 @@ func (b *batch) Reset() { b.b.Reset() b.size = 0 } + +// Replay replays the batch contents. +func (b *batch) Replay(w ethdb.Writer) error { + return b.b.Replay(&replayer{writer: w}) +} + +// replayer is a small wrapper to implement the correct replay methods. +type replayer struct { + writer ethdb.Writer + failure error +} + +// Put inserts the given value into the key-value data store. +func (r *replayer) Put(key, value []byte) { + // If the replay already failed, stop executing ops + if r.failure != nil { + return + } + r.failure = r.writer.Put(key, value) +} + +// Delete removes the key from the key-value data store. +func (r *replayer) Delete(key []byte) { + // If the replay already failed, stop executing ops + if r.failure != nil { + return + } + r.failure = r.writer.Delete(key) +} |