|
|
|
@ -95,3 +95,26 @@ func (db *MemDatabase) LastKnownTD() []byte { |
|
|
|
|
func (db *MemDatabase) Flush() error { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (db *MemDatabase) NewBatch() Batch { |
|
|
|
|
return &memBatch{db: db} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type kv struct{ k, v []byte } |
|
|
|
|
|
|
|
|
|
type memBatch struct { |
|
|
|
|
db *MemDatabase |
|
|
|
|
writes []kv |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (w *memBatch) Put(key, value []byte) error { |
|
|
|
|
w.writes = append(w.writes, kv{key, common.CopyBytes(value)}) |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (w *memBatch) Write() error { |
|
|
|
|
for _, kv := range w.writes { |
|
|
|
|
w.db.db[string(kv.k)] = kv.v |
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|