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(
|
app.MachineKeeper = *machinemodulekeeper.NewKeeper(
|
||||||
appCodec,
|
appCodec,
|
||||||
keys[machinemoduletypes.StoreKey],
|
keys[machinemoduletypes.StoreKey],
|
||||||
keys[machinemoduletypes.IndexKey],
|
keys[machinemoduletypes.TAIndexKey],
|
||||||
|
keys[machinemoduletypes.IssuerPlanetmintIndexKey],
|
||||||
|
keys[machinemoduletypes.IssuerLiquidIndexKey],
|
||||||
keys[machinemoduletypes.MemStoreKey],
|
keys[machinemoduletypes.MemStoreKey],
|
||||||
app.GetSubspace(machinemoduletypes.ModuleName),
|
app.GetSubspace(machinemoduletypes.ModuleName),
|
||||||
)
|
)
|
||||||
|
|||||||
@ -20,13 +20,17 @@ import (
|
|||||||
|
|
||||||
func MachineKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
|
func MachineKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
|
||||||
storeKey := sdk.NewKVStoreKey(types.StoreKey)
|
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)
|
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)
|
||||||
|
|
||||||
db := tmdb.NewMemDB()
|
db := tmdb.NewMemDB()
|
||||||
stateStore := store.NewCommitMultiStore(db)
|
stateStore := store.NewCommitMultiStore(db)
|
||||||
stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, 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)
|
stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil)
|
||||||
require.NoError(t, stateStore.LoadLatestVersion())
|
require.NoError(t, stateStore.LoadLatestVersion())
|
||||||
|
|
||||||
@ -42,7 +46,9 @@ func MachineKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
|
|||||||
k := keeper.NewKeeper(
|
k := keeper.NewKeeper(
|
||||||
cdc,
|
cdc,
|
||||||
storeKey,
|
storeKey,
|
||||||
indexStoreKey,
|
taIndexStoreKey,
|
||||||
|
issuerPlanetmintIndexStoreKey,
|
||||||
|
issuerLiquidIndexStoreKey,
|
||||||
memStoreKey,
|
memStoreKey,
|
||||||
paramsSubspace,
|
paramsSubspace,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -14,11 +14,13 @@ import (
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
Keeper struct {
|
Keeper struct {
|
||||||
cdc codec.BinaryCodec
|
cdc codec.BinaryCodec
|
||||||
storeKey storetypes.StoreKey
|
storeKey storetypes.StoreKey
|
||||||
indexStoreKey storetypes.StoreKey
|
taIndexStoreKey storetypes.StoreKey
|
||||||
memKey storetypes.StoreKey
|
issuerPlanetmintIndexStoreKey storetypes.StoreKey
|
||||||
paramstore paramtypes.Subspace
|
issuerLiquidIndexStoreKey storetypes.StoreKey
|
||||||
|
memKey storetypes.StoreKey
|
||||||
|
paramstore paramtypes.Subspace
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -26,6 +28,8 @@ func NewKeeper(
|
|||||||
cdc codec.BinaryCodec,
|
cdc codec.BinaryCodec,
|
||||||
storeKey,
|
storeKey,
|
||||||
indexStoreKey,
|
indexStoreKey,
|
||||||
|
issuerPlanetmintIndexStoreKey,
|
||||||
|
issuerLiquidIndexStoreKey,
|
||||||
memKey storetypes.StoreKey,
|
memKey storetypes.StoreKey,
|
||||||
ps paramtypes.Subspace,
|
ps paramtypes.Subspace,
|
||||||
|
|
||||||
@ -36,11 +40,13 @@ func NewKeeper(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &Keeper{
|
return &Keeper{
|
||||||
cdc: cdc,
|
cdc: cdc,
|
||||||
storeKey: storeKey,
|
storeKey: storeKey,
|
||||||
indexStoreKey: indexStoreKey,
|
taIndexStoreKey: indexStoreKey,
|
||||||
memKey: memKey,
|
issuerPlanetmintIndexStoreKey: issuerPlanetmintIndexStoreKey,
|
||||||
paramstore: ps,
|
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) {
|
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{
|
index := types.MachineIndex{
|
||||||
MachineId: machine.MachineId,
|
MachineId: machine.MachineId,
|
||||||
IssuerPlanetmint: machine.IssuerPlanetmint,
|
IssuerPlanetmint: machine.IssuerPlanetmint,
|
||||||
@ -42,21 +45,37 @@ func (k Keeper) StoreMachineIndex(ctx sdk.Context, machine types.Machine) {
|
|||||||
issuerPlanetmintIndexKey := GetMachineBytes(machine.IssuerPlanetmint)
|
issuerPlanetmintIndexKey := GetMachineBytes(machine.IssuerPlanetmint)
|
||||||
issuerLiquidIndexKey := GetMachineBytes(machine.IssuerLiquid)
|
issuerLiquidIndexKey := GetMachineBytes(machine.IssuerLiquid)
|
||||||
indexAppendValue := k.cdc.MustMarshal(&index)
|
indexAppendValue := k.cdc.MustMarshal(&index)
|
||||||
indexStore.Set(machineIdIndexKey, indexAppendValue)
|
taIndexStore.Set(machineIdIndexKey, indexAppendValue)
|
||||||
indexStore.Set(issuerPlanetmintIndexKey, indexAppendValue)
|
issuerPlanetmintIndexStore.Set(issuerPlanetmintIndexKey, indexAppendValue)
|
||||||
indexStore.Set(issuerLiquidIndexKey, indexAppendValue)
|
issuerLiquidIndexStore.Set(issuerLiquidIndexKey, indexAppendValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k Keeper) GetMachineIndex(ctx sdk.Context, pubKey string) (val types.MachineIndex, found bool) {
|
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))
|
taIndexStore := prefix.NewStore(ctx.KVStore(k.taIndexStoreKey), types.KeyPrefix(types.TAIndexKey))
|
||||||
index := indexStore.Get(GetMachineBytes(pubKey))
|
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 {
|
keyBytes := GetMachineBytes(pubKey)
|
||||||
return val, false
|
|
||||||
|
taIndex := taIndexStore.Get(keyBytes)
|
||||||
|
if taIndex != nil {
|
||||||
|
k.cdc.Unmarshal(taIndex, &val)
|
||||||
|
return val, true
|
||||||
}
|
}
|
||||||
|
|
||||||
k.cdc.Unmarshal(index, &val)
|
ipIndex := issuerPlanetmintIndexStore.Get(keyBytes)
|
||||||
return val, true
|
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 {
|
func GetMachineBytes(pubKey string) []byte {
|
||||||
|
|||||||
@ -15,7 +15,11 @@ const (
|
|||||||
|
|
||||||
MachineKey = "Machine/value/"
|
MachineKey = "Machine/value/"
|
||||||
|
|
||||||
IndexKey = "Machine/index/"
|
TAIndexKey = "Machine/TAIndex/"
|
||||||
|
|
||||||
|
IssuerPlanetmintIndexKey = "Machine/IssuerPlanetmintIndex/"
|
||||||
|
|
||||||
|
IssuerLiquidIndexKey = "Machine/IssuerLiquidIndex/"
|
||||||
)
|
)
|
||||||
|
|
||||||
func KeyPrefix(p string) []byte {
|
func KeyPrefix(p string) []byte {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user