@@ -24,7 +24,7 @@ Chaincode API
24
24
-------------
25
25
26
26
Every chaincode program must implement the
27
- `Chaincode interface <https ://github.com/hyperledger/fabric/blob/master/ core/chaincode/shim/interfaces.go#L28 >`_
27
+ `Chaincode interface <http ://godoc.org/ github.com/hyperledger/fabric/core/chaincode/shim#Chaincode >`_
28
28
whose methods are called in response to received transactions.
29
29
In particular the ``Init `` method is called when a
30
30
chaincode receives an ``instantiate `` or ``upgrade `` transaction so that the
@@ -33,7 +33,7 @@ application state. The ``Invoke`` method is called in response to receiving an
33
33
``invoke `` transaction to process transaction proposals.
34
34
35
35
The other interface in the chaincode "shim" APIs is the
36
- `ChaincodeStubInterface <https ://github.com/hyperledger/fabric/blob/master/ core/chaincode/shim/interfaces.go#L42 >`_
36
+ `ChaincodeStubInterface <http ://godoc.org/ github.com/hyperledger/fabric/core/chaincode/shim#ChaincodeStub >`_
37
37
which is used to access and modify the ledger, and to make invocations between
38
38
chaincodes.
39
39
@@ -72,10 +72,11 @@ Housekeeping
72
72
^^^^^^^^^^^^
73
73
74
74
First, let's start with some housekeeping. As with every chaincode, it implements the
75
- `Chaincode interface ` <https ://github.com/hyperledger/fabric/blob/master/ core/chaincode/shim/interfaces.go#L28>_,
75
+ `Chaincode interface < http ://godoc.org/ github.com/hyperledger/fabric/core/chaincode/shim#Chaincode >`_
76
76
in particular, ``Init `` and ``Invoke `` functions. So, let's add the go import
77
77
statements for the necessary dependencies for our chaincode. We'll import the
78
- chaincode shim package and the peer protobuf package.
78
+ chaincode shim package and the
79
+ `peer protobuf package <http://godoc.org/github.com/hyperledger/fabric/protos/peer >`_.
79
80
80
81
.. code :: go
81
82
@@ -106,8 +107,8 @@ Next, we'll implement the ``Init`` function.
106
107
no "migration" or nothing to be initialized as part of the upgrade.
107
108
108
109
Next, we'll retrieve the arguments to the ``Init `` call using the
109
- `` ChaincodeStubInterface.GetStringArgs `` function and check for validity.
110
- In our case, we are expecting a key-value pair.
110
+ `ChaincodeStubInterface.GetStringArgs < http://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim#ChaincodeStub.GetStringArgs >`_
111
+ function and check for validity. In our case, we are expecting a key-value pair.
111
112
112
113
.. code :: go
113
114
@@ -125,9 +126,9 @@ In our case, we are expecting a key-value pair.
125
126
126
127
Next, now that we have established that the call is valid, we'll store the
127
128
initial state in the ledger. To do this, we will call
128
- `` ChaincodeStubInterface.PutState `` with the key and value passed in as
129
- the arguments. Assuming all went well, return a peer.Response object that
130
- indicates the initialization was a success.
129
+ `ChaincodeStubInterface.PutState < http://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim#ChaincodeStub.PutState >`_
130
+ with the key and value passed in as the arguments. Assuming all went well,
131
+ return a peer.Response object that indicates the initialization was a success.
131
132
132
133
.. code :: go
133
134
@@ -171,8 +172,9 @@ As with the ``Init`` function above, we need to extract the arguments from the
171
172
name of the chaincode application function to invoke. In our case, our application
172
173
will simply have two functions: ``set `` and ``get ``, that allow the value of an
173
174
asset to be set or its current state to be retrieved. We first call
174
- ``ChaincodeStubInterface.GetFunctionAndParameters `` to extract the function
175
- name and the parameters to that chaincode application function.
175
+ `ChaincodeStubInterface.GetFunctionAndParameters <http://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim#ChaincodeStub.GetFunctionAndParameters >`_
176
+ to extract the function name and the parameters to that chaincode application
177
+ function.
176
178
177
179
.. code :: go
178
180
@@ -220,7 +222,8 @@ Implementing the Chaincode Application
220
222
As noted, our chaincode application implements two functions that can be
221
223
invoked via the ``Invoke `` function. Let's implement those functions now.
222
224
Note that as we mentioned above, to access the ledger's state, we will leverage
223
- the ``ChaincodeStubInterface.PutState `` and ``ChaincodeStubInterface.GetState ``
225
+ the `ChaincodeStubInterface.PutState <http://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim#ChaincodeStub.PutState >`_
226
+ and `ChaincodeStubInterface.GetState <http://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim#ChaincodeStub.GetState >`_
224
227
functions of the chaincode shim API.
225
228
226
229
.. code :: go
@@ -261,7 +264,8 @@ Pulling it All Together
261
264
^^^^^^^^^^^^^^^^^^^^^^^
262
265
263
266
Finally, we need to add the ``main `` function, which will call the
264
- ``shim.Start `` function. Here's the whole chaincode program source.
267
+ `shim.Start <http://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim#Start >`_
268
+ function. Here's the whole chaincode program source.
265
269
266
270
.. code :: go
267
271
0 commit comments