-
Notifications
You must be signed in to change notification settings - Fork 1
/
store.go
67 lines (54 loc) · 1.3 KB
/
store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package mstore
import (
"fmt"
"github.com/cosmos/cosmos-sdk/store"
stypes "github.com/cosmos/cosmos-sdk/store/types"
dbm "github.com/tendermint/tendermint/libs/db"
)
const (
dbHome = "."
dbName = "sample"
)
var (
db dbm.DB
fcms stypes.ForkableCommitMultiStore
)
func InitStore() stypes.CommitID {
var err error
db, err = dbm.NewGoLevelDB(dbName, dbHome)
if err != nil {
panic(err)
}
fcms = store.NewForkableCommitMultiStore(db)
fcms.SetPruning(stypes.PruneSyncable)
return fcms.LastCommitID()
}
func CloseStore() stypes.CommitID {
status := fcms.LastCommitID()
db.Close()
return status
}
func CreateNewCommitKV(key stypes.StoreKey) {
fcms.MountStoreWithDB(key, stypes.StoreTypeIAVL, db)
fcms.LoadLatestVersion()
}
func GetCacheKV(key stypes.StoreKey) stypes.CacheKVStore {
wrapper := fcms.GetKVStore(key).CacheWrap()
cacheKV, ok := wrapper.(stypes.CacheKVStore)
if !ok {
panic(fmt.Errorf("Unsupported StoreType\n"))
}
return cacheKV
}
func GetCommitKV(key stypes.StoreKey) stypes.CommitKVStore {
return fcms.GetCommitKVStore(key)
}
func GetStoreRecoverSpot() stypes.CommitID {
return fcms.Commit()
}
func LoadStoreRecoverSpot(rev int64) error {
return fcms.LoadVersion(rev)
}
func LoadStoreRecoverSpotForOverwriting(rev int64) error {
return fcms.LoadVersionForOverwriting(rev)
}