Skip to content

Commit

Permalink
refactor: remove house uid tem
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpioborn committed Nov 5, 2023
1 parent 7ef4e33 commit 5adb8f0
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 492 deletions.
27 changes: 10 additions & 17 deletions proto/sge/reward/campaign.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,52 +18,45 @@ message Campaign {
json_name = "uid"
];

// house_uid is the unique identifier of the promoter house.
string house_uid = 3 [
(gogoproto.customname) = "HouseUID",
(gogoproto.jsontag) = "house_uid",
json_name = "house_uid"
];

// promoter is the address of campaign promoter.
// Funds for the campaign would be deducted from this account.
string promoter = 4;
string promoter = 3;

// start_ts is the start timestamp of a campaign.
uint64 start_ts = 5 [
uint64 start_ts = 4 [
(gogoproto.customname) = "StartTS",
(gogoproto.jsontag) = "start_ts",
json_name = "start_ts"
];

// end_ts is the end timestamp of a campaign.
uint64 end_ts = 6 [
uint64 end_ts = 5 [
(gogoproto.customname) = "EndTS",
(gogoproto.jsontag) = "end_ts",
json_name = "end_ts"
];

// reward_category is the category of reward.
RewardCategory reward_category = 7;
RewardCategory reward_category = 6;

// reward_type is the type of reward.
RewardType reward_type = 8;
RewardType reward_type = 7;

// amount_type is the type of reward amount.
RewardAmountType reward_amount_type = 9;
RewardAmountType reward_amount_type = 8;

// amount is the amount of reward.
RewardAmount reward_amount = 10;
RewardAmount reward_amount = 9;

// pool is the tracker of pool funds of the campaign.
Pool pool = 11 [ (gogoproto.nullable) = false ];
Pool pool = 10 [ (gogoproto.nullable) = false ];

// is_active is the flag to check if the campaign is active or not.
bool is_active = 12;
bool is_active = 11;

// meta is the metadata of the campaign.
// It is a stringified base64 encoded json.
string meta = 13;
string meta = 12;
}

// Pool is the type for the campaign funding pool.
Expand Down
3 changes: 1 addition & 2 deletions proto/sge/reward/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ service Query {

// Queries a specific Campaign item.
rpc Campaign(QueryCampaignRequest) returns (QueryCampaignResponse) {
option (google.api.http).get = "/sge-network/sge/reward/campaign/{house_uid}/{uid}";
option (google.api.http).get = "/sge-network/sge/reward/campaign/{uid}";
}

// Queries list of all Campaign items.
Expand Down Expand Up @@ -73,7 +73,6 @@ message QueryParamsResponse {
// QueryCampaignRequest is request body of the query campaign endpoint.
message QueryCampaignRequest {
string uid = 1;
string house_uid = 2;
}

// QueryCampaignRequest is response body of the query campaign endpoint.
Expand Down
14 changes: 4 additions & 10 deletions proto/sge/reward/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ message MsgCreateCampaign {
string creator = 1;
// uid is the unique identifier of the campaign.
string uid = 2;
// house_uid is the unique identifier of the promoter house.
string house_uid = 3;
// ticket is the payload data.
string ticket = 4;
string ticket = 3;
}

// MsgCreateCampaignResponse campaign create message response type.
Expand All @@ -37,10 +35,8 @@ message MsgUpdateCampaign {
string creator = 1;
// uid is the unique identifier of the campaign.
string uid = 2;
// house_uid is the unique identifier of the promoter house.
string house_uid = 3;
// ticket is the payload data.
string ticket = 4;
string ticket = 3;
}

// MsgUpdateCampaignResponse campaign update message response type.
Expand All @@ -54,16 +50,14 @@ message MsgGrantReward {
string uid = 2;
// campaign_uid is the unique identifier of the reward campaign.
string campaign_uid = 3;
// house_uid is the unique identifier of the promoter house.
string house_uid = 4;
// created_at is the time when the reward is created.
uint64 created_at = 5 [
uint64 created_at = 4 [
(gogoproto.customname) = "CreatedAt",
(gogoproto.jsontag) = "created_at",
json_name = "created_at"
];
// ticket is the payload data.
string ticket = 6;
string ticket = 5;
}

// MsgGrantSignupRewardResponse execute signup reward message response type.
Expand Down
9 changes: 4 additions & 5 deletions x/reward/keeper/campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ func (k Keeper) SetCampaign(ctx sdk.Context, campaign types.Campaign) {
b := k.cdc.MustMarshal(&campaign)
store.Set(types.GetCampaignKey(
campaign.UID,
campaign.HouseUID,
), b)
}

// GetCampaign returns a campaign from its index
func (k Keeper) GetCampaign(
ctx sdk.Context,
houseUID, uid string,
uid string,
) (val types.Campaign, found bool) {
store := k.getCampaignStore(ctx)

b := store.Get(types.GetCampaignKey(houseUID, uid))
b := store.Get(types.GetCampaignKey(uid))
if b == nil {
return val, false
}
Expand All @@ -35,10 +34,10 @@ func (k Keeper) GetCampaign(
// RemoveCampaign removes a campaign from the store
func (k Keeper) RemoveCampaign(
ctx sdk.Context,
houseUID, uid string,
uid string,
) {
store := k.getCampaignStore(ctx)
store.Delete(types.GetCampaignKey(houseUID, uid))
store.Delete(types.GetCampaignKey(uid))
}

// GetAllCampaign returns all campaign
Expand Down
4 changes: 2 additions & 2 deletions x/reward/keeper/msg_server_campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (k msgServer) CreateCampaign(goCtx context.Context, msg *types.MsgCreateCam
ctx := sdk.UnwrapSDKContext(goCtx)

// Check if the value already exists
_, isFound := k.GetCampaign(ctx, msg.HouseUid, msg.Uid)
_, isFound := k.GetCampaign(ctx, msg.Uid)
if isFound {
return nil, sdkerrors.Wrap(sdkerrtypes.ErrInvalidRequest, "index already set")
}
Expand Down Expand Up @@ -87,7 +87,7 @@ func (k msgServer) UpdateCampaign(goCtx context.Context, msg *types.MsgUpdateCam
}

// Check if the value exists
valFound, isFound := k.GetCampaign(ctx, msg.HouseUid, msg.Uid)
valFound, isFound := k.GetCampaign(ctx, msg.Uid)
if !isFound {
return nil, sdkerrors.Wrap(sdkerrtypes.ErrKeyNotFound, "index not set")
}
Expand Down
2 changes: 1 addition & 1 deletion x/reward/keeper/msg_server_reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
func (k msgServer) GrantReward(goCtx context.Context, msg *types.MsgGrantReward) (*types.MsgGrantRewardResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

campaign, isFound := k.GetCampaign(ctx, msg.HouseUid, msg.CampaignUid)
campaign, isFound := k.GetCampaign(ctx, msg.CampaignUid)
if !isFound {
return nil, sdkerrors.Wrap(sdkerrtypes.ErrInvalidRequest, "campaign with the uid not found")
}
Expand Down
1 change: 0 additions & 1 deletion x/reward/keeper/query_campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func (k Keeper) Campaign(goCtx context.Context, req *types.QueryCampaignRequest)

val, found := k.GetCampaign(
ctx,
req.HouseUid,
req.Uid,
)
if !found {
Expand Down
Loading

0 comments on commit 5adb8f0

Please sign in to comment.