Skip to content

Commit

Permalink
Add pagination to grpc queries (cosmos#317)
Browse files Browse the repository at this point in the history
* Start pagination for queries

* Complete pagination support

* Cleanups

* Use GRPC endpoint in CLI queries

* Decode page-key in cli

* Review feedback
alpe authored Nov 23, 2020

Verified

This commit was signed with the committer’s verified signature. The key has expired.
nowseemee Daniel Beck
1 parent 8af8006 commit b0b407d
Showing 24 changed files with 1,559 additions and 1,006 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ LEDGER_ENABLED ?= true
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')

# for dockerized protobuf tools
PROTO_CONTAINER := cosmwasm/prototool-docker:latest
PROTO_CONTAINER := cosmwasm/prototools-docker:latest
DOCKER_BUF := docker run --rm -v $(shell pwd)/buf.yaml:/workspace/buf.yaml -v $(shell go list -f "{{ .Dir }}" -m github.com/cosmos/cosmos-sdk):/workspace/cosmos_sdk_dir -v $(shell pwd):/workspace/wasmd --workdir /workspace $(PROTO_CONTAINER)
HTTPS_GIT := https://github.com/CosmWasm/wasmd.git

12 changes: 6 additions & 6 deletions contrib/local/02-contracts.sh
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ wasmd q wasm code "$CODE_ID" "$TMPDIR"
rm -f "$TMPDIR"
echo "-----------------------"
echo "## List code"
wasmd query wasm list-code --node=http://localhost:26657 --chain-id=testing | jq
wasmd query wasm list-code --node=http://localhost:26657 --chain-id=testing -o json | jq

echo "-----------------------"
echo "## Create new contract instance"
@@ -25,16 +25,16 @@ wasmd tx wasm instantiate "$CODE_ID" "$INIT" --admin=$(wasmd keys show validator
--from validator --amount="100ustake" --label "local0.1.0" \
--gas 1000000 -y --chain-id=testing -b block | jq

CONTRACT=$(wasmd query wasm list-contract-by-code "$CODE_ID" -o json | jq -r '.[0].address')
CONTRACT=$(wasmd query wasm list-contract-by-code "$CODE_ID" -o json | jq -r '.contract_infos[-1].address')
echo "* Contract address: $CONTRACT"
echo "### Query all"
RESP=$(wasmd query wasm contract-state all "$CONTRACT" -o json)
echo "$RESP"
echo "$RESP" | jq
echo "### Query smart"
wasmd query wasm contract-state smart "$CONTRACT" '{"verifier":{}}' -o json | jq
echo "### Query raw"
KEY=$(echo "$RESP" | jq -r ".[0].key")
wasmd query wasm contract-state raw "$CONTRACT" "$KEY" -o json
KEY=$(echo "$RESP" | jq -r ".models[0].key")
wasmd query wasm contract-state raw "$CONTRACT" "$KEY" -o json | jq


echo "-----------------------"
@@ -47,7 +47,7 @@ wasmd tx wasm execute "$CONTRACT" "$MSG" \

echo "-----------------------"
echo "## Set new admin"
echo "### Query old admin: $(wasmd q wasm contract $CONTRACT -o json | jq -r '.admin')"
echo "### Query old admin: $(wasmd q wasm contract $CONTRACT -o json | jq -r '.contract_info.admin')"
echo "### Update contract"
wasmd tx wasm set-contract-admin "$CONTRACT" $(wasmd keys show fred -a) \
--from validator -y --chain-id=testing -b block | jq
1 change: 0 additions & 1 deletion contrib/local/03-grpc-queries.sh
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ grpcurl -plaintext -import-path $COSMOS_SDK_DIR/third_party/proto -import-path $
-d "{\"address\": \"$CONTRACT\"}" localhost:9090 wasmd.x.wasmd.v1beta1.Query/ContractHistory | jq

echo "### Show contract state"
CONTRACT=$(echo $RESP | jq -r ".contractInfos[-1].address")
grpcurl -plaintext -import-path $COSMOS_SDK_DIR/third_party/proto -import-path $COSMOS_SDK_DIR/proto -import-path . -proto ./x/wasm/internal/types/query.proto \
-d "{\"address\": \"$CONTRACT\"}" localhost:9090 wasmd.x.wasmd.v1beta1.Query/AllContractState | jq

45 changes: 26 additions & 19 deletions doc/proto.md
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@
- [QueryAllContractStateResponse](#wasmd.x.wasmd.v1beta1.QueryAllContractStateResponse)
- [QueryCodeRequest](#wasmd.x.wasmd.v1beta1.QueryCodeRequest)
- [QueryCodeResponse](#wasmd.x.wasmd.v1beta1.QueryCodeResponse)
- [QueryCodesRequest](#wasmd.x.wasmd.v1beta1.QueryCodesRequest)
- [QueryCodesResponse](#wasmd.x.wasmd.v1beta1.QueryCodesResponse)
- [QueryContractHistoryRequest](#wasmd.x.wasmd.v1beta1.QueryContractHistoryRequest)
- [QueryContractHistoryResponse](#wasmd.x.wasmd.v1beta1.QueryContractHistoryResponse)
@@ -51,7 +52,6 @@
- [AccessTypeParam](#wasmd.x.wasmd.v1beta1.AccessTypeParam)
- [CodeInfo](#wasmd.x.wasmd.v1beta1.CodeInfo)
- [ContractCodeHistoryEntry](#wasmd.x.wasmd.v1beta1.ContractCodeHistoryEntry)
- [ContractHistory](#wasmd.x.wasmd.v1beta1.ContractHistory)
- [ContractInfo](#wasmd.x.wasmd.v1beta1.ContractInfo)
- [Model](#wasmd.x.wasmd.v1beta1.Model)
- [Params](#wasmd.x.wasmd.v1beta1.Params)
@@ -436,6 +436,7 @@ QueryAllContractStateRequest is the request type for the Query/AllContractState
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| address | [string](#string) | | address is the address of the contract |
| pagination | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | pagination defines an optional pagination for the request. |



@@ -451,6 +452,7 @@ QueryAllContractStateResponse is the response type for the Query/AllContractStat
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| models | [Model](#wasmd.x.wasmd.v1beta1.Model) | repeated | |
| pagination | [cosmos.base.query.v1beta1.PageResponse](#cosmos.base.query.v1beta1.PageResponse) | | pagination defines the pagination in the response. |



@@ -488,6 +490,21 @@ QueryCodeResponse is the response type for the Query/Code RPC method



<a name="wasmd.x.wasmd.v1beta1.QueryCodesRequest"></a>

### QueryCodesRequest
QueryCodesRequest is the request type for the Query/Codes RPC method


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| pagination | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | pagination defines an optional pagination for the request. |






<a name="wasmd.x.wasmd.v1beta1.QueryCodesResponse"></a>

### QueryCodesResponse
@@ -497,6 +514,7 @@ QueryCodesResponse is the response type for the Query/Codes RPC method
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| code_infos | [CodeInfoResponse](#wasmd.x.wasmd.v1beta1.CodeInfoResponse) | repeated | |
| pagination | [cosmos.base.query.v1beta1.PageResponse](#cosmos.base.query.v1beta1.PageResponse) | | pagination defines the pagination in the response. |



@@ -512,6 +530,7 @@ QueryContractHistoryRequest is the request type for the Query/ContractHistory RP
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| address | [string](#string) | | address is the address of the contract to query |
| pagination | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | pagination defines an optional pagination for the request. |



@@ -527,6 +546,7 @@ QueryContractHistoryResponse is the response type for the Query/ContractHistory
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| entries | [ContractCodeHistoryEntry](#wasmd.x.wasmd.v1beta1.ContractCodeHistoryEntry) | repeated | |
| pagination | [cosmos.base.query.v1beta1.PageResponse](#cosmos.base.query.v1beta1.PageResponse) | | pagination defines the pagination in the response. |



@@ -573,6 +593,7 @@ QueryContractsByCodeRequest is the request type for the Query/ContractsByCode RP
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| code_id | [uint64](#uint64) | | grpc-gateway_out does not support Go style CodID |
| pagination | [cosmos.base.query.v1beta1.PageRequest](#cosmos.base.query.v1beta1.PageRequest) | | pagination defines an optional pagination for the request. |



@@ -588,6 +609,7 @@ QueryContractsByCodeResponse is the response type for the Query/ContractsByCode
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| contract_infos | [ContractInfoWithAddress](#wasmd.x.wasmd.v1beta1.ContractInfoWithAddress) | repeated | |
| pagination | [cosmos.base.query.v1beta1.PageResponse](#cosmos.base.query.v1beta1.PageResponse) | | pagination defines the pagination in the response. |



@@ -676,7 +698,7 @@ Query provides defines the gRPC querier service
| RawContractState | [QueryRawContractStateRequest](#wasmd.x.wasmd.v1beta1.QueryRawContractStateRequest) | [QueryRawContractStateResponse](#wasmd.x.wasmd.v1beta1.QueryRawContractStateResponse) | RawContractState gets single key from the raw store data of a contract |
| SmartContractState | [QuerySmartContractStateRequest](#wasmd.x.wasmd.v1beta1.QuerySmartContractStateRequest) | [QuerySmartContractStateResponse](#wasmd.x.wasmd.v1beta1.QuerySmartContractStateResponse) | SmartContractState get smart query result from the contract |
| Code | [QueryCodeRequest](#wasmd.x.wasmd.v1beta1.QueryCodeRequest) | [QueryCodeResponse](#wasmd.x.wasmd.v1beta1.QueryCodeResponse) | Code gets the binary code and metadata for a singe wasm code |
| Codes | [.google.protobuf.Empty](#google.protobuf.Empty) | [QueryCodesResponse](#wasmd.x.wasmd.v1beta1.QueryCodesResponse) | Codes gets the metadata for all stored wasm codes |
| Codes | [QueryCodesRequest](#wasmd.x.wasmd.v1beta1.QueryCodesRequest) | [QueryCodesResponse](#wasmd.x.wasmd.v1beta1.QueryCodesResponse) | Codes gets the metadata for all stored wasm codes |



@@ -692,12 +714,12 @@ Query provides defines the gRPC querier service
<a name="wasmd.x.wasmd.v1beta1.AbsoluteTxPosition"></a>

### AbsoluteTxPosition
AbsoluteTxPosition can be used to sort contracts
AbsoluteTxPosition is a unique transaction position that allows for global ordering of transactions.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| block_height | [int64](#int64) | | BlockHeight is the block the contract was created at |
| block_height | [uint64](#uint64) | | BlockHeight is the block the contract was created at |
| tx_index | [uint64](#uint64) | | TxIndex is a monotonic counter within the block (actual transaction index, or gas consumed) |


@@ -773,21 +795,6 @@ ContractCodeHistoryEntry metadata to a contract.



<a name="wasmd.x.wasmd.v1beta1.ContractHistory"></a>

### ContractHistory
ContractHistory contains a sorted list of code updates to a contract


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| code_history_entries | [ContractCodeHistoryEntry](#wasmd.x.wasmd.v1beta1.ContractCodeHistoryEntry) | repeated | |






<a name="wasmd.x.wasmd.v1beta1.ContractInfo"></a>

### ContractInfo
2 changes: 1 addition & 1 deletion x/wasm/alias.go
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ var (
ConvertToProposals = types.ConvertToProposals
GetCodeKey = types.GetCodeKey
GetContractAddressKey = types.GetContractAddressKey
GetContractStorePrefixKey = types.GetContractStorePrefixKey
GetContractStorePrefixKey = types.GetContractStorePrefix
NewCodeInfo = types.NewCodeInfo
NewAbsoluteTxPosition = types.NewAbsoluteTxPosition
NewContractInfo = types.NewContractInfo
Loading

0 comments on commit b0b407d

Please sign in to comment.