From b0b407d5f839cfa1c8f0bc7fce06032a3ca5c774 Mon Sep 17 00:00:00 2001 From: Alexander Peters Date: Mon, 23 Nov 2020 12:56:25 +0100 Subject: [PATCH] Add pagination to grpc queries (#317) * Start pagination for queries * Complete pagination support * Cleanups * Use GRPC endpoint in CLI queries * Decode page-key in cli * Review feedback --- Makefile | 2 +- contrib/local/02-contracts.sh | 12 +- contrib/local/03-grpc-queries.sh | 1 - doc/proto.md | 45 +- x/wasm/alias.go | 2 +- x/wasm/client/cli/query.go | 194 ++- x/wasm/internal/keeper/genesis_test.go | 29 +- x/wasm/internal/keeper/keeper.go | 68 +- x/wasm/internal/keeper/keeper_test.go | 40 +- x/wasm/internal/keeper/legacy_querier.go | 56 + x/wasm/internal/keeper/legacy_querier_test.go | 6 +- .../keeper/proposal_integration_test.go | 4 +- x/wasm/internal/keeper/querier.go | 168 +-- x/wasm/internal/keeper/querier_test.go | 199 +++- x/wasm/internal/keeper/test_common.go | 44 +- x/wasm/internal/keeper/test_fuzz.go | 2 +- x/wasm/internal/types/keys.go | 62 +- x/wasm/internal/types/keys_test.go | 45 + x/wasm/internal/types/query.pb.go | 1054 ++++++++++------- x/wasm/internal/types/query.pb.gw.go | 77 +- x/wasm/internal/types/query.proto | 36 +- x/wasm/internal/types/types.go | 46 +- x/wasm/internal/types/types.pb.go | 362 ++---- x/wasm/internal/types/types.proto | 11 +- 24 files changed, 1559 insertions(+), 1006 deletions(-) create mode 100644 x/wasm/internal/types/keys_test.go diff --git a/Makefile b/Makefile index 9e3164f3ae..4b89bc8222 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/contrib/local/02-contracts.sh b/contrib/local/02-contracts.sh index 8c7a049830..8d33f8eeaf 100755 --- a/contrib/local/02-contracts.sh +++ b/contrib/local/02-contracts.sh @@ -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 diff --git a/contrib/local/03-grpc-queries.sh b/contrib/local/03-grpc-queries.sh index 43f7d648b7..e4c9d85548 100755 --- a/contrib/local/03-grpc-queries.sh +++ b/contrib/local/03-grpc-queries.sh @@ -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 diff --git a/doc/proto.md b/doc/proto.md index 953c7b491e..8675c83cbd 100644 --- a/doc/proto.md +++ b/doc/proto.md @@ -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 + + +### 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. | + + + + + + ### 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 ### 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. - - -### 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 | | - - - - - - ### ContractInfo diff --git a/x/wasm/alias.go b/x/wasm/alias.go index ba71991763..c52a70cfe6 100644 --- a/x/wasm/alias.go +++ b/x/wasm/alias.go @@ -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 diff --git a/x/wasm/client/cli/query.go b/x/wasm/client/cli/query.go index 6915902180..5ef015e058 100644 --- a/x/wasm/client/cli/query.go +++ b/x/wasm/client/cli/query.go @@ -1,6 +1,7 @@ package cli import ( + "context" "encoding/base64" "encoding/hex" "encoding/json" @@ -9,11 +10,11 @@ import ( "io/ioutil" "strconv" - "github.com/CosmWasm/wasmd/x/wasm/internal/keeper" "github.com/CosmWasm/wasmd/x/wasm/internal/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/gogo/protobuf/proto" "github.com/spf13/cobra" flag "github.com/spf13/pflag" ) @@ -51,16 +52,25 @@ func GetCmdListCode() *cobra.Command { return err } - route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, keeper.QueryListCode) - res, _, err := clientCtx.Query(route) + pageReq, err := client.ReadPageRequest(withPageKeyDecoded(cmd.Flags())) if err != nil { return err } - fmt.Println(string(res)) // TODO: here and others: handle output format proper. See clientCtx.PrintOutput(string(res)) - return nil + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.Codes( + context.Background(), + &types.QueryCodesRequest{ + Pagination: pageReq, + }, + ) + if err != nil { + return err + } + return clientCtx.WithJSONMarshaler(&VanillaStdJsonMarshaller{}).PrintOutput(res) }, } flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "list codes") return cmd } @@ -83,16 +93,26 @@ func GetCmdListContractByCode() *cobra.Command { return err } - route := fmt.Sprintf("custom/%s/%s/%d", types.QuerierRoute, keeper.QueryListContractByCode, codeID) - res, _, err := clientCtx.Query(route) + pageReq, err := client.ReadPageRequest(withPageKeyDecoded(cmd.Flags())) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.ContractsByCode( + context.Background(), + &types.QueryContractsByCodeRequest{ + CodeId: codeID, + Pagination: pageReq, + }, + ) if err != nil { return err } - fmt.Println(string(res)) - return nil + return clientCtx.WithJSONMarshaler(&VanillaStdJsonMarshaller{}).PrintOutput(res) }, } flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "list contracts by code") return cmd } @@ -115,26 +135,22 @@ func GetCmdQueryCode() *cobra.Command { return err } - route := fmt.Sprintf("custom/%s/%s/%d", types.QuerierRoute, keeper.QueryGetCode, codeID) - res, _, err := clientCtx.Query(route) - if err != nil { - return err - } - if len(res) == 0 { - return fmt.Errorf("contract not found") - } - var code types.QueryCodeResponse - err = json.Unmarshal(res, &code) + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.Code( + context.Background(), + &types.QueryCodeRequest{ + CodeId: codeID, + }, + ) if err != nil { return err } - - if len(code.Data) == 0 { + if len(res.Data) == 0 { return fmt.Errorf("contract not found") } fmt.Printf("Downloading wasm code to %s\n", args[1]) - return ioutil.WriteFile(args[1], code.Data, 0644) + return ioutil.WriteFile(args[1], res.Data, 0644) }, } flags.AddQueryFlagsToCmd(cmd) @@ -155,18 +171,21 @@ func GetCmdGetContractInfo() *cobra.Command { return err } - addr, err := sdk.AccAddressFromBech32(args[0]) + _, err = sdk.AccAddressFromBech32(args[0]) if err != nil { return err } - - route := fmt.Sprintf("custom/%s/%s/%s", types.QuerierRoute, keeper.QueryGetContract, addr.String()) - res, _, err := clientCtx.Query(route) + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.ContractInfo( + context.Background(), + &types.QueryContractInfoRequest{ + Address: args[0], + }, + ) if err != nil { return err } - fmt.Println(string(res)) - return nil + return clientCtx.WithJSONMarshaler(&VanillaStdJsonMarshaller{}).PrintOutput(res) }, } flags.AddQueryFlagsToCmd(cmd) @@ -204,21 +223,31 @@ func GetCmdGetContractStateAll() *cobra.Command { return err } - addr, err := sdk.AccAddressFromBech32(args[0]) + _, err = sdk.AccAddressFromBech32(args[0]) if err != nil { return err } - route := fmt.Sprintf("custom/%s/%s/%s/%s", types.QuerierRoute, keeper.QueryGetContractState, addr.String(), keeper.QueryMethodContractStateAll) - res, _, err := clientCtx.Query(route) + pageReq, err := client.ReadPageRequest(withPageKeyDecoded(cmd.Flags())) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.AllContractState( + context.Background(), + &types.QueryAllContractStateRequest{ + Address: args[0], + Pagination: pageReq, + }, + ) if err != nil { return err } - fmt.Println(string(res)) - return nil + return clientCtx.WithJSONMarshaler(&VanillaStdJsonMarshaller{}).PrintOutput(res) }, } flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "contract state") return cmd } @@ -236,7 +265,7 @@ func GetCmdGetContractStateRaw() *cobra.Command { return err } - addr, err := sdk.AccAddressFromBech32(args[0]) + _, err = sdk.AccAddressFromBech32(args[0]) if err != nil { return err } @@ -244,13 +273,19 @@ func GetCmdGetContractStateRaw() *cobra.Command { if err != nil { return err } - route := fmt.Sprintf("custom/%s/%s/%s/%s", types.QuerierRoute, keeper.QueryGetContractState, addr.String(), keeper.QueryMethodContractStateRaw) - res, _, err := clientCtx.QueryWithData(route, queryData) + + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.RawContractState( + context.Background(), + &types.QueryRawContractStateRequest{ + Address: args[0], + QueryData: queryData, + }, + ) if err != nil { return err } - fmt.Println(string(res)) - return nil + return clientCtx.WithJSONMarshaler(&VanillaStdJsonMarshaller{}).PrintOutput(res) }, } decoder.RegisterFlags(cmd.PersistentFlags(), "key argument") @@ -260,7 +295,6 @@ func GetCmdGetContractStateRaw() *cobra.Command { func GetCmdGetContractStateSmart() *cobra.Command { decoder := newArgDecoder(asciiDecodeString) - cmd := &cobra.Command{ Use: "smart [bech32_address] [query]", Short: "Calls contract with given address with query data and prints the returned result", @@ -273,15 +307,13 @@ func GetCmdGetContractStateSmart() *cobra.Command { return err } - addr, err := sdk.AccAddressFromBech32(args[0]) + _, err = sdk.AccAddressFromBech32(args[0]) if err != nil { return err } - key := args[1] - if key == "" { - return errors.New("key must not be empty") + if args[1] == "" { + return errors.New("query data must not be empty") } - route := fmt.Sprintf("custom/%s/%s/%s/%s", types.QuerierRoute, keeper.QueryGetContractState, addr.String(), keeper.QueryMethodContractStateSmart) queryData, err := decoder.DecodeString(args[1]) if err != nil { @@ -290,12 +322,19 @@ func GetCmdGetContractStateSmart() *cobra.Command { if !json.Valid(queryData) { return errors.New("query data must be json") } - res, _, err := clientCtx.QueryWithData(route, queryData) + + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.SmartContractState( + context.Background(), + &types.QuerySmartContractStateRequest{ + Address: args[0], + QueryData: queryData, + }, + ) if err != nil { return err } - fmt.Println(string(res)) - return nil + return clientCtx.WithJSONMarshaler(&VanillaStdJsonMarshaller{}).PrintOutput(res) }, } decoder.RegisterFlags(cmd.PersistentFlags(), "query argument") @@ -317,21 +356,33 @@ func GetCmdGetContractHistory() *cobra.Command { return err } - addr, err := sdk.AccAddressFromBech32(args[0]) - if err != nil { + _, err = sdk.AccAddressFromBech32(args[0]) + if err == nil { return err } - route := fmt.Sprintf("custom/%s/%s/%s", types.QuerierRoute, keeper.QueryContractHistory, addr.String()) - res, _, err := clientCtx.Query(route) + pageReq, err := client.ReadPageRequest(withPageKeyDecoded(cmd.Flags())) if err != nil { return err } - fmt.Println(string(res)) - return nil + queryClient := types.NewQueryClient(clientCtx) + res, err := queryClient.ContractHistory( + context.Background(), + &types.QueryContractHistoryRequest{ + Address: args[0], + Pagination: pageReq, + }, + ) + if err != nil { + return err + } + + return clientCtx.WithJSONMarshaler(&VanillaStdJsonMarshaller{}).PrintOutput(res) }, } + flags.AddQueryFlagsToCmd(cmd) + flags.AddPaginationFlagsToCmd(cmd, "contract history") return cmd } @@ -377,3 +428,40 @@ func (a *argumentDecoder) DecodeString(s string) ([]byte, error) { func asciiDecodeString(s string) ([]byte, error) { return []byte(s), nil } + +type VanillaStdJsonMarshaller struct { +} + +func (x VanillaStdJsonMarshaller) MarshalJSON(o proto.Message) ([]byte, error) { + return json.Marshal(o) +} + +func (x VanillaStdJsonMarshaller) MustMarshalJSON(o proto.Message) []byte { + b, err := x.MarshalJSON(o) + if err != nil { + panic(err) + } + return b +} + +func (x VanillaStdJsonMarshaller) UnmarshalJSON(bz []byte, ptr proto.Message) error { + panic("not supported") +} + +func (x VanillaStdJsonMarshaller) MustUnmarshalJSON(bz []byte, ptr proto.Message) { + panic("not supported") +} + +// sdk ReadPageRequest expects binary but we encoded to base64 in our marshaller +func withPageKeyDecoded(flagSet *flag.FlagSet) *flag.FlagSet { + encoded, err := flagSet.GetString(flags.FlagPageKey) + if err != nil { + panic(err.Error()) + } + raw, err := base64.StdEncoding.DecodeString(encoded) + if err != nil { + panic(err.Error()) + } + flagSet.Set(flags.FlagPageKey, string(raw)) + return flagSet +} diff --git a/x/wasm/internal/keeper/genesis_test.go b/x/wasm/internal/keeper/genesis_test.go index e541bfc72c..6ffa80f8bf 100644 --- a/x/wasm/internal/keeper/genesis_test.go +++ b/x/wasm/internal/keeper/genesis_test.go @@ -56,7 +56,7 @@ func TestGenesisExportImport(t *testing.T) { require.NoError(t, err) contract.CodeID = codeID contractAddr := srcKeeper.generateContractAddress(srcCtx, codeID) - srcKeeper.setContractInfo(srcCtx, contractAddr, &contract) + srcKeeper.storeContractInfo(srcCtx, contractAddr, &contract) srcKeeper.appendToContractHistory(srcCtx, contractAddr, history...) srcKeeper.importContractState(srcCtx, contractAddr, stateModels) } @@ -79,10 +79,11 @@ func TestGenesisExportImport(t *testing.T) { exportedGenesis, err := json.Marshal(exportedState) require.NoError(t, err) - // reset contract history in source DB for comparision with dest DB + // reset ContractInfo in source DB for comparison with dest DB srcKeeper.IterateContractInfo(srcCtx, func(address sdk.AccAddress, info wasmTypes.ContractInfo) bool { + srcKeeper.deleteContractSecondIndex(srcCtx, address, &info) info.ResetFromGenesis(srcCtx) - srcKeeper.setContractInfo(srcCtx, address, &info) + srcKeeper.storeContractInfo(srcCtx, address, &info) return false }) @@ -101,15 +102,21 @@ func TestGenesisExportImport(t *testing.T) { dstIT := dstCtx.KVStore(dstStoreKeys[j]).Iterator(nil, nil) for i := 0; srcIT.Valid(); i++ { - require.True(t, dstIT.Valid(), "[%s] destination DB has less elements than source. Missing: %s", srcStoreKeys[j].Name(), srcIT.Key()) - require.Equal(t, srcIT.Key(), dstIT.Key(), i) - - isContractHistory := srcStoreKeys[j].Name() == types.StoreKey && bytes.HasPrefix(srcIT.Key(), types.ContractHistoryStorePrefix) - if !isContractHistory { // only skip history entries because we know they are different - require.Equal(t, srcIT.Value(), dstIT.Value(), "[%s] element (%d): %X", srcStoreKeys[j].Name(), i, srcIT.Key()) + isContractHistory := srcStoreKeys[j].Name() == types.StoreKey && bytes.HasPrefix(srcIT.Key(), types.ContractCodeHistoryElementPrefix) + if isContractHistory { + // only skip history entries because we know they are different + // from genesis they are merged into 1 single entry + srcIT.Next() + if bytes.HasPrefix(dstIT.Key(), types.ContractCodeHistoryElementPrefix) { + dstIT.Next() + } + continue } - srcIT.Next() + require.True(t, dstIT.Valid(), "[%s] destination DB has less elements than source. Missing: %x", srcStoreKeys[j].Name(), srcIT.Key()) + require.Equal(t, srcIT.Key(), dstIT.Key(), i) + require.Equal(t, srcIT.Value(), dstIT.Value(), "[%s] element (%d): %X", srcStoreKeys[j].Name(), i, srcIT.Key()) dstIT.Next() + srcIT.Next() } if !assert.False(t, dstIT.Valid()) { t.Fatalf("dest Iterator still has key :%X", dstIT.Key()) @@ -472,7 +479,7 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) { Updated: types.NewAbsoluteTxPosition(ctx), }, } - assert.Equal(t, expHistory, keeper.GetContractHistory(ctx, contractAddr).CodeHistoryEntries) + assert.Equal(t, expHistory, keeper.GetContractHistory(ctx, contractAddr)) } func setupKeeper(t *testing.T) (*Keeper, sdk.Context, []sdk.StoreKey, func()) { diff --git a/x/wasm/internal/keeper/keeper.go b/x/wasm/internal/keeper/keeper.go index 28ce1f5968..72aae77896 100644 --- a/x/wasm/internal/keeper/keeper.go +++ b/x/wasm/internal/keeper/keeper.go @@ -233,7 +233,7 @@ func (k Keeper) instantiate(ctx sdk.Context, codeID uint64, creator, admin sdk.A // create prefixed data store // 0x03 | contractAddress (sdk.AccAddress) - prefixStoreKey := types.GetContractStorePrefixKey(contractAddress) + prefixStoreKey := types.GetContractStorePrefix(contractAddress) prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), prefixStoreKey) // prepare querier @@ -256,9 +256,9 @@ func (k Keeper) instantiate(ctx sdk.Context, codeID uint64, creator, admin sdk.A // persist instance first createdAt := types.NewAbsoluteTxPosition(ctx) - instance := types.NewContractInfo(codeID, creator, admin, label, createdAt) - store.Set(types.GetContractAddressKey(contractAddress), k.cdc.MustMarshalBinaryBare(&instance)) - k.appendToContractHistory(ctx, contractAddress, instance.InitialHistory(initMsg)) + contractInfo := types.NewContractInfo(codeID, creator, admin, label, createdAt) + k.storeContractInfo(ctx, contractAddress, &contractInfo) + k.appendToContractHistory(ctx, contractAddress, contractInfo.InitialHistory(initMsg)) // then dispatch so that contract could be called back err = k.dispatchMessages(ctx, contractAddress, res.Messages) @@ -351,7 +351,7 @@ func (k Keeper) migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller Plugins: k.queryPlugins, } - prefixStoreKey := types.GetContractStorePrefixKey(contractAddress) + prefixStoreKey := types.GetContractStorePrefix(contractAddress) prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), prefixStoreKey) gas := gasForContract(ctx) res, gasUsed, err := k.wasmer.Migrate(newCodeInfo.CodeHash, env, info, msg, &prefixStore, cosmwasmAPI, &querier, gasMeter(ctx), gas) @@ -364,10 +364,14 @@ func (k Keeper) migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller events := types.ParseEvents(res.Attributes, contractAddress) ctx.EventManager().EmitEvents(events) + // delete old secondary index entry + k.deleteContractSecondIndex(ctx, contractAddress, contractInfo) + // persist migration updates historyEntry := contractInfo.AddMigration(ctx, newCodeID, msg) k.appendToContractHistory(ctx, contractAddress, historyEntry) - k.setContractInfo(ctx, contractAddress, contractInfo) + k.storeContractInfo(ctx, contractAddress, contractInfo) + // then dispatch if err := k.dispatchMessages(ctx, contractAddress, res.Messages); err != nil { return nil, sdkerrors.Wrap(err, "dispatch") } @@ -377,6 +381,10 @@ func (k Keeper) migrate(ctx sdk.Context, contractAddress sdk.AccAddress, caller }, nil } +func (k Keeper) deleteContractSecondIndex(ctx sdk.Context, contractAddress sdk.AccAddress, contractInfo *types.ContractInfo) { + ctx.KVStore(k.storeKey).Delete(types.GetContractByCreatedSecondaryIndexKey(contractAddress, contractInfo)) +} + // UpdateContractAdmin sets the admin value on the ContractInfo. It must be a valid address (use ClearContractAdmin to remove it) func (k Keeper) UpdateContractAdmin(ctx sdk.Context, contractAddress sdk.AccAddress, caller sdk.AccAddress, newAdmin sdk.AccAddress) error { return k.setContractAdmin(ctx, contractAddress, caller, newAdmin, k.authZPolicy) @@ -396,25 +404,36 @@ func (k Keeper) setContractAdmin(ctx sdk.Context, contractAddress, caller, newAd return sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "can not modify contract") } contractInfo.Admin = newAdmin.String() - k.setContractInfo(ctx, contractAddress, contractInfo) + k.storeContractInfo(ctx, contractAddress, contractInfo) return nil } func (k Keeper) appendToContractHistory(ctx sdk.Context, contractAddr sdk.AccAddress, newEntries ...types.ContractCodeHistoryEntry) { - history := k.GetContractHistory(ctx, contractAddr) - history.CodeHistoryEntries = append(history.CodeHistoryEntries, newEntries...) - prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.ContractHistoryStorePrefix) - prefixStore.Set(contractAddr, k.cdc.MustMarshalBinaryBare(&history)) + store := ctx.KVStore(k.storeKey) + // find last element position + var pos uint64 + prefixStore := prefix.NewStore(store, types.GetContractCodeHistoryElementPrefix(contractAddr)) + if iter := prefixStore.ReverseIterator(nil, nil); iter.Valid() { + pos = sdk.BigEndianToUint64(iter.Value()) + } + // then store with incrementing position + for _, e := range newEntries { + pos++ + key := types.GetContractCodeHistoryElementKey(contractAddr, pos) + store.Set(key, k.cdc.MustMarshalBinaryBare(&e)) + } } -func (k Keeper) GetContractHistory(ctx sdk.Context, contractAddr sdk.AccAddress) types.ContractHistory { - prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.ContractHistoryStorePrefix) - bz := prefixStore.Get(contractAddr) - var history types.ContractHistory - if len(bz) != 0 { - k.cdc.MustUnmarshalBinaryBare(bz, &history) +func (k Keeper) GetContractHistory(ctx sdk.Context, contractAddr sdk.AccAddress) []types.ContractCodeHistoryEntry { + prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.GetContractCodeHistoryElementPrefix(contractAddr)) + r := make([]types.ContractCodeHistoryEntry, 0) + iter := prefixStore.Iterator(nil, nil) + for ; iter.Valid(); iter.Next() { + var e types.ContractCodeHistoryEntry + k.cdc.MustUnmarshalBinaryBare(iter.Value(), &e) + r = append(r, e) } - return history + return r } // QuerySmart queries the smart contract itself. @@ -445,7 +464,7 @@ func (k Keeper) QueryRaw(ctx sdk.Context, contractAddress sdk.AccAddress, key [] if key == nil { return nil } - prefixStoreKey := types.GetContractStorePrefixKey(contractAddress) + prefixStoreKey := types.GetContractStorePrefix(contractAddress) prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), prefixStoreKey) return prefixStore.Get(key) } @@ -466,7 +485,7 @@ func (k Keeper) contractInstance(ctx sdk.Context, contractAddress sdk.AccAddress } var codeInfo types.CodeInfo k.cdc.MustUnmarshalBinaryBare(contractInfoBz, &codeInfo) - prefixStoreKey := types.GetContractStorePrefixKey(contractAddress) + prefixStoreKey := types.GetContractStorePrefix(contractAddress) prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), prefixStoreKey) return codeInfo, prefixStore, nil } @@ -487,9 +506,10 @@ func (k Keeper) containsContractInfo(ctx sdk.Context, contractAddress sdk.AccAdd return store.Has(types.GetContractAddressKey(contractAddress)) } -func (k Keeper) setContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress, contract *types.ContractInfo) { +func (k Keeper) storeContractInfo(ctx sdk.Context, contractAddress sdk.AccAddress, contract *types.ContractInfo) { store := ctx.KVStore(k.storeKey) store.Set(types.GetContractAddressKey(contractAddress), k.cdc.MustMarshalBinaryBare(contract)) + store.Set(types.GetContractByCreatedSecondaryIndexKey(contractAddress, contract), []byte{}) } func (k Keeper) IterateContractInfo(ctx sdk.Context, cb func(sdk.AccAddress, types.ContractInfo) bool) { @@ -506,13 +526,13 @@ func (k Keeper) IterateContractInfo(ctx sdk.Context, cb func(sdk.AccAddress, typ } func (k Keeper) GetContractState(ctx sdk.Context, contractAddress sdk.AccAddress) sdk.Iterator { - prefixStoreKey := types.GetContractStorePrefixKey(contractAddress) + prefixStoreKey := types.GetContractStorePrefix(contractAddress) prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), prefixStoreKey) return prefixStore.Iterator(nil, nil) } func (k Keeper) importContractState(ctx sdk.Context, contractAddress sdk.AccAddress, models []types.Model) error { - prefixStoreKey := types.GetContractStorePrefixKey(contractAddress) + prefixStoreKey := types.GetContractStorePrefix(contractAddress) prefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), prefixStoreKey) for _, model := range models { if model.Value == nil { @@ -663,7 +683,7 @@ func (k Keeper) importContract(ctx sdk.Context, contractAddr sdk.AccAddress, c * historyEntry := c.ResetFromGenesis(ctx) k.appendToContractHistory(ctx, contractAddr, historyEntry) - k.setContractInfo(ctx, contractAddr, c) + k.storeContractInfo(ctx, contractAddr, c) return k.importContractState(ctx, contractAddr, state) } diff --git a/x/wasm/internal/keeper/keeper_test.go b/x/wasm/internal/keeper/keeper_test.go index 8cf77948f8..51b83ebac4 100644 --- a/x/wasm/internal/keeper/keeper_test.go +++ b/x/wasm/internal/keeper/keeper_test.go @@ -278,7 +278,7 @@ func TestInstantiate(t *testing.T) { require.Equal(t, "cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5", contractAddr.String()) gasAfter := ctx.GasMeter().GasConsumed() - require.Equal(t, uint64(0x115e6), gasAfter-gasBefore) + require.Equal(t, uint64(0x11974), gasAfter-gasBefore) // ensure it is stored properly info := keeper.GetContractInfo(ctx, contractAddr) @@ -293,7 +293,7 @@ func TestInstantiate(t *testing.T) { Updated: types.NewAbsoluteTxPosition(ctx), Msg: json.RawMessage(initMsgBz), }} - assert.Equal(t, exp, keeper.GetContractHistory(ctx, contractAddr).CodeHistoryEntries) + assert.Equal(t, exp, keeper.GetContractHistory(ctx, contractAddr)) } func TestInstantiateWithDeposit(t *testing.T) { @@ -860,7 +860,7 @@ func TestMigrate(t *testing.T) { Updated: types.NewAbsoluteTxPosition(ctx), Msg: spec.migrateMsg, }} - assert.Equal(t, expHistory, keeper.GetContractHistory(ctx, contractAddr).CodeHistoryEntries) + assert.Equal(t, expHistory, keeper.GetContractHistory(ctx, contractAddr)) raw := keeper.QueryRaw(ctx, contractAddr, []byte("config")) var stored map[string][]byte @@ -872,6 +872,31 @@ func TestMigrate(t *testing.T) { } } +func TestMigrateReplacesTheSecondIndex(t *testing.T) { + ctx, keepers := CreateTestInput(t, false, SupportedFeatures, nil, nil) + example := InstantiateHackatomExampleContract(t, ctx, keepers) + + // then assert a second index exists + store := ctx.KVStore(keepers.WasmKeeper.storeKey) + oldContractInfo := keepers.WasmKeeper.GetContractInfo(ctx, example.Contract) + require.NotNil(t, oldContractInfo) + exists := store.Has(types.GetContractByCreatedSecondaryIndexKey(example.Contract, oldContractInfo)) + require.True(t, exists) + + // when do migrate + newCodeExample := StoreBurnerExampleContract(t, ctx, keepers) + migMsgBz := BurnerExampleInitMsg{Payout: example.CreatorAddr}.GetBytes(t) + _, err := keepers.WasmKeeper.Migrate(ctx, example.Contract, example.CreatorAddr, newCodeExample.CodeID, migMsgBz) + require.NoError(t, err) + // then the new index exists + newContractInfo := keepers.WasmKeeper.GetContractInfo(ctx, example.Contract) + exists = store.Has(types.GetContractByCreatedSecondaryIndexKey(example.Contract, newContractInfo)) + require.True(t, exists) + // and the old index was removed + exists = store.Has(types.GetContractByCreatedSecondaryIndexKey(example.Contract, oldContractInfo)) + require.False(t, exists) +} + func TestMigrateWithDispatchedMessage(t *testing.T) { ctx, keepers := CreateTestInput(t, false, SupportedFeatures, nil, nil) accKeeper, keeper, bankKeeper := keepers.AccountKeeper, keepers.WasmKeeper, keepers.BankKeeper @@ -896,18 +921,13 @@ func TestMigrateWithDispatchedMessage(t *testing.T) { Verifier: fred, Beneficiary: fred, } - initMsgBz, err := json.Marshal(initMsg) - require.NoError(t, err) + initMsgBz := initMsg.GetBytes(t) ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) contractAddr, err := keeper.Instantiate(ctx, originalContractID, creator, fred, initMsgBz, "demo contract", deposit) require.NoError(t, err) - migMsg := struct { - Payout sdk.AccAddress `json:"payout"` - }{Payout: myPayoutAddr} - migMsgBz, err := json.Marshal(migMsg) - require.NoError(t, err) + migMsgBz := BurnerExampleInitMsg{Payout: myPayoutAddr}.GetBytes(t) ctx = ctx.WithEventManager(sdk.NewEventManager()).WithBlockHeight(ctx.BlockHeight() + 1) res, err := keeper.Migrate(ctx, contractAddr, fred, burnerContractID, migMsgBz) require.NoError(t, err) diff --git a/x/wasm/internal/keeper/legacy_querier.go b/x/wasm/internal/keeper/legacy_querier.go index 7b4ffcb041..12eb987eaf 100644 --- a/x/wasm/internal/keeper/legacy_querier.go +++ b/x/wasm/internal/keeper/legacy_querier.go @@ -3,7 +3,9 @@ package keeper import ( "encoding/json" "reflect" + "sort" "strconv" + "strings" "github.com/CosmWasm/wasmd/x/wasm/internal/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -118,3 +120,57 @@ func queryContractState(ctx sdk.Context, bech, queryMethod string, data []byte, } return bz, nil } + +func queryCodeList(ctx sdk.Context, keeper Keeper) ([]types.CodeInfoResponse, error) { + var info []types.CodeInfoResponse + keeper.IterateCodeInfos(ctx, func(i uint64, res types.CodeInfo) bool { + info = append(info, types.CodeInfoResponse{ + CodeID: i, + Creator: res.Creator, + DataHash: res.CodeHash, + Source: res.Source, + Builder: res.Builder, + }) + return false + }) + return info, nil +} + +func queryContractHistory(ctx sdk.Context, contractAddr sdk.AccAddress, keeper Keeper) ([]types.ContractCodeHistoryEntry, error) { + history := keeper.GetContractHistory(ctx, contractAddr) + // redact response + for i := range history { + history[i].Updated = nil + } + return history, nil +} + +func queryContractListByCode(ctx sdk.Context, codeID uint64, keeper Keeper) ([]types.ContractInfoWithAddress, error) { + var contracts []types.ContractInfoWithAddress + keeper.IterateContractInfo(ctx, func(addr sdk.AccAddress, info types.ContractInfo) bool { + if info.CodeID == codeID { + // and add the address + infoWithAddress := types.ContractInfoWithAddress{ + Address: addr.String(), + ContractInfo: &info, + } + contracts = append(contracts, infoWithAddress) + } + return false + }) + + // now we sort them by AbsoluteTxPosition + sort.Slice(contracts, func(i, j int) bool { + this := contracts[i].ContractInfo.Created + other := contracts[j].ContractInfo.Created + if this.Equal(other) { + return strings.Compare(contracts[i].Address, contracts[j].Address) < 0 + } + return this.LessThan(other) + }) + + for i := range contracts { + contracts[i].Created = nil + } + return contracts, nil +} diff --git a/x/wasm/internal/keeper/legacy_querier_test.go b/x/wasm/internal/keeper/legacy_querier_test.go index 288ff1cd26..06eb00ddc9 100644 --- a/x/wasm/internal/keeper/legacy_querier_test.go +++ b/x/wasm/internal/keeper/legacy_querier_test.go @@ -280,7 +280,7 @@ func TestLegacyQueryContractHistory(t *testing.T) { Updated: types.NewAbsoluteTxPosition(ctx), Msg: []byte(`"init message"`), }}, - expContent: nil, + expContent: []types.ContractCodeHistoryEntry{}, }, } for msg, spec := range specs { @@ -300,10 +300,6 @@ func TestLegacyQueryContractHistory(t *testing.T) { // then require.NoError(t, err) - if spec.expContent == nil { - require.Nil(t, resData) - return - } var got []types.ContractCodeHistoryEntry err = json.Unmarshal(resData, &got) require.NoError(t, err) diff --git a/x/wasm/internal/keeper/proposal_integration_test.go b/x/wasm/internal/keeper/proposal_integration_test.go index ea889cea0b..95f4105198 100644 --- a/x/wasm/internal/keeper/proposal_integration_test.go +++ b/x/wasm/internal/keeper/proposal_integration_test.go @@ -109,7 +109,7 @@ func TestInstantiateProposal(t *testing.T) { Updated: types.NewAbsoluteTxPosition(ctx), Msg: src.InitMsg, }} - assert.Equal(t, expHistory, wasmKeeper.GetContractHistory(ctx, contractAddr).CodeHistoryEntries) + assert.Equal(t, expHistory, wasmKeeper.GetContractHistory(ctx, contractAddr)) } func TestMigrateProposal(t *testing.T) { @@ -184,7 +184,7 @@ func TestMigrateProposal(t *testing.T) { Updated: types.NewAbsoluteTxPosition(ctx), Msg: src.MigrateMsg, }} - assert.Equal(t, expHistory, wasmKeeper.GetContractHistory(ctx, contractAddr).CodeHistoryEntries) + assert.Equal(t, expHistory, wasmKeeper.GetContractHistory(ctx, contractAddr)) } diff --git a/x/wasm/internal/keeper/querier.go b/x/wasm/internal/keeper/querier.go index 74f0ca0182..efa1160afe 100644 --- a/x/wasm/internal/keeper/querier.go +++ b/x/wasm/internal/keeper/querier.go @@ -2,19 +2,21 @@ package keeper import ( "context" - "sort" + "encoding/binary" "github.com/CosmWasm/wasmd/x/wasm/internal/types" + "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - prototypes "github.com/gogo/protobuf/types" + "github.com/cosmos/cosmos-sdk/types/query" ) +var _ types.QueryServer = &grpcQuerier{} + type grpcQuerier struct { keeper *Keeper } -// todo: this needs proper tests and doc func NewQuerier(keeper *Keeper) grpcQuerier { return grpcQuerier{keeper: keeper} } @@ -43,15 +45,27 @@ func (q grpcQuerier) ContractHistory(c context.Context, req *types.QueryContract return nil, err } - rsp, err := queryContractHistory(sdk.UnwrapSDKContext(c), contractAddr, *q.keeper) - switch { - case err != nil: + ctx := sdk.UnwrapSDKContext(c) + r := make([]types.ContractCodeHistoryEntry, 0) + + prefixStore := prefix.NewStore(ctx.KVStore(q.keeper.storeKey), types.GetContractCodeHistoryElementPrefix(contractAddr)) + pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { + if accumulate { + var e types.ContractCodeHistoryEntry + if err := q.keeper.cdc.UnmarshalBinaryBare(value, &e); err != nil { + return false, err + } + e.Updated = nil // redact + r = append(r, e) + } + return true, nil + }) + if err != nil { return nil, err - case rsp == nil: - return nil, types.ErrNotFound } return &types.QueryContractHistoryResponse{ - Entries: rsp, + Entries: r, + Pagination: pageRes, }, nil } @@ -59,15 +73,31 @@ func (q grpcQuerier) ContractsByCode(c context.Context, req *types.QueryContract if req.CodeId == 0 { return nil, sdkerrors.Wrap(types.ErrInvalid, "code id") } - rsp, err := queryContractListByCode(sdk.UnwrapSDKContext(c), req.CodeId, *q.keeper) - switch { - case err != nil: + ctx := sdk.UnwrapSDKContext(c) + r := make([]types.ContractInfoWithAddress, 0) + + prefixStore := prefix.NewStore(ctx.KVStore(q.keeper.storeKey), types.GetContractByCodeIDSecondaryIndexPrefix(req.CodeId)) + pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { + var contractAddr sdk.AccAddress = key[types.AbsoluteTxPositionLen:] + c := q.keeper.GetContractInfo(ctx, contractAddr) + if c == nil { + return false, types.ErrNotFound + } + c.Created = nil // redact + if accumulate { + r = append(r, types.ContractInfoWithAddress{ + Address: contractAddr.String(), + ContractInfo: c, + }) + } + return true, nil + }) + if err != nil { return nil, err - case rsp == nil: - return nil, types.ErrNotFound } return &types.QueryContractsByCodeResponse{ - ContractInfos: rsp, + ContractInfos: r, + Pagination: pageRes, }, nil } @@ -76,19 +106,29 @@ func (q grpcQuerier) AllContractState(c context.Context, req *types.QueryAllCont if err != nil { return nil, err } - ctx := sdk.UnwrapSDKContext(c) if !q.keeper.containsContractInfo(ctx, contractAddr) { return nil, types.ErrNotFound } - var resultData []types.Model - for iter := q.keeper.GetContractState(ctx, contractAddr); iter.Valid(); iter.Next() { - resultData = append(resultData, types.Model{ - Key: iter.Key(), - Value: iter.Value(), - }) + + r := make([]types.Model, 0) + prefixStore := prefix.NewStore(ctx.KVStore(q.keeper.storeKey), types.GetContractStorePrefix(contractAddr)) + pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { + if accumulate { + r = append(r, types.Model{ + Key: key, + Value: value, + }) + } + return true, nil + }) + if err != nil { + return nil, err } - return &types.QueryAllContractStateResponse{Models: resultData}, nil + return &types.QueryAllContractStateResponse{ + Models: r, + Pagination: pageRes, + }, nil } func (q grpcQuerier) RawContractState(c context.Context, req *types.QueryRawContractStateRequest) (*types.QueryRawContractStateResponse, error) { @@ -141,15 +181,30 @@ func (q grpcQuerier) Code(c context.Context, req *types.QueryCodeRequest) (*type }, nil } -func (q grpcQuerier) Codes(c context.Context, _ *prototypes.Empty) (*types.QueryCodesResponse, error) { - rsp, err := queryCodeList(sdk.UnwrapSDKContext(c), *q.keeper) - switch { - case err != nil: +func (q grpcQuerier) Codes(c context.Context, req *types.QueryCodesRequest) (*types.QueryCodesResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + r := make([]types.CodeInfoResponse, 0) + prefixStore := prefix.NewStore(ctx.KVStore(q.keeper.storeKey), types.CodeKeyPrefix) + pageRes, err := query.FilteredPaginate(prefixStore, req.Pagination, func(key []byte, value []byte, accumulate bool) (bool, error) { + if accumulate { + var c types.CodeInfo + if err := q.keeper.cdc.UnmarshalBinaryBare(value, &c); err != nil { + return false, err + } + r = append(r, types.CodeInfoResponse{ + CodeID: binary.BigEndian.Uint64(key), + Creator: c.Creator, + DataHash: c.CodeHash, + Source: c.Source, + Builder: c.Builder, + }) + } + return true, nil + }) + if err != nil { return nil, err - case rsp == nil: - return nil, types.ErrNotFound } - return &types.QueryCodesResponse{CodeInfos: rsp}, nil + return &types.QueryCodesResponse{CodeInfos: r, Pagination: pageRes}, nil } func queryContractInfo(ctx sdk.Context, addr sdk.AccAddress, keeper Keeper) (*types.ContractInfoWithAddress, error) { @@ -165,31 +220,6 @@ func queryContractInfo(ctx sdk.Context, addr sdk.AccAddress, keeper Keeper) (*ty }, nil } -func queryContractListByCode(ctx sdk.Context, codeID uint64, keeper Keeper) ([]types.ContractInfoWithAddress, error) { - var contracts []types.ContractInfoWithAddress - keeper.IterateContractInfo(ctx, func(addr sdk.AccAddress, info types.ContractInfo) bool { - if info.CodeID == codeID { - // and add the address - infoWithAddress := types.ContractInfoWithAddress{ - Address: addr.String(), - ContractInfo: &info, - } - contracts = append(contracts, infoWithAddress) - } - return false - }) - - // now we sort them by AbsoluteTxPosition - sort.Slice(contracts, func(i, j int) bool { - return contracts[i].ContractInfo.Created.LessThan(contracts[j].ContractInfo.Created) - }) - - for i := range contracts { - contracts[i].Created = nil - } - return contracts, nil -} - func queryCode(ctx sdk.Context, codeID uint64, keeper *Keeper) (*types.QueryCodeResponse, error) { if codeID == 0 { return nil, nil @@ -214,31 +244,3 @@ func queryCode(ctx sdk.Context, codeID uint64, keeper *Keeper) (*types.QueryCode return &types.QueryCodeResponse{CodeInfoResponse: &info, Data: code}, nil } - -func queryCodeList(ctx sdk.Context, keeper Keeper) ([]types.CodeInfoResponse, error) { - var info []types.CodeInfoResponse - keeper.IterateCodeInfos(ctx, func(i uint64, res types.CodeInfo) bool { - info = append(info, types.CodeInfoResponse{ - CodeID: i, - Creator: res.Creator, - DataHash: res.CodeHash, - Source: res.Source, - Builder: res.Builder, - }) - return false - }) - return info, nil -} - -func queryContractHistory(ctx sdk.Context, contractAddr sdk.AccAddress, keeper Keeper) ([]types.ContractCodeHistoryEntry, error) { - history := keeper.GetContractHistory(ctx, contractAddr) - if history.CodeHistoryEntries == nil { - // nil, nil leads to 404 in rest handler - return nil, nil - } - // redact response - for i := range history.CodeHistoryEntries { - history.CodeHistoryEntries[i].Updated = nil - } - return history.CodeHistoryEntries, nil -} diff --git a/x/wasm/internal/keeper/querier_test.go b/x/wasm/internal/keeper/querier_test.go index ea54a72cf9..11870da65a 100644 --- a/x/wasm/internal/keeper/querier_test.go +++ b/x/wasm/internal/keeper/querier_test.go @@ -1,7 +1,7 @@ package keeper import ( - "bytes" + "encoding/base64" "encoding/json" "fmt" "io/ioutil" @@ -10,6 +10,7 @@ import ( "github.com/CosmWasm/wasmd/x/wasm/internal/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkErrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/types/query" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -21,16 +22,17 @@ func TestQueryAllContractState(t *testing.T) { exampleContract := InstantiateHackatomExampleContract(t, ctx, keepers) contractAddr := exampleContract.Contract contractModel := []types.Model{ - {Key: []byte("foo"), Value: []byte(`"bar"`)}, {Key: []byte{0x0, 0x1}, Value: []byte(`{"count":8}`)}, + {Key: []byte("foo"), Value: []byte(`"bar"`)}, } require.NoError(t, keeper.importContractState(ctx, contractAddr, contractModel)) q := NewQuerier(keeper) specs := map[string]struct { - srcQuery *types.QueryAllContractStateRequest - expModelContains []types.Model - expErr *sdkErrors.Error + srcQuery *types.QueryAllContractStateRequest + expModelContains []types.Model + expModelContainsNot []types.Model + expErr *sdkErrors.Error }{ "query all": { srcQuery: &types.QueryAllContractStateRequest{Address: contractAddr.String()}, @@ -40,6 +42,48 @@ func TestQueryAllContractState(t *testing.T) { srcQuery: &types.QueryAllContractStateRequest{Address: RandomBech32AccountAddress(t)}, expErr: types.ErrNotFound, }, + "with pagination offset": { + srcQuery: &types.QueryAllContractStateRequest{ + Address: contractAddr.String(), + Pagination: &query.PageRequest{ + Offset: 1, + }, + }, + expModelContains: []types.Model{ + {Key: []byte("foo"), Value: []byte(`"bar"`)}, + }, + expModelContainsNot: []types.Model{ + {Key: []byte{0x0, 0x1}, Value: []byte(`{"count":8}`)}, + }, + }, + "with pagination limit": { + srcQuery: &types.QueryAllContractStateRequest{ + Address: contractAddr.String(), + Pagination: &query.PageRequest{ + Limit: 1, + }, + }, + expModelContains: []types.Model{ + {Key: []byte{0x0, 0x1}, Value: []byte(`{"count":8}`)}, + }, + expModelContainsNot: []types.Model{ + {Key: []byte("foo"), Value: []byte(`"bar"`)}, + }, + }, + "with pagination next key": { + srcQuery: &types.QueryAllContractStateRequest{ + Address: contractAddr.String(), + Pagination: &query.PageRequest{ + Key: fromBase64("Y29uZmln"), + }, + }, + expModelContains: []types.Model{ + {Key: []byte("foo"), Value: []byte(`"bar"`)}, + }, + expModelContainsNot: []types.Model{ + {Key: []byte{0x0, 0x1}, Value: []byte(`{"count":8}`)}, + }, + }, } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { @@ -51,6 +95,9 @@ func TestQueryAllContractState(t *testing.T) { for _, exp := range spec.expModelContains { assert.Contains(t, got.Models, exp) } + for _, exp := range spec.expModelContainsNot { + assert.NotContains(t, got.Models, exp) + } }) } } @@ -120,7 +167,7 @@ func TestQueryRawContractState(t *testing.T) { srcQuery: &types.QueryRawContractStateRequest{Address: contractAddr, QueryData: []byte("foo")}, expData: []byte(`"bar"`), }, - "query raw binary key": { + "query raw contract binary key": { srcQuery: &types.QueryRawContractStateRequest{Address: contractAddr, QueryData: []byte{0x0, 0x1}}, expData: []byte(`{"count":8}`), }, @@ -217,13 +264,14 @@ func TestQueryContractHistory(t *testing.T) { keeper := keepers.WasmKeeper var ( - otherAddr sdk.AccAddress = bytes.Repeat([]byte{0x2}, sdk.AddrLen) + myContractBech32Addr = RandomBech32AccountAddress(t) + otherBech32Addr = RandomBech32AccountAddress(t) ) specs := map[string]struct { - srcQueryAddr sdk.AccAddress - srcHistory []types.ContractCodeHistoryEntry - expContent []types.ContractCodeHistoryEntry + srcHistory []types.ContractCodeHistoryEntry + req types.QueryContractHistoryRequest + expContent []types.ContractCodeHistoryEntry }{ "response with internal fields cleared": { srcHistory: []types.ContractCodeHistoryEntry{{ @@ -232,6 +280,7 @@ func TestQueryContractHistory(t *testing.T) { Updated: types.NewAbsoluteTxPosition(ctx), Msg: []byte(`"init message"`), }}, + req: types.QueryContractHistoryRequest{Address: myContractBech32Addr}, expContent: []types.ContractCodeHistoryEntry{{ Operation: types.ContractCodeHistoryOperationTypeGenesis, CodeID: firstCodeID, @@ -255,6 +304,7 @@ func TestQueryContractHistory(t *testing.T) { Updated: types.NewAbsoluteTxPosition(ctx), Msg: []byte(`"migrate message 2"`), }}, + req: types.QueryContractHistoryRequest{Address: myContractBech32Addr}, expContent: []types.ContractCodeHistoryEntry{{ Operation: types.ContractCodeHistoryOperationTypeInit, CodeID: firstCodeID, @@ -269,8 +319,56 @@ func TestQueryContractHistory(t *testing.T) { Msg: []byte(`"migrate message 2"`), }}, }, + "with pagination offset": { + srcHistory: []types.ContractCodeHistoryEntry{{ + Operation: types.ContractCodeHistoryOperationTypeInit, + CodeID: firstCodeID, + Updated: types.NewAbsoluteTxPosition(ctx), + Msg: []byte(`"init message"`), + }, { + Operation: types.ContractCodeHistoryOperationTypeMigrate, + CodeID: 2, + Updated: types.NewAbsoluteTxPosition(ctx), + Msg: []byte(`"migrate message 1"`), + }}, + req: types.QueryContractHistoryRequest{ + Address: myContractBech32Addr, + Pagination: &query.PageRequest{ + Offset: 1, + }, + }, + expContent: []types.ContractCodeHistoryEntry{{ + Operation: types.ContractCodeHistoryOperationTypeMigrate, + CodeID: 2, + Msg: []byte(`"migrate message 1"`), + }}, + }, + "with pagination limit": { + srcHistory: []types.ContractCodeHistoryEntry{{ + Operation: types.ContractCodeHistoryOperationTypeInit, + CodeID: firstCodeID, + Updated: types.NewAbsoluteTxPosition(ctx), + Msg: []byte(`"init message"`), + }, { + Operation: types.ContractCodeHistoryOperationTypeMigrate, + CodeID: 2, + Updated: types.NewAbsoluteTxPosition(ctx), + Msg: []byte(`"migrate message 1"`), + }}, + req: types.QueryContractHistoryRequest{ + Address: myContractBech32Addr, + Pagination: &query.PageRequest{ + Limit: 1, + }, + }, + expContent: []types.ContractCodeHistoryEntry{{ + Operation: types.ContractCodeHistoryOperationTypeInit, + CodeID: firstCodeID, + Msg: []byte(`"init message"`), + }}, + }, "unknown contract address": { - srcQueryAddr: otherAddr, + req: types.QueryContractHistoryRequest{Address: otherBech32Addr}, srcHistory: []types.ContractCodeHistoryEntry{{ Operation: types.ContractCodeHistoryOperationTypeGenesis, CodeID: firstCodeID, @@ -282,18 +380,14 @@ func TestQueryContractHistory(t *testing.T) { } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - _, _, myContractAddr := keyPubAddr() - keeper.appendToContractHistory(ctx, myContractAddr, spec.srcHistory...) + xCtx, _ := ctx.CacheContext() - queryContractAddr := spec.srcQueryAddr - if queryContractAddr == nil { - queryContractAddr = myContractAddr - } - req := &types.QueryContractHistoryRequest{Address: queryContractAddr.String()} + cAddr, _ := sdk.AccAddressFromBech32(myContractBech32Addr) + keeper.appendToContractHistory(xCtx, cAddr, spec.srcHistory...) // when q := NewQuerier(keeper) - got, err := q.ContractHistory(sdk.WrapSDKContext(ctx), req) + got, err := q.ContractHistory(sdk.WrapSDKContext(xCtx), &spec.req) // then if spec.expContent == nil { @@ -310,44 +404,81 @@ func TestQueryCodeList(t *testing.T) { wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm") require.NoError(t, err) + ctx, keepers := CreateTestInput(t, false, SupportedFeatures, nil, nil) + keeper := keepers.WasmKeeper + specs := map[string]struct { - codeIDs []uint64 + storedCodeIDs []uint64 + req types.QueryCodesRequest + expCodeIDs []uint64 }{ "none": {}, "no gaps": { - codeIDs: []uint64{1, 2, 3}, + storedCodeIDs: []uint64{1, 2, 3}, + expCodeIDs: []uint64{1, 2, 3}, }, "with gaps": { - codeIDs: []uint64{2, 4, 6}, + storedCodeIDs: []uint64{2, 4, 6}, + expCodeIDs: []uint64{2, 4, 6}, + }, + "with pagination offset": { + storedCodeIDs: []uint64{1, 2, 3}, + req: types.QueryCodesRequest{ + Pagination: &query.PageRequest{ + Offset: 1, + }, + }, + expCodeIDs: []uint64{2, 3}, + }, + "with pagination limit": { + storedCodeIDs: []uint64{1, 2, 3}, + req: types.QueryCodesRequest{ + Pagination: &query.PageRequest{ + Limit: 2, + }, + }, + expCodeIDs: []uint64{1, 2}, + }, + "with pagination next key": { + storedCodeIDs: []uint64{1, 2, 3}, + req: types.QueryCodesRequest{ + Pagination: &query.PageRequest{ + Key: fromBase64("AAAAAAAAAAI="), + }, + }, + expCodeIDs: []uint64{2, 3}, }, } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - ctx, keepers := CreateTestInput(t, false, SupportedFeatures, nil, nil) - keeper := keepers.WasmKeeper + xCtx, _ := ctx.CacheContext() - for _, codeID := range spec.codeIDs { - require.NoError(t, keeper.importCode(ctx, codeID, + for _, codeID := range spec.storedCodeIDs { + require.NoError(t, keeper.importCode(xCtx, codeID, types.CodeInfoFixture(types.WithSHA256CodeHash(wasmCode)), wasmCode), ) } // when q := NewQuerier(keeper) - got, err := q.Codes(sdk.WrapSDKContext(ctx), nil) + got, err := q.Codes(sdk.WrapSDKContext(xCtx), &spec.req) // then - if len(spec.codeIDs) == 0 { - require.Error(t, err) - return - } require.NoError(t, err) - - require.Len(t, got.CodeInfos, len(spec.codeIDs)) - for i, exp := range spec.codeIDs { + require.NotNil(t, got.CodeInfos) + require.Len(t, got.CodeInfos, len(spec.expCodeIDs)) + for i, exp := range spec.expCodeIDs { assert.EqualValues(t, exp, got.CodeInfos[i].CodeID) } }) } } + +func fromBase64(s string) []byte { + r, err := base64.StdEncoding.DecodeString(s) + if err != nil { + panic(err) + } + return r +} diff --git a/x/wasm/internal/keeper/test_common.go b/x/wasm/internal/keeper/test_common.go index 13fc586aaa..bd79efd12a 100644 --- a/x/wasm/internal/keeper/test_common.go +++ b/x/wasm/internal/keeper/test_common.go @@ -340,28 +340,36 @@ func RandomBech32AccountAddress(_ *testing.T) string { return addr.String() } -type HackatomExampleContract struct { +type ExampleContract struct { InitialAmount sdk.Coins Creator crypto.PrivKey CreatorAddr sdk.AccAddress CodeID uint64 } -func StoreHackatomExampleContract(t *testing.T, ctx sdk.Context, keepers TestKeepers) HackatomExampleContract { +func StoreHackatomExampleContract(t *testing.T, ctx sdk.Context, keepers TestKeepers) ExampleContract { + return StoreExampleContract(t, ctx, keepers, "./testdata/hackatom.wasm") +} + +func StoreBurnerExampleContract(t *testing.T, ctx sdk.Context, keepers TestKeepers) ExampleContract { + return StoreExampleContract(t, ctx, keepers, "./testdata/burner.wasm") +} + +func StoreExampleContract(t *testing.T, ctx sdk.Context, keepers TestKeepers, wasmFile string) ExampleContract { anyAmount := sdk.NewCoins(sdk.NewInt64Coin("denom", 1000)) creator, _, creatorAddr := keyPubAddr() fundAccounts(t, ctx, keepers.AccountKeeper, keepers.BankKeeper, creatorAddr, anyAmount) - wasmCode, err := ioutil.ReadFile("./testdata/hackatom.wasm") + wasmCode, err := ioutil.ReadFile(wasmFile) require.NoError(t, err) codeID, err := keepers.WasmKeeper.Create(ctx, creatorAddr, wasmCode, "", "", nil) require.NoError(t, err) - return HackatomExampleContract{anyAmount, creator, creatorAddr, codeID} + return ExampleContract{anyAmount, creator, creatorAddr, codeID} } type HackatomExampleInstance struct { - HackatomExampleContract + ExampleContract Contract sdk.AccAddress Verifier crypto.PrivKey VerifierAddr sdk.AccAddress @@ -382,15 +390,17 @@ func InstantiateHackatomExampleContract(t *testing.T, ctx sdk.Context, keepers T Beneficiary: beneficiaryAddr, }.GetBytes(t) initialAmount := sdk.NewCoins(sdk.NewInt64Coin("denom", 100)) - contractAddr, err := keepers.WasmKeeper.Instantiate(ctx, contract.CodeID, contract.CreatorAddr, nil, initMsgBz, "demo contract to query", initialAmount) + + adminAddr := contract.CreatorAddr + contractAddr, err := keepers.WasmKeeper.Instantiate(ctx, contract.CodeID, contract.CreatorAddr, adminAddr, initMsgBz, "demo contract to query", initialAmount) require.NoError(t, err) return HackatomExampleInstance{ - HackatomExampleContract: contract, - Contract: contractAddr, - Verifier: verifier, - VerifierAddr: verifierAddr, - Beneficiary: beneficiary, - BeneficiaryAddr: beneficiaryAddr, + ExampleContract: contract, + Contract: contractAddr, + Verifier: verifier, + VerifierAddr: verifierAddr, + Beneficiary: beneficiary, + BeneficiaryAddr: beneficiaryAddr, } } @@ -405,6 +415,16 @@ func (m HackatomExampleInitMsg) GetBytes(t *testing.T) []byte { return initMsgBz } +type BurnerExampleInitMsg struct { + Payout sdk.AccAddress `json:"payout"` +} + +func (m BurnerExampleInitMsg) GetBytes(t *testing.T) []byte { + initMsgBz, err := json.Marshal(m) + require.NoError(t, err) + return initMsgBz +} + func createFakeFundedAccount(t *testing.T, ctx sdk.Context, am authkeeper.AccountKeeper, bank bankkeeper.Keeper, coins sdk.Coins) sdk.AccAddress { _, _, addr := keyPubAddr() fundAccounts(t, ctx, am, bank, addr, coins) diff --git a/x/wasm/internal/keeper/test_fuzz.go b/x/wasm/internal/keeper/test_fuzz.go index e3f321f9e6..b693e28848 100644 --- a/x/wasm/internal/keeper/test_fuzz.go +++ b/x/wasm/internal/keeper/test_fuzz.go @@ -22,7 +22,7 @@ func FuzzAddrString(m *string, c fuzz.Continue) { } func FuzzAbsoluteTxPosition(m *types.AbsoluteTxPosition, c fuzz.Continue) { - m.BlockHeight = int64(c.RandUint64()) // can't be negative + m.BlockHeight = c.RandUint64() m.TxIndex = c.RandUint64() } diff --git a/x/wasm/internal/types/keys.go b/x/wasm/internal/types/keys.go index c127f0ebbf..a92d7465a1 100644 --- a/x/wasm/internal/types/keys.go +++ b/x/wasm/internal/types/keys.go @@ -1,8 +1,6 @@ package types import ( - "encoding/binary" - sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -31,11 +29,12 @@ const ( // event attributes // nolint var ( - CodeKeyPrefix = []byte{0x01} - ContractKeyPrefix = []byte{0x02} - ContractStorePrefix = []byte{0x03} - SequenceKeyPrefix = []byte{0x04} - ContractHistoryStorePrefix = []byte{0x05} + CodeKeyPrefix = []byte{0x01} + ContractKeyPrefix = []byte{0x02} + ContractStorePrefix = []byte{0x03} + SequenceKeyPrefix = []byte{0x04} + ContractCodeHistoryElementPrefix = []byte{0x05} + ContractByCodeIDAndCreatedSecondaryIndexPrefix = []byte{0x06} KeyLastCodeID = append(SequenceKeyPrefix, []byte("lastCodeId")...) KeyLastInstanceID = append(SequenceKeyPrefix, []byte("lastContractId")...) @@ -47,16 +46,53 @@ func GetCodeKey(codeID uint64) []byte { return append(CodeKeyPrefix, contractIDBz...) } -func decodeCodeKey(src []byte) uint64 { - return binary.BigEndian.Uint64(src[len(CodeKeyPrefix):]) -} - // GetContractAddressKey returns the key for the WASM contract instance func GetContractAddressKey(addr sdk.AccAddress) []byte { return append(ContractKeyPrefix, addr...) } -// GetContractStorePrefixKey returns the store prefix for the WASM contract instance -func GetContractStorePrefixKey(addr sdk.AccAddress) []byte { +// GetContractStorePrefix returns the store prefix for the WASM contract instance +func GetContractStorePrefix(addr sdk.AccAddress) []byte { return append(ContractStorePrefix, addr...) } + +// GetContractByCreatedSecondaryIndexKey returns the key for the secondary index: +// `` +func GetContractByCreatedSecondaryIndexKey(contractAddr sdk.AccAddress, c *ContractInfo) []byte { + prefix := GetContractByCodeIDSecondaryIndexPrefix(c.CodeID) + prefixLen := len(prefix) + r := make([]byte, prefixLen+AbsoluteTxPositionLen+sdk.AddrLen) + copy(r[0:], prefix) + copy(r[prefixLen:], c.Created.Bytes()) + copy(r[prefixLen+AbsoluteTxPositionLen:], contractAddr) + return r +} + +// GetContractByCodeIDSecondaryIndexPrefix returns the prefix for the second index: `` +func GetContractByCodeIDSecondaryIndexPrefix(codeID uint64) []byte { + prefixLen := len(ContractByCodeIDAndCreatedSecondaryIndexPrefix) + const codeIDLen = 8 + r := make([]byte, prefixLen+codeIDLen) + copy(r[0:], ContractByCodeIDAndCreatedSecondaryIndexPrefix) + copy(r[prefixLen:], sdk.Uint64ToBigEndian(codeID)) + return r +} + +// GetContractCodeHistoryElementKey returns the key a contract code history entry: `` +func GetContractCodeHistoryElementKey(contractAddr sdk.AccAddress, pos uint64) []byte { + prefix := GetContractCodeHistoryElementPrefix(contractAddr) + prefixLen := len(prefix) + r := make([]byte, prefixLen+8) + copy(r[0:], prefix) + copy(r[prefixLen:], sdk.Uint64ToBigEndian(pos)) + return r +} + +// GetContractCodeHistoryElementPrefix returns the key prefix for a contract code history entry: `` +func GetContractCodeHistoryElementPrefix(contractAddr sdk.AccAddress) []byte { + prefixLen := len(ContractCodeHistoryElementPrefix) + r := make([]byte, prefixLen+sdk.AddrLen) + copy(r[0:], ContractCodeHistoryElementPrefix) + copy(r[prefixLen:], contractAddr) + return r +} diff --git a/x/wasm/internal/types/keys_test.go b/x/wasm/internal/types/keys_test.go new file mode 100644 index 0000000000..2d12aef6f8 --- /dev/null +++ b/x/wasm/internal/types/keys_test.go @@ -0,0 +1,45 @@ +package types + +import ( + "bytes" + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/assert" +) + +func TestGetContractByCodeIDSecondaryIndexPrefix(t *testing.T) { + specs := map[string]struct { + src uint64 + exp []byte + }{ + "small number": {src: 1, + exp: []byte{6, 0, 0, 0, 0, 0, 0, 0, 1}, + }, + "big number": {src: 1 << (8 * 7), + exp: []byte{6, 1, 0, 0, 0, 0, 0, 0, 0}, + }, + } + for msg, spec := range specs { + t.Run(msg, func(t *testing.T) { + got := GetContractByCodeIDSecondaryIndexPrefix(spec.src) + assert.Equal(t, spec.exp, got) + }) + } +} + +func TestGetContractByCreatedSecondaryIndexKey(t *testing.T) { + c := &ContractInfo{ + CodeID: 1, + Created: &AbsoluteTxPosition{2 + 1<<(8*7), 3 + 1<<(8*7)}, + } + addr := bytes.Repeat([]byte{4}, sdk.AddrLen) + got := GetContractByCreatedSecondaryIndexKey(addr, c) + exp := []byte{6, // prefix + 0, 0, 0, 0, 0, 0, 0, 1, // codeID + 1, 0, 0, 0, 0, 0, 0, 2, // height + 1, 0, 0, 0, 0, 0, 0, 3, // index + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // address + } + assert.Equal(t, exp, got) +} diff --git a/x/wasm/internal/types/query.pb.go b/x/wasm/internal/types/query.pb.go index bd53045c21..c23a2de7f6 100644 --- a/x/wasm/internal/types/query.pb.go +++ b/x/wasm/internal/types/query.pb.go @@ -8,10 +8,10 @@ import ( context "context" encoding_json "encoding/json" fmt "fmt" + query "github.com/cosmos/cosmos-sdk/types/query" _ "github.com/gogo/protobuf/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" - types "github.com/gogo/protobuf/types" github_com_tendermint_tendermint_libs_bytes "github.com/tendermint/tendermint/libs/bytes" _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" @@ -116,6 +116,8 @@ var xxx_messageInfo_QueryContractInfoResponse proto.InternalMessageInfo type QueryContractHistoryRequest struct { // address is the address of the contract to query Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + // pagination defines an optional pagination for the request. + Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } func (m *QueryContractHistoryRequest) Reset() { *m = QueryContractHistoryRequest{} } @@ -154,6 +156,8 @@ var xxx_messageInfo_QueryContractHistoryRequest proto.InternalMessageInfo // QueryContractHistoryResponse is the response type for the Query/ContractHistory RPC method type QueryContractHistoryResponse struct { Entries []ContractCodeHistoryEntry `protobuf:"bytes,1,rep,name=entries,proto3" json:"entries"` + // pagination defines the pagination in the response. + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } func (m *QueryContractHistoryResponse) Reset() { *m = QueryContractHistoryResponse{} } @@ -192,6 +196,8 @@ var xxx_messageInfo_QueryContractHistoryResponse proto.InternalMessageInfo // QueryContractsByCodeRequest is the request type for the Query/ContractsByCode RPC method type QueryContractsByCodeRequest struct { CodeId uint64 `protobuf:"varint,1,opt,name=code_id,json=codeId,proto3" json:"code_id,omitempty"` + // pagination defines an optional pagination for the request. + Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } func (m *QueryContractsByCodeRequest) Reset() { *m = QueryContractsByCodeRequest{} } @@ -269,6 +275,8 @@ var xxx_messageInfo_ContractInfoWithAddress proto.InternalMessageInfo // QueryContractsByCodeResponse is the response type for the Query/ContractsByCode RPC method type QueryContractsByCodeResponse struct { ContractInfos []ContractInfoWithAddress `protobuf:"bytes,1,rep,name=contract_infos,json=contractInfos,proto3" json:"contract_infos"` + // pagination defines the pagination in the response. + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } func (m *QueryContractsByCodeResponse) Reset() { *m = QueryContractsByCodeResponse{} } @@ -308,6 +316,8 @@ var xxx_messageInfo_QueryContractsByCodeResponse proto.InternalMessageInfo type QueryAllContractStateRequest struct { // address is the address of the contract Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + // pagination defines an optional pagination for the request. + Pagination *query.PageRequest `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } func (m *QueryAllContractStateRequest) Reset() { *m = QueryAllContractStateRequest{} } @@ -346,6 +356,8 @@ var xxx_messageInfo_QueryAllContractStateRequest proto.InternalMessageInfo // QueryAllContractStateResponse is the response type for the Query/AllContractState RPC method type QueryAllContractStateResponse struct { Models []Model `protobuf:"bytes,1,rep,name=models,proto3" json:"models"` + // pagination defines the pagination in the response. + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } func (m *QueryAllContractStateResponse) Reset() { *m = QueryAllContractStateResponse{} } @@ -659,16 +671,57 @@ func (m *QueryCodeResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryCodeResponse proto.InternalMessageInfo +// QueryCodesRequest is the request type for the Query/Codes RPC method +type QueryCodesRequest struct { + // pagination defines an optional pagination for the request. + Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"` +} + +func (m *QueryCodesRequest) Reset() { *m = QueryCodesRequest{} } +func (m *QueryCodesRequest) String() string { return proto.CompactTextString(m) } +func (*QueryCodesRequest) ProtoMessage() {} +func (*QueryCodesRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_845473e9a3330642, []int{16} +} +func (m *QueryCodesRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryCodesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryCodesRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryCodesRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryCodesRequest.Merge(m, src) +} +func (m *QueryCodesRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryCodesRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryCodesRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryCodesRequest proto.InternalMessageInfo + // QueryCodesResponse is the response type for the Query/Codes RPC method type QueryCodesResponse struct { CodeInfos []CodeInfoResponse `protobuf:"bytes,1,rep,name=code_infos,json=codeInfos,proto3" json:"code_infos"` + // pagination defines the pagination in the response. + Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"` } func (m *QueryCodesResponse) Reset() { *m = QueryCodesResponse{} } func (m *QueryCodesResponse) String() string { return proto.CompactTextString(m) } func (*QueryCodesResponse) ProtoMessage() {} func (*QueryCodesResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_845473e9a3330642, []int{16} + return fileDescriptor_845473e9a3330642, []int{17} } func (m *QueryCodesResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -714,104 +767,86 @@ func init() { proto.RegisterType((*QueryCodeRequest)(nil), "wasmd.x.wasmd.v1beta1.QueryCodeRequest") proto.RegisterType((*CodeInfoResponse)(nil), "wasmd.x.wasmd.v1beta1.CodeInfoResponse") proto.RegisterType((*QueryCodeResponse)(nil), "wasmd.x.wasmd.v1beta1.QueryCodeResponse") + proto.RegisterType((*QueryCodesRequest)(nil), "wasmd.x.wasmd.v1beta1.QueryCodesRequest") proto.RegisterType((*QueryCodesResponse)(nil), "wasmd.x.wasmd.v1beta1.QueryCodesResponse") } func init() { proto.RegisterFile("x/wasm/internal/types/query.proto", fileDescriptor_845473e9a3330642) } var fileDescriptor_845473e9a3330642 = []byte{ - // 1033 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x97, 0x41, 0x6f, 0x1b, 0x45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, 0x40, 0x97, 0xec, 0x09, - 0xbc, 0x34, 0x16, 0x33, 0xac, 0x9c, 0x35, 0x43, 0xd0, 0x48, 0x56, 0xba, 0x70, 0x57, 0xa2, 0xb1, - 0xb9, 0x79, 0x4f, 0x07, 0xbf, 0xdf, 0x6a, 0x85, 0xba, 0x2d, 0x41, 0x04, 0x4d, 0xde, 0xe9, 0x27, - 0x70, 0x33, 0x46, 0xa9, 0xb9, 0xdf, 0x87, 0x4c, 0x9b, 0xb9, 0xb4, 0x15, 0xf2, 0x16, 0x63, 0x78, - 0x1f, 0x4b, 0x23, 0x4d, 0xa7, 0x15, 0xe6, 0xb6, 0xc6, 0x72, 0xc8, 0xde, 0xc5, 0xb0, 0xf0, 0x4d, - 0x00, 0x35, 0x15, 0x76, 0x5c, 0x22, 0x88, 0xda, 0x9e, 0x25, 0x27, 0xab, 0xbe, 0x79, 0x40, 0x04, - 0x31, 0x2b, 0x9a, 0xfa, 0xac, 0x63, 0x4d, 0x8d, 0x21, 0xad, 0x94, 0x48, 0x29, 0xd5, 0xb3, 0xf9, - 0x19, 0x18, 0x4a, 0xb4, 0xd5, 0x26, 0x81, 0xf8, 0x6f, 0x79, 0xb6, 0xa0, 0x14, 0xeb, 0x5a, 0x13, - 0xad, 0x44, 0x89, 0xaa, 0xc5, 0xe7, 0xfd, 0x52, 0x9e, 0xfa, 0x75, 0xe6, 0x7a, 0x7e, 0xc3, 0xfe, - 0x82, 0x33, 0xdf, 0x72, 0xc8, 0xde, 0x63, 0xca, 0x39, 0x69, 0x50, 0xcd, 0xfb, 0x0e, 0xe4, 0xf4, - 0x89, 0x9a, 0xa1, 0x11, 0x9e, 0x21, 0xc8, 0x49, 0xc3, 0xb1, 0x69, 0x73, 0x7b, 0xc2, 0xba, 0x9a, - 0x1b, 0xf4, 0x4b, 0x19, 0x65, 0xf6, 0xe0, 0xb4, 0x5f, 0x9a, 0xf3, 0xdc, 0x50, 0x2f, 0x53, 0xaf, - 0x07, 0x94, 0x08, 0x16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0x19, - 0xb8, 0x38, 0xed, 0xe0, 0xe2, 0x5d, 0x98, 0x57, 0x13, 0x11, 0x5f, 0xb3, 0x86, 0xaf, 0xd4, 0x56, - 0xf8, 0xbe, 0x6d, 0x3d, 0x94, 0xef, 0xdb, 0x85, 0xdb, 0x49, 0x01, 0x47, 0xc3, 0xd4, 0x2c, 0xa8, - 0x88, 0x57, 0x31, 0x3e, 0x1b, 0xb1, 0xea, 0x1c, 0xfd, 0x6d, 0xa4, 0x7e, 0x1e, 0x18, 0xe8, 0x68, - 0x60, 0xa0, 0xe3, 0x81, 0x81, 0x9e, 0x0d, 0x0c, 0xf4, 0xfd, 0x89, 0x91, 0x3a, 0x3e, 0x31, 0x52, - 0x7f, 0x9d, 0x18, 0xa9, 0xcf, 0x57, 0x22, 0xd7, 0xd2, 0x06, 0xe3, 0xed, 0x6d, 0xe9, 0x43, 0xc5, - 0xb4, 0xf7, 0xf5, 0xe7, 0xf8, 0x7f, 0x0b, 0xb5, 0x8c, 0x42, 0xad, 0xfc, 0x1b, 0x00, 0x00, 0xff, - 0xff, 0x00, 0xb3, 0x57, 0x00, 0x9d, 0x0c, 0x00, 0x00, -} - -func (this *QueryContractInfoRequest) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*QueryContractInfoRequest) - if !ok { - that2, ok := that.(QueryContractInfoRequest) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Address != that1.Address { - return false - } - return true + // 1115 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x97, 0xcf, 0x6f, 0x1b, 0x45, + 0x14, 0xc7, 0x3d, 0xad, 0xf3, 0xc3, 0xaf, 0x29, 0x84, 0x51, 0xa1, 0xc6, 0xb8, 0xeb, 0xb0, 0xa0, + 0xd6, 0x2d, 0xd2, 0x6e, 0x7e, 0x15, 0x41, 0x39, 0x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, 0x2e, 0xe0, 0xb9, 0x4c, 0x5e, + 0x9f, 0x6c, 0x9a, 0xdb, 0x47, 0xe3, 0x67, 0x07, 0xff, 0x8c, 0x00, 0x1f, 0x1f, 0x35, 0xf8, 0xfa, + 0x20, 0x8e, 0xd4, 0xa9, 0x57, 0x7a, 0xf9, 0xb4, 0x6e, 0x2a, 0x81, 0xd7, 0x64, 0x02, 0xd7, 0xf1, + 0x42, 0xb6, 0xe0, 0x41, 0x90, 0x64, 0x0a, 0x0f, 0x20, 0x2f, 0xb7, 0xf3, 0x95, 0xc1, 0x5b, 0xf3, + 0x68, 0x0f, 0x57, 0xb3, 0x0d, 0x15, 0xd7, 0x8b, 0x92, 0x4b, 0xc3, 0xe5, 0x41, 0x1b, 0x17, 0x6f, + 0xc1, 0x98, 0x6c, 0xad, 0x38, 0x33, 0x70, 0xd4, 0xdb, 0x4b, 0x57, 0x87, 0xb0, 0x54, 0x0c, 0x25, + 0xc9, 0x70, 0x01, 0xe3, 0xe3, 0x0c, 0x35, 0x6b, 0xf7, 0x0f, 0x2d, 0xf7, 0x7d, 0x4f, 0xcb, 0xed, + 0xf6, 0x34, 0xb4, 0xd7, 0xd3, 0xd0, 0xef, 0x3d, 0x0d, 0x7d, 0xb5, 0xaf, 0xe5, 0xf6, 0xf6, 0xb5, + 0xdc, 0x6f, 0xfb, 0x5a, 0xee, 0xc3, 0xd9, 0xd8, 0x6c, 0x5d, 0x62, 0xbc, 0xbd, 0x1a, 0xc4, 0x90, + 0x6b, 0x9a, 0x5b, 0xea, 0x7f, 0xf2, 0x47, 0x6c, 0x7d, 0x5c, 0xfe, 0xea, 0x5c, 0xf8, 0x27, 0x00, + 0x00, 0xff, 0xff, 0xfa, 0x9f, 0xf4, 0xfa, 0x34, 0x0f, 0x00, 0x00, } + func (this *QueryContractInfoResponse) Equal(that interface{}) bool { if that == nil { return this == nil @@ -839,83 +874,6 @@ func (this *QueryContractInfoResponse) Equal(that interface{}) bool { } return true } -func (this *QueryContractHistoryRequest) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*QueryContractHistoryRequest) - if !ok { - that2, ok := that.(QueryContractHistoryRequest) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Address != that1.Address { - return false - } - return true -} -func (this *QueryContractHistoryResponse) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*QueryContractHistoryResponse) - if !ok { - that2, ok := that.(QueryContractHistoryResponse) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if len(this.Entries) != len(that1.Entries) { - return false - } - for i := range this.Entries { - if !this.Entries[i].Equal(&that1.Entries[i]) { - return false - } - } - return true -} -func (this *QueryContractsByCodeRequest) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*QueryContractsByCodeRequest) - if !ok { - that2, ok := that.(QueryContractsByCodeRequest) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.CodeId != that1.CodeId { - return false - } - return true -} func (this *ContractInfoWithAddress) Equal(that interface{}) bool { if that == nil { return this == nil @@ -943,214 +901,6 @@ func (this *ContractInfoWithAddress) Equal(that interface{}) bool { } return true } -func (this *QueryContractsByCodeResponse) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*QueryContractsByCodeResponse) - if !ok { - that2, ok := that.(QueryContractsByCodeResponse) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if len(this.ContractInfos) != len(that1.ContractInfos) { - return false - } - for i := range this.ContractInfos { - if !this.ContractInfos[i].Equal(&that1.ContractInfos[i]) { - return false - } - } - return true -} -func (this *QueryAllContractStateRequest) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*QueryAllContractStateRequest) - if !ok { - that2, ok := that.(QueryAllContractStateRequest) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Address != that1.Address { - return false - } - return true -} -func (this *QueryAllContractStateResponse) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*QueryAllContractStateResponse) - if !ok { - that2, ok := that.(QueryAllContractStateResponse) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if len(this.Models) != len(that1.Models) { - return false - } - for i := range this.Models { - if !this.Models[i].Equal(&that1.Models[i]) { - return false - } - } - return true -} -func (this *QueryRawContractStateRequest) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*QueryRawContractStateRequest) - if !ok { - that2, ok := that.(QueryRawContractStateRequest) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Address != that1.Address { - return false - } - if !bytes.Equal(this.QueryData, that1.QueryData) { - return false - } - return true -} -func (this *QueryRawContractStateResponse) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*QueryRawContractStateResponse) - if !ok { - that2, ok := that.(QueryRawContractStateResponse) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if !bytes.Equal(this.Data, that1.Data) { - return false - } - return true -} -func (this *QuerySmartContractStateRequest) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*QuerySmartContractStateRequest) - if !ok { - that2, ok := that.(QuerySmartContractStateRequest) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Address != that1.Address { - return false - } - if !bytes.Equal(this.QueryData, that1.QueryData) { - return false - } - return true -} -func (this *QuerySmartContractStateResponse) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*QuerySmartContractStateResponse) - if !ok { - that2, ok := that.(QuerySmartContractStateResponse) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if !bytes.Equal(this.Data, that1.Data) { - return false - } - return true -} -func (this *QueryCodeRequest) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*QueryCodeRequest) - if !ok { - that2, ok := that.(QueryCodeRequest) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.CodeId != that1.CodeId { - return false - } - return true -} func (this *CodeInfoResponse) Equal(that interface{}) bool { if that == nil { return this == nil @@ -1214,35 +964,6 @@ func (this *QueryCodeResponse) Equal(that interface{}) bool { } return true } -func (this *QueryCodesResponse) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*QueryCodesResponse) - if !ok { - that2, ok := that.(QueryCodesResponse) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if len(this.CodeInfos) != len(that1.CodeInfos) { - return false - } - for i := range this.CodeInfos { - if !this.CodeInfos[i].Equal(&that1.CodeInfos[i]) { - return false - } - } - return true -} // Reference imports to suppress errors if they are not otherwise used. var _ context.Context @@ -1271,7 +992,7 @@ type QueryClient interface { // Code gets the binary code and metadata for a singe wasm code Code(ctx context.Context, in *QueryCodeRequest, opts ...grpc.CallOption) (*QueryCodeResponse, error) // Codes gets the metadata for all stored wasm codes - Codes(ctx context.Context, in *types.Empty, opts ...grpc.CallOption) (*QueryCodesResponse, error) + Codes(ctx context.Context, in *QueryCodesRequest, opts ...grpc.CallOption) (*QueryCodesResponse, error) } type queryClient struct { @@ -1345,7 +1066,7 @@ func (c *queryClient) Code(ctx context.Context, in *QueryCodeRequest, opts ...gr return out, nil } -func (c *queryClient) Codes(ctx context.Context, in *types.Empty, opts ...grpc.CallOption) (*QueryCodesResponse, error) { +func (c *queryClient) Codes(ctx context.Context, in *QueryCodesRequest, opts ...grpc.CallOption) (*QueryCodesResponse, error) { out := new(QueryCodesResponse) err := c.cc.Invoke(ctx, "/wasmd.x.wasmd.v1beta1.Query/Codes", in, out, opts...) if err != nil { @@ -1371,7 +1092,7 @@ type QueryServer interface { // Code gets the binary code and metadata for a singe wasm code Code(context.Context, *QueryCodeRequest) (*QueryCodeResponse, error) // Codes gets the metadata for all stored wasm codes - Codes(context.Context, *types.Empty) (*QueryCodesResponse, error) + Codes(context.Context, *QueryCodesRequest) (*QueryCodesResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -1399,7 +1120,7 @@ func (*UnimplementedQueryServer) SmartContractState(ctx context.Context, req *Qu func (*UnimplementedQueryServer) Code(ctx context.Context, req *QueryCodeRequest) (*QueryCodeResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Code not implemented") } -func (*UnimplementedQueryServer) Codes(ctx context.Context, req *types.Empty) (*QueryCodesResponse, error) { +func (*UnimplementedQueryServer) Codes(ctx context.Context, req *QueryCodesRequest) (*QueryCodesResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Codes not implemented") } @@ -1534,7 +1255,7 @@ func _Query_Code_Handler(srv interface{}, ctx context.Context, dec func(interfac } func _Query_Codes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(types.Empty) + in := new(QueryCodesRequest) if err := dec(in); err != nil { return nil, err } @@ -1546,7 +1267,7 @@ func _Query_Codes_Handler(srv interface{}, ctx context.Context, dec func(interfa FullMethod: "/wasmd.x.wasmd.v1beta1.Query/Codes", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Codes(ctx, req.(*types.Empty)) + return srv.(QueryServer).Codes(ctx, req.(*QueryCodesRequest)) } return interceptor(ctx, in, info, handler) } @@ -1684,6 +1405,18 @@ func (m *QueryContractHistoryRequest) MarshalToSizedBuffer(dAtA []byte) (int, er _ = i var l int _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } if len(m.Address) > 0 { i -= len(m.Address) copy(dAtA[i:], m.Address) @@ -1714,6 +1447,18 @@ func (m *QueryContractHistoryResponse) MarshalToSizedBuffer(dAtA []byte) (int, e _ = i var l int _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } if len(m.Entries) > 0 { for iNdEx := len(m.Entries) - 1; iNdEx >= 0; iNdEx-- { { @@ -1751,6 +1496,18 @@ func (m *QueryContractsByCodeRequest) MarshalToSizedBuffer(dAtA []byte) (int, er _ = i var l int _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } if m.CodeId != 0 { i = encodeVarintQuery(dAtA, i, uint64(m.CodeId)) i-- @@ -1821,6 +1578,18 @@ func (m *QueryContractsByCodeResponse) MarshalToSizedBuffer(dAtA []byte) (int, e _ = i var l int _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } if len(m.ContractInfos) > 0 { for iNdEx := len(m.ContractInfos) - 1; iNdEx >= 0; iNdEx-- { { @@ -1858,6 +1627,18 @@ func (m *QueryAllContractStateRequest) MarshalToSizedBuffer(dAtA []byte) (int, e _ = i var l int _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } if len(m.Address) > 0 { i -= len(m.Address) copy(dAtA[i:], m.Address) @@ -1888,6 +1669,18 @@ func (m *QueryAllContractStateResponse) MarshalToSizedBuffer(dAtA []byte) (int, _ = i var l int _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } if len(m.Models) > 0 { for iNdEx := len(m.Models) - 1; iNdEx >= 0; iNdEx-- { { @@ -2165,6 +1958,41 @@ func (m *QueryCodeResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *QueryCodesRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryCodesRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryCodesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *QueryCodesResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -2185,6 +2013,18 @@ func (m *QueryCodesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.Pagination != nil { + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } if len(m.CodeInfos) > 0 { for iNdEx := len(m.CodeInfos) - 1; iNdEx >= 0; iNdEx-- { { @@ -2253,6 +2093,10 @@ func (m *QueryContractHistoryRequest) Size() (n int) { if l > 0 { n += 1 + l + sovQuery(uint64(l)) } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -2268,6 +2112,10 @@ func (m *QueryContractHistoryResponse) Size() (n int) { n += 1 + l + sovQuery(uint64(l)) } } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -2280,6 +2128,10 @@ func (m *QueryContractsByCodeRequest) Size() (n int) { if m.CodeId != 0 { n += 1 + sovQuery(uint64(m.CodeId)) } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -2312,6 +2164,10 @@ func (m *QueryContractsByCodeResponse) Size() (n int) { n += 1 + l + sovQuery(uint64(l)) } } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -2325,6 +2181,10 @@ func (m *QueryAllContractStateRequest) Size() (n int) { if l > 0 { n += 1 + l + sovQuery(uint64(l)) } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -2340,6 +2200,10 @@ func (m *QueryAllContractStateResponse) Size() (n int) { n += 1 + l + sovQuery(uint64(l)) } } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -2460,6 +2324,19 @@ func (m *QueryCodeResponse) Size() (n int) { return n } +func (m *QueryCodesRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + func (m *QueryCodesResponse) Size() (n int) { if m == nil { return 0 @@ -2472,6 +2349,10 @@ func (m *QueryCodesResponse) Size() (n int) { n += 1 + l + sovQuery(uint64(l)) } } + if m.Pagination != nil { + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + } return n } @@ -2748,6 +2629,42 @@ func (m *QueryContractHistoryRequest) Unmarshal(dAtA []byte) error { } m.Address = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) @@ -2803,7 +2720,41 @@ func (m *QueryContractHistoryResponse) Unmarshal(dAtA []byte) error { switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Entries", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Entries", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Entries = append(m.Entries, ContractCodeHistoryEntry{}) + if err := m.Entries[len(m.Entries)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) } var msglen int for shift := uint(0); ; shift += 7 { @@ -2830,8 +2781,10 @@ func (m *QueryContractHistoryResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Entries = append(m.Entries, ContractCodeHistoryEntry{}) - if err := m.Entries[len(m.Entries)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -2907,6 +2860,42 @@ func (m *QueryContractsByCodeRequest) Unmarshal(dAtA []byte) error { break } } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) @@ -3115,6 +3104,42 @@ func (m *QueryContractsByCodeResponse) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) @@ -3200,6 +3225,42 @@ func (m *QueryAllContractStateRequest) Unmarshal(dAtA []byte) error { } m.Address = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) @@ -3287,6 +3348,42 @@ func (m *QueryAllContractStateResponse) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) @@ -4120,6 +4217,95 @@ func (m *QueryCodeResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *QueryCodesRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryCodesRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryCodesRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageRequest{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *QueryCodesResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -4183,6 +4369,42 @@ func (m *QueryCodesResponse) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pagination == nil { + m.Pagination = &query.PageResponse{} + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) diff --git a/x/wasm/internal/types/query.pb.gw.go b/x/wasm/internal/types/query.pb.gw.go index a6f6cbd3b1..01f89e1506 100644 --- a/x/wasm/internal/types/query.pb.gw.go +++ b/x/wasm/internal/types/query.pb.gw.go @@ -13,7 +13,6 @@ import ( "io" "net/http" - types_1 "github.com/gogo/protobuf/types" "github.com/golang/protobuf/descriptor" "github.com/golang/protobuf/proto" "github.com/grpc-ecosystem/grpc-gateway/runtime" @@ -88,6 +87,10 @@ func local_request_Query_ContractInfo_0(ctx context.Context, marshaler runtime.M } +var ( + filter_Query_ContractHistory_0 = &utilities.DoubleArray{Encoding: map[string]int{"address": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + func request_Query_ContractHistory_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryContractHistoryRequest var metadata runtime.ServerMetadata @@ -110,6 +113,13 @@ func request_Query_ContractHistory_0(ctx context.Context, marshaler runtime.Mars return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ContractHistory_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := client.ContractHistory(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err @@ -137,11 +147,22 @@ func local_request_Query_ContractHistory_0(ctx context.Context, marshaler runtim return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ContractHistory_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.ContractHistory(ctx, &protoReq) return msg, metadata, err } +var ( + filter_Query_ContractsByCode_0 = &utilities.DoubleArray{Encoding: map[string]int{"code_id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + func request_Query_ContractsByCode_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryContractsByCodeRequest var metadata runtime.ServerMetadata @@ -164,6 +185,13 @@ func request_Query_ContractsByCode_0(ctx context.Context, marshaler runtime.Mars return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "code_id", err) } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ContractsByCode_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := client.ContractsByCode(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err @@ -191,11 +219,22 @@ func local_request_Query_ContractsByCode_0(ctx context.Context, marshaler runtim return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "code_id", err) } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_ContractsByCode_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.ContractsByCode(ctx, &protoReq) return msg, metadata, err } +var ( + filter_Query_AllContractState_0 = &utilities.DoubleArray{Encoding: map[string]int{"address": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} +) + func request_Query_AllContractState_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryAllContractStateRequest var metadata runtime.ServerMetadata @@ -218,6 +257,13 @@ func request_Query_AllContractState_0(ctx context.Context, marshaler runtime.Mar return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AllContractState_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := client.AllContractState(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err @@ -245,6 +291,13 @@ func local_request_Query_AllContractState_0(ctx context.Context, marshaler runti return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "address", err) } + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_AllContractState_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.AllContractState(ctx, &protoReq) return msg, metadata, err @@ -456,19 +509,37 @@ func local_request_Query_Code_0(ctx context.Context, marshaler runtime.Marshaler } +var ( + filter_Query_Codes_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + func request_Query_Codes_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq types_1.Empty + var protoReq QueryCodesRequest var metadata runtime.ServerMetadata + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Codes_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := client.Codes(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } func local_request_Query_Codes_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq types_1.Empty + var protoReq QueryCodesRequest var metadata runtime.ServerMetadata + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Codes_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + msg, err := server.Codes(ctx, &protoReq) return msg, metadata, err diff --git a/x/wasm/internal/types/query.proto b/x/wasm/internal/types/query.proto index a553d43eef..24ae620b20 100644 --- a/x/wasm/internal/types/query.proto +++ b/x/wasm/internal/types/query.proto @@ -3,12 +3,12 @@ package wasmd.x.wasmd.v1beta1; import "gogoproto/gogo.proto"; import "x/wasm/internal/types/types.proto"; -import "google/protobuf/empty.proto"; import "google/api/annotations.proto"; +import "cosmos/base/query/v1beta1/pagination.proto"; option go_package = "github.com/CosmWasm/wasmd/x/wasmd/internal/types"; option (gogoproto.goproto_getters_all) = false; -option (gogoproto.equal_all) = true; +option (gogoproto.equal_all) = false; // Query provides defines the gRPC querier service service Query { @@ -41,7 +41,7 @@ service Query { option (google.api.http).get = "/wasm/v1beta1/code/{code_id}"; } // Codes gets the metadata for all stored wasm codes - rpc Codes (google.protobuf.Empty) returns (QueryCodesResponse) { + rpc Codes (QueryCodesRequest) returns (QueryCodesResponse) { option (google.api.http).get = "/wasm/v1beta1/code"; } } @@ -53,6 +53,8 @@ message QueryContractInfoRequest { } // QueryContractInfoResponse is the response type for the Query/ContractInfo RPC method message QueryContractInfoResponse { + option (gogoproto.equal) = true; + // address is the address of the contract string address = 1; ContractInfo contract_info = 2 [(gogoproto.embed) = true, (gogoproto.jsontag) = ""]; @@ -62,36 +64,51 @@ message QueryContractInfoResponse { message QueryContractHistoryRequest { // address is the address of the contract to query string address = 1; + // pagination defines an optional pagination for the request. + cosmos.base.query.v1beta1.PageRequest pagination = 2; } // QueryContractHistoryResponse is the response type for the Query/ContractHistory RPC method message QueryContractHistoryResponse { repeated ContractCodeHistoryEntry entries = 1 [(gogoproto.nullable) = false]; + // pagination defines the pagination in the response. + cosmos.base.query.v1beta1.PageResponse pagination = 2; } + // QueryContractsByCodeRequest is the request type for the Query/ContractsByCode RPC method message QueryContractsByCodeRequest { uint64 code_id = 1; // grpc-gateway_out does not support Go style CodID + // pagination defines an optional pagination for the request. + cosmos.base.query.v1beta1.PageRequest pagination = 2; } // ContractInfoWithAddress adds the address (key) to the ContractInfo representation message ContractInfoWithAddress { + option (gogoproto.equal) = true; + string address = 1; ContractInfo contract_info = 2 [(gogoproto.embed) = true, (gogoproto.jsontag) = ""]; } // QueryContractsByCodeResponse is the response type for the Query/ContractsByCode RPC method message QueryContractsByCodeResponse { repeated ContractInfoWithAddress contract_infos = 1 [(gogoproto.nullable) = false]; + // pagination defines the pagination in the response. + cosmos.base.query.v1beta1.PageResponse pagination = 2; } // QueryAllContractStateRequest is the request type for the Query/AllContractState RPC method message QueryAllContractStateRequest { // address is the address of the contract string address = 1; + // pagination defines an optional pagination for the request. + cosmos.base.query.v1beta1.PageRequest pagination = 2; } // QueryAllContractStateResponse is the response type for the Query/AllContractState RPC method message QueryAllContractStateResponse { repeated Model models = 1 [(gogoproto.nullable) = false]; + // pagination defines the pagination in the response. + cosmos.base.query.v1beta1.PageResponse pagination = 2; } // QueryRawContractStateRequest is the request type for the Query/RawContractState RPC method @@ -100,6 +117,7 @@ message QueryRawContractStateRequest { string address = 1; bytes query_data = 2; } + // QueryRawContractStateResponse is the response type for the Query/RawContractState RPC method message QueryRawContractStateResponse { // Data contains the raw store data @@ -113,6 +131,7 @@ message QuerySmartContractStateRequest { // QueryData contains the query data passed to the contract bytes query_data = 2; } + // QuerySmartContractStateResponse is the response type for the Query/SmartContractState RPC method message QuerySmartContractStateResponse { // Data contains the json data returned from the smart contract @@ -126,6 +145,8 @@ message QueryCodeRequest { // CodeInfoResponse contains code meta data from CodeInfo message CodeInfoResponse { + option (gogoproto.equal) = true; + uint64 code_id = 1 [(gogoproto.customname) = "CodeID", (gogoproto.jsontag) = "id"]; // id for legacy support string creator = 2; bytes data_hash = 3 [(gogoproto.casttype) = "github.com/tendermint/tendermint/libs/bytes.HexBytes"]; @@ -135,11 +156,20 @@ message CodeInfoResponse { // QueryCodeResponse is the response type for the Query/Code RPC method message QueryCodeResponse { + option (gogoproto.equal) = true; CodeInfoResponse code_info = 1 [(gogoproto.embed) = true, (gogoproto.jsontag) = ""]; bytes data = 2 [(gogoproto.jsontag) = "data"]; } +// QueryCodesRequest is the request type for the Query/Codes RPC method +message QueryCodesRequest { + // pagination defines an optional pagination for the request. + cosmos.base.query.v1beta1.PageRequest pagination = 1; +} + // QueryCodesResponse is the response type for the Query/Codes RPC method message QueryCodesResponse { repeated CodeInfoResponse code_infos = 1 [(gogoproto.nullable) = false]; + // pagination defines the pagination in the response. + cosmos.base.query.v1beta1.PageResponse pagination = 2; } diff --git a/x/wasm/internal/types/types.go b/x/wasm/internal/types/types.go index c21a2814e1..66537bd33c 100644 --- a/x/wasm/internal/types/types.go +++ b/x/wasm/internal/types/types.go @@ -1,6 +1,8 @@ package types import ( + "fmt" + wasmvmtypes "github.com/CosmWasm/wasmvm/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -51,10 +53,6 @@ func NewCodeInfo(codeHash []byte, creator sdk.AccAddress, source string, builder var AllCodeHistoryTypes = []ContractCodeHistoryOperationType{ContractCodeHistoryOperationTypeGenesis, ContractCodeHistoryOperationTypeInit, ContractCodeHistoryOperationTypeMigrate} -func (c *ContractHistory) AppendCodeHistory(newEntries ...ContractCodeHistoryEntry) { - c.CodeHistoryEntries = append(c.CodeHistoryEntries, newEntries...) -} - // NewContractInfo creates a new instance of a given WASM contract info func NewContractInfo(codeID uint64, creator, admin sdk.AccAddress, label string, createdAt *AbsoluteTxPosition) ContractInfo { var adminAddr string @@ -130,6 +128,24 @@ func (c *ContractInfo) AdminAddr() sdk.AccAddress { return admin } +// NewAbsoluteTxPosition gets a block position from the context +func NewAbsoluteTxPosition(ctx sdk.Context) *AbsoluteTxPosition { + // we must safely handle nil gas meters + var index uint64 + meter := ctx.BlockGasMeter() + if meter != nil { + index = meter.GasConsumed() + } + height := ctx.BlockHeight() + if height < 0 { + panic(fmt.Sprintf("unsupported height: %d", height)) + } + return &AbsoluteTxPosition{ + BlockHeight: uint64(height), + TxIndex: index, + } +} + // LessThan can be used to sort func (a *AbsoluteTxPosition) LessThan(b *AbsoluteTxPosition) bool { if a == nil { @@ -141,18 +157,18 @@ func (a *AbsoluteTxPosition) LessThan(b *AbsoluteTxPosition) bool { return a.BlockHeight < b.BlockHeight || (a.BlockHeight == b.BlockHeight && a.TxIndex < b.TxIndex) } -// NewAbsoluteTxPosition gets a timestamp from the context -func NewAbsoluteTxPosition(ctx sdk.Context) *AbsoluteTxPosition { - // we must safely handle nil gas meters - var index uint64 - meter := ctx.BlockGasMeter() - if meter != nil { - index = meter.GasConsumed() - } - return &AbsoluteTxPosition{ - BlockHeight: ctx.BlockHeight(), - TxIndex: index, +// AbsoluteTxPositionLen number of elements in byte representation +const AbsoluteTxPositionLen = 16 + +// Bytes encodes the object into a 16 byte representation with big endian block height and tx index. +func (a *AbsoluteTxPosition) Bytes() []byte { + if a == nil { + panic("object must not be nil") } + r := make([]byte, AbsoluteTxPositionLen) + copy(r[0:], sdk.Uint64ToBigEndian(a.BlockHeight)) + copy(r[8:], sdk.Uint64ToBigEndian(a.TxIndex)) + return r } // NewEnv initializes the environment for a contract instance diff --git a/x/wasm/internal/types/types.pb.go b/x/wasm/internal/types/types.pb.go index 2ba8637bb8..7a466d37ae 100644 --- a/x/wasm/internal/types/types.pb.go +++ b/x/wasm/internal/types/types.pb.go @@ -305,44 +305,6 @@ func (m *ContractInfo) XXX_DiscardUnknown() { var xxx_messageInfo_ContractInfo proto.InternalMessageInfo -// ContractHistory contains a sorted list of code updates to a contract -type ContractHistory struct { - CodeHistoryEntries []ContractCodeHistoryEntry `protobuf:"bytes,1,rep,name=code_history_entries,json=codeHistoryEntries,proto3" json:"code_history_entries"` -} - -func (m *ContractHistory) Reset() { *m = ContractHistory{} } -func (m *ContractHistory) String() string { return proto.CompactTextString(m) } -func (*ContractHistory) ProtoMessage() {} -func (*ContractHistory) Descriptor() ([]byte, []int) { - return fileDescriptor_45de2b3fc8aff6aa, []int{5} -} -func (m *ContractHistory) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *ContractHistory) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_ContractHistory.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *ContractHistory) XXX_Merge(src proto.Message) { - xxx_messageInfo_ContractHistory.Merge(m, src) -} -func (m *ContractHistory) XXX_Size() int { - return m.Size() -} -func (m *ContractHistory) XXX_DiscardUnknown() { - xxx_messageInfo_ContractHistory.DiscardUnknown(m) -} - -var xxx_messageInfo_ContractHistory proto.InternalMessageInfo - // ContractCodeHistoryEntry metadata to a contract. type ContractCodeHistoryEntry struct { Operation ContractCodeHistoryOperationType `protobuf:"varint,1,opt,name=operation,proto3,enum=wasmd.x.wasmd.v1beta1.ContractCodeHistoryOperationType" json:"operation,omitempty"` @@ -357,7 +319,7 @@ func (m *ContractCodeHistoryEntry) Reset() { *m = ContractCodeHistoryEnt func (m *ContractCodeHistoryEntry) String() string { return proto.CompactTextString(m) } func (*ContractCodeHistoryEntry) ProtoMessage() {} func (*ContractCodeHistoryEntry) Descriptor() ([]byte, []int) { - return fileDescriptor_45de2b3fc8aff6aa, []int{6} + return fileDescriptor_45de2b3fc8aff6aa, []int{5} } func (m *ContractCodeHistoryEntry) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -386,10 +348,10 @@ func (m *ContractCodeHistoryEntry) XXX_DiscardUnknown() { var xxx_messageInfo_ContractCodeHistoryEntry proto.InternalMessageInfo -// AbsoluteTxPosition can be used to sort contracts +// AbsoluteTxPosition is a unique transaction position that allows for global ordering of transactions. type AbsoluteTxPosition struct { // BlockHeight is the block the contract was created at - BlockHeight int64 `protobuf:"varint,1,opt,name=block_height,json=blockHeight,proto3" json:"block_height,omitempty"` + BlockHeight uint64 `protobuf:"varint,1,opt,name=block_height,json=blockHeight,proto3" json:"block_height,omitempty"` // TxIndex is a monotonic counter within the block (actual transaction index, or gas consumed) TxIndex uint64 `protobuf:"varint,2,opt,name=tx_index,json=txIndex,proto3" json:"tx_index,omitempty"` } @@ -398,7 +360,7 @@ func (m *AbsoluteTxPosition) Reset() { *m = AbsoluteTxPosition{} } func (m *AbsoluteTxPosition) String() string { return proto.CompactTextString(m) } func (*AbsoluteTxPosition) ProtoMessage() {} func (*AbsoluteTxPosition) Descriptor() ([]byte, []int) { - return fileDescriptor_45de2b3fc8aff6aa, []int{7} + return fileDescriptor_45de2b3fc8aff6aa, []int{6} } func (m *AbsoluteTxPosition) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -439,7 +401,7 @@ func (m *Model) Reset() { *m = Model{} } func (m *Model) String() string { return proto.CompactTextString(m) } func (*Model) ProtoMessage() {} func (*Model) Descriptor() ([]byte, []int) { - return fileDescriptor_45de2b3fc8aff6aa, []int{8} + return fileDescriptor_45de2b3fc8aff6aa, []int{7} } func (m *Model) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -476,7 +438,6 @@ func init() { proto.RegisterType((*Params)(nil), "wasmd.x.wasmd.v1beta1.Params") proto.RegisterType((*CodeInfo)(nil), "wasmd.x.wasmd.v1beta1.CodeInfo") proto.RegisterType((*ContractInfo)(nil), "wasmd.x.wasmd.v1beta1.ContractInfo") - proto.RegisterType((*ContractHistory)(nil), "wasmd.x.wasmd.v1beta1.ContractHistory") proto.RegisterType((*ContractCodeHistoryEntry)(nil), "wasmd.x.wasmd.v1beta1.ContractCodeHistoryEntry") proto.RegisterType((*AbsoluteTxPosition)(nil), "wasmd.x.wasmd.v1beta1.AbsoluteTxPosition") proto.RegisterType((*Model)(nil), "wasmd.x.wasmd.v1beta1.Model") @@ -485,78 +446,76 @@ func init() { func init() { proto.RegisterFile("x/wasm/internal/types/types.proto", fileDescriptor_45de2b3fc8aff6aa) } var fileDescriptor_45de2b3fc8aff6aa = []byte{ - // 1128 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x56, 0xcf, 0x6f, 0x1b, 0x45, - 0x14, 0xf6, 0xda, 0xf9, 0x39, 0xb5, 0x5a, 0x77, 0x48, 0xa8, 0x6b, 0x8a, 0xed, 0x6c, 0x41, 0xa4, - 0x3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1, 0xf3, 0xe3, 0x09, 0x86, 0x09, 0x00, 0x00, + // 1097 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x56, 0xcf, 0x6f, 0x1b, 0xc5, + 0x17, 0xf7, 0xda, 0xce, 0xaf, 0xa9, 0xd5, 0xba, 0xf3, 0x6d, 0xbe, 0x75, 0x4d, 0xb1, 0x9d, 0x2d, + 0x88, 0xa4, 0x8d, 0xec, 0x36, 0x20, 0x8a, 0x72, 0xb3, 0xd7, 0x4b, 0xb2, 0x15, 0xb1, 0xad, 0xb1, + 0x43, 0x1b, 0x24, 0xb4, 0x1a, 0x7b, 0x27, 0xf6, 0xd0, 0xdd, 0x1d, 0x6b, 0x67, 0x9c, 0xda, 0xfd, + 0x0b, 0x90, 0xb9, 0x20, 0x4e, 0x1c, 0xb0, 0x84, 0x04, 0x42, 0xfd, 0x43, 0x38, 0xe4, 0x82, 0xd4, + 0x23, 0x27, 0x0b, 0x12, 0x21, 0xc1, 0x35, 0xc7, 0x9e, 0xd0, 0xee, 0x38, 0xf2, 0x42, 0x7e, 0x99, + 0x8b, 0x77, 0xdf, 0x9b, 0xf7, 0xf9, 0xbc, 0xf9, 0xbc, 0xf7, 0x66, 0x3d, 0x60, 0xa5, 0x5f, 0x78, + 0x81, 0xb9, 0x53, 0xa0, 0xae, 0x20, 0x9e, 0x8b, 0xed, 0x82, 0x18, 0x74, 0x09, 0x97, 0xbf, 0xf9, + 0xae, 0xc7, 0x04, 0x83, 0xcb, 0x7e, 0x80, 0x95, 0xef, 0xe7, 0xe5, 0xf3, 0xe0, 0x51, 0x93, 0x08, + 0xfc, 0x28, 0x7d, 0xab, 0xcd, 0xda, 0x2c, 0x88, 0x28, 0xf8, 0x6f, 0x32, 0x58, 0x6d, 0x82, 0x1b, + 0xc5, 0x56, 0x8b, 0x70, 0xde, 0x18, 0x74, 0x49, 0x0d, 0x7b, 0xd8, 0x81,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2, 0xfe, 0xdf, 0x01, 0x00, 0x00, 0xff, + 0xff, 0x56, 0x10, 0xb5, 0xc6, 0x10, 0x09, 0x00, 0x00, } func (this *AccessTypeParam) Equal(that interface{}) bool { @@ -712,35 +671,6 @@ func (this *ContractInfo) Equal(that interface{}) bool { } return true } -func (this *ContractHistory) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*ContractHistory) - if !ok { - that2, ok := that.(ContractHistory) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if len(this.CodeHistoryEntries) != len(that1.CodeHistoryEntries) { - return false - } - for i := range this.CodeHistoryEntries { - if !this.CodeHistoryEntries[i].Equal(&that1.CodeHistoryEntries[i]) { - return false - } - } - return true -} func (this *ContractCodeHistoryEntry) Equal(that interface{}) bool { if that == nil { return this == nil @@ -1056,43 +986,6 @@ func (m *ContractInfo) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *ContractHistory) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *ContractHistory) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *ContractHistory) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.CodeHistoryEntries) > 0 { - for iNdEx := len(m.CodeHistoryEntries) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.CodeHistoryEntries[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTypes(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - func (m *ContractCodeHistoryEntry) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1326,21 +1219,6 @@ func (m *ContractInfo) Size() (n int) { return n } -func (m *ContractHistory) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.CodeHistoryEntries) > 0 { - for _, e := range m.CodeHistoryEntries { - l = e.Size() - n += 1 + l + sovTypes(uint64(l)) - } - } - return n -} - func (m *ContractCodeHistoryEntry) Size() (n int) { if m == nil { return 0 @@ -2122,94 +2000,6 @@ func (m *ContractInfo) Unmarshal(dAtA []byte) error { } return nil } - -func (m *ContractHistory) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: ContractHistory: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: ContractHistory: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field CodeHistoryEntries", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTypes - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTypes - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTypes - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.CodeHistoryEntries = append(m.CodeHistoryEntries, ContractCodeHistoryEntry{}) - if err := m.CodeHistoryEntries[len(m.CodeHistoryEntries)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTypes(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) < 0 { - return ErrInvalidLengthTypes - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *ContractCodeHistoryEntry) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -2414,7 +2204,7 @@ func (m *AbsoluteTxPosition) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.BlockHeight |= int64(b&0x7F) << shift + m.BlockHeight |= uint64(b&0x7F) << shift if b < 0x80 { break } diff --git a/x/wasm/internal/types/types.proto b/x/wasm/internal/types/types.proto index 2795b43645..53e1b82c97 100644 --- a/x/wasm/internal/types/types.proto +++ b/x/wasm/internal/types/types.proto @@ -58,6 +58,8 @@ message CodeInfo { // ContractInfo stores a WASM contract instance message ContractInfo { + option (gogoproto.equal) = true; + // CodeID is the reference to the stored Wasm code uint64 code_id = 1 [(gogoproto.customname) = "CodeID"]; // Creator address who initially instantiated the contract @@ -84,11 +86,6 @@ enum ContractCodeHistoryOperationType { CONTRACT_CODE_HISTORY_OPERATION_TYPE_GENESIS = 3 [(gogoproto.enumvalue_customname) = "ContractCodeHistoryOperationTypeGenesis"]; } -// ContractHistory contains a sorted list of code updates to a contract -message ContractHistory { - repeated ContractCodeHistoryEntry code_history_entries = 1 [(gogoproto.nullable) = false]; -} - // ContractCodeHistoryEntry metadata to a contract. message ContractCodeHistoryEntry { ContractCodeHistoryOperationType operation = 1; @@ -100,10 +97,10 @@ message ContractCodeHistoryEntry { } -// AbsoluteTxPosition can be used to sort contracts +// AbsoluteTxPosition is a unique transaction position that allows for global ordering of transactions. message AbsoluteTxPosition { // BlockHeight is the block the contract was created at - int64 block_height = 1; + uint64 block_height = 1; // TxIndex is a monotonic counter within the block (actual transaction index, or gas consumed) uint64 tx_index = 2; }