Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add note on differences from standard CosmWasm Sub-message Behavior #165

Open
wants to merge 1 commit into
base: gitbook
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ The sub-messages feature can be used to get the response data or events from the

Then the reply is only executed when the instantiate is successful with the instantiate response data. [https://github.com/terraswap/terraswap/blob/7cf47f5e811fe0c4643a7cd09500702c1e7f3a6b/contracts/terraswap\_factory/src/contract.rs#L148-L170](https://github.com/terraswap/terraswap/blob/7cf47f5e811fe0c4643a7cd09500702c1e7f3a6b/contracts/terraswap\_factory/src/contract.rs#L148-L170).

Note differences from standard CosmWasm:
* Obtaining contract data instantiated w/ sub-messages:
* `msg.result.events` from `msg: Reply` passed into `#entry_point pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> StdResult<Response>` should be used to obtain data, such as `contract_address`, after instantiating a contract. Standard CosmWasm will return `MsgInstantiateContractResponse` data as protobuf binary inside `msg.result.data`. However `msg.result.data` currently returns no binary data on Secret Network v1.4. Thus, utilies such as [`parse_instantiate_response_data`](https://github.com/scrtlabs/cw-plus/blob/14a9db7e8b93039fa856cbe126ffdb230a00734a/packages/utils/src/parse_reply.rs#L106) from `cw-utils` will not work.

Comment on lines +128 to +131
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I'm not sure I understand the difference any chance you can comment with an example of how the data is serialized on other cw 1 chain compared to SCRT serialization?

Copy link
Contributor Author

@luca992 luca992 Oct 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference is that cw 1 chains have
msg.result.data = **MsgInstantiateContractResponse protobuf binary**

for example terraswap decodes that data here:
https://github.com/terraswap/terraswap/blob/48e399eaa2e89cca4da8c7b20c9f5512a47ec36d/contracts/terraswap_factory/src/contract.rs#L231

But on secret 1.4.0: msg.result.data just returns null

I'm guessing it's a bug, based on this comment:

// note: even if contractAddr == nil then contractAddr.String() is ok // \o/🤷🤷‍♂️🤷‍♀️🤦🤦‍♂️🤦‍♀️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INFO  [enclave_contract_engine::wasm::engine] Invoking reply() in wasm
INFO  [enclave_contract_engine::wasm::contract] debug_print: "AAAAAAAAA!"
INFO  [enclave_contract_engine::wasm::contract] debug_print: "msg.result.unwrap().data: !"
INFO  [enclave_contract_engine::wasm::contract] debug_print: "msg.result.unwrap().events: [Event { ty: \"instantiate\", attributes: [Attribute { key: \"code_id\", value: \"3\", encrypted: true }, Attribute { key: \"contract_address\", value: \"secret1sh36qn08g4cqg685cfzmyxqv2952q6r8vqktuh\", encrypted: true }] }, Event { ty: \"wasm\", attributes: [Attribute { key: \"contract_address\", value: \"secret1sh36qn08g4cqg685cfzmyxqv2952q6r8vqktuh\", encrypted: true }] }]!"

image

Copy link
Contributor Author

@luca992 luca992 Oct 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can see no data is returned for msg.result.data
But, on other chains they get:
msg.result.data = **MsgInstantiateContractResponse protobuf binary**


### Storage Migration

Rename the type `Extern` to `Deps`, and radically simplify the `init/handle/migrate/query` entrypoints. Rather than `&mut Extern<S, A, Q>`, use `DepsMut`. And instead of `&Extern<S, A, Q>`, use `Deps`. If you ever pass eg. `foo<A: Api>(api: A)` around, you must now use dynamic trait pointers: `foo(api: &dyn Api)`. Here is the quick search-replace guide on how to fix contract.rs:
Expand Down