Skip to content

Commit

Permalink
CNS-784: added events for plans and projects
Browse files Browse the repository at this point in the history
  • Loading branch information
oren-lava committed Dec 27, 2023
1 parent 8716c13 commit 1dfbec7
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 4 deletions.
10 changes: 10 additions & 0 deletions x/plans/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This document focuses on the plans' technical aspects and does not include curre
* [Queries](#queries)
* [Transactions](#transactions)
* [Proposals](#proposals)
* [Events](#events)

## Concepts

Expand Down Expand Up @@ -249,3 +250,12 @@ A valid `plans-del` JSON proposal format:
}
```

## Events

The plans module has the following events:

| Event | When it happens |
| ---------- | --------------- |
| `add_new_plan_to_storage` | a successful addition of a plan |
| `del_plan_from_storage` | a successful deletion of a plan |

4 changes: 2 additions & 2 deletions x/plans/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func handlePlansAddProposal(ctx sdk.Context, k keeper.Keeper, p *types.PlansAddP
}

details := map[string]string{"planDetails": planElem.String()}
utils.LogLavaEvent(ctx, logger, "add_new_plan_to_storage", details, "Gov Proposal Accepted Plans")
utils.LogLavaEvent(ctx, logger, types.PlanAddEventName, details, "Gov Proposal Accepted Plans")
}
return nil
}
Expand All @@ -56,7 +56,7 @@ func handlePlansDelProposal(ctx sdk.Context, k keeper.Keeper, p *types.PlansDelP
}

details := map[string]string{"index": index}
utils.LogLavaEvent(ctx, logger, "del_plan_from_storage", details, "Gov Proposal Accepted Plans")
utils.LogLavaEvent(ctx, logger, types.PlanDelEventName, details, "Gov Proposal Accepted Plans")
}
return nil
}
5 changes: 5 additions & 0 deletions x/plans/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ const (
MAX_LEN_PLAN_DESCRIPTION = 500
MAX_LEN_PLAN_TYPE = 20
)

const (
PlanAddEventName = "add_new_plan_to_storage"
PlanDelEventName = "del_plan_from_storage"
)
12 changes: 12 additions & 0 deletions x/projects/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Note that the plans module is closely connected to the subscription and projects
* [Project Policy YAML](#project-policy-yaml)
* [Project Keys YAML](#project-keys-yaml)
* [Proposals](#proposals)
* [Events](#events)

## Concepts

Expand Down Expand Up @@ -205,3 +206,14 @@ All fields are mandatory.
## Proposals

The projects module does not support any proposals.

## Events

The projects module has the following events:

| Event | When it happens |
| ---------- | --------------- |
| `add_key_to_project_event` | a successful addition of a project key |
| `del_key_from_project_event` | a successful deletion of a project key |
| `set_admin_policy_event` | a successful set of project's admin policy |
| `set_subscription_policy_event` | a successful set of project's subscription policy |
15 changes: 15 additions & 0 deletions x/projects/keeper/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ func (k Keeper) SetProjectPolicy(ctx sdk.Context, projectIDs []string, policy *p
)
}

projectIDsStr := ""
for _, projectID := range projectIDs {
projectNextEpoch, _, err := k.getProjectForBlock(ctx, projectID, nextEpoch)
if err != nil {
Expand Down Expand Up @@ -326,6 +327,20 @@ func (k Keeper) SetProjectPolicy(ctx sdk.Context, projectIDs []string, policy *p
utils.Attribute{Key: "block", Value: ctxBlock},
)
}

projectIDsStr += projectID + ", "
}

details := map[string]string{
"creator": key,
"project_ids": projectIDsStr,
"policy": policy.String(),
}

if setPolicyEnum == types.SET_ADMIN_POLICY {
utils.LogLavaEvent(ctx, k.Logger(ctx), types.SetAdminPolicyEventName, details, "set admin policy successfully")
} else if setPolicyEnum == types.SET_SUBSCRIPTION_POLICY {
utils.LogLavaEvent(ctx, k.Logger(ctx), types.SetSubscriptionPolicyEventName, details, "set admin policy successfully")
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions x/projects/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const (
)

const (
AddProjectKeyEventName = "add_key_to_project_event"
DelProjectKeyEventName = "del_key_from_project_event"
AddProjectKeyEventName = "add_key_to_project_event"
DelProjectKeyEventName = "del_key_from_project_event"
SetAdminPolicyEventName = "set_admin_policy_event"
SetSubscriptionPolicyEventName = "set_subscription_policy_event"
)

0 comments on commit 1dfbec7

Please sign in to comment.