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 WasmQuery::CodeInfo to get checksum for code ID #1561

Merged
merged 7 commits into from
Jan 5, 2023
Merged

Conversation

webmaster128
Copy link
Member

The motivation for this addition is the following: WasmMsg::Instantiate2 requires a code ID. But when a contract wants to pre-compute the address, it also needs the checksum. It would be very inconvenient if a contract developer had to provide both as part of the instruction. With the query you can just provide a code ID and query the checksum as part of the contract.

@webmaster128 webmaster128 requested a review from alpe January 3, 2023 13:35
@webmaster128 webmaster128 force-pushed the code-query branch 2 times, most recently from 3501878 to c6505ec Compare January 3, 2023 15:20
This was referenced Jan 3, 2023
Copy link
Contributor

@alpe alpe left a comment

Choose a reason for hiding this comment

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

Looks good and useful!
Please see my comment about the InstantiateConfig


/// The essential data from wasmd's [CodeInfo]/[CodeInfoResponse].
///
/// `code_hash`/`data_hash` was renamed to `checksum` to follow the CosmWasm
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 good to have the naming correct here.

packages/std/src/testing/mock.rs Show resolved Hide resolved
pub creator: String,
/// The hash of the Wasm blob
pub checksum: Binary,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to return the InstantiateConfig as well? It feels incomplete without

Copy link
Member Author

Choose a reason for hiding this comment

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

I was hesitant to add it since it is a complex deeply nested type that is not trivial to add to all the layers in between. But I can have a second look today.

I agree it feels incomplete. But on the other hand the smaller the interface, the more we can break on the wasmd side without breaking contracts. Do you see a clear use case for this information in the contract?

Copy link
Member Author

@webmaster128 webmaster128 Jan 5, 2023

Choose a reason for hiding this comment

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

Given that

I would like to avoid blockin Instantiate2 usage on that. The field can be added later on.

@@ -26,6 +26,9 @@ pub enum WasmQuery {
},
/// Returns a [`ContractInfoResponse`] with metadata on the contract from the runtime
ContractInfo { contract_addr: String },
/// Returns a [`CodeInfoResponse`] with metadata of the code
#[cfg(feature = "cosmwasm_1_2")]
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@webmaster128 webmaster128 merged commit f4d5053 into main Jan 5, 2023
@webmaster128 webmaster128 deleted the code-query branch January 5, 2023 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants