github.com/Finschia/finschia-sdk@v0.48.1/store/mem/store.go (about)

     1  package mem
     2  
     3  import (
     4  	"io"
     5  
     6  	dbm "github.com/tendermint/tm-db"
     7  
     8  	"github.com/Finschia/finschia-sdk/store/cachekv"
     9  	"github.com/Finschia/finschia-sdk/store/dbadapter"
    10  	"github.com/Finschia/finschia-sdk/store/listenkv"
    11  	"github.com/Finschia/finschia-sdk/store/tracekv"
    12  	"github.com/Finschia/finschia-sdk/store/types"
    13  )
    14  
    15  var (
    16  	_ types.KVStore   = (*Store)(nil)
    17  	_ types.Committer = (*Store)(nil)
    18  )
    19  
    20  // Store implements an in-memory only KVStore. Entries are persisted between
    21  // commits and thus between blocks. State in Memory store is not committed as part of app state but maintained privately by each node
    22  type Store struct {
    23  	dbadapter.Store
    24  }
    25  
    26  func NewStore() *Store {
    27  	return NewStoreWithDB(dbm.NewMemDB())
    28  }
    29  
    30  func NewStoreWithDB(db *dbm.MemDB) *Store { //nolint: interfacer
    31  	return &Store{Store: dbadapter.Store{DB: db}}
    32  }
    33  
    34  // GetStoreType returns the Store's type.
    35  func (s Store) GetStoreType() types.StoreType {
    36  	return types.StoreTypeMemory
    37  }
    38  
    39  // CacheWrap branches the underlying store.
    40  func (s Store) CacheWrap() types.CacheWrap {
    41  	return cachekv.NewStore(s)
    42  }
    43  
    44  // CacheWrapWithTrace implements KVStore.
    45  func (s Store) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.CacheWrap {
    46  	return cachekv.NewStore(tracekv.NewStore(s, w, tc))
    47  }
    48  
    49  // CacheWrapWithListeners implements the CacheWrapper interface.
    50  func (s Store) CacheWrapWithListeners(storeKey types.StoreKey, listeners []types.WriteListener) types.CacheWrap {
    51  	return cachekv.NewStore(listenkv.NewStore(s, storeKey, listeners))
    52  }
    53  
    54  // Commit performs a no-op as entries are persistent between commitments.
    55  func (s *Store) Commit() (id types.CommitID) { return }
    56  
    57  func (s *Store) SetPruning(pruning types.PruningOptions) {}
    58  
    59  // GetPruning is a no-op as pruning options cannot be directly set on this store.
    60  // They must be set on the root commit multi-store.
    61  func (s *Store) GetPruning() types.PruningOptions { return types.PruningOptions{} }
    62  
    63  func (s Store) LastCommitID() (id types.CommitID) { return }