From 8885ba0d045a451d3691635096135e56d85496e1 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Tue, 27 Feb 2024 13:17:54 +0300 Subject: [PATCH 01/28] refactor: move claims per category to promoter --- proto/sge/reward/campaign.proto | 4 - proto/sge/reward/genesis.proto | 5 + proto/sge/reward/promoter.proto | 51 + proto/sge/reward/query.proto | 6 +- proto/sge/reward/ticket.proto | 4 - x/reward/genesis.go | 22 +- x/reward/keeper/campaign.go | 4 +- x/reward/keeper/msg_server_campaign.go | 2 +- x/reward/keeper/msg_server_reward.go | 23 +- x/reward/keeper/msg_server_reward_test.go | 27 +- x/reward/keeper/promoter.go | 65 ++ x/reward/keeper/query_reward.go | 4 +- x/reward/keeper/reward.go | 16 +- x/reward/keeper/view.go | 12 + x/reward/types/campaign.go | 27 +- x/reward/types/campaign.pb.go | 107 +- x/reward/types/expected_keepers.go | 3 +- x/reward/types/genesis.pb.go | 181 +++- x/reward/types/key_promoter.go | 27 + x/reward/types/key_reward.go | 18 +- x/reward/types/promoter.pb.go | 1092 ++++++++++++++++++++ x/reward/types/query.pb.go | 222 ++-- x/reward/types/query.pb.gw.go | 52 +- x/reward/types/reward_signup_affiliator.go | 7 +- x/reward/types/reward_signup_referrer.go | 7 +- x/reward/types/ticket.go | 4 - x/reward/types/ticket.pb.go | 118 +-- x/reward/types/ticket_test.go | 5 +- 28 files changed, 1808 insertions(+), 307 deletions(-) create mode 100644 proto/sge/reward/promoter.proto create mode 100644 x/reward/keeper/promoter.go create mode 100644 x/reward/types/key_promoter.go create mode 100644 x/reward/types/promoter.pb.go diff --git a/proto/sge/reward/campaign.proto b/proto/sge/reward/campaign.proto index b9605ccd..83b96ec7 100644 --- a/proto/sge/reward/campaign.proto +++ b/proto/sge/reward/campaign.proto @@ -54,10 +54,6 @@ message Campaign { // is_active is the flag to check if the campaign is active or not. bool is_active = 11; - // claims_per_category is the number of times a user can claim a - // reward for category of this campaign. - uint64 claims_per_category = 12; - // meta is the metadata of the campaign. // It is a stringified base64 encoded json. string meta = 13; diff --git a/proto/sge/reward/genesis.proto b/proto/sge/reward/genesis.proto index 937a59bb..58b8568b 100644 --- a/proto/sge/reward/genesis.proto +++ b/proto/sge/reward/genesis.proto @@ -6,6 +6,7 @@ import "gogoproto/gogo.proto"; import "sge/reward/params.proto"; import "sge/reward/campaign.proto"; import "sge/reward/reward.proto"; +import "sge/reward/promoter.proto"; option go_package = "github.com/sge-network/sge/x/reward/types"; @@ -18,4 +19,8 @@ message GenesisState { [ (gogoproto.nullable) = false ]; repeated RewardByCampaign reward_by_campaign_list = 5 [ (gogoproto.nullable) = false ]; + repeated Promoter promoter_list = 6 + [ (gogoproto.nullable) = false ]; + repeated PromoterByAddress promoter_by_address_list = 7 + [ (gogoproto.nullable) = false ]; } diff --git a/proto/sge/reward/promoter.proto b/proto/sge/reward/promoter.proto new file mode 100644 index 00000000..3b717c91 --- /dev/null +++ b/proto/sge/reward/promoter.proto @@ -0,0 +1,51 @@ +syntax = "proto3"; +package sgenetwork.sge.reward; + +import "gogoproto/gogo.proto"; + +import "sge/reward/reward.proto"; + +option go_package = "github.com/sge-network/sge/x/reward/types"; + +// Promoter is type for defining the reward promoter properties and configuration. +message Promoter { + // creator is the address of promoter. + string creator = 1; + + // uid is the unique identifier of a promoter. + string uid = 2 [ + (gogoproto.customname) = "UID", + (gogoproto.jsontag) = "uid", + json_name = "uid" + ]; + + // addresses is the list of account addresses of promoter. + repeated string addresses = 3; + + // conf is the configurations of the current promoter for the reward grant. + PromoterConf conf = 4 [ (gogoproto.nullable) = false ]; +} + +// PromoterConf is type for defining the promoter specific configurations. +message PromoterConf { + // category_cap is the maximium allowed cap for each category. + repeated CategoryCap category_cap = 1 [ (gogoproto.nullable) = false ]; +} + +// CategoryCap is type to define category and its maximum cap. +message CategoryCap { + RewardCategory category = 1; + int32 cap_per_acc = 2; +} + +// PromoterByAddress is type for defining the promoter by address. +message PromoterByAddress { + // promoter_uid is the unique identifier of a certain promoter. + string promoter_uid = 1 [ + (gogoproto.customname) = "PromoterUID", + (gogoproto.jsontag) = "promoter_uid", + json_name = "promoter_uid" + ]; + // address is the address of the promoter account. + string address = 2; +} \ No newline at end of file diff --git a/proto/sge/reward/query.proto b/proto/sge/reward/query.proto index 106e86af..12921ea4 100644 --- a/proto/sge/reward/query.proto +++ b/proto/sge/reward/query.proto @@ -42,7 +42,7 @@ service Query { // Queries list of all Reward items by user address. rpc RewardsByAddress(QueryRewardsByAddressRequest) returns (QueryRewardsByAddressResponse) { - option (google.api.http).get = "/sge-network/sge/reward/rewards/{address}"; + option (google.api.http).get = "/sge-network/sge/reward/rewards/{promoter_uid}/{address}"; } // Queries list of all Reward items by user address and reward type @@ -50,7 +50,7 @@ service Query { rpc RewardsByAddressAndCategory(QueryRewardsByAddressAndCategoryRequest) returns (QueryRewardsByAddressAndCategoryResponse) { option (google.api.http).get = - "/sge-network/sge/reward/rewards/{address}/{category}"; + "/sge-network/sge/reward/rewards/{promoter_uid}/{address}/{category}"; } // Queries list of all Reward items by campaign endpoint. @@ -114,6 +114,7 @@ message QueryRewardsResponse { message QueryRewardsByAddressRequest { cosmos.base.query.v1beta1.PageRequest pagination = 1; string address = 2; + string promoter_uid = 3; } // QueryRewardsByAddressResponse is response body of the query all rewards by @@ -129,6 +130,7 @@ message QueryRewardsByAddressAndCategoryRequest { cosmos.base.query.v1beta1.PageRequest pagination = 1; string address = 2; RewardCategory category = 3; + string promoter_uid = 4; } // QueryRewardsByAddressAndCategoryResponse is response body of the query all diff --git a/proto/sge/reward/ticket.proto b/proto/sge/reward/ticket.proto index b9a58795..74579894 100644 --- a/proto/sge/reward/ticket.proto +++ b/proto/sge/reward/ticket.proto @@ -34,10 +34,6 @@ message CreateCampaignPayload { // is_active is the flag to check if the campaign is active or not. bool is_active = 8; - // claims_per_category is the number of times a user can claim a reward for - // category of this campaign. - uint64 claims_per_category = 9; - // meta is the metadata of the campaign. // It is a stringified base64 encoded json. string meta = 10; diff --git a/x/reward/genesis.go b/x/reward/genesis.go index b841832b..8a1d7b49 100644 --- a/x/reward/genesis.go +++ b/x/reward/genesis.go @@ -1,6 +1,8 @@ package reward import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/sge-network/sge/x/reward/keeper" @@ -9,6 +11,12 @@ import ( // InitGenesis initializes the module's state from a provided genesis state. func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + for _, elem := range genState.PromoterList { + k.SetPromoter(ctx, elem) + } + for _, elem := range genState.PromoterByAddressList { + k.SetPromoterByAddress(ctx, elem) + } // Set all the campaign for _, elem := range genState.CampaignList { k.SetCampaign(ctx, elem) @@ -17,7 +25,19 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) k.SetReward(ctx, elem) } for _, elem := range genState.RewardByCategoryList { - k.SetRewardByReceiver(ctx, elem) + reward, found := k.GetReward(ctx, elem.UID) + if !found { + panic(fmt.Errorf("reward is not valid %s", elem.UID)) + } + camp, found := k.GetCampaign(ctx, reward.CampaignUID) + if !found { + panic(fmt.Errorf("campaign is not valid %s", reward.CampaignUID)) + } + promoter, found := k.GetPromoterByAddress(ctx, camp.Promoter) + if !found { + panic(fmt.Errorf("promoter is not valid %s", camp.Promoter)) + } + k.SetRewardOfReceiverByPromoterAndCategory(ctx, promoter.PromoterUID, elem) } for _, elem := range genState.RewardByCampaignList { k.SetRewardByCampaign(ctx, elem) diff --git a/x/reward/keeper/campaign.go b/x/reward/keeper/campaign.go index 7fe23843..c894a927 100644 --- a/x/reward/keeper/campaign.go +++ b/x/reward/keeper/campaign.go @@ -10,9 +10,7 @@ import ( func (k Keeper) SetCampaign(ctx sdk.Context, campaign types.Campaign) { store := k.getCampaignStore(ctx) b := k.cdc.MustMarshal(&campaign) - store.Set(types.GetCampaignKey( - campaign.UID, - ), b) + store.Set(types.GetCampaignKey(campaign.UID), b) } // GetCampaign returns a campaign from its index diff --git a/x/reward/keeper/msg_server_campaign.go b/x/reward/keeper/msg_server_campaign.go index a88c82e5..307b511e 100644 --- a/x/reward/keeper/msg_server_campaign.go +++ b/x/reward/keeper/msg_server_campaign.go @@ -53,7 +53,7 @@ func (k msgServer) CreateCampaign(goCtx context.Context, msg *types.MsgCreateCam campaign := types.NewCampaign( msg.Creator, payload.Promoter, msg.Uid, - payload.StartTs, payload.EndTs, payload.ClaimsPerCategory, + payload.StartTs, payload.EndTs, payload.RewardType, payload.Category, payload.RewardAmountType, diff --git a/x/reward/keeper/msg_server_reward.go b/x/reward/keeper/msg_server_reward.go index 6a7b9e5c..ff85a200 100644 --- a/x/reward/keeper/msg_server_reward.go +++ b/x/reward/keeper/msg_server_reward.go @@ -48,12 +48,26 @@ func (k msgServer) GrantReward(goCtx context.Context, msg *types.MsgGrantReward) return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "distribution calculation failed %s", err) } - rewards, err := k.GetRewardsByAddressAndCategory(ctx, factData.Receiver.MainAccountAddr, campaign.RewardCategory) + promoterByAddress, isFound := k.GetPromoterByAddress(ctx, campaign.Promoter) + if !isFound { + return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "promoter with the address: %s not found", campaign.Promoter) + } + promoter, isFound := k.GetPromoter(ctx, promoterByAddress.PromoterUID) + if !isFound { + return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "promoter with the uid: %s not found", promoterByAddress.PromoterUID) + } + + rewards, err := k.GetRewardsOfReceiverByPromoterAndCategory(ctx, promoter.UID, factData.Receiver.MainAccountAddr, campaign.RewardCategory) if err != nil { return nil, sdkerrors.Wrap(sdkerrtypes.ErrInvalidRequest, "failed to retrieve rewards for user.") } - if len(rewards) >= cast.ToInt(campaign.ClaimsPerCategory) { - return nil, sdkerrors.Wrap(sdkerrtypes.ErrInvalidRequest, "maximum rewards claimed for the given category.") + + for _, c := range promoter.Conf.CategoryCap { + if c.Category == campaign.RewardCategory { + if len(rewards) >= cast.ToInt(c.CapPerAcc) { + return nil, sdkerrors.Wrap(sdkerrtypes.ErrInvalidRequest, "maximum rewards claimed for the given category.") + } + } } if err := campaign.CheckPoolBalance(factData.Receiver.SubAccountAmount.Add(factData.Receiver.MainAccountAmount)); err != nil { @@ -72,7 +86,8 @@ func (k msgServer) GrantReward(goCtx context.Context, msg *types.MsgGrantReward) factData.Common.SourceUID, factData.Common.Meta, )) - k.SetRewardByReceiver(ctx, types.NewRewardByCategory(msg.Uid, factData.Receiver.MainAccountAddr, campaign.RewardCategory)) + + k.SetRewardOfReceiverByPromoterAndCategory(ctx, promoter.UID, types.NewRewardByCategory(msg.Uid, factData.Receiver.MainAccountAddr, campaign.RewardCategory)) k.SetRewardByCampaign(ctx, types.NewRewardByCampaign(msg.Uid, campaign.UID)) msg.EmitEvent(&ctx, msg.CampaignUid, msg.Uid, campaign.Promoter, *campaign.RewardAmount, factData.Receiver, unlockTS) diff --git a/x/reward/keeper/msg_server_reward_test.go b/x/reward/keeper/msg_server_reward_test.go index ad75745c..2ade6ceb 100644 --- a/x/reward/keeper/msg_server_reward_test.go +++ b/x/reward/keeper/msg_server_reward_test.go @@ -20,6 +20,8 @@ import ( subaccounttypes "github.com/sge-network/sge/x/subaccount/types" ) +var promoterUID = uuid.NewString() + func getDefaultClaim(creator string) jwt.MapClaims { return jwt.MapClaims{ "exp": time.Now().Add(time.Minute * 5).Unix(), @@ -37,6 +39,23 @@ func getDefaultClaim(creator string) jwt.MapClaims { func createCampaign(t *testing.T, k *keeper.Keeper, srv types.MsgServer, ctx sdk.Context, promoter string, claims jwt.MapClaims, ) string { + k.SetPromoter(ctx, types.Promoter{ + Creator: promoter, + UID: promoterUID, + Addresses: []string{promoter}, + Conf: types.PromoterConf{ + CategoryCap: []types.CategoryCap{ + {Category: types.RewardCategory_REWARD_CATEGORY_SIGNUP, CapPerAcc: 1}, + }, + }, + }) + + k.SetPromoterByAddress(ctx, + types.PromoterByAddress{ + Address: promoter, + PromoterUID: promoterUID, + }) + ticket, err := simapp.CreateJwtTicket(claims) require.Nil(t, err) @@ -290,7 +309,7 @@ func TestMsgApplySignupReferrerReward(t *testing.T) { _, err = srv.GrantReward(wctx, reward) require.NoError(t, err) - rewardGrant, err := k.GetRewardsByAddressAndCategory(ctx, referee, types.RewardCategory_REWARD_CATEGORY_SIGNUP) + rewardGrant, err := k.GetRewardsOfReceiverByPromoterAndCategory(ctx, promoterUID, referee, types.RewardCategory_REWARD_CATEGORY_SIGNUP) require.NoError(t, err) require.Equal(t, types.RewardByCategory{ UID: reward.Uid, @@ -298,7 +317,7 @@ func TestMsgApplySignupReferrerReward(t *testing.T) { RewardCategory: types.RewardCategory_REWARD_CATEGORY_SIGNUP, }, rewardGrant[0]) - require.True(t, k.HasRewardByReceiver(ctx, referee, types.RewardCategory_REWARD_CATEGORY_SIGNUP)) + require.True(t, k.HasRewardOfReceiverByPromoter(ctx, promoterUID, referee, types.RewardCategory_REWARD_CATEGORY_SIGNUP)) for _, tc := range []struct { desc string @@ -522,7 +541,7 @@ func TestMsgApplySignupAffiliateeReward(t *testing.T) { _, err = srv.GrantReward(wctx, reward) require.NoError(t, err) - rewardGrant, err := k.GetRewardsByAddressAndCategory(ctx, affiliatee, types.RewardCategory_REWARD_CATEGORY_SIGNUP) + rewardGrant, err := k.GetRewardsOfReceiverByPromoterAndCategory(ctx, promoterUID, affiliatee, types.RewardCategory_REWARD_CATEGORY_SIGNUP) require.NoError(t, err) require.Equal(t, types.RewardByCategory{ UID: reward.Uid, @@ -530,7 +549,7 @@ func TestMsgApplySignupAffiliateeReward(t *testing.T) { RewardCategory: types.RewardCategory_REWARD_CATEGORY_SIGNUP, }, rewardGrant[0]) - require.True(t, k.HasRewardByReceiver(ctx, affiliatee, types.RewardCategory_REWARD_CATEGORY_SIGNUP)) + require.True(t, k.HasRewardOfReceiverByPromoter(ctx, promoterUID, affiliatee, types.RewardCategory_REWARD_CATEGORY_SIGNUP)) for _, tc := range []struct { desc string diff --git a/x/reward/keeper/promoter.go b/x/reward/keeper/promoter.go new file mode 100644 index 00000000..c43b8350 --- /dev/null +++ b/x/reward/keeper/promoter.go @@ -0,0 +1,65 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/reward/types" +) + +// SetPromoter set a specific promoter in the store from its index +func (k Keeper) SetPromoter(ctx sdk.Context, promoter types.Promoter) { + store := k.getPromoterStore(ctx) + b := k.cdc.MustMarshal(&promoter) + store.Set(types.GetPromoterKey(promoter.UID), b) +} + +// GetPromoter returns a promoter, +func (k Keeper) GetPromoter( + ctx sdk.Context, + uid string, +) (val types.Promoter, found bool) { + store := k.getPromoterStore(ctx) + + b := store.Get(types.GetPromoterKey(uid)) + if b == nil { + return val, false + } + + k.cdc.MustUnmarshal(b, &val) + return val, true +} + +// GetAllPromoter returns all promoters +func (k Keeper) GetAllPromoter(ctx sdk.Context) (list []types.Promoter) { + store := k.getPromoterStore(ctx) + iterator := sdk.KVStorePrefixIterator(store, []byte{}) + + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var val types.Promoter + k.cdc.MustUnmarshal(iterator.Value(), &val) + list = append(list, val) + } + + return +} + +// SetPromoterByAddress set a specific promoter in the store from its address +func (k Keeper) SetPromoterByAddress(ctx sdk.Context, promoterByAddress types.PromoterByAddress) { + store := k.getPromoterByAddressStore(ctx) + b := k.cdc.MustMarshal(&promoterByAddress) + store.Set(types.GetPromoterByAddressKey(promoterByAddress.Address), b) +} + +// GetPromoter returns a promoter, +func (k Keeper) GetPromoterByAddress(ctx sdk.Context, address string) (val types.PromoterByAddress, found bool) { + store := k.getPromoterByAddressStore(ctx) + + b := store.Get(types.GetPromoterByAddressKey(address)) + if b == nil { + return val, false + } + + k.cdc.MustUnmarshal(b, &val) + return val, true +} diff --git a/x/reward/keeper/query_reward.go b/x/reward/keeper/query_reward.go index c1d2545e..8ea7acba 100644 --- a/x/reward/keeper/query_reward.go +++ b/x/reward/keeper/query_reward.go @@ -64,7 +64,7 @@ func (k Keeper) RewardsByAddress(goCtx context.Context, req *types.QueryRewardsB ctx := sdk.UnwrapSDKContext(goCtx) store := k.getRewardByReceiverAndCategoryStore(ctx) - rewardStore := prefix.NewStore(store, types.GetRewardsByAccPrefix(req.Address)) + rewardStore := prefix.NewStore(store, types.GetRewardsOfReceiverByPromoterPrefix(req.PromoterUid, req.Address)) pageRes, err := query.Paginate(rewardStore, req.Pagination, func(key []byte, value []byte) error { var reward types.RewardByCategory @@ -91,7 +91,7 @@ func (k Keeper) RewardsByAddressAndCategory(goCtx context.Context, req *types.Qu ctx := sdk.UnwrapSDKContext(goCtx) store := k.getRewardByReceiverAndCategoryStore(ctx) - rewardStore := prefix.NewStore(store, types.GetRewardsByCategoryPrefix(req.Address, req.Category)) + rewardStore := prefix.NewStore(store, types.GetRewardsOfReceiverByPromoterAndCategoryPrefix(req.PromoterUid, req.Address, req.Category)) pageRes, err := query.Paginate(rewardStore, req.Pagination, func(key []byte, value []byte) error { var reward types.RewardByCategory diff --git a/x/reward/keeper/reward.go b/x/reward/keeper/reward.go index 48a4151e..16f94b08 100644 --- a/x/reward/keeper/reward.go +++ b/x/reward/keeper/reward.go @@ -53,20 +53,20 @@ func (k Keeper) GetAllRewards(ctx sdk.Context) (list []types.Reward) { return } -func (k Keeper) SetRewardByReceiver(ctx sdk.Context, rByCategory types.RewardByCategory) { +func (k Keeper) SetRewardOfReceiverByPromoterAndCategory(ctx sdk.Context, promoterUID string, rByCategory types.RewardByCategory) { store := k.getRewardByReceiverAndCategoryStore(ctx) b := k.cdc.MustMarshal(&rByCategory) - store.Set(types.GetRewardsByCategoryKey(rByCategory.Addr, rByCategory.RewardCategory, rByCategory.UID), b) + store.Set(types.GetRewardsOfReceiverByPromoterAndCategoryKey(promoterUID, rByCategory.Addr, rByCategory.RewardCategory, rByCategory.UID), b) } -// GetRewardsByAddressAndCategory returns all rewards by address and category. -func (k Keeper) GetRewardsByAddressAndCategory( +// GetRewardsOfReceiverByPromoterAndCategory returns all rewards by address and category. +func (k Keeper) GetRewardsOfReceiverByPromoterAndCategory( ctx sdk.Context, - addr string, + promoterUID, addr string, category types.RewardCategory, ) (list []types.RewardByCategory, err error) { store := k.getRewardByReceiverAndCategoryStore(ctx) - iterator := sdk.KVStorePrefixIterator(store, types.GetRewardsByCategoryPrefix(addr, category)) + iterator := sdk.KVStorePrefixIterator(store, types.GetRewardsOfReceiverByPromoterAndCategoryPrefix(promoterUID, addr, category)) defer func() { err = iterator.Close() @@ -82,8 +82,8 @@ func (k Keeper) GetRewardsByAddressAndCategory( } // HasRewardByReceiver returns true if there is a record for the category and reward receiver -func (k Keeper) HasRewardByReceiver(ctx sdk.Context, addr string, category types.RewardCategory) bool { - rewardsByCat, err := k.GetRewardsByAddressAndCategory(ctx, addr, category) +func (k Keeper) HasRewardOfReceiverByPromoter(ctx sdk.Context, promoterUID, addr string, category types.RewardCategory) bool { + rewardsByCat, err := k.GetRewardsOfReceiverByPromoterAndCategory(ctx, promoterUID, addr, category) if err != nil || len(rewardsByCat) > 0 { return true } diff --git a/x/reward/keeper/view.go b/x/reward/keeper/view.go index be5119bc..56ddc0d5 100644 --- a/x/reward/keeper/view.go +++ b/x/reward/keeper/view.go @@ -30,3 +30,15 @@ func (k Keeper) getRewardsByCampaignStore(ctx sdk.Context) prefix.Store { store := ctx.KVStore(k.storeKey) return prefix.NewStore(store, types.RewardByCampaignKeyPrefix) } + +// getPromoterByAddressStore gets the store containing all promoter by address. +func (k Keeper) getPromoterByAddressStore(ctx sdk.Context) prefix.Store { + store := ctx.KVStore(k.storeKey) + return prefix.NewStore(store, types.PromoterAddressKeyPrefix) +} + +// getPromoterStore gets the store containing all promoters. +func (k Keeper) getPromoterStore(ctx sdk.Context) prefix.Store { + store := ctx.KVStore(k.storeKey) + return prefix.NewStore(store, types.PromoterKeyPrefix) +} diff --git a/x/reward/types/campaign.go b/x/reward/types/campaign.go index f61a9aa7..8b7b5c5f 100644 --- a/x/reward/types/campaign.go +++ b/x/reward/types/campaign.go @@ -7,7 +7,7 @@ import ( func NewCampaign( creator, promoter, uID string, - startTS, endTS, claimsPerCategory uint64, + startTS, endTS uint64, rewardType RewardType, rewardCategory RewardCategory, rewardAmountType RewardAmountType, @@ -17,19 +17,18 @@ func NewCampaign( pool Pool, ) Campaign { return Campaign{ - Creator: creator, - Promoter: promoter, - UID: uID, - StartTS: startTS, - EndTS: endTS, - RewardCategory: rewardCategory, - RewardType: rewardType, - RewardAmountType: rewardAmountType, - RewardAmount: rewardAmount, - IsActive: isActive, - Meta: meta, - Pool: pool, - ClaimsPerCategory: claimsPerCategory, + Creator: creator, + Promoter: promoter, + UID: uID, + StartTS: startTS, + EndTS: endTS, + RewardCategory: rewardCategory, + RewardType: rewardType, + RewardAmountType: rewardAmountType, + RewardAmount: rewardAmount, + IsActive: isActive, + Meta: meta, + Pool: pool, } } diff --git a/x/reward/types/campaign.pb.go b/x/reward/types/campaign.pb.go index b1249d6a..1e36025b 100644 --- a/x/reward/types/campaign.pb.go +++ b/x/reward/types/campaign.pb.go @@ -49,9 +49,6 @@ type Campaign struct { Pool Pool `protobuf:"bytes,10,opt,name=pool,proto3" json:"pool"` // is_active is the flag to check if the campaign is active or not. IsActive bool `protobuf:"varint,11,opt,name=is_active,json=isActive,proto3" json:"is_active,omitempty"` - // claims_per_category is the number of times a user can claim a - // reward for category of this campaign. - ClaimsPerCategory uint64 `protobuf:"varint,12,opt,name=claims_per_category,json=claimsPerCategory,proto3" json:"claims_per_category,omitempty"` // meta is the metadata of the campaign. // It is a stringified base64 encoded json. Meta string `protobuf:"bytes,13,opt,name=meta,proto3" json:"meta,omitempty"` @@ -167,13 +164,6 @@ func (m *Campaign) GetIsActive() bool { return false } -func (m *Campaign) GetClaimsPerCategory() uint64 { - if m != nil { - return m.ClaimsPerCategory - } - return 0 -} - func (m *Campaign) GetMeta() string { if m != nil { return m.Meta @@ -228,42 +218,40 @@ func init() { func init() { proto.RegisterFile("sge/reward/campaign.proto", fileDescriptor_6d1d1b3139567e36) } var fileDescriptor_6d1d1b3139567e36 = []byte{ - // 545 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0x4f, 0x6f, 0xd3, 0x3c, - 0x1c, 0xc7, 0x9b, 0xa7, 0x69, 0x9b, 0xba, 0x5d, 0x1f, 0xf0, 0x98, 0x66, 0x3a, 0x29, 0x09, 0x45, - 0x88, 0x22, 0xb4, 0x44, 0xda, 0xc4, 0x85, 0xdb, 0x52, 0x90, 0xd8, 0x05, 0x4d, 0xde, 0x76, 0xe1, - 0x52, 0x79, 0xa9, 0x95, 0x45, 0x6b, 0xe2, 0xc8, 0x76, 0x19, 0x7d, 0x17, 0xe3, 0x5d, 0xed, 0xb8, - 0x23, 0xe2, 0x10, 0xa1, 0xf4, 0xb6, 0x23, 0xaf, 0x00, 0xd9, 0xc9, 0xc2, 0x86, 0x60, 0xda, 0x25, - 0xfe, 0xfd, 0xf9, 0x7e, 0x3f, 0x49, 0xec, 0x9f, 0xc1, 0x53, 0x11, 0x51, 0x9f, 0xd3, 0x73, 0xc2, - 0x67, 0x7e, 0x48, 0x92, 0x8c, 0xc4, 0x51, 0xea, 0x65, 0x9c, 0x49, 0x06, 0x37, 0x44, 0x44, 0x53, - 0x2a, 0xcf, 0x19, 0x3f, 0xf3, 0x44, 0x44, 0xbd, 0x52, 0x35, 0x7c, 0x12, 0xb1, 0x88, 0x69, 0x85, - 0xaf, 0xa2, 0x52, 0x3c, 0xdc, 0xbc, 0xc5, 0x29, 0x97, 0xb2, 0x31, 0xfa, 0xda, 0x02, 0xd6, 0xa4, - 0x02, 0x43, 0x04, 0x3a, 0x21, 0xa7, 0x44, 0x32, 0x8e, 0x0c, 0xd7, 0x18, 0x77, 0xf1, 0x4d, 0x0a, - 0x5d, 0xd0, 0x5c, 0xc4, 0x33, 0xf4, 0x9f, 0xaa, 0x06, 0x83, 0x22, 0x77, 0x9a, 0xc7, 0xfb, 0xef, - 0xae, 0x73, 0x47, 0x55, 0xb1, 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8, 0x05, 0xba, 0xb1, 0x98, 0x92, 0x50, - 0xc6, 0x9f, 0x29, 0xea, 0xb9, 0xc6, 0xd8, 0xc2, 0x56, 0x2c, 0xf6, 0x74, 0x0e, 0x3d, 0xb0, 0x1e, - 0xce, 0x49, 0x9c, 0x88, 0x69, 0x46, 0xf9, 0xef, 0xc3, 0xe8, 0xab, 0x23, 0xc4, 0x8f, 0xcb, 0xd6, - 0x01, 0xe5, 0xf5, 0x46, 0x43, 0x60, 0x26, 0x54, 0x12, 0xb4, 0xa6, 0x47, 0x46, 0xc7, 0xa3, 0x0b, - 0x03, 0x98, 0xea, 0xad, 0x70, 0x02, 0x5a, 0x92, 0x49, 0x32, 0x2f, 0xa7, 0x31, 0xd8, 0x56, 0x1f, - 0xf1, 0x3d, 0x77, 0x36, 0x42, 0x26, 0x12, 0x26, 0xc4, 0xec, 0xcc, 0x8b, 0x99, 0x9f, 0x10, 0x79, - 0xea, 0xed, 0xa7, 0xf2, 0x67, 0xee, 0xf4, 0x97, 0x24, 0x99, 0xbf, 0x1d, 0x69, 0xcf, 0x08, 0x97, - 0x5e, 0x05, 0x11, 0x19, 0x4d, 0x65, 0x35, 0xbc, 0x0f, 0x85, 0x68, 0xcf, 0x08, 0x97, 0xde, 0x60, - 0x72, 0x59, 0xd8, 0xc6, 0x55, 0x61, 0x1b, 0x3f, 0x0a, 0xdb, 0xb8, 0x58, 0xd9, 0x8d, 0xab, 0x95, - 0xdd, 0xf8, 0xb6, 0xb2, 0x1b, 0x9f, 0x5e, 0x45, 0xb1, 0x3c, 0x5d, 0x9c, 0x78, 0x21, 0x4b, 0x7c, - 0x11, 0xd1, 0xed, 0x6a, 0x07, 0x55, 0xec, 0x7f, 0xb9, 0xb9, 0x72, 0xea, 0xe4, 0xc5, 0x49, 0x5b, - 0x5f, 0xb9, 0xdd, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xb3, 0x08, 0x2a, 0x3e, 0xd5, 0x03, 0x00, - 0x00, + // 517 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0x4f, 0x6f, 0xd3, 0x30, + 0x18, 0xc6, 0x6b, 0x9a, 0xb6, 0xa9, 0xbb, 0x15, 0x64, 0x98, 0x66, 0x3a, 0x29, 0x09, 0x45, 0x88, + 0x22, 0xb4, 0x44, 0xda, 0xc4, 0x85, 0xdb, 0x52, 0x90, 0xd8, 0x05, 0x21, 0x6f, 0xbb, 0x70, 0xa9, + 0xbc, 0xd4, 0xca, 0xa2, 0x35, 0x71, 0x64, 0xbb, 0x8c, 0x7e, 0x8b, 0x7d, 0xac, 0x1d, 0x77, 0x44, + 0x1c, 0x22, 0x48, 0x6f, 0x3b, 0xf2, 0x09, 0x90, 0x9d, 0xac, 0xda, 0x10, 0x9b, 0x76, 0xc9, 0xfb, + 0xef, 0x79, 0x7e, 0x52, 0xec, 0xd7, 0xf0, 0xb9, 0x8c, 0x59, 0x20, 0xd8, 0x19, 0x15, 0xd3, 0x20, + 0xa2, 0x69, 0x4e, 0x93, 0x38, 0xf3, 0x73, 0xc1, 0x15, 0x47, 0x1b, 0x32, 0x66, 0x19, 0x53, 0x67, + 0x5c, 0x9c, 0xfa, 0x32, 0x66, 0x7e, 0xa5, 0x1a, 0x3c, 0x8b, 0x79, 0xcc, 0x8d, 0x22, 0xd0, 0x59, + 0x25, 0x1e, 0x6c, 0xde, 0xe0, 0x54, 0xa1, 0x1a, 0x0c, 0x7f, 0x5b, 0xd0, 0x1e, 0xd7, 0x60, 0x84, + 0x61, 0x27, 0x12, 0x8c, 0x2a, 0x2e, 0x30, 0xf0, 0xc0, 0xa8, 0x4b, 0xae, 0x4b, 0xe4, 0xc1, 0xe6, + 0x3c, 0x99, 0xe2, 0x47, 0xba, 0x1b, 0xf6, 0xcb, 0xc2, 0x6d, 0x1e, 0xed, 0x7f, 0xb8, 0x2a, 0x5c, + 0xdd, 0x25, 0xfa, 0x83,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ec, 0x26, 0x72, 0x42, 0x23, 0x95, 0x7c, 0x63, + 0xb8, 0xe7, 0x81, 0x91, 0x4d, 0xec, 0x44, 0xee, 0x99, 0x1a, 0x21, 0x68, 0xa5, 0x4c, 0x51, 0xbc, + 0x6e, 0x56, 0xc0, 0xe4, 0xc3, 0x73, 0x00, 0x2d, 0x4d, 0x41, 0x63, 0xd8, 0x52, 0x5c, 0xd1, 0x59, + 0xb5, 0x5d, 0xe1, 0xb6, 0x86, 0xfe, 0x2c, 0xdc, 0x8d, 0x88, 0xcb, 0x94, 0x4b, 0x39, 0x3d, 0xf5, + 0x13, 0x1e, 0xa4, 0x54, 0x9d, 0xf8, 0xfb, 0x99, 0xfa, 0x53, 0xb8, 0x6b, 0x0b, 0x9a, 0xce, 0xde, + 0x0f, 0x8d, 0x67, 0x48, 0x2a, 0xaf, 0x86, 0xc8, 0x9c, 0x65, 0xaa, 0x5e, 0xc6, 0x87, 0x42, 0x8c, + 0x67, 0x48, 0x2a, 0x6f, 0x38, 0xbe, 0x28, 0x1d, 0x70, 0x59, 0x3a, 0xe0, 0x57, 0xe9, 0x80, 0xf3, + 0xa5, 0xd3, 0xb8, 0x5c, 0x3a, 0x8d, 0x1f, 0x4b, 0xa7, 0xf1, 0xf5, 0x4d, 0x9c, 0xa8, 0x93, 0xf9, + 0xb1, 0x1f, 0xf1, 0x34, 0x90, 0x31, 0xdb, 0xae, 0x4f, 0x44, 0xe7, 0xc1, 0xf7, 0xeb, 0x27, 0xa4, + 0x6f, 0x52, 0x1e, 0xb7, 0xcd, 0x13, 0xda, 0xfd, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x3d, 0xcd, 0xa3, + 0x61, 0xa5, 0x03, 0x00, 0x00, } func (m *Campaign) Marshal() (dAtA []byte, err error) { @@ -293,11 +281,6 @@ func (m *Campaign) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x6a } - if m.ClaimsPerCategory != 0 { - i = encodeVarintCampaign(dAtA, i, uint64(m.ClaimsPerCategory)) - i-- - dAtA[i] = 0x60 - } if m.IsActive { i-- if m.IsActive { @@ -475,9 +458,6 @@ func (m *Campaign) Size() (n int) { if m.IsActive { n += 2 } - if m.ClaimsPerCategory != 0 { - n += 1 + sovCampaign(uint64(m.ClaimsPerCategory)) - } l = len(m.Meta) if l > 0 { n += 1 + l + sovCampaign(uint64(l)) @@ -813,25 +793,6 @@ func (m *Campaign) Unmarshal(dAtA []byte) error { } } m.IsActive = bool(v != 0) - case 12: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimsPerCategory", wireType) - } - m.ClaimsPerCategory = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowCampaign - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ClaimsPerCategory |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } case 13: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Meta", wireType) diff --git a/x/reward/types/expected_keepers.go b/x/reward/types/expected_keepers.go index 7445762e..eac09a54 100644 --- a/x/reward/types/expected_keepers.go +++ b/x/reward/types/expected_keepers.go @@ -71,5 +71,6 @@ type SubAccountKeeper interface { // RewardKeeper defines the expected interface needed to get and filter the rewards. type RewardKeeper interface { - HasRewardByReceiver(ctx sdk.Context, addr string, category RewardCategory) bool + HasRewardOfReceiverByPromoter(ctx sdk.Context, promoterUID, addr string, category RewardCategory) bool + GetPromoterByAddress(ctx sdk.Context, address string) (val PromoterByAddress, found bool) } diff --git a/x/reward/types/genesis.pb.go b/x/reward/types/genesis.pb.go index c3bdca04..7eaff929 100644 --- a/x/reward/types/genesis.pb.go +++ b/x/reward/types/genesis.pb.go @@ -25,11 +25,13 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the reward module's genesis state. type GenesisState struct { - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` - CampaignList []Campaign `protobuf:"bytes,2,rep,name=campaign_list,json=campaignList,proto3" json:"campaign_list"` - RewardList []Reward `protobuf:"bytes,3,rep,name=reward_list,json=rewardList,proto3" json:"reward_list"` - RewardByCategoryList []RewardByCategory `protobuf:"bytes,4,rep,name=reward_by_category_list,json=rewardByCategoryList,proto3" json:"reward_by_category_list"` - RewardByCampaignList []RewardByCampaign `protobuf:"bytes,5,rep,name=reward_by_campaign_list,json=rewardByCampaignList,proto3" json:"reward_by_campaign_list"` + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + CampaignList []Campaign `protobuf:"bytes,2,rep,name=campaign_list,json=campaignList,proto3" json:"campaign_list"` + RewardList []Reward `protobuf:"bytes,3,rep,name=reward_list,json=rewardList,proto3" json:"reward_list"` + RewardByCategoryList []RewardByCategory `protobuf:"bytes,4,rep,name=reward_by_category_list,json=rewardByCategoryList,proto3" json:"reward_by_category_list"` + RewardByCampaignList []RewardByCampaign `protobuf:"bytes,5,rep,name=reward_by_campaign_list,json=rewardByCampaignList,proto3" json:"reward_by_campaign_list"` + PromoterList []Promoter `protobuf:"bytes,6,rep,name=promoter_list,json=promoterList,proto3" json:"promoter_list"` + PromoterByAddressList []PromoterByAddress `protobuf:"bytes,7,rep,name=promoter_by_address_list,json=promoterByAddressList,proto3" json:"promoter_by_address_list"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -100,6 +102,20 @@ func (m *GenesisState) GetRewardByCampaignList() []RewardByCampaign { return nil } +func (m *GenesisState) GetPromoterList() []Promoter { + if m != nil { + return m.PromoterList + } + return nil +} + +func (m *GenesisState) GetPromoterByAddressList() []PromoterByAddress { + if m != nil { + return m.PromoterByAddressList + } + return nil +} + func init() { proto.RegisterType((*GenesisState)(nil), "sgenetwork.sge.reward.GenesisState") } @@ -107,28 +123,31 @@ func init() { func init() { proto.RegisterFile("sge/reward/genesis.proto", fileDescriptor_cf3f52dafc32b537) } var fileDescriptor_cf3f52dafc32b537 = []byte{ - // 324 bytes of a gzipped FileDescriptorProto -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x93, 0x70, 0xb9, 0x26, 0x08, 0x4c, 0x41, 0xcd, 0xe1, - 0x82, 0x08, 0x82, 0x4d, 0x49, 0xe1, 0x12, 0x87, 0x9a, 0x92, 0x54, 0x19, 0x9f, 0x9c, 0x58, 0x92, - 0x9a, 0x9e, 0x5f, 0x54, 0x09, 0x31, 0x91, 0x05, 0x6c, 0xa2, 0x3a, 0x7e, 0x13, 0x2b, 0x9d, 0xa1, - 0x7a, 0xa0, 0x66, 0x8b, 0x14, 0xa1, 0x89, 0x63, 0xb3, 0x05, 0x39, 0x04, 0x58, 0x89, 0xb4, 0x05, - 0x25, 0x24, 0x90, 0x6c, 0x41, 0x84, 0x88, 0x93, 0xf3, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, - 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, - 0xcb, 0x31, 0x44, 0x69, 0xa6, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0x17, - 0xa7, 0xa7, 0xea, 0x42, 0x6d, 0x02, 0xb1, 0xf5, 0x2b, 0x60, 0xf1, 0x5e, 0x52, 0x59, 0x90, 0x5a, - 0x9c, 0xc4, 0x06, 0x8e, 0x77, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x4a, 0x9d, 0xa4, 0xe3, - 0x8d, 0x02, 0x00, 0x00, + // 376 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x41, 0x4f, 0xc2, 0x30, + 0x1c, 0xc5, 0x37, 0x41, 0x4c, 0x0a, 0x5c, 0x16, 0x08, 0x93, 0xc4, 0x41, 0xbc, 0x88, 0x07, 0xb7, + 0x04, 0x8f, 0x9e, 0x04, 0x13, 0x13, 0xe2, 0x81, 0xe0, 0xcd, 0x0b, 0xe9, 0x58, 0x53, 0x17, 0x1d, + 0x5d, 0xda, 0x1a, 0xdc, 0xb7, 0xf0, 0x63, 0x71, 0xe4, 0xe8, 0x89, 0x18, 0xf8, 0x22, 0x66, 0xfd, + 0x77, 0x66, 0x92, 0x81, 0x9e, 0xda, 0xb5, 0xef, 0xfd, 0xde, 0x3f, 0x6f, 0x45, 0xb6, 0xa0, 0xc4, + 0xe3, 0x64, 0x81, 0x79, 0xe0, 0x51, 0x32, 0x27, 0x22, 0x14, 0x6e, 0xcc, 0x99, 0x64, 0x56, 0x53, + 0xa4, 0xdf, 0x72, 0xc1, 0xf8, 0x8b, 0x2b, 0x28, 0x71, 0x41, 0xd4, 0x6e, 0x50, 0x46, 0x99, 0x52, + 0x78, 0xe9, 0x0e, 0xc4, 0xed, 0x56, 0x0e, 0x13, 0x63, 0x8e, 0x23, 0x4d, 0x69, 0x9f, 0xe6, 0x2e, + 0x66, 0x38, 0x8a, 0x71, 0x48, 0xe7, 0x05, 0x1e, 0x58, 0x0a, 0x3c, 0x31, 0x67, 0x11, 0x93, 0x84, + 0xc3, 0xd5, 0xf9, 0xba, 0x8c, 0x6a, 0xf7, 0x30, 0xe6, 0xa3, 0xc4, 0x92, 0x58, 0x37, 0xa8, 0x02, + 0x79, 0xb6, 0xd9, 0x35, 0x7b, 0xd5, 0xfe, 0x99, 0x5b, 0x38, 0xb6, 0x3b, 0x56, 0xa2, 0x41, 0x79, + 0xb9, 0xee, 0x18, 0x13, 0x6d, 0xb1, 0x46, 0xa8, 0x9e, 0xcd, 0x34, 0x7d, 0x0d, 0x85, 0xb4, 0x8f, + 0xba, 0xa5, 0x5e, 0xb5, 0xdf, 0xd9, 0xc3, 0x18, 0x6a, 0xad, 0xa6, 0xd4, 0x32, 0xef, 0x43, 0x28, + 0xa4, 0x75, 0x87, 0xaa, 0x20, 0x03, 0x52, 0x49, 0x91, 0xf6, 0x4d, 0x33, 0x51, 0x8b, 0xe6, 0x20, + 0x38, 0x54, 0x94, 0x00, 0xb5, 0x34, 0xc5, 0x4f, 0xa6, 0x33, 0x2c, 0x09, 0x65, 0x3c, 0x01, 0x62, + 0x59, 0x11, 0x2f, 0x0e, 0x13, 0x93, 0xa1, 0xf6, 0x68, 0x76, 0x83, 0xef, 0x9c, 0x17, 0xa5, 0xe4, + 0x1b, 0x38, 0xfe, 0x67, 0xca, 0xaf, 0x26, 0x72, 0x29, 0xb9, 0x46, 0x46, 0xa8, 0x9e, 0xfd, 0x3d, + 0x60, 0x57, 0x0e, 0xb6, 0x3b, 0xd6, 0xda, 0xac, 0xdd, 0xcc, 0xab, 0x58, 0x14, 0xd9, 0x3f, 0x2c, + 0x3f, 0x99, 0xe2, 0x20, 0xe0, 0x44, 0x08, 0xc0, 0x9e, 0x28, 0x6c, 0xef, 0x2f, 0x6c, 0x72, 0x0b, + 0x26, 0xcd, 0x6f, 0xc6, 0xbb, 0x17, 0x69, 0xd0, 0x60, 0xb8, 0xdc, 0x38, 0xe6, 0x6a, 0xe3, 0x98, + 0x5f, 0x1b, 0xc7, 0xfc, 0xd8, 0x3a, 0xc6, 0x6a, 0xeb, 0x18, 0x9f, 0x5b, 0xc7, 0x78, 0xba, 0xa4, + 0xa1, 0x7c, 0x7e, 0xf3, 0xdd, 0x19, 0x8b, 0x3c, 0x41, 0xc9, 0x95, 0xce, 0x4a, 0xf7, 0xde, 0x7b, + 0xf6, 0x5c, 0x65, 0x12, 0x13, 0xe1, 0x57, 0xd4, 0x63, 0xbd, 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, + 0xd3, 0x6c, 0xe5, 0xbd, 0x5d, 0x03, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -151,6 +170,34 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.PromoterByAddressList) > 0 { + for iNdEx := len(m.PromoterByAddressList) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.PromoterByAddressList[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + } + } + if len(m.PromoterList) > 0 { + for iNdEx := len(m.PromoterList) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.PromoterList[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + } + } if len(m.RewardByCampaignList) > 0 { for iNdEx := len(m.RewardByCampaignList) - 1; iNdEx >= 0; iNdEx-- { { @@ -263,6 +310,18 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } + if len(m.PromoterList) > 0 { + for _, e := range m.PromoterList { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + if len(m.PromoterByAddressList) > 0 { + for _, e := range m.PromoterByAddressList { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } return n } @@ -470,6 +529,74 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PromoterList", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PromoterList = append(m.PromoterList, Promoter{}) + if err := m.PromoterList[len(m.PromoterList)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PromoterByAddressList", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PromoterByAddressList = append(m.PromoterByAddressList, PromoterByAddress{}) + if err := m.PromoterByAddressList[len(m.PromoterByAddressList)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/reward/types/key_promoter.go b/x/reward/types/key_promoter.go new file mode 100644 index 00000000..509e6bcd --- /dev/null +++ b/x/reward/types/key_promoter.go @@ -0,0 +1,27 @@ +package types + +import ( + "encoding/binary" + + "github.com/sge-network/sge/utils" +) + +var _ binary.ByteOrder + +var ( + // PromoterKeyPrefix is the prefix to retrieve all promoter + PromoterKeyPrefix = []byte{0x04} + + // PromoterAddressKeyPrefix is the prefix to retrieve all addresses promoter + PromoterAddressKeyPrefix = []byte{0x05} +) + +// GetPromoterKey returns the store key to retrieve a promoter +func GetPromoterKey(uid string) []byte { + return utils.StrBytes(uid) +} + +// GetPromoterByAddressKey returns the promoter of a certain promoter address. +func GetPromoterByAddressKey(accAddr string) []byte { + return utils.StrBytes(accAddr) +} diff --git a/x/reward/types/key_reward.go b/x/reward/types/key_reward.go index 66043780..19f9742e 100644 --- a/x/reward/types/key_reward.go +++ b/x/reward/types/key_reward.go @@ -19,20 +19,20 @@ var ( RewardByCampaignKeyPrefix = []byte{0x03} ) -// GetRewardsByAccPrefix returns the store key to retrieve list of all applied rewards of a certain campaign +// GetRewardsOfReceiverByPromoterPrefix returns the store key to retrieve list of all applied rewards of a certain campaign // this should be used with RewardByReceiverKeyPrefix -func GetRewardsByAccPrefix(receiverAcc string) []byte { - return utils.StrBytes(receiverAcc) +func GetRewardsOfReceiverByPromoterPrefix(promoterUID, receiverAcc string) []byte { + return append(utils.StrBytes(promoterUID), utils.StrBytes(receiverAcc)...) } -// GetRewardsByCategoryPrefix returns the store key to retrieve list of all applied rewards of certain address and category -func GetRewardsByCategoryPrefix(receiverAcc string, rewardCategory RewardCategory) []byte { - return append(GetRewardsByAccPrefix(receiverAcc), utils.Int32ToBytes(int32(rewardCategory))...) +// GetRewardsOfReceiverByPromoterAndCategoryPrefix returns the store key to retrieve list of all applied rewards of certain address and category +func GetRewardsOfReceiverByPromoterAndCategoryPrefix(promoterUID, receiverAcc string, rewardCategory RewardCategory) []byte { + return append(GetRewardsOfReceiverByPromoterPrefix(promoterUID, receiverAcc), utils.Int32ToBytes(int32(rewardCategory))...) } -// GetRewardsByCategoryKey returns the store key to retrieve list of applied reward of certain address and category -func GetRewardsByCategoryKey(receiverAcc string, rewardCategory RewardCategory, uid string) []byte { - return append(GetRewardsByCategoryPrefix(receiverAcc, rewardCategory), utils.StrBytes(uid)...) +// GetRewardsOfReceiverByPromoterAndCategoryKey returns the store key to retrieve list of applied reward of certain address and category +func GetRewardsOfReceiverByPromoterAndCategoryKey(promoterUID, receiverAcc string, rewardCategory RewardCategory, uid string) []byte { + return append(GetRewardsOfReceiverByPromoterAndCategoryPrefix(promoterUID, receiverAcc, rewardCategory), utils.StrBytes(uid)...) } // GetRewardKey returns the store key to retrieve a certain reward. diff --git a/x/reward/types/promoter.pb.go b/x/reward/types/promoter.pb.go new file mode 100644 index 00000000..7fd7945a --- /dev/null +++ b/x/reward/types/promoter.pb.go @@ -0,0 +1,1092 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sge/reward/promoter.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Promoter is type for defining the reward promoter properties and configuration. +type Promoter struct { + // creator is the address of promoter. + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + // uid is the unique identifier of a promoter. + UID string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid"` + // addresses is the list of account addresses of promoter. + Addresses []string `protobuf:"bytes,3,rep,name=addresses,proto3" json:"addresses,omitempty"` + // conf is the configurations of the current promoter for the reward grant. + Conf PromoterConf `protobuf:"bytes,4,opt,name=conf,proto3" json:"conf"` +} + +func (m *Promoter) Reset() { *m = Promoter{} } +func (m *Promoter) String() string { return proto.CompactTextString(m) } +func (*Promoter) ProtoMessage() {} +func (*Promoter) Descriptor() ([]byte, []int) { + return fileDescriptor_35eedf87bdac6383, []int{0} +} +func (m *Promoter) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Promoter) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Promoter.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 *Promoter) XXX_Merge(src proto.Message) { + xxx_messageInfo_Promoter.Merge(m, src) +} +func (m *Promoter) XXX_Size() int { + return m.Size() +} +func (m *Promoter) XXX_DiscardUnknown() { + xxx_messageInfo_Promoter.DiscardUnknown(m) +} + +var xxx_messageInfo_Promoter proto.InternalMessageInfo + +func (m *Promoter) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *Promoter) GetUID() string { + if m != nil { + return m.UID + } + return "" +} + +func (m *Promoter) GetAddresses() []string { + if m != nil { + return m.Addresses + } + return nil +} + +func (m *Promoter) GetConf() PromoterConf { + if m != nil { + return m.Conf + } + return PromoterConf{} +} + +// PromoterConf is type for defining the promoter specific configurations. +type PromoterConf struct { + // category_cap is the maximium allowed cap for each category. + CategoryCap []CategoryCap `protobuf:"bytes,1,rep,name=category_cap,json=categoryCap,proto3" json:"category_cap"` +} + +func (m *PromoterConf) Reset() { *m = PromoterConf{} } +func (m *PromoterConf) String() string { return proto.CompactTextString(m) } +func (*PromoterConf) ProtoMessage() {} +func (*PromoterConf) Descriptor() ([]byte, []int) { + return fileDescriptor_35eedf87bdac6383, []int{1} +} +func (m *PromoterConf) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PromoterConf) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PromoterConf.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 *PromoterConf) XXX_Merge(src proto.Message) { + xxx_messageInfo_PromoterConf.Merge(m, src) +} +func (m *PromoterConf) XXX_Size() int { + return m.Size() +} +func (m *PromoterConf) XXX_DiscardUnknown() { + xxx_messageInfo_PromoterConf.DiscardUnknown(m) +} + +var xxx_messageInfo_PromoterConf proto.InternalMessageInfo + +func (m *PromoterConf) GetCategoryCap() []CategoryCap { + if m != nil { + return m.CategoryCap + } + return nil +} + +// CategoryCap is type to define category and its maximum cap. +type CategoryCap struct { + Category RewardCategory `protobuf:"varint,1,opt,name=category,proto3,enum=sgenetwork.sge.reward.RewardCategory" json:"category,omitempty"` + CapPerAcc int32 `protobuf:"varint,2,opt,name=cap_per_acc,json=capPerAcc,proto3" json:"cap_per_acc,omitempty"` +} + +func (m *CategoryCap) Reset() { *m = CategoryCap{} } +func (m *CategoryCap) String() string { return proto.CompactTextString(m) } +func (*CategoryCap) ProtoMessage() {} +func (*CategoryCap) Descriptor() ([]byte, []int) { + return fileDescriptor_35eedf87bdac6383, []int{2} +} +func (m *CategoryCap) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CategoryCap) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CategoryCap.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 *CategoryCap) XXX_Merge(src proto.Message) { + xxx_messageInfo_CategoryCap.Merge(m, src) +} +func (m *CategoryCap) XXX_Size() int { + return m.Size() +} +func (m *CategoryCap) XXX_DiscardUnknown() { + xxx_messageInfo_CategoryCap.DiscardUnknown(m) +} + +var xxx_messageInfo_CategoryCap proto.InternalMessageInfo + +func (m *CategoryCap) GetCategory() RewardCategory { + if m != nil { + return m.Category + } + return RewardCategory_REWARD_CATEGORY_UNSPECIFIED +} + +func (m *CategoryCap) GetCapPerAcc() int32 { + if m != nil { + return m.CapPerAcc + } + return 0 +} + +// PromoterByAddress is type for defining the promoter by address. +type PromoterByAddress struct { + // promoter_uid is the unique identifier of a certain promoter. + PromoterUID string `protobuf:"bytes,1,opt,name=promoter_uid,proto3" json:"promoter_uid"` + // address is the address of the promoter account. + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` +} + +func (m *PromoterByAddress) Reset() { *m = PromoterByAddress{} } +func (m *PromoterByAddress) String() string { return proto.CompactTextString(m) } +func (*PromoterByAddress) ProtoMessage() {} +func (*PromoterByAddress) Descriptor() ([]byte, []int) { + return fileDescriptor_35eedf87bdac6383, []int{3} +} +func (m *PromoterByAddress) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PromoterByAddress) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_PromoterByAddress.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 *PromoterByAddress) XXX_Merge(src proto.Message) { + xxx_messageInfo_PromoterByAddress.Merge(m, src) +} +func (m *PromoterByAddress) XXX_Size() int { + return m.Size() +} +func (m *PromoterByAddress) XXX_DiscardUnknown() { + xxx_messageInfo_PromoterByAddress.DiscardUnknown(m) +} + +var xxx_messageInfo_PromoterByAddress proto.InternalMessageInfo + +func (m *PromoterByAddress) GetPromoterUID() string { + if m != nil { + return m.PromoterUID + } + return "" +} + +func (m *PromoterByAddress) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func init() { + proto.RegisterType((*Promoter)(nil), "sgenetwork.sge.reward.Promoter") + proto.RegisterType((*PromoterConf)(nil), "sgenetwork.sge.reward.PromoterConf") + proto.RegisterType((*CategoryCap)(nil), "sgenetwork.sge.reward.CategoryCap") + proto.RegisterType((*PromoterByAddress)(nil), "sgenetwork.sge.reward.PromoterByAddress") +} + +func init() { proto.RegisterFile("sge/reward/promoter.proto", fileDescriptor_35eedf87bdac6383) } + +var fileDescriptor_35eedf87bdac6383 = []byte{ + // 403 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x52, 0xbd, 0xae, 0xd3, 0x30, + 0x18, 0x8d, 0x49, 0x81, 0x1b, 0xa7, 0xba, 0x12, 0x16, 0x88, 0x70, 0x85, 0x92, 0x28, 0x08, 0x29, + 0x0c, 0x24, 0x52, 0x99, 0x19, 0x9a, 0xb0, 0x20, 0x96, 0xca, 0x12, 0x0b, 0x0c, 0x91, 0xeb, 0xb8, + 0xa6, 0x42, 0xad, 0x2d, 0x3b, 0x55, 0xe9, 0x5b, 0xf0, 0x0e, 0xbc, 0x4c, 0xc7, 0x8e, 0x4c, 0x11, + 0x4a, 0x37, 0x9e, 0x02, 0xe5, 0xc7, 0xb4, 0x95, 0x6e, 0x17, 0xdb, 0xdf, 0xf9, 0xce, 0x77, 0x64, + 0x9f, 0x63, 0xf8, 0x42, 0x73, 0x96, 0x2a, 0xb6, 0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xee, + 0x36, 0x33, 0x8b, 0xff, 0x8f, 0x21, 0x1f, 0xba, 0x94, 0xc8, 0x42, 0x32, 0x55, 0x10, 0x4a, 0x3b, + 0xd7, 0x1e, 0x62, 0x87, 0x12, 0x39, 0x63, 0x6a, 0x4a, 0x69, 0xa4, 0xe0, 0x13, 0xf3, 0x9c, 0x6c, + 0x37, 0xed, 0x4d, 0x42, 0x39, 0x1c, 0x9b, 0x84, 0x8b, 0xd6, 0xeb, 0x2e, 0x81, 0x2c, 0x68, 0xea, + 0xc0, 0x35, 0xe4, 0xde, 0xf3, 0x0b, 0x1a, 0xbe, 0xa8, 0xda, 0x04, 0x07, 0xd3, 0xfb, 0xac, 0xb0, + 0x29, 0xb3, 0x7c, 0xdf, 0xf8, 0xe0, 0xd0, 0xf8, 0xe0, 0x4f, 0xe3, 0x83, 0x9f, 0x47, 0xdf, 0x3a, + 0x1c, 0x7d, 0xeb, 0xf7, 0xd1, 0xb7, 0xbe, 0xbc, 0xe1, 0xcb, 0xea, 0xdb, 0x66, 0x9e, 0x50, 0xb1, + 0x4a, 0x35, 0x67, 0x6f, 0x87, 0x97, 0xb6, 0xe7, 0xf4, 0x87, 0xf9, 0x34, 0xd5, 0x4e, 0x32, 0x3d, + 0x7f, 0xd4, 0x7d, 0x9a, 0x77, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0x52, 0x04, 0xe9, 0xf0, 0x97, + 0x02, 0x00, 0x00, +} + +func (m *Promoter) 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 *Promoter) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Promoter) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Conf.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPromoter(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + if len(m.Addresses) > 0 { + for iNdEx := len(m.Addresses) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Addresses[iNdEx]) + copy(dAtA[i:], m.Addresses[iNdEx]) + i = encodeVarintPromoter(dAtA, i, uint64(len(m.Addresses[iNdEx]))) + i-- + dAtA[i] = 0x1a + } + } + if len(m.UID) > 0 { + i -= len(m.UID) + copy(dAtA[i:], m.UID) + i = encodeVarintPromoter(dAtA, i, uint64(len(m.UID))) + i-- + dAtA[i] = 0x12 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintPromoter(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *PromoterConf) 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 *PromoterConf) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PromoterConf) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CategoryCap) > 0 { + for iNdEx := len(m.CategoryCap) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.CategoryCap[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintPromoter(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *CategoryCap) 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 *CategoryCap) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CategoryCap) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.CapPerAcc != 0 { + i = encodeVarintPromoter(dAtA, i, uint64(m.CapPerAcc)) + i-- + dAtA[i] = 0x10 + } + if m.Category != 0 { + i = encodeVarintPromoter(dAtA, i, uint64(m.Category)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *PromoterByAddress) 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 *PromoterByAddress) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PromoterByAddress) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintPromoter(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0x12 + } + if len(m.PromoterUID) > 0 { + i -= len(m.PromoterUID) + copy(dAtA[i:], m.PromoterUID) + i = encodeVarintPromoter(dAtA, i, uint64(len(m.PromoterUID))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintPromoter(dAtA []byte, offset int, v uint64) int { + offset -= sovPromoter(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Promoter) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovPromoter(uint64(l)) + } + l = len(m.UID) + if l > 0 { + n += 1 + l + sovPromoter(uint64(l)) + } + if len(m.Addresses) > 0 { + for _, s := range m.Addresses { + l = len(s) + n += 1 + l + sovPromoter(uint64(l)) + } + } + l = m.Conf.Size() + n += 1 + l + sovPromoter(uint64(l)) + return n +} + +func (m *PromoterConf) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.CategoryCap) > 0 { + for _, e := range m.CategoryCap { + l = e.Size() + n += 1 + l + sovPromoter(uint64(l)) + } + } + return n +} + +func (m *CategoryCap) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Category != 0 { + n += 1 + sovPromoter(uint64(m.Category)) + } + if m.CapPerAcc != 0 { + n += 1 + sovPromoter(uint64(m.CapPerAcc)) + } + return n +} + +func (m *PromoterByAddress) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.PromoterUID) + if l > 0 { + n += 1 + l + sovPromoter(uint64(l)) + } + l = len(m.Address) + if l > 0 { + n += 1 + l + sovPromoter(uint64(l)) + } + return n +} + +func sovPromoter(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozPromoter(x uint64) (n int) { + return sovPromoter(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Promoter) 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 ErrIntOverflowPromoter + } + 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: Promoter: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Promoter: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPromoter + } + 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 ErrInvalidLengthPromoter + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPromoter + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPromoter + } + 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 ErrInvalidLengthPromoter + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPromoter + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.UID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Addresses", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPromoter + } + 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 ErrInvalidLengthPromoter + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPromoter + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Addresses = append(m.Addresses, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Conf", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPromoter + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPromoter + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPromoter + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Conf.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPromoter(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPromoter + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PromoterConf) 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 ErrIntOverflowPromoter + } + 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: PromoterConf: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PromoterConf: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CategoryCap", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPromoter + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthPromoter + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthPromoter + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CategoryCap = append(m.CategoryCap, CategoryCap{}) + if err := m.CategoryCap[len(m.CategoryCap)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPromoter(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPromoter + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *CategoryCap) 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 ErrIntOverflowPromoter + } + 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: CategoryCap: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CategoryCap: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Category", wireType) + } + m.Category = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPromoter + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Category |= RewardCategory(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CapPerAcc", wireType) + } + m.CapPerAcc = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPromoter + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CapPerAcc |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipPromoter(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPromoter + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PromoterByAddress) 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 ErrIntOverflowPromoter + } + 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: PromoterByAddress: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PromoterByAddress: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PromoterUID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPromoter + } + 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 ErrInvalidLengthPromoter + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPromoter + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PromoterUID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPromoter + } + 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 ErrInvalidLengthPromoter + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPromoter + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipPromoter(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPromoter + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipPromoter(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPromoter + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPromoter + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPromoter + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthPromoter + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPromoter + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthPromoter + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthPromoter = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPromoter = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPromoter = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/reward/types/query.pb.go b/x/reward/types/query.pb.go index 8405e5e4..b7a3cc6b 100644 --- a/x/reward/types/query.pb.go +++ b/x/reward/types/query.pb.go @@ -493,8 +493,9 @@ func (m *QueryRewardsResponse) GetPagination() *query.PageResponse { // QueryRewardsByAddressRequest is request body for the query all rewards by // address endpoint. type QueryRewardsByAddressRequest struct { - Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` - Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` + PromoterUid string `protobuf:"bytes,3,opt,name=promoter_uid,json=promoterUid,proto3" json:"promoter_uid,omitempty"` } func (m *QueryRewardsByAddressRequest) Reset() { *m = QueryRewardsByAddressRequest{} } @@ -544,6 +545,13 @@ func (m *QueryRewardsByAddressRequest) GetAddress() string { return "" } +func (m *QueryRewardsByAddressRequest) GetPromoterUid() string { + if m != nil { + return m.PromoterUid + } + return "" +} + // QueryRewardsByAddressResponse is response body of the query all rewards by // address endpoint. type QueryRewardsByAddressResponse struct { @@ -601,9 +609,10 @@ func (m *QueryRewardsByAddressResponse) GetPagination() *query.PageResponse { // QueryRewardsByAddressAndCategoryRequest is request body for the query all // rewards by address and category endpoint. type QueryRewardsByAddressAndCategoryRequest struct { - Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` - Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` - Category RewardCategory `protobuf:"varint,3,opt,name=category,proto3,enum=sgenetwork.sge.reward.RewardCategory" json:"category,omitempty"` + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` + Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` + Category RewardCategory `protobuf:"varint,3,opt,name=category,proto3,enum=sgenetwork.sge.reward.RewardCategory" json:"category,omitempty"` + PromoterUid string `protobuf:"bytes,4,opt,name=promoter_uid,json=promoterUid,proto3" json:"promoter_uid,omitempty"` } func (m *QueryRewardsByAddressAndCategoryRequest) Reset() { @@ -662,6 +671,13 @@ func (m *QueryRewardsByAddressAndCategoryRequest) GetCategory() RewardCategory { return RewardCategory_REWARD_CATEGORY_UNSPECIFIED } +func (m *QueryRewardsByAddressAndCategoryRequest) GetPromoterUid() string { + if m != nil { + return m.PromoterUid + } + return "" +} + // QueryRewardsByAddressAndCategoryResponse is response body of the query all // rewards by address and category endpoint. type QueryRewardsByAddressAndCategoryResponse struct { @@ -848,60 +864,62 @@ func init() { func init() { proto.RegisterFile("sge/reward/query.proto", fileDescriptor_324afa5f2186a8c0) } var fileDescriptor_324afa5f2186a8c0 = []byte{ - // 848 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x97, 0x4b, 0x4f, 0x13, 0x51, - 0x14, 0xc7, 0x7b, 0x41, 0x0b, 0x5c, 0x8c, 0xc1, 0x23, 0x20, 0x56, 0x18, 0x60, 0xd4, 0x3e, 0x78, - 0xcc, 0x84, 0x87, 0x1a, 0xe3, 0x83, 0x00, 0x89, 0x6c, 0xb1, 0x89, 0x1b, 0x12, 0x43, 0xa6, 0xf4, - 0x66, 0x9c, 0x68,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 0x3b, 0x32, 0x15, 0xcc, 0x58, 0xf2, 0x18, 0x9c, 0x27, 0x0e, 0xd1, - 0x46, 0x3c, 0xaa, 0xbb, 0xe6, 0x76, 0xde, 0x49, 0x17, 0x61, 0x07, 0xe1, 0x9e, 0xf2, 0x4a, 0x85, - 0x40, 0xb9, 0xca, 0x3a, 0x4d, 0x07, 0xb4, 0x96, 0x68, 0x09, 0x8e, 0x76, 0x11, 0xc6, 0x5b, 0xa1, - 0x31, 0x78, 0x85, 0x70, 0x58, 0x1c, 0x97, 0xe6, 0x7d, 0xab, 0x5a, 0xb3, 0xcd, 0xfb, 0x56, 0xbd, - 0x69, 0xf5, 0x29, 0x0e, 0x13, 0x85, 0x4b, 0x8d, 0x60, 0xe4, 0x45, 0xa8, 0xf4, 0x12, 0xe1, 0x2e, - 0xf9, 0x05, 0x40, 0x80, 0x2c, 0x65, 0x85, 0x26, 0x03, 0xd9, 0x4a, 0xa4, 0x18, 0x47, 0x1a, 0x87, - 0xd1, 0xe6, 0x48, 0x0c, 0xde, 0x23, 0xdc, 0xe7, 0x9f, 0x6d, 0x30, 0x17, 0x20, 0x95, 0x7f, 0x23, - 0x46, 0xe6, 0x8f, 0xe6, 0x24, 0x41, 0x67, 0x38, 0xe8, 0x24, 0x24, 0x5a, 0x80, 0x9a, 0xdb, 0x72, - 0xaa, 0x17, 0xe1, 0x07, 0xc2, 0x17, 0x9a, 0x8c, 0x63, 0xb8, 0x7d, 0x14, 0x90, 0xda, 0xc5, 0x14, - 0x59, 0x38, 0xb6, 0xbf, 0xac, 0xe9, 0x26, 0xaf, 0xe9, 0x2a, 0xcc, 0x07, 0xae, 0xc9, 0xdc, 0x56, - 0x1b, 0xa7, 0x08, 0x5f, 0x10, 0x3e, 0x53, 0x33, 0x21, 0x21, 0x98, 0xba, 0xfe, 0xef, 0xfd, 0xca, - 0x11, 0xbd, 0x64, 0x01, 0x0b, 0xbc, 0x80, 0xeb, 0x70, 0xad, 0x55, 0x01, 0x87, 0x03, 0xa0, 0x72, - 0xf8, 0x17, 0x97, 0x96, 0x77, 0xf7, 0x35, 0xb4, 0xb7, 0xaf, 0xa1, 0x5f, 0xfb, 0x1a, 0x7a, 0x7d, - 0xa0, 0x85, 0xf6, 0x0e, 0xb4, 0xd0, 0xf7, 0x03, 0x2d, 0xb4, 0x96, 0xb0, 0x1d, 0xef, 0x41, 0x3e, - 0x65, 0x6c, 0xd0, 0x4c, 0x4d, 0xf0, 0x27, 0x2a, 0xbc, 0x57, 0xc8, 0x11, 0x96, 0x0a, 0xf3, 0x9f, - 0x3f, 0x73, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x25, 0x82, 0xdd, 0x83, 0xdc, 0x0d, 0x00, 0x00, + // 878 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x97, 0x4b, 0x4f, 0x13, 0x5d, + 0x18, 0xc7, 0x7b, 0x80, 0xb7, 0xc0, 0x81, 0xbc, 0xe1, 0x3d, 0x2f, 0x20, 0x56, 0x18, 0xe8, 0xa8, + 0x6d, 0xb9, 0xcd, 0x04, 0xd0, 0x78, 0x8b, 0x22, 0x34, 0xca, 0xc2, 0x0d, 0x36, 0x71, 0x43, 0x62, + 0xc8, 0x94, 0x9e, 0x8c, 0x13, 0x6d, 0xcf, 0x30, 0x67, 0x2a, 0x36, 0x4d, 0x37, 0x6e, 0x4c, 0x34, + 0x26, 0x26, 0xc4, 0xad, 0x1b, 0xfd, 0x02, 0xba, 0x36, 0x31, 0xee, 0x58, 0x62, 0xdc, 0xb8, 0x32, + 0x06, 0xdc, 0xb9, 0xf2, 0x1b, 0x98, 0x9e, 0x4b, 0x69, 0x67, 0x7a, 0x19, 0x9a, 0x6a, 0x5c, 0xb5, + 0xce, 0x3c, 0x97, 0xdf, 0xf3, 0xff, 0x9f, 0x9e, 0x47, 0xe0, 0x28, 0x35, 0xb1, 0xee, 0xe0, 0x1d, + 0xc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d3, 0x72, 0xef, 0xe5, 0xd3, 0xda, + 0x16, 0xc9, 0xfa, 0x8a, 0x3f, 0x92, 0xe5, 0xdd, 0x82, 0x8d, 0x69, 0x3a, 0xcc, 0xfe, 0xc4, 0x5a, + 0xfa, 0x15, 0x00, 0x00, 0xff, 0xff, 0x0a, 0x7f, 0x1b, 0x06, 0x40, 0x0e, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1624,6 +1642,13 @@ func (m *QueryRewardsByAddressRequest) MarshalToSizedBuffer(dAtA []byte) (int, e _ = i var l int _ = l + if len(m.PromoterUid) > 0 { + i -= len(m.PromoterUid) + copy(dAtA[i:], m.PromoterUid) + i = encodeVarintQuery(dAtA, i, uint64(len(m.PromoterUid))) + i-- + dAtA[i] = 0x1a + } if len(m.Address) > 0 { i -= len(m.Address) copy(dAtA[i:], m.Address) @@ -1715,6 +1740,13 @@ func (m *QueryRewardsByAddressAndCategoryRequest) MarshalToSizedBuffer(dAtA []by _ = i var l int _ = l + if len(m.PromoterUid) > 0 { + i -= len(m.PromoterUid) + copy(dAtA[i:], m.PromoterUid) + i = encodeVarintQuery(dAtA, i, uint64(len(m.PromoterUid))) + i-- + dAtA[i] = 0x22 + } if m.Category != 0 { i = encodeVarintQuery(dAtA, i, uint64(m.Category)) i-- @@ -2039,6 +2071,10 @@ func (m *QueryRewardsByAddressRequest) Size() (n int) { if l > 0 { n += 1 + l + sovQuery(uint64(l)) } + l = len(m.PromoterUid) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -2078,6 +2114,10 @@ func (m *QueryRewardsByAddressAndCategoryRequest) Size() (n int) { if m.Category != 0 { n += 1 + sovQuery(uint64(m.Category)) } + l = len(m.PromoterUid) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -3114,6 +3154,38 @@ func (m *QueryRewardsByAddressRequest) Unmarshal(dAtA []byte) error { } m.Address = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PromoterUid", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PromoterUid = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) @@ -3371,6 +3443,38 @@ func (m *QueryRewardsByAddressAndCategoryRequest) Unmarshal(dAtA []byte) error { break } } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PromoterUid", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PromoterUid = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) diff --git a/x/reward/types/query.pb.gw.go b/x/reward/types/query.pb.gw.go index 6a9886e6..70134ca9 100644 --- a/x/reward/types/query.pb.gw.go +++ b/x/reward/types/query.pb.gw.go @@ -232,7 +232,7 @@ func local_request_Query_Rewards_0(ctx context.Context, marshaler runtime.Marsha } var ( - filter_Query_RewardsByAddress_0 = &utilities.DoubleArray{Encoding: map[string]int{"address": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} + filter_Query_RewardsByAddress_0 = &utilities.DoubleArray{Encoding: map[string]int{"promoter_uid": 0, "address": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}} ) func request_Query_RewardsByAddress_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { @@ -246,6 +246,17 @@ func request_Query_RewardsByAddress_0(ctx context.Context, marshaler runtime.Mar _ = err ) + val, ok = pathParams["promoter_uid"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "promoter_uid") + } + + protoReq.PromoterUid, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "promoter_uid", err) + } + val, ok = pathParams["address"] if !ok { return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") @@ -280,6 +291,17 @@ func local_request_Query_RewardsByAddress_0(ctx context.Context, marshaler runti _ = err ) + val, ok = pathParams["promoter_uid"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "promoter_uid") + } + + protoReq.PromoterUid, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "promoter_uid", err) + } + val, ok = pathParams["address"] if !ok { return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") @@ -304,7 +326,7 @@ func local_request_Query_RewardsByAddress_0(ctx context.Context, marshaler runti } var ( - filter_Query_RewardsByAddressAndCategory_0 = &utilities.DoubleArray{Encoding: map[string]int{"address": 0, "category": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}} + filter_Query_RewardsByAddressAndCategory_0 = &utilities.DoubleArray{Encoding: map[string]int{"promoter_uid": 0, "address": 1, "category": 2}, Base: []int{1, 1, 2, 3, 0, 0, 0}, Check: []int{0, 1, 1, 1, 2, 3, 4}} ) func request_Query_RewardsByAddressAndCategory_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { @@ -319,6 +341,17 @@ func request_Query_RewardsByAddressAndCategory_0(ctx context.Context, marshaler _ = err ) + val, ok = pathParams["promoter_uid"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "promoter_uid") + } + + protoReq.PromoterUid, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "promoter_uid", err) + } + val, ok = pathParams["address"] if !ok { return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") @@ -367,6 +400,17 @@ func local_request_Query_RewardsByAddressAndCategory_0(ctx context.Context, mars _ = err ) + val, ok = pathParams["promoter_uid"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "promoter_uid") + } + + protoReq.PromoterUid, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "promoter_uid", err) + } + val, ok = pathParams["address"] if !ok { return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "address") @@ -880,9 +924,9 @@ var ( pattern_Query_Rewards_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"sge-network", "sge", "reward", "rewards"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_RewardsByAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"sge-network", "sge", "reward", "rewards", "address"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_RewardsByAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"sge-network", "sge", "reward", "rewards", "promoter_uid", "address"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_RewardsByAddressAndCategory_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5}, []string{"sge-network", "sge", "reward", "rewards", "address", "category"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_RewardsByAddressAndCategory_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4, 1, 0, 4, 1, 5, 5, 1, 0, 4, 1, 5, 6}, []string{"sge-network", "sge", "reward", "rewards", "promoter_uid", "address", "category"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_RewardsByCampaign_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"sge-network", "sge", "reward", "rewards", "campaign", "campaign_uid"}, "", runtime.AssumeColonVerbOpt(false))) ) diff --git a/x/reward/types/reward_signup_affiliator.go b/x/reward/types/reward_signup_affiliator.go index 6dd0e5f9..00c73de0 100644 --- a/x/reward/types/reward_signup_affiliator.go +++ b/x/reward/types/reward_signup_affiliator.go @@ -51,7 +51,12 @@ func (sur SignUpAffiliatorReward) Calculate(goCtx context.Context, ctx sdk.Conte return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "%s", err) } - if !keepers.RewardKeeper.HasRewardByReceiver(ctx, payload.Affiliatee, RewardCategory_REWARD_CATEGORY_SIGNUP) { + promoter, isFound := keepers.GetPromoterByAddress(ctx, campaign.Promoter) + if !isFound { + return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "promoter with the address: %s not found", &campaign.Promoter) + } + + if !keepers.RewardKeeper.HasRewardOfReceiverByPromoter(ctx, promoter.PromoterUID, payload.Affiliatee, RewardCategory_REWARD_CATEGORY_SIGNUP) { return RewardFactoryData{}, sdkerrors.Wrap(sdkerrtypes.ErrInvalidRequest, "affiliatee account has signed up yet, there is no affiliatee claim record") } diff --git a/x/reward/types/reward_signup_referrer.go b/x/reward/types/reward_signup_referrer.go index 5f95a2f4..45c6c553 100644 --- a/x/reward/types/reward_signup_referrer.go +++ b/x/reward/types/reward_signup_referrer.go @@ -48,7 +48,12 @@ func (sur SignUpReferrerReward) Calculate(goCtx context.Context, ctx sdk.Context return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "%s", err) } - if !keepers.RewardKeeper.HasRewardByReceiver(ctx, payload.Referee, RewardCategory_REWARD_CATEGORY_SIGNUP) { + promoter, isFound := keepers.GetPromoterByAddress(ctx, campaign.Promoter) + if !isFound { + return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "promoter with the address: %s not found", &campaign.Promoter) + } + + if !keepers.RewardKeeper.HasRewardOfReceiverByPromoter(ctx, promoter.PromoterUID, payload.Referee, RewardCategory_REWARD_CATEGORY_SIGNUP) { return RewardFactoryData{}, sdkerrors.Wrap(sdkerrtypes.ErrInvalidRequest, "referee account has signed up yet, there is no referee claim record") } diff --git a/x/reward/types/ticket.go b/x/reward/types/ticket.go index 744035d4..d7a78848 100644 --- a/x/reward/types/ticket.go +++ b/x/reward/types/ticket.go @@ -40,10 +40,6 @@ func (payload *CreateCampaignPayload) Validate(blockTime uint64) error { return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "sub account should have unlock period") } - if payload.ClaimsPerCategory == 0 { - return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "claim per category should be a positive number") - } - return nil } diff --git a/x/reward/types/ticket.pb.go b/x/reward/types/ticket.pb.go index 1fafafe4..3f9790d0 100644 --- a/x/reward/types/ticket.pb.go +++ b/x/reward/types/ticket.pb.go @@ -43,9 +43,6 @@ type CreateCampaignPayload struct { RewardAmount *RewardAmount `protobuf:"bytes,7,opt,name=reward_amount,json=rewardAmount,proto3" json:"reward_amount,omitempty"` // is_active is the flag to check if the campaign is active or not. IsActive bool `protobuf:"varint,8,opt,name=is_active,json=isActive,proto3" json:"is_active,omitempty"` - // claims_per_category is the number of times a user can claim a reward for - // category of this campaign. - ClaimsPerCategory uint64 `protobuf:"varint,9,opt,name=claims_per_category,json=claimsPerCategory,proto3" json:"claims_per_category,omitempty"` // meta is the metadata of the campaign. // It is a stringified base64 encoded json. Meta string `protobuf:"bytes,10,opt,name=meta,proto3" json:"meta,omitempty"` @@ -140,13 +137,6 @@ func (m *CreateCampaignPayload) GetIsActive() bool { return false } -func (m *CreateCampaignPayload) GetClaimsPerCategory() uint64 { - if m != nil { - return m.ClaimsPerCategory - } - return 0 -} - func (m *CreateCampaignPayload) GetMeta() string { if m != nil { return m.Meta @@ -506,47 +496,46 @@ func init() { func init() { proto.RegisterFile("sge/reward/ticket.proto", fileDescriptor_5d710bc1249ca8ae) } var fileDescriptor_5d710bc1249ca8ae = []byte{ - // 633 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0x4f, 0x6b, 0xd4, 0x40, - 0x14, 0xdf, 0x69, 0xb7, 0xbb, 0xd9, 0x57, 0x15, 0x9d, 0x76, 0x31, 0xb6, 0x90, 0xae, 0x11, 0x71, - 0x15, 0xcc, 0xc2, 0x7a, 0x14, 0x84, 0xdd, 0x2d, 0x5a, 0xe9, 0xa5, 0xa4, 0x2d, 0x82, 0x97, 0x30, - 0x4d, 0xa6, 0xe9, 0xb0, 0x4d, 0x26, 0xcc, 0xcc, 0xb6, 0xe6, 0x0b, 0x78, 0x14, 0x3f, 0x93, 0xa7, - 0x1e, 0x7b, 0xf4, 0x54, 0x64, 0x7b, 0xf3, 0xe0, 0x67, 0x90, 0x4c, 0xd2, 0x34, 0x2b, 0x75, 0x29, - 0x88, 0xa7, 0xbc, 0x37, 0xef, 0xf7, 0x7e, 0xef, 0xf7, 0xfe, 0x10, 0x78, 0x28, 0x43, 0xda, 0x13, - 0xf4, 0x94, 0x88, 0xa0, 0xa7, 0x98, 0x3f, 0xa6, 0xca, 0x49, 0x04, 0x57, 0x1c, 0xb7, 0x65, 0x48, - 0x63, 0xaa, 0x4e, 0xb9, 0x18, 0x3b, 0x32, 0xa4, 0x4e, 0x8e, 0x59, 0x5b, 0x0d, 0x79, 0xc8, 0x35, - 0xa2, 0x97, 0x59, 0x39, 0x78, 0x0d, 0x67, 0x2c, 0x2a, 0x4d, 0x68, 0x6f, 0x9c, 0xfa, 0xc5, 0x5b, - 0x95, 0x39, 0xff, 0xe4, 0x01, 0xfb, 0xd7, 0x22, 0xb4, 0x47, 0x82, 0x12, 0x45, 0x47, 0x24, 0x4a, - 0x08, 0x0b, 0xe3, 0x1d, 0x92, 0x1e, 0x73, 0x12, 0xe0, 0x35, 0x30, 0x12, 0xc1, 0x23, 0xae, 0xa8, - 0x30, 0x51, 0x07, 0x75, 0x5b, 0x6e, 0xe9, 0xe3, 0x47, 0x60, 0x48, 0x45, 0x84, 0xf2, 0x94, 0x34, - 0x17, 0x3a, 0xa8, 0x5b, 0x77, 0x9b, 0xda, 0xdf, 0x93, 0xb8, 0x0d, 0x0d, 0x1a, 0x07, 0x59, 0x60, - 0x51, 0x07, 0x96, 0x68, 0x1c, 0xec, 0x49, 0x3c, 0x00, 0xc3, 0x27, 0x8a, 0x86, 0x5c, 0xa4, 0x66, - 0xbd, 0x83, 0xba, 0xf7, 0xfa, 0x4f, 0x9d, 0x1b, 0x9b, 0x72, 0x5c, 0xfd, 0x19, 0x15, 0x60, 0xb7, - 0x4c, 0xc3, 0x43, 0x58, 0xce, 0x21, 0x5e, 0xd6, 0x9c, 0xb9, 0xa4, 0x59, 0x1e, 0xcf, 0x65, 0xd9, - 0x4b, 0x13, 0xea, 0x82, 0x28, 0x6d, 0xbc, 0x0f, 0xb8, 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xc2, 0xe2, - 0xf5, 0x14, 0xf0, 0x1b, 0x30, 0xc6, 0xa9, 0xef, 0x05, 0x44, 0x11, 0x7d, 0x8e, 0x37, 0xec, 0x2a, - 0xbb, 0x0c, 0x67, 0x3b, 0xf5, 0x37, 0x89, 0x22, 0x85, 0x52, 0xb7, 0x39, 0xce, 0x7d, 0x3b, 0x00, - 0xf3, 0x9d, 0x20, 0xb1, 0xda, 0x65, 0x61, 0x3c, 0x49, 0x66, 0xda, 0xc1, 0x5b, 0xd0, 0xf0, 0x75, - 0x4b, 0x5a, 0xe8, 0x72, 0xff, 0xc5, 0xdc, 0x2b, 0x98, 0x19, 0xc2, 0xb0, 0x7e, 0x76, 0xb1, 0x51, - 0x73, 0x8b, 0x7c, 0xfb, 0x33, 0x82, 0xce, 0x4c, 0x99, 0x43, 0x2a, 0x04, 0x15, 0x7f, 0x2b, 0x87, - 0xfe, 0xad, 0x1c, 0x36, 0xa1, 0x29, 0xb2, 0x12, 0x34, 0x5f, 0x74, 0xcb, 0xbd, 0x72, 0xed, 0x2f, - 0x08, 0xec, 0x8a, 0x90, 0xc1, 0xe1, 0x21, 0x3b, 0x66, 0x44, 0xf1, 0xff, 0x26, 0xc5, 0x02, 0x20, - 0x45, 0x91, 0x52, 0x4d, 0xe5, 0x65, 0x38, 0x3a, 0x9b, 0x5a, 0xe8, 0x7c, 0x6a, 0xa1, 0x1f, 0x53, - 0x0b, 0x7d, 0xbd, 0xb4, 0x6a, 0xe7, 0x97, 0x56, 0xed, 0xfb, 0xa5, 0x55, 0xfb, 0xf8, 0x3c, 0x64, - 0xea, 0x68, 0x72, 0xe0, 0xf8, 0x3c, 0xea, 0xc9, 0x90, 0xbe, 0x2c, 0xca, 0x67, 0x76, 0xef, 0x53, - 0xf9, 0x73, 0x4d, 0x13, 0x2a, 0x0f, 0x1a, 0xfa, 0x17, 0xf8, 0xea, 0x77, 0x00, 0x00, 0x00, 0xff, - 0xff, 0x28, 0xb9, 0x2a, 0x10, 0x77, 0x05, 0x00, 0x00, + // 610 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0xcf, 0x6e, 0xd3, 0x4e, + 0x10, 0xce, 0xb6, 0x69, 0xe2, 0x4c, 0x7f, 0x3f, 0x84, 0x96, 0x46, 0x98, 0x56, 0x72, 0x83, 0x11, + 0x22, 0x20, 0xe1, 0x48, 0xe1, 0x88, 0x84, 0x94, 0xa4, 0x82, 0xa2, 0x5e, 0x90, 0xdb, 0x0a, 0x89, + 0x4b, 0xb4, 0xb5, 0xa7, 0xae, 0x95, 0xda, 0x6b, 0xed, 0x6e, 0x5a, 0xfc, 0x02, 0x1c, 0x11, 0x4f, + 0xc4, 0x81, 0x53, 0x8f, 0x3d, 0x72, 0xaa, 0x50, 0x7a, 0xe3, 0x29, 0x90, 0xd7, 0x6e, 0x6a, 0xa3, + 0x12, 0x55, 0x42, 0x9c, 0x76, 0x66, 0xf6, 0x9b, 0xef, 0x9b, 0x3f, 0xab, 0x85, 0xfb, 0x32, 0xc0, + 0x9e, 0xc0, 0x53, 0x26, 0xfc, 0x9e, 0x0a, 0xbd, 0x09, 0x2a, 0x27, 0x11, 0x5c, 0x71, 0xda, 0x96, + 0x01, 0xc6, 0xa8, 0x4e, 0xb9, 0x98, 0x38, 0x32, 0x40, 0x27, 0xc7, 0xac, 0xaf, 0x05, 0x3c, 0xe0, + 0x1a, 0xd1, 0xcb, 0xac, 0x1c, 0xbc, 0x4e, 0x33, 0x16, 0x95, 0x26, 0xd8, 0x9b, 0xa4, 0x5e, 0x11, + 0x2b, 0x33, 0xe7, 0x47, 0x7e, 0x61, 0x7f, 0x5d, 0x86, 0xf6, 0x48, 0x20, 0x53, 0x38, 0x62, 0x51, + 0xc2, 0xc2, 0x20, 0x7e, 0xc7, 0xd2, 0x63, 0xce, 0x7c, 0xba, 0x0e, 0x46, 0x22, 0x78, 0xc4, 0x15, + 0x0a, 0x93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 0x22, 0xc3, + 0xd1, 0xd9, 0xcc, 0x22, 0xe7, 0x33, 0x8b, 0xfc, 0x98, 0x59, 0xe4, 0xcb, 0xa5, 0x55, 0x3b, 0xbf, + 0xb4, 0x6a, 0xdf, 0x2f, 0xad, 0xda, 0x87, 0xa7, 0x41, 0xa8, 0x8e, 0xa6, 0x07, 0x8e, 0xc7, 0xa3, + 0x9e, 0x0c, 0xf0, 0x79, 0x21, 0x9f, 0xd9, 0xbd, 0x8f, 0xf3, 0xcf, 0x32, 0x4d, 0x50, 0x1e, 0x34, + 0xf4, 0x97, 0xf6, 0xe2, 0x57, 0x00, 0x00, 0x00, 0xff, 0xff, 0xb3, 0xbb, 0x16, 0x92, 0x47, 0x05, + 0x00, 0x00, } func (m *CreateCampaignPayload) Marshal() (dAtA []byte, err error) { @@ -576,11 +565,6 @@ func (m *CreateCampaignPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x52 } - if m.ClaimsPerCategory != 0 { - i = encodeVarintTicket(dAtA, i, uint64(m.ClaimsPerCategory)) - i-- - dAtA[i] = 0x48 - } if m.IsActive { i-- if m.IsActive { @@ -918,9 +902,6 @@ func (m *CreateCampaignPayload) Size() (n int) { if m.IsActive { n += 2 } - if m.ClaimsPerCategory != 0 { - n += 1 + sovTicket(uint64(m.ClaimsPerCategory)) - } l = len(m.Meta) if l > 0 { n += 1 + l + sovTicket(uint64(l)) @@ -1240,25 +1221,6 @@ func (m *CreateCampaignPayload) Unmarshal(dAtA []byte) error { } } m.IsActive = bool(v != 0) - case 9: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ClaimsPerCategory", wireType) - } - m.ClaimsPerCategory = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTicket - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ClaimsPerCategory |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } case 10: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Meta", wireType) diff --git a/x/reward/types/ticket_test.go b/x/reward/types/ticket_test.go index 061a4ab3..069a9ff0 100644 --- a/x/reward/types/ticket_test.go +++ b/x/reward/types/ticket_test.go @@ -61,9 +61,8 @@ func TestCreateCampaignPayloadValidation(t *testing.T) { SubaccountAmount: sdkmath.NewInt(1000), UnlockPeriod: uint64(time.Now().Add(10 * time.Minute).Unix()), }, - ClaimsPerCategory: 1, - IsActive: true, - Meta: "sample campaign", + IsActive: true, + Meta: "sample campaign", }, }, } From a83f79613b7d3dacc8c0bdd85e869d8b9d1879b6 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Tue, 27 Feb 2024 13:26:53 +0300 Subject: [PATCH 02/28] lint: wrong formater pointer type --- x/reward/types/reward_signup_affiliator.go | 2 +- x/reward/types/reward_signup_referrer.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x/reward/types/reward_signup_affiliator.go b/x/reward/types/reward_signup_affiliator.go index 00c73de0..7f969f0b 100644 --- a/x/reward/types/reward_signup_affiliator.go +++ b/x/reward/types/reward_signup_affiliator.go @@ -53,7 +53,7 @@ func (sur SignUpAffiliatorReward) Calculate(goCtx context.Context, ctx sdk.Conte promoter, isFound := keepers.GetPromoterByAddress(ctx, campaign.Promoter) if !isFound { - return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "promoter with the address: %s not found", &campaign.Promoter) + return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "promoter with the address: %s not found", campaign.Promoter) } if !keepers.RewardKeeper.HasRewardOfReceiverByPromoter(ctx, promoter.PromoterUID, payload.Affiliatee, RewardCategory_REWARD_CATEGORY_SIGNUP) { diff --git a/x/reward/types/reward_signup_referrer.go b/x/reward/types/reward_signup_referrer.go index 45c6c553..7a8c344a 100644 --- a/x/reward/types/reward_signup_referrer.go +++ b/x/reward/types/reward_signup_referrer.go @@ -50,7 +50,7 @@ func (sur SignUpReferrerReward) Calculate(goCtx context.Context, ctx sdk.Context promoter, isFound := keepers.GetPromoterByAddress(ctx, campaign.Promoter) if !isFound { - return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "promoter with the address: %s not found", &campaign.Promoter) + return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "promoter with the address: %s not found", campaign.Promoter) } if !keepers.RewardKeeper.HasRewardOfReceiverByPromoter(ctx, promoter.PromoterUID, payload.Referee, RewardCategory_REWARD_CATEGORY_SIGNUP) { From a68c1096e962341a1b09a542f2021786ea1270a5 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Tue, 27 Feb 2024 13:43:50 +0300 Subject: [PATCH 03/28] test: fix reward genesis --- x/reward/genesis_test.go | 52 +++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/x/reward/genesis_test.go b/x/reward/genesis_test.go index 497fbc5b..590bf851 100644 --- a/x/reward/genesis_test.go +++ b/x/reward/genesis_test.go @@ -13,39 +13,75 @@ import ( ) func TestGenesis(t *testing.T) { + promoterAddr := "promoter" + promoterUID := uuid.NewString() + + campaignUID1 := uuid.NewString() + campaignUID2 := uuid.NewString() + + rewardID1 := uuid.NewString() + rewardID2 := uuid.NewString() + genesisState := types.GenesisState{ Params: types.DefaultParams(), + PromoterList: []types.Promoter{ + { + Creator: promoterAddr, + UID: promoterUID, + Addresses: []string{promoterAddr}, + Conf: types.PromoterConf{ + CategoryCap: []types.CategoryCap{ + { + Category: types.RewardCategory_REWARD_CATEGORY_SIGNUP, + CapPerAcc: 1, + }, + }, + }, + }, + }, + PromoterByAddressList: []types.PromoterByAddress{ + { + PromoterUID: promoterUID, + Address: promoterAddr, + }, + }, CampaignList: []types.Campaign{ { - UID: uuid.NewString(), + UID: campaignUID1, + Promoter: promoterAddr, }, { - UID: uuid.NewString(), + UID: campaignUID2, + Promoter: promoterAddr, }, }, RewardList: []types.Reward{ { - UID: uuid.NewString(), + UID: rewardID1, + CampaignUID: campaignUID1, }, { - UID: uuid.NewString(), + UID: rewardID2, + CampaignUID: campaignUID2, }, }, RewardByCategoryList: []types.RewardByCategory{ { - UID: uuid.NewString(), + UID: rewardID1, }, { - UID: uuid.NewString(), + UID: rewardID2, }, }, RewardByCampaignList: []types.RewardByCampaign{ { - UID: uuid.NewString(), + UID: rewardID1, + CampaignUID: campaignUID1, }, { - UID: uuid.NewString(), + UID: rewardID1, + CampaignUID: campaignUID2, }, }, } From b22c0512160899b6f4ba513eef045373ebf9bae9 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Mon, 4 Mar 2024 13:37:42 +0300 Subject: [PATCH 04/28] feat: promoter config set tx --- proto/sge/reward/ticket.proto | 6 + proto/sge/reward/tx.proto | 15 + x/reward/client/cli/tx.go | 1 + x/reward/client/cli/tx_promoter.go | 46 +++ x/reward/keeper/msg_server_promoter.go | 48 +++ x/reward/types/errors.go | 2 + x/reward/types/events.go | 1 + x/reward/types/messages_promoter.go | 75 ++++ x/reward/types/ticket.go | 18 + x/reward/types/ticket.pb.go | 253 ++++++++++-- x/reward/types/tx.pb.go | 514 +++++++++++++++++++++++-- 11 files changed, 901 insertions(+), 78 deletions(-) create mode 100644 x/reward/client/cli/tx_promoter.go create mode 100644 x/reward/keeper/msg_server_promoter.go create mode 100644 x/reward/types/messages_promoter.go diff --git a/proto/sge/reward/ticket.proto b/proto/sge/reward/ticket.proto index 74579894..859a1945 100644 --- a/proto/sge/reward/ticket.proto +++ b/proto/sge/reward/ticket.proto @@ -4,6 +4,7 @@ package sgenetwork.sge.reward; import "gogoproto/gogo.proto"; import "sge/type/kyc.proto"; import "sge/reward/reward.proto"; +import "sge/reward/promoter.proto"; option go_package = "github.com/sge-network/sge/x/reward/types"; @@ -105,4 +106,9 @@ message GrantSignupAffiliatorRewardPayload { // affiliatee is the address of the account that used this affiliator's // address as source_uid string affiliatee = 2; +} + +// SetPromoterConfPayload is the payload for the promoter configuration change. +message SetPromoterConfPayload { + PromoterConf conf = 1 [ (gogoproto.nullable) = false ]; } \ No newline at end of file diff --git a/proto/sge/reward/tx.proto b/proto/sge/reward/tx.proto index 5570ce8d..a7760dab 100644 --- a/proto/sge/reward/tx.proto +++ b/proto/sge/reward/tx.proto @@ -8,6 +8,8 @@ option go_package = "github.com/sge-network/sge/x/reward/types"; // Msg defines the Msg service. service Msg { + // SetPromoterConf is a method to set the configurations of a promoter. + rpc SetPromoterConf(MsgSetPromoterConf) returns (MsgSetPromoterConfResponse); // CreateCampaign is a method to create a campaign rpc CreateCampaign(MsgCreateCampaign) returns (MsgCreateCampaignResponse); // UpdateCampaign is a method to update campaign @@ -18,6 +20,19 @@ service Msg { rpc GrantReward(MsgGrantReward) returns (MsgGrantRewardResponse); } +// MsgSetPromoterConf is msg to set promoter configuration. +message MsgSetPromoterConf { + // creator is the address of message signer account. + string creator = 1; + // uid is the unique identifier of the promoter. + string uid = 2; + // ticket is the payload data. + string ticket = 3; +} + +// MsgCreateCampaignResponse campaign create message response type. +message MsgSetPromoterConfResponse {} + // MsgCreateCampaign is msg to create a reward campaign message MsgCreateCampaign { // creator is the address of campaign creator account. diff --git a/x/reward/client/cli/tx.go b/x/reward/client/cli/tx.go index bf7131ab..f4aec33a 100644 --- a/x/reward/client/cli/tx.go +++ b/x/reward/client/cli/tx.go @@ -24,6 +24,7 @@ func GetTxCmd() *cobra.Command { RunE: client.ValidateCmd, } + cmd.AddCommand(CmdSetPromoterConf()) cmd.AddCommand(CmdCreateCampaign()) cmd.AddCommand(CmdUpdateCampaign()) cmd.AddCommand(CmdWithdrawFunds()) diff --git a/x/reward/client/cli/tx_promoter.go b/x/reward/client/cli/tx_promoter.go new file mode 100644 index 00000000..be0286fe --- /dev/null +++ b/x/reward/client/cli/tx_promoter.go @@ -0,0 +1,46 @@ +package cli + +import ( + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + + "github.com/sge-network/sge/x/reward/types" +) + +func CmdSetPromoterConf() *cobra.Command { + cmd := &cobra.Command{ + Use: "set-promoter-conf [uid] [ticket]", + Short: "Set promoter config", + Long: "Set promoter config of a promoter by uid and the ticket", + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) (err error) { + // Get indexes + argUID := args[0] + + // Get value arguments + argTicket := args[1] + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + msg := types.NewMsgSetPromoterConfig( + clientCtx.GetFromAddress().String(), + argUID, + argTicket, + ) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/reward/keeper/msg_server_promoter.go b/x/reward/keeper/msg_server_promoter.go new file mode 100644 index 00000000..999b9094 --- /dev/null +++ b/x/reward/keeper/msg_server_promoter.go @@ -0,0 +1,48 @@ +package keeper + +import ( + "context" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/x/reward/types" +) + +func (k msgServer) SetPromoterConf(goCtx context.Context, msg *types.MsgSetPromoterConf) (*types.MsgSetPromoterConfResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Check if the value already exists + promoter, isFound := k.GetPromoter(ctx, msg.Uid) + if !isFound { + return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "promoter does not exist", msg.Uid) + } + + creatorIsPromoter := false + for _, p := range promoter.Addresses { + if p == msg.Creator { + creatorIsPromoter = true + } + } + + if !creatorIsPromoter { + return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "creator should be one of stored addresses in promoter") + } + + var payload types.SetPromoterConfPayload + if err := k.ovmKeeper.VerifyTicketUnmarshal(goCtx, msg.Ticket, &payload); err != nil { + return nil, sdkerrors.Wrapf(types.ErrInTicketVerification, "%s", err) + } + + if err := payload.Validate(); err != nil { + return nil, err + } + + promoter.Conf = payload.Conf + + k.SetPromoter(ctx, promoter) + + msg.EmitEvent(&ctx, promoter.Conf) + + return &types.MsgSetPromoterConfResponse{}, nil +} diff --git a/x/reward/types/errors.go b/x/reward/types/errors.go index ca2fdbde..093a078d 100644 --- a/x/reward/types/errors.go +++ b/x/reward/types/errors.go @@ -37,4 +37,6 @@ var ( ErrCampaignHasNotStarted = sdkerrors.Register(ModuleName, 7127, "campaign validity period is not started yet") ErrUserKycFailed = sdkerrors.Register(ModuleName, 7128, "KYC Validation failed for receiver account address") 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") ) diff --git a/x/reward/types/events.go b/x/reward/types/events.go index 27953918..b5ef8904 100644 --- a/x/reward/types/events.go +++ b/x/reward/types/events.go @@ -10,4 +10,5 @@ const ( attributeKeyMainAmount = "main_acc_amount" attributeKeySubAmount = "sub_acc_amount" attributeKeyUnlockTS = "sub_acc_unlock_ts" + attributeKeyPromoterConf = "promoter_conf" ) diff --git a/x/reward/types/messages_promoter.go b/x/reward/types/messages_promoter.go new file mode 100644 index 00000000..3de553e5 --- /dev/null +++ b/x/reward/types/messages_promoter.go @@ -0,0 +1,75 @@ +package types + +import ( + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/sge-network/sge/utils" +) + +const ( + TypeMsgSetPromoterConf = "set_promoter_conf" +) + +var _ sdk.Msg = &MsgSetPromoterConf{} + +func NewMsgSetPromoterConfig( + creator string, + uid string, + ticket string, +) *MsgSetPromoterConf { + return &MsgSetPromoterConf{ + Creator: creator, + Uid: uid, + Ticket: ticket, + } +} + +func (msg *MsgSetPromoterConf) Route() string { + return RouterKey +} + +func (msg *MsgSetPromoterConf) Type() string { + return TypeMsgSetPromoterConf +} + +func (msg *MsgSetPromoterConf) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgSetPromoterConf) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgSetPromoterConf) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "invalid creator address (%s)", err) + } + + if !utils.IsValidUID(msg.Uid) { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "invalid uid") + } + + if msg.Ticket == "" { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "invalid ticket") + } + + return nil +} + +// EmitEvent emits the event for the message success. +func (msg *MsgSetPromoterConf) EmitEvent(ctx *sdk.Context, conf PromoterConf) { + emitter := utils.NewEventEmitter(ctx, attributeValueCategory) + emitter.AddMsg(TypeMsgSetPromoterConf, msg.Creator, + sdk.NewAttribute(attributeKeyUID, msg.Uid), + sdk.NewAttribute(attributeKeyPromoterConf, conf.String()), + ) + emitter.Emit() +} diff --git a/x/reward/types/ticket.go b/x/reward/types/ticket.go index d7a78848..b8f9d2dd 100644 --- a/x/reward/types/ticket.go +++ b/x/reward/types/ticket.go @@ -102,3 +102,21 @@ func (payload *RewardPayloadCommon) Validate() error { } return nil } + +// Validate validates promoter config set ticket payload. +func (payload *SetPromoterConfPayload) Validate() error { + catMap := make(map[RewardCategory]struct{}) + for _, v := range payload.Conf.CategoryCap { + _, ok := catMap[v.Category] + if ok { + return sdkerrors.Wrapf(ErrDuplicateCategoryInConf, "%s", v.Category) + } + if v.CapPerAcc <= 0 { + return sdkerrors.Wrapf(ErrCategoryCapShouldBePos, "%s", v.Category) + } + + catMap[v.Category] = struct{}{} + } + + return nil +} diff --git a/x/reward/types/ticket.pb.go b/x/reward/types/ticket.pb.go index 3f9790d0..d1465c1c 100644 --- a/x/reward/types/ticket.pb.go +++ b/x/reward/types/ticket.pb.go @@ -483,6 +483,51 @@ func (m *GrantSignupAffiliatorRewardPayload) GetAffiliatee() string { return "" } +// SetPromoterConfPayload is the payload for the promoter configuration change. +type SetPromoterConfPayload struct { + Conf PromoterConf `protobuf:"bytes,1,opt,name=conf,proto3" json:"conf"` +} + +func (m *SetPromoterConfPayload) Reset() { *m = SetPromoterConfPayload{} } +func (m *SetPromoterConfPayload) String() string { return proto.CompactTextString(m) } +func (*SetPromoterConfPayload) ProtoMessage() {} +func (*SetPromoterConfPayload) Descriptor() ([]byte, []int) { + return fileDescriptor_5d710bc1249ca8ae, []int{7} +} +func (m *SetPromoterConfPayload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SetPromoterConfPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SetPromoterConfPayload.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 *SetPromoterConfPayload) XXX_Merge(src proto.Message) { + xxx_messageInfo_SetPromoterConfPayload.Merge(m, src) +} +func (m *SetPromoterConfPayload) XXX_Size() int { + return m.Size() +} +func (m *SetPromoterConfPayload) XXX_DiscardUnknown() { + xxx_messageInfo_SetPromoterConfPayload.DiscardUnknown(m) +} + +var xxx_messageInfo_SetPromoterConfPayload proto.InternalMessageInfo + +func (m *SetPromoterConfPayload) GetConf() PromoterConf { + if m != nil { + return m.Conf + } + return PromoterConf{} +} + func init() { proto.RegisterType((*CreateCampaignPayload)(nil), "sgenetwork.sge.reward.CreateCampaignPayload") proto.RegisterType((*UpdateCampaignPayload)(nil), "sgenetwork.sge.reward.UpdateCampaignPayload") @@ -491,51 +536,54 @@ func init() { proto.RegisterType((*GrantSignupRewardPayload)(nil), "sgenetwork.sge.reward.GrantSignupRewardPayload") proto.RegisterType((*GrantSignupReferrerRewardPayload)(nil), "sgenetwork.sge.reward.GrantSignupReferrerRewardPayload") proto.RegisterType((*GrantSignupAffiliatorRewardPayload)(nil), "sgenetwork.sge.reward.GrantSignupAffiliatorRewardPayload") + proto.RegisterType((*SetPromoterConfPayload)(nil), "sgenetwork.sge.reward.SetPromoterConfPayload") } func init() { proto.RegisterFile("sge/reward/ticket.proto", fileDescriptor_5d710bc1249ca8ae) } var fileDescriptor_5d710bc1249ca8ae = []byte{ - // 610 bytes of a gzipped FileDescriptorProto + // 647 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0xcf, 0x6e, 0xd3, 0x4e, - 0x10, 0xce, 0xb6, 0x69, 0xe2, 0x4c, 0x7f, 0x3f, 0x84, 0x96, 0x46, 0x98, 0x56, 0x72, 0x83, 0x11, - 0x22, 0x20, 0xe1, 0x48, 0xe1, 0x88, 0x84, 0x94, 0xa4, 0x82, 0xa2, 0x5e, 0x90, 0xdb, 0x0a, 0x89, - 0x4b, 0xb4, 0xb5, 0xa7, 0xae, 0x95, 0xda, 0x6b, 0xed, 0x6e, 0x5a, 0xfc, 0x02, 0x1c, 0x11, 0x4f, - 0xc4, 0x81, 0x53, 0x8f, 0x3d, 0x72, 0xaa, 0x50, 0x7a, 0xe3, 0x29, 0x90, 0xd7, 0x6e, 0x6a, 0xa3, - 0x12, 0x55, 0x42, 0x9c, 0x76, 0x66, 0xf6, 0x9b, 0xef, 0x9b, 0x3f, 0xab, 0x85, 0xfb, 0x32, 0xc0, - 0x9e, 0xc0, 0x53, 0x26, 0xfc, 0x9e, 0x0a, 0xbd, 0x09, 0x2a, 0x27, 0x11, 0x5c, 0x71, 0xda, 0x96, - 0x01, 0xc6, 0xa8, 0x4e, 0xb9, 0x98, 0x38, 0x32, 0x40, 0x27, 0xc7, 0xac, 0xaf, 0x05, 0x3c, 0xe0, - 0x1a, 0xd1, 0xcb, 0xac, 0x1c, 0xbc, 0x4e, 0x33, 0x16, 0x95, 0x26, 0xd8, 0x9b, 0xa4, 0x5e, 0x11, - 0x2b, 0x33, 0xe7, 0x47, 0x7e, 0x61, 0x7f, 0x5d, 0x86, 0xf6, 0x48, 0x20, 0x53, 0x38, 0x62, 0x51, - 0xc2, 0xc2, 0x20, 0x7e, 0xc7, 0xd2, 0x63, 0xce, 0x7c, 0xba, 0x0e, 0x46, 0x22, 0x78, 0xc4, 0x15, - 0x0a, 0x93, 0x74, 0x48, 0xb7, 0xe5, 0xce, 0x7d, 0xfa, 0x00, 0x0c, 0xa9, 0x98, 0x50, 0x63, 0x25, - 0xcd, 0xa5, 0x0e, 0xe9, 0xd6, 0xdd, 0xa6, 0xf6, 0xf7, 0x24, 0x6d, 0x43, 0x03, 0x63, 0x3f, 0xbb, - 0x58, 0xd6, 0x17, 0x2b, 0x18, 0xfb, 0x7b, 0x92, 0x0e, 0xc0, 0xf0, 0x98, 0xc2, 0x80, 0x8b, 0xd4, - 0xac, 0x77, 0x48, 0xf7, 0x4e, 0xff, 0xb1, 0x73, 0x63, 0x53, 0x8e, 0xab, 0x8f, 0x51, 0x01, 0x76, - 0xe7, 0x69, 0x74, 0x08, 0xab, 0x39, 0x64, 0x9c, 0x35, 0x67, 0xae, 0x68, 0x96, 0x87, 0x0b, 0x59, - 0xf6, 0xd2, 0x04, 0x5d, 0x10, 0x73, 0x9b, 0xee, 0x03, 0x2d, 0x38, 0x58, 0xc4, 0xa7, 0xb1, 0xca, - 0xa9, 0x1a, 0x9a, 0xea, 0xc9, 0x42, 0xaa, 0x81, 0xc6, 0x6b, 0xc2, 0xbb, 0xe2, 0xb7, 0x08, 0xdd, - 0x86, 0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 0xf4, 0xf1, 0xb9, 0x1f, 0xa8, + 0xa3, 0xf1, 0xa1, 0xed, 0xf2, 0xb0, 0x2d, 0x7d, 0x7c, 0x99, 0xb3, 0xa6, 0x76, 0xfb, 0xd3, 0xec, + 0x81, 0x4e, 0x62, 0x94, 0x87, 0x15, 0xfd, 0x56, 0xbe, 0xfa, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x15, + 0xe0, 0xe0, 0x0b, 0xbb, 0x05, 0x00, 0x00, } func (m *CreateCampaignPayload) Marshal() (dAtA []byte, err error) { @@ -859,6 +907,39 @@ func (m *GrantSignupAffiliatorRewardPayload) MarshalToSizedBuffer(dAtA []byte) ( return len(dAtA) - i, nil } +func (m *SetPromoterConfPayload) 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 *SetPromoterConfPayload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SetPromoterConfPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Conf.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTicket(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func encodeVarintTicket(dAtA []byte, offset int, v uint64) int { offset -= sovTicket(v) base := offset @@ -1003,6 +1084,17 @@ func (m *GrantSignupAffiliatorRewardPayload) Size() (n int) { return n } +func (m *SetPromoterConfPayload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Conf.Size() + n += 1 + l + sovTicket(uint64(l)) + return n +} + func sovTicket(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1940,6 +2032,89 @@ func (m *GrantSignupAffiliatorRewardPayload) Unmarshal(dAtA []byte) error { } return nil } +func (m *SetPromoterConfPayload) 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 ErrIntOverflowTicket + } + 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: SetPromoterConfPayload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SetPromoterConfPayload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Conf", 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 err := m.Conf.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTicket(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTicket + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTicket(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/reward/types/tx.pb.go b/x/reward/types/tx.pb.go index 6c7fa231..70c55422 100644 --- a/x/reward/types/tx.pb.go +++ b/x/reward/types/tx.pb.go @@ -29,6 +29,107 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// MsgSetPromoterConf is msg to set promoter configuration. +type MsgSetPromoterConf struct { + // creator is the address of message signer account. + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + // uid is the unique identifier of the promoter. + Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty"` + // ticket is the payload data. + Ticket string `protobuf:"bytes,3,opt,name=ticket,proto3" json:"ticket,omitempty"` +} + +func (m *MsgSetPromoterConf) Reset() { *m = MsgSetPromoterConf{} } +func (m *MsgSetPromoterConf) String() string { return proto.CompactTextString(m) } +func (*MsgSetPromoterConf) ProtoMessage() {} +func (*MsgSetPromoterConf) Descriptor() ([]byte, []int) { + return fileDescriptor_ad69e28332238e66, []int{0} +} +func (m *MsgSetPromoterConf) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSetPromoterConf) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSetPromoterConf.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 *MsgSetPromoterConf) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSetPromoterConf.Merge(m, src) +} +func (m *MsgSetPromoterConf) XXX_Size() int { + return m.Size() +} +func (m *MsgSetPromoterConf) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSetPromoterConf.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSetPromoterConf proto.InternalMessageInfo + +func (m *MsgSetPromoterConf) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgSetPromoterConf) GetUid() string { + if m != nil { + return m.Uid + } + return "" +} + +func (m *MsgSetPromoterConf) GetTicket() string { + if m != nil { + return m.Ticket + } + return "" +} + +// MsgCreateCampaignResponse campaign create message response type. +type MsgSetPromoterConfResponse struct { +} + +func (m *MsgSetPromoterConfResponse) Reset() { *m = MsgSetPromoterConfResponse{} } +func (m *MsgSetPromoterConfResponse) String() string { return proto.CompactTextString(m) } +func (*MsgSetPromoterConfResponse) ProtoMessage() {} +func (*MsgSetPromoterConfResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ad69e28332238e66, []int{1} +} +func (m *MsgSetPromoterConfResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgSetPromoterConfResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgSetPromoterConfResponse.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 *MsgSetPromoterConfResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgSetPromoterConfResponse.Merge(m, src) +} +func (m *MsgSetPromoterConfResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgSetPromoterConfResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgSetPromoterConfResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgSetPromoterConfResponse proto.InternalMessageInfo + // MsgCreateCampaign is msg to create a reward campaign type MsgCreateCampaign struct { // creator is the address of campaign creator account. @@ -45,7 +146,7 @@ func (m *MsgCreateCampaign) Reset() { *m = MsgCreateCampaign{} } func (m *MsgCreateCampaign) String() string { return proto.CompactTextString(m) } func (*MsgCreateCampaign) ProtoMessage() {} func (*MsgCreateCampaign) Descriptor() ([]byte, []int) { - return fileDescriptor_ad69e28332238e66, []int{0} + return fileDescriptor_ad69e28332238e66, []int{2} } func (m *MsgCreateCampaign) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -103,7 +204,7 @@ func (m *MsgCreateCampaignResponse) Reset() { *m = MsgCreateCampaignResp func (m *MsgCreateCampaignResponse) String() string { return proto.CompactTextString(m) } func (*MsgCreateCampaignResponse) ProtoMessage() {} func (*MsgCreateCampaignResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ad69e28332238e66, []int{1} + return fileDescriptor_ad69e28332238e66, []int{3} } func (m *MsgCreateCampaignResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -149,7 +250,7 @@ func (m *MsgUpdateCampaign) Reset() { *m = MsgUpdateCampaign{} } func (m *MsgUpdateCampaign) String() string { return proto.CompactTextString(m) } func (*MsgUpdateCampaign) ProtoMessage() {} func (*MsgUpdateCampaign) Descriptor() ([]byte, []int) { - return fileDescriptor_ad69e28332238e66, []int{2} + return fileDescriptor_ad69e28332238e66, []int{4} } func (m *MsgUpdateCampaign) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -207,7 +308,7 @@ func (m *MsgUpdateCampaignResponse) Reset() { *m = MsgUpdateCampaignResp func (m *MsgUpdateCampaignResponse) String() string { return proto.CompactTextString(m) } func (*MsgUpdateCampaignResponse) ProtoMessage() {} func (*MsgUpdateCampaignResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ad69e28332238e66, []int{3} + return fileDescriptor_ad69e28332238e66, []int{5} } func (m *MsgUpdateCampaignResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -252,7 +353,7 @@ func (m *MsgGrantReward) Reset() { *m = MsgGrantReward{} } func (m *MsgGrantReward) String() string { return proto.CompactTextString(m) } func (*MsgGrantReward) ProtoMessage() {} func (*MsgGrantReward) Descriptor() ([]byte, []int) { - return fileDescriptor_ad69e28332238e66, []int{4} + return fileDescriptor_ad69e28332238e66, []int{6} } func (m *MsgGrantReward) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -317,7 +418,7 @@ func (m *MsgGrantRewardResponse) Reset() { *m = MsgGrantRewardResponse{} func (m *MsgGrantRewardResponse) String() string { return proto.CompactTextString(m) } func (*MsgGrantRewardResponse) ProtoMessage() {} func (*MsgGrantRewardResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ad69e28332238e66, []int{5} + return fileDescriptor_ad69e28332238e66, []int{7} } func (m *MsgGrantRewardResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -360,7 +461,7 @@ func (m *MsgWithdrawFunds) Reset() { *m = MsgWithdrawFunds{} } func (m *MsgWithdrawFunds) String() string { return proto.CompactTextString(m) } func (*MsgWithdrawFunds) ProtoMessage() {} func (*MsgWithdrawFunds) Descriptor() ([]byte, []int) { - return fileDescriptor_ad69e28332238e66, []int{6} + return fileDescriptor_ad69e28332238e66, []int{8} } func (m *MsgWithdrawFunds) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -418,7 +519,7 @@ func (m *MsgWithdrawFundsResponse) Reset() { *m = MsgWithdrawFundsRespon func (m *MsgWithdrawFundsResponse) String() string { return proto.CompactTextString(m) } func (*MsgWithdrawFundsResponse) ProtoMessage() {} func (*MsgWithdrawFundsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ad69e28332238e66, []int{7} + return fileDescriptor_ad69e28332238e66, []int{9} } func (m *MsgWithdrawFundsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -448,6 +549,8 @@ func (m *MsgWithdrawFundsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgWithdrawFundsResponse proto.InternalMessageInfo func init() { + proto.RegisterType((*MsgSetPromoterConf)(nil), "sgenetwork.sge.reward.MsgSetPromoterConf") + proto.RegisterType((*MsgSetPromoterConfResponse)(nil), "sgenetwork.sge.reward.MsgSetPromoterConfResponse") proto.RegisterType((*MsgCreateCampaign)(nil), "sgenetwork.sge.reward.MsgCreateCampaign") proto.RegisterType((*MsgCreateCampaignResponse)(nil), "sgenetwork.sge.reward.MsgCreateCampaignResponse") proto.RegisterType((*MsgUpdateCampaign)(nil), "sgenetwork.sge.reward.MsgUpdateCampaign") @@ -461,37 +564,39 @@ func init() { func init() { proto.RegisterFile("sge/reward/tx.proto", fileDescriptor_ad69e28332238e66) } var fileDescriptor_ad69e28332238e66 = []byte{ - // 468 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0x41, 0x6f, 0xd3, 0x30, - 0x14, 0xc7, 0x1b, 0x82, 0x86, 0x78, 0x85, 0x69, 0x04, 0x36, 0x85, 0x20, 0xa5, 0x50, 0x09, 0x31, - 0x0e, 0x73, 0x10, 0xbb, 0x71, 0x5c, 0x25, 0x10, 0x87, 0x5e, 0x22, 0x06, 0x12, 0x97, 0xc9, 0x4b, - 0x8c, 0x6b, 0xb5, 0x89, 0x2d, 0xdb, 0x51, 0xb7, 0x6f, 0xc1, 0x17, 0xe1, 0xc0, 0xb7, 0xd8, 0x71, - 0x47, 0xc4, 0xa1, 0x42, 0xed, 0x37, 0xe0, 0x13, 0x20, 0xbb, 0x4d, 0x68, 0xba, 0x75, 0x4a, 0xe1, - 0xe6, 0xe7, 0xf7, 0x7f, 0xef, 0xf7, 0xfe, 0xc9, 0x93, 0xe1, 0xa1, 0xa2, 0x24, 0x92, 0x64, 0x8c, - 0x65, 0x1a, 0xe9, 0x33, 0x24, 0x24, 0xd7, 0xdc, 0xdb, 0x55, 0x94, 0xe4, 0x44, 0x8f, 0xb9, 0x1c, - 0x22, 0x45, 0x09, 0x9a, 0xe7, 0x83, 0x47, 0x94, 0x53, 0x6e, 0x15, 0x91, 0x39, 0xcd, 0xc5, 0xdd, - 0x6f, 0x0e, 0x3c, 0xe8, 0x2b, 0xda, 0x93, 0x04, 0x6b, 0xd2, 0xc3, 0x99, 0xc0, 0x8c, 0xe6, 0x9e, - 0x0f, 0x77, 0x12, 0x73, 0xc3, 0xa5, 0xef, 0x3c, 0x75, 0xf6, 0xef, 0xc6, 0x65, 0xe8, 0xed, 0x80, - 0x5b, 0xb0, 0xd4, 0xbf, 0x65, 0x6f, 0xcd, 0xd1, 0xfb, 0x00, 0x6d, 0xcd, 0x35, 0x1e, 0x9d, 0x7c, - 0x29, 0xf2, 0x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56, 0xb6, 0xe8, 0x06, 0x5a, 0x5d, 0x79, 0x13, - 0xed, 0xfa, 0x5f, 0xed, 0x31, 0xb8, 0x5f, 0xff, 0xa8, 0x2f, 0xd6, 0xb7, 0xa8, 0x09, 0x83, 0xa8, - 0xa1, 0xb0, 0x42, 0x25, 0xd0, 0x5e, 0x5e, 0xa9, 0xe7, 0xeb, 0xeb, 0x97, 0x64, 0xc1, 0x41, 0x23, - 0x59, 0x09, 0x39, 0xea, 0x5d, 0x4c, 0x43, 0xe7, 0x72, 0x1a, 0x3a, 0xbf, 0xa6, 0xa1, 0xf3, 0x75, - 0x16, 0xb6, 0x2e, 0x67, 0x61, 0xeb, 0xc7, 0x2c, 0x6c, 0x7d, 0x7e, 0x49, 0x99, 0x1e, 0x14, 0xa7, - 0x28, 0xe1, 0x59, 0xa4, 0x28, 0x39, 0x58, 0xf4, 0x34, 0xe7, 0xe8, 0xac, 0x7a, 0xc9, 0xce, 0x05, - 0x51, 0xa7, 0x5b, 0xf6, 0x81, 0x3a, 0xfc, 0x13, 0x00, 0x00, 0xff, 0xff, 0xb8, 0x77, 0xc5, 0x13, - 0xe4, 0x04, 0x00, 0x00, + // 505 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x41, 0x6e, 0xd3, 0x40, + 0x14, 0x8d, 0x49, 0x55, 0xc4, 0x0f, 0x94, 0x62, 0x68, 0x65, 0x0c, 0x72, 0xc0, 0x12, 0xa2, 0x5d, + 0xd4, 0x06, 0xba, 0x63, 0xd9, 0x48, 0x20, 0x16, 0x96, 0x50, 0xa0, 0x80, 0xd8, 0x54, 0x53, 0x7b, + 0x3a, 0xb1, 0x12, 0x7b, 0x46, 0x33, 0x63, 0xa5, 0xbd, 0x05, 0x67, 0x60, 0xcf, 0x3d, 0xba, 0xec, + 0x12, 0xb1, 0x88, 0x50, 0x72, 0x03, 0x4e, 0x80, 0x6c, 0xc7, 0x96, 0xc7, 0x69, 0x2a, 0x07, 0xba, + 0x9b, 0x3f, 0x7e, 0xff, 0xbd, 0xff, 0xe4, 0xf7, 0x07, 0xee, 0x0b, 0x82, 0x5d, 0x8e, 0xc7, 0x88, + 0x07, 0xae, 0x3c, 0x75, 0x18, 0xa7, 0x92, 0xea, 0x5b, 0x82, 0xe0, 0x18, 0xcb, 0x31, 0xe5, 0x43, + 0x47, 0x10, 0xec, 0xe4, 0xdf, 0xcd, 0x07, 0x84, 0x12, 0x9a, 0x21, 0xdc, 0xf4, 0x94, 0x83, 0xed, + 0x2f, 0xa0, 0x7b, 0x82, 0x7c, 0xc0, 0xf2, 0x3d, 0xa7, 0x11, 0x95, 0x98, 0xf7, 0x68, 0x7c, 0xa2, + 0x1b, 0x70, 0xd3, 0xe7, 0x18, 0x49, 0xca, 0x0d, 0xed, 0x89, 0xb6, 0x73, 0xab, 0x5f, 0x94, 0xfa, + 0x26, 0xb4, 0x93, 0x30, 0x30, 0x6e, 0x64, 0xb7, 0xe9, 0x51, 0xdf, 0x86, 0x75, 0x19, 0xfa, 0x43, + 0x2c, 0x8d, 0x76, 0x76, 0x39, 0xaf, 0xec, 0xc7, 0x60, 0x2e, 0x32, 0xf7, 0xb1, 0x60, 0x34, 0x16, + 0xd8, 0xfe, 0xa1, 0xc1, 0x3d, 0x4f, 0x90, 0x5e, 0x4a, 0x8b, 0x7b, 0x28, 0x62, 0x28, 0x24, 0xf1, + 0x4a, 0xba, 0x1f, 0xa1, 0x23, 0xa9, 0x44, 0xa3, 0xa3, 0x93, 0x24, 0x0e, 0x44, 0x2e, 0x7e, 0xb0, + 0x7f, 0x3e, 0xe9, 0xb6, 0x7e, 0x4d, 0xba, 0x5b, 0x3e, 0x15, 0x11, 0x15, 0x22, 0x18, 0x3a, 0x21, + 0x75, 0x23, 0x24, 0x07, 0xce, 0xbb, 0x58, 0xfe, 0x99, 0x74, 0xf5, 0x33, 0x14, 0x8d, 0x5e, 0xdb, + 0x95, 0x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bd, 0xf3, 0xa9, 0xa5, 0x5d, 0x4c, 0x2d, 0xed, + 0xf7, 0xd4, 0xd2, 0xbe, 0xcd, 0xac, 0xd6, 0xc5, 0xcc, 0x6a, 0xfd, 0x9c, 0x59, 0xad, 0xaf, 0xbb, + 0x24, 0x94, 0x83, 0xe4, 0xd8, 0xf1, 0x69, 0xe4, 0x0a, 0x82, 0xf7, 0xe6, 0x9c, 0xe9, 0xd9, 0x3d, + 0x2d, 0x9f, 0xec, 0x33, 0x86, 0xc5, 0xf1, 0x7a, 0xf6, 0x12, 0xef, 0xff, 0x0d, 0x00, 0x00, 0xff, + 0xff, 0x85, 0x43, 0xde, 0x62, 0xcd, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -506,6 +611,8 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { + // SetPromoterConf is a method to set the configurations of a promoter. + SetPromoterConf(ctx context.Context, in *MsgSetPromoterConf, opts ...grpc.CallOption) (*MsgSetPromoterConfResponse, error) // CreateCampaign is a method to create a campaign CreateCampaign(ctx context.Context, in *MsgCreateCampaign, opts ...grpc.CallOption) (*MsgCreateCampaignResponse, error) // UpdateCampaign is a method to update campaign @@ -524,6 +631,15 @@ func NewMsgClient(cc grpc1.ClientConn) MsgClient { return &msgClient{cc} } +func (c *msgClient) SetPromoterConf(ctx context.Context, in *MsgSetPromoterConf, opts ...grpc.CallOption) (*MsgSetPromoterConfResponse, error) { + out := new(MsgSetPromoterConfResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.reward.Msg/SetPromoterConf", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *msgClient) CreateCampaign(ctx context.Context, in *MsgCreateCampaign, opts ...grpc.CallOption) (*MsgCreateCampaignResponse, error) { out := new(MsgCreateCampaignResponse) err := c.cc.Invoke(ctx, "/sgenetwork.sge.reward.Msg/CreateCampaign", in, out, opts...) @@ -562,6 +678,8 @@ func (c *msgClient) GrantReward(ctx context.Context, in *MsgGrantReward, opts .. // MsgServer is the server API for Msg service. type MsgServer interface { + // SetPromoterConf is a method to set the configurations of a promoter. + SetPromoterConf(context.Context, *MsgSetPromoterConf) (*MsgSetPromoterConfResponse, error) // CreateCampaign is a method to create a campaign CreateCampaign(context.Context, *MsgCreateCampaign) (*MsgCreateCampaignResponse, error) // UpdateCampaign is a method to update campaign @@ -576,6 +694,9 @@ type MsgServer interface { type UnimplementedMsgServer struct { } +func (*UnimplementedMsgServer) SetPromoterConf(ctx context.Context, req *MsgSetPromoterConf) (*MsgSetPromoterConfResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method SetPromoterConf not implemented") +} func (*UnimplementedMsgServer) CreateCampaign(ctx context.Context, req *MsgCreateCampaign) (*MsgCreateCampaignResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method CreateCampaign not implemented") } @@ -593,6 +714,24 @@ func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) } +func _Msg_SetPromoterConf_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgSetPromoterConf) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).SetPromoterConf(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.reward.Msg/SetPromoterConf", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).SetPromoterConf(ctx, req.(*MsgSetPromoterConf)) + } + return interceptor(ctx, in, info, handler) +} + func _Msg_CreateCampaign_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(MsgCreateCampaign) if err := dec(in); err != nil { @@ -669,6 +808,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "sgenetwork.sge.reward.Msg", HandlerType: (*MsgServer)(nil), Methods: []grpc.MethodDesc{ + { + MethodName: "SetPromoterConf", + Handler: _Msg_SetPromoterConf_Handler, + }, { MethodName: "CreateCampaign", Handler: _Msg_CreateCampaign_Handler, @@ -690,6 +833,73 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ Metadata: "sge/reward/tx.proto", } +func (m *MsgSetPromoterConf) 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 *MsgSetPromoterConf) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSetPromoterConf) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Ticket) > 0 { + i -= len(m.Ticket) + copy(dAtA[i:], m.Ticket) + i = encodeVarintTx(dAtA, i, uint64(len(m.Ticket))) + i-- + dAtA[i] = 0x1a + } + if len(m.Uid) > 0 { + i -= len(m.Uid) + copy(dAtA[i:], m.Uid) + i = encodeVarintTx(dAtA, i, uint64(len(m.Uid))) + i-- + dAtA[i] = 0x12 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgSetPromoterConfResponse) 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 *MsgSetPromoterConfResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgSetPromoterConfResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func (m *MsgCreateCampaign) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -996,6 +1206,36 @@ func encodeVarintTx(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } +func (m *MsgSetPromoterConf) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Uid) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Ticket) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgSetPromoterConfResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func (m *MsgCreateCampaign) Size() (n int) { if m == nil { return 0 @@ -1130,6 +1370,202 @@ func sovTx(x uint64) (n int) { func sozTx(x uint64) (n int) { return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } +func (m *MsgSetPromoterConf) 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 ErrIntOverflowTx + } + 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: MsgSetPromoterConf: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSetPromoterConf: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Uid", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Uid = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Ticket", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Ticket = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgSetPromoterConfResponse) 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 ErrIntOverflowTx + } + 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: MsgSetPromoterConfResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgSetPromoterConfResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *MsgCreateCampaign) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 From 9baaa32e271aaa97cac23bd231aff6e2b987457d Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Mon, 4 Mar 2024 14:40:31 +0300 Subject: [PATCH 05/28] test: msg server and type test for promoter config --- x/reward/keeper/msg_server_promoter.go | 2 +- x/reward/keeper/msg_server_promoter_test.go | 116 ++++++++++++++++++++ x/reward/types/messages_promoter_test.go | 62 +++++++++++ 3 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 x/reward/keeper/msg_server_promoter_test.go create mode 100644 x/reward/types/messages_promoter_test.go diff --git a/x/reward/keeper/msg_server_promoter.go b/x/reward/keeper/msg_server_promoter.go index 999b9094..9fcaa4bb 100644 --- a/x/reward/keeper/msg_server_promoter.go +++ b/x/reward/keeper/msg_server_promoter.go @@ -15,7 +15,7 @@ func (k msgServer) SetPromoterConf(goCtx context.Context, msg *types.MsgSetPromo // Check if the value already exists promoter, isFound := k.GetPromoter(ctx, msg.Uid) if !isFound { - return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "promoter does not exist", msg.Uid) + return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "promoter does not exist %s", msg.Uid) } creatorIsPromoter := false diff --git a/x/reward/keeper/msg_server_promoter_test.go b/x/reward/keeper/msg_server_promoter_test.go new file mode 100644 index 00000000..5ce13fe2 --- /dev/null +++ b/x/reward/keeper/msg_server_promoter_test.go @@ -0,0 +1,116 @@ +package keeper_test + +import ( + "testing" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/golang-jwt/jwt" + "github.com/google/uuid" + "github.com/sge-network/sge/testutil/simapp" + "github.com/stretchr/testify/require" + + "github.com/sge-network/sge/x/reward/keeper" + "github.com/sge-network/sge/x/reward/types" +) + +func TestSetPromoterConfig(t *testing.T) { + k, ctx := setupKeeper(t) + srv := keeper.NewMsgServerImpl(*k) + ctx = ctx.WithBlockTime(time.Now()) + wctx := sdk.WrapSDKContext(ctx) + promoter := simapp.TestParamUsers["user1"].Address.String() + promoterUID := uuid.NewString() + k.SetPromoter(ctx, types.Promoter{ + Creator: promoter, + UID: promoterUID, + Addresses: []string{ + promoter, + }, + Conf: types.PromoterConf{ + CategoryCap: []types.CategoryCap{ + { + Category: types.RewardCategory_REWARD_CATEGORY_SIGNUP, + CapPerAcc: 1, + }, + }, + }, + }) + + for _, tc := range []struct { + desc string + claims jwt.MapClaims + uid string + err error + }{ + { + desc: "invalid ticket", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "conf": "invalid", + }, + uid: promoterUID, + err: types.ErrInTicketVerification, + }, + { + desc: "duplicate cap category", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "conf": types.PromoterConf{ + CategoryCap: []types.CategoryCap{ + {Category: types.RewardCategory_REWARD_CATEGORY_SIGNUP, CapPerAcc: 1}, + {Category: types.RewardCategory_REWARD_CATEGORY_SIGNUP, CapPerAcc: 1}, + }, + }, + }, + uid: promoterUID, + err: types.ErrDuplicateCategoryInConf, + }, + { + desc: "low cap category", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "conf": types.PromoterConf{ + CategoryCap: []types.CategoryCap{ + {Category: types.RewardCategory_REWARD_CATEGORY_SIGNUP, CapPerAcc: 0}, + {Category: types.RewardCategory_REWARD_CATEGORY_AFFILIATE, CapPerAcc: 1}, + }, + }, + }, + uid: promoterUID, + err: types.ErrCategoryCapShouldBePos, + }, + { + desc: "valid", + claims: jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "conf": types.PromoterConf{ + CategoryCap: []types.CategoryCap{ + {Category: types.RewardCategory_REWARD_CATEGORY_SIGNUP, CapPerAcc: 1}, + }, + }, + }, + uid: promoterUID, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + ticket, err := simapp.CreateJwtTicket(tc.claims) + require.Nil(t, err) + conf := &types.MsgSetPromoterConf{ + Uid: tc.uid, + Creator: promoter, + Ticket: ticket, + } + _, err = srv.SetPromoterConf(wctx, conf) + if tc.err != nil { + require.ErrorContains(t, err, tc.err.Error()) + } else { + require.NoError(t, err) + } + }) + } +} diff --git a/x/reward/types/messages_promoter_test.go b/x/reward/types/messages_promoter_test.go new file mode 100644 index 00000000..bc0b5afb --- /dev/null +++ b/x/reward/types/messages_promoter_test.go @@ -0,0 +1,62 @@ +package types_test + +import ( + "testing" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/google/uuid" + "github.com/sge-network/sge/testutil/sample" + "github.com/sge-network/sge/x/reward/types" + "github.com/stretchr/testify/require" +) + +func TestMsgSetPromoterConf_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg types.MsgSetPromoterConf + err error + }{ + { + name: "invalid address", + msg: types.MsgSetPromoterConf{ + Creator: "invalid_address", + }, + err: sdkerrors.ErrInvalidAddress, + }, + { + name: "invalid campaign uid", + msg: types.MsgSetPromoterConf{ + Creator: sample.AccAddress(), + Uid: "bad uid", + Ticket: "ticket", + }, + err: sdkerrors.ErrInvalidRequest, + }, + { + name: "invalid ticket", + msg: types.MsgSetPromoterConf{ + Creator: sample.AccAddress(), + Uid: uuid.NewString(), + }, + err: sdkerrors.ErrInvalidRequest, + }, + { + name: "valid address", + msg: types.MsgSetPromoterConf{ + Creator: sample.AccAddress(), + Uid: uuid.NewString(), + Ticket: "ticket", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.ValidateBasic() + if tt.err != nil { + require.ErrorIs(t, err, tt.err) + return + } + require.NoError(t, err) + }) + } +} From 7d6cf1cae09ee5db876aa4c90b02e5618cbc252a Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Wed, 6 Mar 2024 13:32:32 +0300 Subject: [PATCH 06/28] feat: category cap for campaign --- proto/sge/reward/campaign.proto | 3 + proto/sge/reward/ticket.proto | 3 + x/reward/keeper/msg_server_campaign.go | 1 + x/reward/keeper/msg_server_reward.go | 14 +++ x/reward/keeper/msg_server_reward_test.go | 84 ++++++++++++--- x/reward/keeper/reward.go | 18 ++++ x/reward/keeper/view.go | 6 ++ x/reward/types/campaign.go | 2 + x/reward/types/campaign.pb.go | 97 +++++++++++------ x/reward/types/key_reward.go | 8 ++ x/reward/types/ticket.pb.go | 121 ++++++++++++++-------- 11 files changed, 272 insertions(+), 85 deletions(-) diff --git a/proto/sge/reward/campaign.proto b/proto/sge/reward/campaign.proto index 83b96ec7..1f4382c7 100644 --- a/proto/sge/reward/campaign.proto +++ b/proto/sge/reward/campaign.proto @@ -57,6 +57,9 @@ message Campaign { // meta is the metadata of the campaign. // It is a stringified base64 encoded json. string meta = 13; + + // cap_count is the maximum allowed grant for a certain account. + uint64 cap_count = 14; } // Pool tracks funds assigned and spent to/for a campaign. diff --git a/proto/sge/reward/ticket.proto b/proto/sge/reward/ticket.proto index 859a1945..cbc57a0f 100644 --- a/proto/sge/reward/ticket.proto +++ b/proto/sge/reward/ticket.proto @@ -38,6 +38,9 @@ message CreateCampaignPayload { // meta is the metadata of the campaign. // It is a stringified base64 encoded json. string meta = 10; + + // cap_count is the maximum allowed grant for a certain account. + uint64 cap_count = 11; } // 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 307b511e..feefadbe 100644 --- a/x/reward/keeper/msg_server_campaign.go +++ b/x/reward/keeper/msg_server_campaign.go @@ -61,6 +61,7 @@ func (k msgServer) CreateCampaign(goCtx context.Context, msg *types.MsgCreateCam payload.IsActive, payload.Meta, types.NewPool(msg.TotalFunds), + payload.CapCount, ) rewardFactory, err := campaign.GetRewardsFactory() diff --git a/x/reward/keeper/msg_server_reward.go b/x/reward/keeper/msg_server_reward.go index ff85a200..a649b9a4 100644 --- a/x/reward/keeper/msg_server_reward.go +++ b/x/reward/keeper/msg_server_reward.go @@ -48,6 +48,20 @@ func (k msgServer) GrantReward(goCtx context.Context, msg *types.MsgGrantReward) return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "distribution calculation failed %s", err) } + var grantStats uint64 + if campaign.CapCount > 0 { + grantStats, isFound = k.GetRewardGrantsStats(ctx, msg.CampaignUid, factData.Receiver.MainAccountAddr) + if !isFound { + grantStats = 0 + } + if grantStats >= campaign.CapCount { + return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "maximum count cap of the campaign is reached %d", grantStats) + } + + grantStats++ + k.SetRewardGrantsStats(ctx, msg.CampaignUid, factData.Receiver.MainAccountAddr, grantStats) + } + promoterByAddress, isFound := k.GetPromoterByAddress(ctx, campaign.Promoter) if !isFound { return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "promoter with the address: %s not found", campaign.Promoter) diff --git a/x/reward/keeper/msg_server_reward_test.go b/x/reward/keeper/msg_server_reward_test.go index 2ade6ceb..bc3134b4 100644 --- a/x/reward/keeper/msg_server_reward_test.go +++ b/x/reward/keeper/msg_server_reward_test.go @@ -22,6 +22,10 @@ import ( var promoterUID = uuid.NewString() +var defaultCategoryCap = []types.CategoryCap{ + {Category: types.RewardCategory_REWARD_CATEGORY_SIGNUP, CapPerAcc: 1}, +} + func getDefaultClaim(creator string) jwt.MapClaims { return jwt.MapClaims{ "exp": time.Now().Add(time.Minute * 5).Unix(), @@ -37,16 +41,14 @@ func getDefaultClaim(creator string) jwt.MapClaims { } func createCampaign(t *testing.T, k *keeper.Keeper, srv types.MsgServer, ctx sdk.Context, - promoter string, claims jwt.MapClaims, + promoter string, claims jwt.MapClaims, categoryCap []types.CategoryCap, ) string { k.SetPromoter(ctx, types.Promoter{ Creator: promoter, UID: promoterUID, Addresses: []string{promoter}, Conf: types.PromoterConf{ - CategoryCap: []types.CategoryCap{ - {Category: types.RewardCategory_REWARD_CATEGORY_SIGNUP, CapPerAcc: 1}, - }, + CategoryCap: categoryCap, }, }) @@ -100,7 +102,7 @@ func TestMsgApplySignupReward(t *testing.T) { UnlockPeriod: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), } - campUID := createCampaign(t, k, srv, ctx, promoter, campClaims) + campUID := createCampaign(t, k, srv, ctx, promoter, campClaims, defaultCategoryCap) for _, tc := range []struct { desc string @@ -152,6 +154,62 @@ func TestMsgApplySignupReward(t *testing.T) { } } +func TestMsgApplySignupRewardWithCap(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() + receiverAddr := simapp.TestParamUsers["user2"].Address.String() + + _, err := tApp.SubaccountKeeper.CreateSubAccount(ctx, receiverAddr, receiverAddr, []subaccounttypes.LockedBalance{ + { + Amount: sdk.ZeroInt(), + UnlockTS: uint64(ctx.BlockTime().Add(60 * time.Minute).Unix()), + }, + }) + require.NoError(t, err) + + campClaims := getDefaultClaim(promoter) + campClaims["reward_type"] = types.RewardType_REWARD_TYPE_SIGNUP + campClaims["reward_amount_type"] = types.RewardAmountType_REWARD_AMOUNT_TYPE_FIXED + campClaims["reward_amount"] = types.RewardAmount{ + SubaccountAmount: sdkmath.NewInt(100), + UnlockPeriod: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), + } + campClaims["cap_count"] = 1 + + campUID := createCampaign(t, k, srv, ctx, promoter, campClaims, []types.CategoryCap{}) + + ticket, err := simapp.CreateJwtTicket(jwt.MapClaims{ + "exp": time.Now().Add(time.Minute * 5).Unix(), + "iat": time.Now().Unix(), + "common": types.RewardPayloadCommon{ + Receiver: receiverAddr, + SourceUID: "", + Meta: "signup reward for example user", + KycData: &sgetypes.KycDataPayload{ + Approved: true, + ID: receiverAddr, + }, + }, + }) + require.Nil(t, err) + reward := &types.MsgGrantReward{ + Uid: uuid.NewString(), + Creator: promoter, + CampaignUid: campUID, + Ticket: ticket, + } + _, err = srv.GrantReward(wctx, reward) + require.NoError(t, err) + + reward.Uid = uuid.NewString() + _, err = srv.GrantReward(wctx, reward) + require.ErrorContains(t, err, "maximum count cap of the campaign is reached") +} + func TestMsgApplySignupRefereeReward(t *testing.T) { tApp, k, ctx := setupKeeperAndApp(t) srv := keeper.NewMsgServerImpl(*k) @@ -179,7 +237,7 @@ func TestMsgApplySignupRefereeReward(t *testing.T) { UnlockPeriod: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), } - campUID := createCampaign(t, k, srv, ctx, promoter, campClaims) + campUID := createCampaign(t, k, srv, ctx, promoter, campClaims, defaultCategoryCap) for _, tc := range []struct { desc string @@ -272,7 +330,7 @@ func TestMsgApplySignupReferrerReward(t *testing.T) { SubaccountAmount: sdkmath.NewInt(100), UnlockPeriod: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), } - referralSignupCampUID := createCampaign(t, k, srv, ctx, promoter, referralSignupCampClaims) + referralSignupCampUID := createCampaign(t, k, srv, ctx, promoter, referralSignupCampClaims, defaultCategoryCap) // referral campaign referralCampClaims := getDefaultClaim(promoter) @@ -283,7 +341,7 @@ func TestMsgApplySignupReferrerReward(t *testing.T) { SubaccountAmount: sdkmath.NewInt(100), UnlockPeriod: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), } - referralCampUID := createCampaign(t, k, srv, ctx, promoter, referralCampClaims) + referralCampUID := createCampaign(t, k, srv, ctx, promoter, referralCampClaims, defaultCategoryCap) refereeClaims := jwt.MapClaims{ "exp": time.Now().Add(time.Minute * 5).Unix(), @@ -411,7 +469,7 @@ func TestMsgApplySignupAffiliateReward(t *testing.T) { UnlockPeriod: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), } - campUID := createCampaign(t, k, srv, ctx, promoter, campClaims) + campUID := createCampaign(t, k, srv, ctx, promoter, campClaims, defaultCategoryCap) for _, tc := range []struct { desc string @@ -504,7 +562,7 @@ func TestMsgApplySignupAffiliateeReward(t *testing.T) { SubaccountAmount: sdkmath.NewInt(100), UnlockPeriod: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), } - affiliateSignupCampUID := createCampaign(t, k, srv, ctx, promoter, affiliateSignupCampClaims) + affiliateSignupCampUID := createCampaign(t, k, srv, ctx, promoter, affiliateSignupCampClaims, defaultCategoryCap) // affiliate campaign affiliateCampClaims := getDefaultClaim(promoter) @@ -515,7 +573,7 @@ func TestMsgApplySignupAffiliateeReward(t *testing.T) { MainAccountAmount: sdkmath.NewInt(100), UnlockPeriod: 0, } - affiliateCampUID := createCampaign(t, k, srv, ctx, promoter, affiliateCampClaims) + affiliateCampUID := createCampaign(t, k, srv, ctx, promoter, affiliateCampClaims, defaultCategoryCap) affiliateClaims := jwt.MapClaims{ "exp": time.Now().Add(time.Minute * 5).Unix(), @@ -633,7 +691,7 @@ func TestMsgApplySignupRewardSubAcc(t *testing.T) { UnlockPeriod: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), } - campUID := createCampaign(t, k, srv, ctx, promoter, campClaims) + campUID := createCampaign(t, k, srv, ctx, promoter, campClaims, defaultCategoryCap) _, err := tApp.SubaccountKeeper.CreateSubAccount(ctx, receiverAddr, receiverAddr, []subaccounttypes.LockedBalance{ { @@ -748,7 +806,7 @@ func TestMsgApplySubAccFunds(t *testing.T) { UnlockPeriod: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), } - campUID := createCampaign(t, k, srv, ctx, promoter, campClaims) + campUID := createCampaign(t, k, srv, ctx, promoter, campClaims, defaultCategoryCap) claims := jwt.MapClaims{ "exp": time.Now().Add(time.Minute * 5).Unix(), diff --git a/x/reward/keeper/reward.go b/x/reward/keeper/reward.go index 16f94b08..28473a72 100644 --- a/x/reward/keeper/reward.go +++ b/x/reward/keeper/reward.go @@ -2,6 +2,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/utils" "github.com/sge-network/sge/x/reward/types" ) @@ -127,3 +128,20 @@ func (k Keeper) GetAllRewardsByCampaign(ctx sdk.Context) (list []types.RewardByC return } + +func (k Keeper) SetRewardGrantsStats(ctx sdk.Context, campaignUID, accAddr string, count uint64) { + store := k.getRewardGrantsStatStore(ctx) + b := utils.Uint64ToBytes(count) + store.Set(types.GetRewardGrantStatKey(campaignUID, accAddr), b) +} + +func (k Keeper) GetRewardGrantsStats(ctx sdk.Context, campaignUID, accAddr string) (val uint64, found bool) { + store := k.getRewardGrantsStatStore(ctx) + b := store.Get(types.GetRewardGrantStatKey(campaignUID, accAddr)) + if b == nil { + return val, false + } + + val = utils.Uint64FromBytes(b) + return val, true +} diff --git a/x/reward/keeper/view.go b/x/reward/keeper/view.go index 56ddc0d5..273f7d92 100644 --- a/x/reward/keeper/view.go +++ b/x/reward/keeper/view.go @@ -42,3 +42,9 @@ func (k Keeper) getPromoterStore(ctx sdk.Context) prefix.Store { store := ctx.KVStore(k.storeKey) return prefix.NewStore(store, types.PromoterKeyPrefix) } + +// getRewardGrantsStatStore gets the store containing all reward grant stats. +func (k Keeper) getRewardGrantsStatStore(ctx sdk.Context) prefix.Store { + store := ctx.KVStore(k.storeKey) + return prefix.NewStore(store, types.RewardGrantStatKeyPrefix) +} diff --git a/x/reward/types/campaign.go b/x/reward/types/campaign.go index 8b7b5c5f..4d595fa8 100644 --- a/x/reward/types/campaign.go +++ b/x/reward/types/campaign.go @@ -15,6 +15,7 @@ func NewCampaign( isActive bool, meta string, pool Pool, + capCount uint64, ) Campaign { return Campaign{ Creator: creator, @@ -29,6 +30,7 @@ func NewCampaign( IsActive: isActive, Meta: meta, Pool: pool, + CapCount: capCount, } } diff --git a/x/reward/types/campaign.pb.go b/x/reward/types/campaign.pb.go index 1e36025b..654c5fb0 100644 --- a/x/reward/types/campaign.pb.go +++ b/x/reward/types/campaign.pb.go @@ -52,6 +52,8 @@ type Campaign struct { // meta is the metadata of the campaign. // It is a stringified base64 encoded json. 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"` } func (m *Campaign) Reset() { *m = Campaign{} } @@ -171,6 +173,13 @@ func (m *Campaign) GetMeta() string { return "" } +func (m *Campaign) GetCapCount() uint64 { + if m != nil { + return m.CapCount + } + return 0 +} + // 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"` @@ -218,40 +227,41 @@ func init() { func init() { proto.RegisterFile("sge/reward/campaign.proto", fileDescriptor_6d1d1b3139567e36) } var fileDescriptor_6d1d1b3139567e36 = []byte{ - // 517 bytes of a gzipped FileDescriptorProto + // 536 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0x4f, 0x6f, 0xd3, 0x30, 0x18, 0xc6, 0x6b, 0x9a, 0xb6, 0xa9, 0xbb, 0x15, 0x64, 0x98, 0x66, 0x3a, 0x29, 0x09, 0x45, 0x88, 0x22, 0xb4, 0x44, 0xda, 0xc4, 0x85, 0xdb, 0x52, 0x90, 0xd8, 0x05, 0x21, 0x6f, 0xbb, 0x70, 0xa9, 0xbc, 0xd4, 0xca, 0xa2, 0x35, 0x71, 0x64, 0xbb, 0x8c, 0x7e, 0x8b, 0x7d, 0xac, 0x1d, 0x77, 0x44, - 0x1c, 0x22, 0x48, 0x6f, 0x3b, 0xf2, 0x09, 0x90, 0x9d, 0xac, 0xda, 0x10, 0x9b, 0x76, 0xc9, 0xfb, - 0xef, 0x79, 0x7e, 0x52, 0xec, 0xd7, 0xf0, 0xb9, 0x8c, 0x59, 0x20, 0xd8, 0x19, 0x15, 0xd3, 0x20, - 0xa2, 0x69, 0x4e, 0x93, 0x38, 0xf3, 0x73, 0xc1, 0x15, 0x47, 0x1b, 0x32, 0x66, 0x19, 0x53, 0x67, - 0x5c, 0x9c, 0xfa, 0x32, 0x66, 0x7e, 0xa5, 0x1a, 0x3c, 0x8b, 0x79, 0xcc, 0x8d, 0x22, 0xd0, 0x59, - 0x25, 0x1e, 0x6c, 0xde, 0xe0, 0x54, 0xa1, 0x1a, 0x0c, 0x7f, 0x5b, 0xd0, 0x1e, 0xd7, 0x60, 0x84, - 0x61, 0x27, 0x12, 0x8c, 0x2a, 0x2e, 0x30, 0xf0, 0xc0, 0xa8, 0x4b, 0xae, 0x4b, 0xe4, 0xc1, 0xe6, - 0x3c, 0x99, 0xe2, 0x47, 0xba, 0x1b, 0xf6, 0xcb, 0xc2, 0x6d, 0x1e, 0xed, 0x7f, 0xb8, 0x2a, 0x5c, - 0xdd, 0x25, 0xfa, 0x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0x0c, 0x49, 0xe5, 0xd5, 0x10, 0x99, 0xb3, 0x4c, 0xd5, 0x93, 0xfa, + 0x50, 0x88, 0xf1, 0x0c, 0x49, 0xe5, 0x0d, 0xc7, 0x17, 0xa5, 0x03, 0x2e, 0x4b, 0x07, 0xfc, 0x2a, + 0x1d, 0x70, 0xbe, 0x74, 0x1a, 0x97, 0x4b, 0xa7, 0xf1, 0x63, 0xe9, 0x34, 0xbe, 0xbe, 0x89, 0x13, + 0x75, 0x32, 0x3f, 0xf6, 0x23, 0x9e, 0x06, 0x32, 0x66, 0xdb, 0xf5, 0x71, 0xe9, 0x38, 0xf8, 0x7e, + 0xfd, 0xbe, 0xf4, 0x35, 0xcb, 0xe3, 0xb6, 0x79, 0x5f, 0xbb, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, + 0xad, 0x1c, 0x52, 0x91, 0xc2, 0x03, 0x00, 0x00, } func (m *Campaign) Marshal() (dAtA []byte, err error) { @@ -274,6 +284,11 @@ func (m *Campaign) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.CapCount != 0 { + i = encodeVarintCampaign(dAtA, i, uint64(m.CapCount)) + i-- + dAtA[i] = 0x70 + } if len(m.Meta) > 0 { i -= len(m.Meta) copy(dAtA[i:], m.Meta) @@ -462,6 +477,9 @@ func (m *Campaign) Size() (n int) { if l > 0 { n += 1 + l + sovCampaign(uint64(l)) } + if m.CapCount != 0 { + n += 1 + sovCampaign(uint64(m.CapCount)) + } return n } @@ -825,6 +843,25 @@ func (m *Campaign) Unmarshal(dAtA []byte) error { } m.Meta = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 14: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CapCount", wireType) + } + m.CapCount = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCampaign + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CapCount |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipCampaign(dAtA[iNdEx:]) diff --git a/x/reward/types/key_reward.go b/x/reward/types/key_reward.go index 19f9742e..8d56a279 100644 --- a/x/reward/types/key_reward.go +++ b/x/reward/types/key_reward.go @@ -17,6 +17,9 @@ var ( // RewardByCampaignKeyPrefix is the prefix to retrieve all applied rewards for a certain campaign. RewardByCampaignKeyPrefix = []byte{0x03} + + // RewardGrantStatKeyPrefix is the prefix to retrieve count of reward grants for a certain account. + RewardGrantStatKeyPrefix = []byte{0x06} ) // GetRewardsOfReceiverByPromoterPrefix returns the store key to retrieve list of all applied rewards of a certain campaign @@ -51,3 +54,8 @@ func GetRewardsByCampaignPrefix(campaignUID string) []byte { func GetRewardsByCampaignKey(campaignUID, uid string) []byte { return append(utils.StrBytes(campaignUID), utils.StrBytes(uid)...) } + +// GetRewardGrantStatKey returns the store key to retrieve a certain account. +func GetRewardGrantStatKey(campaignUID, addr string) []byte { + return append(utils.StrBytes(campaignUID), utils.StrBytes(addr)...) +} diff --git a/x/reward/types/ticket.pb.go b/x/reward/types/ticket.pb.go index d1465c1c..003e60a8 100644 --- a/x/reward/types/ticket.pb.go +++ b/x/reward/types/ticket.pb.go @@ -46,6 +46,8 @@ type CreateCampaignPayload struct { // meta is the metadata of the campaign. // It is a stringified base64 encoded json. 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"` } func (m *CreateCampaignPayload) Reset() { *m = CreateCampaignPayload{} } @@ -144,6 +146,13 @@ func (m *CreateCampaignPayload) GetMeta() string { return "" } +func (m *CreateCampaignPayload) GetCapCount() uint64 { + if m != nil { + return m.CapCount + } + return 0 +} + // UpdateCampaignPayload is the type for campaign update payload. type UpdateCampaignPayload struct { // end_ts is the end timestamp of the campaign. @@ -542,48 +551,49 @@ func init() { func init() { proto.RegisterFile("sge/reward/ticket.proto", fileDescriptor_5d710bc1249ca8ae) } var fileDescriptor_5d710bc1249ca8ae = []byte{ - // 647 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0xcf, 0x6e, 0xd3, 0x4e, - 0x10, 0xce, 0xb6, 0x69, 0xfe, 0x4c, 0x7f, 0x3f, 0x84, 0x96, 0x06, 0xdc, 0x56, 0x72, 0x83, 0x11, - 0x22, 0x20, 0xe1, 0x48, 0xe1, 0x88, 0x40, 0x4a, 0x52, 0x41, 0x51, 0x2f, 0x95, 0xdb, 0xaa, 0x12, - 0x97, 0x68, 0x6b, 0x4f, 0x5c, 0x2b, 0xb5, 0xd7, 0xda, 0xdd, 0xb4, 0xf8, 0x05, 0x38, 0x22, 0x9e, - 0x88, 0x03, 0xa7, 0x1e, 0x7b, 0xe4, 0x54, 0xa1, 0xf4, 0xc6, 0x53, 0x20, 0xaf, 0x9d, 0xd4, 0x41, - 0x6d, 0x55, 0x09, 0x71, 0xf2, 0xcc, 0xce, 0x37, 0xdf, 0x7c, 0x33, 0xb3, 0x5e, 0x78, 0x24, 0x7d, - 0x6c, 0x0b, 0x3c, 0x65, 0xc2, 0x6b, 0xab, 0xc0, 0x1d, 0xa1, 0xb2, 0x63, 0xc1, 0x15, 0xa7, 0x0d, - 0xe9, 0x63, 0x84, 0xea, 0x94, 0x8b, 0x91, 0x2d, 0x7d, 0xb4, 0x33, 0xcc, 0xda, 0x8a, 0xcf, 0x7d, - 0xae, 0x11, 0xed, 0xd4, 0xca, 0xc0, 0x6b, 0x34, 0x65, 0x51, 0x49, 0x8c, 0xed, 0x51, 0xe2, 0xe6, - 0x67, 0x45, 0xe6, 0xec, 0x93, 0x07, 0x56, 0x0b, 0x81, 0x58, 0xf0, 0x90, 0x2b, 0x14, 0x59, 0xc8, - 0xfa, 0xb6, 0x08, 0x8d, 0xbe, 0x40, 0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- 0xbe, 0x10, 0xb0, 0x0a, 0x42, 0xba, 0xc3, 0x61, 0x70, 0x1c, 0x30, 0xc5, 0xff, 0x99, 0x14, 0x13, - 0x80, 0xe5, 0x45, 0x66, 0x6a, 0x0a, 0x27, 0xd6, 0x01, 0x3c, 0xdc, 0x45, 0xb5, 0x93, 0xdf, 0xa9, - 0x3e, 0x8f, 0x86, 0x53, 0x0d, 0x6f, 0xa0, 0xec, 0xf2, 0x68, 0x98, 0x2b, 0xb8, 0xe9, 0x8f, 0x2a, - 0x66, 0xe6, 0xa5, 0x75, 0x5a, 0xaf, 0x7f, 0x36, 0x31, 0xc9, 0xf9, 0xc4, 0x24, 0x3f, 0x27, 0x26, - 0xf9, 0x7a, 0x69, 0x96, 0xce, 0x2f, 0xcd, 0xd2, 0x8f, 0x4b, 0xb3, 0xf4, 0xf1, 0xb9, 0x1f, 0xa8, - 0xa3, 0xf1, 0xa1, 0xed, 0xf2, 0xb0, 0x2d, 0x7d, 0x7c, 0x99, 0xb3, 0xa6, 0x76, 0xfb, 0xd3, 0xec, - 0x81, 0x4e, 0x62, 0x94, 0x87, 0x15, 0xfd, 0x56, 0xbe, 0xfa, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x15, - 0xe0, 0xe0, 0x0b, 0xbb, 0x05, 0x00, 0x00, + // 662 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0x41, 0x6b, 0xdb, 0x4a, + 0x10, 0xf6, 0x26, 0x8e, 0x2d, 0x8f, 0xdf, 0x7b, 0x3c, 0xf6, 0xc5, 0xaf, 0x4a, 0x02, 0x8a, 0xab, + 0x52, 0xea, 0x16, 0x2a, 0x83, 0x7b, 0x2c, 0x2d, 0xd8, 0x0a, 0x6d, 0x4a, 0x2e, 0x41, 0x49, 0x08, + 0xf4, 0x62, 0x36, 0xab, 0xb5, 0x22, 0x1c, 0x69, 0xc5, 0xee, 0x3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0x0b, 0x7d, + 0xbe, 0xb2, 0x2a, 0x17, 0x57, 0x56, 0xe5, 0xeb, 0x95, 0x55, 0x79, 0xff, 0x34, 0x08, 0xd5, 0xf1, + 0xe4, 0xc8, 0xa1, 0x3c, 0xea, 0xca, 0x80, 0x3d, 0x2f, 0x58, 0x33, 0xbb, 0xfb, 0x61, 0xfe, 0x7a, + 0xa7, 0x09, 0x93, 0x47, 0x35, 0xfd, 0x90, 0xbe, 0xf8, 0x19, 0x00, 0x00, 0xff, 0xff, 0x57, 0xb2, + 0x0b, 0x5b, 0xd8, 0x05, 0x00, 0x00, } func (m *CreateCampaignPayload) Marshal() (dAtA []byte, err error) { @@ -606,6 +616,11 @@ func (m *CreateCampaignPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.CapCount != 0 { + i = encodeVarintTicket(dAtA, i, uint64(m.CapCount)) + i-- + dAtA[i] = 0x58 + } if len(m.Meta) > 0 { i -= len(m.Meta) copy(dAtA[i:], m.Meta) @@ -987,6 +1002,9 @@ func (m *CreateCampaignPayload) Size() (n int) { if l > 0 { n += 1 + l + sovTicket(uint64(l)) } + if m.CapCount != 0 { + n += 1 + sovTicket(uint64(m.CapCount)) + } return n } @@ -1345,6 +1363,25 @@ func (m *CreateCampaignPayload) Unmarshal(dAtA []byte) error { } m.Meta = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 11: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CapCount", wireType) + } + m.CapCount = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTicket + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CapCount |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipTicket(dAtA[iNdEx:]) From 70b9687bf2a23a92adb45b794b332a8186e793fd Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:12:32 +0300 Subject: [PATCH 07/28] feat: bet bonus implementation the commit. # # On branch feature/reward-bet-bonus # Changes to be committed: # modified: proto/sge/reward/ticket.proto # new file: x/reward/types/reward_bet_bonus.go # modified: x/reward/types/ticket.pb.go # --- proto/sge/reward/ticket.proto | 14 ++ x/reward/types/reward_bet_bonus.go | 90 ++++++++ x/reward/types/ticket.pb.go | 317 +++++++++++++++++++++++++---- 3 files changed, 377 insertions(+), 44 deletions(-) create mode 100644 x/reward/types/reward_bet_bonus.go diff --git a/proto/sge/reward/ticket.proto b/proto/sge/reward/ticket.proto index cbc57a0f..9f92b0f7 100644 --- a/proto/sge/reward/ticket.proto +++ b/proto/sge/reward/ticket.proto @@ -111,6 +111,20 @@ message GrantSignupAffiliatorRewardPayload { string affiliatee = 2; } +// GrantBetBonusRewardPayload is the type for bet bonus reward +// grant payload. +message GrantBetBonusRewardPayload { + // common is the common properties of a reward + RewardPayloadCommon common = 1 [ (gogoproto.nullable) = false ]; + + // bet_uid is the list of uids + string bet_uid = 2 [ + (gogoproto.customname) = "BetUID", + (gogoproto.jsontag) = "bet_uid", + json_name = "bet_uid" + ]; +} + // SetPromoterConfPayload is the payload for the promoter configuration change. message SetPromoterConfPayload { PromoterConf conf = 1 [ (gogoproto.nullable) = false ]; diff --git a/x/reward/types/reward_bet_bonus.go b/x/reward/types/reward_bet_bonus.go new file mode 100644 index 00000000..9156a9d1 --- /dev/null +++ b/x/reward/types/reward_bet_bonus.go @@ -0,0 +1,90 @@ +package types + +import ( + context "context" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" +) + +var percent = sdk.NewInt(100) + +// BetBonusReward is the type for bet bonus rewards calculations +type BetBonusReward struct{} + +// NewBetBonusReward create new object of bet bonus reward calculator type. +func NewBetBonusReward() BetBonusReward { return BetBonusReward{} } + +// ValidateCampaign validates campaign definitions. +func (sur BetBonusReward) ValidateCampaign(campaign Campaign) error { + if campaign.RewardCategory != RewardCategory_REWARD_CATEGORY_BET_DISCOUNT { + return sdkerrors.Wrapf(ErrWrongRewardCategory, "bet bonus rewards can only have single definition") + } + if campaign.RewardAmount.MainAccountAmount.GT(percent) { + return sdkerrors.Wrapf(ErrWrongAmountForType, "bet bonus rewards percent for main account should be between 0 and 100") + } + if campaign.RewardAmount.SubaccountAmount.GT(percent) { + return sdkerrors.Wrapf(ErrWrongAmountForType, "bet bonus rewards percent for sub account should be between 0 and 100") + } + if campaign.RewardAmount.MainAccountAmount.IsZero() && campaign.RewardAmount.SubaccountAmount.IsZero() { + return sdkerrors.Wrapf(ErrWrongAmountForType, "one of main account and sub account percentage should be higher than zero") + } + if campaign.RewardAmountType != RewardAmountType_REWARD_AMOUNT_TYPE_PERCENTAGE { + return sdkerrors.Wrapf(ErrWrongRewardAmountType, "reward amount type not supported for given reward type.") + } + + return nil +} + +// Calculate parses ticket payload and returns the distribution list of bet bonus reward. +func (sur BetBonusReward) Calculate(goCtx context.Context, ctx sdk.Context, keepers RewardFactoryKeepers, + campaign Campaign, ticket, creator string, +) (RewardFactoryData, error) { + var payload GrantBetBonusRewardPayload + if err := keepers.OVMKeeper.VerifyTicketUnmarshal(goCtx, ticket, &payload); err != nil { + return RewardFactoryData{}, sdkerrors.Wrapf(ErrInTicketVerification, "%s", err) + } + + if err := payload.Common.Validate(); err != nil { + return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "%s", err) + } + + addr, err := sdk.AccAddressFromBech32(payload.Common.Receiver) + if err != nil { + return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "%s", err) + } + + if keepers.SubAccountKeeper.IsSubAccount(ctx, addr) { + return RewardFactoryData{}, ErrReceiverAddrCanNotBeSubAcc + } + + subAccountAddressString, err := keepers.getSubAccAddr(ctx, creator, payload.Common.Receiver) + if err != nil { + return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "%s", err) + } + + uid2ID, found := keepers.BetKeeper.GetBetID(ctx, payload.BetUID) + if !found { + return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "bet id not found for uid %s", payload.BetUID) + } + + bet, found := keepers.BetKeeper.GetBet(ctx, payload.Common.Receiver, uid2ID.ID) + if !found { + 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) + + return NewRewardFactoryData( + NewReceiver( + subAccountAddressString, + payload.Common.Receiver, + mainAmount, + subAmount, + campaign.RewardAmount.UnlockPeriod, + ), + payload.Common, + ), nil +} diff --git a/x/reward/types/ticket.pb.go b/x/reward/types/ticket.pb.go index 003e60a8..178c3d0a 100644 --- a/x/reward/types/ticket.pb.go +++ b/x/reward/types/ticket.pb.go @@ -492,6 +492,62 @@ func (m *GrantSignupAffiliatorRewardPayload) GetAffiliatee() string { return "" } +// GrantBetBonusRewardPayload is the type for bet bonus reward +// grant payload. +type GrantBetBonusRewardPayload struct { + // common is the common properties of a reward + Common RewardPayloadCommon `protobuf:"bytes,1,opt,name=common,proto3" json:"common"` + // bet_uid is the list of uids + BetUID string `protobuf:"bytes,2,opt,name=bet_uid,proto3" json:"bet_uid"` +} + +func (m *GrantBetBonusRewardPayload) Reset() { *m = GrantBetBonusRewardPayload{} } +func (m *GrantBetBonusRewardPayload) String() string { return proto.CompactTextString(m) } +func (*GrantBetBonusRewardPayload) ProtoMessage() {} +func (*GrantBetBonusRewardPayload) Descriptor() ([]byte, []int) { + return fileDescriptor_5d710bc1249ca8ae, []int{7} +} +func (m *GrantBetBonusRewardPayload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GrantBetBonusRewardPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GrantBetBonusRewardPayload.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 *GrantBetBonusRewardPayload) XXX_Merge(src proto.Message) { + xxx_messageInfo_GrantBetBonusRewardPayload.Merge(m, src) +} +func (m *GrantBetBonusRewardPayload) XXX_Size() int { + return m.Size() +} +func (m *GrantBetBonusRewardPayload) XXX_DiscardUnknown() { + xxx_messageInfo_GrantBetBonusRewardPayload.DiscardUnknown(m) +} + +var xxx_messageInfo_GrantBetBonusRewardPayload proto.InternalMessageInfo + +func (m *GrantBetBonusRewardPayload) GetCommon() RewardPayloadCommon { + if m != nil { + return m.Common + } + return RewardPayloadCommon{} +} + +func (m *GrantBetBonusRewardPayload) GetBetUID() string { + if m != nil { + return m.BetUID + } + return "" +} + // SetPromoterConfPayload is the payload for the promoter configuration change. type SetPromoterConfPayload struct { Conf PromoterConf `protobuf:"bytes,1,opt,name=conf,proto3" json:"conf"` @@ -501,7 +557,7 @@ func (m *SetPromoterConfPayload) Reset() { *m = SetPromoterConfPayload{} func (m *SetPromoterConfPayload) String() string { return proto.CompactTextString(m) } func (*SetPromoterConfPayload) ProtoMessage() {} func (*SetPromoterConfPayload) Descriptor() ([]byte, []int) { - return fileDescriptor_5d710bc1249ca8ae, []int{7} + return fileDescriptor_5d710bc1249ca8ae, []int{8} } func (m *SetPromoterConfPayload) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -545,55 +601,58 @@ func init() { proto.RegisterType((*GrantSignupRewardPayload)(nil), "sgenetwork.sge.reward.GrantSignupRewardPayload") proto.RegisterType((*GrantSignupReferrerRewardPayload)(nil), "sgenetwork.sge.reward.GrantSignupReferrerRewardPayload") proto.RegisterType((*GrantSignupAffiliatorRewardPayload)(nil), "sgenetwork.sge.reward.GrantSignupAffiliatorRewardPayload") + proto.RegisterType((*GrantBetBonusRewardPayload)(nil), "sgenetwork.sge.reward.GrantBetBonusRewardPayload") proto.RegisterType((*SetPromoterConfPayload)(nil), "sgenetwork.sge.reward.SetPromoterConfPayload") } func init() { proto.RegisterFile("sge/reward/ticket.proto", fileDescriptor_5d710bc1249ca8ae) } var fileDescriptor_5d710bc1249ca8ae = []byte{ - // 662 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0x41, 0x6b, 0xdb, 0x4a, - 0x10, 0xf6, 0x26, 0x8e, 0x2d, 0x8f, 0xdf, 0x7b, 0x3c, 0xf6, 0xc5, 0xaf, 0x4a, 0x02, 0x8a, 0xab, - 0x52, 0xea, 0x16, 0x2a, 0x83, 0x7b, 0x2c, 0x2d, 0xd8, 0x0a, 0x6d, 0x4a, 0x2e, 0x41, 0x49, 0x08, - 0xf4, 0x62, 0x36, 0xab, 0xb5, 0x22, 0x1c, 0x69, 0xc5, 0xee, 0x3a, 0xa9, 0xfe, 0x40, 0x8f, 0xa5, - 0xbf, 0xa9, 0xa7, 0x1c, 0x73, 0x2c, 0x14, 0x42, 0x71, 0x6e, 0xfd, 0x15, 0x45, 0x2b, 0xd9, 0x91, - 0x4b, 0x12, 0x02, 0xa5, 0x27, 0xcd, 0xec, 0x7c, 0xf3, 0x7d, 0x33, 0x3b, 0xa3, 0x85, 0x07, 0x32, - 0x60, 0x5d, 0xc1, 0xce, 0x88, 0xf0, 0xbb, 0x2a, 0xa4, 0x63, 0xa6, 0x9c, 0x44, 0x70, 0xc5, 0x71, - 0x4b, 0x06, 0x2c, 0x66, 0xea, 0x8c, 0x8b, 0xb1, 0x23, 0x03, 0xe6, 0xe4, 0x98, 0xf5, 0xd5, 0x80, - 0x07, 0x5c, 0x23, 0xba, 0x99, 0x95, 0x83, 0xd7, 0x71, 0xc6, 0xa2, 0xd2, 0x84, 0x75, 0xc7, 0x29, - 0x2d, 0xce, 0xca, 0xcc, 0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, - 0xac, 0x78, 0x45, 0xbe, 0xfd, 0x11, 0x41, 0x7b, 0x41, 0x66, 0xc4, 0x84, 0x60, 0xe2, 0x36, 0x39, - 0xf4, 0x7b, 0x72, 0xd8, 0x84, 0xba, 0xc8, 0x24, 0x58, 0x3e, 0xe8, 0x86, 0x37, 0x73, 0xed, 0x4f, - 0x08, 0xec, 0x52, 0x21, 0xfd, 0xd1, 0x28, 0x3c, 0x09, 0x89, 0xe2, 0x7f, 0xac, 0x14, 0x0b, 0x80, - 0x14, 0x22, 0xf3, 0x6a, 0x4a, 0x27, 0xf6, 0x21, 0xfc, 0xbf, 0xc7, 0xd4, 0x6e, 0xb1, 0x53, 0x2e, - 0x8f, 0x47, 0xb3, 0x1a, 0x5e, 0x41, 0x95, 0xf2, 0x78, 0x54, 0x54, 0x70, 0xdb, 0xef, 0x56, 0xce, - 0x2c, 0xa4, 0x75, 0xda, 0xc0, 0x3d, 0x9f, 0x5a, 0xe8, 0x62, 0x6a, 0xa1, 0xef, 0x53, 0x0b, 0x7d, - 0xbe, 0xb2, 0x2a, 0x17, 0x57, 0x56, 0xe5, 0xeb, 0x95, 0x55, 0x79, 0xff, 0x34, 0x08, 0xd5, 0xf1, - 0xe4, 0xc8, 0xa1, 0x3c, 0xea, 0xca, 0x80, 0x3d, 0x2f, 0x58, 0x33, 0xbb, 0xfb, 0x61, 0xfe, 0x7a, - 0xa7, 0x09, 0x93, 0x47, 0x35, 0xfd, 0x90, 0xbe, 0xf8, 0x19, 0x00, 0x00, 0xff, 0xff, 0x57, 0xb2, - 0x0b, 0x5b, 0xd8, 0x05, 0x00, 0x00, + // 698 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0x41, 0x6b, 0xdb, 0x4a, + 0x10, 0xf6, 0x26, 0x8e, 0x2d, 0x8f, 0xdf, 0x7b, 0x3c, 0xf6, 0xc5, 0xaf, 0x8a, 0x03,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+ 0x1e, 0x4c, 0xe4, 0x7d, 0x09, 0x69, 0x43, 0xf1, 0x08, 0x55, 0x66, 0xed, 0x2a, 0xb3, 0x69, 0xbd, + 0xd0, 0x43, 0x95, 0xec, 0xdc, 0x3c, 0x68, 0xcf, 0x0d, 0xeb, 0x10, 0xfe, 0xdf, 0x43, 0xb5, 0x9b, + 0x6e, 0x7b, 0x9f, 0x07, 0xc3, 0xb9, 0xa8, 0x57, 0x90, 0x77, 0x78, 0x30, 0x4c, 0x25, 0xdd, 0xf4, + 0x10, 0x64, 0x33, 0x53, 0x2d, 0x3a, 0xad, 0xd7, 0x3f, 0x9f, 0xd5, 0xc8, 0xc5, 0xac, 0x46, 0x7e, + 0xcc, 0x6a, 0xe4, 0xf3, 0x65, 0x2d, 0x77, 0x71, 0x59, 0xcb, 0x7d, 0xbb, 0xac, 0xe5, 0xde, 0x3f, + 0xf5, 0x7c, 0x75, 0x3c, 0x39, 0x6a, 0x39, 0x7c, 0xdc, 0x96, 0x1e, 0x3e, 0x4f, 0x59, 0x63, 0xbb, + 0xfd, 0x61, 0xf1, 0x5f, 0x89, 0x42, 0x94, 0x47, 0x05, 0xfd, 0xc4, 0xbf, 0xf8, 0x15, 0x00, 0x00, + 0xff, 0xff, 0x36, 0x67, 0x85, 0x1c, 0x72, 0x06, 0x00, 0x00, } func (m *CreateCampaignPayload) Marshal() (dAtA []byte, err error) { @@ -922,6 +981,46 @@ func (m *GrantSignupAffiliatorRewardPayload) MarshalToSizedBuffer(dAtA []byte) ( return len(dAtA) - i, nil } +func (m *GrantBetBonusRewardPayload) 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 *GrantBetBonusRewardPayload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GrantBetBonusRewardPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.BetUID) > 0 { + i -= len(m.BetUID) + copy(dAtA[i:], m.BetUID) + i = encodeVarintTicket(dAtA, i, uint64(len(m.BetUID))) + i-- + dAtA[i] = 0x12 + } + { + size, err := m.Common.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTicket(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func (m *SetPromoterConfPayload) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1102,6 +1201,21 @@ func (m *GrantSignupAffiliatorRewardPayload) Size() (n int) { return n } +func (m *GrantBetBonusRewardPayload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Common.Size() + n += 1 + l + sovTicket(uint64(l)) + l = len(m.BetUID) + if l > 0 { + n += 1 + l + sovTicket(uint64(l)) + } + return n +} + func (m *SetPromoterConfPayload) Size() (n int) { if m == nil { return 0 @@ -2069,6 +2183,121 @@ func (m *GrantSignupAffiliatorRewardPayload) Unmarshal(dAtA []byte) error { } return nil } +func (m *GrantBetBonusRewardPayload) 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 ErrIntOverflowTicket + } + 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: GrantBetBonusRewardPayload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GrantBetBonusRewardPayload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Common", 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 err := m.Common.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BetUID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTicket + } + 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 ErrInvalidLengthTicket + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTicket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.BetUID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTicket(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTicket + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *SetPromoterConfPayload) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 From 918c73395d239af0effa7d8fa55d401ca0ee3f15 Mon Sep 17 00:00:00 2001 From: waaiifu Date: Sat, 9 Mar 2024 14:11:10 +0530 Subject: [PATCH 08/28] Adds main market identifier in bet ticket --- proto/sge/bet/bet.proto | 2 ++ 1 file changed, 2 insertions(+) diff --git a/proto/sge/bet/bet.proto b/proto/sge/bet/bet.proto index a1d41352..144ce543 100644 --- a/proto/sge/bet/bet.proto +++ b/proto/sge/bet/bet.proto @@ -180,4 +180,6 @@ message MetaData { sgenetwork.sge.bet.OddsType selected_odds_type = 1; // selected_odds_value is metadata for bet string selected_odds_value = 2; + // is_main_market will tell weather the bet placed on the main market or not + bool is_main_market = 3; } From 77f9a1b19f58cead58b0b12744b396ccbcd79456 Mon Sep 17 00:00:00 2001 From: waaiifu Date: Sun, 10 Mar 2024 15:49:18 +0530 Subject: [PATCH 09/28] Adds bet pb.go --- x/bet/types/bet.pb.go | 165 ++++++++++++++++++++++++++---------------- 1 file changed, 104 insertions(+), 61 deletions(-) diff --git a/x/bet/types/bet.pb.go b/x/bet/types/bet.pb.go index fe0eee5b..cfde1ab2 100644 --- a/x/bet/types/bet.pb.go +++ b/x/bet/types/bet.pb.go @@ -492,6 +492,8 @@ type MetaData struct { SelectedOddsType OddsType `protobuf:"varint,1,opt,name=selected_odds_type,json=selectedOddsType,proto3,enum=sgenetwork.sge.bet.OddsType" json:"selected_odds_type,omitempty"` // selected_odds_value is metadata for bet SelectedOddsValue string `protobuf:"bytes,2,opt,name=selected_odds_value,json=selectedOddsValue,proto3" json:"selected_odds_value,omitempty"` + // is_main_market will tell weather the bet placed on the main market or not + IsMainMarket bool `protobuf:"varint,3,opt,name=is_main_market,json=isMainMarket,proto3" json:"is_main_market,omitempty"` } func (m *MetaData) Reset() { *m = MetaData{} } @@ -541,6 +543,13 @@ func (m *MetaData) GetSelectedOddsValue() string { return "" } +func (m *MetaData) GetIsMainMarket() bool { + if m != nil { + return m.IsMainMarket + } + return false +} + func init() { proto.RegisterEnum("sgenetwork.sge.bet.Bet_Status", Bet_Status_name, Bet_Status_value) proto.RegisterEnum("sgenetwork.sge.bet.Bet_Result", Bet_Result_name, Bet_Result_value) @@ -555,67 +564,68 @@ func init() { func init() { proto.RegisterFile("sge/bet/bet.proto", fileDescriptor_9bc076bb1a4d9f6e) } var fileDescriptor_9bc076bb1a4d9f6e = []byte{ - // 949 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0x41, 0x6f, 0xe2, 0x46, - 0x14, 0xc6, 0xc0, 0x92, 0xf0, 0x92, 0x10, 0x33, 0xd9, 0xee, 0x5a, 0xe9, 0x2e, 0x20, 0x4b, 0xad, - 0x90, 0xaa, 0x35, 0x12, 0xab, 0xdd, 0x43, 0x7b, 0x29, 0x60, 0xa7, 0xa1, 0x25, 0x40, 0x07, 0x68, - 0xa5, 0x3d, 0xd4, 0x32, 0x78, 0x42, 0xdc, 0xd8, 0x18, 0x79, 0x86, 0x36, 0xf9, 0x03, 0x3d, 0xf7, - 0x27, 0xf4, 0xe7, 0xec, 0x71, 0x8f, 0x55, 0x0f, 0xa8, 0x25, 0xb7, 0x3d, 0xee, 0x2f, 0xa8, 0x66, - 0x3c, 0x10, 0xa3, 0xa6, 0xd9, 0x1c, 0x12, 0x66, 0xbe, 0xf9, 0xbe, 0xef, 0x8d, 0xdf, 0xbc, 0x79, - 0x03, 0x45, 0x3a, 0x25, 0xb5, 0x31, 0x61, 0xfc, 0xcf, 0x98, 0x47, 0x21, 0x0b, 0x11, 0xa2, 0x53, - 0x32, 0x23, 0xec, 0xd7, 0x30, 0xba, 0x34, 0xe8, 0x94, 0x18, 0x63, 0xc2, 0x8e, 0x1f, 0x4f, 0xc3, - 0x69, 0x28, 0x96, 0x6b, 0x7c, 0x14, 0x33, 0x8f, 0x9f, 0xae, 0xc5, 0xa1, 0xeb, 0x52, 0x9b, 0x5d, - 0xcf, 0x49, 0xbc, 0xa0, 0xbf, 0xdf, 0x81, 0x4c, 0x93, 0x30, 0x54, 0x81, 0xcc, 0xc2, 0x73, 0x35, - 0xa5, 0xa2, 0x54, 0xf3, 0xcd, 0xc2, 0x6a, 0x59, 0xce, 0x8c, 0xda, 0xe6, 0xfb, 0x65, 0x99, 0xa3, - 0x98, 0xff, 0x43, 0x5f, 0x01, 0x04, 0x4e, 0x74, 0x49, 0x98, 0xcd, 0x89, 0x69, 0x41, 0xfc, 0x74, - 0xb5, 0x2c, 0xe7, 0xcf, 0x04, 0x1a, 0xd3, 0x13, 0x14, 0x9c, 0x18, 0xa3, 0x97, 0xb0, 0x2b, 0x22, - 0x73, 0x69, 0x46, 0x48, 0x9f, 0xae, 0x96, 0xe5, 0x9d, 0x9e, 0xeb, 0xd2, 0x58, 0xb8, 0x59, 0xc6, - 0x9b, 0x11, 0x7a, 0x0e, 0x20, 0xc6, 0xbf, 0x38, 0xfe, 0x82, 0x68, 0x8f, 0xb8, 0x0c, 0xe7, 0x39, - 0xf2, 0x03, 0x07, 0xd0, 0x2b, 0xc8, 0x39, 0x41, 0xb8, 0x98, 0x31, 0x2d, 0x27, 0x1c, 0x9f, 0xbf, - 0x5d, 0x96, 0x53, 0x7f, 0x2d, 0xcb, 0x9f, 0x4c, 0x42, 0x1a, 0x84, 0x94, 0xba, 0x97, 0x86, 0x17, - 0xd6, 0x02, 0x87, 0x5d, 0x18, 0xed, 0x19, 0xc3, 0x92, 0x8c, 0x6a, 0x90, 0x39, 0x27, 0x44, 0xdb, - 0x79, 0x88, 0x86, 0x33, 0xd1, 0x6b, 0xc8, 0x51, 0xe6, 0xb0, 0x05, 0xd5, 0x76, 0x2b, 0x4a, 0xb5, - 0x50, 0x2f, 0x19, 0xff, 0x4d, 0xbb, 0xd1, 0x24, 0xcc, 0x18, 0x08, 0x16, 0x96, 0x6c, 0xae, 0x8b, - 0x08, 0x5d, 0xf8, 0x4c, 0xcb, 0xdf, 0xaf, 0xc3, 0x82, 0x85, 0x25, 0x1b, 0x69, 0xb0, 0x33, 0x89, - 0x88, 0xc3, 0xc2, 0x48, 0x03, 0xf1, 0xcd, 0xeb, 0x29, 0x4f, 0x88, 0x18, 0x12, 0xd7, 0x76, 0x98, - 0xb6, 0x57, 0x51, 0xaa, 0x19, 0x9c, 0x97, 0x48, 0x83, 0xa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x4a, 0xa9, 0x3f, 0x6f, 0x4a, - 0xa9, 0x37, 0xc9, 0x06, 0x46, 0xa7, 0xe4, 0x85, 0xdc, 0x04, 0x1f, 0xd7, 0xae, 0xc4, 0x83, 0x28, - 0x9a, 0xd8, 0x38, 0x27, 0x5e, 0xc3, 0x97, 0xff, 0x06, 0x00, 0x00, 0xff, 0xff, 0xa8, 0x4e, 0x5a, - 0xf7, 0x65, 0x07, 0x00, 0x00, + // 973 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0xdd, 0x6e, 0x1b, 0x45, + 0x14, 0xce, 0xda, 0xae, 0x13, 0x9f, 0x24, 0x8e, 0x3d, 0x29, 0xed, 0x2a, 0xb4, 0xb6, 0xb5, 0x02, + 0x14, 0x09, 0x75, 0x2d, 0xa5, 0x6a, 0x2f, 0xe0, 0x06, 0x3b, 0xbb, 0x25, 0x06, 0xc7, 0x09, 0x63, + 0x1b, 0xa4, 0x5e, 0xb0, 0x1a, 0x7b, 0x27, 0xce, 0x92, 0xfd, 0xb1, 0x76, 0xc6, 0x90, 0xbc, 0x05, + 0x8f, 0xc0, 0x03, 0xf0, 0x20, 0xbd, 0xec, 0x25, 0xe2, 0xc2, 0x02, 0xe7, 0xae, 0x97, 0x7d, 0x02, + 0x34, 0x3f, 0x4e, 0xd6, 0x22, 0x94, 0x5c, 0x24, 0x9e, 0xf9, 0xe6, 0xfb, 0xbe, 0x99, 0x3d, 0x73, + 0xe6, 0x1c, 0xa8, 0xb2, 0x09, 0x6d, 0x8e, 0x28, 0x17, 0x7f, 0xf6, 0x34, 0x4d, 0x78, 0x82, 0x10, + 0x9b, 0xd0, 0x98, 0xf2, 0x5f, 0x92, 0xf4, 0xc2, 0x66, 0x13, 0x6a, 0x8f, 0x28, 0xdf, 0x7b, 0x38, + 0x49, 0x26, 0x89, 0x5c, 0x6e, 0x8a, 0x91, 0x62, 0xee, 0x3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, 0xfb, 0x07, 0x57, 0x53, 0x2a, 0x6a, 0x93, 0xd2, 0x2d, 0x11, 0x64, 0xc3, 0xee, 0xaa, + 0x97, 0xea, 0x00, 0xea, 0xa2, 0xab, 0x59, 0xba, 0xea, 0x04, 0x9f, 0x40, 0x39, 0x60, 0x5e, 0x44, + 0x82, 0xd8, 0x53, 0x3d, 0x47, 0xc6, 0x6e, 0x03, 0x6f, 0x05, 0xec, 0x98, 0x04, 0xb1, 0x6a, 0x50, + 0xed, 0xaf, 0xde, 0x2c, 0x6a, 0xc6, 0xdb, 0x45, 0xcd, 0xf8, 0x6b, 0x51, 0x33, 0x7e, 0xbd, 0xae, + 0xad, 0xbd, 0xbd, 0xae, 0xad, 0xfd, 0x71, 0x5d, 0x5b, 0x7b, 0x9d, 0x2d, 0x73, 0x6c, 0x42, 0x9f, + 0xe9, 0xa3, 0x8a, 0x71, 0xf3, 0x52, 0xb6, 0x4d, 0x59, 0xea, 0x46, 0x45, 0xd9, 0x33, 0x9f, 0xff, + 0x13, 0x00, 0x00, 0xff, 0xff, 0x99, 0x7a, 0x48, 0xed, 0x8b, 0x07, 0x00, 0x00, } func (m *Bet) Marshal() (dAtA []byte, err error) { @@ -934,6 +944,16 @@ func (m *MetaData) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.IsMainMarket { + i-- + if m.IsMainMarket { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x18 + } if len(m.SelectedOddsValue) > 0 { i -= len(m.SelectedOddsValue) copy(dAtA[i:], m.SelectedOddsValue) @@ -1098,6 +1118,9 @@ func (m *MetaData) Size() (n int) { if l > 0 { n += 1 + l + sovBet(uint64(l)) } + if m.IsMainMarket { + n += 2 + } return n } @@ -2140,6 +2163,26 @@ func (m *MetaData) Unmarshal(dAtA []byte) error { } m.SelectedOddsValue = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IsMainMarket", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowBet + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.IsMainMarket = bool(v != 0) default: iNdEx = preIndex skippy, err := skipBet(dAtA[iNdEx:]) From 9e7de9c5cddb35d82c67a5d64a8177015ecf429e Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Wed, 20 Mar 2024 21:00:21 +0300 Subject: [PATCH 10/28] feat: promoter transactions and queries and upgrade handler --- app/app.go | 2 + app/upgrades/v8/consts.go | 19 + app/upgrades/v8/upgrades.go | 52 ++ proto/sge/reward/query.proto | 34 + proto/sge/reward/ticket.proto | 11 + proto/sge/reward/tx.proto | 13 + x/reward/client/cli/query.go | 2 + x/reward/client/cli/query_promoter.go | 75 ++ x/reward/client/cli/tx.go | 1 + x/reward/client/cli/tx_promoter.go | 30 + x/reward/keeper/msg_server_promoter.go | 30 + x/reward/keeper/query_promoter.go | 64 ++ x/reward/types/messages_promoter.go | 56 ++ x/reward/types/promoter.go | 20 + x/reward/types/query.pb.go | 1086 +++++++++++++++++++++--- x/reward/types/query.pb.gw.go | 184 ++++ x/reward/types/ticket.go | 27 +- x/reward/types/ticket.pb.go | 319 ++++++- x/reward/types/tx.pb.go | 470 +++++++++- 19 files changed, 2278 insertions(+), 217 deletions(-) create mode 100644 app/upgrades/v8/consts.go create mode 100644 app/upgrades/v8/upgrades.go create mode 100644 x/reward/client/cli/query_promoter.go create mode 100644 x/reward/keeper/query_promoter.go create mode 100644 x/reward/types/promoter.go diff --git a/app/app.go b/app/app.go index c6b50680..cadf7eb3 100644 --- a/app/app.go +++ b/app/app.go @@ -45,6 +45,7 @@ import ( v5 "github.com/sge-network/sge/app/upgrades/v5" v6 "github.com/sge-network/sge/app/upgrades/v6" v7 "github.com/sge-network/sge/app/upgrades/v7" + v8 "github.com/sge-network/sge/app/upgrades/v8" abci "github.com/tendermint/tendermint/abci/types" tmjson "github.com/tendermint/tendermint/libs/json" @@ -82,6 +83,7 @@ var ( v5.Upgrade, v6.Upgrade, v7.Upgrade, + v8.Upgrade, } ) diff --git a/app/upgrades/v8/consts.go b/app/upgrades/v8/consts.go new file mode 100644 index 00000000..585c935f --- /dev/null +++ b/app/upgrades/v8/consts.go @@ -0,0 +1,19 @@ +package v8 + +import ( + store "github.com/cosmos/cosmos-sdk/store/types" + + "github.com/sge-network/sge/app/upgrades" +) + +// UpgradeName defines the on-chain upgrade name for the v1.6.0 upgrade. +const UpgradeName = "v1.6.0" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: UpgradeName, + CreateUpgradeHandler: CreateUpgradeHandler, + StoreUpgrades: store.StoreUpgrades{ + Added: []string{}, + Deleted: []string{}, + }, +} diff --git a/app/upgrades/v8/upgrades.go b/app/upgrades/v8/upgrades.go new file mode 100644 index 00000000..41a912c5 --- /dev/null +++ b/app/upgrades/v8/upgrades.go @@ -0,0 +1,52 @@ +package v8 + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/google/uuid" + "github.com/sge-network/sge/app/keepers" + "github.com/sge-network/sge/x/reward/types" +) + +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + k *keepers.AppKeepers, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + allCampaigns := k.RewardKeeper.GetAllCampaign(ctx) + promoters := make(map[string]struct{}) + for _, c := range allCampaigns { + c.CapCount = 0 // infinite cap for all campaigns + k.RewardKeeper.SetCampaign(ctx, c) + promoters[c.Promoter] = struct{}{} + } + + promoterAddresses := []string{} + for addr := range promoters { + promoterAddresses = append(promoterAddresses, addr) + } + + promoterUID := uuid.NewString() + k.RewardKeeper.SetPromoter(ctx, types.Promoter{ + Creator: promoterAddresses[0], + UID: promoterUID, + Addresses: promoterAddresses, + Conf: types.PromoterConf{ + CategoryCap: []types.CategoryCap{ + {Category: types.RewardCategory_REWARD_CATEGORY_SIGNUP, CapPerAcc: 1}, + }, + }, + }) + + for _, addr := range promoterAddresses { + k.RewardKeeper.SetPromoterByAddress(ctx, types.PromoterByAddress{ + PromoterUID: promoterUID, + Address: addr, + }) + } + + return mm.RunMigrations(ctx, configurator, fromVM) + } +} diff --git a/proto/sge/reward/query.proto b/proto/sge/reward/query.proto index 12921ea4..f1dcb6fe 100644 --- a/proto/sge/reward/query.proto +++ b/proto/sge/reward/query.proto @@ -8,6 +8,7 @@ import "cosmos/base/query/v1beta1/pagination.proto"; import "sge/reward/params.proto"; import "sge/reward/campaign.proto"; import "sge/reward/reward.proto"; +import "sge/reward/promoter.proto"; option go_package = "github.com/sge-network/sge/x/reward/types"; @@ -19,6 +20,16 @@ service Query { option (google.api.http).get = "/sge-network/sge/reward/params"; } + // PromoterByAddress queries a certain promoter. + rpc PromoterByAddress(QueryPromoterByAddressRequest) returns (QueryPromoterByAddressResponse) { + option (google.api.http).get = "/sge-network/sge/reward/promoter-by-address/{addr}"; + } + + // Queries list of all Promoter items. + rpc Promoters(QueryPromotersRequest) returns (QueryPromotersResponse) { + option (google.api.http).get = "/sge-network/sge/reward/promoters"; + } + // Queries a specific Campaign item. rpc Campaign(QueryCampaignRequest) returns (QueryCampaignResponse) { option (google.api.http).get = "/sge-network/sge/reward/campaign/{uid}"; @@ -70,6 +81,29 @@ message QueryParamsResponse { Params params = 1 [ (gogoproto.nullable) = false ]; } +// QueryPromoterByAddressRequest is request type for the Query/GetPromoterByAddress RPC method. +message QueryPromoterByAddressRequest { + string addr = 1; +} + +// QueryPromoterByAddressResponse is response type for the Query/GetPromoterByAddress RPC method. +message QueryPromoterByAddressResponse { + // promoter holds the queries promoter. + Promoter promoter = 1 [ (gogoproto.nullable) = false ]; +} + +// QueryPromotersRequest is request body for the query all promoters endpoint. +message QueryPromotersRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + +// QueryPromotersResponse is response body of the query all promoters +// endpoint. +message QueryPromotersResponse { + repeated Promoter promoter = 1 [ (gogoproto.nullable) = false ]; + cosmos.base.query.v1beta1.PageResponse pagination = 2; +} + // QueryCampaignRequest is request body of the query campaign endpoint. message QueryCampaignRequest { string uid = 1; } diff --git a/proto/sge/reward/ticket.proto b/proto/sge/reward/ticket.proto index 9f92b0f7..9dea2dab 100644 --- a/proto/sge/reward/ticket.proto +++ b/proto/sge/reward/ticket.proto @@ -125,6 +125,17 @@ message GrantBetBonusRewardPayload { ]; } +// CreatePromoterPayload is the payload for the promoter create. +message CreatePromoterPayload { + // uid is the uid of the promoter to be created + string uid = 1 [ + (gogoproto.customname) = "UID", + (gogoproto.jsontag) = "uid", + json_name = "uid" + ]; + PromoterConf conf = 2 [ (gogoproto.nullable) = false ]; +} + // SetPromoterConfPayload is the payload for the promoter configuration change. message SetPromoterConfPayload { PromoterConf conf = 1 [ (gogoproto.nullable) = false ]; diff --git a/proto/sge/reward/tx.proto b/proto/sge/reward/tx.proto index a7760dab..03f4e63f 100644 --- a/proto/sge/reward/tx.proto +++ b/proto/sge/reward/tx.proto @@ -10,6 +10,8 @@ option go_package = "github.com/sge-network/sge/x/reward/types"; service Msg { // SetPromoterConf is a method to set the configurations of a promoter. rpc SetPromoterConf(MsgSetPromoterConf) returns (MsgSetPromoterConfResponse); + // CreatePromoter is a method to create a promoter + rpc CreatePromoter(MsgCreatePromoter) returns (MsgCreatePromoterResponse); // CreateCampaign is a method to create a campaign rpc CreateCampaign(MsgCreateCampaign) returns (MsgCreateCampaignResponse); // UpdateCampaign is a method to update campaign @@ -20,6 +22,17 @@ service Msg { rpc GrantReward(MsgGrantReward) returns (MsgGrantRewardResponse); } +// MsgCreatePromoter is msg to create a promoter. +message MsgCreatePromoter { + // creator is the address of message signer account. + string creator = 1; + // ticket is the payload data. + string ticket = 2; +} + +// MsgCreatePromoterResponse promoter create message response type. +message MsgCreatePromoterResponse {} + // MsgSetPromoterConf is msg to set promoter configuration. message MsgSetPromoterConf { // creator is the address of message signer account. diff --git a/x/reward/client/cli/query.go b/x/reward/client/cli/query.go index 60a26fad..d8dd719a 100644 --- a/x/reward/client/cli/query.go +++ b/x/reward/client/cli/query.go @@ -22,6 +22,8 @@ func GetQueryCmd(_ string) *cobra.Command { } cmd.AddCommand(CmdQueryParams()) + cmd.AddCommand(CmdListPromoters()) + cmd.AddCommand(CmdGetPromoterByAddress()) cmd.AddCommand(CmdListCampaign()) cmd.AddCommand(CmdGetCampaign()) cmd.AddCommand(CmdListReward()) diff --git a/x/reward/client/cli/query_promoter.go b/x/reward/client/cli/query_promoter.go new file mode 100644 index 00000000..426fb77b --- /dev/null +++ b/x/reward/client/cli/query_promoter.go @@ -0,0 +1,75 @@ +package cli + +import ( + "context" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + + "github.com/sge-network/sge/x/reward/types" +) + +func CmdListPromoters() *cobra.Command { + cmd := &cobra.Command{ + Use: "promoters", + Short: "list all promoters", + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + pageReq, err := client.ReadPageRequest(cmd.Flags()) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryPromotersRequest{ + Pagination: pageReq, + } + + res, err := queryClient.Promoters(context.Background(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddPaginationFlagsToCmd(cmd, cmd.Use) + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdGetPromoterByAddress() *cobra.Command { + cmd := &cobra.Command{ + Use: "promoter-by-address [addr]", + Short: "shows a promoter by its address", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + argAddress := args[0] + + params := &types.QueryPromoterByAddressRequest{ + Addr: argAddress, + } + + res, err := queryClient.PromoterByAddress(context.Background(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/reward/client/cli/tx.go b/x/reward/client/cli/tx.go index f4aec33a..ed1a3ef8 100644 --- a/x/reward/client/cli/tx.go +++ b/x/reward/client/cli/tx.go @@ -24,6 +24,7 @@ func GetTxCmd() *cobra.Command { RunE: client.ValidateCmd, } + cmd.AddCommand(CmdCreatePromoter()) cmd.AddCommand(CmdSetPromoterConf()) cmd.AddCommand(CmdCreateCampaign()) cmd.AddCommand(CmdUpdateCampaign()) diff --git a/x/reward/client/cli/tx_promoter.go b/x/reward/client/cli/tx_promoter.go index be0286fe..89ed2d70 100644 --- a/x/reward/client/cli/tx_promoter.go +++ b/x/reward/client/cli/tx_promoter.go @@ -10,6 +10,36 @@ import ( "github.com/sge-network/sge/x/reward/types" ) +func CmdCreatePromoter() *cobra.Command { + cmd := &cobra.Command{ + Use: "create-promoter [ticket]", + Short: "Create a new promoter", + Long: "Creating a new promoter with certain configurations the ticket", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + // Get value arguments + argTicket := args[0] + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + msg := types.NewMsgCreatePromoter( + clientCtx.GetFromAddress().String(), + argTicket, + ) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} func CmdSetPromoterConf() *cobra.Command { cmd := &cobra.Command{ Use: "set-promoter-conf [uid] [ticket]", diff --git a/x/reward/keeper/msg_server_promoter.go b/x/reward/keeper/msg_server_promoter.go index 9fcaa4bb..2126c2ed 100644 --- a/x/reward/keeper/msg_server_promoter.go +++ b/x/reward/keeper/msg_server_promoter.go @@ -9,6 +9,36 @@ import ( "github.com/sge-network/sge/x/reward/types" ) +func (k msgServer) CreatePromoter(goCtx context.Context, msg *types.MsgCreatePromoter) (*types.MsgCreatePromoterResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + var payload types.CreatePromoterPayload + if err := k.ovmKeeper.VerifyTicketUnmarshal(goCtx, msg.Ticket, &payload); err != nil { + return nil, sdkerrors.Wrapf(types.ErrInTicketVerification, "%s", err) + } + + // Check if the value already exists + _, isFound := k.GetPromoter(ctx, payload.UID) + if isFound { + return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "promoter with the uid: %s already exists", payload.UID) + } + + if err := payload.Validate(); err != nil { + return nil, err + } + + k.SetPromoter(ctx, types.Promoter{ + Creator: msg.Creator, + Addresses: []string{msg.Creator}, + UID: payload.UID, + Conf: payload.Conf, + }) + + msg.EmitEvent(&ctx, payload.UID, payload.Conf) + + return &types.MsgCreatePromoterResponse{}, nil +} + func (k msgServer) SetPromoterConf(goCtx context.Context, msg *types.MsgSetPromoterConf) (*types.MsgSetPromoterConfResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) diff --git a/x/reward/keeper/query_promoter.go b/x/reward/keeper/query_promoter.go new file mode 100644 index 00000000..dfedf679 --- /dev/null +++ b/x/reward/keeper/query_promoter.go @@ -0,0 +1,64 @@ +package keeper + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" + "github.com/sge-network/sge/x/reward/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (k Keeper) Promoters(goCtx context.Context, req *types.QueryPromotersRequest) (*types.QueryPromotersResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + var promoters []types.Promoter + ctx := sdk.UnwrapSDKContext(goCtx) + + store := ctx.KVStore(k.storeKey) + promoterStore := prefix.NewStore(store, types.PromoterKeyPrefix) + + pageRes, err := query.Paginate(promoterStore, req.Pagination, func(key []byte, value []byte) error { + var promoter types.Promoter + if err := k.cdc.Unmarshal(value, &promoter); err != nil { + return err + } + + promoters = append(promoters, promoter) + return nil + }) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + return &types.QueryPromotersResponse{Promoter: promoters, Pagination: pageRes}, nil +} + +func (k Keeper) PromoterByAddress(goCtx context.Context, req *types.QueryPromoterByAddressRequest) (*types.QueryPromoterByAddressResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(goCtx) + + promoterByAddress, found := k.GetPromoterByAddress( + ctx, + req.Addr, + ) + if !found { + return nil, status.Error(codes.NotFound, "promoter with the provided address not found") + } + + promoter, found := k.GetPromoter( + ctx, + promoterByAddress.PromoterUID, + ) + if !found { + return nil, status.Error(codes.NotFound, "promoter with the provided uid found") + } + + return &types.QueryPromoterByAddressResponse{Promoter: promoter}, nil +} diff --git a/x/reward/types/messages_promoter.go b/x/reward/types/messages_promoter.go index 3de553e5..96e8c131 100644 --- a/x/reward/types/messages_promoter.go +++ b/x/reward/types/messages_promoter.go @@ -10,9 +10,11 @@ import ( const ( TypeMsgSetPromoterConf = "set_promoter_conf" + TypeMsgCreatePromoter = "create_promoter" ) var _ sdk.Msg = &MsgSetPromoterConf{} +var _ sdk.Msg = &MsgCreatePromoter{} func NewMsgSetPromoterConfig( creator string, @@ -73,3 +75,57 @@ func (msg *MsgSetPromoterConf) EmitEvent(ctx *sdk.Context, conf PromoterConf) { ) emitter.Emit() } + +func NewMsgCreatePromoter( + creator string, + ticket string, +) *MsgCreatePromoter { + return &MsgCreatePromoter{ + Creator: creator, + Ticket: ticket, + } +} + +func (msg *MsgCreatePromoter) Route() string { + return RouterKey +} + +func (msg *MsgCreatePromoter) Type() string { + return TypeMsgCreatePromoter +} + +func (msg *MsgCreatePromoter) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgCreatePromoter) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgCreatePromoter) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "invalid creator address (%s)", err) + } + + if msg.Ticket == "" { + return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "invalid ticket") + } + + return nil +} + +// EmitEvent emits the event for the message success. +func (msg *MsgCreatePromoter) EmitEvent(ctx *sdk.Context, uid string, conf PromoterConf) { + emitter := utils.NewEventEmitter(ctx, attributeValueCategory) + emitter.AddMsg(TypeMsgCreatePromoter, msg.Creator, + sdk.NewAttribute(attributeKeyUID, uid), + sdk.NewAttribute(attributeKeyPromoterConf, conf.String()), + ) + emitter.Emit() +} diff --git a/x/reward/types/promoter.go b/x/reward/types/promoter.go new file mode 100644 index 00000000..91876b1e --- /dev/null +++ b/x/reward/types/promoter.go @@ -0,0 +1,20 @@ +package types + +import sdkerrors "cosmossdk.io/errors" + +func (cf *PromoterConf) Validate() error { + catMap := make(map[RewardCategory]struct{}) + for _, v := range cf.CategoryCap { + _, ok := catMap[v.Category] + if ok { + return sdkerrors.Wrapf(ErrDuplicateCategoryInConf, "%s", v.Category) + } + if v.CapPerAcc <= 0 { + return sdkerrors.Wrapf(ErrCategoryCapShouldBePos, "%s", v.Category) + } + + catMap[v.Category] = struct{}{} + } + + return nil +} diff --git a/x/reward/types/query.pb.go b/x/reward/types/query.pb.go index b7a3cc6b..40424699 100644 --- a/x/reward/types/query.pb.go +++ b/x/reward/types/query.pb.go @@ -113,6 +113,196 @@ func (m *QueryParamsResponse) GetParams() Params { return Params{} } +// QueryPromoterByAddressRequest is request type for the Query/GetPromoterByAddress RPC method. +type QueryPromoterByAddressRequest struct { + Addr string `protobuf:"bytes,1,opt,name=addr,proto3" json:"addr,omitempty"` +} + +func (m *QueryPromoterByAddressRequest) Reset() { *m = QueryPromoterByAddressRequest{} } +func (m *QueryPromoterByAddressRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPromoterByAddressRequest) ProtoMessage() {} +func (*QueryPromoterByAddressRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_324afa5f2186a8c0, []int{2} +} +func (m *QueryPromoterByAddressRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPromoterByAddressRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPromoterByAddressRequest.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 *QueryPromoterByAddressRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPromoterByAddressRequest.Merge(m, src) +} +func (m *QueryPromoterByAddressRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPromoterByAddressRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPromoterByAddressRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPromoterByAddressRequest proto.InternalMessageInfo + +func (m *QueryPromoterByAddressRequest) GetAddr() string { + if m != nil { + return m.Addr + } + return "" +} + +// QueryPromoterByAddressResponse is response type for the Query/GetPromoterByAddress RPC method. +type QueryPromoterByAddressResponse struct { + // promoter holds the queries promoter. + Promoter Promoter `protobuf:"bytes,1,opt,name=promoter,proto3" json:"promoter"` +} + +func (m *QueryPromoterByAddressResponse) Reset() { *m = QueryPromoterByAddressResponse{} } +func (m *QueryPromoterByAddressResponse) String() string { return proto.CompactTextString(m) } +func (*QueryPromoterByAddressResponse) ProtoMessage() {} +func (*QueryPromoterByAddressResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_324afa5f2186a8c0, []int{3} +} +func (m *QueryPromoterByAddressResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPromoterByAddressResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPromoterByAddressResponse.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 *QueryPromoterByAddressResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPromoterByAddressResponse.Merge(m, src) +} +func (m *QueryPromoterByAddressResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryPromoterByAddressResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPromoterByAddressResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPromoterByAddressResponse proto.InternalMessageInfo + +func (m *QueryPromoterByAddressResponse) GetPromoter() Promoter { + if m != nil { + return m.Promoter + } + return Promoter{} +} + +// QueryPromotersRequest is request body for the query all promoters endpoint. +type QueryPromotersRequest struct { + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryPromotersRequest) Reset() { *m = QueryPromotersRequest{} } +func (m *QueryPromotersRequest) String() string { return proto.CompactTextString(m) } +func (*QueryPromotersRequest) ProtoMessage() {} +func (*QueryPromotersRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_324afa5f2186a8c0, []int{4} +} +func (m *QueryPromotersRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPromotersRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPromotersRequest.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 *QueryPromotersRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPromotersRequest.Merge(m, src) +} +func (m *QueryPromotersRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryPromotersRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPromotersRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPromotersRequest proto.InternalMessageInfo + +func (m *QueryPromotersRequest) GetPagination() *query.PageRequest { + if m != nil { + return m.Pagination + } + return nil +} + +// QueryPromotersResponse is response body of the query all promoters +// endpoint. +type QueryPromotersResponse struct { + Promoter []Promoter `protobuf:"bytes,1,rep,name=promoter,proto3" json:"promoter"` + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryPromotersResponse) Reset() { *m = QueryPromotersResponse{} } +func (m *QueryPromotersResponse) String() string { return proto.CompactTextString(m) } +func (*QueryPromotersResponse) ProtoMessage() {} +func (*QueryPromotersResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_324afa5f2186a8c0, []int{5} +} +func (m *QueryPromotersResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryPromotersResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryPromotersResponse.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 *QueryPromotersResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryPromotersResponse.Merge(m, src) +} +func (m *QueryPromotersResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryPromotersResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryPromotersResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryPromotersResponse proto.InternalMessageInfo + +func (m *QueryPromotersResponse) GetPromoter() []Promoter { + if m != nil { + return m.Promoter + } + return nil +} + +func (m *QueryPromotersResponse) GetPagination() *query.PageResponse { + if m != nil { + return m.Pagination + } + return nil +} + // QueryCampaignRequest is request body of the query campaign endpoint. type QueryCampaignRequest struct { Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid,omitempty"` @@ -122,7 +312,7 @@ func (m *QueryCampaignRequest) Reset() { *m = QueryCampaignRequest{} } func (m *QueryCampaignRequest) String() string { return proto.CompactTextString(m) } func (*QueryCampaignRequest) ProtoMessage() {} func (*QueryCampaignRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_324afa5f2186a8c0, []int{2} + return fileDescriptor_324afa5f2186a8c0, []int{6} } func (m *QueryCampaignRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -167,7 +357,7 @@ func (m *QueryCampaignResponse) Reset() { *m = QueryCampaignResponse{} } func (m *QueryCampaignResponse) String() string { return proto.CompactTextString(m) } func (*QueryCampaignResponse) ProtoMessage() {} func (*QueryCampaignResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_324afa5f2186a8c0, []int{3} + return fileDescriptor_324afa5f2186a8c0, []int{7} } func (m *QueryCampaignResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -212,7 +402,7 @@ func (m *QueryCampaignsRequest) Reset() { *m = QueryCampaignsRequest{} } func (m *QueryCampaignsRequest) String() string { return proto.CompactTextString(m) } func (*QueryCampaignsRequest) ProtoMessage() {} func (*QueryCampaignsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_324afa5f2186a8c0, []int{4} + return fileDescriptor_324afa5f2186a8c0, []int{8} } func (m *QueryCampaignsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -259,7 +449,7 @@ func (m *QueryCampaignsResponse) Reset() { *m = QueryCampaignsResponse{} func (m *QueryCampaignsResponse) String() string { return proto.CompactTextString(m) } func (*QueryCampaignsResponse) ProtoMessage() {} func (*QueryCampaignsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_324afa5f2186a8c0, []int{5} + return fileDescriptor_324afa5f2186a8c0, []int{9} } func (m *QueryCampaignsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -311,7 +501,7 @@ func (m *QueryRewardRequest) Reset() { *m = QueryRewardRequest{} } func (m *QueryRewardRequest) String() string { return proto.CompactTextString(m) } func (*QueryRewardRequest) ProtoMessage() {} func (*QueryRewardRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_324afa5f2186a8c0, []int{6} + return fileDescriptor_324afa5f2186a8c0, []int{10} } func (m *QueryRewardRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -356,7 +546,7 @@ func (m *QueryRewardResponse) Reset() { *m = QueryRewardResponse{} } func (m *QueryRewardResponse) String() string { return proto.CompactTextString(m) } func (*QueryRewardResponse) ProtoMessage() {} func (*QueryRewardResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_324afa5f2186a8c0, []int{7} + return fileDescriptor_324afa5f2186a8c0, []int{11} } func (m *QueryRewardResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -401,7 +591,7 @@ func (m *QueryRewardsRequest) Reset() { *m = QueryRewardsRequest{} } func (m *QueryRewardsRequest) String() string { return proto.CompactTextString(m) } func (*QueryRewardsRequest) ProtoMessage() {} func (*QueryRewardsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_324afa5f2186a8c0, []int{8} + return fileDescriptor_324afa5f2186a8c0, []int{12} } func (m *QueryRewardsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -447,7 +637,7 @@ func (m *QueryRewardsResponse) Reset() { *m = QueryRewardsResponse{} } func (m *QueryRewardsResponse) String() string { return proto.CompactTextString(m) } func (*QueryRewardsResponse) ProtoMessage() {} func (*QueryRewardsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_324afa5f2186a8c0, []int{9} + return fileDescriptor_324afa5f2186a8c0, []int{13} } func (m *QueryRewardsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -502,7 +692,7 @@ func (m *QueryRewardsByAddressRequest) Reset() { *m = QueryRewardsByAddr func (m *QueryRewardsByAddressRequest) String() string { return proto.CompactTextString(m) } func (*QueryRewardsByAddressRequest) ProtoMessage() {} func (*QueryRewardsByAddressRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_324afa5f2186a8c0, []int{10} + return fileDescriptor_324afa5f2186a8c0, []int{14} } func (m *QueryRewardsByAddressRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -563,7 +753,7 @@ func (m *QueryRewardsByAddressResponse) Reset() { *m = QueryRewardsByAdd func (m *QueryRewardsByAddressResponse) String() string { return proto.CompactTextString(m) } func (*QueryRewardsByAddressResponse) ProtoMessage() {} func (*QueryRewardsByAddressResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_324afa5f2186a8c0, []int{11} + return fileDescriptor_324afa5f2186a8c0, []int{15} } func (m *QueryRewardsByAddressResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -621,7 +811,7 @@ func (m *QueryRewardsByAddressAndCategoryRequest) Reset() { func (m *QueryRewardsByAddressAndCategoryRequest) String() string { return proto.CompactTextString(m) } func (*QueryRewardsByAddressAndCategoryRequest) ProtoMessage() {} func (*QueryRewardsByAddressAndCategoryRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_324afa5f2186a8c0, []int{12} + return fileDescriptor_324afa5f2186a8c0, []int{16} } func (m *QueryRewardsByAddressAndCategoryRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -691,7 +881,7 @@ func (m *QueryRewardsByAddressAndCategoryResponse) Reset() { func (m *QueryRewardsByAddressAndCategoryResponse) String() string { return proto.CompactTextString(m) } func (*QueryRewardsByAddressAndCategoryResponse) ProtoMessage() {} func (*QueryRewardsByAddressAndCategoryResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_324afa5f2186a8c0, []int{13} + return fileDescriptor_324afa5f2186a8c0, []int{17} } func (m *QueryRewardsByAddressAndCategoryResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -745,7 +935,7 @@ func (m *QueryRewardsByCampaignRequest) Reset() { *m = QueryRewardsByCam func (m *QueryRewardsByCampaignRequest) String() string { return proto.CompactTextString(m) } func (*QueryRewardsByCampaignRequest) ProtoMessage() {} func (*QueryRewardsByCampaignRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_324afa5f2186a8c0, []int{14} + return fileDescriptor_324afa5f2186a8c0, []int{18} } func (m *QueryRewardsByCampaignRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -799,7 +989,7 @@ func (m *QueryRewardsByCampaignResponse) Reset() { *m = QueryRewardsByCa func (m *QueryRewardsByCampaignResponse) String() string { return proto.CompactTextString(m) } func (*QueryRewardsByCampaignResponse) ProtoMessage() {} func (*QueryRewardsByCampaignResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_324afa5f2186a8c0, []int{15} + return fileDescriptor_324afa5f2186a8c0, []int{19} } func (m *QueryRewardsByCampaignResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -845,6 +1035,10 @@ func (m *QueryRewardsByCampaignResponse) GetPagination() *query.PageResponse { func init() { proto.RegisterType((*QueryParamsRequest)(nil), "sgenetwork.sge.reward.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "sgenetwork.sge.reward.QueryParamsResponse") + proto.RegisterType((*QueryPromoterByAddressRequest)(nil), "sgenetwork.sge.reward.QueryPromoterByAddressRequest") + proto.RegisterType((*QueryPromoterByAddressResponse)(nil), "sgenetwork.sge.reward.QueryPromoterByAddressResponse") + proto.RegisterType((*QueryPromotersRequest)(nil), "sgenetwork.sge.reward.QueryPromotersRequest") + proto.RegisterType((*QueryPromotersResponse)(nil), "sgenetwork.sge.reward.QueryPromotersResponse") proto.RegisterType((*QueryCampaignRequest)(nil), "sgenetwork.sge.reward.QueryCampaignRequest") proto.RegisterType((*QueryCampaignResponse)(nil), "sgenetwork.sge.reward.QueryCampaignResponse") proto.RegisterType((*QueryCampaignsRequest)(nil), "sgenetwork.sge.reward.QueryCampaignsRequest") @@ -864,62 +1058,70 @@ func init() { func init() { proto.RegisterFile("sge/reward/query.proto", fileDescriptor_324afa5f2186a8c0) } var fileDescriptor_324afa5f2186a8c0 = []byte{ - // 878 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x97, 0x4b, 0x4f, 0x13, 0x5d, - 0x18, 0xc7, 0x7b, 0x80, 0xb7, 0xc0, 0x81, 0xbc, 0xe1, 0x3d, 0x2f, 0x20, 0x56, 0x18, 0xe8, 0xa8, - 0x6d, 0xb9, 0xcd, 0x04, 0xd0, 0x78, 0x8b, 0x22, 0x34, 0xca, 0xc2, 0x0d, 0x36, 0x71, 0x43, 0x62, - 0xc8, 0x94, 0x9e, 0x8c, 0x13, 0x6d, 0xcf, 0x30, 0x67, 0x2a, 0x36, 0x4d, 0x37, 0x6e, 0x4c, 0x34, - 0x26, 0x26, 0xc4, 0xad, 0x1b, 0xfd, 0x02, 0xba, 0x36, 0x31, 0xee, 0x58, 0x62, 0xdc, 0xb8, 0x32, - 0x06, 0xdc, 0xb9, 0xf2, 0x1b, 0x98, 0x9e, 0x4b, 0x69, 0x67, 0x7a, 0x19, 0x9a, 0x6a, 0x5c, 0xb5, - 0xce, 0x3c, 0x97, 0xdf, 0xf3, 0xff, 0x9f, 0x9e, 0x47, 0xe0, 0x28, 0x35, 0xb1, 0xee, 0xe0, 0x1d, - 0xc3, 0xc9, 0xe8, 0xdb, 0x79, 0xec, 0x14, 0x34, 0xdb, 0x21, 0x2e, 0x41, 0x23, 0xd4, 0xc4, 0x39, - 0xec, 0xee, 0x10, 0xe7, 0xbe, 0x46, 0x4d, 0xac, 0xf1, 0x90, 0xc8, 0xb0, 0x49, 0x4c, 0xc2, 0x22, - 0xf4, 0xf2, 0x37, 0x1e, 0x1c, 0x19, 0x37, 0x09, 0x31, 0x1f, 0x60, 0xdd, 0xb0, 0x2d, 0xdd, 0xc8, - 0xe5, 0x88, 0x6b, 0xb8, 0x16, 0xc9, 0x51, 0xf1, 0x76, 0x66, 0x8b, 0xd0, 0x2c, 0xa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, 0x1b, 0x5a, 0x0a, 0xd0, 0xca, 0xbb, 0x57, 0x23, 0xe7, 0x8e, 0x97, 0x24, 0x40, 0xaf, 0x33, - 0xd0, 0xcb, 0xe8, 0x62, 0x0b, 0x50, 0xbd, 0x58, 0x7d, 0x55, 0x97, 0xf4, 0xa2, 0xd8, 0x03, 0x25, - 0xf4, 0x03, 0xc0, 0x53, 0x4d, 0x6e, 0x67, 0x74, 0xed, 0x38, 0x5c, 0xfe, 0x55, 0x16, 0x59, 0x6e, - 0x3b, 0x5f, 0x8c, 0x78, 0x8b, 0x8d, 0x78, 0x03, 0x25, 0xdb, 0x1d, 0x51, 0x2f, 0xca, 0x95, 0x55, - 0x42, 0x1f, 0x01, 0xfc, 0xcf, 0x77, 0x7f, 0xa2, 0x60, 0xda, 0x7b, 0x6f, 0x83, 0xf3, 0xc7, 0xcc, - 0x12, 0xf3, 0x2c, 0xb3, 0x79, 0x2e, 0xa1, 0x0b, 0xad, 0xe6, 0x39, 0xba, 0x1e, 0xaa, 0x57, 0x43, - 0x69, 0x35, 0xb9, 0x77, 0xa0, 0x80, 0xfd, 0x03, 0x05, 0x7c, 0x3b, 0x50, 0xc0, 0x8b, 0x43, 0x25, - 0xb4, 0x7f, 0xa8, 0x84, 0xbe, 0x1c, 0x2a, 0xa1, 0x8d, 0x69, 0xd3, 0x72, 0xef, 0xe5, 0xd3, 0xda, - 0x16, 0xc9, 0xfa, 0x8a, 0x3f, 0x92, 0xe5, 0xdd, 0x82, 0x8d, 0x69, 0x3a, 0xcc, 0xfe, 0xc4, 0x5a, - 0xfa, 0x15, 0x00, 0x00, 0xff, 0xff, 0x0a, 0x7f, 0x1b, 0x06, 0x40, 0x0e, 0x00, 0x00, + // 1004 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x98, 0xcf, 0x6f, 0x1b, 0x45, + 0x14, 0xc7, 0x33, 0x4d, 0x70, 0x9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e0, 0xb5, 0xac, 0x7c, 0xc6, 0xc7, 0xc3, 0xe4, 0x7d, 0x3b, 0x3c, 0x6c, 0x3c, 0x3e, + 0xd2, 0xd0, 0x93, 0x23, 0x0d, 0xfd, 0x75, 0xa4, 0xa1, 0x6f, 0x8f, 0xb5, 0x95, 0x27, 0xc7, 0xda, + 0xca, 0x1f, 0xc7, 0xda, 0xca, 0xdd, 0x1d, 0xc7, 0x0d, 0x3e, 0xee, 0xb5, 0x8c, 0x36, 0xed, 0xc4, + 0x16, 0xff, 0x5c, 0x2d, 0x1f, 0xf4, 0x3d, 0xc2, 0x5a, 0x05, 0xfe, 0x9f, 0x85, 0xbd, 0xff, 0x02, + 0x00, 0x00, 0xff, 0xff, 0x58, 0x4e, 0x9a, 0x90, 0x52, 0x11, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -936,6 +1138,10 @@ const _ = grpc.SupportPackageIsVersion4 type QueryClient interface { // Parameters queries the parameters of the module. Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + // PromoterByAddress queries a certain promoter. + PromoterByAddress(ctx context.Context, in *QueryPromoterByAddressRequest, opts ...grpc.CallOption) (*QueryPromoterByAddressResponse, error) + // Queries list of all Promoter items. + Promoters(ctx context.Context, in *QueryPromotersRequest, opts ...grpc.CallOption) (*QueryPromotersResponse, error) // Queries a specific Campaign item. Campaign(ctx context.Context, in *QueryCampaignRequest, opts ...grpc.CallOption) (*QueryCampaignResponse, error) // Queries list of all Campaign items. @@ -970,6 +1176,24 @@ func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts . return out, nil } +func (c *queryClient) PromoterByAddress(ctx context.Context, in *QueryPromoterByAddressRequest, opts ...grpc.CallOption) (*QueryPromoterByAddressResponse, error) { + out := new(QueryPromoterByAddressResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.reward.Query/PromoterByAddress", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Promoters(ctx context.Context, in *QueryPromotersRequest, opts ...grpc.CallOption) (*QueryPromotersResponse, error) { + out := new(QueryPromotersResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.reward.Query/Promoters", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *queryClient) Campaign(ctx context.Context, in *QueryCampaignRequest, opts ...grpc.CallOption) (*QueryCampaignResponse, error) { out := new(QueryCampaignResponse) err := c.cc.Invoke(ctx, "/sgenetwork.sge.reward.Query/Campaign", in, out, opts...) @@ -1037,6 +1261,10 @@ func (c *queryClient) RewardsByCampaign(ctx context.Context, in *QueryRewardsByC type QueryServer interface { // Parameters queries the parameters of the module. Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + // PromoterByAddress queries a certain promoter. + PromoterByAddress(context.Context, *QueryPromoterByAddressRequest) (*QueryPromoterByAddressResponse, error) + // Queries list of all Promoter items. + Promoters(context.Context, *QueryPromotersRequest) (*QueryPromotersResponse, error) // Queries a specific Campaign item. Campaign(context.Context, *QueryCampaignRequest) (*QueryCampaignResponse, error) // Queries list of all Campaign items. @@ -1061,6 +1289,12 @@ type UnimplementedQueryServer struct { func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") } +func (*UnimplementedQueryServer) PromoterByAddress(ctx context.Context, req *QueryPromoterByAddressRequest) (*QueryPromoterByAddressResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PromoterByAddress not implemented") +} +func (*UnimplementedQueryServer) Promoters(ctx context.Context, req *QueryPromotersRequest) (*QueryPromotersResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Promoters not implemented") +} func (*UnimplementedQueryServer) Campaign(ctx context.Context, req *QueryCampaignRequest) (*QueryCampaignResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Campaign not implemented") } @@ -1105,6 +1339,42 @@ func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } +func _Query_PromoterByAddress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPromoterByAddressRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).PromoterByAddress(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.reward.Query/PromoterByAddress", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).PromoterByAddress(ctx, req.(*QueryPromoterByAddressRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Promoters_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryPromotersRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Promoters(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.reward.Query/Promoters", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Promoters(ctx, req.(*QueryPromotersRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _Query_Campaign_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(QueryCampaignRequest) if err := dec(in); err != nil { @@ -1239,6 +1509,14 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "Params", Handler: _Query_Params_Handler, }, + { + MethodName: "PromoterByAddress", + Handler: _Query_PromoterByAddress_Handler, + }, + { + MethodName: "Promoters", + Handler: _Query_Promoters_Handler, + }, { MethodName: "Campaign", Handler: _Query_Campaign_Handler, @@ -1328,7 +1606,7 @@ func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *QueryCampaignRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryPromoterByAddressRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1338,27 +1616,27 @@ func (m *QueryCampaignRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryCampaignRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryPromoterByAddressRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryCampaignRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryPromoterByAddressRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.Uid) > 0 { - i -= len(m.Uid) - copy(dAtA[i:], m.Uid) - i = encodeVarintQuery(dAtA, i, uint64(len(m.Uid))) + if len(m.Addr) > 0 { + i -= len(m.Addr) + copy(dAtA[i:], m.Addr) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Addr))) i-- dAtA[i] = 0xa } return len(dAtA) - i, nil } -func (m *QueryCampaignResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryPromoterByAddressResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1368,18 +1646,18 @@ func (m *QueryCampaignResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryCampaignResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryPromoterByAddressResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryCampaignResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryPromoterByAddressResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l { - size, err := m.Campaign.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Promoter.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -1391,7 +1669,7 @@ func (m *QueryCampaignResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *QueryCampaignsRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryPromotersRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1401,12 +1679,12 @@ func (m *QueryCampaignsRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryCampaignsRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryPromotersRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryCampaignsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryPromotersRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1426,7 +1704,7 @@ func (m *QueryCampaignsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *QueryCampaignsResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryPromotersResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1436,12 +1714,12 @@ func (m *QueryCampaignsResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryCampaignsResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryPromotersResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryCampaignsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryPromotersResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1458,10 +1736,10 @@ func (m *QueryCampaignsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) i-- dAtA[i] = 0x12 } - if len(m.Campaign) > 0 { - for iNdEx := len(m.Campaign) - 1; iNdEx >= 0; iNdEx-- { + if len(m.Promoter) > 0 { + for iNdEx := len(m.Promoter) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.Campaign[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Promoter[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -1475,7 +1753,7 @@ func (m *QueryCampaignsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } -func (m *QueryRewardRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryCampaignRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1485,12 +1763,12 @@ func (m *QueryRewardRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryRewardRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryCampaignRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryRewardRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryCampaignRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1505,7 +1783,7 @@ func (m *QueryRewardRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *QueryRewardResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryCampaignResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1515,18 +1793,18 @@ func (m *QueryRewardResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryRewardResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryCampaignResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryRewardResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryCampaignResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l { - size, err := m.Reward.MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Campaign.MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -1538,7 +1816,7 @@ func (m *QueryRewardResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *QueryRewardsRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryCampaignsRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1548,12 +1826,12 @@ func (m *QueryRewardsRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryRewardsRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryCampaignsRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryRewardsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryCampaignsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1573,7 +1851,7 @@ func (m *QueryRewardsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *QueryRewardsResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryCampaignsResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1583,12 +1861,12 @@ func (m *QueryRewardsResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryRewardsResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryCampaignsResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryRewardsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryCampaignsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1605,10 +1883,10 @@ func (m *QueryRewardsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x12 } - if len(m.Rewards) > 0 { - for iNdEx := len(m.Rewards) - 1; iNdEx >= 0; iNdEx-- { + if len(m.Campaign) > 0 { + for iNdEx := len(m.Campaign) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.Rewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + size, err := m.Campaign[iNdEx].MarshalToSizedBuffer(dAtA[:i]) if err != nil { return 0, err } @@ -1622,7 +1900,7 @@ func (m *QueryRewardsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *QueryRewardsByAddressRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryRewardRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1632,26 +1910,173 @@ func (m *QueryRewardsByAddressRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryRewardsByAddressRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryRewardRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryRewardsByAddressRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryRewardRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l - if len(m.PromoterUid) > 0 { - i -= len(m.PromoterUid) - copy(dAtA[i:], m.PromoterUid) - i = encodeVarintQuery(dAtA, i, uint64(len(m.PromoterUid))) + if len(m.Uid) > 0 { + i -= len(m.Uid) + copy(dAtA[i:], m.Uid) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Uid))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0xa } - if len(m.Address) > 0 { - i -= len(m.Address) - copy(dAtA[i:], m.Address) + return len(dAtA) - i, nil +} + +func (m *QueryRewardResponse) 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 *QueryRewardResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryRewardResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Reward.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryRewardsRequest) 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 *QueryRewardsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryRewardsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryRewardsResponse) 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 *QueryRewardsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryRewardsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Rewards) > 0 { + for iNdEx := len(m.Rewards) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Rewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryRewardsByAddressRequest) 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 *QueryRewardsByAddressRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryRewardsByAddressRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.PromoterUid) > 0 { + i -= len(m.PromoterUid) + copy(dAtA[i:], m.PromoterUid) + i = encodeVarintQuery(dAtA, i, uint64(len(m.PromoterUid))) + i-- + dAtA[i] = 0x1a + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) i = encodeVarintQuery(dAtA, i, uint64(len(m.Address))) i-- dAtA[i] = 0x12 @@ -1945,6 +2370,62 @@ func (m *QueryParamsResponse) Size() (n int) { return n } +func (m *QueryPromoterByAddressRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Addr) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryPromoterByAddressResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Promoter.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryPromotersRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryPromotersResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Promoter) > 0 { + for _, e := range m.Promoter { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + func (m *QueryCampaignRequest) Size() (n int) { if m == nil { return 0 @@ -2315,6 +2796,377 @@ func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *QueryPromoterByAddressRequest) 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 ErrIntOverflowQuery + } + 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: QueryPromoterByAddressRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPromoterByAddressRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Addr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Addr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPromoterByAddressResponse) 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 ErrIntOverflowQuery + } + 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: QueryPromoterByAddressResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPromoterByAddressResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Promoter", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Promoter.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPromotersRequest) 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 ErrIntOverflowQuery + } + 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: QueryPromotersRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPromotersRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryPromotersResponse) 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 ErrIntOverflowQuery + } + 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: QueryPromotersResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryPromotersResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Promoter", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Promoter = append(m.Promoter, Promoter{}) + if err := m.Promoter[len(m.Promoter)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *QueryCampaignRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/reward/types/query.pb.gw.go b/x/reward/types/query.pb.gw.go index 70134ca9..4015978e 100644 --- a/x/reward/types/query.pb.gw.go +++ b/x/reward/types/query.pb.gw.go @@ -51,6 +51,96 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal } +func request_Query_PromoterByAddress_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPromoterByAddressRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["addr"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "addr") + } + + protoReq.Addr, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "addr", err) + } + + msg, err := client.PromoterByAddress(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_PromoterByAddress_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPromoterByAddressRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["addr"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "addr") + } + + protoReq.Addr, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "addr", err) + } + + msg, err := server.PromoterByAddress(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_Promoters_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_Promoters_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPromotersRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Promoters_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Promoters(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Promoters_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryPromotersRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Promoters_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Promoters(ctx, &protoReq) + return msg, metadata, err + +} + func request_Query_Campaign_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryCampaignRequest var metadata runtime.ServerMetadata @@ -548,6 +638,52 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_PromoterByAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_PromoterByAddress_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PromoterByAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Promoters_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Promoters_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Promoters_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + mux.Handle("GET", pattern_Query_Campaign_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -770,6 +906,46 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_PromoterByAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_PromoterByAddress_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_PromoterByAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Promoters_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Promoters_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Promoters_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + mux.Handle("GET", pattern_Query_Campaign_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -916,6 +1092,10 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie var ( pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"sge-network", "sge", "reward", "params"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_PromoterByAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"sge-network", "sge", "reward", "promoter-by-address", "addr"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_Promoters_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"sge-network", "sge", "reward", "promoters"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Campaign_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"sge-network", "sge", "reward", "campaign", "uid"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_Campaigns_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"sge-network", "sge", "reward", "campaigns"}, "", runtime.AssumeColonVerbOpt(false))) @@ -934,6 +1114,10 @@ var ( var ( forward_Query_Params_0 = runtime.ForwardResponseMessage + forward_Query_PromoterByAddress_0 = runtime.ForwardResponseMessage + + forward_Query_Promoters_0 = runtime.ForwardResponseMessage + forward_Query_Campaign_0 = runtime.ForwardResponseMessage forward_Query_Campaigns_0 = runtime.ForwardResponseMessage diff --git a/x/reward/types/ticket.go b/x/reward/types/ticket.go index b8f9d2dd..c4b18f37 100644 --- a/x/reward/types/ticket.go +++ b/x/reward/types/ticket.go @@ -7,6 +7,8 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/utils" + "github.com/sge-network/sge/x/bet/types" ) // Validate validates campaign creation ticket payload. @@ -104,18 +106,21 @@ func (payload *RewardPayloadCommon) Validate() error { } // Validate validates promoter config set ticket payload. -func (payload *SetPromoterConfPayload) Validate() error { - catMap := make(map[RewardCategory]struct{}) - for _, v := range payload.Conf.CategoryCap { - _, ok := catMap[v.Category] - if ok { - return sdkerrors.Wrapf(ErrDuplicateCategoryInConf, "%s", v.Category) - } - if v.CapPerAcc <= 0 { - return sdkerrors.Wrapf(ErrCategoryCapShouldBePos, "%s", v.Category) - } +func (payload *CreatePromoterPayload) Validate() error { + if !utils.IsValidUID(payload.UID) { + return types.ErrInvalidBetUID + } + if err := payload.Conf.Validate(); err != nil { + return err + } - catMap[v.Category] = struct{}{} + return nil +} + +// Validate validates promoter config set ticket payload. +func (payload *SetPromoterConfPayload) Validate() error { + if err := payload.Conf.Validate(); err != nil { + return err } return nil diff --git a/x/reward/types/ticket.pb.go b/x/reward/types/ticket.pb.go index 178c3d0a..1cff863e 100644 --- a/x/reward/types/ticket.pb.go +++ b/x/reward/types/ticket.pb.go @@ -548,6 +548,60 @@ func (m *GrantBetBonusRewardPayload) GetBetUID() string { return "" } +// CreatePromoterPayload is the payload for the promoter create. +type CreatePromoterPayload struct { + // uid is the uid of the promoter to be created + UID string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid"` + Conf PromoterConf `protobuf:"bytes,2,opt,name=conf,proto3" json:"conf"` +} + +func (m *CreatePromoterPayload) Reset() { *m = CreatePromoterPayload{} } +func (m *CreatePromoterPayload) String() string { return proto.CompactTextString(m) } +func (*CreatePromoterPayload) ProtoMessage() {} +func (*CreatePromoterPayload) Descriptor() ([]byte, []int) { + return fileDescriptor_5d710bc1249ca8ae, []int{8} +} +func (m *CreatePromoterPayload) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CreatePromoterPayload) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CreatePromoterPayload.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 *CreatePromoterPayload) XXX_Merge(src proto.Message) { + xxx_messageInfo_CreatePromoterPayload.Merge(m, src) +} +func (m *CreatePromoterPayload) XXX_Size() int { + return m.Size() +} +func (m *CreatePromoterPayload) XXX_DiscardUnknown() { + xxx_messageInfo_CreatePromoterPayload.DiscardUnknown(m) +} + +var xxx_messageInfo_CreatePromoterPayload proto.InternalMessageInfo + +func (m *CreatePromoterPayload) GetUID() string { + if m != nil { + return m.UID + } + return "" +} + +func (m *CreatePromoterPayload) GetConf() PromoterConf { + if m != nil { + return m.Conf + } + return PromoterConf{} +} + // SetPromoterConfPayload is the payload for the promoter configuration change. type SetPromoterConfPayload struct { Conf PromoterConf `protobuf:"bytes,1,opt,name=conf,proto3" json:"conf"` @@ -557,7 +611,7 @@ func (m *SetPromoterConfPayload) Reset() { *m = SetPromoterConfPayload{} func (m *SetPromoterConfPayload) String() string { return proto.CompactTextString(m) } func (*SetPromoterConfPayload) ProtoMessage() {} func (*SetPromoterConfPayload) Descriptor() ([]byte, []int) { - return fileDescriptor_5d710bc1249ca8ae, []int{8} + return fileDescriptor_5d710bc1249ca8ae, []int{9} } func (m *SetPromoterConfPayload) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -602,57 +656,60 @@ func init() { proto.RegisterType((*GrantSignupReferrerRewardPayload)(nil), "sgenetwork.sge.reward.GrantSignupReferrerRewardPayload") proto.RegisterType((*GrantSignupAffiliatorRewardPayload)(nil), "sgenetwork.sge.reward.GrantSignupAffiliatorRewardPayload") proto.RegisterType((*GrantBetBonusRewardPayload)(nil), "sgenetwork.sge.reward.GrantBetBonusRewardPayload") + proto.RegisterType((*CreatePromoterPayload)(nil), "sgenetwork.sge.reward.CreatePromoterPayload") proto.RegisterType((*SetPromoterConfPayload)(nil), "sgenetwork.sge.reward.SetPromoterConfPayload") } func init() { proto.RegisterFile("sge/reward/ticket.proto", fileDescriptor_5d710bc1249ca8ae) } var fileDescriptor_5d710bc1249ca8ae = []byte{ - // 698 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0x41, 0x6b, 0xdb, 0x4a, - 0x10, 0xf6, 0x26, 0x8e, 0x2d, 0x8f, 0xdf, 0x7b, 0x3c, 0xf6, 0xc5, 0xaf, 0x8a, 0x03, 0xb6, 0xab, - 0x52, 0xea, 0x16, 0x6a, 0x83, 0x7b, 0x2c, 0x2d, 0xd8, 0x0e, 0x6d, 0x4a, 0x2e, 0x41, 0x49, 0x08, - 0xf4, 0x62, 0x36, 0xd2, 0x58, 0x11, 0x8e, 0xb5, 0x62, 0x77, 0x9d, 0x54, 0x7f, 0xa0, 0xc7, 0xd2, - 0x5b, 0xff, 0x4f, 0x4f, 0x39, 0xe6, 0x58, 0x28, 0x98, 0xe2, 0xdc, 0xfa, 0x2b, 0x8a, 0x56, 0xb2, - 0x23, 0x97, 0x24, 0x04, 0x4a, 0x4e, 0x9a, 0xd9, 0xf9, 0xe6, 0x9b, 0x6f, 0x76, 0x86, 0x15, 0x3c, - 0x90, 0x1e, 0xb6, 0x05, 0x9e, 0x31, 0xe1, 0xb6, 0x95, 0xef, 0x8c, 0x50, 0xb5, 0x42, 0xc1, 0x15, - 0xa7, 0x15, 0xe9, 0x61, 0x80, 0xea, 0x8c, 0x8b, 0x51, 0x4b, 0x7a, 0xd8, 0x4a, 0x30, 0xd5, 0x75, - 0x8f, 0x7b, 0x5c, 0x23, 0xda, 0xb1, 0x95, 0x80, 0xab, 0x34, 0x66, 0x51, 0x51, 0x88, 0xed, 0x51, - 0xe4, 0xa4, 0x67, 0x59, 0xe6, 0xe4, 0x93, 0x06, 0x36, 0x32, 0x81, 0x50, 0xf0, 0x31, 0x57, 0x28, - 0x92, 0x90, 0xf5, 0x7d, 0x15, 0x2a, 0x7d, 0x81, 0x4c, 0x61, 0x9f, 0x8d, 0x43, 0xe6, 0x7b, 0xc1, - 0x2e, 0x8b, 0x4e, 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 0xe7, 0xae, - 0xf5, 0x89, 0x80, 0x95, 0x11, 0xd2, 0x1d, 0x0e, 0xfd, 0x13, 0x9f, 0x29, 0x7e, 0x6f, 0x52, 0x6a, - 0x00, 0x2c, 0x2d, 0xb2, 0x50, 0x93, 0x39, 0xb1, 0xbe, 0x10, 0xa8, 0x6a, 0x41, 0x3d, 0x54, 0x3d, - 0x1e, 0x4c, 0xe4, 0x7d, 0x09, 0x69, 0x43, 0xf1, 0x08, 0x55, 0x66, 0xed, 0x2a, 0xb3, 0x69, 0xbd, - 0xd0, 0x43, 0x95, 0xec, 0xdc, 0x3c, 0x68, 0xcf, 0x0d, 0xeb, 0x10, 0xfe, 0xdf, 0x43, 0xb5, 0x9b, - 0x6e, 0x7b, 0x9f, 0x07, 0xc3, 0xb9, 0xa8, 0x57, 0x90, 0x77, 0x78, 0x30, 0x4c, 0x25, 0xdd, 0xf4, - 0x10, 0x64, 0x33, 0x53, 0x2d, 0x3a, 0xad, 0xd7, 0x3f, 0x9f, 0xd5, 0xc8, 0xc5, 0xac, 0x46, 0x7e, - 0xcc, 0x6a, 0xe4, 0xf3, 0x65, 0x2d, 0x77, 0x71, 0x59, 0xcb, 0x7d, 0xbb, 0xac, 0xe5, 0xde, 0x3f, - 0xf5, 0x7c, 0x75, 0x3c, 0x39, 0x6a, 0x39, 0x7c, 0xdc, 0x96, 0x1e, 0x3e, 0x4f, 0x59, 0x63, 0xbb, - 0xfd, 0x61, 0xf1, 0x5f, 0x89, 0x42, 0x94, 0x47, 0x05, 0xfd, 0xc4, 0xbf, 0xf8, 0x15, 0x00, 0x00, - 0xff, 0xff, 0x36, 0x67, 0x85, 0x1c, 0x72, 0x06, 0x00, 0x00, + // 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, 0xf8, 0x5f, 0x27, 0x78, 0x13, 0xee, 0x2f, 0xc0, 0xea, 0xa5, 0x26, + 0x6a, 0x55, 0xba, 0x4f, 0x6f, 0x81, 0x68, 0xdd, 0xcb, 0xa2, 0xe1, 0x75, 0x28, 0x7b, 0x62, 0x40, + 0x6c, 0xe9, 0x1d, 0x53, 0x5d, 0x6b, 0xa2, 0x96, 0x66, 0x69, 0x9e, 0xe8, 0x29, 0x1f, 0x63, 0x28, + 0x8c, 0xa9, 0x24, 0x3a, 0xa8, 0x71, 0x28, 0x3b, 0x2a, 0xb0, 0x49, 0x30, 0xb0, 0x15, 0x6d, 0x45, + 0x5d, 0xb9, 0x66, 0x93, 0xa0, 0x1f, 0xf9, 0xc6, 0x16, 0x54, 0xf7, 0x02, 0xe7, 0x8a, 0xe1, 0x5e, + 0x4e, 0x09, 0x65, 0xa7, 0xb4, 0xc0, 0xbe, 0xb4, 0xc8, 0x6e, 0x74, 0x61, 0x75, 0xdf, 0x93, 0x87, + 0x0e, 0x27, 0x27, 0xef, 0x27, 0xbe, 0x23, 0x6e, 0xb1, 0x28, 0xc6, 0x77, 0x04, 0x0f, 0xe3, 0x6e, + 0x93, 0xec, 0x3e, 0x1b, 0x8f, 0x99, 0x1f, 0xd5, 0x70, 0x6a, 0x53, 0xef, 0xf8, 0xb2, 0x26, 0xf5, + 0xf1, 0x1b, 0x00, 0xc1, 0x26, 0xdc, 0xa6, 0x83, 0x89, 0xe7, 0x28, 0x15, 0x65, 0x73, 0x7d, 0x36, + 0x6d, 0x94, 0x77, 0xd4, 0xe9, 0xde, 0xc7, 0x8d, 0xdf, 0xd3, 0x46, 0x26, 0xc5, 0xca, 0xd8, 0xf3, + 0x2b, 0xca, 0x67, 0xae, 0xe8, 0x1d, 0x68, 0xa3, 0xd0, 0x1e, 0x38, 0x44, 0x12, 0xb5, 0x7b, 0x57, + 0x0c, 0x26, 0x5a, 0x83, 0xf6, 0x56, 0x68, 0x6f, 0x10, 0x49, 0x12, 0xa5, 0x56, 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, } func (m *CreateCampaignPayload) Marshal() (dAtA []byte, err error) { @@ -1021,6 +1078,46 @@ func (m *GrantBetBonusRewardPayload) MarshalToSizedBuffer(dAtA []byte) (int, err return len(dAtA) - i, nil } +func (m *CreatePromoterPayload) 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 *CreatePromoterPayload) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CreatePromoterPayload) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Conf.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTicket(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.UID) > 0 { + i -= len(m.UID) + copy(dAtA[i:], m.UID) + i = encodeVarintTicket(dAtA, i, uint64(len(m.UID))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *SetPromoterConfPayload) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1216,6 +1313,21 @@ func (m *GrantBetBonusRewardPayload) Size() (n int) { return n } +func (m *CreatePromoterPayload) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.UID) + if l > 0 { + n += 1 + l + sovTicket(uint64(l)) + } + l = m.Conf.Size() + n += 1 + l + sovTicket(uint64(l)) + return n +} + func (m *SetPromoterConfPayload) Size() (n int) { if m == nil { return 0 @@ -2298,6 +2410,121 @@ func (m *GrantBetBonusRewardPayload) Unmarshal(dAtA []byte) error { } return nil } +func (m *CreatePromoterPayload) 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 ErrIntOverflowTicket + } + 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: CreatePromoterPayload: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CreatePromoterPayload: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field UID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTicket + } + 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 ErrInvalidLengthTicket + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTicket + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.UID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Conf", 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 err := m.Conf.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTicket(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTicket + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *SetPromoterConfPayload) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/reward/types/tx.pb.go b/x/reward/types/tx.pb.go index 70c55422..43a552f9 100644 --- a/x/reward/types/tx.pb.go +++ b/x/reward/types/tx.pb.go @@ -29,6 +29,98 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// MsgCreatePromoter is msg to create a promoter. +type MsgCreatePromoter struct { + // creator is the address of message signer account. + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + // ticket is the payload data. + Ticket string `protobuf:"bytes,2,opt,name=ticket,proto3" json:"ticket,omitempty"` +} + +func (m *MsgCreatePromoter) Reset() { *m = MsgCreatePromoter{} } +func (m *MsgCreatePromoter) String() string { return proto.CompactTextString(m) } +func (*MsgCreatePromoter) ProtoMessage() {} +func (*MsgCreatePromoter) Descriptor() ([]byte, []int) { + return fileDescriptor_ad69e28332238e66, []int{0} +} +func (m *MsgCreatePromoter) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreatePromoter) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreatePromoter.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 *MsgCreatePromoter) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreatePromoter.Merge(m, src) +} +func (m *MsgCreatePromoter) XXX_Size() int { + return m.Size() +} +func (m *MsgCreatePromoter) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreatePromoter.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreatePromoter proto.InternalMessageInfo + +func (m *MsgCreatePromoter) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgCreatePromoter) GetTicket() string { + if m != nil { + return m.Ticket + } + return "" +} + +// MsgCreatePromoterResponse promoter create message response type. +type MsgCreatePromoterResponse struct { +} + +func (m *MsgCreatePromoterResponse) Reset() { *m = MsgCreatePromoterResponse{} } +func (m *MsgCreatePromoterResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCreatePromoterResponse) ProtoMessage() {} +func (*MsgCreatePromoterResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ad69e28332238e66, []int{1} +} +func (m *MsgCreatePromoterResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCreatePromoterResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCreatePromoterResponse.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 *MsgCreatePromoterResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCreatePromoterResponse.Merge(m, src) +} +func (m *MsgCreatePromoterResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgCreatePromoterResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCreatePromoterResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCreatePromoterResponse proto.InternalMessageInfo + // MsgSetPromoterConf is msg to set promoter configuration. type MsgSetPromoterConf struct { // creator is the address of message signer account. @@ -43,7 +135,7 @@ func (m *MsgSetPromoterConf) Reset() { *m = MsgSetPromoterConf{} } func (m *MsgSetPromoterConf) String() string { return proto.CompactTextString(m) } func (*MsgSetPromoterConf) ProtoMessage() {} func (*MsgSetPromoterConf) Descriptor() ([]byte, []int) { - return fileDescriptor_ad69e28332238e66, []int{0} + return fileDescriptor_ad69e28332238e66, []int{2} } func (m *MsgSetPromoterConf) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -101,7 +193,7 @@ func (m *MsgSetPromoterConfResponse) Reset() { *m = MsgSetPromoterConfRe func (m *MsgSetPromoterConfResponse) String() string { return proto.CompactTextString(m) } func (*MsgSetPromoterConfResponse) ProtoMessage() {} func (*MsgSetPromoterConfResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ad69e28332238e66, []int{1} + return fileDescriptor_ad69e28332238e66, []int{3} } func (m *MsgSetPromoterConfResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -146,7 +238,7 @@ func (m *MsgCreateCampaign) Reset() { *m = MsgCreateCampaign{} } func (m *MsgCreateCampaign) String() string { return proto.CompactTextString(m) } func (*MsgCreateCampaign) ProtoMessage() {} func (*MsgCreateCampaign) Descriptor() ([]byte, []int) { - return fileDescriptor_ad69e28332238e66, []int{2} + return fileDescriptor_ad69e28332238e66, []int{4} } func (m *MsgCreateCampaign) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -204,7 +296,7 @@ func (m *MsgCreateCampaignResponse) Reset() { *m = MsgCreateCampaignResp func (m *MsgCreateCampaignResponse) String() string { return proto.CompactTextString(m) } func (*MsgCreateCampaignResponse) ProtoMessage() {} func (*MsgCreateCampaignResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ad69e28332238e66, []int{3} + return fileDescriptor_ad69e28332238e66, []int{5} } func (m *MsgCreateCampaignResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -250,7 +342,7 @@ func (m *MsgUpdateCampaign) Reset() { *m = MsgUpdateCampaign{} } func (m *MsgUpdateCampaign) String() string { return proto.CompactTextString(m) } func (*MsgUpdateCampaign) ProtoMessage() {} func (*MsgUpdateCampaign) Descriptor() ([]byte, []int) { - return fileDescriptor_ad69e28332238e66, []int{4} + return fileDescriptor_ad69e28332238e66, []int{6} } func (m *MsgUpdateCampaign) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -308,7 +400,7 @@ func (m *MsgUpdateCampaignResponse) Reset() { *m = MsgUpdateCampaignResp func (m *MsgUpdateCampaignResponse) String() string { return proto.CompactTextString(m) } func (*MsgUpdateCampaignResponse) ProtoMessage() {} func (*MsgUpdateCampaignResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ad69e28332238e66, []int{5} + return fileDescriptor_ad69e28332238e66, []int{7} } func (m *MsgUpdateCampaignResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -353,7 +445,7 @@ func (m *MsgGrantReward) Reset() { *m = MsgGrantReward{} } func (m *MsgGrantReward) String() string { return proto.CompactTextString(m) } func (*MsgGrantReward) ProtoMessage() {} func (*MsgGrantReward) Descriptor() ([]byte, []int) { - return fileDescriptor_ad69e28332238e66, []int{6} + return fileDescriptor_ad69e28332238e66, []int{8} } func (m *MsgGrantReward) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -418,7 +510,7 @@ func (m *MsgGrantRewardResponse) Reset() { *m = MsgGrantRewardResponse{} func (m *MsgGrantRewardResponse) String() string { return proto.CompactTextString(m) } func (*MsgGrantRewardResponse) ProtoMessage() {} func (*MsgGrantRewardResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ad69e28332238e66, []int{7} + return fileDescriptor_ad69e28332238e66, []int{9} } func (m *MsgGrantRewardResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -461,7 +553,7 @@ func (m *MsgWithdrawFunds) Reset() { *m = MsgWithdrawFunds{} } func (m *MsgWithdrawFunds) String() string { return proto.CompactTextString(m) } func (*MsgWithdrawFunds) ProtoMessage() {} func (*MsgWithdrawFunds) Descriptor() ([]byte, []int) { - return fileDescriptor_ad69e28332238e66, []int{8} + return fileDescriptor_ad69e28332238e66, []int{10} } func (m *MsgWithdrawFunds) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -519,7 +611,7 @@ func (m *MsgWithdrawFundsResponse) Reset() { *m = MsgWithdrawFundsRespon func (m *MsgWithdrawFundsResponse) String() string { return proto.CompactTextString(m) } func (*MsgWithdrawFundsResponse) ProtoMessage() {} func (*MsgWithdrawFundsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ad69e28332238e66, []int{9} + return fileDescriptor_ad69e28332238e66, []int{11} } func (m *MsgWithdrawFundsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -549,6 +641,8 @@ func (m *MsgWithdrawFundsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgWithdrawFundsResponse proto.InternalMessageInfo func init() { + proto.RegisterType((*MsgCreatePromoter)(nil), "sgenetwork.sge.reward.MsgCreatePromoter") + proto.RegisterType((*MsgCreatePromoterResponse)(nil), "sgenetwork.sge.reward.MsgCreatePromoterResponse") proto.RegisterType((*MsgSetPromoterConf)(nil), "sgenetwork.sge.reward.MsgSetPromoterConf") proto.RegisterType((*MsgSetPromoterConfResponse)(nil), "sgenetwork.sge.reward.MsgSetPromoterConfResponse") proto.RegisterType((*MsgCreateCampaign)(nil), "sgenetwork.sge.reward.MsgCreateCampaign") @@ -564,39 +658,41 @@ func init() { func init() { proto.RegisterFile("sge/reward/tx.proto", fileDescriptor_ad69e28332238e66) } var fileDescriptor_ad69e28332238e66 = []byte{ - // 505 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x41, 0x6e, 0xd3, 0x40, - 0x14, 0x8d, 0x49, 0x55, 0xc4, 0x0f, 0x94, 0x62, 0x68, 0x65, 0x0c, 0x72, 0xc0, 0x12, 0xa2, 0x5d, - 0xd4, 0x06, 0xba, 0x63, 0xd9, 0x48, 0x20, 0x16, 0x96, 0x50, 0xa0, 0x80, 0xd8, 0x54, 0x53, 0x7b, - 0x3a, 0xb1, 0x12, 0x7b, 0x46, 0x33, 0x63, 0xa5, 0xbd, 0x05, 0x67, 0x60, 0xcf, 0x3d, 0xba, 0xec, - 0x12, 0xb1, 0x88, 0x50, 0x72, 0x03, 0x4e, 0x80, 0x6c, 0xc7, 0x96, 0xc7, 0x69, 0x2a, 0x07, 0xba, - 0x9b, 0x3f, 0x7e, 0xff, 0xbd, 0xff, 0xe4, 0xf7, 0x07, 0xee, 0x0b, 0x82, 0x5d, 0x8e, 0xc7, 0x88, - 0x07, 0xae, 0x3c, 0x75, 0x18, 0xa7, 0x92, 0xea, 0x5b, 0x82, 0xe0, 0x18, 0x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 0xf7, 0xe6, 0x9c, 0xe9, 0xd9, 0x3d, - 0x2d, 0x9f, 0xec, 0x33, 0x86, 0xc5, 0xf1, 0x7a, 0xf6, 0x12, 0xef, 0xff, 0x0d, 0x00, 0x00, 0xff, - 0xff, 0x85, 0x43, 0xde, 0x62, 0xcd, 0x05, 0x00, 0x00, + // 531 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x95, 0xc1, 0x6e, 0xd3, 0x30, + 0x18, 0xc7, 0x1b, 0x06, 0x43, 0x7c, 0x85, 0x31, 0x02, 0x9b, 0x42, 0x40, 0x29, 0x44, 0x42, 0x6c, + 0x87, 0x25, 0xc0, 0x6e, 0x1c, 0x57, 0x01, 0xe2, 0x10, 0x09, 0x15, 0x06, 0x88, 0xcb, 0xe4, 0x25, + 0x9e, 0x1b, 0xb5, 0x89, 0x2d, 0xdb, 0x51, 0xb7, 0xb7, 0xd8, 0x8b, 0xf0, 0x1e, 0x3b, 0xee, 0x88, + 0x38, 0x54, 0xa8, 0x7d, 0x03, 0x9e, 0x00, 0x25, 0x69, 0xa2, 0x38, 0x5d, 0xbb, 0x0c, 0xb8, 0xd9, + 0xf1, 0xdf, 0xdf, 0xef, 0xfb, 0x47, 0xff, 0x4f, 0x86, 0xfb, 0x82, 0x60, 0x97, 0xe3, 0x11, 0xe2, + 0x81, 0x2b, 0x8f, 0x1d, 0xc6, 0xa9, 0xa4, 0xfa, 0x86, 0x20, 0x38, 0xc6, 0x72, 0x44, 0xf9, 0xc0, + 0x11, 0x04, 0x3b, 0xf9, 0xb9, 0xf9, 0x80, 0x50, 0x42, 0x33, 0x85, 0x9b, 0xae, 0x72, 0xb1, 0xfd, + 0x06, 0xee, 0x79, 0x82, 0x74, 0x39, 0x46, 0x12, 0x7f, 0xe0, 0x34, 0xa2, 0x12, 0x73, 0xdd, 0x80, + 0x9b, 0x7e, 0xfa, 0x85, 0x72, 0x43, 0x7b, 0xa2, 0x6d, 0xdd, 0xea, 0x15, 0x5b, 0x7d, 0x13, 0x56, + 0x65, 0xe8, 0x0f, 0xb0, 0x34, 0xae, 0x65, 0x07, 0xb3, 0x9d, 0xfd, 0x08, 0x1e, 0xce, 0x95, 0xe9, + 0x61, 0xc1, 0x68, 0x2c, 0xb0, 0xfd, 0x15, 0x74, 0x4f, 0x90, 0x8f, 0x58, 0x16, 0x27, 0x5d, 0x1a, + 0x1f, 0x2d, 0x81, 0xac, 0xc3, 0x4a, 0x12, 0x06, 0x33, 0x42, 0xba, 0xac, 0x60, 0x57, 0x14, 0xec, + 0x63, 0x30, 0xe7, 0x2b, 0x97, 0xdc, 0xef, 0x5a, 0xc5, 0x5c, 0x17, 0x45, 0x0c, 0x85, 0x24, 0xbe, + 0x12, 0xf7, 0x13, 0xb4, 0x25, 0x95, 0x68, 0x78, 0x70, 0x94, 0xc4, 0x81, 0xc8, 0xe1, 0x7b, 0xbb, + 0x67, 0xe3, 0x4e, 0xeb, 0xe7, 0xb8, 0xb3, 0xe1, 0x53, 0x11, 0x51, 0x21, 0x82, 0x81, 0x13, 0x52, + 0x37, 0x42, 0xb2, 0xef, 0xbc, 0x8f, 0xe5, 0xef, 0x71, 0x47, 0x3f, 0x41, 0xd1, 0xf0, 0xb5, 0x5d, + 0xb9, 0x69, 0xf7, 0x20, 0xdb, 0xbd, 0x4d, 0x37, 0x15, 0x37, 0xd7, 0x17, 0xfe, 0xc4, 0xa2, 0xdd, + 0xba, 0x99, 0x7d, 0x16, 0xfc, 0x93, 0x19, 0x96, 0xb0, 0xbf, 0x34, 0x53, 0xde, 0xcc, 0xcc, 0xb0, + 0x84, 0x35, 0x31, 0xa3, 0xb6, 0x5b, 0x9a, 0x19, 0xc1, 0x9a, 0x27, 0xc8, 0x3b, 0x8e, 0x62, 0xd9, + 0xcb, 0xd2, 0x79, 0x25, 0x23, 0x4f, 0xe1, 0xb6, 0x3f, 0xab, 0x78, 0x90, 0x1e, 0xe5, 0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xbd, 0x2d, 0xbb, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0xb1, 0xba, 0x9b, 0xc3, 0x9f, + 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -613,6 +709,8 @@ const _ = grpc.SupportPackageIsVersion4 type MsgClient interface { // SetPromoterConf is a method to set the configurations of a promoter. SetPromoterConf(ctx context.Context, in *MsgSetPromoterConf, opts ...grpc.CallOption) (*MsgSetPromoterConfResponse, error) + // CreatePromoter is a method to create a promoter + CreatePromoter(ctx context.Context, in *MsgCreatePromoter, opts ...grpc.CallOption) (*MsgCreatePromoterResponse, error) // CreateCampaign is a method to create a campaign CreateCampaign(ctx context.Context, in *MsgCreateCampaign, opts ...grpc.CallOption) (*MsgCreateCampaignResponse, error) // UpdateCampaign is a method to update campaign @@ -640,6 +738,15 @@ func (c *msgClient) SetPromoterConf(ctx context.Context, in *MsgSetPromoterConf, return out, nil } +func (c *msgClient) CreatePromoter(ctx context.Context, in *MsgCreatePromoter, opts ...grpc.CallOption) (*MsgCreatePromoterResponse, error) { + out := new(MsgCreatePromoterResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.reward.Msg/CreatePromoter", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *msgClient) CreateCampaign(ctx context.Context, in *MsgCreateCampaign, opts ...grpc.CallOption) (*MsgCreateCampaignResponse, error) { out := new(MsgCreateCampaignResponse) err := c.cc.Invoke(ctx, "/sgenetwork.sge.reward.Msg/CreateCampaign", in, out, opts...) @@ -680,6 +787,8 @@ func (c *msgClient) GrantReward(ctx context.Context, in *MsgGrantReward, opts .. type MsgServer interface { // SetPromoterConf is a method to set the configurations of a promoter. SetPromoterConf(context.Context, *MsgSetPromoterConf) (*MsgSetPromoterConfResponse, error) + // CreatePromoter is a method to create a promoter + CreatePromoter(context.Context, *MsgCreatePromoter) (*MsgCreatePromoterResponse, error) // CreateCampaign is a method to create a campaign CreateCampaign(context.Context, *MsgCreateCampaign) (*MsgCreateCampaignResponse, error) // UpdateCampaign is a method to update campaign @@ -697,6 +806,9 @@ type UnimplementedMsgServer struct { func (*UnimplementedMsgServer) SetPromoterConf(ctx context.Context, req *MsgSetPromoterConf) (*MsgSetPromoterConfResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SetPromoterConf not implemented") } +func (*UnimplementedMsgServer) CreatePromoter(ctx context.Context, req *MsgCreatePromoter) (*MsgCreatePromoterResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreatePromoter not implemented") +} func (*UnimplementedMsgServer) CreateCampaign(ctx context.Context, req *MsgCreateCampaign) (*MsgCreateCampaignResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method CreateCampaign not implemented") } @@ -732,6 +844,24 @@ func _Msg_SetPromoterConf_Handler(srv interface{}, ctx context.Context, dec func return interceptor(ctx, in, info, handler) } +func _Msg_CreatePromoter_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCreatePromoter) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).CreatePromoter(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.reward.Msg/CreatePromoter", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).CreatePromoter(ctx, req.(*MsgCreatePromoter)) + } + return interceptor(ctx, in, info, handler) +} + func _Msg_CreateCampaign_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(MsgCreateCampaign) if err := dec(in); err != nil { @@ -812,6 +942,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "SetPromoterConf", Handler: _Msg_SetPromoterConf_Handler, }, + { + MethodName: "CreatePromoter", + Handler: _Msg_CreatePromoter_Handler, + }, { MethodName: "CreateCampaign", Handler: _Msg_CreateCampaign_Handler, @@ -833,6 +967,66 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ Metadata: "sge/reward/tx.proto", } +func (m *MsgCreatePromoter) 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 *MsgCreatePromoter) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreatePromoter) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Ticket) > 0 { + i -= len(m.Ticket) + copy(dAtA[i:], m.Ticket) + i = encodeVarintTx(dAtA, i, uint64(len(m.Ticket))) + i-- + dAtA[i] = 0x12 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgCreatePromoterResponse) 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 *MsgCreatePromoterResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCreatePromoterResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func (m *MsgSetPromoterConf) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1206,6 +1400,32 @@ func encodeVarintTx(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } +func (m *MsgCreatePromoter) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Ticket) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgCreatePromoterResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func (m *MsgSetPromoterConf) Size() (n int) { if m == nil { return 0 @@ -1370,6 +1590,170 @@ func sovTx(x uint64) (n int) { func sozTx(x uint64) (n int) { return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } +func (m *MsgCreatePromoter) 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 ErrIntOverflowTx + } + 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: MsgCreatePromoter: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreatePromoter: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Ticket", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Ticket = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCreatePromoterResponse) 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 ErrIntOverflowTx + } + 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: MsgCreatePromoterResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCreatePromoterResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *MsgSetPromoterConf) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 From 7a315c3aa1f87d3a89e3f7ac21808c013c4ca532 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Wed, 20 Mar 2024 21:04:09 +0300 Subject: [PATCH 11/28] lint: gofumpt --- x/reward/client/cli/tx_promoter.go | 1 + x/reward/types/messages_promoter.go | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/x/reward/client/cli/tx_promoter.go b/x/reward/client/cli/tx_promoter.go index 89ed2d70..762f3ad6 100644 --- a/x/reward/client/cli/tx_promoter.go +++ b/x/reward/client/cli/tx_promoter.go @@ -40,6 +40,7 @@ func CmdCreatePromoter() *cobra.Command { return cmd } + func CmdSetPromoterConf() *cobra.Command { cmd := &cobra.Command{ Use: "set-promoter-conf [uid] [ticket]", diff --git a/x/reward/types/messages_promoter.go b/x/reward/types/messages_promoter.go index 96e8c131..c83924b1 100644 --- a/x/reward/types/messages_promoter.go +++ b/x/reward/types/messages_promoter.go @@ -13,8 +13,10 @@ const ( TypeMsgCreatePromoter = "create_promoter" ) -var _ sdk.Msg = &MsgSetPromoterConf{} -var _ sdk.Msg = &MsgCreatePromoter{} +var ( + _ sdk.Msg = &MsgSetPromoterConf{} + _ sdk.Msg = &MsgCreatePromoter{} +) func NewMsgSetPromoterConfig( creator string, From 1e7db8835d40120c22691c788ec4b6956e1bcb87 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Wed, 27 Mar 2024 13:31:20 +0300 Subject: [PATCH 12/28] feat: campaign custom withdraw amount --- proto/sge/reward/authz.proto | 8 +- proto/sge/reward/campaign.proto | 5 + proto/sge/reward/tx.proto | 5 + x/reward/client/cli/tx_campaign.go | 10 +- x/reward/keeper/campaign.go | 2 +- x/reward/keeper/msg_server_campaign.go | 17 +++- x/reward/types/authz.pb.go | 83 ++++++++++++---- x/reward/types/campaign.pb.go | 122 +++++++++++++++++------- x/reward/types/campaign_authorizaton.go | 44 ++++++++- x/reward/types/consts.go | 9 +- x/reward/types/messages_campaign.go | 2 + x/reward/types/pool.go | 23 ++++- x/reward/types/tx.pb.go | 111 +++++++++++++++------ 13 files changed, 337 insertions(+), 104 deletions(-) diff --git a/proto/sge/reward/authz.proto b/proto/sge/reward/authz.proto index 9e266ba7..e45dd744 100644 --- a/proto/sge/reward/authz.proto +++ b/proto/sge/reward/authz.proto @@ -25,4 +25,10 @@ message UpdateCampaignAuthorization { // WithdrawCampaignAuthorization allows the grantee to withdraw remaining // pool balance of the campaign from the granter's account. -message WithdrawCampaignAuthorization {} \ No newline at end of file +message WithdrawCampaignAuthorization { + // withdraw_limit is the maximum limit of the withdrawal by authorization. + string withdraw_limit = 1 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; +} \ No newline at end of file diff --git a/proto/sge/reward/campaign.proto b/proto/sge/reward/campaign.proto index b9605ccd..2607c7f4 100644 --- a/proto/sge/reward/campaign.proto +++ b/proto/sge/reward/campaign.proto @@ -75,4 +75,9 @@ message Pool { (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"spent\"" ]; + string withdrawn = 3 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"spent\"" + ]; } \ No newline at end of file diff --git a/proto/sge/reward/tx.proto b/proto/sge/reward/tx.proto index 5570ce8d..400247d4 100644 --- a/proto/sge/reward/tx.proto +++ b/proto/sge/reward/tx.proto @@ -80,6 +80,11 @@ message MsgWithdrawFunds { string uid = 2; // ticket is the payload data. string ticket = 3; + // amount is the requested withdrawal amount + string amount = 4 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; } // MsgWithdrawFundsResponse withdraw funds message response type. diff --git a/x/reward/client/cli/tx_campaign.go b/x/reward/client/cli/tx_campaign.go index 3145c737..39663183 100644 --- a/x/reward/client/cli/tx_campaign.go +++ b/x/reward/client/cli/tx_campaign.go @@ -95,7 +95,7 @@ func CmdUpdateCampaign() *cobra.Command { func CmdWithdrawFunds() *cobra.Command { cmd := &cobra.Command{ - Use: "withdraw-funds [uid] [ticket]", + Use: "withdraw-funds [uid] [amount] [ticket]", Short: "Withdraw funds from a campaign", Long: "Withdrawal of the funds from a certain campaign", Args: cobra.ExactArgs(2), @@ -103,8 +103,13 @@ func CmdWithdrawFunds() *cobra.Command { // Get indexes argUID := args[0] + argWithdrawAmountCosmosInt, ok := sdkmath.NewIntFromString(args[1]) + if !ok { + return types.ErrInvalidFunds + } + // Get value arguments - argTicket := args[1] + argTicket := args[2] clientCtx, err := client.GetClientTxContext(cmd) if err != nil { @@ -114,6 +119,7 @@ func CmdWithdrawFunds() *cobra.Command { msg := types.NewMsgWithdrawFunds( clientCtx.GetFromAddress().String(), argUID, + argWithdrawAmountCosmosInt, argTicket, ) if err := msg.ValidateBasic(); err != nil { diff --git a/x/reward/keeper/campaign.go b/x/reward/keeper/campaign.go index 7079908e..b80336b2 100644 --- a/x/reward/keeper/campaign.go +++ b/x/reward/keeper/campaign.go @@ -58,7 +58,7 @@ func (k Keeper) GetAllCampaign(ctx sdk.Context) (list []types.Campaign) { func (k Keeper) UpdateCampaignPool(ctx sdk.Context, campaign types.Campaign, receiver types.Receiver) { totalAmount := receiver.SubaccountAmount.Add(receiver.MainAccountAmount) // Fixme: Check if the logic is correct - campaign.Pool.Spent = campaign.Pool.Spent.Add(totalAmount) + campaign.Pool.Spend(totalAmount) k.SetCampaign(ctx, campaign) } diff --git a/x/reward/keeper/msg_server_campaign.go b/x/reward/keeper/msg_server_campaign.go index a88c82e5..176f73be 100644 --- a/x/reward/keeper/msg_server_campaign.go +++ b/x/reward/keeper/msg_server_campaign.go @@ -129,7 +129,7 @@ func (k msgServer) UpdateCampaign(goCtx context.Context, msg *types.MsgUpdateCam return nil, sdkerrors.Wrapf(types.ErrInFundingCampaignPool, "%s", err) } - campaign.Pool.Total = campaign.Pool.Total.Add(msg.TopupFunds) + campaign.Pool.TopUp(msg.TopupFunds) } campaign.EndTS = payload.EndTs @@ -172,12 +172,16 @@ func (k msgServer) WithdrawFunds(goCtx context.Context, msg *types.MsgWithdrawFu return nil, err } } - availableAmount := valFound.Pool.Total.Sub(valFound.Pool.Spent) + availableAmount := valFound.Pool.AvailableAmount() // check if the pool amount is positive if availableAmount.IsNil() || !availableAmount.GT(sdkmath.ZeroInt()) { return nil, sdkerrors.Wrapf(types.ErrWithdrawFromCampaignPool, "pool amount should be positive") } + if availableAmount.LT(msg.Amount) { + return nil, sdkerrors.Wrapf(types.ErrWithdrawFromCampaignPool, "not enough withdrawable balance %s", availableAmount) + } + // transfer the funds present in campaign to the promoter if err := k.modFunder.Refund( types.RewardPoolFunder{}, ctx, @@ -187,9 +191,12 @@ func (k msgServer) WithdrawFunds(goCtx context.Context, msg *types.MsgWithdrawFu return nil, sdkerrors.Wrapf(types.ErrWithdrawFromCampaignPool, "%s", err) } // set the pool amount to zero - valFound.Pool.Total = sdkmath.ZeroInt() - // deactivate the campaign - valFound.IsActive = false + valFound.Pool.Withdraw(msg.Amount) + + if valFound.Pool.AvailableAmount().LTE(sdkmath.ZeroInt()) { + // deactivate the campaign + valFound.IsActive = false + } // store the campaign k.SetCampaign(ctx, valFound) diff --git a/x/reward/types/authz.pb.go b/x/reward/types/authz.pb.go index 1a72f80f..d932f1c1 100644 --- a/x/reward/types/authz.pb.go +++ b/x/reward/types/authz.pb.go @@ -105,6 +105,8 @@ var xxx_messageInfo_UpdateCampaignAuthorization proto.InternalMessageInfo // WithdrawCampaignAuthorization allows the grantee to withdraw remaining // pool balance of the campaign from the granter's account. type WithdrawCampaignAuthorization struct { + // withdraw_limit is the maximum limit of the withdrawal by authorization. + WithdrawLimit cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=withdraw_limit,json=withdrawLimit,proto3,customtype=cosmossdk.io/math.Int" json:"withdraw_limit"` } func (m *WithdrawCampaignAuthorization) Reset() { *m = WithdrawCampaignAuthorization{} } @@ -149,23 +151,24 @@ func init() { func init() { proto.RegisterFile("sge/reward/authz.proto", fileDescriptor_4c01411aa0c16fcd) } var fileDescriptor_4c01411aa0c16fcd = []byte{ - // 252 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x90, 0x31, 0x4b, 0x03, 0x31, - 0x18, 0x86, 0xef, 0x16, 0xc1, 0x73, 0x2b, 0x56, 0x44, 0x69, 0x4e, 0x9c, 0x74, 0x30, 0x19, 0xdc, - 0x05, 0x7b, 0x93, 0xe0, 0x24, 0x88, 0x20, 0x88, 0xa4, 0xcd, 0x47, 0x12, 0x6a, 0xf2, 0x85, 0xe4, - 0x3b, 0x4e, 0xfb, 0x2b, 0xfc, 0x59, 0x1d, 0x3b, 0x8a, 0x43, 0x91, 0xbb, 0x3f, 0x22, 0x77, 0xd5, - 0xcd, 0xd5, 0xed, 0x1d, 0x9e, 0xf7, 0x7d, 0xe1, 0x29, 0x0e, 0x92, 0x06, 0x11, 0xa1, 0x91, 0x51, - 0x09, 0x59, 0x93, 0x59, 0xf2, 0x10, 0x91, 0x70, 0x34, 0x4e, 0x1a, 0x3c, 0x50, 0x83, 0x71, 0xc1, - 0x93, 0x06, 0xbe, 0x45, 0x8e, 0xf6, 0x35, 0x6a, 0x1c, 0x08, 0xd1, 0xa7, 0x2d, 0x7c, 0xfa, 0x54, - 0x1c, 0x57, 0x11, 0x24, 0x41, 0x25, 0x5d, 0x90, 0x56, 0xfb, 0xeb, 0x9a, 0x0c, 0x46, 0xbb, 0x94, - 0x64, 0xd1, 0x8f, 0xae, 0x8a, 0xbd, 0x14, 0xc0, 0xab, 0xe7, 0x17, 0xeb, 0x2c, 0x1d, 0xe6, 0x27, - 0xf9, 0xd9, 0xee, 0x74, 0xb2, 0xda, 0x94, 0xd9, 0xe7, 0xa6, 0x1c, 0xcf, 0x31, 0x39, 0x4c, 0x49, - 0x2d, 0xb8, 0x45, 0xe1, 0x24, 0x19, 0x7e, 0xe3, 0xe9, 0xae, 0x18, 0x1a, 0xb7, 0x7d, 0xa1, 0x9f, - 0xbf, 0x0f, 0xea, 0xdf, 0xe6, 0xcb, 0x62, 0xf2, 0x60, 0xc9, 0xa8, 0x28, 0x9b, 0x3f, 0x0f, 0xa6, - 0xd5, 0xaa, 0x65, 0xf9, 0xba, 0x65, 0xf9, 0x57, 0xcb, 0xf2, 0xf7, 0x8e, 0x65, 0xeb, 0x8e, 0x65, - 0x1f, 0x1d, 0xcb, 0x1e, 0xcf, 0xb5, 0x25, 0x53, 0xcf, 0xf8, 0x1c, 0x9d, 0x48, 0x1a, 0x2e, 0x7e, - 0x8c, 0xf5, 0x59, 0xbc, 0xfe, 0x6a, 0xa5, 0xb7, 0x00, 0x69, 0xb6, 0x33, 0xa8, 0xba, 0xfc, 0x0e, - 0x00, 0x00, 0xff, 0xff, 0x16, 0xa5, 0x07, 0x9a, 0x71, 0x01, 0x00, 0x00, + // 268 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x91, 0xb1, 0x4a, 0x03, 0x41, + 0x10, 0x86, 0xef, 0x1a, 0xc1, 0x15, 0x2d, 0x82, 0x11, 0x51, 0xb2, 0x11, 0x2b, 0x2d, 0xdc, 0x2d, + 0xec, 0x05, 0x73, 0x36, 0x82, 0x95, 0x20, 0x82, 0x20, 0xb2, 0xc9, 0x0d, 0x7b, 0x4b, 0xdc, 0x9d, + 0x65, 0x77, 0x8e, 0xd3, 0x3c, 0x85, 0x8f, 0x95, 0x32, 0xa5, 0x58, 0x04, 0xb9, 0x7b, 0x11, 0xb9, + 0x4b, 0xd2, 0xd9, 0x58, 0xd8, 0x4d, 0xf1, 0xfd, 0xff, 0x07, 0xff, 0xb0, 0x83, 0xa8, 0x41, 0x06, + 0xa8, 0x54, 0xc8, 0xa5, 0x2a, 0xa9, 0x98, 0x09, 0x1f, 0x90, 0xb0, 0xd7, 0x8f, 0x1a, 0x1c, 0x50, + 0x85, 0x61, 0x2a, 0xa2, 0x06, 0xb1, 0x42, 0x8e, 0xf6, 0x35, 0x6a, 0xec, 0x08, 0xd9, 0x5e, 0x2b, + 0xf8, 0xf4, 0x99, 0x1d, 0x67, 0x01, 0x14, 0x41, 0xa6, 0xac, 0x57, 0x46, 0xbb, 0xeb, 0x92, 0x0a, + 0x0c, 0x66, 0xa6, 0xc8, 0xa0, 0xeb, 0x5d, 0xb1, 0x9d, 0xe8, 0xc1, 0xe5, 0x2f, 0xaf, 0xc6, 0x1a, + 0x3a, 0x4c, 0x4f, 0xd2, 0xb3, 0xed, 0xd1, 0x60, 0xbe, 0x1c, 0x26, 0x5f, 0xcb, 0x61, 0x7f, 0x82, + 0xd1, 0x62, 0x8c, 0xf9, 0x54, 0x18, 0x94, 0x56, 0x51, 0x21, 0x6e, 0x1d, 0xdd, 0xb3, 0x2e, 0x71, + 0xd7, 0x06, 0xda, 0xfa, 0x07, 0x9f, 0xff, 0x5b, 0x3d, 0xb0, 0xc1, 0xa3, 0xa1, 0x22, 0x0f, 0xaa, + 0xfa, 0x5d, 0x70, 0xc3, 0xf6, 0xaa, 0x35, 0xf0, 0x17, 0xc7, 0xee, 0x26, 0xd4, 0x69, 0x46, 0xd9, + 0xbc, 0xe6, 0xe9, 0xa2, 0xe6, 0xe9, 0x77, 0xcd, 0xd3, 0x8f, 0x86, 0x27, 0x8b, 0x86, 0x27, 0x9f, + 0x0d, 0x4f, 0x9e, 0xce, 0xb5, 0xa1, 0xa2, 0x1c, 0x8b, 0x09, 0x5a, 0x19, 0x35, 0x5c, 0xac, 0x77, + 0x6f, 0x6f, 0xf9, 0xb6, 0x79, 0x0e, 0xbd, 0x7b, 0x88, 0xe3, 0xad, 0x6e, 0xf0, 0xcb, 0x9f, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x7e, 0x60, 0xa2, 0x52, 0xb7, 0x01, 0x00, 0x00, } func (m *CreateCampaignAuthorization) Marshal() (dAtA []byte, err error) { @@ -254,6 +257,16 @@ func (m *WithdrawCampaignAuthorization) MarshalToSizedBuffer(dAtA []byte) (int, _ = i var l int _ = l + { + size := m.WithdrawLimit.Size() + i -= size + if _, err := m.WithdrawLimit.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintAuthz(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -296,6 +309,8 @@ func (m *WithdrawCampaignAuthorization) Size() (n int) { } var l int _ = l + l = m.WithdrawLimit.Size() + n += 1 + l + sovAuthz(uint64(l)) return n } @@ -502,6 +517,40 @@ func (m *WithdrawCampaignAuthorization) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: WithdrawCampaignAuthorization: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field WithdrawLimit", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAuthz + } + 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 ErrInvalidLengthAuthz + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAuthz + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.WithdrawLimit.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipAuthz(dAtA[iNdEx:]) diff --git a/x/reward/types/campaign.pb.go b/x/reward/types/campaign.pb.go index b1249d6a..b7300ec1 100644 --- a/x/reward/types/campaign.pb.go +++ b/x/reward/types/campaign.pb.go @@ -183,8 +183,9 @@ func (m *Campaign) GetMeta() string { // 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"` - Spent cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=spent,proto3,customtype=cosmossdk.io/math.Int" json:"spent" yaml:"spent"` + Total cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=total,proto3,customtype=cosmossdk.io/math.Int" json:"total" yaml:"total"` + Spent cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=spent,proto3,customtype=cosmossdk.io/math.Int" json:"spent" yaml:"spent"` + Withdrawn cosmossdk_io_math.Int `protobuf:"bytes,3,opt,name=withdrawn,proto3,customtype=cosmossdk.io/math.Int" json:"withdrawn" yaml:"spent"` } func (m *Pool) Reset() { *m = Pool{} } @@ -228,41 +229,42 @@ func init() { func init() { proto.RegisterFile("sge/reward/campaign.proto", fileDescriptor_6d1d1b3139567e36) } var fileDescriptor_6d1d1b3139567e36 = []byte{ - // 545 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0x4f, 0x6f, 0xd3, 0x3c, - 0x1c, 0xc7, 0x9b, 0xa7, 0x69, 0x9b, 0xba, 0x5d, 0x1f, 0xf0, 0x98, 0x66, 0x3a, 0x29, 0x09, 0x45, - 0x88, 0x22, 0xb4, 0x44, 0xda, 0xc4, 0x85, 0xdb, 0x52, 0x90, 0xd8, 0x05, 0x4d, 0xde, 0x76, 0xe1, - 0x52, 0x79, 0xa9, 0x95, 0x45, 0x6b, 0xe2, 0xc8, 0x76, 0x19, 0x7d, 0x17, 0xe3, 0x5d, 0xed, 0xb8, - 0x23, 0xe2, 0x10, 0xa1, 0xf4, 0xb6, 0x23, 0xaf, 0x00, 0xd9, 0xc9, 0xc2, 0x86, 0x60, 0xda, 0x25, - 0xfe, 0xfd, 0xf9, 0x7e, 0x3f, 0x49, 0xec, 0x9f, 0xc1, 0x53, 0x11, 0x51, 0x9f, 0xd3, 0x73, 0xc2, - 0x67, 0x7e, 0x48, 0x92, 0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0x11, 0x19, 0x4d, 0x65, 0x35, 0xbc, 0x0f, 0x85, 0x68, 0xcf, 0x08, 0x97, 0xde, 0x60, - 0x72, 0x59, 0xd8, 0xc6, 0x55, 0x61, 0x1b, 0x3f, 0x0a, 0xdb, 0xb8, 0x58, 0xd9, 0x8d, 0xab, 0x95, - 0xdd, 0xf8, 0xb6, 0xb2, 0x1b, 0x9f, 0x5e, 0x45, 0xb1, 0x3c, 0x5d, 0x9c, 0x78, 0x21, 0x4b, 0x7c, - 0x11, 0xd1, 0xed, 0x6a, 0x07, 0x55, 0xec, 0x7f, 0xb9, 0xb9, 0x72, 0xea, 0xe4, 0xc5, 0x49, 0x5b, - 0x5f, 0xb9, 0xdd, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xb3, 0x08, 0x2a, 0x3e, 0xd5, 0x03, 0x00, + // 561 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0x4f, 0x6f, 0xd3, 0x30, + 0x18, 0xc6, 0x1b, 0x9a, 0xb6, 0xa9, 0xdb, 0x15, 0xf0, 0x98, 0x16, 0x3a, 0x29, 0x09, 0x45, 0x88, + 0x22, 0xb4, 0x44, 0xda, 0xc4, 0x85, 0xdb, 0x52, 0x90, 0x98, 0x90, 0xd0, 0xe4, 0x6d, 0x17, 0x2e, + 0x95, 0x97, 0x58, 0x69, 0xb4, 0x26, 0x8e, 0x6c, 0x97, 0xd2, 0x6f, 0x01, 0xdf, 0x6a, 0xc7, 0x1d, + 0x11, 0x12, 0x11, 0x4a, 0x6f, 0x3b, 0xf2, 0x09, 0x90, 0x9d, 0xac, 0xdb, 0x10, 0x4c, 0xe3, 0x12, + 0xbf, 0x7f, 0x9e, 0xe7, 0x97, 0xc4, 0x7e, 0x0d, 0x1e, 0xf3, 0x88, 0x78, 0x8c, 0xcc, 0x31, 0x0b, + 0xbd, 0x00, 0x27, 0x19, 0x8e, 0xa3, 0xd4, 0xcd, 0x18, 0x15, 0x14, 0x6e, 0xf0, 0x88, 0xa4, 0x44, + 0xcc, 0x29, 0x3b, 0x75, 0x79, 0x44, 0xdc, 0x52, 0xd5, 0x7f, 0x14, 0xd1, 0x88, 0x2a, 0x85, 0x27, + 0xa3, 0x52, 0xdc, 0xdf, 0xbc, 0xc6, 0x29, 0x97, 0xb2, 0x31, 0xf8, 0xda, 0x00, 0xc6, 0xa8, 0x02, + 0x43, 0x13, 0xb4, 0x02, 0x46, 0xb0, 0xa0, 0xcc, 0xd4, 0x1c, 0x6d, 0xd8, 0x46, 0x97, 0x29, 0x74, + 0x40, 0x7d, 0x16, 0x87, 0xe6, 0x3d, 0x59, 0xf5, 0x7b, 0x45, 0x6e, 0xd7, 0x8f, 0xf7, 0xdf, 0x5c, + 0xe4, 0xb6, 0xac, 0x22, 0xf9, 0x80, 0x7d, 0x60, 0x64, 0x8c, 0x26, 0x54, 0x10, 0x66, 0xd6, 0x95, + 0x79, 0x95, 0xc3, 0x5d, 0x60, 0x70, 0x81, 0x99, 0x18, 0x0b, 0x6e, 0xea, 0x8e, 0x36, 0xd4, 0xfd, + 0xcd, 0x22, 0xb7, 0x5b, 0x87, 0xb2, 0x76, 0x74, 0x78, 0x91, 0xdb, 0xab, 0x36, 0x5a, 0x45, 0xf0, + 0x25, 0x68, 0x92, 0x34, 0x94, 0x96, 0x86, 0xb2, 0xac, 0x17, 0xb9, 0xdd, 0x78, 0x9b, 0x86, 0xca, + 0x50, 0xb5, 0x50, 0xb5, 0xc2, 0x0f, 0xe0, 0x7e, 0xf9, 0x5b, 0xe3, 0x00, 0x0b, 0x12, 0x51, 0xb6, + 0x30, 0x9b, 0x8e, 0x36, 0xec, 0xed, 0x3c, 0x73, 0xff, 0xba, 0x4d, 0x2e, 0x52, 0xcb, 0xa8, 0x12, + 0xa3, 0x1e, 0xbb, 0x91, 0x43, 0x1f, 0x74, 0x2a, 0x9e, 0x58, 0x64, 0xc4, 0x6c, 0x29,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x92, 0x8a, 0x6a, 0x78, 0xef, 0x0a, 0x51, 0x9e, 0x01, 0x2a, 0xbd, 0xf0, + 0x3d, 0x68, 0xcf, 0x63, 0x31, 0x09, 0x19, 0x9e, 0xa7, 0xe5, 0x78, 0xff, 0x2f, 0xe8, 0xca, 0xef, + 0x8f, 0xce, 0x0a, 0x4b, 0x3b, 0x2f, 0x2c, 0xed, 0x67, 0x61, 0x69, 0x5f, 0x96, 0x56, 0xed, 0x7c, + 0x69, 0xd5, 0xbe, 0x2d, 0xad, 0xda, 0xc7, 0x17, 0x51, 0x2c, 0x26, 0xb3, 0x13, 0x37, 0xa0, 0x89, + 0xc7, 0x23, 0xb2, 0x5d, 0x1d, 0x87, 0x8c, 0xbd, 0xcf, 0x97, 0xf7, 0x57, 0x8e, 0x11, 0x3f, 0x69, + 0xaa, 0xfb, 0xbb, 0xfb, 0x3b, 0x00, 0x00, 0xff, 0xff, 0x69, 0x7c, 0xd6, 0xed, 0x22, 0x04, 0x00, 0x00, } @@ -399,6 +401,16 @@ func (m *Pool) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size := m.Withdrawn.Size() + i -= size + if _, err := m.Withdrawn.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintCampaign(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a { size := m.Spent.Size() i -= size @@ -495,6 +507,8 @@ func (m *Pool) Size() (n int) { n += 1 + l + sovCampaign(uint64(l)) l = m.Spent.Size() n += 1 + l + sovCampaign(uint64(l)) + l = m.Withdrawn.Size() + n += 1 + l + sovCampaign(uint64(l)) return n } @@ -982,6 +996,40 @@ func (m *Pool) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Withdrawn", 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.Withdrawn.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipCampaign(dAtA[iNdEx:]) diff --git a/x/reward/types/campaign_authorizaton.go b/x/reward/types/campaign_authorizaton.go index 519b3f70..e3c47a19 100644 --- a/x/reward/types/campaign_authorizaton.go +++ b/x/reward/types/campaign_authorizaton.go @@ -121,24 +121,58 @@ func (a UpdateCampaignAuthorization) ValidateBasic() error { return nil } +var _ authz.Authorization = &WithdrawCampaignAuthorization{} + +// NewWithdrawAuthorization creates a new WithdrawAuthorization object. +func NewWithdrawAuthorization(withdrawLimit sdkmath.Int) *WithdrawCampaignAuthorization { + return &WithdrawCampaignAuthorization{ + WithdrawLimit: withdrawLimit, + } +} + // MsgTypeURL implements Authorization.MsgTypeURL. func (WithdrawCampaignAuthorization) MsgTypeURL() string { - return sdk.MsgTypeURL(&MsgUpdateCampaign{}) + return sdk.MsgTypeURL(&MsgWithdrawFunds{}) } // Accept implements Authorization.Accept. func (a WithdrawCampaignAuthorization) Accept(_ sdk.Context, msg sdk.Msg) (authz.AcceptResponse, error) { - _, ok := msg.(*MsgWithdrawFunds) + mWithdraw, ok := msg.(*MsgWithdrawFunds) if !ok { return authz.AcceptResponse{}, sdkerrtypes.ErrInvalidType.Wrap("type mismatch") } + limitLeft := a.WithdrawLimit.Sub(mWithdraw.Amount) + if limitLeft.IsNegative() { + return authz.AcceptResponse{}, sdkerrtypes.ErrInsufficientFunds.Wrapf( + "requested amount is more than withdraw limit", + ) + } + if limitLeft.IsZero() { + return authz.AcceptResponse{Accept: true, Delete: true}, nil + } + return authz.AcceptResponse{ Accept: true, - Delete: true, - Updated: &WithdrawCampaignAuthorization{}, + Delete: false, + Updated: &WithdrawCampaignAuthorization{WithdrawLimit: limitLeft}, }, nil } // ValidateBasic implements Authorization.ValidateBasic. -func (a WithdrawCampaignAuthorization) ValidateBasic() error { return nil } +func (a WithdrawCampaignAuthorization) ValidateBasic() error { + if a.WithdrawLimit.IsNil() { + return sdkerrtypes.ErrInvalidCoins.Wrap("withdraw limit cannot be nil") + } + if a.WithdrawLimit.LTE(sdk.ZeroInt()) { + return sdkerrtypes.ErrInvalidCoins.Wrap("withdraw limit cannot be less than or equal to zero") + } + if a.WithdrawLimit.GT(maxWithdrawGrant) { + return sdkerrtypes.ErrInvalidCoins.Wrapf( + "withdraw limit cannot be grated than %s", + maxWithdrawGrant, + ) + } + + return nil +} diff --git a/x/reward/types/consts.go b/x/reward/types/consts.go index 18364abd..41821183 100644 --- a/x/reward/types/consts.go +++ b/x/reward/types/consts.go @@ -2,5 +2,10 @@ package types import sdkmath "cosmossdk.io/math" -// minCampaignFunds is the minimum campaign funds allowed grant. -var minCampaignFunds = sdkmath.NewInt(100) +var ( + // minCampaignFunds is the minimum campaign funds allowed grant. + minCampaignFunds = sdkmath.NewInt(100) + + // maxWithdrawGrant is the maximum withdraw allowed grant. + maxWithdrawGrant = sdkmath.NewInt(100) +) diff --git a/x/reward/types/messages_campaign.go b/x/reward/types/messages_campaign.go index 03495f50..58919c7d 100644 --- a/x/reward/types/messages_campaign.go +++ b/x/reward/types/messages_campaign.go @@ -149,11 +149,13 @@ var _ sdk.Msg = &MsgWithdrawFunds{} func NewMsgWithdrawFunds( creator string, uid string, + amount sdkmath.Int, ticket string, ) *MsgWithdrawFunds { return &MsgWithdrawFunds{ Creator: creator, Uid: uid, + Amount: amount, Ticket: ticket, } } diff --git a/x/reward/types/pool.go b/x/reward/types/pool.go index 1aa2d09b..b29981ce 100644 --- a/x/reward/types/pool.go +++ b/x/reward/types/pool.go @@ -7,15 +7,32 @@ import ( func NewPool(total sdkmath.Int) Pool { return Pool{ - Total: total, - Spent: sdkmath.ZeroInt(), + Total: total, + Spent: sdkmath.ZeroInt(), + Withdrawn: sdkmath.ZeroInt(), } } func (p *Pool) CheckBalance(toSpend sdkmath.Int) error { - availablePool := p.Total.Sub(p.Spent) + availablePool := p.AvailableAmount() if availablePool.LT(toSpend) { return sdkerrors.Wrapf(ErrCampaignPoolBalance, "amount %s, available pool %s", toSpend, availablePool) } return nil } + +func (p *Pool) Spend(amount sdkmath.Int) { + p.Spent = p.Spent.Add(amount) +} + +func (p *Pool) TopUp(amount sdkmath.Int) { + p.Total = p.Total.Add(amount) +} + +func (p *Pool) Withdraw(amount sdkmath.Int) { + p.Withdrawn = p.Withdrawn.Add(amount) +} + +func (p *Pool) AvailableAmount() sdkmath.Int { + return p.Total.Sub(p.Withdrawn).Sub(p.Spent) +} diff --git a/x/reward/types/tx.pb.go b/x/reward/types/tx.pb.go index 6c7fa231..433e17a2 100644 --- a/x/reward/types/tx.pb.go +++ b/x/reward/types/tx.pb.go @@ -354,6 +354,8 @@ type MsgWithdrawFunds struct { Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty"` // ticket is the payload data. Ticket string `protobuf:"bytes,3,opt,name=ticket,proto3" json:"ticket,omitempty"` + // amount is the requested withdrawal amount + Amount cosmossdk_io_math.Int `protobuf:"bytes,4,opt,name=amount,proto3,customtype=cosmossdk.io/math.Int" json:"amount"` } func (m *MsgWithdrawFunds) Reset() { *m = MsgWithdrawFunds{} } @@ -461,37 +463,38 @@ func init() { func init() { proto.RegisterFile("sge/reward/tx.proto", fileDescriptor_ad69e28332238e66) } var fileDescriptor_ad69e28332238e66 = []byte{ - // 468 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0x41, 0x6f, 0xd3, 0x30, - 0x14, 0xc7, 0x1b, 0x82, 0x86, 0x78, 0x85, 0x69, 0x04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, 0x5e, 0x5e, 0xa9, 0xe7, 0xeb, 0xeb, 0x97, 0x64, 0xc1, 0x41, 0x23, - 0x59, 0x09, 0x39, 0xea, 0x5d, 0x4c, 0x43, 0xe7, 0x72, 0x1a, 0x3a, 0xbf, 0xa6, 0xa1, 0xf3, 0x75, - 0x16, 0xb6, 0x2e, 0x67, 0x61, 0xeb, 0xc7, 0x2c, 0x6c, 0x7d, 0x7e, 0x49, 0x99, 0x1e, 0x14, 0xa7, - 0x28, 0xe1, 0x59, 0xa4, 0x28, 0x39, 0x58, 0xf4, 0x34, 0xe7, 0xe8, 0xac, 0x7a, 0xc9, 0xce, 0x05, - 0x51, 0xa7, 0x5b, 0xf6, 0x81, 0x3a, 0xfc, 0x13, 0x00, 0x00, 0xff, 0xff, 0xb8, 0x77, 0xc5, 0x13, - 0xe4, 0x04, 0x00, 0x00, + // 487 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xc1, 0x6e, 0xd3, 0x40, + 0x10, 0x8d, 0x31, 0x0a, 0x62, 0x02, 0x55, 0x59, 0x68, 0x65, 0x8c, 0x70, 0xc0, 0x12, 0xa2, 0x1c, + 0x6a, 0x23, 0x2a, 0x2e, 0x1c, 0x13, 0x09, 0xc4, 0x21, 0x17, 0x8b, 0x0a, 0x89, 0x4b, 0xb5, 0xb5, + 0x97, 0x8d, 0x95, 0xd8, 0xbb, 0xf2, 0xae, 0x95, 0xf6, 0x23, 0x90, 0xf8, 0x11, 0x0e, 0xfc, 0x45, + 0x8f, 0x3d, 0x22, 0x0e, 0x11, 0x4a, 0xfe, 0x80, 0x2f, 0x40, 0xbb, 0xb1, 0x4d, 0x9c, 0x36, 0x91, + 0x03, 0xb7, 0x9d, 0x99, 0x37, 0xf3, 0xde, 0xf3, 0x8e, 0x17, 0xee, 0x0b, 0x4a, 0xfc, 0x8c, 0x4c, + 0x70, 0x16, 0xf9, 0xf2,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0xe0, 0x39, 0x27, 0xe2, 0xb4, 0xad, 0x1f, 0xb6, 0xa3, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x22, + 0x00, 0x46, 0xf8, 0x1c, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -938,6 +941,16 @@ func (m *MsgWithdrawFunds) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size := m.Amount.Size() + i -= size + if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 if len(m.Ticket) > 0 { i -= len(m.Ticket) copy(dAtA[i:], m.Ticket) @@ -1112,6 +1125,8 @@ func (m *MsgWithdrawFunds) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } + l = m.Amount.Size() + n += 1 + l + sovTx(uint64(l)) return n } @@ -1943,6 +1958,40 @@ func (m *MsgWithdrawFunds) Unmarshal(dAtA []byte) error { } m.Ticket = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + 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 ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) From 4eae9882d2f026b10ce39ffacf87f6c61b9df5a7 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Thu, 28 Mar 2024 09:53:08 +0300 Subject: [PATCH 13/28] test: fix missing withraw in pool --- x/reward/keeper/campaign_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/reward/keeper/campaign_test.go b/x/reward/keeper/campaign_test.go index aae62008..12b5926b 100644 --- a/x/reward/keeper/campaign_test.go +++ b/x/reward/keeper/campaign_test.go @@ -33,7 +33,7 @@ func createNCampaign(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.Camp items[i].RewardAmountType = types.RewardAmountType_REWARD_AMOUNT_TYPE_FIXED items[i].IsActive = true items[i].Meta = "campaign " + items[i].UID - items[i].Pool = types.Pool{Spent: sdk.ZeroInt(), Total: sdkmath.NewInt(100)} + items[i].Pool = types.Pool{Spent: sdk.ZeroInt(), Withdrawn: sdk.ZeroInt(), Total: sdkmath.NewInt(100)} keeper.SetCampaign(ctx, items[i]) } From 6be1551e35e374fa68bc0560ebaa96a97d13bbc3 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Thu, 28 Mar 2024 12:52:21 +0300 Subject: [PATCH 14/28] fix: commandline arg count campaign withdraw --- x/reward/client/cli/tx_campaign.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/reward/client/cli/tx_campaign.go b/x/reward/client/cli/tx_campaign.go index 39663183..e273b8be 100644 --- a/x/reward/client/cli/tx_campaign.go +++ b/x/reward/client/cli/tx_campaign.go @@ -98,7 +98,7 @@ func CmdWithdrawFunds() *cobra.Command { Use: "withdraw-funds [uid] [amount] [ticket]", Short: "Withdraw funds from a campaign", Long: "Withdrawal of the funds from a certain campaign", - Args: cobra.ExactArgs(2), + Args: cobra.ExactArgs(3), RunE: func(cmd *cobra.Command, args []string) (err error) { // Get indexes argUID := args[0] From 5480f239593fe548cb07961ed1332bd5bacb00ce Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Thu, 28 Mar 2024 13:35:39 +0300 Subject: [PATCH 15/28] fix: withdraw campaign wrong bank amount --- x/reward/keeper/msg_server_campaign.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/reward/keeper/msg_server_campaign.go b/x/reward/keeper/msg_server_campaign.go index 176f73be..5a18ef3b 100644 --- a/x/reward/keeper/msg_server_campaign.go +++ b/x/reward/keeper/msg_server_campaign.go @@ -186,7 +186,7 @@ func (k msgServer) WithdrawFunds(goCtx context.Context, msg *types.MsgWithdrawFu if err := k.modFunder.Refund( types.RewardPoolFunder{}, ctx, sdk.MustAccAddressFromBech32(payload.Promoter), - availableAmount, + msg.Amount, ); err != nil { return nil, sdkerrors.Wrapf(types.ErrWithdrawFromCampaignPool, "%s", err) } From c6d5de806d7747c201e538c3bf2cdc8a8419f966 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Thu, 28 Mar 2024 15:45:15 +0300 Subject: [PATCH 16/28] feat: campaing constraints and bet bonus --- proto/sge/reward/campaign.proto | 12 + proto/sge/reward/ticket.proto | 4 + x/reward/keeper/msg_server_campaign.go | 1 + x/reward/types/campaign.go | 2 + x/reward/types/campaign.pb.go | 302 ++++++++++++++++++++++--- x/reward/types/expected_keepers.go | 6 + x/reward/types/reward_bet_bonus.go | 20 +- x/reward/types/ticket.pb.go | 157 +++++++++---- 8 files changed, 420 insertions(+), 84 deletions(-) diff --git a/proto/sge/reward/campaign.proto b/proto/sge/reward/campaign.proto index 1f4382c7..4dd63ea8 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. @@ -74,4 +77,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 feefadbe..ac76d7ef 100644 --- a/x/reward/keeper/msg_server_campaign.go +++ b/x/reward/keeper/msg_server_campaign.go @@ -62,6 +62,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/types/campaign.go b/x/reward/types/campaign.go index 4d595fa8..417431b3 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, } } diff --git a/x/reward/types/campaign.pb.go b/x/reward/types/campaign.pb.go index 654c5fb0..cbd15c7b 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"` @@ -219,49 +228,92 @@ 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{ - // 536 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0x4f, 0x6f, 0xd3, 0x30, - 0x18, 0xc6, 0x6b, 0x9a, 0xb6, 0xa9, 0xbb, 0x15, 0x64, 0x98, 0x66, 0x3a, 0x29, 0x09, 0x45, 0x88, - 0x22, 0xb4, 0x44, 0xda, 0xc4, 0x85, 0xdb, 0x52, 0x90, 0xd8, 0x05, 0x21, 0x6f, 0xbb, 0x70, 0xa9, - 0xbc, 0xd4, 0xca, 0xa2, 0x35, 0x71, 0x64, 0xbb, 0x8c, 0x7e, 0x8b, 0x7d, 0xac, 0x1d, 0x77, 0x44, - 0x1c, 0x22, 0x94, 0xde, 0x76, 0xe4, 0x03, 0x20, 0x64, 0x27, 0xab, 0x36, 0xc4, 0xa6, 0x5d, 0xea, - 0xf7, 0xcf, 0xf3, 0xfc, 0xdc, 0xd8, 0xaf, 0xe1, 0x73, 0x19, 0xb3, 0x40, 0xb0, 0x33, 0x2a, 0xa6, - 0x41, 0x44, 0xd3, 0x9c, 0x26, 0x71, 0xe6, 0xe7, 0x82, 0x2b, 0x8e, 0x36, 0x64, 0xcc, 0x32, 0xa6, - 0xce, 0xb8, 0x38, 0xf5, 0x65, 0xcc, 0xfc, 0x4a, 0x35, 0x78, 0x16, 0xf3, 0x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xf1, 0x63, 0xe9, 0x34, 0xbe, 0xbe, 0x89, 0x13, - 0x75, 0x32, 0x3f, 0xf6, 0x23, 0x9e, 0x06, 0x32, 0x66, 0xdb, 0xf5, 0x71, 0xe9, 0x38, 0xf8, 0x7e, - 0xfd, 0xbe, 0xf4, 0x35, 0xcb, 0xe3, 0xb6, 0x79, 0x5f, 0xbb, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, - 0xad, 0x1c, 0x52, 0x91, 0xc2, 0x03, 0x00, 0x00, + // 602 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0x41, 0x4f, 0xdb, 0x30, + 0x14, 0xc7, 0x9b, 0xd1, 0x42, 0x70, 0xa1, 0x4c, 0x66, 0x08, 0x0f, 0xa4, 0x26, 0xcb, 0x34, 0xad, + 0xdb, 0x44, 0x22, 0x81, 0xb6, 0xc3, 0x6e, 0x24, 0x9b, 0x34, 0xa4, 0x69, 0x9a, 0x0c, 0x5c, 0xa6, + 0x49, 0x95, 0x49, 0xad, 0x10, 0xd1, 0xc4, 0x91, 0x6d, 0x06, 0xfd, 0x16, 0x7c, 0x2c, 0x0e, 0x3b, + 0x70, 0x9c, 0x76, 0x88, 0xa6, 0x70, 0xe3, 0xb8, 0x4f, 0x30, 0xd9, 0x4e, 0x3b, 0x3a, 0x01, 0xe3, + 0x52, 0xbf, 0xf7, 0xfc, 0xfe, 0xbf, 0xfc, 0x6b, 0x3f, 0x19, 0x3c, 0x16, 0x09, 0x0d, 0x38, 0x3d, + 0x21, 0x7c, 0x10, 0xc4, 0x24, 0x2b, 0x48, 0x9a, 0xe4, 0x7e, 0xc1, 0x99, 0x64, 0x70, 0x45, 0x24, + 0x34, 0xa7, 0xf2, 0x84, 0xf1, 0x23, 0x5f, 0x24, 0xd4, 0x37, 0x5d, 0x6b, 0x8f, 0x12, 0x96, 0x30, + 0xdd, 0x11, 0xa8, 0xc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6, + 0x78, 0xd8, 0x68, 0x3d, 0x01, 0x96, 0x6f, 0xb0, 0x0d, 0xbf, 0x82, 0x4e, 0x46, 0x4e, 0xfb, 0x07, + 0x54, 0x8e, 0xef, 0xd1, 0x38, 0x7d, 0xf3, 0xbf, 0x8f, 0xac, 0x98, 0x8f, 0x4c, 0x8b, 0x3d, 0xbc, + 0x90, 0x91, 0xd3, 0x90, 0x4a, 0x73, 0xb5, 0x61, 0x74, 0x5e, 0x75, 0xad, 0x8b, 0xaa, 0x6b, 0xfd, + 0xaa, 0xba, 0xd6, 0xd9, 0x65, 0xb7, 0x71, 0x71, 0xd9, 0x6d, 0xfc, 0xb8, 0xec, 0x36, 0xbe, 0xbc, + 0x48, 0x52, 0x79, 0x78, 0x7c, 0xe0, 0xc7, 0x2c, 0x0b, 0x44, 0x42, 0x37, 0xea, 0x53, 0x56, 0x71, + 0x70, 0x3a, 0x7e, 0x22, 0xd4, 0xa4, 0x8a, 0x83, 0x59, 0xfd, 0x44, 0x6c, 0xfd, 0x09, 0x00, 0x00, + 0xff, 0xff, 0x9e, 0x3a, 0x9b, 0xbe, 0x85, 0x04, 0x00, 0x00, } func (m *Campaign) Marshal() (dAtA []byte, err error) { @@ -284,6 +336,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-- @@ -420,6 +484,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 @@ -480,6 +577,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 } @@ -496,6 +597,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 } @@ -862,6 +974,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:]) @@ -1001,6 +1149,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/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..999150b8 100644 --- a/x/reward/types/reward_bet_bonus.go +++ b/x/reward/types/reward_bet_bonus.go @@ -4,6 +4,7 @@ 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" ) @@ -74,8 +75,23 @@ 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) + 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( 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, 0xf8, 0x5f, 0x27, 0x78, 0x13, 0xee, 0x2f, 0xc0, 0xea, 0xa5, 0x26, - 0x6a, 0x55, 0xba, 0x4f, 0x6f, 0x81, 0x68, 0xdd, 0xcb, 0xa2, 0xe1, 0x75, 0x28, 0x7b, 0x62, 0x40, - 0x6c, 0xe9, 0x1d, 0x53, 0x5d, 0x6b, 0xa2, 0x96, 0x66, 0x69, 0x9e, 0xe8, 0x29, 0x1f, 0x63, 0x28, - 0x8c, 0xa9, 0x24, 0x3a, 0xa8, 0x71, 0x28, 0x3b, 0x2a, 0xb0, 0x49, 0x30, 0xb0, 0x15, 0x6d, 0x45, - 0x5d, 0xb9, 0x66, 0x93, 0xa0, 0x1f, 0xf9, 0xc6, 0x16, 0x54, 0xf7, 0x02, 0xe7, 0x8a, 0xe1, 0x5e, - 0x4e, 0x09, 0x65, 0xa7, 0xb4, 0xc0, 0xbe, 0xb4, 0xc8, 0x6e, 0x74, 0x61, 0x75, 0xdf, 0x93, 0x87, - 0x0e, 0x27, 0x27, 0xef, 0x27, 0xbe, 0x23, 0x6e, 0xb1, 0x28, 0xc6, 0x77, 0x04, 0x0f, 0xe3, 0x6e, - 0x93, 0xec, 0x3e, 0x1b, 0x8f, 0x99, 0x1f, 0xd5, 0x70, 0x6a, 0x53, 0xef, 0xf8, 0xb2, 0x26, 0xf5, - 0xf1, 0x1b, 0x00, 0xc1, 0x26, 0xdc, 0xa6, 0x83, 0x89, 0xe7, 0x28, 0x15, 0x65, 0x73, 0x7d, 0x36, - 0x6d, 0x94, 0x77, 0xd4, 0xe9, 0xde, 0xc7, 0x8d, 0xdf, 0xd3, 0x46, 0x26, 0xc5, 0xca, 0xd8, 0xf3, - 0x2b, 0xca, 0x67, 0xae, 0xe8, 0x1d, 0x68, 0xa3, 0xd0, 0x1e, 0x38, 0x44, 0x12, 0xb5, 0x7b, 0x57, - 0x0c, 0x26, 0x5a, 0x83, 0xf6, 0x56, 0x68, 0x6f, 0x10, 0x49, 0x12, 0xa5, 0x56, 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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 0x70, 0x13, 0x10, 0xc5, 0xdf, 0x8c, 0x4a, 0x1b, 0x80, 0x64, + 0x4d, 0x96, 0x6c, 0x0a, 0x27, 0xd6, 0x1f, 0x08, 0x5a, 0x9a, 0x90, 0xcd, 0x94, 0xcd, 0xc3, 0x99, + 0x7c, 0x2b, 0x22, 0x03, 0xa8, 0x5d, 0x31, 0x55, 0x90, 0x5d, 0x73, 0x31, 0xef, 0x54, 0x6d, 0xa6, + 0x52, 0xcd, 0xe5, 0x41, 0x37, 0x37, 0xac, 0xfb, 0xfc, 0x53, 0x7c, 0x9a, 0x09, 0x3e, 0xe7, 0xd4, + 0x85, 0x72, 0x82, 0xa2, 0xa5, 0x6d, 0xef, 0x2e, 0xe6, 0x9d, 0x72, 0x0a, 0x91, 0x9c, 0xba, 0xc9, + 0x03, 0x7f, 0x07, 0x15, 0xca, 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:]) From 4075b43d44f5349f56a03bb3a4516068ae17260d Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Tue, 2 Apr 2024 08:54:24 +0300 Subject: [PATCH 17/28] test: bet bonus message server --- x/reward/keeper/msg_server_campaign_test.go | 34 ++-- x/reward/keeper/msg_server_reward_test.go | 186 +++++++++++++++++--- x/reward/types/campaign.go | 2 + 3 files changed, 184 insertions(+), 38 deletions(-) diff --git a/x/reward/keeper/msg_server_campaign_test.go b/x/reward/keeper/msg_server_campaign_test.go index 117fcc4a..310ea14a 100644 --- a/x/reward/keeper/msg_server_campaign_test.go +++ b/x/reward/keeper/msg_server_campaign_test.go @@ -42,9 +42,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) @@ -108,9 +110,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) @@ -212,9 +216,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 +262,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()) @@ -319,9 +325,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_reward_test.go b/x/reward/keeper/msg_server_reward_test.go index a4c2e79d..ada0a110 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,142 @@ 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), + } + 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{ + SubaccountAmount: sdkmath.NewInt(10), + UnlockPeriod: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), + } + 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 +859,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 +877,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 +894,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 +950,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/types/campaign.go b/x/reward/types/campaign.go index 417431b3..e5bfd3cc 100644 --- a/x/reward/types/campaign.go +++ b/x/reward/types/campaign.go @@ -49,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) } From 5a1455b84280d69aaf5862ae4778f5d52ab0733c Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Tue, 2 Apr 2024 14:07:01 +0300 Subject: [PATCH 18/28] feat: make constrainst mandatory for bet bonus --- x/reward/types/errors.go | 1 + x/reward/types/reward_bet_bonus.go | 3 +++ 2 files changed, 4 insertions(+) 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/reward_bet_bonus.go b/x/reward/types/reward_bet_bonus.go index 999150b8..852c4c53 100644 --- a/x/reward/types/reward_bet_bonus.go +++ b/x/reward/types/reward_bet_bonus.go @@ -34,6 +34,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 } From 1f4275c3653a274ef8d308a80cce950db080b286 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Wed, 3 Apr 2024 20:52:43 +0300 Subject: [PATCH 19/28] fix: check promoter --- x/reward/keeper/msg_server_campaign.go | 4 ++++ x/reward/keeper/msg_server_promoter.go | 4 ++++ x/reward/keeper/promoter.go | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/x/reward/keeper/msg_server_campaign.go b/x/reward/keeper/msg_server_campaign.go index 8ca6bd2c..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 { 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/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)) +} From 25ede28e8af2a776a09ebee8b96a52be0aa9ec29 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Wed, 3 Apr 2024 21:17:07 +0300 Subject: [PATCH 20/28] test: fix campaign promoter --- x/reward/keeper/msg_server_campaign_test.go | 28 ++++++++++++++++++++- x/reward/keeper/msg_server_reward_test.go | 3 +++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/x/reward/keeper/msg_server_campaign_test.go b/x/reward/keeper/msg_server_campaign_test.go index 310ea14a..86524218 100644 --- a/x/reward/keeper/msg_server_campaign_test.go +++ b/x/reward/keeper/msg_server_campaign_test.go @@ -22,12 +22,28 @@ 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(), @@ -76,6 +92,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) @@ -147,10 +165,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) @@ -203,6 +225,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(), @@ -273,6 +297,8 @@ func TestCampaignMsgServerUpdateWithAuthorization(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) diff --git a/x/reward/keeper/msg_server_reward_test.go b/x/reward/keeper/msg_server_reward_test.go index ada0a110..31978c8f 100644 --- a/x/reward/keeper/msg_server_reward_test.go +++ b/x/reward/keeper/msg_server_reward_test.go @@ -708,6 +708,9 @@ func TestMsgApplyBetBonus(t *testing.T) { SubaccountAmount: sdkmath.NewInt(10), UnlockPeriod: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), } + betBonusCampClaims["constraints"] = types.CampaignConstraints{ + MaxBetAmount: sdkmath.NewInt(300), + } betBonusCampUID := createCampaign(t, k, srv, ctx, promoter, betBonusCampClaims, defaultCategoryCap) betBonusClaims := jwt.MapClaims{ From 0ff45969ed7ef02323362c109eb13643f963d68a Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Wed, 3 Apr 2024 21:23:37 +0300 Subject: [PATCH 21/28] lint: gofumpt --- x/reward/keeper/msg_server_campaign_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/reward/keeper/msg_server_campaign_test.go b/x/reward/keeper/msg_server_campaign_test.go index 86524218..f64de9b0 100644 --- a/x/reward/keeper/msg_server_campaign_test.go +++ b/x/reward/keeper/msg_server_campaign_test.go @@ -35,6 +35,7 @@ func setTestPromoter(k *keeper.Keeper, ctx sdk.Context, promoterAddr string) { Address: promoterAddr, }) } + func TestCampaignMsgServerCreate(t *testing.T) { k, ctx := setupKeeper(t) srv := keeper.NewMsgServerImpl(*k) From 0cf4d1c6dbca9b574dacfd74680bc6ead17b1bf7 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Thu, 4 Apr 2024 14:28:21 +0300 Subject: [PATCH 22/28] feat: if the bet is not settled, prevent bet bonus reward --- x/reward/types/reward_bet_bonus.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/x/reward/types/reward_bet_bonus.go b/x/reward/types/reward_bet_bonus.go index 852c4c53..7644e39c 100644 --- a/x/reward/types/reward_bet_bonus.go +++ b/x/reward/types/reward_bet_bonus.go @@ -7,6 +7,7 @@ import ( 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) @@ -78,6 +79,10 @@ 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) } + if bet.Status != bettypes.Bet_STATUS_SETTLED { + return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "bet should be settled") + } + effectiveBetAmount := sdk.NewDecFromInt(bet.Amount) if campaign.Constraints != nil { if !campaign.Constraints.MaxBetAmount.IsNil() && campaign.Constraints.MaxBetAmount.GT(sdkmath.ZeroInt()) { From 2cf1d86c6430c8e4dc97612f405504fae700f281 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Thu, 4 Apr 2024 17:42:07 +0300 Subject: [PATCH 23/28] fix: change condition of the bet result for bet bonus --- x/reward/types/reward_bet_bonus.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x/reward/types/reward_bet_bonus.go b/x/reward/types/reward_bet_bonus.go index 7644e39c..1c512c82 100644 --- a/x/reward/types/reward_bet_bonus.go +++ b/x/reward/types/reward_bet_bonus.go @@ -79,8 +79,9 @@ 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) } - if bet.Status != bettypes.Bet_STATUS_SETTLED { - return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "bet should be settled") + 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) From 2b523b7faf71c363c95033595e27bad0ea6b0687 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Thu, 4 Apr 2024 17:49:10 +0300 Subject: [PATCH 24/28] test: fix the bet result to be winner or loser --- x/reward/keeper/msg_server_reward_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x/reward/keeper/msg_server_reward_test.go b/x/reward/keeper/msg_server_reward_test.go index 31978c8f..06ce5291 100644 --- a/x/reward/keeper/msg_server_reward_test.go +++ b/x/reward/keeper/msg_server_reward_test.go @@ -688,6 +688,8 @@ func TestMsgApplyBetBonus(t *testing.T) { 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) From 45380ad40868a1d4afd955976c98c6f1c364fec2 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Thu, 4 Apr 2024 20:38:15 +0300 Subject: [PATCH 25/28] fix: main account and subaccount interchange funds --- x/reward/types/reward_bet_bonus.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/reward/types/reward_bet_bonus.go b/x/reward/types/reward_bet_bonus.go index 1c512c82..2e77d694 100644 --- a/x/reward/types/reward_bet_bonus.go +++ b/x/reward/types/reward_bet_bonus.go @@ -106,8 +106,8 @@ func (sur BetBonusReward) Calculate(goCtx context.Context, ctx sdk.Context, keep NewReceiver( subAccountAddressString, payload.Common.Receiver, - mainAmount, subAmount, + mainAmount, campaign.RewardAmount.UnlockPeriod, ), payload.Common, From 6e6b60f8e67b181ba895d14398164c7f902e090f Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Thu, 4 Apr 2024 20:49:59 +0300 Subject: [PATCH 26/28] test: fix subaccount duplicate reward grant --- x/reward/keeper/msg_server_reward_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/reward/keeper/msg_server_reward_test.go b/x/reward/keeper/msg_server_reward_test.go index 06ce5291..030a915e 100644 --- a/x/reward/keeper/msg_server_reward_test.go +++ b/x/reward/keeper/msg_server_reward_test.go @@ -707,8 +707,8 @@ func TestMsgApplyBetBonus(t *testing.T) { betBonusCampClaims["reward_type"] = types.RewardType_REWARD_TYPE_BET_DISCOUNT betBonusCampClaims["reward_amount_type"] = types.RewardAmountType_REWARD_AMOUNT_TYPE_PERCENTAGE betBonusCampClaims["reward_amount"] = types.RewardAmount{ - SubaccountAmount: sdkmath.NewInt(10), - UnlockPeriod: uint64(ctx.BlockTime().Add(10 * time.Minute).Unix()), + MainAccountAmount: sdkmath.NewInt(10), + UnlockPeriod: 0, } betBonusCampClaims["constraints"] = types.CampaignConstraints{ MaxBetAmount: sdkmath.NewInt(300), From 80bce182400b3ad5777c35223cd64ce3c4497b26 Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Fri, 5 Apr 2024 16:10:14 +0300 Subject: [PATCH 27/28] feat: include withdrawn in upgrade handler --- app/upgrades/v8/upgrades.go | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/app/upgrades/v8/upgrades.go b/app/upgrades/v8/upgrades.go index 41a912c5..943a9e40 100644 --- a/app/upgrades/v8/upgrades.go +++ b/app/upgrades/v8/upgrades.go @@ -1,6 +1,7 @@ package v8 import ( + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" @@ -19,6 +20,7 @@ func CreateUpgradeHandler( promoters := make(map[string]struct{}) for _, c := range allCampaigns { c.CapCount = 0 // infinite cap for all campaigns + c.Pool.Withdrawn = sdkmath.ZeroInt() k.RewardKeeper.SetCampaign(ctx, c) promoters[c.Promoter] = struct{}{} } @@ -28,23 +30,25 @@ func CreateUpgradeHandler( promoterAddresses = append(promoterAddresses, addr) } - promoterUID := uuid.NewString() - k.RewardKeeper.SetPromoter(ctx, types.Promoter{ - Creator: promoterAddresses[0], - UID: promoterUID, - Addresses: promoterAddresses, - Conf: types.PromoterConf{ - CategoryCap: []types.CategoryCap{ - {Category: types.RewardCategory_REWARD_CATEGORY_SIGNUP, CapPerAcc: 1}, + if len(promoterAddresses) > 0 { + promoterUID := uuid.NewString() + k.RewardKeeper.SetPromoter(ctx, types.Promoter{ + Creator: promoterAddresses[0], + UID: promoterUID, + Addresses: promoterAddresses, + Conf: types.PromoterConf{ + CategoryCap: []types.CategoryCap{ + {Category: types.RewardCategory_REWARD_CATEGORY_SIGNUP, CapPerAcc: 1}, + }, }, - }, - }) - - for _, addr := range promoterAddresses { - k.RewardKeeper.SetPromoterByAddress(ctx, types.PromoterByAddress{ - PromoterUID: promoterUID, - Address: addr, }) + + for _, addr := range promoterAddresses { + k.RewardKeeper.SetPromoterByAddress(ctx, types.PromoterByAddress{ + PromoterUID: promoterUID, + Address: addr, + }) + } } return mm.RunMigrations(ctx, configurator, fromVM) From b423944649dd707bfc960e1730a0fcce3a4956fa Mon Sep 17 00:00:00 2001 From: scorpioborn <97235353+scorpioborn@users.noreply.github.com> Date: Sun, 7 Apr 2024 15:17:35 +0300 Subject: [PATCH 28/28] feat: prevent non main market bets for bet bonus grant --- x/reward/keeper/msg_server_reward_test.go | 3 +++ x/reward/types/reward_bet_bonus.go | 12 +++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/x/reward/keeper/msg_server_reward_test.go b/x/reward/keeper/msg_server_reward_test.go index 030a915e..7a723053 100644 --- a/x/reward/keeper/msg_server_reward_test.go +++ b/x/reward/keeper/msg_server_reward_test.go @@ -690,6 +690,9 @@ func TestMsgApplyBetBonus(t *testing.T) { Amount: sdkmath.NewInt(301), Result: bettypes.Bet_RESULT_LOST, Status: bettypes.Bet_STATUS_SETTLED, + Meta: bettypes.MetaData{ + IsMainMarket: true, + }, } tApp.BetKeeper.SetBet(ctx, bet, 1) diff --git a/x/reward/types/reward_bet_bonus.go b/x/reward/types/reward_bet_bonus.go index 2e77d694..f387dc51 100644 --- a/x/reward/types/reward_bet_bonus.go +++ b/x/reward/types/reward_bet_bonus.go @@ -79,6 +79,10 @@ 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) } + if !bet.Meta.IsMainMarket { + return RewardFactoryData{}, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "bet bonus grant is allowed for main market bets only %s", payload.BetUID) + } + 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) @@ -87,11 +91,9 @@ func (sur BetBonusReward) Calculate(goCtx context.Context, ctx sdk.Context, keep 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), - ) - } + effectiveBetAmount = sdk.NewDecFromInt( + sdkmath.MinInt(campaign.Constraints.MaxBetAmount, bet.Amount), + ) } }