-
Notifications
You must be signed in to change notification settings - Fork 4
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
Describe building contract and query creation #182
base: cw-tutorial/contract-creation
Are you sure you want to change the base?
Describe building contract and query creation #182
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Please don't get discouraged by the number of comments - they're mostly nitpicks. The one thing I think is sort of important is the snake case one.
Overall it's still a very solid guide! :)
@@ -1,4 +1,6 @@ | |||
{ | |||
"contract-creation": "Contract creation", | |||
"entry-points": "Entry points" | |||
"entry-points": "Entry points", | |||
"building-contract": "Building contract", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"building-contract": "Building contract", | |
"building-contract": "Building the contract", |
|
||
The `--target` argument tells cargo to perform cross-compilation for a given target instead of | ||
building a native binary for an OS it is running on - in this case, `wasm32-unknown-unknown`, which | ||
is a fancy name for Wasm target. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is a fancy name for Wasm target. | |
is a fancy name for the Wasm target. |
building even smaller binaries. For production, all the contracts should be compiled using this | ||
tool, but for learning purposes, it is not an essential thing to do. | ||
|
||
## Aliasing build command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## Aliasing build command | |
## Aliasing the build command |
|
||
## Aliasing build command | ||
|
||
Now I can see you are disappointed in building your contracts with some overcomplicated command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I can see you are disappointed in building your contracts with some overcomplicated command | |
Now I can imagine you are disappointed in building your contracts with some overcomplicated command |
|
||
## Checking contract validity | ||
|
||
When the contract is built, the last step is to ensure it is a valid CosmWasm contract is to call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the contract is built, the last step is to ensure it is a valid CosmWasm contract is to call | |
Once the contract is built, the last step is to ensure it is a valid CosmWasm contract by calling |
Note that our entry point still has the same `Empty` type for its `msg` argument - it means that the | ||
query message we would send to the contract is still an empty JSON: `{}` | ||
|
||
The last thing that changed is the return type. Instead of returning the `Response` type on the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last thing that changed is the return type. Instead of returning the `Response` type on the | |
The last thing that changed is the return type. Instead of returning the `Response` type for the |
query message we would send to the contract is still an empty JSON: `{}` | ||
|
||
The last thing that changed is the return type. Instead of returning the `Response` type on the | ||
success case, we return an arbitrary serializable object. This is because queries are not using a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
success case, we return an arbitrary serializable object. This is because queries are not using a | |
success case, we return an arbitrary serializable object. This is because queries do not use a |
JSON. It is terrible - if we would like to add another query in the future, it would be difficult to | ||
have any reasonable distinction between query variants. | ||
|
||
In practice, we address this by using a non-empty query message type. Improve our contract: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In practice, we address this by using a non-empty query message type. Improve our contract: | |
In practice, we address this by using a non-empty query message type. Let's improve our contract: |
message: String, | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our convention is to encode enum variants as snake_case JSON names. We either use the rename_all
Serde attribute or go through the cw_serde
macro.
|
||
Straightforward top-level module. Definition of submodules and entry points, nothing more. | ||
|
||
Now, when we have the contract ready to do something, let's go and test it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, when we have the contract ready to do something, let's go and test it. | |
Now, since our contract is ready to do something, let's go and test it. |
I'm guessing this better conveys what you meant, could be wrong
Part of #176