diff options
author | Felix Lange <fjl@twurst.com> | 2015-08-18 19:42:21 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-09-15 05:36:30 +0800 |
commit | 8b32f10f16f19c0b8985399fafdfe31af29493a1 (patch) | |
tree | c8fc463ce665286c7e604fc56e0a7f1ac7c6fa9a /ethdb/memory_database.go | |
parent | 8c4dab77ba48dc68073fe1df79e7000043c0f966 (diff) | |
download | go-tangerine-8b32f10f16f19c0b8985399fafdfe31af29493a1.tar.gz go-tangerine-8b32f10f16f19c0b8985399fafdfe31af29493a1.tar.zst go-tangerine-8b32f10f16f19c0b8985399fafdfe31af29493a1.zip |
ethdb: add NewBatch
Diffstat (limited to 'ethdb/memory_database.go')
-rw-r--r-- | ethdb/memory_database.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/ethdb/memory_database.go b/ethdb/memory_database.go index d50f8f9d4..4fcce1812 100644 --- a/ethdb/memory_database.go +++ b/ethdb/memory_database.go @@ -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 +} |