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: add support for Desmos features #662

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 7 additions & 6 deletions Dockerfile.cosmwasm
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@


FROM golang:1.20-alpine AS builder
RUN apk update && apk add --no-cache make git
WORKDIR /go/src/github.com/forbole/bdjuno
COPY . ./

RUN apk update && apk add --no-cache ca-certificates build-base git
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.1.1/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a
ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.1.1/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a
RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep 9ecb037336bd56076573dc18c26631a9d2099a7f2b40dc04b6cae31ffb4c8f9a
RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep 6e4de7ba9bad4ae9679c7f9ecf7e283dd0160e71567c6a7be6ae47c81ebe7f32

ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.3.0/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a
RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep b1610f9c8ad8bdebf5b8f819f71d238466f83521c74a2deb799078932e862722

ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.3.0/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a
RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep b4aad4480f9b4c46635b4943beedbb72c929eab1d1b9467fe3b43e6dbf617e32

## Copy the library you want to the final location that will be found by the linker flag `-lwasmvm_muslc`
RUN cp /lib/libwasmvm_muslc.$(uname -m).a /lib/libwasmvm_muslc.a
RUN go mod download
Expand Down
112 changes: 112 additions & 0 deletions cmd/bdjuno/desmos.go
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)
}
8 changes: 4 additions & 4 deletions cmd/bdjuno/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ package main

import (
"github.com/cosmos/cosmos-sdk/types/module"
desmosapp "github.com/desmos-labs/desmos/v6/app"
"github.com/forbole/juno/v5/cmd"
initcmd "github.com/forbole/juno/v5/cmd/init"
migratecmd "github.com/forbole/juno/v5/cmd/migrate"
parsetypes "github.com/forbole/juno/v5/cmd/parse/types"
startcmd "github.com/forbole/juno/v5/cmd/start"
"github.com/forbole/juno/v5/modules/messages"

migratecmd "github.com/forbole/bdjuno/v4/cmd/migrate"
parsecmd "github.com/forbole/bdjuno/v4/cmd/parse"

"github.com/forbole/bdjuno/v4/types/config"

"cosmossdk.io/simapp"

"github.com/forbole/bdjuno/v4/database"
"github.com/forbole/bdjuno/v4/modules"
)
Expand Down Expand Up @@ -55,7 +54,7 @@ func main() {
// This should be edited by custom implementations if needed.
func getBasicManagers() []module.BasicManager {
return []module.BasicManager{
simapp.ModuleBasics,
desmosapp.ModuleBasics,
}
}

Expand All @@ -64,6 +63,7 @@ func getBasicManagers() []module.BasicManager {
// This should be edited by custom implementations if needed.
func getAddressesParser() messages.MessageAddressesParser {
return messages.JoinMessageParsers(
desmosMessageAddressesParser,
messages.CosmosMessageAddressesParser,
)
}
14 changes: 13 additions & 1 deletion cmd/parse/gov/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/forbole/juno/v5/types/config"
"github.com/spf13/cobra"

"github.com/forbole/bdjuno/v4/modules/profiles"

"github.com/forbole/bdjuno/v4/database"
"github.com/forbole/bdjuno/v4/modules/distribution"
"github.com/forbole/bdjuno/v4/modules/gov"
Expand Down Expand Up @@ -53,9 +55,19 @@ func proposalCmd(parseConfig *parsecmdtypes.Config) *cobra.Command {
mintModule := mint.NewModule(sources.MintSource, parseCtx.EncodingConfig.Codec, db)
slashingModule := slashing.NewModule(sources.SlashingSource, parseCtx.EncodingConfig.Codec, db)
stakingModule := staking.NewModule(sources.StakingSource, parseCtx.EncodingConfig.Codec, db)
profilesModule := profiles.NewModule(sources.ProfilesSource, parseCtx.EncodingConfig.Codec, db)

// Build the gov module
govModule := gov.NewModule(sources.GovSource, distrModule, mintModule, slashingModule, stakingModule, parseCtx.EncodingConfig.Codec, db)
govModule := gov.NewModule(
sources.GovSource,
distrModule,
mintModule,
slashingModule,
stakingModule,
profilesModule,
parseCtx.EncodingConfig.Codec,
db,
)

err = refreshProposalDetails(parseCtx, proposalID, govModule)
if err != nil {
Expand Down
32 changes: 32 additions & 0 deletions database/profiles.go
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(&params.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
}
32 changes: 32 additions & 0 deletions database/profiles_test.go
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)
}
8 changes: 8 additions & 0 deletions database/schema/13-profiles.sql
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);
8 changes: 8 additions & 0 deletions database/types/profiles.go
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"`
}
Loading
Loading