diff --git a/proto/sge/reward/campaign.proto b/proto/sge/reward/campaign.proto index 808352c2..4577d0af 100644 --- a/proto/sge/reward/campaign.proto +++ b/proto/sge/reward/campaign.proto @@ -60,6 +60,9 @@ message Campaign { // cap_count is the maximum allowed grant for a certain account. uint64 cap_count = 14; + + // constraints is the constrains of a campaign. + CampaignConstraints constraints = 15; } // Pool tracks funds assigned and spent to/for a campaign. @@ -79,4 +82,13 @@ message Pool { (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"spent\"" ]; +} + +// CampaignConstraints contains campaign constraints and criteria. +message CampaignConstraints { + string max_bet_amount = 1 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"max_bet_amount\"" + ]; } \ No newline at end of file diff --git a/proto/sge/reward/ticket.proto b/proto/sge/reward/ticket.proto index 9dea2dab..b634da04 100644 --- a/proto/sge/reward/ticket.proto +++ b/proto/sge/reward/ticket.proto @@ -3,6 +3,7 @@ package sgenetwork.sge.reward; import "gogoproto/gogo.proto"; import "sge/type/kyc.proto"; +import "sge/reward/campaign.proto"; import "sge/reward/reward.proto"; import "sge/reward/promoter.proto"; @@ -41,6 +42,9 @@ message CreateCampaignPayload { // cap_count is the maximum allowed grant for a certain account. uint64 cap_count = 11; + + // constraints is the constrains of a campaign. + CampaignConstraints constraints = 12; } // UpdateCampaignPayload is the type for campaign update payload. diff --git a/x/reward/keeper/msg_server_campaign.go b/x/reward/keeper/msg_server_campaign.go index 0c48f07a..a8b6bcdd 100644 --- a/x/reward/keeper/msg_server_campaign.go +++ b/x/reward/keeper/msg_server_campaign.go @@ -28,6 +28,10 @@ func (k msgServer) CreateCampaign(goCtx context.Context, msg *types.MsgCreateCam return nil, sdkerrors.Wrapf(types.ErrInTicketVerification, "%s", err) } + if !k.IsPromoter(ctx, payload.Promoter) { + return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "promoter with the address: %s not found", payload.Promoter) + } + if msg.Creator != payload.Promoter { if err := utils.ValidateMsgAuthorization(k.authzKeeper, ctx, msg.Creator, payload.Promoter, msg, types.ErrAuthorizationNotFound, types.ErrAuthorizationNotAccepted); err != nil { @@ -62,6 +66,7 @@ func (k msgServer) CreateCampaign(goCtx context.Context, msg *types.MsgCreateCam payload.Meta, types.NewPool(msg.TotalFunds), payload.CapCount, + payload.Constraints, ) rewardFactory, err := campaign.GetRewardsFactory() diff --git a/x/reward/keeper/msg_server_campaign_test.go b/x/reward/keeper/msg_server_campaign_test.go index 117fcc4a..f64de9b0 100644 --- a/x/reward/keeper/msg_server_campaign_test.go +++ b/x/reward/keeper/msg_server_campaign_test.go @@ -22,12 +22,29 @@ import ( // Prevent strconv unused error var _ = strconv.IntSize +func setTestPromoter(k *keeper.Keeper, ctx sdk.Context, promoterAddr string) { + k.SetPromoter(ctx, types.Promoter{ + Creator: promoterAddr, + UID: promoterUID, + Addresses: []string{ + promoterAddr, + }, + }) + k.SetPromoterByAddress(ctx, types.PromoterByAddress{ + PromoterUID: promoterUID, + Address: promoterAddr, + }) +} + func TestCampaignMsgServerCreate(t *testing.T) { k, ctx := setupKeeper(t) srv := keeper.NewMsgServerImpl(*k) ctx = ctx.WithBlockTime(time.Now()) wctx := sdk.WrapSDKContext(ctx) creator := simapp.TestParamUsers["user1"].Address.String() + + setTestPromoter(k, ctx, creator) + for i := 0; i < 5; i++ { ticketClaim := jwt.MapClaims{ "exp": time.Now().Add(time.Minute * 5).Unix(), @@ -42,9 +59,11 @@ func TestCampaignMsgServerCreate(t *testing.T) { SubaccountAmount: sdkmath.NewInt(100), UnlockPeriod: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), }, - "is_active": true, - "meta": "sample campaign", - "claims_per_category": 1, + "is_active": true, + "meta": "sample campaign", + "constraints": &types.CampaignConstraints{ + MaxBetAmount: sdkmath.NewInt(300), + }, } ticket, err := simapp.CreateJwtTicket(ticketClaim) require.Nil(t, err) @@ -74,6 +93,8 @@ func TestCampaignMsgServerCreateWithAuthoriation(t *testing.T) { creator := simapp.TestParamUsers["user2"] promoter := simapp.TestParamUsers["user1"] + setTestPromoter(k, ctx, promoter.Address.String()) + grantAmount := sdkmath.NewInt(1000000) expTime := time.Now().Add(5 * time.Minute) @@ -108,9 +129,11 @@ func TestCampaignMsgServerCreateWithAuthoriation(t *testing.T) { SubaccountAmount: sdkmath.NewInt(100), UnlockPeriod: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), }, - "is_active": true, - "meta": "sample campaign", - "claims_per_category": 1, + "is_active": true, + "meta": "sample campaign", + "constraints": &types.CampaignConstraints{ + MaxBetAmount: sdkmath.NewInt(300), + }, } ticket, err := simapp.CreateJwtTicket(ticketClaim) require.Nil(t, err) @@ -143,10 +166,14 @@ func TestCampaignMsgServerUnAuthorizedCreate(t *testing.T) { ctx = ctx.WithBlockTime(time.Now()) wctx := sdk.WrapSDKContext(ctx) creator := simapp.TestParamUsers["user1"].Address.String() + promoter := sample.AccAddress() + + setTestPromoter(k, ctx, promoter) + ticketClaim := jwt.MapClaims{ "exp": time.Now().Add(time.Minute * 5).Unix(), "iat": time.Now().Unix(), - "promoter": sample.AccAddress(), + "promoter": promoter, } ticket, err := simapp.CreateJwtTicket(ticketClaim) require.Nil(t, err) @@ -199,6 +226,8 @@ func TestCampaignMsgServerUpdate(t *testing.T) { creator := simapp.TestParamUsers["user1"].Address.String() + setTestPromoter(k, ctx, creator) + ticketClaim := jwt.MapClaims{ "exp": time.Now().Add(time.Minute * 5).Unix(), "iat": time.Now().Unix(), @@ -212,9 +241,11 @@ func TestCampaignMsgServerUpdate(t *testing.T) { SubaccountAmount: sdkmath.NewInt(100), UnlockPeriod: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), }, - "is_active": true, - "meta": "sample campaign", - "claims_per_category": 1, + "is_active": true, + "meta": "sample campaign", + "constraints": &types.CampaignConstraints{ + MaxBetAmount: sdkmath.NewInt(300), + }, } ticket, err := simapp.CreateJwtTicket(ticketClaim) require.Nil(t, err) @@ -256,7 +287,7 @@ func TestCampaignMsgServerUpdate(t *testing.T) { } } -func TestCampaignMsgServerUpdateWithAuthoriation(t *testing.T) { +func TestCampaignMsgServerUpdateWithAuthorization(t *testing.T) { tApp, k, ctx := setupKeeperAndApp(t) srv := keeper.NewMsgServerImpl(*k) ctx = ctx.WithBlockTime(time.Now()) @@ -267,6 +298,8 @@ func TestCampaignMsgServerUpdateWithAuthoriation(t *testing.T) { creator := simapp.TestParamUsers["user2"] promoter := simapp.TestParamUsers["user1"] + setTestPromoter(k, ctx, promoter.Address.String()) + grantAmount := sdkmath.NewInt(1000000) expTime := time.Now().Add(5 * time.Minute) @@ -319,9 +352,11 @@ func TestCampaignMsgServerUpdateWithAuthoriation(t *testing.T) { SubaccountAmount: sdkmath.NewInt(100), UnlockPeriod: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), }, - "is_active": true, - "meta": "sample campaign", - "claims_per_category": 1, + "is_active": true, + "meta": "sample campaign", + "constraints": &types.CampaignConstraints{ + MaxBetAmount: sdkmath.NewInt(300), + }, } ticket, err := simapp.CreateJwtTicket(ticketClaim) require.Nil(t, err) diff --git a/x/reward/keeper/msg_server_promoter.go b/x/reward/keeper/msg_server_promoter.go index 2126c2ed..ec32a142 100644 --- a/x/reward/keeper/msg_server_promoter.go +++ b/x/reward/keeper/msg_server_promoter.go @@ -33,6 +33,10 @@ func (k msgServer) CreatePromoter(goCtx context.Context, msg *types.MsgCreatePro UID: payload.UID, Conf: payload.Conf, }) + k.SetPromoterByAddress(ctx, types.PromoterByAddress{ + PromoterUID: payload.UID, + Address: msg.Creator, + }) msg.EmitEvent(&ctx, payload.UID, payload.Conf) diff --git a/x/reward/keeper/msg_server_reward_test.go b/x/reward/keeper/msg_server_reward_test.go index a4c2e79d..030a915e 100644 --- a/x/reward/keeper/msg_server_reward_test.go +++ b/x/reward/keeper/msg_server_reward_test.go @@ -15,6 +15,7 @@ import ( "github.com/sge-network/sge/testutil/sample" "github.com/sge-network/sge/testutil/simapp" sgetypes "github.com/sge-network/sge/types" + bettypes "github.com/sge-network/sge/x/bet/types" "github.com/sge-network/sge/x/reward/keeper" "github.com/sge-network/sge/x/reward/types" subaccounttypes "github.com/sge-network/sge/x/subaccount/types" @@ -28,15 +29,14 @@ var defaultCategoryCap = []types.CategoryCap{ func getDefaultClaim(creator string) jwt.MapClaims { return jwt.MapClaims{ - "exp": time.Now().Add(time.Minute * 5).Unix(), - "iat": time.Now().Unix(), - "promoter": creator, - "start_ts": time.Now().Unix(), - "end_ts": time.Now().Add(5 * time.Minute).Unix(), - "category": types.RewardCategory_REWARD_CATEGORY_SIGNUP, - "claims_per_category": 1, - "is_active": true, - "meta": "sample campaign", + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "promoter": creator, + "start_ts": time.Now().Unix(), + "end_ts": time.Now().Add(5 * time.Minute).Unix(), + "category": types.RewardCategory_REWARD_CATEGORY_SIGNUP, + "is_active": true, + "meta": "sample campaign", } } @@ -126,7 +126,7 @@ func TestMsgApplySignupReward(t *testing.T) { "common": types.RewardPayloadCommon{ Receiver: receiverAddr, SourceUID: "", - Meta: "signup reward for example user", + Meta: "signup reward for sample user", KycData: &sgetypes.KycDataPayload{ Approved: true, ID: receiverAddr, @@ -188,7 +188,7 @@ func TestMsgApplySignupRewardWithCap(t *testing.T) { "common": types.RewardPayloadCommon{ Receiver: receiverAddr, SourceUID: "", - Meta: "signup reward for example user", + Meta: "signup reward for sample user", KycData: &sgetypes.KycDataPayload{ Approved: true, ID: receiverAddr, @@ -261,7 +261,7 @@ func TestMsgApplySignupRefereeReward(t *testing.T) { "common": types.RewardPayloadCommon{ Receiver: receiverAddr, SourceUID: "", - Meta: "signup reward for example user", + Meta: "signup reward for sample user", }, }, err: sdkerrtypes.ErrInvalidRequest, @@ -274,7 +274,7 @@ func TestMsgApplySignupRefereeReward(t *testing.T) { "common": types.RewardPayloadCommon{ Receiver: receiverAddr, SourceUID: referrer, - Meta: "signup reward for example user", + Meta: "signup reward for sample user", KycData: &sgetypes.KycDataPayload{ Approved: true, ID: receiverAddr, @@ -349,7 +349,7 @@ func TestMsgApplySignupReferrerReward(t *testing.T) { "common": types.RewardPayloadCommon{ Receiver: referee, SourceUID: referrer, - Meta: "signup reward for example user", + Meta: "signup reward for sample user", KycData: &sgetypes.KycDataPayload{ Approved: true, ID: referee, @@ -399,7 +399,7 @@ func TestMsgApplySignupReferrerReward(t *testing.T) { "common": types.RewardPayloadCommon{ Receiver: receiverAddr, SourceUID: "", - Meta: "signup reward for example user", + Meta: "signup reward for sample user", }, "referee": "invalid", }, @@ -413,7 +413,7 @@ func TestMsgApplySignupReferrerReward(t *testing.T) { "common": types.RewardPayloadCommon{ Receiver: receiverAddr, SourceUID: "", - Meta: "signup reward for example user", + Meta: "signup reward for sample user", KycData: &sgetypes.KycDataPayload{ Approved: true, ID: receiverAddr, @@ -493,7 +493,7 @@ func TestMsgApplySignupAffiliateReward(t *testing.T) { "common": types.RewardPayloadCommon{ Receiver: receiverAddr, SourceUID: "", - Meta: "signup reward for example user", + Meta: "signup reward for sample user", }, }, err: sdkerrtypes.ErrInvalidRequest, @@ -506,7 +506,7 @@ func TestMsgApplySignupAffiliateReward(t *testing.T) { "common": types.RewardPayloadCommon{ Receiver: receiverAddr, SourceUID: leadGen, - Meta: "signup reward for example user", + Meta: "signup reward for sample user", KycData: &sgetypes.KycDataPayload{ Approved: true, ID: receiverAddr, @@ -581,7 +581,7 @@ func TestMsgApplySignupAffiliateeReward(t *testing.T) { "common": types.RewardPayloadCommon{ Receiver: affiliatee, SourceUID: affiliator, - Meta: "signup reward for example user", + Meta: "signup reward for sample user", KycData: &sgetypes.KycDataPayload{ Approved: true, ID: affiliatee, @@ -631,7 +631,7 @@ func TestMsgApplySignupAffiliateeReward(t *testing.T) { "common": types.RewardPayloadCommon{ Receiver: receiverAddr, SourceUID: "", - Meta: "signup reward for example user", + Meta: "signup reward for sample user", }, "affiliatee": "invalid", }, @@ -645,7 +645,7 @@ func TestMsgApplySignupAffiliateeReward(t *testing.T) { "common": types.RewardPayloadCommon{ Receiver: receiverAddr, SourceUID: "", - Meta: "signup reward for example user", + Meta: "signup reward for sample user", KycData: &sgetypes.KycDataPayload{ Approved: true, ID: receiverAddr, @@ -674,6 +674,147 @@ func TestMsgApplySignupAffiliateeReward(t *testing.T) { } } +func TestMsgApplyBetBonus(t *testing.T) { + tApp, k, ctx := setupKeeperAndApp(t) + srv := keeper.NewMsgServerImpl(*k) + ctx = ctx.WithBlockTime(time.Now()) + wctx := sdk.WrapSDKContext(ctx) + + promoter := simapp.TestParamUsers["user1"].Address.String() + bettor := simapp.TestParamUsers["user2"].Address.String() + + bet := bettypes.Bet{ + Creator: bettor, + UID: uuid.NewString(), + MarketUID: uuid.NewString(), + Amount: sdkmath.NewInt(301), + Result: bettypes.Bet_RESULT_LOST, + Status: bettypes.Bet_STATUS_SETTLED, + } + tApp.BetKeeper.SetBet(ctx, bet, 1) + + _, err := tApp.SubaccountKeeper.CreateSubaccount(ctx, bettor, bettor, []subaccounttypes.LockedBalance{ + { + Amount: sdk.ZeroInt(), + UnlockTS: uint64(ctx.BlockTime().Add(60 * time.Minute).Unix()), + }, + }) + require.NoError(t, err) + + // referral signup campaign + betBonusCampClaims := getDefaultClaim(promoter) + betBonusCampClaims["category"] = types.RewardCategory_REWARD_CATEGORY_BET_DISCOUNT + betBonusCampClaims["reward_type"] = types.RewardType_REWARD_TYPE_BET_DISCOUNT + betBonusCampClaims["reward_amount_type"] = types.RewardAmountType_REWARD_AMOUNT_TYPE_PERCENTAGE + betBonusCampClaims["reward_amount"] = types.RewardAmount{ + MainAccountAmount: sdkmath.NewInt(10), + UnlockPeriod: 0, + } + betBonusCampClaims["constraints"] = types.CampaignConstraints{ + MaxBetAmount: sdkmath.NewInt(300), + } + betBonusCampUID := createCampaign(t, k, srv, ctx, promoter, betBonusCampClaims, defaultCategoryCap) + + betBonusClaims := jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "common": types.RewardPayloadCommon{ + Receiver: bettor, + SourceUID: "", + Meta: "bet bonus reward for sample user", + KycData: &sgetypes.KycDataPayload{ + Approved: true, + ID: bettor, + }, + }, + "bet_uid": bet.UID, + } + betBonusTicket, err := simapp.CreateJwtTicket(betBonusClaims) + require.Nil(t, err) + reward := &types.MsgGrantReward{ + Uid: uuid.NewString(), + Creator: promoter, + CampaignUid: betBonusCampUID, + Ticket: betBonusTicket, + } + _, err = srv.GrantReward(wctx, reward) + require.NoError(t, err) + + rewardGrant, err := k.GetRewardsOfReceiverByPromoterAndCategory(ctx, promoterUID, bettor, types.RewardCategory_REWARD_CATEGORY_BET_DISCOUNT) + require.NoError(t, err) + require.Equal(t, types.RewardByCategory{ + UID: reward.Uid, + Addr: bettor, + RewardCategory: types.RewardCategory_REWARD_CATEGORY_BET_DISCOUNT, + }, rewardGrant[0]) + + require.True(t, k.HasRewardOfReceiverByPromoter(ctx, promoterUID, bettor, types.RewardCategory_REWARD_CATEGORY_BET_DISCOUNT)) + + for _, tc := range []struct { + desc string + claims jwt.MapClaims + err error + }{ + { + desc: "invalid ticket", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "common": "invalid", + }, + err: types.ErrInTicketVerification, + }, + { + desc: "invalid bettor", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "common": types.RewardPayloadCommon{ + Receiver: bettor, + SourceUID: "", + Meta: "bet bonus reward for sample user", + }, + "bet_uid": "invalid", + }, + err: sdkerrtypes.ErrInvalidRequest, + }, + { + desc: "valid", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "common": types.RewardPayloadCommon{ + Receiver: bettor, + SourceUID: "", + Meta: "bet bonus reward for sample user", + KycData: &sgetypes.KycDataPayload{ + Approved: true, + ID: bettor, + }, + }, + "bet_uid": bet.UID, + }, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + ticket, err := simapp.CreateJwtTicket(tc.claims) + require.Nil(t, err) + reward := &types.MsgGrantReward{ + Uid: uuid.NewString(), + Creator: promoter, + CampaignUid: betBonusCampUID, + Ticket: ticket, + } + _, err = srv.GrantReward(wctx, reward) + if tc.err != nil { + require.ErrorContains(t, err, tc.err.Error()) + } else { + require.NoError(t, err) + } + }) + } +} + func TestMsgApplySignupRewardSubaccount(t *testing.T) { tApp, k, ctx := setupKeeperAndApp(t) srv := keeper.NewMsgServerImpl(*k) @@ -723,7 +864,7 @@ func TestMsgApplySignupRewardSubaccount(t *testing.T) { "common": types.RewardPayloadCommon{ Receiver: "invalid", SourceUID: "source id", - Meta: "signup reward for example user", + Meta: "signup reward for sample user", KycData: &sgetypes.KycDataPayload{ Approved: false, ID: "", @@ -741,7 +882,7 @@ func TestMsgApplySignupRewardSubaccount(t *testing.T) { "common": types.RewardPayloadCommon{ Receiver: sample.AccAddress(), SourceUID: "source id", - Meta: "signup reward for example user", + Meta: "signup reward for sample user", KycData: &sgetypes.KycDataPayload{ Approved: false, ID: "", @@ -758,7 +899,7 @@ func TestMsgApplySignupRewardSubaccount(t *testing.T) { "common": types.RewardPayloadCommon{ Receiver: receiverAddr, SourceUID: "source id", - Meta: "signup reward for example user", + Meta: "signup reward for sample user", KycData: &sgetypes.KycDataPayload{ Approved: true, ID: receiverAddr, @@ -814,7 +955,7 @@ func TestMsgApplySubaccountFunds(t *testing.T) { "common": types.RewardPayloadCommon{ Receiver: receiverAddr, SourceUID: "source id", - Meta: "signup reward for example user", + Meta: "signup reward for sample user", KycData: &sgetypes.KycDataPayload{ Approved: true, ID: receiverAddr, diff --git a/x/reward/keeper/promoter.go b/x/reward/keeper/promoter.go index c43b8350..c9f14cee 100644 --- a/x/reward/keeper/promoter.go +++ b/x/reward/keeper/promoter.go @@ -63,3 +63,9 @@ func (k Keeper) GetPromoterByAddress(ctx sdk.Context, address string) (val types k.cdc.MustUnmarshal(b, &val) return val, true } + +// IsPromoter returns true if there is a promoter with address +func (k Keeper) IsPromoter(ctx sdk.Context, address string) bool { + store := k.getPromoterByAddressStore(ctx) + return store.Has(types.GetPromoterByAddressKey(address)) +} diff --git a/x/reward/types/campaign.go b/x/reward/types/campaign.go index 4d595fa8..e5bfd3cc 100644 --- a/x/reward/types/campaign.go +++ b/x/reward/types/campaign.go @@ -16,6 +16,7 @@ func NewCampaign( meta string, pool Pool, capCount uint64, + constraint *CampaignConstraints, ) Campaign { return Campaign{ Creator: creator, @@ -31,6 +32,7 @@ func NewCampaign( Meta: meta, Pool: pool, CapCount: capCount, + Constraints: constraint, } } @@ -47,6 +49,8 @@ func (c *Campaign) GetRewardsFactory() (IRewardFactory, error) { return NewSignUpAffiliateeReward(), nil case RewardType_REWARD_TYPE_AFFILIATE: return NewSignUpAffiliatorReward(), nil + case RewardType_REWARD_TYPE_BET_DISCOUNT: + return NewBetBonusReward(), nil default: return nil, sdkerrors.Wrapf(ErrUnknownRewardType, "%d", c.RewardType) } diff --git a/x/reward/types/campaign.pb.go b/x/reward/types/campaign.pb.go index 8611e800..d0b1e15e 100644 --- a/x/reward/types/campaign.pb.go +++ b/x/reward/types/campaign.pb.go @@ -54,6 +54,8 @@ type Campaign struct { Meta string `protobuf:"bytes,13,opt,name=meta,proto3" json:"meta,omitempty"` // cap_count is the maximum allowed grant for a certain account. CapCount uint64 `protobuf:"varint,14,opt,name=cap_count,json=capCount,proto3" json:"cap_count,omitempty"` + // constraints is the constrains of a campaign. + Constraints *CampaignConstraints `protobuf:"bytes,15,opt,name=constraints,proto3" json:"constraints,omitempty"` } func (m *Campaign) Reset() { *m = Campaign{} } @@ -180,6 +182,13 @@ func (m *Campaign) GetCapCount() uint64 { return 0 } +func (m *Campaign) GetConstraints() *CampaignConstraints { + if m != nil { + return m.Constraints + } + return nil +} + // Pool tracks funds assigned and spent to/for a campaign. type Pool struct { Total cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=total,proto3,customtype=cosmossdk.io/math.Int" json:"total" yaml:"total"` @@ -220,50 +229,93 @@ func (m *Pool) XXX_DiscardUnknown() { var xxx_messageInfo_Pool proto.InternalMessageInfo +// CampaignConstraints contains campaign constraints and criteria. +type CampaignConstraints struct { + MaxBetAmount cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=max_bet_amount,json=maxBetAmount,proto3,customtype=cosmossdk.io/math.Int" json:"max_bet_amount" yaml:"max_bet_amount"` +} + +func (m *CampaignConstraints) Reset() { *m = CampaignConstraints{} } +func (m *CampaignConstraints) String() string { return proto.CompactTextString(m) } +func (*CampaignConstraints) ProtoMessage() {} +func (*CampaignConstraints) Descriptor() ([]byte, []int) { + return fileDescriptor_6d1d1b3139567e36, []int{2} +} +func (m *CampaignConstraints) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CampaignConstraints) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CampaignConstraints.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *CampaignConstraints) XXX_Merge(src proto.Message) { + xxx_messageInfo_CampaignConstraints.Merge(m, src) +} +func (m *CampaignConstraints) XXX_Size() int { + return m.Size() +} +func (m *CampaignConstraints) XXX_DiscardUnknown() { + xxx_messageInfo_CampaignConstraints.DiscardUnknown(m) +} + +var xxx_messageInfo_CampaignConstraints proto.InternalMessageInfo + func init() { proto.RegisterType((*Campaign)(nil), "sgenetwork.sge.reward.Campaign") proto.RegisterType((*Pool)(nil), "sgenetwork.sge.reward.Pool") + proto.RegisterType((*CampaignConstraints)(nil), "sgenetwork.sge.reward.CampaignConstraints") } func init() { proto.RegisterFile("sge/reward/campaign.proto", fileDescriptor_6d1d1b3139567e36) } var fileDescriptor_6d1d1b3139567e36 = []byte{ - // 554 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0x4f, 0x6f, 0xd3, 0x30, - 0x18, 0xc6, 0x1b, 0x96, 0xb6, 0xa9, 0xbb, 0x15, 0x64, 0x98, 0x66, 0x3a, 0x29, 0x09, 0x45, 0x88, - 0x22, 0xb4, 0x44, 0xda, 0xc4, 0x85, 0xdb, 0x52, 0x90, 0x98, 0x90, 0x10, 0xf2, 0xb6, 0x0b, 0x97, - 0xca, 0x4b, 0xac, 0x34, 0x5a, 0x13, 0x47, 0xb6, 0x4b, 0xe9, 0xb7, 0xe0, 0x63, 0xed, 0xb8, 0x23, - 0x42, 0x22, 0x42, 0xe9, 0x6d, 0x47, 0x3e, 0x00, 0x42, 0x76, 0xb2, 0xb2, 0x21, 0x98, 0xc6, 0x25, - 0x7e, 0xff, 0x3c, 0xcf, 0xcf, 0x89, 0xf3, 0x1a, 0x3c, 0x14, 0x31, 0xf5, 0x39, 0x9d, 0x13, 0x1e, - 0xf9, 0x21, 0x49, 0x73, 0x92, 0xc4, 0x99, 0x97, 0x73, 0x26, 0x19, 0xdc, 0x14, 0x31, 0xcd, 0xa8, - 0x9c, 0x33, 0x7e, 0xea, 0x89, 0x98, 0x7a, 0x95, 0xaa, 0xff, 0x20, 0x66, 0x31, 0xd3, 0x0a, 0x5f, - 0x45, 0x95, 0xb8, 0xbf, 0x75, 0x85, 0x53, 0x2d, 0x55, 0x63, 0xf0, 0xd3, 0x04, 0xd6, 0xa8, 0x06, - 0x43, 0x04, 0xda, 0x21, 0xa7, 0x44, 0x32, 0x8e, 0x0c, 0xd7, 0x18, 0x76, 0xf0, 0x65, 0x0a, 0x5d, - 0xb0, 0x36, 0x4b, 0x22, 0x74, 0x47, 0x55, 0x83, 0x5e, 0x59, 0x38, 0x6b, 0xc7, 0x07, 0xaf, 0x2e, - 0x0a, 0x47, 0x55, 0xb1, 0x7a, 0xc0, 0x3e, 0xb0, 0x72, 0xce, 0x52, 0x26, 0x29, 0x47, 0x6b, 0xda, - 0x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of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0xc1, 0x4f, 0xdb, 0x3e, + 0x14, 0xc7, 0x9b, 0x1f, 0x2d, 0xa4, 0x2e, 0x94, 0x9f, 0xcc, 0x10, 0x1e, 0x48, 0x4d, 0x97, 0x69, + 0x5a, 0xb7, 0x89, 0x54, 0x02, 0x6d, 0x87, 0xdd, 0x48, 0x36, 0x69, 0x68, 0xd3, 0x34, 0x19, 0xb8, + 0x4c, 0x93, 0x2a, 0x93, 0x58, 0x21, 0xa2, 0x89, 0x23, 0xdb, 0xac, 0xf4, 0xbf, 0xd8, 0x9f, 0xc5, + 0x61, 0x07, 0x8e, 0xd3, 0xa4, 0x45, 0x53, 0xb8, 0x71, 0xdc, 0x5f, 0x30, 0xd9, 0x4e, 0x0b, 0x4c, + 0xc0, 0xd8, 0x25, 0x7e, 0xef, 0xf9, 0x7d, 0x3f, 0x7e, 0xb6, 0x5f, 0x0c, 0xee, 0x8b, 0x98, 0xf6, + 0x39, 0x1d, 0x11, 0x1e, 0xf5, 0x43, 0x92, 0xe6, 0x24, 0x89, 0x33, 0x2f, 0xe7, 0x4c, 0x32, 0xb8, + 0x2c, 0x62, 0x9a, 0x51, 0x39, 0x62, 0xfc, 0xd0, 0x13, 0x31, 0xf5, 0x4c, 0xd6, 0xea, 0xbd, 0x98, + 0xc5, 0x4c, 0x67, 0xf4, 0x95, 0x65, 0x92, 0x57, 0x57, 0x2e, 0x71, 0xcc, 0x60, 0x26, 0xdc, 0xaf, + 0x0d, 0x60, 0x07, 0x15, 0x18, 0x22, 0x30, 0x17, 0x72, 0x4a, 0x24, 0xe3, 0xc8, 0xea, 0x5a, 0xbd, + 0x26, 0x9e, 0xb8, 0xb0, 0x0b, 0x66, 0x8e, 0x92, 0x08, 0xfd, 0xa7, 0xa2, 0x7e, 0xbb, 0x2c, 0x9c, + 0x99, 0xbd, 0xed, 0x57, 0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 0xa7, 0x86, 0x75, 0x3a, 0x5c, + 0x03, 0xcd, 0x44, 0x0c, 0x48, 0x28, 0x93, 0xcf, 0x14, 0xb5, 0xba, 0x56, 0xcf, 0xc6, 0x76, 0x22, + 0xb6, 0xb4, 0x0f, 0x21, 0xa8, 0xa7, 0x54, 0x12, 0xb4, 0xa0, 0x5b, 0x40, 0xdb, 0x4a, 0x10, 0x92, + 0x7c, 0x10, 0xea, 0x6a, 0xdb, 0xea, 0x32, 0xb1, 0x1d, 0x92, 0x3c, 0xd0, 0x45, 0xbc, 0x03, 0xad, + 0x90, 0x65, 0x42, 0x72, 0x92, 0x64, 0x52, 0xa0, 0x45, 0x5d, 0xcb, 0xd3, 0x1b, 0x6a, 0x99, 0x74, + 0x6a, 0x70, 0xa1, 0xc0, 0x97, 0xe5, 0xee, 0x0f, 0x0b, 0xd4, 0x55, 0xc1, 0x30, 0x00, 0x0d, 0xc9, + 0x24, 0x19, 0x9a, 0x46, 0xf6, 0xd7, 0x55, 0xfd, 0xdf, 0x0b, 0x67, 0x39, 0x64, 0x22, 0x65, 0x42, + 0x44, 0x87, 0x5e, 0xc2, 0xfa, 0x29, 0x91, 0x07, 0xde, 0x76, 0x26, 0x7f, 0x15, 0xce, 0xfc, 0x98, + 0xa4, 0xc3, 0x97, 0xae, 0xd6, 0xb8, 0xd8, 0x68, 0x15, 0x44, 0xe4, 0x34, 0x93, 0x55, 0xdf, 0xdf, + 0x15, 0xa2, 0x35, 0x2e, 0x36, 0x5a, 0xf8, 0x16, 0x34, 0x47, 0x89, 0x3c, 0x88, 0x38, 0x19, 0x65, + 0xe6, 0xcf, 0xf8, 0x57, 0xd0, 0x85, 0xde, 0x15, 0x60, 0xe9, 0x9a, 0x33, 0x80, 0x9f, 0x40, 0x3b, + 0x25, 0xc7, 0x83, 0x7d, 0x2a, 0x27, 0x4d, 0x61, 0xb6, 0xfd, 0xe2, 0x6f, 0x0b, 0x2d, 0x9b, 0x85, + 0xae, 0x8a, 0x5d, 0x3c, 0x9f, 0x92, 0x63, 0x9f, 0x4a, 0xd3, 0x27, 0x7e, 0x70, 0x52, 0x76, 0xac, + 0xd3, 0xb2, 0x63, 0xfd, 0x2c, 0x3b, 0xd6, 0x97, 0xb3, 0x4e, 0xed, 0xf4, 0xac, 0x53, 0xfb, 0x76, + 0xd6, 0xa9, 0x7d, 0x7c, 0x12, 0x27, 0xf2, 0xe0, 0x68, 0xdf, 0x0b, 0x59, 0xda, 0x17, 0x31, 0x5d, + 0xaf, 0xae, 0x4c, 0xd9, 0xfd, 0xe3, 0xc9, 0x7b, 0xa3, 0xda, 0x5e, 0xec, 0xcf, 0xea, 0xf7, 0x66, + 0xf3, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x43, 0x73, 0x63, 0x30, 0xd2, 0x04, 0x00, 0x00, } func (m *Campaign) Marshal() (dAtA []byte, err error) { @@ -286,6 +338,18 @@ func (m *Campaign) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.Constraints != nil { + { + size, err := m.Constraints.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCampaign(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x7a + } if m.CapCount != 0 { i = encodeVarintCampaign(dAtA, i, uint64(m.CapCount)) i-- @@ -432,6 +496,39 @@ func (m *Pool) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *CampaignConstraints) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CampaignConstraints) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CampaignConstraints) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.MaxBetAmount.Size() + i -= size + if _, err := m.MaxBetAmount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintCampaign(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func encodeVarintCampaign(dAtA []byte, offset int, v uint64) int { offset -= sovCampaign(v) base := offset @@ -492,6 +589,10 @@ func (m *Campaign) Size() (n int) { if m.CapCount != 0 { n += 1 + sovCampaign(uint64(m.CapCount)) } + if m.Constraints != nil { + l = m.Constraints.Size() + n += 1 + l + sovCampaign(uint64(l)) + } return n } @@ -510,6 +611,17 @@ func (m *Pool) Size() (n int) { return n } +func (m *CampaignConstraints) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.MaxBetAmount.Size() + n += 1 + l + sovCampaign(uint64(l)) + return n +} + func sovCampaign(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -876,6 +988,42 @@ func (m *Campaign) Unmarshal(dAtA []byte) error { break } } + case 15: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Constraints", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCampaign + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCampaign + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCampaign + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Constraints == nil { + m.Constraints = &CampaignConstraints{} + } + if err := m.Constraints.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipCampaign(dAtA[iNdEx:]) @@ -1049,6 +1197,90 @@ func (m *Pool) Unmarshal(dAtA []byte) error { } return nil } +func (m *CampaignConstraints) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCampaign + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CampaignConstraints: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CampaignConstraints: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxBetAmount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCampaign + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCampaign + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCampaign + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MaxBetAmount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCampaign(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCampaign + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipCampaign(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/reward/types/errors.go b/x/reward/types/errors.go index 87170e29..335a0fd5 100644 --- a/x/reward/types/errors.go +++ b/x/reward/types/errors.go @@ -39,4 +39,5 @@ var ( ErrUserKycNotProvided = sdkerrors.Register(ModuleName, 7129, "KYC data not provided") ErrDuplicateCategoryInConf = sdkerrors.Register(ModuleName, 7130, "duplicate category in promoter configurations") ErrCategoryCapShouldBePos = sdkerrors.Register(ModuleName, 7131, "category cap should be a positive number") + ErrMissingConstraintForCampaign = sdkerrors.Register(ModuleName, 7132, "missing constraints in the campaign") ) diff --git a/x/reward/types/expected_keepers.go b/x/reward/types/expected_keepers.go index c91495f4..3e4c2248 100644 --- a/x/reward/types/expected_keepers.go +++ b/x/reward/types/expected_keepers.go @@ -10,6 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/authz" bettypes "github.com/sge-network/sge/x/bet/types" + markettypes "github.com/sge-network/sge/x/market/types" subaccounttypes "github.com/sge-network/sge/x/subaccount/types" ) @@ -35,6 +36,11 @@ type BetKeeper interface { GetBetID(ctx sdk.Context, uid string) (val bettypes.UID2ID, found bool) } +// BetKeeper defines the expected interface needed to access market state. +type MarketKeeper interface { + GetMarket(ctx sdk.Context, marketUID string) (markettypes.Market, bool) +} + // OVMKeeper defines the expected interface needed to verify ticket and unmarshal it type OVMKeeper interface { VerifyTicketUnmarshal(goCtx context.Context, ticket string, clm interface{}) error diff --git a/x/reward/types/reward_bet_bonus.go b/x/reward/types/reward_bet_bonus.go index 9bfb849e..2e77d694 100644 --- a/x/reward/types/reward_bet_bonus.go +++ b/x/reward/types/reward_bet_bonus.go @@ -4,8 +4,10 @@ import ( context "context" sdkerrors "cosmossdk.io/errors" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + bettypes "github.com/sge-network/sge/x/bet/types" ) var percent = sdk.NewInt(100) @@ -33,6 +35,9 @@ func (sur BetBonusReward) ValidateCampaign(campaign Campaign) error { if campaign.RewardAmountType != RewardAmountType_REWARD_AMOUNT_TYPE_PERCENTAGE { return sdkerrors.Wrapf(ErrWrongRewardAmountType, "reward amount type not supported for given reward type.") } + if campaign.Constraints == nil || campaign.Constraints.MaxBetAmount.IsNil() { + return sdkerrors.Wrapf(ErrMissingConstraintForCampaign, "constraints and max bet amount should be set for the bet bonus reward.") + } return nil } @@ -74,15 +79,35 @@ func (sur BetBonusReward) Calculate(goCtx context.Context, ctx sdk.Context, keep return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "bet not found with uid %s", payload.BetUID) } - mainAmount := bet.Amount.Mul(campaign.RewardAmount.MainAccountAmount).Quo(percent) - subAmount := bet.Amount.Mul(campaign.RewardAmount.SubaccountAmount).Quo(percent) + if bet.Result != bettypes.Bet_RESULT_LOST && + bet.Result != bettypes.Bet_RESULT_WON { + return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "bet should be winner or loser, requested bet result is %s", bet.Result) + } + + effectiveBetAmount := sdk.NewDecFromInt(bet.Amount) + if campaign.Constraints != nil { + if !campaign.Constraints.MaxBetAmount.IsNil() && campaign.Constraints.MaxBetAmount.GT(sdkmath.ZeroInt()) { + if bet.Meta.IsMainMarket { + effectiveBetAmount = sdk.NewDecFromInt( + sdkmath.MinInt(campaign.Constraints.MaxBetAmount, bet.Amount), + ) + } + } + } + + mainAmount := effectiveBetAmount.Mul( + sdk.NewDecFromInt(campaign.RewardAmount.MainAccountAmount).QuoInt(percent), + ).TruncateInt() + subAmount := effectiveBetAmount.Mul( + sdk.NewDecFromInt(campaign.RewardAmount.SubaccountAmount).QuoInt(percent), + ).TruncateInt() return NewRewardFactoryData( NewReceiver( subAccountAddressString, payload.Common.Receiver, - mainAmount, subAmount, + mainAmount, campaign.RewardAmount.UnlockPeriod, ), payload.Common, diff --git a/x/reward/types/ticket.pb.go b/x/reward/types/ticket.pb.go index 1cff863e..26bb9f16 100644 --- a/x/reward/types/ticket.pb.go +++ b/x/reward/types/ticket.pb.go @@ -48,6 +48,8 @@ type CreateCampaignPayload struct { Meta string `protobuf:"bytes,10,opt,name=meta,proto3" json:"meta,omitempty"` // cap_count is the maximum allowed grant for a certain account. CapCount uint64 `protobuf:"varint,11,opt,name=cap_count,json=capCount,proto3" json:"cap_count,omitempty"` + // constraints is the constrains of a campaign. + Constraints *CampaignConstraints `protobuf:"bytes,12,opt,name=constraints,proto3" json:"constraints,omitempty"` } func (m *CreateCampaignPayload) Reset() { *m = CreateCampaignPayload{} } @@ -153,6 +155,13 @@ func (m *CreateCampaignPayload) GetCapCount() uint64 { return 0 } +func (m *CreateCampaignPayload) GetConstraints() *CampaignConstraints { + if m != nil { + return m.Constraints + } + return nil +} + // UpdateCampaignPayload is the type for campaign update payload. type UpdateCampaignPayload struct { // end_ts is the end timestamp of the campaign. @@ -663,53 +672,55 @@ func init() { func init() { proto.RegisterFile("sge/reward/ticket.proto", fileDescriptor_5d710bc1249ca8ae) } var fileDescriptor_5d710bc1249ca8ae = []byte{ - // 728 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0xc1, 0x6a, 0xdb, 0x40, - 0x10, 0xf5, 0xc6, 0x8e, 0x2d, 0x8f, 0xdb, 0x50, 0xb6, 0x71, 0xab, 0x38, 0x60, 0xbb, 0x2a, 0xa5, - 0x6e, 0xa1, 0x36, 0xb8, 0xc7, 0xd2, 0x82, 0xe5, 0xd0, 0xa6, 0xe4, 0x12, 0x94, 0x84, 0x40, 0x2f, - 0x66, 0x23, 0xad, 0x15, 0xe1, 0x58, 0x2b, 0x76, 0xd7, 0x49, 0xf4, 0x03, 0x3d, 0x96, 0xde, 0xfa, - 0x3f, 0x3d, 0xe5, 0x98, 0x63, 0xa1, 0x60, 0x8a, 0x73, 0xeb, 0x57, 0x14, 0xad, 0x24, 0x47, 0x2e, - 0x49, 0x08, 0x2d, 0xb9, 0x48, 0x33, 0x3b, 0x33, 0xef, 0xbd, 0xd9, 0x19, 0x24, 0x78, 0x2c, 0x5c, - 0xda, 0xe1, 0xf4, 0x84, 0x70, 0xa7, 0x23, 0x3d, 0x7b, 0x44, 0x65, 0x3b, 0xe0, 0x4c, 0x32, 0x5c, - 0x15, 0x2e, 0xf5, 0xa9, 0x3c, 0x61, 0x7c, 0xd4, 0x16, 0x2e, 0x6d, 0xc7, 0x39, 0xb5, 0x55, 0x97, - 0xb9, 0x4c, 0x65, 0x74, 0x22, 0x2b, 0x4e, 0xae, 0xe1, 0x08, 0x45, 0x86, 0x01, 0xed, 0x8c, 0x42, - 0x3b, 0x39, 0xcb, 0x22, 0xc7, 0xaf, 0x24, 0xb0, 0x96, 0x09, 0x04, 0x9c, 0x8d, 0x99, 0xa4, 0x3c, - 0x0e, 0x19, 0x3f, 0xf3, 0x50, 0xed, 0x73, 0x4a, 0x24, 0xed, 0x93, 0x71, 0x40, 0x3c, 0xd7, 0xdf, - 0x26, 0xe1, 0x11, 0x23, 0x0e, 0xae, 0x81, 0x96, 0xe6, 0xea, 0xa8, 0x89, 0x5a, 0x65, 0x6b, 0xee, - 0xe3, 0x35, 0xd0, 0x84, 0x24, 0x5c, 0x0e, 0xa4, 0xd0, 0x97, 0x9a, 0xa8, 0x55, 0xb0, 0x4a, 0xca, - 0xdf, 0x15, 0xb8, 0x0a, 0x45, 0xea, 0x3b, 0x51, 0x20, 0xaf, 0x02, 0xcb, 0xd4, 0x77, 0x76, 0x05, - 0xee, 0x81, 0x66, 0x13, 0x49, 0x5d, 0xc6, 0x43, 0xbd, 0xd0, 0x44, 0xad, 0x95, 0xee, 0xb3, 0xf6, - 0x95, 0xfd, 0xb6, 0x2d, 0xf5, 0xea, 0x27, 0xc9, 0xd6, 0xbc, 0x0c, 0x9b, 0x50, 0x89, 0x53, 0x06, - 0x51, 0xdf, 0xfa, 0xb2, 0x42, 0x79, 0x72, 0x23, 0xca, 0x6e, 0x18, 0x50, 0x0b, 0xf8, 0xdc, 0xc6, - 0x7b, 0x80, 0x13, 0x0c, 0x32, 0x66, 0x13, 0x5f, 0xc6, 0x50, 0x45, 0x05, 0xf5, 0xfc, 0x46, 0xa8, - 0x9e, 0xca, 0x57, 0x80, 0x0f, 0xf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, 0x69, 0x14, 0xfb, - 0x86, 0x03, 0xfa, 0x07, 0x4e, 0x7c, 0xb9, 0xe3, 0xb9, 0xfe, 0x24, 0x58, 0x68, 0x07, 0x6f, 0x42, - 0xd1, 0x56, 0x2d, 0x29, 0xa1, 0x95, 0xee, 0xcb, 0x1b, 0x47, 0xbe, 0x70, 0x09, 0x66, 0xe1, 0x6c, - 0xda, 0xc8, 0x59, 0x49, 0xbd, 0xf1, 0x19, 0x41, 0x73, 0x81, 0x66, 0x48, 0x39, 0xa7, 0xfc, 0x3a, - 0x3a, 0xf4, 0x7f, 0x74, 0x58, 0x87, 0x12, 0x8f, 0x28, 0x68, 0x3c, 0xe8, 0xb2, 0x95, 0xba, 0xc6, - 0x17, 0x04, 0x46, 0x46, 0x48, 0x6f, 0x38, 0xf4, 0x8e, 0x3c, 0x22, 0xd9, 0x9d, 0x49, 0xa9, 0x03, - 0x90, 0x84, 0x64, 0xae, 0x26, 0x73, 0x62, 0x7c, 0x43, 0x50, 0x53, 0x82, 0x4c, 0x2a, 0x4d, 0xe6, - 0x4f, 0xc4, 0x5d, 0x09, 0xe9, 0x40, 0xe9, 0x80, 0xca, 0xcc, 0xda, 0x55, 0x67, 0xd3, 0x46, 0xd1, - 0xa4, 0x32, 0xde, 0xb9, 0x34, 0x68, 0xa5, 0x86, 0x71, 0x9a, 0x7e, 0x3c, 0xb7, 0x93, 0x85, 0x4f, - 0x35, 0x35, 0x21, 0x1f, 0xa1, 0xa8, 0xd5, 0x36, 0x57, 0x66, 0xd3, 0x46, 0x3e, 0x86, 0x88, 0x4e, - 0xad, 0xe8, 0x81, 0xdf, 0x42, 0xc1, 0x66, 0xfe, 0x30, 0x59, 0x9b, 0xeb, 0xbe, 0x14, 0x29, 0x6e, - 0x9f, 0xf9, 0xc3, 0x44, 0xac, 0x2a, 0x33, 0xf6, 0xe1, 0xd1, 0x0e, 0x95, 0xd9, 0x70, 0x4a, 0x9d, - 0x02, 0xa3, 0x7f, 0x02, 0x36, 0xfb, 0x67, 0xb3, 0x3a, 0x3a, 0x9f, 0xd5, 0xd1, 0xaf, 0x59, 0x1d, - 0x7d, 0xbd, 0xa8, 0xe7, 0xce, 0x2f, 0xea, 0xb9, 0x1f, 0x17, 0xf5, 0xdc, 0xa7, 0x17, 0xae, 0x27, - 0x0f, 0x27, 0x07, 0x6d, 0x9b, 0x8d, 0x3b, 0xc2, 0xa5, 0xaf, 0x12, 0xd4, 0xc8, 0xee, 0x9c, 0xce, - 0xff, 0x68, 0x61, 0x40, 0xc5, 0x41, 0x51, 0xfd, 0x5c, 0x5e, 0xff, 0x09, 0x00, 0x00, 0xff, 0xff, - 0x8b, 0x46, 0xd0, 0x88, 0xec, 0x06, 0x00, 0x00, + // 759 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0xc1, 0x6e, 0xf3, 0x44, + 0x10, 0xce, 0x36, 0x69, 0xe2, 0x4c, 0x4a, 0x85, 0x96, 0x06, 0xdc, 0x54, 0x4a, 0x82, 0x11, 0x22, + 0x20, 0x91, 0x48, 0xe5, 0x88, 0x40, 0x8a, 0x5d, 0x41, 0x51, 0x39, 0x54, 0x6e, 0xab, 0x4a, 0x5c, + 0xa2, 0xed, 0x7a, 0xe3, 0x5a, 0x69, 0xbc, 0xd6, 0xee, 0xa6, 0xad, 0x5f, 0x80, 0x23, 0xe2, 0xc6, + 0x33, 0xf0, 0x1a, 0x9c, 0x7a, 0xec, 0x91, 0x53, 0x84, 0xd2, 0x1b, 0x4f, 0x81, 0xbc, 0xb6, 0x53, + 0x07, 0x25, 0x55, 0xf5, 0xff, 0xea, 0xc5, 0x9e, 0xd9, 0x99, 0xf9, 0xe6, 0xdb, 0x99, 0x4f, 0x36, + 0x7c, 0x22, 0x7d, 0x36, 0x10, 0xec, 0x8e, 0x08, 0x6f, 0xa0, 0x02, 0x3a, 0x61, 0xaa, 0x1f, 0x09, + 0xae, 0x38,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0xc3, 0x71, 0x26, 0x9b, 0x4d, 0xdf, 0x9d, 0x1c, 0xd7, 0xe1, 0xe1, + 0x38, 0x23, 0xab, 0xcb, 0xac, 0x4b, 0xf8, 0xf8, 0x8c, 0xa9, 0x62, 0x38, 0x6f, 0x9d, 0x03, 0xa3, + 0x77, 0x02, 0xb6, 0x9d, 0x87, 0x45, 0x1b, 0x3d, 0x2e, 0xda, 0xe8, 0x9f, 0x45, 0x1b, 0xfd, 0xfe, + 0xd4, 0x2e, 0x3d, 0x3e, 0xb5, 0x4b, 0x7f, 0x3f, 0xb5, 0x4b, 0xbf, 0x7c, 0xe9, 0x07, 0xea, 0x7a, + 0x76, 0xd5, 0xa7, 0x7c, 0x3a, 0x90, 0x3e, 0xfb, 0x3a, 0x43, 0x4d, 0xec, 0xc1, 0xfd, 0xf2, 0xd7, + 0x19, 0x47, 0x4c, 0x5e, 0x55, 0xf5, 0xaf, 0xea, 0x9b, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0x02, + 0xbd, 0x7a, 0x8d, 0x55, 0x07, 0x00, 0x00, } func (m *CreateCampaignPayload) Marshal() (dAtA []byte, err error) { @@ -732,6 +743,18 @@ func (m *CreateCampaignPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.Constraints != nil { + { + size, err := m.Constraints.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTicket(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x62 + } if m.CapCount != 0 { i = encodeVarintTicket(dAtA, i, uint64(m.CapCount)) i-- @@ -1201,6 +1224,10 @@ func (m *CreateCampaignPayload) Size() (n int) { if m.CapCount != 0 { n += 1 + sovTicket(uint64(m.CapCount)) } + if m.Constraints != nil { + l = m.Constraints.Size() + n += 1 + l + sovTicket(uint64(l)) + } return n } @@ -1608,6 +1635,42 @@ func (m *CreateCampaignPayload) Unmarshal(dAtA []byte) error { break } } + case 12: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Constraints", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTicket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTicket + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTicket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Constraints == nil { + m.Constraints = &CampaignConstraints{} + } + if err := m.Constraints.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTicket(dAtA[iNdEx:])