diff --git a/app/app.go b/app/app.go index fc6ba32..af08133 100644 --- a/app/app.go +++ b/app/app.go @@ -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), ) diff --git a/testutil/keeper/machine.go b/testutil/keeper/machine.go index 86970db..5e4a842 100644 --- a/testutil/keeper/machine.go +++ b/testutil/keeper/machine.go @@ -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, ) diff --git a/x/machine/keeper/keeper.go b/x/machine/keeper/keeper.go index 19ac520..a7b5aa4 100644 --- a/x/machine/keeper/keeper.go +++ b/x/machine/keeper/keeper.go @@ -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, } } diff --git a/x/machine/keeper/machine.go b/x/machine/keeper/machine.go index adcc930..0f972c5 100644 --- a/x/machine/keeper/machine.go +++ b/x/machine/keeper/machine.go @@ -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 { diff --git a/x/machine/types/keys.go b/x/machine/types/keys.go index ec9ea83..d1c7455 100644 --- a/x/machine/types/keys.go +++ b/x/machine/types/keys.go @@ -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 {