deps.storageis being used as a function parameter. This gives us a clue as to what the
depsvariable contains - objects that allow the contract to interact with functionality outside the contract code itself. Some examples of this are using long-term storage, calling efficient crypto APIs, or querying the blockchain state.
#[derive]stuff, and instead look at our data structures. We can see that our
Statedata structure contains the exact types that we expected when thinking about the design of the contract. We'll also note that we chose to contain the user data in the
msgis some data type that tells us what function we need to call.
ExecuteMsgis defined as:
ExecuteMsgis just an enumeration of the different message types (and their parameters) that a user can send to the contract. The way this works in practice is that the user sends his data as a JSON object. This object then gets parsed and matched according to the definition in
ExecuteMsg. If the object does not match one of the enum types? The transaction will fail and get rejected!
Responseobject in this case returns something called an attribute. An attribute is a key-value pair that gets returned after a successful message that can help summarizing what happened. Attributes can even be indexed, queried and used as event triggers via WebSocket.
QueryMsgdata type are functionally similar to the
ExecuteMsgtype we've seen earlier. By now you'll know where this data type is defined, so you can go take a look at the definition and verify this assumption.
to_binarymethod sticks out as odd. We haven't seen this in our executes or the instantiate function. The reason for this is that queries are returned as binary data. Executes and the instantiate function return complex objects that are saved to the blockchain state, whereas queries are simple and only need to return the specific data the user cares about.
RicherResponse(we ignore the
StdResultwrapper - it is used to handle and include errors in the possible return types).
RicherResponseis a custom type that we defined (in msg.rs).