-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for Desmos features (#662)
## Description This PR implements all the Desmos-related features. <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### 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 - [ ] provided a link to the relevant issue or specification - [ ] 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 API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
- Loading branch information
Showing
24 changed files
with
752 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
poststypes "github.com/desmos-labs/desmos/v6/x/posts/types" | ||
profilestypes "github.com/desmos-labs/desmos/v6/x/profiles/types" | ||
reactionstypes "github.com/desmos-labs/desmos/v6/x/reactions/types" | ||
relationshiptypes "github.com/desmos-labs/desmos/v6/x/relationships/types" | ||
reportstypes "github.com/desmos-labs/desmos/v6/x/reports/types" | ||
subspacestypes "github.com/desmos-labs/desmos/v6/x/subspaces/types" | ||
|
||
junomessages "github.com/forbole/juno/v5/modules/messages" | ||
) | ||
|
||
// desmosMessageAddressesParser represents a parser able to get the addresses of the involved | ||
// account from a Desmos message | ||
var desmosMessageAddressesParser = junomessages.JoinMessageParsers( | ||
profilesMessageAddressesParser, | ||
) | ||
|
||
// profilesMessageAddressesParser represents a MessageAddressesParser for the x/profiles module | ||
func profilesMessageAddressesParser(_ codec.Codec, cosmosMsg sdk.Msg) ([]string, error) { | ||
switch msg := cosmosMsg.(type) { | ||
|
||
case *poststypes.MsgCreatePost: | ||
return []string{msg.Author}, nil | ||
case *poststypes.MsgEditPost: | ||
return []string{msg.Editor}, nil | ||
case *poststypes.MsgDeletePost: | ||
return []string{msg.Signer}, nil | ||
case *poststypes.MsgAddPostAttachment: | ||
return []string{msg.Editor}, nil | ||
case *poststypes.MsgRemovePostAttachment: | ||
return []string{msg.Editor}, nil | ||
case *poststypes.MsgAnswerPoll: | ||
return []string{msg.Signer}, nil | ||
|
||
case *profilestypes.MsgRequestDTagTransfer: | ||
return []string{msg.Sender, msg.Receiver}, nil | ||
case *profilestypes.MsgCancelDTagTransferRequest: | ||
return []string{msg.Sender, msg.Receiver}, nil | ||
case *profilestypes.MsgAcceptDTagTransferRequest: | ||
return []string{msg.Sender, msg.Receiver}, nil | ||
case *profilestypes.MsgRefuseDTagTransferRequest: | ||
return []string{msg.Sender, msg.Receiver}, nil | ||
|
||
case *reactionstypes.MsgAddReaction: | ||
return []string{msg.User}, nil | ||
case *reactionstypes.MsgRemoveReaction: | ||
return []string{msg.User}, nil | ||
case *reactionstypes.MsgAddRegisteredReaction: | ||
return []string{msg.User}, nil | ||
case *reactionstypes.MsgEditRegisteredReaction: | ||
return []string{msg.User}, nil | ||
case *reactionstypes.MsgRemoveRegisteredReaction: | ||
return []string{msg.User}, nil | ||
case *reactionstypes.MsgSetReactionsParams: | ||
return []string{msg.User}, nil | ||
|
||
case *relationshiptypes.MsgCreateRelationship: | ||
return []string{msg.Signer, msg.Counterparty}, nil | ||
case *relationshiptypes.MsgDeleteRelationship: | ||
return []string{msg.Signer, msg.Counterparty}, nil | ||
case *relationshiptypes.MsgBlockUser: | ||
return []string{msg.Blocker, msg.Blocked}, nil | ||
case *relationshiptypes.MsgUnblockUser: | ||
return []string{msg.Blocker, msg.Blocked}, nil | ||
|
||
case *reportstypes.MsgCreateReport: | ||
return []string{msg.Reporter}, nil | ||
case *reportstypes.MsgDeleteReport: | ||
return []string{msg.Signer}, nil | ||
case *reportstypes.MsgSupportStandardReason: | ||
return []string{msg.Signer}, nil | ||
case *reportstypes.MsgAddReason: | ||
return []string{msg.Signer}, nil | ||
case *reportstypes.MsgRemoveReason: | ||
return []string{msg.Signer}, nil | ||
|
||
case *subspacestypes.MsgCreateSubspace: | ||
return []string{msg.Creator}, nil | ||
case *subspacestypes.MsgEditSubspace: | ||
return []string{msg.Signer}, nil | ||
case *subspacestypes.MsgDeleteSubspace: | ||
return []string{msg.Signer}, nil | ||
case *subspacestypes.MsgCreateSection: | ||
return []string{msg.Creator}, nil | ||
case *subspacestypes.MsgEditSection: | ||
return []string{msg.Editor}, nil | ||
case *subspacestypes.MsgMoveSection: | ||
return []string{msg.Signer}, nil | ||
case *subspacestypes.MsgDeleteSection: | ||
return []string{msg.Signer}, nil | ||
case *subspacestypes.MsgCreateUserGroup: | ||
return append([]string{msg.Creator}, msg.InitialMembers...), nil | ||
case *subspacestypes.MsgEditUserGroup: | ||
return []string{msg.Signer}, nil | ||
case *subspacestypes.MsgMoveUserGroup: | ||
return []string{msg.Signer}, nil | ||
case *subspacestypes.MsgDeleteUserGroup: | ||
return []string{msg.Signer}, nil | ||
case *subspacestypes.MsgAddUserToUserGroup: | ||
return []string{msg.Signer, msg.User}, nil | ||
case *subspacestypes.MsgRemoveUserFromUserGroup: | ||
return []string{msg.Signer, msg.User}, nil | ||
case *subspacestypes.MsgSetUserPermissions: | ||
return []string{msg.Signer, msg.User}, nil | ||
} | ||
|
||
return nil, junomessages.MessageNotSupported(cosmosMsg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package database | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/forbole/bdjuno/v4/types" | ||
) | ||
|
||
// SaveProfilesParams save the params of profiles module in the database | ||
func (db *Db) SaveProfilesParams(params *types.ProfilesParams) error { | ||
paramsBz, err := json.Marshal(¶ms.Params) | ||
if err != nil { | ||
return fmt.Errorf("error while marshaling profiles params: %s", err) | ||
} | ||
|
||
stmt := ` | ||
INSERT INTO profiles_params (params, height) | ||
VALUES ($1, $2) | ||
ON CONFLICT (one_row_id) DO UPDATE | ||
SET params = excluded.params, | ||
height = excluded.height | ||
WHERE profiles_params.height <= excluded.height` | ||
|
||
_, err = db.SQL.Exec(stmt, string(paramsBz), params.Height) | ||
|
||
if err != nil { | ||
return fmt.Errorf("error while storing profiles params: %s", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package database_test | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
profilestypes "github.com/desmos-labs/desmos/v6/x/profiles/types" | ||
|
||
dbtypes "github.com/forbole/bdjuno/v4/database/types" | ||
"github.com/forbole/bdjuno/v4/types" | ||
) | ||
|
||
func (suite *DbTestSuite) TestBigDipperDb_SaveProfilesParams() { | ||
profilesParams := profilestypes.Params{ | ||
Nickname: profilestypes.NewNicknameParams(sdk.NewInt(1), sdk.NewInt(100)), | ||
DTag: profilestypes.NewDTagParams("abc", sdk.NewInt(1), sdk.NewInt(100)), | ||
Bio: profilestypes.NewBioParams(sdk.NewInt(100)), | ||
Oracle: profilestypes.NewOracleParams(1, 1, 1, 1, 1, sdk.NewCoin("band", sdk.NewInt(1))), | ||
} | ||
err := suite.database.SaveProfilesParams(types.NewProfilesParams(profilesParams, 10)) | ||
suite.Require().NoError(err) | ||
|
||
var rows []dbtypes.ProfilesParamsRow | ||
err = suite.database.SQL.Select(&rows, `SELECT * FROM profiles_params`) | ||
suite.Require().NoError(err) | ||
suite.Require().Len(rows, 1) | ||
|
||
var stored profilestypes.Params | ||
err = json.Unmarshal([]byte(rows[0].Params), &stored) | ||
suite.Require().NoError(err) | ||
suite.Require().Equal(profilesParams, stored) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE TABLE profiles_params | ||
( | ||
one_row_id BOOLEAN NOT NULL DEFAULT TRUE PRIMARY KEY, | ||
params JSONB NOT NULL, | ||
height BIGINT NOT NULL, | ||
CHECK (one_row_id) | ||
); | ||
CREATE INDEX profiles_params_height_index ON profiles_params (height); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package types | ||
|
||
// ProfilesParamsRow represents a single row inside the profiles_params table | ||
type ProfilesParamsRow struct { | ||
OneRowID bool `db:"one_row_id"` | ||
Params string `db:"params"` | ||
Height int64 `db:"height"` | ||
} |
Oops, something went wrong.