|
| 1 | +// Copyright 2021 The go-ethereum Authors |
| 2 | +// This file is part of the go-ethereum library. |
| 3 | +// |
| 4 | +// The go-ethereum library is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU Lesser General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// The go-ethereum library is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU Lesser General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU Lesser General Public License |
| 15 | +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +//go:build js |
| 18 | +// +build js |
| 19 | + |
| 20 | +// Package leveldb implements the key-value database layer based on LevelDB. |
| 21 | +package leveldb |
| 22 | + |
| 23 | +import ( |
| 24 | + "errors" |
| 25 | + |
| 26 | + "github.com/ethereum/go-ethereum/ethdb" |
| 27 | +) |
| 28 | + |
| 29 | +type Database struct { |
| 30 | + unconstructable struct{} |
| 31 | +} |
| 32 | + |
| 33 | +// New returns a wrapped LevelDB object. The namespace is the prefix that the |
| 34 | +// metrics reporting should use for surfacing internal stats. |
| 35 | +func New(file string, cache int, handles int, namespace string, readonly bool) (*Database, error) { |
| 36 | + return nil, errors.New("leveldb is unavailable on JS platforms") |
| 37 | +} |
| 38 | + |
| 39 | +/* |
| 40 | +// NewCustom returns a wrapped LevelDB object. The namespace is the prefix that the |
| 41 | +// metrics reporting should use for surfacing internal stats. |
| 42 | +// The customize function allows the caller to modify the leveldb options. |
| 43 | +func NewCustom(file string, namespace string, customize func(options *opt.Options)) (*Database, error) { |
| 44 | + return nil, errors.New("leveldb is unavailable on JS platforms") |
| 45 | +} |
| 46 | +
|
| 47 | +// configureOptions sets some default options, then runs the provided setter. |
| 48 | +func configureOptions(customizeFn func(*opt.Options)) *opt.Options { |
| 49 | + // Set default options |
| 50 | + options := &opt.Options{ |
| 51 | + Filter: filter.NewBloomFilter(10), |
| 52 | + DisableSeeksCompaction: true, |
| 53 | + } |
| 54 | + // Allow caller to make custom modifications to the options |
| 55 | + if customizeFn != nil { |
| 56 | + customizeFn(options) |
| 57 | + } |
| 58 | + return options |
| 59 | +} |
| 60 | +*/ |
| 61 | + |
| 62 | +// Close stops the metrics collection, flushes any pending data to disk and closes |
| 63 | +// all io accesses to the underlying key-value store. |
| 64 | +func (db *Database) Close() error { |
| 65 | + panic("Method called on unconstructable leveldb database") |
| 66 | +} |
| 67 | + |
| 68 | +// Has retrieves if a key is present in the key-value store. |
| 69 | +func (db *Database) Has(key []byte) (bool, error) { |
| 70 | + panic("Method called on unconstructable leveldb database") |
| 71 | +} |
| 72 | + |
| 73 | +// Get retrieves the given key if it's present in the key-value store. |
| 74 | +func (db *Database) Get(key []byte) ([]byte, error) { |
| 75 | + panic("Method called on unconstructable leveldb database") |
| 76 | +} |
| 77 | + |
| 78 | +// Put inserts the given value into the key-value store. |
| 79 | +func (db *Database) Put(key []byte, value []byte) error { |
| 80 | + panic("Method called on unconstructable leveldb database") |
| 81 | +} |
| 82 | + |
| 83 | +// Delete removes the key from the key-value store. |
| 84 | +func (db *Database) Delete(key []byte) error { |
| 85 | + panic("Method called on unconstructable leveldb database") |
| 86 | +} |
| 87 | + |
| 88 | +// NewBatch creates a write-only key-value store that buffers changes to its host |
| 89 | +// database until a final write is called. |
| 90 | +func (db *Database) NewBatch() ethdb.Batch { |
| 91 | + panic("Method called on unconstructable leveldb database") |
| 92 | +} |
| 93 | + |
| 94 | +// NewIterator creates a binary-alphabetical iterator over a subset |
| 95 | +// of database content with a particular key prefix, starting at a particular |
| 96 | +// initial key (or after, if it does not exist). |
| 97 | +func (db *Database) NewIterator(prefix []byte, start []byte) ethdb.Iterator { |
| 98 | + panic("Method called on unconstructable leveldb database") |
| 99 | +} |
| 100 | + |
| 101 | +// Stat returns a particular internal stat of the database. |
| 102 | +func (db *Database) Stat(property string) (string, error) { |
| 103 | + panic("Method called on unconstructable leveldb database") |
| 104 | +} |
| 105 | + |
| 106 | +// Compact flattens the underlying data store for the given key range. In essence, |
| 107 | +// deleted and overwritten versions are discarded, and the data is rearranged to |
| 108 | +// reduce the cost of operations needed to access them. |
| 109 | +// |
| 110 | +// A nil start is treated as a key before all keys in the data store; a nil limit |
| 111 | +// is treated as a key after all keys in the data store. If both is nil then it |
| 112 | +// will compact entire data store. |
| 113 | +func (db *Database) Compact(start []byte, limit []byte) error { |
| 114 | + panic("Method called on unconstructable leveldb database") |
| 115 | +} |
| 116 | + |
| 117 | +// Path returns the path to the database directory. |
| 118 | +func (db *Database) Path() string { |
| 119 | + panic("Method called on unconstructable leveldb database") |
| 120 | +} |
0 commit comments