Skip to content

Commit

Permalink
feat: add wasm bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmic-vagabond committed Aug 31, 2023
1 parent d9d4200 commit 45c8d42
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,9 @@ func NewElysApp(
// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
availableCapabilities := strings.Join(AllCapabilities(), ",")

wasmOpts = append(RegisterCustomPlugins(), wasmOpts...)

app.WasmKeeper = wasm.NewKeeper(
appCodec,
keys[wasm.StoreKey],
Expand Down
36 changes: 36 additions & 0 deletions app/wasm.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package app

import (
"encoding/json"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// AllCapabilities 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
Expand All @@ -12,3 +21,30 @@ func AllCapabilities() []string {
"cosmwasm_1_2",
}
}

type QueryPlugin struct {
}

// NewQueryPlugin returns a reference to a new QueryPlugin.
func NewQueryPlugin() *QueryPlugin {
return &QueryPlugin{}
}

func RegisterCustomPlugins() []wasmkeeper.Option {
wasmQueryPlugin := NewQueryPlugin()

queryPluginOpt := wasmkeeper.WithQueryPlugins(&wasmkeeper.QueryPlugins{
Custom: CustomQuerier(wasmQueryPlugin),
})

return []wasm.Option{
queryPluginOpt,
}
}

// CustomQuerier dispatches custom CosmWasm bindings queries.
func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessage) ([]byte, error) {
return func(ctx sdk.Context, request json.RawMessage) ([]byte, error) {
return nil, wasmvmtypes.UnsupportedRequest{Kind: "unknown XXXXYYYYZZZ query variant"}
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
cosmossdk.io/math v1.0.1
cosmossdk.io/simapp v0.0.0-20230323161446-0af178d721ff
github.com/CosmWasm/wasmd v0.41.0
github.com/CosmWasm/wasmvm v1.3.0
github.com/bandprotocol/bandchain-packet v0.0.2
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
Expand All @@ -33,7 +34,6 @@ require (
cosmossdk.io/depinject v1.0.0-alpha.3 // indirect
cosmossdk.io/log v1.1.1-0.20230704160919-88f2c830b0ca // indirect
cosmossdk.io/tools/rosetta v0.2.1 // indirect
github.com/CosmWasm/wasmvm v1.3.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/rosetta-sdk-go v0.10.0 // indirect
Expand Down

0 comments on commit 45c8d42

Please sign in to comment.