Skip to content

Commit f4643f4

Browse files
mbwhiteryjones
andauthored
FABCN-405 Fix tutorial reference (#150) (#152)
Updated to use 2.1 modules Signed-off-by: Ry Jones <ry@linux.com> Co-authored-by: Matthew B White <mbwhite@users.noreply.github.com> Signed-off-by: Matthew B White <whitemat@uk.ibm.com> Co-authored-by: Ry Jones <ry@linux.com>
1 parent c1979e3 commit f4643f4

2 files changed

Lines changed: 46 additions & 46 deletions

File tree

TUTORIAL.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Quick Start
1+
# Quick Start
22

33
Aim: to get a simple smart contract up and running
44

@@ -8,7 +8,7 @@ Aim: to get a simple smart contract up and running
88

99
An initial `package.json` is as follows;
1010

11-
The dependencies of `fabric-chaincode-api` and `fabric-shim` will be required.
11+
The dependencies of `fabric-contract-api` and `fabric-shim` will be required.
1212

1313
```
1414
{
@@ -28,13 +28,13 @@ The dependencies of `fabric-chaincode-api` and `fabric-shim` will be required.
2828
"author": "",
2929
"license": "Apache-2.0",
3030
"dependencies": {
31-
"fabric-chaincode-api": "2.1.3-unstable",
32-
"fabric-shim": "2.1.3-unstable"
31+
"fabric-contract-api": "^2.1.0",
32+
"fabric-shim": "^2.1.0"
3333
}
3434
}
3535
3636
```
37-
Remember to add in any additional business logic, and testing libraries needed
37+
Remember to add in any additional business logic, and testing libraries needed
3838

3939
Adding `fabric-shim` as a dependency, gives a command `fabric-chaincode-node` that is the script to run for `npm start`.
4040

@@ -65,7 +65,7 @@ Within the class you can defined as many or functions as you wish. These transac
6565

6666
Node states that module exports are defined in `index.js`
6767

68-
In this example we have a single value that can be queried and updated. This has been split into to parts for demonstration purposes.
68+
In this example we have a single value that can be queried and updated. This has been split into to parts for demonstration purposes.
6969

7070
```
7171
// index.js
@@ -77,7 +77,7 @@ const RemoveValues = require('./removevalues')
7777
module.exports.contracts = [UpdateValues,RemoveValues];
7878
```
7979

80-
This exports two classes that together form the Contract. There can be other code that within the model that is used in a support role.
80+
This exports two classes that together form the Contract. There can be other code that within the model that is used in a support role.
8181
*Note that the 'contracts' word is mandatory.*
8282

8383
### 4: What do these classes need to contain?
@@ -124,7 +124,7 @@ Note that ALL the functions defined in these modules will be called by the clien
124124

125125
- There are 3 functions `setup` `setNewAssetValue` and `doubleAssetValue` that can be called by issuing the appropriate invoke client side
126126
- The `ctx` in the function is a transaction context; each time a invoke is called this will be a new instance that can be used by the function implementation to access apis such as the world state of information on invoking identity.
127-
- The arguments are split out from the array passed on the invoke.
127+
- The arguments are split out from the array passed on the invoke.
128128
- The constructor contains a 'name' to help identify the sets of functions
129129

130130
## Running chaincode in development mode
@@ -158,29 +158,29 @@ Will get things working...
158158
Then you can invoke the chaincode via this command.
159159

160160
```
161-
$ peer chaincode invoke --orderer localhost:7050 --channelID mychannel -c '{"Args":["UpdateValuesContract:getAssetValue"]}' -n mycontract4
161+
$ peer chaincode invoke --orderer localhost:7050 --channelID mychannel -c '{"Args":["UpdateValuesContract:getAssetValue"]}' -n mycontract4
162162
```
163163

164164

165165
## Additional support provided by the SmartContract class
166166

167-
In the case where you ask for a function to be executed, it could be the case that this doesn't exist.
168-
You can provide you own function to be executed in this case, the default is to throw and error but you're able to customise this if you wish.
167+
In the case where you ask for a function to be executed, it could be the case that this doesn't exist.
168+
You can provide you own function to be executed in this case, the default is to throw and error but you're able to customise this if you wish.
169169

170170
For example
171171

172172

173173
```
174-
/**
175-
* Sets a name so that the functions in this particular class can
174+
/**
175+
* Sets a name so that the functions in this particular class can
176176
* be separated from others.
177177
*/
178178
constructor() {
179179
super('UpdateValuesContract');
180180
}
181181
182182
/** The function to invoke if something unkown comes in.
183-
*
183+
*
184184
*/
185185
async unknownTransaction(ctx){
186186
throw new Error('a custom error message')
@@ -199,15 +199,15 @@ For example
199199

200200
### Structure of the Transaction Context
201201

202-
In Fabric, there is a *stub* api that provides chaincode with functionality.
202+
In Fabric, there is a *stub* api that provides chaincode with functionality.
203203
No functionality has been removed, but a new approach to providing abstractions on this to facilitate programming.
204204

205205
*user additions*: additional properties can be added to the object to support for example common handling of the data serialization.
206206

207-
The context object contains
207+
The context object contains
208208

209209
- `ctx.stub` the same stub instance as in earlier versions for compatibility
210-
- `ctx.identity` and instance of the Client Identity object
210+
- `ctx.identity` and instance of the Client Identity object
211211

212212
You are at liberty to create a subclass of the Context to provide additional functions, or per-transaction context storage. For example
213213

@@ -220,7 +220,7 @@ You are at liberty to create a subclass of the Context to provide additional fun
220220
}
221221
```
222222

223-
and the Context class itself is
223+
and the Context class itself is
224224

225225
```
226226
const { Context } = require('fabric-contract-api');
@@ -255,17 +255,17 @@ Definitions as per https://www.ietf.org/rfc/rfc2119.txt
255255
- as per node.js language standard
256256
- Duplicate function names in a single class is an error
257257
- Any function that is dynamically added will not be registered as an invokable function
258-
- There are no specific function that is invoked per Fabric's *init* chaincode spi. The instantiate flow can pass function name and parameters; therefore consider
258+
- There are no specific function that is invoked per Fabric's *init* chaincode spi. The instantiate flow can pass function name and parameters; therefore consider
259259
a dedicated function that will be called for new chaincode deployments, and for upgrade deployments.
260260

261261
## Restrictions on programming in side a Contract function
262262

263263
Hyperledger Fabric's consensus algorithm permits the ability to use general purpose languages; rather than a more restrictive language. But the following restrictions apply
264264

265265
- Functions should not create random variables, or use any function whose return values are functions of the current time or location of execution
266-
- i.e. the function will be executed in another context (i.e. peer process). This could potentially be in a different time zone in a different locale.
266+
- i.e. the function will be executed in another context (i.e. peer process). This could potentially be in a different time zone in a different locale.
267267
- Functions should be away that they may read state, and write state. But they are producing a set of changes that will be applied to the state. The implication is that updates to the state
268-
may not be read back.
268+
may not be read back.
269269

270270
```
271271
let v1 = getState("key")
@@ -276,9 +276,9 @@ let v2 = getState("key")
276276
v2=="world" // is false, v2 is "hello"
277277
```
278278

279-
In any subsequent invocation, the value would be seen to be updated.
279+
In any subsequent invocation, the value would be seen to be updated.
280280

281-
Note that if you have use any Flux architecture implications such as Redux, the above restrictions will be familiar.
281+
Note that if you have use any Flux architecture implications such as Redux, the above restrictions will be familiar.
282282

283283

284284

docs/_jsdoc/tutorials/using-contractinterface.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11

22

3-
This outlines the theory of the how the new node module works; with the fabric samples project you will find scenario-based approaches.
3+
This outlines the theory of the how the new node module works; with the fabric samples project you will find scenario-based approaches.
44

55
## Writing the chaincode
66

77
### 1: Chaincode is created as an npm module.
88

99
An initial `package.json` is as follows;
1010

11-
The dependencies of `fabric-chaincode-api` and `fabric-shim` will be required.
11+
The dependencies of `fabric-contract-api` and `fabric-shim` will be required.
1212

1313
```
1414
{
@@ -28,13 +28,13 @@ The dependencies of `fabric-chaincode-api` and `fabric-shim` will be required.
2828
"author": "",
2929
"license": "Apache-2.0",
3030
"dependencies": {
31-
"fabric-chaincode-api": "2.1.3-unstable",
32-
"fabric-shim": "2.1.3-unstable"
31+
"fabric-contract-api": "^2.1.0",
32+
"fabric-shim": "^2.1.0"
3333
}
3434
}
3535
3636
```
37-
Remember to add in any additional business logic, and testing libraries needed
37+
Remember to add in any additional business logic, and testing libraries needed
3838

3939
Adding `fabric-shim` as a dependency, gives a command `fabric-chaincode-node` that is the script to run for `npm start`.
4040

@@ -65,7 +65,7 @@ Within the class you can defined as many or functions as you wish. These transac
6565

6666
Node states that module exports are defined in `index.js`
6767

68-
In this example we have a single value that can be queried and updated. This has been split into to parts for demonstration purposes.
68+
In this example we have a single value that can be queried and updated. This has been split into to parts for demonstration purposes.
6969

7070
```
7171
// index.js
@@ -77,7 +77,7 @@ const RemoveValues = require('./removevalues')
7777
module.exports.contracts = [UpdateValues,RemoveValues];
7878
```
7979

80-
This exports two classes that together form the Contract. There can be other code that within the model that is used in a support role.
80+
This exports two classes that together form the Contract. There can be other code that within the model that is used in a support role.
8181
*Note that the 'contracts' word is mandatory.*
8282

8383
### 4: What do these classes need to contain?
@@ -124,7 +124,7 @@ Note that ALL the functions defined in these modules will be called by the clien
124124

125125
- There are 3 functions `setup` `setNewAssetValue` and `doubleAssetValue` that can be called by issuing the appropriate invoke client side
126126
- The `ctx` in the function is a transaction context; each time a invoke is called this will be a new instance that can be used by the function implementation to access apis such as the world state of information on invoking identity.
127-
- The arguments are split out from the array passed on the invoke.
127+
- The arguments are split out from the array passed on the invoke.
128128
- The constructor contains a 'name' to help identify the sets of functions
129129

130130
## Running chaincode in development mode
@@ -158,29 +158,29 @@ Will get things working...
158158
Then you can invoke the chaincode via this command.
159159

160160
```
161-
$ peer chaincode invoke --orderer localhost:7050 --channelID mychannel -c '{"Args":["UpdateValuesContract:getAssetValue"]}' -n mycontract4
161+
$ peer chaincode invoke --orderer localhost:7050 --channelID mychannel -c '{"Args":["UpdateValuesContract:getAssetValue"]}' -n mycontract4
162162
```
163163

164164

165165
## Additional support provided by the SmartContract class
166166

167-
In the case where you ask for a function to be executed, it could be the case that this doesn't exist.
168-
You can provide you own function to be executed in this case, the default is to throw and error but you're able to customise this if you wish.
167+
In the case where you ask for a function to be executed, it could be the case that this doesn't exist.
168+
You can provide you own function to be executed in this case, the default is to throw and error but you're able to customise this if you wish.
169169

170170
For example
171171

172172

173173
```
174-
/**
175-
* Sets a name so that the functions in this particular class can
174+
/**
175+
* Sets a name so that the functions in this particular class can
176176
* be separated from others.
177177
*/
178178
constructor() {
179179
super('UpdateValuesContract');
180180
}
181181
182182
/** The function to invoke if something unkown comes in.
183-
*
183+
*
184184
*/
185185
async unknownTransaction(ctx){
186186
throw new Error('a custom error message')
@@ -199,15 +199,15 @@ For example
199199

200200
### Structure of the Transaction Context
201201

202-
In Fabric, there is a *stub* api that provides chaincode with functionality.
202+
In Fabric, there is a *stub* api that provides chaincode with functionality.
203203
No functionality has been removed, but a new approach to providing abstractions on this to facilitate programming.
204204

205205
*user additions*: additional properties can be added to the object to support for example common handling of the data serialization.
206206

207-
The context object contains
207+
The context object contains
208208

209209
- `ctx.stub` the same stub instance as in earlier versions for compatibility
210-
- `ctx.identity` and instance of the Client Identity object
210+
- `ctx.identity` and instance of the Client Identity object
211211

212212
You are at liberty to create a subclass of the Context to provide additional functions, or per-transaction context storage. For example
213213

@@ -220,7 +220,7 @@ You are at liberty to create a subclass of the Context to provide additional fun
220220
}
221221
```
222222

223-
and the Context class itself is
223+
and the Context class itself is
224224

225225
```
226226
const { Context } = require('fabric-contract-api');
@@ -255,17 +255,17 @@ Definitions as per https://www.ietf.org/rfc/rfc2119.txt
255255
- as per node.js language standard
256256
- Duplicate function names in a single class is an error
257257
- Any function that is dynamically added will not be registered as an invokable function
258-
- There are no specific function that is invoked per Fabric's *init* chaincode spi. The instantiate flow can pass function name and parameters; therefore consider
258+
- There are no specific function that is invoked per Fabric's *init* chaincode spi. The instantiate flow can pass function name and parameters; therefore consider
259259
a dedicated function that will be called for new chaincode deployments, and for upgrade deployments.
260260

261261
## Restrictions on programming in side a Contract function
262262

263263
Hyperledger Fabric's consensus algorithm permits the ability to use general purpose languages; rather than a more restrictive language. But the following restrictions apply
264264

265265
- Functions should not create random variables, or use any function whose return values are functions of the current time or location of execution
266-
- i.e. the function will be executed in another context (i.e. peer process). This could potentially be in a different time zone in a different locale.
266+
- i.e. the function will be executed in another context (i.e. peer process). This could potentially be in a different time zone in a different locale.
267267
- Functions should be away that they may read state, and write state. But they are producing a set of changes that will be applied to the state. The implication is that updates to the state
268-
may not be read back.
268+
may not be read back.
269269

270270
```
271271
let v1 = getState("key")
@@ -276,9 +276,9 @@ let v2 = getState("key")
276276
v2=="world" // is false, v2 is "hello"
277277
```
278278

279-
In any subsequent invocation, the value would be seen to be updated.
279+
In any subsequent invocation, the value would be seen to be updated.
280280

281-
Note that if you have use any Flux architecture implications such as Redux, the above restrictions will be familiar.
281+
Note that if you have use any Flux architecture implications such as Redux, the above restrictions will be familiar.
282282

283283

284284

0 commit comments

Comments
 (0)