github.com/MetalBlockchain/subnet-evm@v0.4.9/ethdb/database.go (about)

     1  // (c) 2020-2021, Ava Labs, Inc.
     2  //
     3  // This file is a derived work, based on the go-ethereum library whose original
     4  // notices appear below.
     5  //
     6  // It is distributed under a license compatible with the licensing terms of the
     7  // original code from which it is derived.
     8  //
     9  // Much love to the original authors for their work.
    10  // **********
    11  // Copyright 2014 The go-ethereum Authors
    12  // This file is part of the go-ethereum library.
    13  //
    14  // The go-ethereum library is free software: you can redistribute it and/or modify
    15  // it under the terms of the GNU Lesser General Public License as published by
    16  // the Free Software Foundation, either version 3 of the License, or
    17  // (at your option) any later version.
    18  //
    19  // The go-ethereum library is distributed in the hope that it will be useful,
    20  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    21  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    22  // GNU Lesser General Public License for more details.
    23  //
    24  // You should have received a copy of the GNU Lesser General Public License
    25  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    26  
    27  // Package ethdb defines the interfaces for an Ethereum data store.
    28  package ethdb
    29  
    30  import "io"
    31  
    32  // KeyValueReader wraps the Has and Get method of a backing data store.
    33  type KeyValueReader interface {
    34  	// Has retrieves if a key is present in the key-value data store.
    35  	Has(key []byte) (bool, error)
    36  
    37  	// Get retrieves the given key if it's present in the key-value data store.
    38  	Get(key []byte) ([]byte, error)
    39  }
    40  
    41  // KeyValueWriter wraps the Put method of a backing data store.
    42  type KeyValueWriter interface {
    43  	// Put inserts the given value into the key-value data store.
    44  	Put(key []byte, value []byte) error
    45  
    46  	// Delete removes the key from the key-value data store.
    47  	Delete(key []byte) error
    48  }
    49  
    50  // Stater wraps the Stat method of a backing data store.
    51  type Stater interface {
    52  	// Stat returns a particular internal stat of the database.
    53  	Stat(property string) (string, error)
    54  }
    55  
    56  // Compacter wraps the Compact method of a backing data store.
    57  type Compacter interface {
    58  	// Compact flattens the underlying data store for the given key range. In essence,
    59  	// deleted and overwritten versions are discarded, and the data is rearranged to
    60  	// reduce the cost of operations needed to access them.
    61  	//
    62  	// A nil start is treated as a key before all keys in the data store; a nil limit
    63  	// is treated as a key after all keys in the data store. If both is nil then it
    64  	// will compact entire data store.
    65  	Compact(start []byte, limit []byte) error
    66  }
    67  
    68  // KeyValueStore contains all the methods required to allow handling different
    69  // key-value data stores backing the high level database.
    70  type KeyValueStore interface {
    71  	KeyValueReader
    72  	KeyValueWriter
    73  	Batcher
    74  	Iteratee
    75  	Stater
    76  	Compacter
    77  	io.Closer
    78  }
    79  
    80  // Reader contains the methods required to read data from key-value storage.
    81  type Reader interface {
    82  	KeyValueReader
    83  }
    84  
    85  // Writer contains the methods required to write data to key-value storage.
    86  type Writer interface {
    87  	KeyValueWriter
    88  }
    89  
    90  // Database contains all the methods required by the high level database to not
    91  // only access the key-value data store but also the chain freezer.
    92  type Database interface {
    93  	Reader
    94  	Writer
    95  	Batcher
    96  	Iteratee
    97  	Stater
    98  	Compacter
    99  	io.Closer
   100  }