2022-09-22 15:34:50 +00:00
|
|
|
package verkletrie
|
2022-09-13 13:05:58 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
|
|
|
"github.com/ledgerwatch/erigon-lib/kv/mdbx"
|
|
|
|
)
|
|
|
|
|
|
|
|
type VerkleMarker struct {
|
|
|
|
db kv.RwDB
|
|
|
|
tx kv.RwTx
|
|
|
|
}
|
|
|
|
|
2022-09-16 13:11:13 +00:00
|
|
|
//nolint:gocritic
|
2022-09-13 13:05:58 +00:00
|
|
|
func NewVerkleMarker() *VerkleMarker {
|
|
|
|
markedSlotsDb, err := mdbx.NewTemporaryMdbx()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
tx, err := markedSlotsDb.BeginRw(context.TODO())
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &VerkleMarker{
|
|
|
|
db: markedSlotsDb,
|
|
|
|
tx: tx,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *VerkleMarker) MarkAsDone(key []byte) error {
|
|
|
|
return v.tx.Put(kv.Headers, key, []byte{0})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *VerkleMarker) IsMarked(key []byte) (bool, error) {
|
|
|
|
return v.tx.Has(kv.Headers, key)
|
|
|
|
}
|
|
|
|
|
2022-09-16 13:11:13 +00:00
|
|
|
func (v *VerkleMarker) Rollback() {
|
2022-09-13 13:05:58 +00:00
|
|
|
v.tx.Rollback()
|
|
|
|
v.db.Close()
|
|
|
|
}
|