Skip to content

Commit

Permalink
working state
Browse files Browse the repository at this point in the history
  • Loading branch information
P-U-D-G-E committed Nov 7, 2023
1 parent ced9be5 commit 9156b40
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 93 deletions.
4 changes: 4 additions & 0 deletions x/reward/keeper/msg_server_campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 113 in x/reward/keeper/msg_server_campaign.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

return both the `nil` error and invalid value: use a sentinel error instead (nilnil)
}
20 changes: 10 additions & 10 deletions x/reward/keeper/msg_server_reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

Expand Down
23 changes: 2 additions & 21 deletions x/reward/keeper/query_reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 90 in x/reward/keeper/query_reward.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

return both the `nil` error and invalid value: use a sentinel error instead (nilnil)
}

func (k Keeper) RewardsByCampaign(goCtx context.Context, req *types.QueryRewardsByCampaignRequest) (*types.QueryRewardsByCampaignResponse, error) {
Expand Down
30 changes: 0 additions & 30 deletions x/reward/keeper/reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
52 changes: 26 additions & 26 deletions x/reward/types/reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 0 additions & 3 deletions x/reward/types/reward_signup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
6 changes: 3 additions & 3 deletions x/reward/types/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()) &&
Expand Down

0 comments on commit 9156b40

Please sign in to comment.