github.com/intfoundation/intchain@v0.0.0-20220727031208-4316ad31ca73/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/intfoundation/intchain/intdb"
    21  	"github.com/intfoundation/intchain/intdb/leveldb"
    22  	"github.com/intfoundation/intchain/intdb/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 intdb.KeyValueStore) intdb.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() intdb.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) intdb.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) (intdb.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  }