cosmos-sdk/store/cachemultistore.go

85 lines
2.0 KiB
Go
Raw Normal View History

2017-12-01 08:52:54 -08:00
package store
import dbm "github.com/tendermint/tmlibs/db"
//----------------------------------------
// cacheMultiStore
2017-12-03 22:55:15 -08:00
// cacheMultiStore holds many cache-wrapped stores.
2017-12-01 08:52:54 -08:00
// Implements MultiStore.
type cacheMultiStore struct {
2017-12-04 00:23:10 -08:00
db dbm.CacheDB
curVersion int64
2017-12-01 08:52:54 -08:00
lastCommitID CommitID
2017-12-04 00:56:25 -08:00
substores map[string]CacheWrap
2017-12-01 08:52:54 -08:00
}
2017-12-04 00:23:10 -08:00
func newCacheMultiStoreFromRMS(rms *rootMultiStore) cacheMultiStore {
2017-12-01 08:52:54 -08:00
cms := cacheMultiStore{
2017-12-04 00:23:10 -08:00
db: rms.db.CacheDB(),
curVersion: rms.curVersion,
lastCommitID: rms.lastCommitID,
2017-12-04 00:56:25 -08:00
substores: make(map[string]CacheWrap, len(rms.substores)),
2017-12-04 00:23:10 -08:00
}
for name, substore := range rms.substores {
2017-12-04 00:56:25 -08:00
cms.substores[name] = substore.CacheWrap()
2017-12-04 00:23:10 -08:00
}
return cms
}
func newCacheMultiStoreFromCMS(cms cacheMultiStore) cacheMultiStore {
2017-12-04 00:56:25 -08:00
cms2 := cacheMultiStore{
2017-12-04 00:23:10 -08:00
db: cms.db.CacheDB(),
curVersion: cms.curVersion,
lastCommitID: cms.lastCommitID,
2017-12-04 00:56:25 -08:00
substores: make(map[string]CacheWrap, len(cms.substores)),
2017-12-01 08:52:54 -08:00
}
2017-12-04 00:56:25 -08:00
for name, substore := range cms.substores {
cms2.substores[name] = substore.CacheWrap()
2017-12-01 08:52:54 -08:00
}
2017-12-04 00:56:25 -08:00
return cms2
2017-12-01 08:52:54 -08:00
}
// Implements CacheMultiStore
func (cms cacheMultiStore) LastCommitID() CommitID {
return cms.lastCommitID
}
// Implements CacheMultiStore
func (cms cacheMultiStore) CurrentVersion() int64 {
2017-12-04 00:23:10 -08:00
return cms.curVersion
2017-12-01 08:52:54 -08:00
}
// Implements CacheMultiStore
func (cms cacheMultiStore) Write() {
cms.db.Write()
2017-12-04 00:23:10 -08:00
for _, substore := range cms.substores {
2017-12-03 15:01:17 -08:00
substore.Write()
2017-12-01 08:52:54 -08:00
}
}
2017-12-04 00:56:25 -08:00
// Implements CacheMultiStore
func (cms cacheMultiStore) CacheWrap() CacheWrap {
return cms.CacheMultiStore()
}
2017-12-01 08:52:54 -08:00
// Implements CacheMultiStore
2017-12-04 00:23:10 -08:00
func (cms cacheMultiStore) CacheMultiStore() CacheMultiStore {
return newCacheMultiStoreFromCMS(cms)
2017-12-01 08:52:54 -08:00
}
// Implements CacheMultiStore
2017-12-04 00:56:25 -08:00
func (cms cacheMultiStore) GetStore(name string) interface{} {
return cms.substores[name]
2017-12-01 08:52:54 -08:00
}
// Implements CacheMultiStore
2017-12-04 00:23:10 -08:00
func (cms cacheMultiStore) GetKVStore(name string) KVStore {
2017-12-04 00:56:25 -08:00
return cms.substores[name].(KVStore)
2017-12-01 08:52:54 -08:00
}
// Implements CacheMultiStore
2017-12-04 00:23:10 -08:00
func (cms cacheMultiStore) GetIterKVStore(name string) IterKVStore {
2017-12-04 00:56:25 -08:00
return cms.substores[name].(IterKVStore)
2017-12-01 08:52:54 -08:00
}