/
wasm_config.go
189 lines (159 loc) · 9.39 KB
/
wasm_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package app
import (
"fmt"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
wasmdesmos "github.com/desmos-labs/desmos/v7/cosmwasm"
postskeeper "github.com/desmos-labs/desmos/v7/x/posts/keeper"
poststypes "github.com/desmos-labs/desmos/v7/x/posts/types"
postswasm "github.com/desmos-labs/desmos/v7/x/posts/wasm"
profileskeeper "github.com/desmos-labs/desmos/v7/x/profiles/keeper"
profilestypes "github.com/desmos-labs/desmos/v7/x/profiles/types"
profileswasm "github.com/desmos-labs/desmos/v7/x/profiles/wasm"
reactionskeeper "github.com/desmos-labs/desmos/v7/x/reactions/keeper"
reactionstypes "github.com/desmos-labs/desmos/v7/x/reactions/types"
reactionswasm "github.com/desmos-labs/desmos/v7/x/reactions/wasm"
relationshipskeeper "github.com/desmos-labs/desmos/v7/x/relationships/keeper"
relationshipstypes "github.com/desmos-labs/desmos/v7/x/relationships/types"
relationshipswasm "github.com/desmos-labs/desmos/v7/x/relationships/wasm"
reportskeeper "github.com/desmos-labs/desmos/v7/x/reports/keeper"
reportstypes "github.com/desmos-labs/desmos/v7/x/reports/types"
reportswasm "github.com/desmos-labs/desmos/v7/x/reports/wasm"
subspaceskeeper "github.com/desmos-labs/desmos/v7/x/subspaces/keeper"
subspacestypes "github.com/desmos-labs/desmos/v7/x/subspaces/types"
subspaceswasm "github.com/desmos-labs/desmos/v7/x/subspaces/wasm"
tokenfactorytypes "github.com/desmos-labs/desmos/v7/x/tokenfactory/types"
desmoswasmtypes "github.com/desmos-labs/desmos/v7/x/wasm/types"
)
const (
// DefaultDesmosInstanceCost is how much SDK gas we charge each time we load a WASM instance
DefaultDesmosInstanceCost uint64 = 60_000
// DefaultDesmosCompileCost is how much SDK gas is charged *per byte* for compiling WASM code
DefaultDesmosCompileCost uint64 = 2
)
// DesmosWasmGasRegister is defaults plus a custom compile amount
func DesmosWasmGasRegister() wasmtypes.WasmGasRegisterConfig {
gasConfig := wasmtypes.DefaultGasRegisterConfig()
gasConfig.InstanceCost = DefaultDesmosInstanceCost
gasConfig.CompileCost = DefaultDesmosCompileCost
return gasConfig
}
func NewDesmosWasmGasRegister() wasmtypes.WasmGasRegister {
return wasmtypes.NewWasmGasRegister(DesmosWasmGasRegister())
}
// 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,
postsKeeper *postskeeper.Keeper,
reportsKeeper reportskeeper.Keeper,
reactionsKeeper reactionskeeper.Keeper,
) wasmkeeper.QueryPlugins {
queriers := map[string]wasmdesmos.Querier{
wasmdesmos.QueryRouteProfiles: profileswasm.NewProfilesWasmQuerier(profilesKeeper, cdc),
wasmdesmos.QueryRouteSubspaces: subspaceswasm.NewSubspacesWasmQuerier(subspacesKeeper, cdc),
wasmdesmos.QueryRouteRelationships: relationshipswasm.NewRelationshipsWasmQuerier(relationshipsKeeper, cdc),
wasmdesmos.QueryRoutePosts: postswasm.NewPostsWasmQuerier(postsKeeper, cdc),
wasmdesmos.QueryRouteReports: reportswasm.NewReportsWasmQuerier(reportsKeeper, cdc),
wasmdesmos.QueryRouteReactions: reactionswasm.NewReactionsWasmQuerier(reactionsKeeper, cdc),
// add other modules querier here
}
querier := wasmdesmos.NewQuerier(queriers)
protoCdc, ok := cdc.(*codec.ProtoCodec)
if !ok {
panic(fmt.Errorf("codec must be *codec.ProtoCodec type: actual: %T", cdc))
}
stargateCdc := codec.NewProtoCodec(desmoswasmtypes.NewWasmInterfaceRegistry(protoCdc.InterfaceRegistry()))
return wasmkeeper.QueryPlugins{
Stargate: wasmkeeper.AcceptListStargateQuerier(GetStargateAcceptedQueries(), grpcQueryRouter, stargateCdc),
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{},
"/desmos.posts.v3.Query/IncomingPostOwnerTransferRequests": &poststypes.QueryIncomingPostOwnerTransferRequestsResponse{},
// 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{},
// Register x/tokenfactory queries
"/desmos.tokenfactory.v1.Query/Params": &tokenfactorytypes.QueryParamsResponse{},
"/desmos.tokenfactory.v1.Query/SubspaceDenoms": &tokenfactorytypes.QuerySubspaceDenomsResponse{},
}
}
// NewDesmosCustomMessageEncoder initialize the custom message encoder to desmos app for contracts
func NewDesmosCustomMessageEncoder(cdc codec.Codec) wasmkeeper.MessageEncoders {
// Initialization of custom Desmos messages for contracts
parserRouter := wasmdesmos.NewParserRouter()
parsers := map[string]wasmdesmos.MsgParserInterface{
wasmdesmos.WasmMsgParserRouteProfiles: profileswasm.NewWasmMsgParser(cdc),
wasmdesmos.WasmMsgParserRouteSubspaces: subspaceswasm.NewWasmMsgParser(cdc),
wasmdesmos.WasmMsgParserRouteRelationships: relationshipswasm.NewWasmMsgParser(cdc),
wasmdesmos.WasmMsgParserRoutePosts: postswasm.NewWasmMsgParser(cdc),
wasmdesmos.WasmMsgParserRouteReports: reportswasm.NewWasmMsgParser(cdc),
wasmdesmos.WasmMsgParserRouteReactions: reactionswasm.NewWasmMsgParser(cdc),
// add other modules parsers here
}
parserRouter.Parsers = parsers
return wasmkeeper.MessageEncoders{
Custom: parserRouter.ParseCustom,
}
}
// AllWasmCapabilities returns all capabilities available with the current wasmvm
// See https://github.com/CosmWasm/cosmwasm/blob/main/docs/CAPABILITIES-BUILT-IN.md
// This functionality is going to be moved upstream: https://github.com/CosmWasm/wasmvm/issues/425
func AllWasmCapabilities() []string {
return []string{
"iterator",
"staking",
"stargate",
"cosmwasm_1_1",
"cosmwasm_1_2",
"cosmwasm_1_3",
"cosmwasm_1_4",
}
}