You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is done by using the stub function `stub.PutState`. The function interprets the first argument sent in the deployment request as the value to be stored under the key 'hello_world' in the ledger. Where did this argument come from, and what is a deploy request? All will be explained after we finish implementing the chaincode interface. If an error occurs because the wrong number of arguments was passed in or because something went wrong when writing to the ledger, then this function will return an error. Otherwise, it exits cleanly, returning nothing.
149
-
<<<<<<< HEAD
150
143
151
144
### Invoke()
152
145
153
-
=======
154
-
155
-
### Invoke()
156
-
157
-
>>>>>>> 87d7fc6... Fixed a few of the paths to include 'src', and added the branching option to the 'git clone'
158
146
`Invoke` is called when you want to call chaincode functions to do real work. Invocations will be captured as a transactions, which get grouped into blocks on the chain. When you need to update the ledger, you will do so by invoking your chaincode. The structure of `Invoke` is simple. It receives a `function` and an array of arguments. Based on what function was passed in through the `function` parameter in the invoke request, `Invoke` will either call a helper function or return an error.
159
147
160
148
In your `chaincode_start.go` file, change the `Invoke` function so that it calls a generic write function.
You're probably thinking that this `write` function looks similar to `Init`. It is very similar. Both functions check for a certain number of arguments, and then write a key/value pair to the ledger. However, you'll notice that `write` uses two arguments, allowing you to pass in both the key and the value for the call to `PutState`. Basically, this function allows you to store any key/value pair you want into the blockchain ledger.
225
-
<<<<<<< HEAD
226
-
227
-
### Query()
228
-
229
-
=======
230
189
231
190
### Query()
232
191
233
-
>>>>>>> 87d7fc6... Fixed a few of the paths to include 'src', and added the branching option to the 'git clone'
234
192
As the name implies, `Query` is called whenever you query your chaincode's state. Queries do not result in blocks being added to the chain, and you cannot use functions like `PutState` inside of `Query` or any helper functions it calls. You will use `Query` to read the value of your chaincode state's key/value pairs.
235
193
236
194
In your `chaincode_start.go` file, change the `Query` function so that it calls a generic read function, similar to what you did in `Invoke`.
0 commit comments