mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-24 06:25:47 +00:00
split up index store
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
f5cdba9ed5
commit
0902ca5375
@ -515,7 +515,9 @@ func New(
|
||||
app.MachineKeeper = *machinemodulekeeper.NewKeeper(
|
||||
appCodec,
|
||||
keys[machinemoduletypes.StoreKey],
|
||||
keys[machinemoduletypes.IndexKey],
|
||||
keys[machinemoduletypes.TAIndexKey],
|
||||
keys[machinemoduletypes.IssuerPlanetmintIndexKey],
|
||||
keys[machinemoduletypes.IssuerLiquidIndexKey],
|
||||
keys[machinemoduletypes.MemStoreKey],
|
||||
app.GetSubspace(machinemoduletypes.ModuleName),
|
||||
)
|
||||
|
||||
@ -20,13 +20,17 @@ import (
|
||||
|
||||
func MachineKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
|
||||
storeKey := sdk.NewKVStoreKey(types.StoreKey)
|
||||
indexStoreKey := sdk.NewKVStoreKey(types.IndexKey)
|
||||
taIndexStoreKey := sdk.NewKVStoreKey(types.TAIndexKey)
|
||||
issuerPlanetmintIndexStoreKey := sdk.NewKVStoreKey(types.IssuerPlanetmintIndexKey)
|
||||
issuerLiquidIndexStoreKey := sdk.NewKVStoreKey(types.IssuerLiquidIndexKey)
|
||||
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)
|
||||
|
||||
db := tmdb.NewMemDB()
|
||||
stateStore := store.NewCommitMultiStore(db)
|
||||
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db)
|
||||
stateStore.MountStoreWithDB(indexStoreKey, storetypes.StoreTypeIAVL, db)
|
||||
stateStore.MountStoreWithDB(taIndexStoreKey, storetypes.StoreTypeIAVL, db)
|
||||
stateStore.MountStoreWithDB(issuerPlanetmintIndexStoreKey, storetypes.StoreTypeIAVL, db)
|
||||
stateStore.MountStoreWithDB(issuerLiquidIndexStoreKey, storetypes.StoreTypeIAVL, db)
|
||||
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil)
|
||||
require.NoError(t, stateStore.LoadLatestVersion())
|
||||
|
||||
@ -42,7 +46,9 @@ func MachineKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
|
||||
k := keeper.NewKeeper(
|
||||
cdc,
|
||||
storeKey,
|
||||
indexStoreKey,
|
||||
taIndexStoreKey,
|
||||
issuerPlanetmintIndexStoreKey,
|
||||
issuerLiquidIndexStoreKey,
|
||||
memStoreKey,
|
||||
paramsSubspace,
|
||||
)
|
||||
|
||||
@ -14,11 +14,13 @@ import (
|
||||
|
||||
type (
|
||||
Keeper struct {
|
||||
cdc codec.BinaryCodec
|
||||
storeKey storetypes.StoreKey
|
||||
indexStoreKey storetypes.StoreKey
|
||||
memKey storetypes.StoreKey
|
||||
paramstore paramtypes.Subspace
|
||||
cdc codec.BinaryCodec
|
||||
storeKey storetypes.StoreKey
|
||||
taIndexStoreKey storetypes.StoreKey
|
||||
issuerPlanetmintIndexStoreKey storetypes.StoreKey
|
||||
issuerLiquidIndexStoreKey storetypes.StoreKey
|
||||
memKey storetypes.StoreKey
|
||||
paramstore paramtypes.Subspace
|
||||
}
|
||||
)
|
||||
|
||||
@ -26,6 +28,8 @@ func NewKeeper(
|
||||
cdc codec.BinaryCodec,
|
||||
storeKey,
|
||||
indexStoreKey,
|
||||
issuerPlanetmintIndexStoreKey,
|
||||
issuerLiquidIndexStoreKey,
|
||||
memKey storetypes.StoreKey,
|
||||
ps paramtypes.Subspace,
|
||||
|
||||
@ -36,11 +40,13 @@ func NewKeeper(
|
||||
}
|
||||
|
||||
return &Keeper{
|
||||
cdc: cdc,
|
||||
storeKey: storeKey,
|
||||
indexStoreKey: indexStoreKey,
|
||||
memKey: memKey,
|
||||
paramstore: ps,
|
||||
cdc: cdc,
|
||||
storeKey: storeKey,
|
||||
taIndexStoreKey: indexStoreKey,
|
||||
issuerPlanetmintIndexStoreKey: issuerPlanetmintIndexStoreKey,
|
||||
issuerLiquidIndexStoreKey: issuerLiquidIndexStoreKey,
|
||||
memKey: memKey,
|
||||
paramstore: ps,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -31,7 +31,10 @@ func (k Keeper) GetMachine(ctx sdk.Context, pubKey string) (val types.Machine, f
|
||||
}
|
||||
|
||||
func (k Keeper) StoreMachineIndex(ctx sdk.Context, machine types.Machine) {
|
||||
indexStore := prefix.NewStore(ctx.KVStore(k.indexStoreKey), types.KeyPrefix(types.IndexKey))
|
||||
taIndexStore := prefix.NewStore(ctx.KVStore(k.taIndexStoreKey), types.KeyPrefix(types.TAIndexKey))
|
||||
issuerPlanetmintIndexStore := prefix.NewStore(ctx.KVStore(k.issuerPlanetmintIndexStoreKey), types.KeyPrefix(types.IssuerPlanetmintIndexKey))
|
||||
issuerLiquidIndexStore := prefix.NewStore(ctx.KVStore(k.issuerLiquidIndexStoreKey), types.KeyPrefix(types.IssuerLiquidIndexKey))
|
||||
|
||||
index := types.MachineIndex{
|
||||
MachineId: machine.MachineId,
|
||||
IssuerPlanetmint: machine.IssuerPlanetmint,
|
||||
@ -42,21 +45,37 @@ func (k Keeper) StoreMachineIndex(ctx sdk.Context, machine types.Machine) {
|
||||
issuerPlanetmintIndexKey := GetMachineBytes(machine.IssuerPlanetmint)
|
||||
issuerLiquidIndexKey := GetMachineBytes(machine.IssuerLiquid)
|
||||
indexAppendValue := k.cdc.MustMarshal(&index)
|
||||
indexStore.Set(machineIdIndexKey, indexAppendValue)
|
||||
indexStore.Set(issuerPlanetmintIndexKey, indexAppendValue)
|
||||
indexStore.Set(issuerLiquidIndexKey, indexAppendValue)
|
||||
taIndexStore.Set(machineIdIndexKey, indexAppendValue)
|
||||
issuerPlanetmintIndexStore.Set(issuerPlanetmintIndexKey, indexAppendValue)
|
||||
issuerLiquidIndexStore.Set(issuerLiquidIndexKey, indexAppendValue)
|
||||
}
|
||||
|
||||
func (k Keeper) GetMachineIndex(ctx sdk.Context, pubKey string) (val types.MachineIndex, found bool) {
|
||||
indexStore := prefix.NewStore(ctx.KVStore(k.indexStoreKey), types.KeyPrefix(types.IndexKey))
|
||||
index := indexStore.Get(GetMachineBytes(pubKey))
|
||||
taIndexStore := prefix.NewStore(ctx.KVStore(k.taIndexStoreKey), types.KeyPrefix(types.TAIndexKey))
|
||||
issuerPlanetmintIndexStore := prefix.NewStore(ctx.KVStore(k.issuerPlanetmintIndexStoreKey), types.KeyPrefix(types.IssuerPlanetmintIndexKey))
|
||||
issuerLiquidIndexStore := prefix.NewStore(ctx.KVStore(k.issuerLiquidIndexStoreKey), types.KeyPrefix(types.IssuerLiquidIndexKey))
|
||||
|
||||
if index == nil {
|
||||
return val, false
|
||||
keyBytes := GetMachineBytes(pubKey)
|
||||
|
||||
taIndex := taIndexStore.Get(keyBytes)
|
||||
if taIndex != nil {
|
||||
k.cdc.Unmarshal(taIndex, &val)
|
||||
return val, true
|
||||
}
|
||||
|
||||
k.cdc.Unmarshal(index, &val)
|
||||
return val, true
|
||||
ipIndex := issuerPlanetmintIndexStore.Get(keyBytes)
|
||||
if ipIndex != nil {
|
||||
k.cdc.Unmarshal(ipIndex, &val)
|
||||
return val, true
|
||||
}
|
||||
|
||||
ilIndex := issuerLiquidIndexStore.Get(keyBytes)
|
||||
if ilIndex != nil {
|
||||
k.cdc.Unmarshal(ilIndex, &val)
|
||||
return val, true
|
||||
}
|
||||
|
||||
return val, false
|
||||
}
|
||||
|
||||
func GetMachineBytes(pubKey string) []byte {
|
||||
|
||||
@ -15,7 +15,11 @@ const (
|
||||
|
||||
MachineKey = "Machine/value/"
|
||||
|
||||
IndexKey = "Machine/index/"
|
||||
TAIndexKey = "Machine/TAIndex/"
|
||||
|
||||
IssuerPlanetmintIndexKey = "Machine/IssuerPlanetmintIndex/"
|
||||
|
||||
IssuerLiquidIndexKey = "Machine/IssuerLiquidIndex/"
|
||||
)
|
||||
|
||||
func KeyPrefix(p string) []byte {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user