Skip to content

Commit

Permalink
feat: relationships module (#750)
Browse files Browse the repository at this point in the history
## Description
This PR implements the new `x/relationships` module. This module contains all the user blocks and relationships actions that were previously present inside the `x/profiles` module. 

Some changes have been done to the logic of relationships and user blocks, particularly: 
- it is **not** required anymore to have a Desmos profile in order to block another user 
- it is **not** required anymore that both parties have a Desmos profile in order to establish a relationship 
- blocking a user inside the subspace `0` will **not** lead to the user being blocked on all subspaces anymore. The subspace with id `0` now only identifies the `x/profiles` subspace. Users blocked there won't be able to send DTag transfer requests to other users or perform other actions from within the `x/profiles` module that involve the blocker. 

Depends-On: #753

---

### 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...

- [ ] 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
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://docs.cosmos.network/v0.44/building-modules/intro.html)
- [ ] 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
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] 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 Mar 1, 2022
1 parent 04dd751 commit 8998def
Show file tree
Hide file tree
Showing 129 changed files with 6,467 additions and 5,563 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: feat
module: none
pull_request: 750
description: Split relationships and user blocks into the new x/relationships module
backward_compatible: false
date: 2022-02-28T13:15:58.416244744Z
164 changes: 145 additions & 19 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ import (
"path/filepath"
"strings"

profilesv2 "github.com/desmos-labs/desmos/v2/x/profiles/legacy/v2"

"github.com/desmos-labs/desmos/v2/x/relationships"
relationshipstypes "github.com/desmos-labs/desmos/v2/x/relationships/types"

"github.com/desmos-labs/desmos/v2/x/subspaces"

"github.com/cosmos/cosmos-sdk/version"

"github.com/cosmos/cosmos-sdk/x/auth/vesting"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/authz"
"github.com/cosmos/cosmos-sdk/x/feegrant"

Expand Down Expand Up @@ -86,6 +92,7 @@ import (
"github.com/desmos-labs/desmos/v2/x/profiles"
profileskeeper "github.com/desmos-labs/desmos/v2/x/profiles/keeper"
profilestypes "github.com/desmos-labs/desmos/v2/x/profiles/types"
relationshipskeeper "github.com/desmos-labs/desmos/v2/x/relationships/keeper"
subspaceskeeper "github.com/desmos-labs/desmos/v2/x/subspaces/keeper"
subspacestypes "github.com/desmos-labs/desmos/v2/x/subspaces/types"

Expand Down Expand Up @@ -213,6 +220,7 @@ var (

// Custom modules
profiles.AppModuleBasic{},
relationships.AppModuleBasic{},
subspaces.AppModuleBasic{},
)

Expand Down Expand Up @@ -273,8 +281,9 @@ type DesmosApp struct {
ScopedWasmKeeper capabilitykeeper.ScopedKeeper

// Custom modules
SubspacesKeeper subspaceskeeper.Keeper
ProfileKeeper profileskeeper.Keeper
SubspacesKeeper subspaceskeeper.Keeper
ProfileKeeper profileskeeper.Keeper
RelationshipsKeeper relationshipskeeper.Keeper

// Module Manager
mm *module.Manager
Expand Down Expand Up @@ -321,7 +330,7 @@ func NewDesmosApp(
authzkeeper.StoreKey, wasm.StoreKey,

// Custom modules
subspacestypes.StoreKey, profilestypes.StoreKey,
profilestypes.StoreKey, relationshipstypes.StoreKey, subspacestypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -411,21 +420,40 @@ func NewDesmosApp(
)
transferModule := ibctransfer.NewAppModule(app.TransferKeeper)

// Create subspaces keeper
app.SubspacesKeeper = subspaceskeeper.NewKeeper(app.appCodec, keys[subspacestypes.StoreKey])
// Create subspaces keeper and module
subspacesKeeper := subspaceskeeper.NewKeeper(app.appCodec, keys[subspacestypes.StoreKey])

// Create the relationships keeper
app.RelationshipsKeeper = relationshipskeeper.NewKeeper(
appCodec,
keys[relationshipstypes.StoreKey],
&subspacesKeeper,
)

// Create profiles keeper
// Create profiles keeper and module
app.ProfileKeeper = profileskeeper.NewKeeper(
app.appCodec,
keys[profilestypes.StoreKey],
app.GetSubspace(profilestypes.ModuleName),
app.AccountKeeper,
app.SubspacesKeeper,
app.RelationshipsKeeper,
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
scopedProfilesKeeper,
)
profilesModule := profiles.NewAppModule(appCodec, legacyAmino, app.ProfileKeeper, app.SubspacesKeeper, app.AccountKeeper, app.BankKeeper)
profilesModule := profiles.NewAppModule(
appCodec,
legacyAmino,
app.ProfileKeeper,
app.AccountKeeper,
app.BankKeeper,
)

// 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()),
)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
Expand Down Expand Up @@ -525,6 +553,7 @@ func NewDesmosApp(
// Custom modules
subspaces.NewAppModule(appCodec, app.SubspacesKeeper, app.AccountKeeper, app.BankKeeper),
profilesModule,
relationships.NewAppModule(appCodec, app.RelationshipsKeeper, app.SubspacesKeeper, profilesv2.NewKeeper(keys[profilestypes.StoreKey], appCodec), app.AccountKeeper, app.BankKeeper),
)

// During begin block slashing happens after distr.BeginBlocker so that
Expand All @@ -533,25 +562,117 @@ func NewDesmosApp(
// NOTE: staking module is required if HistoricalEntries param > 0
// NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC)
app.mm.SetOrderBeginBlockers(
upgradetypes.ModuleName, capabilitytypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName,
upgradetypes.ModuleName,
capabilitytypes.ModuleName,
minttypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
evidencetypes.ModuleName,
stakingtypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
govtypes.ModuleName,
crisistypes.ModuleName,
genutiltypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
vestingtypes.ModuleName,
ibchost.ModuleName,
ibctransfertypes.ModuleName,
wasm.ModuleName,

subspacestypes.ModuleName,
relationshipstypes.ModuleName,
profilestypes.ModuleName,
)
app.mm.SetOrderEndBlockers(
crisistypes.ModuleName,
govtypes.ModuleName,
stakingtypes.ModuleName,
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
minttypes.ModuleName,
genutiltypes.ModuleName,
evidencetypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
ibchost.ModuleName,
ibctransfertypes.ModuleName,
wasm.ModuleName,

subspacestypes.ModuleName,
relationshipstypes.ModuleName,
profilestypes.ModuleName,
)
app.mm.SetOrderEndBlockers(crisistypes.ModuleName, govtypes.ModuleName, stakingtypes.ModuleName)

// NOTE: The genutils module must occur after staking so that pools are
// properly initialized with tokens from genesis accounts.
// NOTE: The genutils module must also occur after auth so that it can access the params from auth.
// NOTE: Capability module must occur first so that it can initialize any capabilities
// so that other modules that want to create or claim capabilities afterwards in InitChain
// can do so safely.
// NOTE: The crisis module should occur after all other modules to run the invariants at genesis correctly
app.mm.SetOrderInitGenesis(
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName,
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName,
ibchost.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, ibctransfertypes.ModuleName,
feegrant.ModuleName, wasm.ModuleName,
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
distrtypes.ModuleName,
stakingtypes.ModuleName,
slashingtypes.ModuleName,
govtypes.ModuleName,
minttypes.ModuleName,
genutiltypes.ModuleName,
evidencetypes.ModuleName,
authz.ModuleName,
feegrant.ModuleName,
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
ibchost.ModuleName,
ibctransfertypes.ModuleName,
wasm.ModuleName,

// Custom modules
subspacestypes.ModuleName, profilestypes.ModuleName,
subspacestypes.ModuleName,
profilestypes.ModuleName,
relationshipstypes.ModuleName,

crisistypes.ModuleName,
)

// NOTE: The auth module must occur before everyone else. All other modules can be sorted
// alphabetically (default order)
// NOTE: The relationships module must occur before the profiles module, or all relationships will be deleted
app.mm.SetOrderMigrations(
authtypes.ModuleName,
authz.ModuleName,
banktypes.ModuleName,
capabilitytypes.ModuleName,
distrtypes.ModuleName,
evidencetypes.ModuleName,
feegrant.ModuleName,
genutiltypes.ModuleName,
govtypes.ModuleName,
ibchost.ModuleName,
minttypes.ModuleName,
slashingtypes.ModuleName,
stakingtypes.ModuleName,
ibctransfertypes.ModuleName,
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
wasm.ModuleName,

// Custom modules
subspacestypes.ModuleName,
relationshipstypes.ModuleName,
profilestypes.ModuleName,

crisistypes.ModuleName,
)
Expand Down Expand Up @@ -586,8 +707,9 @@ func NewDesmosApp(
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper),

// Custom modules
subspaces.NewAppModule(app.appCodec, app.SubspacesKeeper, app.AccountKeeper, app.BankKeeper),
profiles.NewAppModule(app.appCodec, legacyAmino, app.ProfileKeeper, app.SubspacesKeeper, app.AccountKeeper, app.BankKeeper),
subspaces.NewAppModule(appCodec, app.SubspacesKeeper, app.AccountKeeper, app.BankKeeper),
profilesModule,
relationships.NewAppModule(appCodec, app.RelationshipsKeeper, app.SubspacesKeeper, profilesv2.NewKeeper(keys[profilestypes.StoreKey], appCodec), app.AccountKeeper, app.BankKeeper),
)

app.sm.RegisterStoreDecoders()
Expand Down Expand Up @@ -780,6 +902,9 @@ func (app *DesmosApp) RegisterTendermintService(clientCtx client.Context) {

func (app *DesmosApp) registerUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler("v3.0.0", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// Set the initial version of the x/relationships module to 1 so that we can migrate to 2
fromVM[relationshipstypes.ModuleName] = 1

// Nothing to do here for the x/subspaces module since the InitGenesis will be called
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})
Expand All @@ -794,6 +919,7 @@ func (app *DesmosApp) registerUpgradeHandlers() {
Added: []string{
wasm.ModuleName,
subspacestypes.ModuleName,
relationshipstypes.ModuleName,
},
}

Expand Down
Loading

0 comments on commit 8998def

Please sign in to comment.