Skip to content

Commit

Permalink
Add QueryCodeInfoResponse type
Browse files Browse the repository at this point in the history
  • Loading branch information
pinosu committed Aug 2, 2024
1 parent bc6feb1 commit 54d3ead
Show file tree
Hide file tree
Showing 6 changed files with 371 additions and 136 deletions.
18 changes: 17 additions & 1 deletion docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
- [QueryBuildAddressRequest](#cosmwasm.wasm.v1.QueryBuildAddressRequest)
- [QueryBuildAddressResponse](#cosmwasm.wasm.v1.QueryBuildAddressResponse)
- [QueryCodeInfoRequest](#cosmwasm.wasm.v1.QueryCodeInfoRequest)
- [QueryCodeInfoResponse](#cosmwasm.wasm.v1.QueryCodeInfoResponse)
- [QueryCodeRequest](#cosmwasm.wasm.v1.QueryCodeRequest)
- [QueryCodeResponse](#cosmwasm.wasm.v1.QueryCodeResponse)
- [QueryCodesRequest](#cosmwasm.wasm.v1.QueryCodesRequest)
Expand Down Expand Up @@ -1082,6 +1083,21 @@ QueryCodeInfoRequest is the request type for the Query/Code RPC method



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

### QueryCodeInfoResponse
QueryCodeInfoResponse is the response type for the Query/Code RPC method


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `code_info` | [CodeInfoResponse](#cosmwasm.wasm.v1.CodeInfoResponse) | | |






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

### QueryCodeRequest
Expand Down Expand Up @@ -1424,7 +1440,7 @@ Query provides defines the gRPC querier service
| `SmartContractState` | [QuerySmartContractStateRequest](#cosmwasm.wasm.v1.QuerySmartContractStateRequest) | [QuerySmartContractStateResponse](#cosmwasm.wasm.v1.QuerySmartContractStateResponse) | SmartContractState get smart query result from the contract | GET|/cosmwasm/wasm/v1/contract/{address}/smart/{query_data}|
| `Code` | [QueryCodeRequest](#cosmwasm.wasm.v1.QueryCodeRequest) | [QueryCodeResponse](#cosmwasm.wasm.v1.QueryCodeResponse) | Code gets the binary code and metadata for a single 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|
| `CodeInfo` | [QueryCodeInfoRequest](#cosmwasm.wasm.v1.QueryCodeInfoRequest) | [CodeInfoResponse](#cosmwasm.wasm.v1.CodeInfoResponse) | CodeInfo gets the metadata for a single wasm code | GET|/cosmwasm/wasm/v1/code-info/{code_id}|
| `CodeInfo` | [QueryCodeInfoRequest](#cosmwasm.wasm.v1.QueryCodeInfoRequest) | [QueryCodeInfoResponse](#cosmwasm.wasm.v1.QueryCodeInfoResponse) | CodeInfo gets the metadata for a single wasm code | GET|/cosmwasm/wasm/v1/code-info/{code_id}|
| `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|
| `ContractsByCreator` | [QueryContractsByCreatorRequest](#cosmwasm.wasm.v1.QueryContractsByCreatorRequest) | [QueryContractsByCreatorResponse](#cosmwasm.wasm.v1.QueryContractsByCreatorResponse) | ContractsByCreator gets the contracts by creator | GET|/cosmwasm/wasm/v1/contracts/creator/{creator_address}|
Expand Down
9 changes: 8 additions & 1 deletion proto/cosmwasm/wasm/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ service Query {
}

// CodeInfo gets the metadata for a single wasm code
rpc CodeInfo(QueryCodeInfoRequest) returns (CodeInfoResponse) {
rpc CodeInfo(QueryCodeInfoRequest) returns (QueryCodeInfoResponse) {
option (cosmos.query.v1.module_query_safe) = true;
option (google.api.http).get = "/cosmwasm/wasm/v1/code-info/{code_id}";
}
Expand Down Expand Up @@ -222,6 +222,13 @@ message QueryCodeInfoRequest {
uint64 code_id = 1; // grpc-gateway_out does not support Go style CodeID
}

// QueryCodeInfoResponse is the response type for the Query/Code RPC method
message QueryCodeInfoResponse {
option (gogoproto.equal) = true;
CodeInfoResponse code_info = 1
[ (gogoproto.embed) = true, (gogoproto.jsontag) = "" ];
}

// CodeInfoResponse contains code meta data from CodeInfo
message CodeInfoResponse {
option (gogoproto.equal) = true;
Expand Down
5 changes: 4 additions & 1 deletion x/wasm/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,11 @@ func GetCmdQueryCodeInfo() *cobra.Command {
if err != nil {
return err
}
if res.CodeInfoResponse == nil {
return fmt.Errorf("code not found")

Check warning on line 265 in x/wasm/client/cli/query.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/client/cli/query.go#L265

Added line #L265 was not covered by tests
}

return clientCtx.PrintProto(res)
return clientCtx.PrintProto(res.CodeInfoResponse)
},
SilenceUsage: true,
}
Expand Down
10 changes: 6 additions & 4 deletions x/wasm/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,18 +285,20 @@ func (q GrpcQuerier) Codes(c context.Context, req *types.QueryCodesRequest) (*ty
return &types.QueryCodesResponse{CodeInfos: r, Pagination: pageRes}, nil
}

func (q GrpcQuerier) CodeInfo(c context.Context, req *types.QueryCodeInfoRequest) (*types.CodeInfoResponse, error) {
func (q GrpcQuerier) CodeInfo(c context.Context, req *types.QueryCodeInfoRequest) (*types.QueryCodeInfoResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")

Check warning on line 290 in x/wasm/keeper/querier.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/keeper/querier.go#L290

Added line #L290 was not covered by tests
}
if req.CodeId == 0 {
return nil, errorsmod.Wrap(types.ErrInvalid, "code id")

Check warning on line 293 in x/wasm/keeper/querier.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/keeper/querier.go#L293

Added line #L293 was not covered by tests
}
rsp := queryCodeInfo(sdk.UnwrapSDKContext(c), req.CodeId, q.keeper)
if rsp == nil {
info := queryCodeInfo(sdk.UnwrapSDKContext(c), req.CodeId, q.keeper)
if info == nil {
return nil, types.ErrNoSuchCodeFn(req.CodeId).Wrapf("code id %d", req.CodeId)

Check warning on line 297 in x/wasm/keeper/querier.go

View check run for this annotation

Codecov / codecov/patch

x/wasm/keeper/querier.go#L297

Added line #L297 was not covered by tests
}
return rsp, nil
return &types.QueryCodeInfoResponse{
CodeInfoResponse: info,
}, nil
}

func queryContractInfo(ctx sdk.Context, addr sdk.AccAddress, keeper types.ViewKeeper) (*types.QueryContractInfoResponse, error) {
Expand Down
12 changes: 7 additions & 5 deletions x/wasm/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,11 +814,13 @@ func TestQueryCodeInfo(t *testing.T) {
CodeId: spec.codeID,
})
require.NoError(t, err)
expectedResponse := &types.CodeInfoResponse{
CodeID: spec.codeID,
Creator: codeInfo.Creator,
DataHash: codeInfo.CodeHash,
InstantiatePermission: spec.accessConfig,
expectedResponse := &types.QueryCodeInfoResponse{
CodeInfoResponse: &types.CodeInfoResponse{
CodeID: spec.codeID,
Creator: codeInfo.Creator,
DataHash: codeInfo.CodeHash,
InstantiatePermission: spec.accessConfig,
},
}
require.NotNil(t, got)
require.EqualValues(t, expectedResponse, got)
Expand Down
Loading

0 comments on commit 54d3ead

Please sign in to comment.