cosmos-sdk/store/cachemultistore.go

67 lines
1.5 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 {
db dbm.DB
version int64
lastCommitID CommitID
2017-12-03 22:55:15 -08:00
substores map[string]CacheWriter
2017-12-01 08:52:54 -08:00
}
func newCacheMultiStore(rs *rootMultiStore) cacheMultiStore {
cms := cacheMultiStore{
2017-12-03 23:17:10 -08:00
db: rs.db.CacheDB(),
2017-12-03 15:01:17 -08:00
version: rs.curVersion,
2017-12-01 08:52:54 -08:00
lastCommitID: rs.lastCommitID,
2017-12-03 22:55:15 -08:00
substores: make(map[string]CacheWriter, len(rs.substores)),
2017-12-01 08:52:54 -08:00
}
for name, substore := range rs.substores {
2017-12-03 22:55:15 -08:00
cms.substores[name] = substore.CacheWrap().(CacheWriter)
2017-12-01 08:52:54 -08:00
}
return cms
}
// Implements CacheMultiStore
func (cms cacheMultiStore) LastCommitID() CommitID {
return cms.lastCommitID
}
// Implements CacheMultiStore
func (cms cacheMultiStore) CurrentVersion() int64 {
return cms.version
}
// Implements CacheMultiStore
func (cms cacheMultiStore) Write() {
cms.db.Write()
2017-12-03 15:01:17 -08:00
for substore := range cms.substores {
substore.Write()
2017-12-01 08:52:54 -08:00
}
}
// Implements CacheMultiStore
func (rs cacheMultiStore) CacheMultiStore() CacheMultiStore {
return newCacheMultiStore(rs)
}
// Implements CacheMultiStore
func (rs cacheMultiStore) GetCommitter(name string) Committer {
return rs.store[name]
}
// Implements CacheMultiStore
func (rs cacheMultiStore) GetKVStore(name string) KVStore {
return rs.store[name].(KVStore)
}
// Implements CacheMultiStore
func (rs cacheMultiStore) GetIterKVStore(name string) IterKVStore {
return rs.store[name].(IterKVStore)
}