Skip to content

Commit

Permalink
Merge pull request #969 from public-awesome/jhernandezb/add-params-query
Browse files Browse the repository at this point in the history
add params query
  • Loading branch information
alpe authored Sep 1, 2022
2 parents 62b18f3 + e54d56e commit 0f2794c
Show file tree
Hide file tree
Showing 8 changed files with 582 additions and 76 deletions.
28 changes: 28 additions & 0 deletions docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
- [QueryContractInfoResponse](#cosmwasm.wasm.v1.QueryContractInfoResponse)
- [QueryContractsByCodeRequest](#cosmwasm.wasm.v1.QueryContractsByCodeRequest)
- [QueryContractsByCodeResponse](#cosmwasm.wasm.v1.QueryContractsByCodeResponse)
- [QueryParamsRequest](#cosmwasm.wasm.v1.QueryParamsRequest)
- [QueryParamsResponse](#cosmwasm.wasm.v1.QueryParamsResponse)
- [QueryPinnedCodesRequest](#cosmwasm.wasm.v1.QueryPinnedCodesRequest)
- [QueryPinnedCodesResponse](#cosmwasm.wasm.v1.QueryPinnedCodesResponse)
- [QueryRawContractStateRequest](#cosmwasm.wasm.v1.QueryRawContractStateRequest)
Expand Down Expand Up @@ -1083,6 +1085,31 @@ Query/ContractsByCode RPC method



<a name="cosmwasm.wasm.v1.QueryParamsRequest"></a>

### QueryParamsRequest
QueryParamsRequest is the request type for the Query/Params RPC method.






<a name="cosmwasm.wasm.v1.QueryParamsResponse"></a>

### QueryParamsResponse
QueryParamsResponse is the response type for the Query/Params RPC method.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `params` | [Params](#cosmwasm.wasm.v1.Params) | | params defines the parameters of the module. |






<a name="cosmwasm.wasm.v1.QueryPinnedCodesRequest"></a>

### QueryPinnedCodesRequest
Expand Down Expand Up @@ -1204,6 +1231,7 @@ Query provides defines the gRPC querier service
| `Code` | [QueryCodeRequest](#cosmwasm.wasm.v1.QueryCodeRequest) | [QueryCodeResponse](#cosmwasm.wasm.v1.QueryCodeResponse) | Code gets the binary code and metadata for a singe wasm code | GET|/cosmwasm/wasm/v1/code/{code_id}|
| `Codes` | [QueryCodesRequest](#cosmwasm.wasm.v1.QueryCodesRequest) | [QueryCodesResponse](#cosmwasm.wasm.v1.QueryCodesResponse) | Codes gets the metadata for all stored wasm codes | GET|/cosmwasm/wasm/v1/code|
| `PinnedCodes` | [QueryPinnedCodesRequest](#cosmwasm.wasm.v1.QueryPinnedCodesRequest) | [QueryPinnedCodesResponse](#cosmwasm.wasm.v1.QueryPinnedCodesResponse) | PinnedCodes gets the pinned code ids | GET|/cosmwasm/wasm/v1/codes/pinned|
| `Params` | [QueryParamsRequest](#cosmwasm.wasm.v1.QueryParamsRequest) | [QueryParamsResponse](#cosmwasm.wasm.v1.QueryParamsResponse) | Params gets the module params | GET|/cosmwasm/wasm/v1/codes/params|

<!-- end services -->

Expand Down
14 changes: 14 additions & 0 deletions proto/cosmwasm/wasm/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ service Query {
rpc PinnedCodes(QueryPinnedCodesRequest) returns (QueryPinnedCodesResponse) {
option (google.api.http).get = "/cosmwasm/wasm/v1/codes/pinned";
}

// Params gets the module params
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/cosmwasm/wasm/v1/codes/params";
}
}

// QueryContractInfoRequest is the request type for the Query/ContractInfo RPC
Expand Down Expand Up @@ -222,3 +227,12 @@ message QueryPinnedCodesResponse {
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1 [ (gogoproto.nullable) = false ];
}
30 changes: 30 additions & 0 deletions x/wasm/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func GetQueryCmd() *cobra.Command {
GetCmdGetContractState(),
GetCmdListPinnedCode(),
GetCmdLibVersion(),
GetCmdQueryParams(),
)
return queryCmd
}
Expand Down Expand Up @@ -540,3 +541,32 @@ func withPageKeyDecoded(flagSet *flag.FlagSet) *flag.FlagSet {
}
return flagSet
}

// GetCmdQueryParams implements a command to return the current wasm
// parameters.
func GetCmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "Query the current wasm parameters",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryParamsRequest{}
res, err := queryClient.Params(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(&res.Params)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
7 changes: 7 additions & 0 deletions x/wasm/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,10 @@ func (q grpcQuerier) PinnedCodes(c context.Context, req *types.QueryPinnedCodesR
Pagination: pageRes,
}, nil
}

// Params returns params of the module.
func (q grpcQuerier) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
params := q.keeper.GetParams(ctx)
return &types.QueryParamsResponse{Params: params}, nil
}
28 changes: 28 additions & 0 deletions x/wasm/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,34 @@ func TestQueryPinnedCodes(t *testing.T) {
}
}

func TestQueryParams(t *testing.T) {
ctx, keepers := CreateTestInput(t, false, SupportedFeatures)
keeper := keepers.WasmKeeper

q := Querier(keeper)

paramsResponse, err := q.Params(sdk.WrapSDKContext(ctx), &types.QueryParamsRequest{})
require.NoError(t, err)
require.NotNil(t, paramsResponse)

defaultParams := types.DefaultParams()

require.Equal(t, paramsResponse.Params.CodeUploadAccess, defaultParams.CodeUploadAccess)
require.Equal(t, paramsResponse.Params.InstantiateDefaultPermission, defaultParams.InstantiateDefaultPermission)

keeper.SetParams(ctx, types.Params{
CodeUploadAccess: types.AllowNobody,
InstantiateDefaultPermission: types.AccessTypeNobody,
})

paramsResponse, err = q.Params(sdk.WrapSDKContext(ctx), &types.QueryParamsRequest{})
require.NoError(t, err)
require.NotNil(t, paramsResponse)

require.Equal(t, paramsResponse.Params.CodeUploadAccess, types.AllowNobody)
require.Equal(t, paramsResponse.Params.InstantiateDefaultPermission, types.AccessTypeNobody)
}

func TestQueryCodeInfo(t *testing.T) {
wasmCode, err := os.ReadFile("./testdata/hackatom.wasm")
require.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions x/wasm/types/exported_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ViewKeeper interface {
IterateCodeInfos(ctx sdk.Context, cb func(uint64, CodeInfo) bool)
GetByteCode(ctx sdk.Context, codeID uint64) ([]byte, error)
IsPinnedCode(ctx sdk.Context, codeID uint64) bool
GetParams(ctx sdk.Context) Params
}

// ContractOpsKeeper contains mutable operations on a contract.
Expand Down
Loading

0 comments on commit 0f2794c

Please sign in to comment.