Skip to content

Commit

Permalink
Merge pull request #290 from scorpioborn/feature/reward-validation
Browse files Browse the repository at this point in the history
Feature / Reward grant validations
  • Loading branch information
3eyedraga authored Nov 9, 2023
2 parents 3bb2898 + c66c5ad commit c2edd78
Show file tree
Hide file tree
Showing 12 changed files with 327 additions and 611 deletions.
5 changes: 3 additions & 2 deletions x/reward/keeper/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
)

// DistributeRewards distributes the rewards according to the input distribution list.
func (k Keeper) DistributeRewards(ctx sdk.Context, funderAddr string, receiver types.Receiver) error {
func (k Keeper) DistributeRewards(ctx sdk.Context, receiver types.Receiver) error {
if receiver.SubAccountAmount.GT(sdk.ZeroInt()) {
if _, err := k.subaccountKeeper.TopUp(ctx, funderAddr, receiver.MainAccountAddr,
moduleAccAddr := types.RewardPoolFunder{}.GetModuleAcc()
if _, err := k.subaccountKeeper.TopUp(ctx, k.accountKeeper.GetModuleAddress(moduleAccAddr).String(), receiver.MainAccountAddr,
[]subaccounttypes.LockedBalance{
{
UnlockTS: uint64(ctx.BlockTime().Unix()) + receiver.UnlockPeriod,
Expand Down
2 changes: 2 additions & 0 deletions x/reward/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type (
memKey storetypes.StoreKey
paramstore paramtypes.Subspace
modFunder *utils.ModuleAccFunder
accountKeeper types.AccountKeeper
authzKeeper types.AuthzKeeper
betKeeper types.BetKeeper
ovmKeeper types.OVMKeeper
Expand Down Expand Up @@ -60,6 +61,7 @@ func NewKeeper(
expectedKeepers.AccountKeeper,
types.ErrorBank,
),
accountKeeper: expectedKeepers.AccountKeeper,
betKeeper: betKeeper,
ovmKeeper: ovmKeeper,
subaccountKeeper: subaccountKeeper,
Expand Down
2 changes: 1 addition & 1 deletion x/reward/keeper/msg_server_campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (k msgServer) CreateCampaign(goCtx context.Context, msg *types.MsgCreateCam
return nil, err
}

err = rewardFactory.VaidateCampaign(campaign)
err = rewardFactory.VaidateCampaign(campaign, uint64(ctx.BlockTime().Unix()))
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions x/reward/keeper/msg_server_reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (k msgServer) GrantReward(goCtx context.Context, msg *types.MsgGrantReward)
return nil, types.ErrInsufficientPoolBalance
}

if err := k.DistributeRewards(ctx, campaign.Promoter, recevier); err != nil {
if err := k.DistributeRewards(ctx, recevier); err != nil {
return nil, sdkerrors.Wrapf(types.ErrInDistributionOfRewards, "%s", err)
}

Expand All @@ -62,7 +62,7 @@ func (k msgServer) GrantReward(goCtx context.Context, msg *types.MsgGrantReward)
msg.Uid, msg.Creator, recevier.MainAccountAddr,
msg.CampaignUid, campaign.RewardAmount,
rewardCommon.SourceUID,
"",
rewardCommon.Meta,
))
k.SetRewardByReceiver(ctx, types.NewRewardByCategory(msg.Uid, recevier.MainAccountAddr, campaign.RewardCategory))
k.SetRewardByCampaign(ctx, types.NewRewardByCampaign(msg.Uid, campaign.UID))
Expand Down
Loading

0 comments on commit c2edd78

Please sign in to comment.