diff --git a/CHANGELOG.md b/CHANGELOG.md index a5841ae2..b12300fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * With upgraded versions, added in support for new Msg types and pubkey `secp256r1` * Now pulling `wasmd` protos from `provenance-io/wasmd` instead of `CosmWasm/wasmd` [#238](https://github.com/provenance-io/explorer-service/issues/238) * Current version at v0.19.0 + * Pinned CosmWasm/wasmd protos to `v0.17.0` for backwards compatibility ### Improvements * Translated Smart Contract msg bytes to human-readable json diff --git a/buildSrc/src/main/kotlin/io/provenance/DownloadProtosTask.kt b/buildSrc/src/main/kotlin/io/provenance/DownloadProtosTask.kt index 598d4d75..353324d9 100644 --- a/buildSrc/src/main/kotlin/io/provenance/DownloadProtosTask.kt +++ b/buildSrc/src/main/kotlin/io/provenance/DownloadProtosTask.kt @@ -54,6 +54,12 @@ open class DownloadProtosTask : DefaultTask() { @Input var ibcVersion: String? = null + /** + * Hard coded to v0.17.0 for backwards compatibility. Needed to serialize/deserialize older wasmd protos. + */ + @Input + val cosmwasmVersion: String = "v0.17.0" + /** * Connects directly to provenance-io GitHub release directory * and downloads the `provenanceVersion` proto zip file. @@ -102,6 +108,14 @@ open class DownloadProtosTask : DefaultTask() { excludePattern = Regex(".*testutil/.*"), protoRootDir = "proto" ) + + untar( + file = unGzip(toTempFile("https://github.com/CosmWasm/wasmd/tarball/${this.cosmwasmVersion}")), + destinationDir = thirdPartyPath(), + includePattern = Regex(".*/proto/.*\\.proto\$"), + excludePattern = Regex(".*third_party/.*|.*proto/ibc/.*"), + protoRootDir = "proto" + ) } /** diff --git a/service/src/main/kotlin/io/provenance/explorer/config/RestConfig.kt b/service/src/main/kotlin/io/provenance/explorer/config/RestConfig.kt index 80f63f1d..0ea28032 100644 --- a/service/src/main/kotlin/io/provenance/explorer/config/RestConfig.kt +++ b/service/src/main/kotlin/io/provenance/explorer/config/RestConfig.kt @@ -251,6 +251,12 @@ fun msgDescriptors() = cosmwasm.wasm.v1.Tx.MsgMigrateContract.getDescriptor(), cosmwasm.wasm.v1.Tx.MsgUpdateAdmin.getDescriptor(), cosmwasm.wasm.v1.Tx.MsgClearAdmin.getDescriptor(), + cosmwasm.wasm.v1beta1.Tx.MsgStoreCode.getDescriptor(), + cosmwasm.wasm.v1beta1.Tx.MsgInstantiateContract.getDescriptor(), + cosmwasm.wasm.v1beta1.Tx.MsgExecuteContract.getDescriptor(), + cosmwasm.wasm.v1beta1.Tx.MsgMigrateContract.getDescriptor(), + cosmwasm.wasm.v1beta1.Tx.MsgUpdateAdmin.getDescriptor(), + cosmwasm.wasm.v1beta1.Tx.MsgClearAdmin.getDescriptor(), cosmos.crisis.v1beta1.Tx.MsgVerifyInvariant.getDescriptor(), ibc.applications.transfer.v1.Tx.MsgTransfer.getDescriptor(), ibc.core.channel.v1.Tx.MsgChannelOpenInit.getDescriptor(), @@ -311,6 +317,13 @@ fun contentDescriptors() = Proposal.ClearAdminProposal.getDescriptor(), Proposal.PinCodesProposal.getDescriptor(), Proposal.UnpinCodesProposal.getDescriptor(), + cosmwasm.wasm.v1beta1.Proposal.StoreCodeProposal.getDescriptor(), + cosmwasm.wasm.v1beta1.Proposal.InstantiateContractProposal.getDescriptor(), + cosmwasm.wasm.v1beta1.Proposal.MigrateContractProposal.getDescriptor(), + cosmwasm.wasm.v1beta1.Proposal.UpdateAdminProposal.getDescriptor(), + cosmwasm.wasm.v1beta1.Proposal.ClearAdminProposal.getDescriptor(), + cosmwasm.wasm.v1beta1.Proposal.PinCodesProposal.getDescriptor(), + cosmwasm.wasm.v1beta1.Proposal.UnpinCodesProposal.getDescriptor(), Client.ClientUpdateProposal.getDescriptor(), SetDenomMetadataProposal.getDescriptor() ) diff --git a/service/src/main/kotlin/io/provenance/explorer/grpc/extensions/MsgConverter.kt b/service/src/main/kotlin/io/provenance/explorer/grpc/extensions/MsgConverter.kt index e94bd222..1abb2350 100644 --- a/service/src/main/kotlin/io/provenance/explorer/grpc/extensions/MsgConverter.kt +++ b/service/src/main/kotlin/io/provenance/explorer/grpc/extensions/MsgConverter.kt @@ -138,6 +138,12 @@ fun Any.toMsgExecuteContract() = this.unpack(cosmwasm.wasm.v1.Tx.MsgExecuteContr fun Any.toMsgMigrateContract() = this.unpack(cosmwasm.wasm.v1.Tx.MsgMigrateContract::class.java) fun Any.toMsgUpdateAdmin() = this.unpack(cosmwasm.wasm.v1.Tx.MsgUpdateAdmin::class.java) fun Any.toMsgClearAdmin() = this.unpack(cosmwasm.wasm.v1.Tx.MsgClearAdmin::class.java) +fun Any.toMsgStoreCodeOld() = this.unpack(cosmwasm.wasm.v1beta1.Tx.MsgStoreCode::class.java) +fun Any.toMsgInstantiateContractOld() = this.unpack(cosmwasm.wasm.v1beta1.Tx.MsgInstantiateContract::class.java) +fun Any.toMsgExecuteContractOld() = this.unpack(cosmwasm.wasm.v1beta1.Tx.MsgExecuteContract::class.java) +fun Any.toMsgMigrateContractOld() = this.unpack(cosmwasm.wasm.v1beta1.Tx.MsgMigrateContract::class.java) +fun Any.toMsgUpdateAdminOld() = this.unpack(cosmwasm.wasm.v1beta1.Tx.MsgUpdateAdmin::class.java) +fun Any.toMsgClearAdminOld() = this.unpack(cosmwasm.wasm.v1beta1.Tx.MsgClearAdmin::class.java) fun Any.toMsgAddScopeDataAccessRequest() = this.unpack(MsgAddScopeDataAccessRequest::class.java) fun Any.toMsgDeleteScopeDataAccessRequest() = this.unpack(MsgDeleteScopeDataAccessRequest::class.java) fun Any.toMsgAddScopeOwnerRequest() = this.unpack(MsgAddScopeOwnerRequest::class.java) @@ -245,12 +251,19 @@ fun Any.getAssociatedAddresses(): List = typeUrl.endsWith("MsgBindOSLocatorRequest") -> this.toMsgBindOSLocatorRequest().let { listOf(it.locator.owner) } typeUrl.endsWith("MsgDeleteOSLocatorRequest") -> this.toMsgDeleteOSLocatorRequest().let { listOf(it.locator.owner) } typeUrl.endsWith("MsgModifyOSLocatorRequest") -> this.toMsgModifyOSLocatorRequest().let { listOf(it.locator.owner) } - typeUrl.endsWith("MsgStoreCode") -> this.toMsgStoreCode().let { listOf(it.sender) } - typeUrl.endsWith("MsgInstantiateContract") -> this.toMsgInstantiateContract().let { listOf(it.sender, it.admin) } - typeUrl.endsWith("MsgExecuteContract") -> this.toMsgExecuteContract().let { listOf(it.sender) } - typeUrl.endsWith("MsgMigrateContract") -> this.toMsgMigrateContract().let { listOf(it.sender) } - typeUrl.endsWith("MsgUpdateAdmin") -> this.toMsgUpdateAdmin().let { listOf(it.sender, it.newAdmin) } - typeUrl.endsWith("MsgClearAdmin") -> this.toMsgClearAdmin().let { listOf(it.sender) } + typeUrl.endsWith("v1.Tx.MsgStoreCode") -> this.toMsgStoreCode().let { listOf(it.sender) } + typeUrl.endsWith("v1.Tx.MsgInstantiateContract") -> this.toMsgInstantiateContract().let { listOf(it.sender, it.admin) } + typeUrl.endsWith("v1.Tx.MsgExecuteContract") -> this.toMsgExecuteContract().let { listOf(it.sender) } + typeUrl.endsWith("v1.Tx.MsgMigrateContract") -> this.toMsgMigrateContract().let { listOf(it.sender) } + typeUrl.endsWith("v1.Tx.MsgUpdateAdmin") -> this.toMsgUpdateAdmin().let { listOf(it.sender, it.newAdmin) } + typeUrl.endsWith("v1.Tx.MsgClearAdmin") -> this.toMsgClearAdmin().let { listOf(it.sender) } + typeUrl.endsWith("v1beta1.Tx.MsgStoreCode") -> this.toMsgStoreCodeOld().let { listOf(it.sender) } + typeUrl.endsWith("v1beta1.Tx.MsgInstantiateContract") -> this.toMsgInstantiateContractOld() + .let { listOf(it.sender, it.admin) } + typeUrl.endsWith("v1beta1.Tx.MsgExecuteContract") -> this.toMsgExecuteContractOld().let { listOf(it.sender) } + typeUrl.endsWith("v1beta1.Tx.MsgMigrateContract") -> this.toMsgMigrateContractOld().let { listOf(it.sender) } + typeUrl.endsWith("v1beta1.Tx.MsgUpdateAdmin") -> this.toMsgUpdateAdminOld().let { listOf(it.sender, it.newAdmin) } + typeUrl.endsWith("v1beta1.Tx.MsgClearAdmin") -> this.toMsgClearAdminOld().let { listOf(it.sender) } typeUrl.endsWith("MsgAddScopeDataAccessRequest") -> this.toMsgAddScopeDataAccessRequest() .let { it.signersList + it.dataAccessList } typeUrl.endsWith("MsgDeleteScopeDataAccessRequest") -> this.toMsgDeleteScopeDataAccessRequest() diff --git a/third_party/proto/cosmwasm/wasm/v1beta1/genesis.proto b/third_party/proto/cosmwasm/wasm/v1beta1/genesis.proto new file mode 100644 index 00000000..c00fd066 --- /dev/null +++ b/third_party/proto/cosmwasm/wasm/v1beta1/genesis.proto @@ -0,0 +1,60 @@ +syntax = "proto3"; +package cosmwasm.wasm.v1beta1; + +import "gogoproto/gogo.proto"; +import "cosmwasm/wasm/v1beta1/types.proto"; +import "cosmwasm/wasm/v1beta1/tx.proto"; + +option go_package = "github.com/CosmWasm/wasmd/x/wasm/types"; + +// GenesisState - genesis state of x/wasm +message GenesisState { + Params params = 1 [ (gogoproto.nullable) = false ]; + repeated Code codes = 2 + [ (gogoproto.nullable) = false, (gogoproto.jsontag) = "codes,omitempty" ]; + repeated Contract contracts = 3 [ + (gogoproto.nullable) = false, + (gogoproto.jsontag) = "contracts,omitempty" + ]; + repeated Sequence sequences = 4 [ + (gogoproto.nullable) = false, + (gogoproto.jsontag) = "sequences,omitempty" + ]; + repeated GenMsgs gen_msgs = 5 [ + (gogoproto.nullable) = false, + (gogoproto.jsontag) = "gen_msgs,omitempty" + ]; + + // GenMsgs define the messages that can be executed during genesis phase in + // order. The intention is to have more human readable data that is auditable. + message GenMsgs { + // sum is a single message + oneof sum { + MsgStoreCode store_code = 1; + MsgInstantiateContract instantiate_contract = 2; + MsgExecuteContract execute_contract = 3; + } + } +} + +// Code struct encompasses CodeInfo and CodeBytes +message Code { + uint64 code_id = 1 [ (gogoproto.customname) = "CodeID" ]; + CodeInfo code_info = 2 [ (gogoproto.nullable) = false ]; + bytes code_bytes = 3; + // Pinned to wasmvm cache + bool pinned = 4; +} + +// Contract struct encompasses ContractAddress, ContractInfo, and ContractState +message Contract { + string contract_address = 1; + ContractInfo contract_info = 2 [ (gogoproto.nullable) = false ]; + repeated Model contract_state = 3 [ (gogoproto.nullable) = false ]; +} + +// Sequence key and value of an id generation counter +message Sequence { + bytes id_key = 1 [ (gogoproto.customname) = "IDKey" ]; + uint64 value = 2; +} \ No newline at end of file diff --git a/third_party/proto/cosmwasm/wasm/v1beta1/ibc.proto b/third_party/proto/cosmwasm/wasm/v1beta1/ibc.proto new file mode 100644 index 00000000..e0462c34 --- /dev/null +++ b/third_party/proto/cosmwasm/wasm/v1beta1/ibc.proto @@ -0,0 +1,30 @@ +syntax = "proto3"; +package cosmwasm.wasm.v1beta1; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/CosmWasm/wasmd/x/wasm/types"; +option (gogoproto.goproto_getters_all) = false; + +// MsgIBCSend +message MsgIBCSend { + // the channel by which the packet will be sent + string channel = 2 [ (gogoproto.moretags) = "yaml:\"source_channel\"" ]; + + // Timeout height relative to the current block height. + // The timeout is disabled when set to 0. + uint64 timeout_height = 4 + [ (gogoproto.moretags) = "yaml:\"timeout_height\"" ]; + // Timeout timestamp (in nanoseconds) relative to the current block timestamp. + // The timeout is disabled when set to 0. + uint64 timeout_timestamp = 5 + [ (gogoproto.moretags) = "yaml:\"timeout_timestamp\"" ]; + + // data is the payload to transfer + bytes data = 6 [ (gogoproto.casttype) = "encoding/json.RawMessage" ]; +} + +// MsgIBCCloseChannel port and channel need to be owned by the contract +message MsgIBCCloseChannel { + string channel = 2 [ (gogoproto.moretags) = "yaml:\"source_channel\"" ]; +} diff --git a/third_party/proto/cosmwasm/wasm/v1beta1/proposal.proto b/third_party/proto/cosmwasm/wasm/v1beta1/proposal.proto new file mode 100644 index 00000000..4387bb67 --- /dev/null +++ b/third_party/proto/cosmwasm/wasm/v1beta1/proposal.proto @@ -0,0 +1,121 @@ +syntax = "proto3"; +package cosmwasm.wasm.v1beta1; + +import "gogoproto/gogo.proto"; +import "cosmos/base/v1beta1/coin.proto"; +import "cosmwasm/wasm/v1beta1/types.proto"; + +option go_package = "github.com/CosmWasm/wasmd/x/wasm/types"; +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_getters_all) = false; +option (gogoproto.equal_all) = true; + +// StoreCodeProposal gov proposal content type to submit WASM code to the system +message StoreCodeProposal { + // Title is a short summary + string title = 1; + // Description is a human readable text + string description = 2; + // RunAs is the address that is passed to the contract's environment as sender + string run_as = 3; + // WASMByteCode can be raw or gzip compressed + bytes wasm_byte_code = 4 [ (gogoproto.customname) = "WASMByteCode" ]; + // Source is a valid absolute HTTPS URI to the contract's source code, + // optional + string source = 5; + // Builder is a valid docker image name with tag, optional + string builder = 6; + // InstantiatePermission to apply on contract creation, optional + AccessConfig instantiate_permission = 7; +} + +// InstantiateContractProposal gov proposal content type to instantiate a +// contract. +message InstantiateContractProposal { + // Title is a short summary + string title = 1; + // Description is a human readable text + string description = 2; + // RunAs is the address that is passed to the contract's environment as sender + string run_as = 3; + // Admin is an optional address that can execute migrations + string admin = 4; + // CodeID is the reference to the stored WASM code + uint64 code_id = 5 [ (gogoproto.customname) = "CodeID" ]; + // Label is optional metadata to be stored with a constract instance. + string label = 6; + // InitMsg json encoded message to be passed to the contract on instantiation + bytes init_msg = 7; + // Funds coins that are transferred to the contract on instantiation + repeated cosmos.base.v1beta1.Coin funds = 8 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} + +// MigrateContractProposal gov proposal content type to migrate a contract. +message MigrateContractProposal { + // Title is a short summary + string title = 1; + // Description is a human readable text + string description = 2; + // RunAs is the address that is passed to the contract's environment as sender + string run_as = 3; + // Contract is the address of the smart contract + string contract = 4; + // CodeID references the new WASM code + uint64 code_id = 5 [ (gogoproto.customname) = "CodeID" ]; + // MigrateMsg json encoded message to be passed to the contract on migration + bytes migrate_msg = 6; +} + +// UpdateAdminProposal gov proposal content type to set an admin for a contract. +message UpdateAdminProposal { + // Title is a short summary + string title = 1; + // Description is a human readable text + string description = 2; + // NewAdmin address to be set + string new_admin = 3 [ (gogoproto.moretags) = "yaml:\"new_admin\"" ]; + // Contract is the address of the smart contract + string contract = 4; +} + +// ClearAdminProposal gov proposal content type to clear the admin of a +// contract. +message ClearAdminProposal { + // Title is a short summary + string title = 1; + // Description is a human readable text + string description = 2; + // Contract is the address of the smart contract + string contract = 3; +} + +// PinCodesProposal gov proposal content type to pin a set of code ids in the +// wasmvm cache. +message PinCodesProposal { + // Title is a short summary + string title = 1 [ (gogoproto.moretags) = "yaml:\"title\"" ]; + // Description is a human readable text + string description = 2 [ (gogoproto.moretags) = "yaml:\"description\"" ]; + // CodeIDs references the new WASM codes + repeated uint64 code_ids = 3 [ + (gogoproto.customname) = "CodeIDs", + (gogoproto.moretags) = "yaml:\"code_ids\"" + ]; +} + +// UnpinCodesProposal gov proposal content type to unpin a set of code ids in +// the wasmvm cache. +message UnpinCodesProposal { + // Title is a short summary + string title = 1 [ (gogoproto.moretags) = "yaml:\"title\"" ]; + // Description is a human readable text + string description = 2 [ (gogoproto.moretags) = "yaml:\"description\"" ]; + // CodeIDs references the WASM codes + repeated uint64 code_ids = 3 [ + (gogoproto.customname) = "CodeIDs", + (gogoproto.moretags) = "yaml:\"code_ids\"" + ]; +} diff --git a/third_party/proto/cosmwasm/wasm/v1beta1/query.proto b/third_party/proto/cosmwasm/wasm/v1beta1/query.proto new file mode 100644 index 00000000..3f96cc68 --- /dev/null +++ b/third_party/proto/cosmwasm/wasm/v1beta1/query.proto @@ -0,0 +1,201 @@ +syntax = "proto3"; +package cosmwasm.wasm.v1beta1; + +import "gogoproto/gogo.proto"; +import "cosmwasm/wasm/v1beta1/types.proto"; +import "google/api/annotations.proto"; +import "cosmos/base/query/v1beta1/pagination.proto"; + +option go_package = "github.com/CosmWasm/wasmd/x/wasm/types"; +option (gogoproto.goproto_getters_all) = false; +option (gogoproto.equal_all) = false; + +// Query provides defines the gRPC querier service +service Query { + // ContractInfo gets the contract meta data + rpc ContractInfo(QueryContractInfoRequest) + returns (QueryContractInfoResponse) { + option (google.api.http).get = "/wasm/v1beta1/contract/{address}"; + } + // ContractHistory gets the contract code history + rpc ContractHistory(QueryContractHistoryRequest) + returns (QueryContractHistoryResponse) { + option (google.api.http).get = "/wasm/v1beta1/contract/{address}/history"; + } + // ContractsByCode lists all smart contracts for a code id + rpc ContractsByCode(QueryContractsByCodeRequest) + returns (QueryContractsByCodeResponse) { + option (google.api.http).get = "/wasm/v1beta1/code/{code_id}/contracts"; + } + // AllContractState gets all raw store data for a single contract + rpc AllContractState(QueryAllContractStateRequest) + returns (QueryAllContractStateResponse) { + option (google.api.http).get = "/wasm/v1beta1/contract/{address}/state"; + } + // RawContractState gets single key from the raw store data of a contract + rpc RawContractState(QueryRawContractStateRequest) + returns (QueryRawContractStateResponse) { + option (google.api.http).get = + "/wasm/v1beta1/contract/{address}/raw/{query_data}"; + } + // SmartContractState get smart query result from the contract + rpc SmartContractState(QuerySmartContractStateRequest) + returns (QuerySmartContractStateResponse) { + option (google.api.http).get = + "/wasm/v1beta1/contract/{address}/smart/{query_data}"; + } + // Code gets the binary code and metadata for a singe wasm code + rpc Code(QueryCodeRequest) returns (QueryCodeResponse) { + option (google.api.http).get = "/wasm/v1beta1/code/{code_id}"; + } + // Codes gets the metadata for all stored wasm codes + rpc Codes(QueryCodesRequest) returns (QueryCodesResponse) { + option (google.api.http).get = "/wasm/v1beta1/code"; + } +} + +// QueryContractInfoRequest is the request type for the Query/ContractInfo RPC +// method +message QueryContractInfoRequest { + // address is the address of the contract to query + string address = 1; +} +// 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.nullable) = false, + (gogoproto.jsontag) = "" + ]; +} + +// QueryContractHistoryRequest is the request type for the Query/ContractHistory +// RPC method +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; +} + +// QueryContractsByCodeResponse is the response type for the +// Query/ContractsByCode RPC method +message QueryContractsByCodeResponse { + // contracts are a set of contract addresses + repeated string contracts = 1; + + // 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 +message QueryRawContractStateRequest { + // address is the address of the contract + 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 + bytes data = 1; +} + +// QuerySmartContractStateRequest is the request type for the +// Query/SmartContractState RPC method +message QuerySmartContractStateRequest { + // address is the address of the contract + string address = 1; + // 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 + bytes data = 1 [ (gogoproto.casttype) = "encoding/json.RawMessage" ]; +} + +// QueryCodeRequest is the request type for the Query/Code RPC method +message QueryCodeRequest { + uint64 code_id = 1; // grpc-gateway_out does not support Go style CodID +} + +// 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" ]; + string source = 4; + string builder = 5; +} + +// 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/third_party/proto/cosmwasm/wasm/v1beta1/tx.proto b/third_party/proto/cosmwasm/wasm/v1beta1/tx.proto new file mode 100644 index 00000000..c3ddd3bf --- /dev/null +++ b/third_party/proto/cosmwasm/wasm/v1beta1/tx.proto @@ -0,0 +1,138 @@ +syntax = "proto3"; +package cosmwasm.wasm.v1beta1; + +import "cosmos/base/v1beta1/coin.proto"; +import "gogoproto/gogo.proto"; +import "cosmwasm/wasm/v1beta1/types.proto"; + +option go_package = "github.com/CosmWasm/wasmd/x/wasm/types"; +option (gogoproto.goproto_getters_all) = false; + +// Msg defines the wasm Msg service. +service Msg { + // StoreCode to submit Wasm code to the system + rpc StoreCode(MsgStoreCode) returns (MsgStoreCodeResponse); + // Instantiate creates a new smart contract instance for the given code id. + rpc InstantiateContract(MsgInstantiateContract) + returns (MsgInstantiateContractResponse); + // Execute submits the given message data to a smart contract + rpc ExecuteContract(MsgExecuteContract) returns (MsgExecuteContractResponse); + // Migrate runs a code upgrade/ downgrade for a smart contract + rpc MigrateContract(MsgMigrateContract) returns (MsgMigrateContractResponse); + // UpdateAdmin sets a new admin for a smart contract + rpc UpdateAdmin(MsgUpdateAdmin) returns (MsgUpdateAdminResponse); + // ClearAdmin removes any admin stored for a smart contract + rpc ClearAdmin(MsgClearAdmin) returns (MsgClearAdminResponse); +} + +// MsgStoreCode submit Wasm code to the system +message MsgStoreCode { + // Sender is the that actor that signed the messages + string sender = 1; + // WASMByteCode can be raw or gzip compressed + bytes wasm_byte_code = 2 [ (gogoproto.customname) = "WASMByteCode" ]; + // Source is a valid absolute HTTPS URI to the contract's source code, + // optional + string source = 3; + // Builder is a valid docker image name with tag, optional + string builder = 4; + // InstantiatePermission access control to apply on contract creation, + // optional + AccessConfig instantiate_permission = 5; +} +// MsgStoreCodeResponse returns store result data. +message MsgStoreCodeResponse { + // CodeID is the reference to the stored WASM code + uint64 code_id = 1 [ (gogoproto.customname) = "CodeID" ]; +} + +// MsgInstantiateContract create a new smart contract instance for the given +// code id. +message MsgInstantiateContract { + // Sender is the that actor that signed the messages + string sender = 1; + // Admin is an optional address that can execute migrations + string admin = 2; + // CodeID is the reference to the stored WASM code + uint64 code_id = 3 [ (gogoproto.customname) = "CodeID" ]; + // Label is optional metadata to be stored with a contract instance. + string label = 4; + // InitMsg json encoded message to be passed to the contract on instantiation + bytes init_msg = 5; + // Funds coins that are transferred to the contract on instantiation + repeated cosmos.base.v1beta1.Coin funds = 6 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} +// MsgInstantiateContractResponse return instantiation result data +message MsgInstantiateContractResponse { + // Address is the bech32 address of the new contract instance. + string address = 1; + // Data contains base64-encoded bytes to returned from the contract + bytes data = 2; +} + +// MsgExecuteContract submits the given message data to a smart contract +message MsgExecuteContract { + // Sender is the that actor that signed the messages + string sender = 1; + // Contract is the address of the smart contract + string contract = 2; + // Msg json encoded message to be passed to the contract + bytes msg = 3; + // Funds coins that are transferred to the contract on execution + repeated cosmos.base.v1beta1.Coin funds = 5 [ + (gogoproto.nullable) = false, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; +} + +// MsgExecuteContractResponse returns execution result data. +message MsgExecuteContractResponse { + // Data contains base64-encoded bytes to returned from the contract + bytes data = 1; +} + +// MsgMigrateContract runs a code upgrade/ downgrade for a smart contract +message MsgMigrateContract { + // Sender is the that actor that signed the messages + string sender = 1; + // Contract is the address of the smart contract + string contract = 2; + // CodeID references the new WASM code + uint64 code_id = 3 [ (gogoproto.customname) = "CodeID" ]; + // MigrateMsg json encoded message to be passed to the contract on migration + bytes migrate_msg = 4; +} + +// MsgMigrateContractResponse returns contract migration result data. +message MsgMigrateContractResponse { + // Data contains same raw bytes returned as data from the wasm contract. + // (May be empty) + bytes data = 1; +} + +// MsgUpdateAdmin sets a new admin for a smart contract +message MsgUpdateAdmin { + // Sender is the that actor that signed the messages + string sender = 1; + // NewAdmin address to be set + string new_admin = 2; + // Contract is the address of the smart contract + string contract = 3; +} + +// MsgUpdateAdminResponse returns empty data +message MsgUpdateAdminResponse {} + +// MsgClearAdmin removes any admin stored for a smart contract +message MsgClearAdmin { + // Sender is the that actor that signed the messages + string sender = 1; + // Contract is the address of the smart contract + string contract = 3; +} + +// MsgClearAdminResponse returns empty data +message MsgClearAdminResponse {} diff --git a/third_party/proto/cosmwasm/wasm/v1beta1/types.proto b/third_party/proto/cosmwasm/wasm/v1beta1/types.proto new file mode 100644 index 00000000..6e17eeae --- /dev/null +++ b/third_party/proto/cosmwasm/wasm/v1beta1/types.proto @@ -0,0 +1,143 @@ +syntax = "proto3"; +package cosmwasm.wasm.v1beta1; + +import "cosmos_proto/cosmos.proto"; +import "gogoproto/gogo.proto"; +import "google/protobuf/any.proto"; + +option go_package = "github.com/CosmWasm/wasmd/x/wasm/types"; +option (gogoproto.goproto_getters_all) = false; +option (gogoproto.equal_all) = true; + +// AccessType permission types +enum AccessType { + option (gogoproto.goproto_enum_prefix) = false; + option (gogoproto.goproto_enum_stringer) = false; + // AccessTypeUnspecified placeholder for empty value + ACCESS_TYPE_UNSPECIFIED = 0 + [ (gogoproto.enumvalue_customname) = "AccessTypeUnspecified" ]; + // AccessTypeNobody forbidden + ACCESS_TYPE_NOBODY = 1 + [ (gogoproto.enumvalue_customname) = "AccessTypeNobody" ]; + // AccessTypeOnlyAddress restricted to an address + ACCESS_TYPE_ONLY_ADDRESS = 2 + [ (gogoproto.enumvalue_customname) = "AccessTypeOnlyAddress" ]; + // AccessTypeEverybody unrestricted + ACCESS_TYPE_EVERYBODY = 3 + [ (gogoproto.enumvalue_customname) = "AccessTypeEverybody" ]; +} + +// AccessTypeParam +message AccessTypeParam { + option (gogoproto.goproto_stringer) = true; + AccessType value = 1 [ (gogoproto.moretags) = "yaml:\"value\"" ]; +} + +// AccessConfig access control type. +message AccessConfig { + option (gogoproto.goproto_stringer) = true; + AccessType permission = 1 [ (gogoproto.moretags) = "yaml:\"permission\"" ]; + string address = 2 [ (gogoproto.moretags) = "yaml:\"address\"" ]; +} + +// Params defines the set of wasm parameters. +message Params { + option (gogoproto.goproto_stringer) = false; + AccessConfig code_upload_access = 1 [ + (gogoproto.nullable) = false, + (gogoproto.moretags) = "yaml:\"code_upload_access\"" + ]; + AccessType instantiate_default_permission = 2 + [ (gogoproto.moretags) = "yaml:\"instantiate_default_permission\"" ]; + uint64 max_wasm_code_size = 3 + [ (gogoproto.moretags) = "yaml:\"max_wasm_code_size\"" ]; +} + +// CodeInfo is data for the uploaded contract WASM code +message CodeInfo { + // CodeHash is the unique identifier created by wasmvm + bytes code_hash = 1; + // Creator address who initially stored the code + string creator = 2; + // Source is a valid absolute HTTPS URI to the contract's source code, + // optional + string source = 3; + // Builder is a valid docker image name with tag, optional + string builder = 4; + // InstantiateConfig access control to apply on contract creation, optional + AccessConfig instantiate_config = 5 [ (gogoproto.nullable) = false ]; +} + +// 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 + string creator = 2; + // Admin is an optional address that can execute migrations + string admin = 3; + // Label is optional metadata to be stored with a contract instance. + string label = 4; + // Created Tx position when the contract was instantiated. + // This data should kept internal and not be exposed via query results. Just + // use for sorting + AbsoluteTxPosition created = 5; + string ibc_port_id = 6 [ (gogoproto.customname) = "IBCPortID" ]; + + // Extension is an extension point to store custom metadata within the + // persistence model. + google.protobuf.Any extension = 7 + [ (cosmos_proto.accepts_interface) = "ContractInfoExtension" ]; +} + +// ContractCodeHistoryOperationType actions that caused a code change +enum ContractCodeHistoryOperationType { + option (gogoproto.goproto_enum_prefix) = false; + // ContractCodeHistoryOperationTypeUnspecified placeholder for empty value + CONTRACT_CODE_HISTORY_OPERATION_TYPE_UNSPECIFIED = 0 + [ (gogoproto.enumvalue_customname) = + "ContractCodeHistoryOperationTypeUnspecified" ]; + // ContractCodeHistoryOperationTypeInit on chain contract instantiation + CONTRACT_CODE_HISTORY_OPERATION_TYPE_INIT = 1 + [ (gogoproto.enumvalue_customname) = + "ContractCodeHistoryOperationTypeInit" ]; + // ContractCodeHistoryOperationTypeMigrate code migration + CONTRACT_CODE_HISTORY_OPERATION_TYPE_MIGRATE = 2 + [ (gogoproto.enumvalue_customname) = + "ContractCodeHistoryOperationTypeMigrate" ]; + // ContractCodeHistoryOperationTypeGenesis based on genesis data + CONTRACT_CODE_HISTORY_OPERATION_TYPE_GENESIS = 3 + [ (gogoproto.enumvalue_customname) = + "ContractCodeHistoryOperationTypeGenesis" ]; +} + +// ContractCodeHistoryEntry metadata to a contract. +message ContractCodeHistoryEntry { + ContractCodeHistoryOperationType operation = 1; + // CodeID is the reference to the stored WASM code + uint64 code_id = 2 [ (gogoproto.customname) = "CodeID" ]; + // Updated Tx position when the operation was executed. + AbsoluteTxPosition updated = 3; + bytes msg = 4 [ (gogoproto.casttype) = "encoding/json.RawMessage" ]; +} + +// AbsoluteTxPosition is a unique transaction position that allows for global +// ordering of transactions. +message AbsoluteTxPosition { + // BlockHeight is the block the contract was created at + uint64 block_height = 1; + // TxIndex is a monotonic counter within the block (actual transaction index, + // or gas consumed) + uint64 tx_index = 2; +} + +// Model is a struct that holds a KV pair +message Model { + // hex-encode key to read it better (this is often ascii) + bytes key = 1 [ (gogoproto.casttype) = + "github.com/tendermint/tendermint/libs/bytes.HexBytes" ]; + // base64-encode raw value + bytes value = 2; +}