Skip to content

Commit

Permalink
feat: ADR-011: Reports module (#860)
Browse files Browse the repository at this point in the history
## Description

This PR implements the `x/reports` module as detailed inside [ADR-011](https://github.com/desmos-labs/desmos/blob/master/docs/architecture/adr-011-reports-module.md).

Depends-On: #847 

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://docs.cosmos.network/v0.44/building-modules/intro.html)
- [x] included the necessary unit and integration [tests](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
RiccardoM authored Jun 7, 2022
1 parent 2defa30 commit 40f3e5c
Show file tree
Hide file tree
Showing 81 changed files with 22,579 additions and 3,307 deletions.
2 changes: 2 additions & 0 deletions .changeset/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ modules:
description: Subspaces
- id: x/posts
description: Posts
- id: x/reports
description: Reports
- id: x/fees
description: Fees
- id: x/supply
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: feat
module: x/reports
pull_request: 860
description: Added the new `x/reports` module
backward_compatible: true
date: 2022-05-30T09:02:36.66780769Z
39 changes: 35 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ import (
profileskeeper "github.com/desmos-labs/desmos/v3/x/profiles/keeper"
profilestypes "github.com/desmos-labs/desmos/v3/x/profiles/types"
relationshipskeeper "github.com/desmos-labs/desmos/v3/x/relationships/keeper"
"github.com/desmos-labs/desmos/v3/x/reports"
reportskeeper "github.com/desmos-labs/desmos/v3/x/reports/keeper"
reportstypes "github.com/desmos-labs/desmos/v3/x/reports/types"

"github.com/desmos-labs/desmos/v3/x/subspaces"
subspaceskeeper "github.com/desmos-labs/desmos/v3/x/subspaces/keeper"
Expand Down Expand Up @@ -239,6 +242,7 @@ var (
relationships.AppModuleBasic{},
subspaces.AppModuleBasic{},
posts.AppModuleBasic{},
reports.AppModuleBasic{},
fees.AppModuleBasic{},
supply.AppModuleBasic{},
)
Expand Down Expand Up @@ -305,6 +309,7 @@ type DesmosApp struct {
ProfileKeeper profileskeeper.Keeper
RelationshipsKeeper relationshipskeeper.Keeper
PostsKeeper postskeeper.Keeper
ReportsKeeper reportskeeper.Keeper
SupplyKeeper supplykeeper.Keeper

// Module Manager
Expand Down Expand Up @@ -353,7 +358,7 @@ func NewDesmosApp(

// Custom modules
profilestypes.StoreKey, relationshipstypes.StoreKey, subspacestypes.StoreKey,
poststypes.StoreKey,
poststypes.StoreKey, reportstypes.StoreKey,
feestypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -486,20 +491,39 @@ func NewDesmosApp(
profilesIBCModule := profiles.NewIBCModule(app.appCodec, app.ProfileKeeper)

// Create posts keeper and module
app.PostsKeeper = postskeeper.NewKeeper(
postsKeeper := postskeeper.NewKeeper(
app.appCodec,
keys[poststypes.StoreKey],
app.GetSubspace(poststypes.ModuleName),
&subspacesKeeper,
app.RelationshipsKeeper,
)

// Create reports keeper
app.ReportsKeeper = reportskeeper.NewKeeper(
app.appCodec,
keys[reportstypes.StoreKey],
app.GetSubspace(reportstypes.ModuleName),
&subspacesKeeper,
app.RelationshipsKeeper,
&postsKeeper,
)

// Register the posts hooks
// NOTE: postsKeeper above is passed by reference, so that it will contain these hooks
app.PostsKeeper = *postsKeeper.SetHooks(
poststypes.NewMultiPostsHooks(
app.ReportsKeeper.Hooks(),
),
)

// Register the subspaces hooks
// NOTE: subspacesKeeper above is passed by reference, so that it will contain these hooks
app.SubspacesKeeper = *subspacesKeeper.SetHooks(
subspacestypes.NewMultiSubspacesHooks(
app.RelationshipsKeeper.Hooks(),
app.PostsKeeper.Hooks(),
app.ReportsKeeper.Hooks(),
),
)

Expand Down Expand Up @@ -606,6 +630,7 @@ func NewDesmosApp(
profilesModule,
relationships.NewAppModule(appCodec, app.RelationshipsKeeper, app.SubspacesKeeper, profilesv4.NewKeeper(keys[profilestypes.StoreKey], appCodec), app.AccountKeeper, app.BankKeeper, app.FeesKeeper),
posts.NewAppModule(appCodec, app.PostsKeeper, app.SubspacesKeeper, app.AccountKeeper, app.BankKeeper, app.FeesKeeper),
reports.NewAppModule(appCodec, app.ReportsKeeper, app.SubspacesKeeper, app.PostsKeeper, app.AccountKeeper, app.BankKeeper, app.FeesKeeper),
supply.NewAppModule(appCodec, legacyAmino, app.SupplyKeeper),
)

Expand Down Expand Up @@ -640,6 +665,7 @@ func NewDesmosApp(
relationshipstypes.ModuleName,
profilestypes.ModuleName,
poststypes.ModuleName,
reportstypes.ModuleName,
supplytypes.ModuleName,
)
app.mm.SetOrderEndBlockers(
Expand Down Expand Up @@ -668,6 +694,7 @@ func NewDesmosApp(
relationshipstypes.ModuleName,
profilestypes.ModuleName,
poststypes.ModuleName,
reportstypes.ModuleName,
supplytypes.ModuleName,
)

Expand Down Expand Up @@ -703,6 +730,7 @@ func NewDesmosApp(
profilestypes.ModuleName,
relationshipstypes.ModuleName,
poststypes.ModuleName,
reportstypes.ModuleName,
supplytypes.ModuleName,

crisistypes.ModuleName,
Expand Down Expand Up @@ -737,6 +765,7 @@ func NewDesmosApp(
relationshipstypes.ModuleName,
profilestypes.ModuleName,
poststypes.ModuleName,
reportstypes.ModuleName,
supplytypes.ModuleName,

crisistypes.ModuleName,
Expand Down Expand Up @@ -780,6 +809,7 @@ func NewDesmosApp(
profilesModule,
relationships.NewAppModule(appCodec, app.RelationshipsKeeper, app.SubspacesKeeper, profilesv4.NewKeeper(keys[profilestypes.StoreKey], appCodec), app.AccountKeeper, app.BankKeeper, app.FeesKeeper),
posts.NewAppModule(appCodec, app.PostsKeeper, app.SubspacesKeeper, app.AccountKeeper, app.BankKeeper, app.FeesKeeper),
reports.NewAppModule(appCodec, app.ReportsKeeper, app.SubspacesKeeper, app.PostsKeeper, app.AccountKeeper, app.BankKeeper, app.FeesKeeper),
)

app.sm.RegisterStoreDecoders()
Expand Down Expand Up @@ -958,7 +988,7 @@ func (app *DesmosApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.API

// register swagger API from root so that other applications can override easily
if apiConfig.Swagger {
RegisterSwaggerAPI(clientCtx, apiSvr.Router)
RegisterSwaggerAPI(apiSvr.Router)
}
}

Expand Down Expand Up @@ -994,7 +1024,7 @@ func (app *DesmosApp) registerUpgrade(upgrade upgrades.Upgrade) {
}

// RegisterSwaggerAPI registers swagger route with API Server
func RegisterSwaggerAPI(ctx client.Context, rtr *mux.Router) {
func RegisterSwaggerAPI(rtr *mux.Router) {
statikFS, err := fs.New()
if err != nil {
panic(err)
Expand Down Expand Up @@ -1033,6 +1063,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(subspacestypes.ModuleName)
paramsKeeper.Subspace(profilestypes.ModuleName)
paramsKeeper.Subspace(poststypes.ModuleName)
paramsKeeper.Subspace(reportstypes.ModuleName)

return paramsKeeper
}
6 changes: 6 additions & 0 deletions app/params/weights.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ const (
DefaultWeightMsgAddPostAttachment int = 50
DefaultWeightMsgRemovePostAttachment int = 50
DefaultWeightMsgAnswerPoll int = 50

DefaultWeightMsgCreateReport int = 50
DefaultWeightMsgDeleteReport int = 35
DefaultWeightMsgSupportStandardReason int = 20
DefaultWeightMsgAddReason int = 10
DefaultWeightMsgRemoveReason int = 10
)
9 changes: 4 additions & 5 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ import (
"path/filepath"
"testing"

poststypes "github.com/desmos-labs/desmos/v3/x/posts/types"

feestypes "github.com/desmos-labs/desmos/v3/x/fees/types"

poststypes "github.com/desmos-labs/desmos/v3/x/posts/types"
relationshipstypes "github.com/desmos-labs/desmos/v3/x/relationships/types"
reportstypes "github.com/desmos-labs/desmos/v3/x/reports/types"
subspacestypes "github.com/desmos-labs/desmos/v3/x/subspaces/types"

authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"

subspacestypes "github.com/desmos-labs/desmos/v3/x/subspaces/types"

banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
Expand Down Expand Up @@ -255,6 +253,7 @@ func TestAppImportExport(t *testing.T) {
{app.keys[profilestypes.StoreKey], newApp.keys[profilestypes.StoreKey], [][]byte{}},
{app.keys[relationshipstypes.StoreKey], newApp.keys[relationshipstypes.StoreKey], [][]byte{}},
{app.keys[poststypes.StoreKey], newApp.keys[poststypes.StoreKey], [][]byte{}},
{app.keys[reportstypes.StoreKey], newApp.keys[reportstypes.StoreKey], [][]byte{}},
}

for _, skp := range storeKeysPrefixes {
Expand Down
8 changes: 8 additions & 0 deletions client/docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
}
}
},
{
"url": "./tmp-swagger-gen/desmos/reports/v1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "ReportsParams"
}
}
},
{
"url": "./tmp-swagger-gen/desmos/fees/v1/query.swagger.json",
"operationIds": {
Expand Down
Loading

0 comments on commit 40f3e5c

Please sign in to comment.