Skip to content

Commit

Permalink
Add back CosmWasm wasmd protos (#241)
Browse files Browse the repository at this point in the history
* Needed for backwards compatibility for now
  • Loading branch information
Carolyn Russell authored Sep 15, 2021
1 parent f782f7d commit 95118e4
Show file tree
Hide file tree
Showing 10 changed files with 740 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions buildSrc/src/main/kotlin/io/provenance/DownloadProtosTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"
)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -245,12 +251,19 @@ fun Any.getAssociatedAddresses(): List<String> =
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()
Expand Down
60 changes: 60 additions & 0 deletions third_party/proto/cosmwasm/wasm/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -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;
}
30 changes: 30 additions & 0 deletions third_party/proto/cosmwasm/wasm/v1beta1/ibc.proto
Original file line number Diff line number Diff line change
@@ -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\"" ];
}
121 changes: 121 additions & 0 deletions third_party/proto/cosmwasm/wasm/v1beta1/proposal.proto
Original file line number Diff line number Diff line change
@@ -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\""
];
}
Loading

0 comments on commit 95118e4

Please sign in to comment.