diff --git a/x/reward/keeper/msg_server_campaign.go b/x/reward/keeper/msg_server_campaign.go index b7ff33a4..7bd01bfc 100644 --- a/x/reward/keeper/msg_server_campaign.go +++ b/x/reward/keeper/msg_server_campaign.go @@ -108,3 +108,7 @@ func (k msgServer) UpdateCampaign(goCtx context.Context, msg *types.MsgUpdateCam return &types.MsgUpdateCampaignResponse{}, nil } + +func (k msgServer) WithdrawFunds(goCtx context.Context, msg *types.MsgWithdrawFunds) (*types.MsgWithdrawFundsResponse, error) { + return nil, nil +} diff --git a/x/reward/keeper/msg_server_reward.go b/x/reward/keeper/msg_server_reward.go index 1483e334..f4438e99 100644 --- a/x/reward/keeper/msg_server_reward.go +++ b/x/reward/keeper/msg_server_reward.go @@ -27,7 +27,7 @@ func (k msgServer) GrantReward(goCtx context.Context, msg *types.MsgGrantReward) return nil, sdkerrors.Wrap(sdkerrtypes.ErrInvalidRequest, "failed to retrieve reward factory") } - recevier, rewardCommon, isSubAccount, oneTimeKey, err := rewardFactory.Calculate(goCtx, ctx, + recevier, _, isSubAccount, _, err := rewardFactory.Calculate(goCtx, ctx, types.RewardFactoryKeepers{ OVMKeeper: k.ovmKeeper, BetKeeper: k.betKeeper, @@ -46,15 +46,15 @@ func (k msgServer) GrantReward(goCtx context.Context, msg *types.MsgGrantReward) } k.UpdateCampaignPool(ctx, campaign, recevier) - k.SetReward(ctx, types.NewReward( - msg.Uid, msg.Creator, recevier.Addr, - msg.CampaignUid, campaign.RewardAmount, - rewardCommon.Source, rewardCommon.SourceCode, rewardCommon.SourceUID, - uint64(ctx.BlockTime().Unix()), - )) - k.SetOneTimeReward(ctx, types.NewOneTimeReward(oneTimeKey, campaign.RewardType)) - k.SetRewardByReceiver(ctx, types.NewRewardByType(msg.Uid, recevier.Addr, campaign.RewardType)) - k.SetRewardByCampaign(ctx, types.NewRewardByCampaign(msg.Uid, campaign.UID)) + // k.SetReward(ctx, types.NewReward( + // msg.Uid, msg.Creator, recevier.Addr, + // msg.CampaignUid, campaign.RewardAmount, + // rewardCommon.Source, rewardCommon.SourceCode, rewardCommon.SourceUID, + // uint64(ctx.BlockTime().Unix()), + // )) + // k.SetOneTimeReward(ctx, types.NewOneTimeReward(oneTimeKey, campaign.RewardType)) + // k.SetRewardByReceiver(ctx, types.NewRewardByType(msg.Uid, recevier.Addr, campaign.RewardType)) + // k.SetRewardByCampaign(ctx, types.NewRewardByCampaign(msg.Uid, campaign.UID)) msg.EmitEvent(&ctx, msg.CampaignUid, recevier) diff --git a/x/reward/keeper/query_reward.go b/x/reward/keeper/query_reward.go index 4af15da8..d6dc9b32 100644 --- a/x/reward/keeper/query_reward.go +++ b/x/reward/keeper/query_reward.go @@ -82,31 +82,12 @@ func (k Keeper) RewardsByAddress(goCtx context.Context, req *types.QueryRewardsB return &types.QueryRewardsByAddressResponse{Rewards: rewards, Pagination: pageRes}, nil } -func (k Keeper) RewardsByAddressAndType(goCtx context.Context, req *types.QueryRewardsByAddressAndTypeRequest) (*types.QueryRewardsByAddressAndTypeResponse, error) { +func (k Keeper) RewardsByAddressAndCategory(goCtx context.Context, req *types.QueryRewardsByAddressAndCategoryRequest) (*types.QueryRewardsByAddressAndCategoryResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } - var rewards []types.Reward - ctx := sdk.UnwrapSDKContext(goCtx) - - store := k.getRewardByReceiverAndTypeStore(ctx) - rewardStore := prefix.NewStore(store, types.GetRewardsByTypePrefix(req.Address, req.RewardType)) - - pageRes, err := query.Paginate(rewardStore, req.Pagination, func(key []byte, value []byte) error { - var reward types.Reward - if err := k.cdc.Unmarshal(value, &reward); err != nil { - return err - } - - rewards = append(rewards, reward) - return nil - }) - if err != nil { - return nil, status.Error(codes.Internal, err.Error()) - } - - return &types.QueryRewardsByAddressAndTypeResponse{Rewards: rewards, Pagination: pageRes}, nil + return nil, nil } func (k Keeper) RewardsByCampaign(goCtx context.Context, req *types.QueryRewardsByCampaignRequest) (*types.QueryRewardsByCampaignResponse, error) { diff --git a/x/reward/keeper/reward.go b/x/reward/keeper/reward.go index 40960468..9142d0c1 100644 --- a/x/reward/keeper/reward.go +++ b/x/reward/keeper/reward.go @@ -52,33 +52,3 @@ func (k Keeper) GetAllReward(ctx sdk.Context) (list []types.Reward) { return } - -// SetOneTimeReward set a specific record to track if a reward is already given or not. -func (k Keeper) SetOneTimeReward(ctx sdk.Context, oneTimeReward types.OneTimeReward) { - store := k.getRewardOneTimeStore(ctx) - b := k.cdc.MustMarshal(&oneTimeReward) - store.Set(types.GetOneTimeRewardsPrefix(oneTimeReward.RewardType, oneTimeReward.OneTimeKey), b) -} - -// HasOneTimeReward returns if the reward for the reward type is already given. -func (k Keeper) HasOneTimeReward( - ctx sdk.Context, - oneTimeReward types.OneTimeReward, -) bool { - store := k.getRewardOneTimeStore(ctx) - return store.Has(types.GetOneTimeRewardsPrefix(oneTimeReward.RewardType, oneTimeReward.OneTimeKey)) -} - -// SetOneTimeReward set a specific record to track if a reward is already given or not. -func (k Keeper) SetRewardByReceiver(ctx sdk.Context, rewByType types.RewardByType) { - store := k.getRewardByReceiverAndTypeStore(ctx) - b := k.cdc.MustMarshal(&rewByType) - store.Set(types.GetRewardsByTypeKey(rewByType.Addr, rewByType.RewardType, rewByType.UID), b) -} - -// SetOneTimeReward set a specific record to track if a reward is already given or not. -func (k Keeper) SetRewardByCampaign(ctx sdk.Context, rewByCampaign types.RewardByCampaign) { - store := k.getRewardsByCampaignStore(ctx) - b := k.cdc.MustMarshal(&rewByCampaign) - store.Set(types.GetRewardsByCampaignKey(rewByCampaign.CampaignUID, rewByCampaign.UID), b) -} diff --git a/x/reward/types/reward.go b/x/reward/types/reward.go index d7a04ced..a4a971c5 100644 --- a/x/reward/types/reward.go +++ b/x/reward/types/reward.go @@ -35,37 +35,37 @@ func NewReward( Receiver: receiver, CampaignUID: campaignUID, RewardAmount: rewardAmount, - Source: source, - SourceCode: sourceCode, - SourceUID: sourceID, - CreatedAt: blockTime, + // Source: source, + // SourceCode: sourceCode, + SourceUID: sourceID, + // CreatedAt: blockTime, } } -func NewOneTimeReward( - oneTimeKey string, - rewType RewardType, -) OneTimeReward { - return OneTimeReward{ - OneTimeKey: oneTimeKey, - RewardType: rewType, - } -} +// func NewOneTimeReward( +// oneTimeKey string, +// rewType RewardType, +// ) OneTimeReward { +// return OneTimeReward{ +// OneTimeKey: oneTimeKey, +// RewardType: rewType, +// } +// } -func NewRewardByType(uid, addr string, rewType RewardType) RewardByType { - return RewardByType{ - UID: uid, - RewardType: rewType, - Addr: addr, - } -} +// func NewRewardByType(uid, addr string, rewType RewardType) RewardByType { +// return RewardByType{ +// UID: uid, +// RewardType: rewType, +// Addr: addr, +// } +// } -func NewRewardByCampaign(uid, campaignUID string) RewardByCampaign { - return RewardByCampaign{ - UID: uid, - CampaignUID: campaignUID, - } -} +// func NewRewardByCampaign(uid, campaignUID string) RewardByCampaign { +// return RewardByCampaign{ +// UID: uid, +// CampaignUID: campaignUID, +// } +// } // IRewardFactory defines the methods that should be implemented for all reward types. type IRewardFactory interface { diff --git a/x/reward/types/reward_signup.go b/x/reward/types/reward_signup.go index c68b3775..b861de3c 100644 --- a/x/reward/types/reward_signup.go +++ b/x/reward/types/reward_signup.go @@ -19,9 +19,6 @@ func (sur SignUpReward) VaidateCampaign(campaign Campaign) error { if campaign.RewardCategory != RewardCategory_REWARD_CATEGORY_SIGNUP { return sdkerrors.Wrapf(ErrWrongRewardCategory, "signup rewards can only have single definition") } - if campaign.RewardAmount.MainAccountAmount.GT(sdkmath.ZeroInt()) { - return sdkerrors.Wrapf(ErrInvalidGranteeType, "signup rewards can be defined for subaccount only") - } if campaign.RewardAmount.SubaccountAmount.LTE(sdkmath.ZeroInt()) { return sdkerrors.Wrapf(ErrWrongAmountForType, "signup rewards for subaccount should be positive") } diff --git a/x/reward/types/ticket.go b/x/reward/types/ticket.go index 566245d5..d6c39ba5 100644 --- a/x/reward/types/ticket.go +++ b/x/reward/types/ticket.go @@ -32,9 +32,9 @@ func (payload *CreateCampaignPayload) Validate(blockTime uint64) error { return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "pool amount should be positive") } - if payload.RewardAmount.MainAccountAmount.GT(sdkmath.ZeroInt()) && - payload.RewardAmount.SubaccountAmount.GT(sdkmath.ZeroInt()) { - return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "reward amount should be set for main account or subaccount not both") + if payload.RewardAmount.MainAccountAmount.Equal(sdkmath.ZeroInt()) && + payload.RewardAmount.SubaccountAmount.Equal(sdkmath.ZeroInt()) { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "reward amount should be set for atleast one of main account or subaccount") } if payload.RewardAmount.SubaccountAmount.GT(sdkmath.ZeroInt()) &&