github.com/neatlab/neatio@v1.7.3-0.20220425043230-d903e92fcc75/chain/core/rawdb/database.go (about)

     1  // Copyright 2018 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  package rawdb
    18  
    19  import (
    20  	"github.com/neatlab/neatio/neatdb"
    21  	"github.com/neatlab/neatio/neatdb/leveldb"
    22  	"github.com/neatlab/neatio/neatdb/memorydb"
    23  )
    24  
    25  // NewDatabase creates a high level database on top of a given key-value data
    26  // store without a freezer moving immutable chain segments into cold storage.
    27  func NewDatabase(db neatdb.KeyValueStore) neatdb.Database {
    28  	return db
    29  }
    30  
    31  // NewMemoryDatabase creates an ephemeral in-memory key-value database without a
    32  // freezer moving immutable chain segments into cold storage.
    33  func NewMemoryDatabase() neatdb.Database {
    34  	return NewDatabase(memorydb.New())
    35  }
    36  
    37  // NewMemoryDatabaseWithCap creates an ephemeral in-memory key-value database with
    38  // an initial starting capacity, but without a freezer moving immutable chain
    39  // segments into cold storage.
    40  func NewMemoryDatabaseWithCap(size int) neatdb.Database {
    41  	return NewDatabase(memorydb.NewWithCap(size))
    42  }
    43  
    44  // NewLevelDBDatabase creates a persistent key-value database without a freezer
    45  // moving immutable chain segments into cold storage.
    46  func NewLevelDBDatabase(file string, cache int, handles int, namespace string) (neatdb.Database, error) {
    47  	db, err := leveldb.New(file, cache, handles, namespace)
    48  	if err != nil {
    49  		return nil, err
    50  	}
    51  	return NewDatabase(db), nil
    52  }