You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
42 lines
1.1 KiB
package prefix
|
|
|
|
import "github.com/ethereum/go-ethereum/ethdb"
|
|
|
|
type PrefixBatch struct {
|
|
prefix []byte
|
|
batch ethdb.Batch
|
|
}
|
|
|
|
func newPrefixBatch(prefix []byte, batch ethdb.Batch) *PrefixBatch {
|
|
return &PrefixBatch{prefix: prefix, batch: batch}
|
|
}
|
|
|
|
// Put inserts the given value into the key-value data store.
|
|
func (p *PrefixBatch) Put(key []byte, value []byte) error {
|
|
return p.batch.Put(append(append([]byte{}, p.prefix...), key...), value)
|
|
}
|
|
|
|
// Delete removes the key from the key-value data store.
|
|
func (p *PrefixBatch) Delete(key []byte) error {
|
|
return p.batch.Delete(append(append([]byte{}, p.prefix...), key...))
|
|
}
|
|
|
|
// ValueSize retrieves the amount of data queued up for writing.
|
|
func (p *PrefixBatch) ValueSize() int {
|
|
return p.batch.ValueSize()
|
|
}
|
|
|
|
// Write flushes any accumulated data to disk.
|
|
func (p *PrefixBatch) Write() error {
|
|
return p.batch.Write()
|
|
}
|
|
|
|
// Reset resets the batch for reuse.
|
|
func (p *PrefixBatch) Reset() {
|
|
p.batch.Reset()
|
|
}
|
|
|
|
// Replay replays the batch contents.
|
|
func (p *PrefixBatch) Replay(w ethdb.KeyValueWriter) error {
|
|
return p.batch.Replay(newPrefixBatchReplay(p.prefix, w))
|
|
}
|
|
|