Skip to content

Commit

Permalink
feat: set stargate querier accepted list (#1083)
Browse files Browse the repository at this point in the history
## Description

This PR set stargate querier accepted list to enable wasm contract to query the allowed data from the chain query router.



---

### 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
dadamu authored Feb 23, 2023
1 parent 7f38ac5 commit 581e029
Show file tree
Hide file tree
Showing 15 changed files with 173 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: feat
module: other
pull_request: 1083
description: Set stargate querier accepted list
backward_compatible: true
date: 2023-02-23T15:45:35.2217003Z
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup Go 🧰
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: Compute diff 📜
uses: technote-space/get-diff-action@v6.1.2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Go 🧰
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: Compute diff 📜
uses: technote-space/get-diff-action@v6.1.2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mutest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup Go 🧰
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: Run mutation tests 🧪
continue-on-error: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/on-chain-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Setup Go 🧰
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: Install Desmos 🔧
run: make clean install
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Go 🧰
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: Unshallow
run: git fetch --prune --unshallow --tags --force
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
# - name: Setup Go 🧰
# uses: actions/setup-go@v3
# with:
# go-version: 1.18
# go-version: 1.19
#
# - name: Build the binary 🏭
# run: |
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
# - name: Setup Go 🧰
# uses: actions/setup-go@v3
# with:
# go-version: 1.18
# go-version: 1.19
#
# - name: Compute diff 📜
# uses: technote-space/get-diff-action@v6.1.0
Expand Down Expand Up @@ -131,7 +131,7 @@ jobs:
# - name: Setup Go 🧰
# uses: actions/setup-go@v3
# with:
# go-version: 1.18
# go-version: 1.19
#
# - name: Build the binary 🏭
# run: |
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/sims.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Setup Go 🧰
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: Build 🔨
run: make build
Expand All @@ -39,7 +39,7 @@ jobs:
- name: Setup Go 🧰
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: Install runsim 🏃
run: export GO111MODULE="on" && go install github.com/cosmos/tools/cmd/runsim@v1.0.0
Expand All @@ -60,7 +60,7 @@ jobs:
- name: Setup Go 🧰
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: Compute diff 📜
uses: technote-space/get-diff-action@v6.1.2
Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
- name: Setup Go 🧰
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: Compute diff 📜
uses: technote-space/get-diff-action@v6.1.2
Expand Down Expand Up @@ -122,7 +122,7 @@ jobs:
- name: Setup Go 🧰
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: Compute diff 📜
uses: technote-space/get-diff-action@v6.1.2
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup Go 🧰
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: Display go version 🛂
run: go version
Expand All @@ -49,7 +49,7 @@ jobs:
- name: Setup Go 🧰
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: Compute diff 📜
uses: technote-space/get-diff-action@v6.1.2
Expand Down Expand Up @@ -113,7 +113,7 @@ jobs:
- name: Setup Go 🧰
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: Compute diff 📜
uses: technote-space/get-diff-action@v6.1.2
Expand Down Expand Up @@ -220,7 +220,7 @@ jobs:
- name: Setup Go 🧰
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: Compute diff 📜
uses: technote-space/get-diff-action@v6.1.2
Expand Down Expand Up @@ -308,7 +308,7 @@ jobs:
- name: Setup Go 🧰
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- name: Compute diff 📜
uses: technote-space/get-diff-action@v6.1.2
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,10 @@ test-cover:
@export VERSION=$(VERSION); bash -x contrib/test_cover.sh
.PHONY: test-cover

becnchstat_cmd=golang.org/x/perf/cmd/benchstat
benchmark:
@go test -mod=readonly -bench=. -count=$(BENCH_COUNT) -run=^a ./... >bench-$(REF_NAME).txt
@test -s $(GOPATH)/bin/benchstat || GO111MODULE=off GOFLAGS= GOBIN=$(GOPATH)/bin go install -u golang.org/x/perf/cmd/benchstat
@test -e bench-master.txt && benchstat bench-master.txt bench-$(REF_NAME).txt || benchstat bench-$(REF_NAME).txt
@go test -mod=readonly -bench=. -count=$(BENCH_COUNT) -run=^a ./... > bench-$(REF_NAME).txt
@test -e bench-master.txt && go run $(becnchstat_cmd) bench-master.txt bench-$(REF_NAME).txt || go run $(becnchstat_cmd) bench-$(REF_NAME).txt
.PHONY: benchmark

test-mutation:
Expand Down
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ const (
// if telemetry is enabled, the wasmVM cache metrics are activated.
func GetWasmOpts(
appOpts servertypes.AppOptions,
grpcQueryRouter *baseapp.GRPCQueryRouter,
cdc codec.Codec,
profilesKeeper profileskeeper.Keeper,
subspacesKeeper subspaceskeeper.Keeper,
Expand All @@ -203,6 +204,7 @@ func GetWasmOpts(

customQueryPlugin := NewDesmosCustomQueryPlugin(
cdc,
grpcQueryRouter,
profilesKeeper,
subspacesKeeper,
relationshipsKeeper,
Expand Down Expand Up @@ -619,6 +621,7 @@ func NewDesmosApp(

wasmOpts := GetWasmOpts(
appOpts,
app.GRPCQueryRouter(),
app.appCodec,
app.ProfileKeeper,
app.SubspacesKeeper,
Expand Down
70 changes: 69 additions & 1 deletion app/wasm_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,33 @@ package app
import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"

wasmdesmos "github.com/desmos-labs/desmos/v4/cosmwasm"

postskeeper "github.com/desmos-labs/desmos/v4/x/posts/keeper"
poststypes "github.com/desmos-labs/desmos/v4/x/posts/types"
postswasm "github.com/desmos-labs/desmos/v4/x/posts/wasm"

profileskeeper "github.com/desmos-labs/desmos/v4/x/profiles/keeper"
profilestypes "github.com/desmos-labs/desmos/v4/x/profiles/types"
profileswasm "github.com/desmos-labs/desmos/v4/x/profiles/wasm"

reactionskeeper "github.com/desmos-labs/desmos/v4/x/reactions/keeper"
reactionstypes "github.com/desmos-labs/desmos/v4/x/reactions/types"
reactionswasm "github.com/desmos-labs/desmos/v4/x/reactions/wasm"

relationshipskeeper "github.com/desmos-labs/desmos/v4/x/relationships/keeper"
relationshipstypes "github.com/desmos-labs/desmos/v4/x/relationships/types"
relationshipswasm "github.com/desmos-labs/desmos/v4/x/relationships/wasm"

reportskeeper "github.com/desmos-labs/desmos/v4/x/reports/keeper"
reportstypes "github.com/desmos-labs/desmos/v4/x/reports/types"
reportswasm "github.com/desmos-labs/desmos/v4/x/reports/wasm"

subspaceskeeper "github.com/desmos-labs/desmos/v4/x/subspaces/keeper"
subspacestypes "github.com/desmos-labs/desmos/v4/x/subspaces/types"
subspaceswasm "github.com/desmos-labs/desmos/v4/x/subspaces/wasm"
)

Expand All @@ -43,6 +56,7 @@ func NewDesmosWasmGasRegister() wasmkeeper.WasmGasRegister {
// NewDesmosCustomQueryPlugin initialize the custom querier to handle desmos queries for contracts
func NewDesmosCustomQueryPlugin(
cdc codec.Codec,
grpcQueryRouter *baseapp.GRPCQueryRouter,
profilesKeeper profileskeeper.Keeper,
subspacesKeeper subspaceskeeper.Keeper,
relationshipsKeeper relationshipskeeper.Keeper,
Expand All @@ -63,7 +77,61 @@ func NewDesmosCustomQueryPlugin(
querier := wasmdesmos.NewQuerier(queriers)

return wasm.QueryPlugins{
Custom: querier.QueryCustom,
Stargate: wasmkeeper.AcceptListStargateQuerier(GetStargateAcceptedQueries(), grpcQueryRouter, cdc),
Custom: querier.QueryCustom,
}
}

// GetStargateAcceptedQueries returns the stargate accepted queries
func GetStargateAcceptedQueries() wasmkeeper.AcceptedStargateQueries {
return wasmkeeper.AcceptedStargateQueries{
// Register x/profiles queries
"/desmos.profiles.v3.Query/Profile": &profilestypes.QueryProfileResponse{},
"/desmos.profiles.v3.Query/IncomingDTagTransferRequests": &profilestypes.QueryIncomingDTagTransferRequestsResponse{},
"/desmos.profiles.v3.Query/ChainLinks": &profilestypes.QueryChainLinksResponse{},
"/desmos.profiles.v3.Query/ChainLinkOwners": &profilestypes.QueryChainLinkOwnersResponse{},
"/desmos.profiles.v3.Query/DefaultExternalAddresses": &profilestypes.QueryDefaultExternalAddressesResponse{},
"/desmos.profiles.v3.Query/ApplicationLinks": &profilestypes.QueryApplicationLinksResponse{},
"/desmos.profiles.v3.Query/ApplicationLinkByClientID": &profilestypes.QueryApplicationLinkByClientIDResponse{},
"/desmos.profiles.v3.Query/ApplicationLinkOwners": &profilestypes.QueryApplicationLinkOwnersResponse{},

// Register x/relationships queries
"/desmos.relationships.v1.Query/Relationships": &relationshipstypes.QueryRelationshipsResponse{},
"/desmos.relationships.v1.Query/Blocks": &relationshipstypes.QueryBlocksResponse{},

// Register x/subspaces queries
"/desmos.subspaces.v3.Query/Subspaces": &subspacestypes.QuerySubspacesResponse{},
"/desmos.subspaces.v3.Query/Subspace": &subspacestypes.QuerySubspaceResponse{},
"/desmos.subspaces.v3.Query/Sections": &subspacestypes.QuerySectionsResponse{},
"/desmos.subspaces.v3.Query/Section": &subspacestypes.QuerySectionResponse{},
"/desmos.subspaces.v3.Query/UserGroups": &subspacestypes.QueryUserGroupsResponse{},
"/desmos.subspaces.v3.Query/UserGroup": &subspacestypes.QueryUserGroupResponse{},
"/desmos.subspaces.v3.Query/UserGroupMembers": &subspacestypes.QueryUserGroupMembersResponse{},
"/desmos.subspaces.v3.Query/UserPermissions": &subspacestypes.QueryUserPermissionsResponse{},
"/desmos.subspaces.v3.Query/UserAllowances": &subspacestypes.QueryUserAllowancesResponse{},
"/desmos.subspaces.v3.Query/GroupAllowances": &subspacestypes.QueryGroupAllowancesResponse{},

// Register x/posts queries
"/desmos.posts.v3.Query/SubspacePosts": &poststypes.QuerySubspacePostsResponse{},
"/desmos.posts.v3.Query/SectionPosts": &poststypes.QuerySectionPostsResponse{},
"/desmos.posts.v3.Query/Post": &poststypes.QueryPostResponse{},
"/desmos.posts.v3.Query/PostAttachments": &poststypes.QueryPostAttachmentsResponse{},
"/desmos.posts.v3.Query/PollAnswers": &poststypes.QueryPollAnswersResponse{},
"/desmos.posts.v3.Query/Params": &poststypes.QueryParamsResponse{},

// Register x/reports queries
"/desmos.reports.v1.Query/Reports": &reportstypes.QueryReportsResponse{},
"/desmos.reports.v1.Query/Report": &reportstypes.QueryReportResponse{},
"/desmos.reports.v1.Query/Reasons": &reportstypes.QueryReasonsResponse{},
"/desmos.reports.v1.Query/Reason": &reportstypes.QueryReasonResponse{},
"/desmos.reports.v1.Query/Params": &reportstypes.QueryParamsResponse{},

// Register x/reactions queries
"/desmos.reactions.v1.Query/Reactions": &reactionstypes.QueryReactionsResponse{},
"/desmos.reactions.v1.Query/Reaction": &reactionstypes.QueryReactionResponse{},
"/desmos.reactions.v1.Query/RegisteredReactions": &reactionstypes.QueryRegisteredReactionsResponse{},
"/desmos.reactions.v1.Query/RegisteredReaction": &reactionstypes.QueryRegisteredReactionResponse{},
"/desmos.reactions.v1.Query/ReactionsParams": &reactionstypes.QueryReactionsParamsResponse{},
}
}

Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ require (
github.com/Masterminds/semver v1.5.0 // indirect
github.com/OpenPeeDeeP/depguard v1.1.1 // indirect
github.com/Workiva/go-datastructures v1.0.53 // indirect
github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794 // indirect
github.com/alexkohler/prealloc v1.0.0 // indirect
github.com/alingse/asasalint v0.0.11 // indirect
github.com/ashanbrown/forbidigo v1.3.0 // indirect
Expand Down Expand Up @@ -263,6 +264,7 @@ require (
golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/perf v0.0.0-20230221235046-aebcfb61e84c // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/term v0.4.0 // indirect
Expand All @@ -282,7 +284,7 @@ replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0

// Our wasmd branch is: https://github.com/desmos-labs/wasmd v0.30.x-desmos
github.com/CosmWasm/wasmd => github.com/desmos-labs/wasmd v0.30.0-desmos.1
github.com/CosmWasm/wasmd => github.com/desmos-labs/wasmd v0.30.0-desmos.2

// Fixes Dragonberry
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
Expand Down
Loading

0 comments on commit 581e029

Please sign in to comment.