Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ADR-016: Reactions module #898

Merged
merged 54 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
beb6468
added x/reactions types
RiccardoM Jun 7, 2022
12bb641
Merge branch 'master' of github.com:desmos-labs/desmos into riccardo/…
RiccardoM Jun 7, 2022
d1df146
updated ADR
RiccardoM Jun 7, 2022
e3087c4
added the query types
RiccardoM Jun 7, 2022
e6b8fe2
started to implement the keeper methods
RiccardoM Jun 7, 2022
5a4110e
added MsgEditRegisteredReaction
RiccardoM Jun 7, 2022
90205bf
added keeper tests and improved messages and reactions
RiccardoM Jun 7, 2022
67a39ce
added external hooks tests
RiccardoM Jun 8, 2022
24993d4
Merge branch 'master' of github.com:desmos-labs/desmos into riccardo/…
RiccardoM Jun 8, 2022
5338e44
added keeper genesis and improved hooks
RiccardoM Jun 8, 2022
a2e9df1
added gRPC query methods implementation
RiccardoM Jun 8, 2022
fefc091
added gRPC server tests
RiccardoM Jun 8, 2022
4df886a
added the invariants
RiccardoM Jun 8, 2022
d3524e8
added migrations
RiccardoM Jun 8, 2022
da76992
added the msg server implementation
RiccardoM Jun 8, 2022
1e7a83d
Merge branch 'master' of github.com:desmos-labs/desmos into riccardo/…
RiccardoM Jun 8, 2022
f4cf872
updated permissions with latest changes
RiccardoM Jun 9, 2022
7fd784c
Merge branch 'master' of github.com:desmos-labs/desmos into riccardo/…
RiccardoM Jun 9, 2022
84b6944
fixed tests
RiccardoM Jun 9, 2022
0fb36f8
added profile requirement for MsgAddReaction
RiccardoM Jun 9, 2022
9185107
added MsgServer tests
RiccardoM Jun 9, 2022
23c72bb
added the reactions module to app.go
RiccardoM Jun 9, 2022
47c282b
added the simulation operations
RiccardoM Jun 9, 2022
fe2b9cf
Merge branch 'master' of github.com:desmos-labs/desmos into riccardo/…
RiccardoM Jun 9, 2022
3b4362a
fixed tests
RiccardoM Jun 9, 2022
2bbe74b
fixed simulation tests
RiccardoM Jun 9, 2022
ab37ac9
started adding the CLI commands
RiccardoM Jun 9, 2022
9cb96b6
Merge branch 'master' of github.com:desmos-labs/desmos into riccardo/…
RiccardoM Jun 10, 2022
634f880
reverted reports changes
RiccardoM Jun 10, 2022
dd2ee2a
completed CLI command implementation
RiccardoM Jun 10, 2022
9994480
added CLI tests
RiccardoM Jun 10, 2022
d83d326
fixed proto lint
RiccardoM Jun 10, 2022
95bc190
added changeset entry
RiccardoM Jun 10, 2022
c1109a7
added norace build tags to CLI tests
RiccardoM Jun 10, 2022
3c57a47
Merge branch 'master' of github.com:desmos-labs/desmos into riccardo/…
RiccardoM Jun 10, 2022
a7c8b5f
reverted changes
RiccardoM Jun 10, 2022
3b0bab6
Update proto/desmos/reactions/v1/genesis.proto
RiccardoM Jun 20, 2022
501d1d5
Update x/reactions/client/cli/tx.go
RiccardoM Jun 20, 2022
edbb5b1
Update x/reactions/client/cli/tx.go
RiccardoM Jun 20, 2022
aab0f90
Update x/reactions/keeper/msg_server.go
RiccardoM Jun 20, 2022
2781304
Update x/reactions/keeper/msg_server.go
RiccardoM Jun 20, 2022
85397cd
Update x/reactions/keeper/reactions_test.go
RiccardoM Jun 20, 2022
7381d2f
Update x/reactions/types/genesis.go
RiccardoM Jun 20, 2022
8fc8672
Update x/reactions/client/cli/tx.go
RiccardoM Jun 20, 2022
54bc3ca
Update x/reactions/client/cli/tx.go
RiccardoM Jun 20, 2022
98008da
Update x/reactions/client/cli/tx.go
RiccardoM Jun 20, 2022
82b3dc2
Update x/reactions/keeper/external_hooks.go
RiccardoM Jun 20, 2022
7951e32
Merge branch 'master' of github.com:desmos-labs/desmos into riccardo/…
RiccardoM Jun 20, 2022
0055062
updated Proto files
RiccardoM Jun 20, 2022
3c563bc
added the ability to filter post reactions for a given user
RiccardoM Jun 21, 2022
c017e72
improved the CLI commands descriptions
RiccardoM Jun 21, 2022
20517d4
fixed building errors and CLI tests
RiccardoM Jun 21, 2022
84ae572
added CLI commands to reactions module
RiccardoM Jun 21, 2022
7bcef1b
Merge branch 'master' into riccardo/adr-016-reactions-module
mergify[bot] Jun 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/reactions
description: Reactions
- id: x/reports
description: Reports
- id: x/fees
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: feat
module: x/reactions
pull_request: 898
description: Added the new x/reactions module
backward_compatible: true
date: 2022-06-10T09:58:20.626124304Z
28 changes: 26 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"path/filepath"
"strings"

"github.com/desmos-labs/desmos/v3/x/reactions"
reactionstypes "github.com/desmos-labs/desmos/v3/x/reactions/types"

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

Expand Down Expand Up @@ -103,11 +106,11 @@ import (
"github.com/desmos-labs/desmos/v3/x/profiles"
profileskeeper "github.com/desmos-labs/desmos/v3/x/profiles/keeper"
profilestypes "github.com/desmos-labs/desmos/v3/x/profiles/types"
reactionskeeper "github.com/desmos-labs/desmos/v3/x/reactions/keeper"
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"
subspacestypes "github.com/desmos-labs/desmos/v3/x/subspaces/types"
Expand Down Expand Up @@ -243,6 +246,7 @@ var (
subspaces.AppModuleBasic{},
posts.AppModuleBasic{},
reports.AppModuleBasic{},
reactions.AppModuleBasic{},
fees.AppModuleBasic{},
supply.AppModuleBasic{},
)
Expand Down Expand Up @@ -310,6 +314,7 @@ type DesmosApp struct {
RelationshipsKeeper relationshipskeeper.Keeper
PostsKeeper postskeeper.Keeper
ReportsKeeper reportskeeper.Keeper
ReactionsKeeper reactionskeeper.Keeper
SupplyKeeper supplykeeper.Keeper

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

// Custom modules
profilestypes.StoreKey, relationshipstypes.StoreKey, subspacestypes.StoreKey,
poststypes.StoreKey, reportstypes.StoreKey,
poststypes.StoreKey, reportstypes.StoreKey, reactionstypes.StoreKey,
feestypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -511,11 +516,22 @@ func NewDesmosApp(
&postsKeeper,
)

// Create reactions keeper
app.ReactionsKeeper = reactionskeeper.NewKeeper(
app.appCodec,
keys[reactionstypes.StoreKey],
app.ProfileKeeper,
&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(),
app.ReactionsKeeper.Hooks(),
),
)

Expand All @@ -526,6 +542,7 @@ func NewDesmosApp(
app.RelationshipsKeeper.Hooks(),
app.PostsKeeper.Hooks(),
app.ReportsKeeper.Hooks(),
app.ReactionsKeeper.Hooks(),
),
)

Expand Down Expand Up @@ -633,6 +650,7 @@ func NewDesmosApp(
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),
reactions.NewAppModule(appCodec, app.ReactionsKeeper, app.SubspacesKeeper, app.PostsKeeper, app.AccountKeeper, app.BankKeeper, app.FeesKeeper),
supply.NewAppModule(appCodec, legacyAmino, app.SupplyKeeper),
)

Expand Down Expand Up @@ -668,6 +686,7 @@ func NewDesmosApp(
profilestypes.ModuleName,
poststypes.ModuleName,
reportstypes.ModuleName,
reactionstypes.ModuleName,
supplytypes.ModuleName,
)
app.mm.SetOrderEndBlockers(
Expand Down Expand Up @@ -697,6 +716,7 @@ func NewDesmosApp(
profilestypes.ModuleName,
poststypes.ModuleName,
reportstypes.ModuleName,
reactionstypes.ModuleName,
supplytypes.ModuleName,
)

Expand Down Expand Up @@ -733,6 +753,7 @@ func NewDesmosApp(
relationshipstypes.ModuleName,
poststypes.ModuleName,
reportstypes.ModuleName,
reactionstypes.ModuleName,
supplytypes.ModuleName,

crisistypes.ModuleName,
Expand Down Expand Up @@ -768,6 +789,7 @@ func NewDesmosApp(
profilestypes.ModuleName,
poststypes.ModuleName,
reportstypes.ModuleName,
reactionstypes.ModuleName,
supplytypes.ModuleName,

crisistypes.ModuleName,
Expand Down Expand Up @@ -812,6 +834,7 @@ func NewDesmosApp(
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),
reactions.NewAppModule(appCodec, app.ReactionsKeeper, app.SubspacesKeeper, app.PostsKeeper, app.AccountKeeper, app.BankKeeper, app.FeesKeeper),
)

app.sm.RegisterStoreDecoders()
Expand Down Expand Up @@ -1066,6 +1089,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(profilestypes.ModuleName)
paramsKeeper.Subspace(poststypes.ModuleName)
paramsKeeper.Subspace(reportstypes.ModuleName)
paramsKeeper.Subspace(reactionstypes.ModuleName)

return paramsKeeper
}
7 changes: 7 additions & 0 deletions app/params/weights.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ const (
DefaultWeightMsgSupportStandardReason int = 20
DefaultWeightMsgAddReason int = 10
DefaultWeightMsgRemoveReason int = 10

DefaultWeightMsgAddReaction int = 40
DefaultWeightMsgRemoveReaction int = 30
DefaultWeightMsgAddRegisteredReaction int = 25
DefaultWeightMsgEditRegisteredReaction int = 25
DefaultWeightMsgRemoveRegisteredReaction int = 15
DefaultWeightMsgSetReactionsParams int = 10
)
3 changes: 3 additions & 0 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"path/filepath"
"testing"

reactionstypes "github.com/desmos-labs/desmos/v3/x/reactions/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"
Expand Down Expand Up @@ -254,6 +256,7 @@ func TestAppImportExport(t *testing.T) {
{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{}},
{app.keys[reactionstypes.StoreKey], newApp.keys[reactionstypes.StoreKey], [][]byte{}},
}

for _, skp := range storeKeysPrefixes {
Expand Down
34 changes: 24 additions & 10 deletions docs/architecture/adr-016-reactions-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Status

DRAFT Not Implemented
ACCEPTED Implemented

## Abstract

Expand Down Expand Up @@ -259,17 +259,17 @@ syntax = "proto3";
// Query defines the gRPC querier service.
service Query {
// Reactions allows to query the reactions present inside a subspace
rpc Reactions(QueryReactionsRequest) returns QueryReactionsResponse {
rpc Reactions(QueryReactionsRequest) returns (QueryReactionsResponse) {
option (google.api.http).get = "/desmos/reactions/v1/{subspace_id}/reactions";
}

// RegisteredReactions allows to query the registered reaction of a subspace
rpc RegisteredReactions(QueryRegisteredReactionsRequest) returns QueryRegisteredReactionsResponse {
rpc RegisteredReactions(QueryRegisteredReactionsRequest) returns (QueryRegisteredReactionsResponse) {
option (google.api.http).get = "/desmos/reactions/v1/{subspace_id}/registered-reactions";
}

// ReactionsParams allows to query the reaction params of a subspace
rpc ReactionsParams(QueryReactionsParamsRequest) returns QueryReactionsParamsResponse {
rpc ReactionsParams(QueryReactionsParamsRequest) returns (QueryReactionsParamsResponse) {
option (google.api.http).get = "/desmos/reactions/v1/{subspace_id}/params";
}
}
Expand All @@ -278,7 +278,7 @@ service Query {
message QueryReactionsRequest {
// Id of the subspace to query the reactions for
uint64 subspace_id = 1;

// (optional) Post id to query the reactions for
uint64 post_id = 2;

Expand All @@ -292,14 +292,28 @@ message QueryReactionsResponse {
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryReactionsParamsRequest is the request type for the
// Query/ReactionsParams RPC method
// QueryRegisteredReactionsRequest is the request type for the Query/RegisteredReactions RPC method
message QueryRegisteredReactionsRequest {
// Id of the subspace to query the registered reactions for
uint64 subspace_id = 1;

// pagination defines an optional pagination for the request.
optional cosmos.base.query.v1beta1.PageRequest pagination = 3;
}

// QueryRegisteredReactionsResponse is the response type for the Query/RegisteredReactions RPC method
message QueryRegisteredReactionsResponse {
repeated RegisteredReaction registered_reactions = 1;
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryReactionsParamsRequest is the request type for the Query/ReactionsParams RPC method
message QueryReactionsParamsRequest {
// Id of the subspace for which to query the params
uint64 subspace_id = 1;
}

// QueryReactionsParamsResponse is the response type for the
// Query/ReactionsParam RPC method
// QueryReactionsParamsResponse is the response type for the Query/ReactionsParam RPC method
message QueryReactionsParamsResponse {
// Params related to RegisteredReactionValue reactions
RegisteredReactionValueParams registered = 1;
Expand Down
22 changes: 22 additions & 0 deletions proto/desmos/reactions/v1/client/cli.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
syntax = "proto3";
package desmos.reactions.v1.client;

import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";
import "google/protobuf/timestamp.proto";
import "cosmos_proto/cosmos.proto";

import "desmos/reactions/v1/models.proto";

option go_package = "github.com/desmos-labs/desmos/v3/x/reactions/client/utils";

// SetReactionsParamsJSON contains the data that can be specified when setting a
// subspace reactions params using the CLI command
message SetReactionsParamsJSON {
// Params related to RegisteredReactionValue reactions
RegisteredReactionValueParams registered_reaction_params = 1
[ (gogoproto.nullable) = false ];

// Params related to FreeTextValue reactions
FreeTextValueParams free_text_params = 2 [ (gogoproto.nullable) = false ];
}
46 changes: 46 additions & 0 deletions proto/desmos/reactions/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
syntax = "proto3";
package desmos.reactions.v1;

import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";
import "google/protobuf/timestamp.proto";
import "cosmos_proto/cosmos.proto";

import "desmos/reactions/v1/models.proto";

option go_package = "github.com/desmos-labs/desmos/v3/x/reactions/types";

// GenesisState contains the data of the genesis state for the reactions module
message GenesisState {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = true;

repeated SubspaceDataEntry subspaces_data = 1
[ (gogoproto.nullable) = false ];
repeated RegisteredReaction registered_reactions = 2
[ (gogoproto.nullable) = false ];
repeated PostDataEntry posts_data = 3 [ (gogoproto.nullable) = false ];
repeated Reaction reactions = 4 [ (gogoproto.nullable) = false ];
repeated SubspaceReactionsParams subspaces_params = 5
[ (gogoproto.nullable) = false ];
}

// SubspaceDataEntry contains the data related to a single subspace
message SubspaceDataEntry {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename this in something more meaningful such as SubspaceRelatedIDs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is going to take a while (changing all names is tedious), can we delay this along with #895? This we can we can change everything in one go to make it similar to other modules as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RiccardoM yes course

option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = true;

uint64 subspace_id = 1 [ (gogoproto.customname) = "SubspaceID" ];
uint32 registered_reaction_id = 2
[ (gogoproto.customname) = "RegisteredReactionID" ];
}

// PostDataEntry contains the data related to a single post
message PostDataEntry {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename this as well in PostRelatedIDs

option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = true;

uint64 subspace_id = 1 [ (gogoproto.customname) = "SubspaceID" ];
uint64 post_id = 2 [ (gogoproto.customname) = "PostID" ];
uint32 reaction_id = 3 [ (gogoproto.customname) = "ReactionID" ];
}
Loading