2022-08-23 07:35:50 +00:00
|
|
|
// VulcanizeDB
|
|
|
|
// Copyright © 2022 Vulcanize
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2022-01-18 06:23:01 +00:00
|
|
|
package validator
|
|
|
|
|
|
|
|
import (
|
2022-06-03 13:28:02 +00:00
|
|
|
"errors"
|
|
|
|
|
2022-01-18 06:23:01 +00:00
|
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
|
|
|
)
|
|
|
|
|
2022-06-03 13:28:02 +00:00
|
|
|
var errNotSupported = errors.New("this operation is not supported")
|
|
|
|
|
2022-01-18 06:23:01 +00:00
|
|
|
type database struct {
|
|
|
|
ethDB ethdb.Database
|
|
|
|
}
|
|
|
|
|
|
|
|
func newDatabase(db ethdb.Database) *database {
|
|
|
|
return &database{
|
|
|
|
ethDB: db,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *database) NewIterator(prefix []byte, start []byte) ethdb.Iterator {
|
|
|
|
return d.ethDB.NewIterator(prefix, start)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *database) Has(key []byte) (bool, error) {
|
|
|
|
return d.ethDB.Has(key)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *database) Get(key []byte) ([]byte, error) {
|
|
|
|
return d.ethDB.Get(key)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *database) Put(key []byte, value []byte) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *database) Delete(key []byte) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *database) Stat(property string) (string, error) {
|
|
|
|
return d.ethDB.Stat(property)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *database) Compact(start []byte, limit []byte) error {
|
|
|
|
return d.ethDB.Compact(start, limit)
|
|
|
|
}
|
|
|
|
|
|
|
|
// HasAncient returns an error as we don't have a backing chain freezer.
|
|
|
|
func (d *database) HasAncient(kind string, number uint64) (bool, error) {
|
|
|
|
return d.ethDB.HasAncient(kind, number)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ancient returns an error as we don't have a backing chain freezer.
|
|
|
|
func (d *database) Ancient(kind string, number uint64) ([]byte, error) {
|
|
|
|
return d.ethDB.Ancient(kind, number)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AncientRange returns an error as we don't have a backing chain freezer.
|
|
|
|
func (d *database) AncientRange(kind string, start, max, maxByteSize uint64) ([][]byte, error) {
|
|
|
|
return d.ethDB.AncientRange(kind, start, max, maxByteSize)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ancients returns an error as we don't have a backing chain freezer.
|
|
|
|
func (d *database) Ancients() (uint64, error) {
|
|
|
|
return d.ethDB.Ancients()
|
|
|
|
}
|
|
|
|
|
|
|
|
// AncientSize returns an error as we don't have a backing chain freezer.
|
|
|
|
func (d *database) AncientSize(kind string) (uint64, error) {
|
|
|
|
return d.ethDB.AncientSize(kind)
|
|
|
|
}
|
|
|
|
|
2022-05-18 12:05:30 +00:00
|
|
|
// Tail returns the number of first stored item in the freezer.
|
|
|
|
func (d *database) Tail() (uint64, error) {
|
|
|
|
return d.Tail()
|
|
|
|
}
|
|
|
|
|
2022-01-18 06:23:01 +00:00
|
|
|
// ModifyAncients is not supported.
|
|
|
|
func (d *database) ModifyAncients(fn func(ethdb.AncientWriteOp) error) (int64, error) {
|
|
|
|
return 0, nil
|
|
|
|
}
|
|
|
|
|
2022-05-18 12:05:30 +00:00
|
|
|
// TruncateHead discards all but the first n ancient data from the ancient store.
|
|
|
|
func (d *database) TruncateHead(n uint64) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// TruncateTail discards the first n ancient data from the ancient store.
|
|
|
|
func (d *database) TruncateTail(n uint64) error {
|
2022-01-18 06:23:01 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *database) Sync() error {
|
|
|
|
return d.ethDB.Sync()
|
|
|
|
}
|
|
|
|
|
2022-05-18 12:05:30 +00:00
|
|
|
// MigrateTable processes and migrates entries of a given table to a new format.
|
|
|
|
func (d *database) MigrateTable(string, func([]byte) ([]byte, error)) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-18 06:23:01 +00:00
|
|
|
func (d *database) NewBatch() ethdb.Batch {
|
|
|
|
return d.ethDB.NewBatch()
|
|
|
|
}
|
|
|
|
|
2022-05-18 12:05:30 +00:00
|
|
|
// NewBatchWithSize creates a write-only database batch with pre-allocated buffer.
|
|
|
|
func (d *database) NewBatchWithSize(size int) ethdb.Batch {
|
|
|
|
return d.ethDB.NewBatchWithSize(size)
|
|
|
|
}
|
|
|
|
|
2022-06-03 13:28:02 +00:00
|
|
|
func (d *database) ReadAncients(fn func(ethdb.AncientReaderOp) error) (err error) {
|
2022-01-18 06:23:01 +00:00
|
|
|
return d.ethDB.ReadAncients(fn)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *database) Close() error {
|
|
|
|
return d.ethDB.Close()
|
|
|
|
}
|
2022-05-18 12:05:30 +00:00
|
|
|
|
|
|
|
// NewSnapshot creates a database snapshot based on the current state.
|
|
|
|
func (d *database) NewSnapshot() (ethdb.Snapshot, error) {
|
|
|
|
return d.NewSnapshot()
|
|
|
|
}
|
2022-06-03 13:28:02 +00:00
|
|
|
|
|
|
|
// NewSnapshot creates a database snapshot based on the current state.
|
|
|
|
func (d *database) AncientDatadir() (string, error) {
|
|
|
|
return "", errNotSupported
|
|
|
|
}
|