Lorenz Herzberger 94830df5fc
184 implement staged claim (#190)
* adjust issuePoPRewards to mint stagedCRDDL
* add GetChallengeRange
* add resolveStagedClaims on ReissueRDDLResult msg
* move claim resolve to distribution result
* add StagedDenom and ClaimDenom to config
* added the prepare4linting.sh script
* renamed PoPEpochs to PopEpochs
* renamed DistributionAddressPoP to DistributionAddressPop
* added config value ReIssuanceEpochs
* detached the re-issuance from the distribution process and schedule them independently
* changed logging messages
* added an explicit util/kv_serialize.go file to have all KV serialization done
* switched to Bigendian serialization of int64 to have the ordered list on the kvstore
* added ComputeReIssuanceValue to enable re-issuances once a day or defined by ReIssuanceEpoch
* integrated a ReIssuanceValue computation test case
* adjusted the challenges test cases to be epoch-dependent
* added ReIssuances per ReIssuanceEpoch
* extended the Reissue message
* checking ReIssuanceProposal in the ante handler
* added precision setter for the UINT to RDDL token converter (and test cases)
* add e2e test case for pop rewards


Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
Co-authored-by: Jürgen Eckel <juergen@riddleandcode.com>
2023-12-05 10:51:06 +01:00

104 lines
3.7 KiB
Go

package keeper
import (
"github.com/planetmint/planetmint-go/util"
"github.com/planetmint/planetmint-go/x/machine/types"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func (k Keeper) StoreMachine(ctx sdk.Context, machine types.Machine) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.MachineKey))
appendValue := k.cdc.MustMarshal(&machine)
store.Set(util.SerializeString(machine.IssuerPlanetmint), appendValue)
}
func (k Keeper) GetMachine(ctx sdk.Context, index types.MachineIndex) (val types.Machine, found bool) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.MachineKey))
machine := store.Get(util.SerializeString(index.IssuerPlanetmint))
if machine == nil {
return val, false
}
if err := k.cdc.Unmarshal(machine, &val); err != nil {
return val, false
}
return val, true
}
func (k Keeper) StoreMachineIndex(ctx sdk.Context, machine types.Machine) {
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))
addressIndexStore := prefix.NewStore(ctx.KVStore(k.addressIndexStoreKey), types.KeyPrefix(types.AddressIndexKey))
index := types.MachineIndex{
MachineId: machine.MachineId,
IssuerPlanetmint: machine.IssuerPlanetmint,
IssuerLiquid: machine.IssuerLiquid,
Address: machine.Address,
}
machineIDIndexKey := util.SerializeString(machine.MachineId)
issuerPlanetmintIndexKey := util.SerializeString(machine.IssuerPlanetmint)
issuerLiquidIndexKey := util.SerializeString(machine.IssuerLiquid)
addressIndexKey := util.SerializeString(machine.Address)
indexAppendValue := k.cdc.MustMarshal(&index)
taIndexStore.Set(machineIDIndexKey, indexAppendValue)
issuerPlanetmintIndexStore.Set(issuerPlanetmintIndexKey, indexAppendValue)
issuerLiquidIndexStore.Set(issuerLiquidIndexKey, indexAppendValue)
addressIndexStore.Set(addressIndexKey, indexAppendValue)
}
func (k Keeper) GetMachineIndexByPubKey(ctx sdk.Context, pubKey string) (val types.MachineIndex, found bool) {
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))
keyBytes := util.SerializeString(pubKey)
taIndex := taIndexStore.Get(keyBytes)
if taIndex != nil {
if err := k.cdc.Unmarshal(taIndex, &val); err != nil {
return val, false
}
return val, true
}
ipIndex := issuerPlanetmintIndexStore.Get(keyBytes)
if ipIndex != nil {
if err := k.cdc.Unmarshal(ipIndex, &val); err != nil {
return val, false
}
return val, true
}
ilIndex := issuerLiquidIndexStore.Get(keyBytes)
if ilIndex != nil {
if err := k.cdc.Unmarshal(ilIndex, &val); err != nil {
return val, false
}
return val, true
}
return val, false
}
func (k Keeper) GetMachineIndexByAddress(ctx sdk.Context, address string) (val types.MachineIndex, found bool) {
addressIndexStore := prefix.NewStore(ctx.KVStore(k.addressIndexStoreKey), types.KeyPrefix(types.AddressIndexKey))
keyBytes := util.SerializeString(address)
adIndex := addressIndexStore.Get(keyBytes)
if adIndex != nil {
if err := k.cdc.Unmarshal(adIndex, &val); err != nil {
return val, false
}
return val, true
}
return val, false
}