github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/store/mem/store.go (about)

     1  package mem
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/store/cachekv"
     7  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/store/listenkv"
     8  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/store/tracekv"
     9  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/store/types"
    10  	"github.com/fibonacci-chain/fbc/libs/iavl"
    11  	dbm "github.com/fibonacci-chain/fbc/libs/tm-db"
    12  
    13  	"github.com/fibonacci-chain/fbc/libs/cosmos-sdk/store/dbadapter"
    14  )
    15  
    16  var (
    17  	_ types.KVStore   = (*Store)(nil)
    18  	_ types.Committer = (*Store)(nil)
    19  )
    20  
    21  // Store implements an in-memory only KVStore. Entries are persisted between
    22  // commits and thus between blocks. State in Memory store is not committed as part of app state but maintained privately by each node
    23  type Store struct {
    24  	dbadapter.Store
    25  }
    26  
    27  func (s *Store) CommitterCommit(_ *iavl.TreeDelta) (_ types.CommitID, _ *iavl.TreeDelta) {
    28  	return
    29  }
    30  
    31  func (s *Store) GetDBReadTime() int {
    32  	return 0
    33  }
    34  
    35  func (s *Store) GetDBWriteCount() int {
    36  	return 0
    37  }
    38  
    39  func (s *Store) GetDBReadCount() int {
    40  	return 0
    41  }
    42  
    43  func (s *Store) GetNodeReadCount() int {
    44  	return 0
    45  }
    46  
    47  func (s *Store) GetFlatKVReadTime() int {
    48  	return 0
    49  }
    50  
    51  func (s *Store) GetFlatKVWriteTime() int {
    52  	return 0
    53  }
    54  
    55  func (s *Store) GetFlatKVReadCount() int {
    56  	return 0
    57  }
    58  
    59  func (s *Store) GetFlatKVWriteCount() int {
    60  	return 0
    61  }
    62  
    63  func (s *Store) ResetCount() {}
    64  
    65  func NewStore() *Store {
    66  	return NewStoreWithDB(dbm.NewMemDB())
    67  }
    68  
    69  func NewStoreWithDB(db *dbm.MemDB) *Store { // nolint: interfacer
    70  	return &Store{Store: dbadapter.Store{DB: db}}
    71  }
    72  
    73  // GetStoreType returns the Store's type.
    74  func (s Store) GetStoreType() types.StoreType {
    75  	return types.StoreTypeMemory
    76  }
    77  
    78  // CacheWrap branches the underlying store.
    79  func (s Store) CacheWrap() types.CacheWrap {
    80  	return cachekv.NewStore(s)
    81  }
    82  
    83  // CacheWrapWithTrace implements KVStore.
    84  func (s Store) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.CacheWrap {
    85  	return cachekv.NewStore(tracekv.NewStore(s, w, tc))
    86  }
    87  
    88  // CacheWrapWithListeners implements the CacheWrapper interface.
    89  func (s Store) CacheWrapWithListeners(storeKey types.StoreKey, listeners []types.WriteListener) types.CacheWrap {
    90  	return cachekv.NewStore(listenkv.NewStore(s, storeKey, listeners))
    91  }
    92  
    93  // Commit performs a no-op as entries are persistent between commitments.
    94  func (s *Store) Commit() (id types.CommitID) { return }
    95  
    96  func (s *Store) SetPruning(pruning types.PruningOptions) {}
    97  
    98  // GetPruning is a no-op as pruning options cannot be directly set on this store.
    99  // They must be set on the root commit multi-store.
   100  func (s *Store) GetPruning() types.PruningOptions { return types.PruningOptions{} }
   101  
   102  func (s Store) LastCommitID() (id types.CommitID) { return }
   103  func (s Store) LastCommitVersion() (v int64)      { return }
   104  func (s *Store) SetUpgradeVersion(int64)          {}