mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-09-13 20:00:10 +00:00

* 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>
86 lines
2.4 KiB
Go
86 lines
2.4 KiB
Go
package keeper
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
errorsmod "cosmossdk.io/errors"
|
|
"cosmossdk.io/math"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/planetmint/planetmint-go/config"
|
|
"github.com/planetmint/planetmint-go/x/dao/types"
|
|
)
|
|
|
|
func (k msgServer) DistributionResult(goCtx context.Context, msg *types.MsgDistributionResult) (*types.MsgDistributionResultResponse, error) {
|
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
|
|
distribution, found := k.LookupDistributionOrder(ctx, msg.GetLastPop())
|
|
if found {
|
|
distribution.DaoTxID = msg.DaoTxID
|
|
distribution.PopTxID = msg.PopTxID
|
|
distribution.InvestorTxID = msg.InvestorTxID
|
|
err := k.resolveStagedClaims(ctx, distribution.FirstPop, distribution.LastPop)
|
|
if err != nil {
|
|
return nil, errorsmod.Wrapf(types.ErrResolvingStagedClaims, " for provieded PoP heights: %d %d", distribution.FirstPop, distribution.LastPop)
|
|
}
|
|
k.StoreDistributionOrder(ctx, distribution)
|
|
} else {
|
|
return nil, errorsmod.Wrapf(types.ErrDistributionNotFound, " for provided block height %s", strconv.FormatInt(msg.GetLastPop(), 10))
|
|
}
|
|
|
|
return &types.MsgDistributionResultResponse{}, nil
|
|
}
|
|
|
|
func (k msgServer) resolveStagedClaims(ctx sdk.Context, start int64, end int64) (err error) {
|
|
// lookup all challenges since the last distribution
|
|
challenges, err := k.GetChallengeRange(ctx, start, end)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, challenge := range challenges {
|
|
err = k.convertClaim(ctx, challenge.Challengee)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = k.convertClaim(ctx, challenge.Challenger)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (k msgServer) convertClaim(ctx sdk.Context, addr string) (err error) {
|
|
cfg := config.GetConfig()
|
|
accAddress, err := sdk.AccAddressFromBech32(addr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
stagedClaim := k.bankKeeper.GetBalance(ctx, accAddress, cfg.StagedDenom)
|
|
|
|
if stagedClaim.Amount.GT(math.ZeroInt()) {
|
|
claim := sdk.NewCoins(sdk.NewCoin(cfg.ClaimDenom, stagedClaim.Amount))
|
|
err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, accAddress, types.ModuleName, sdk.NewCoins(stagedClaim))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = k.bankKeeper.BurnCoins(ctx, types.ModuleName, sdk.NewCoins(stagedClaim))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = k.bankKeeper.MintCoins(ctx, types.ModuleName, claim)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, accAddress, claim)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|