@@ -19,7 +19,7 @@ The dependencies of `fabric-contract-api` and `fabric-shim` will be required.
1919 "npm": "^6.4.1"
2020 },
2121 "scripts": {
22- "test":"mocha.....
22+ "test":"mocha.....
2323 },
2424 "engine-strict": true,
2525 "engineStrict": true,
@@ -74,7 +74,7 @@ In this example we have a single value that can be queried and updated. This has
7474const UpdateValues = require('./updatevalues')
7575const RemoveValues = require('./removevalues')
7676
77- module.exports.contracts = [UpdateValues,RemoveValues];
77+ module.exports.contracts = [UpdateValues, RemoveValues];
7878```
7979
8080This exports two classes that together form the Contract. There can be other code that within the model that is used in a support role.
@@ -97,24 +97,23 @@ const util = require('util');
9797/**
9898 * Support the Updating of values within the SmartContract
9999 */
100- class UpdateValues extends Contract{
100+ class UpdateValues extends Contract {
101101
102- constructor(){
103- super('UpdateValuesContract');
104- }
105-
106- async instantiate(ctx){
107- // .....
108- }
102+ constructor() {
103+ super('UpdateValuesContract');
104+ }
109105
110- async setNewAssetValue (ctx, newValue ) {
111- // .....
112- }
106+ async instantiate (ctx) {
107+ // .....
108+ }
113109
114- async doubleAssetValue (ctx) {
115- // .....
116- }
110+ async setNewAssetValue (ctx, newValue ) {
111+ // .....
112+ }
117113
114+ async doubleAssetValue(ctx) {
115+ // .....
116+ }
118117};
119118
120119module.exports = UpdateValues;
@@ -171,40 +170,39 @@ For example
171170
172171
173172```
174- /**
175- * Sets a name so that the functions in this particular class can
176- * be separated from others.
177- */
178- constructor() {
179- super('UpdateValuesContract');
180- }
181-
182- /** The function to invoke if something unkown comes in.
183- *
184- */
185- async unknownTransaction(ctx){
186- throw new Error('a custom error message')
187- }
188-
189- async beforeTransaction(ctx){
190- console.info(`Transaction ID: ${ctx.stub.getTxID()}`);
191- }
192-
193- async afterTransaction(ctx,result){
194- // log result to preferred log implementation
195- // emit events etc...
196- }
197-
198- async aroundTransaction(ctx, fn, parameters) {
199- try {
200- // don't forget to call super, or your transaction function won't run!
201- super.aroundTransaction(ctx, fn, parameters)
202- } catch (error) {
203- // do something with the error, then rethrow
204- throw error
205- }
206- }
173+ /**
174+ * Sets a name so that the functions in this particular class can
175+ * be separated from others.
176+ */
177+ constructor() {
178+ super('UpdateValuesContract');
179+ }
207180
181+ /** The function to invoke if something unkown comes in.
182+ *
183+ */
184+ async unknownTransaction(ctx) {
185+ throw new Error('a custom error message');
186+ }
187+
188+ async beforeTransaction(ctx){
189+ console.info(`Transaction ID: ${ctx.stub.getTxID()}`);
190+ }
191+
192+ async afterTransaction(ctx,result){
193+ // log result to preferred log implementation
194+ // emit events etc...
195+ }
196+
197+ async aroundTransaction(ctx, fn, parameters) {
198+ try {
199+ // don't forget to call super, or your transaction function won't run!
200+ super.aroundTransaction(ctx, fn, parameters);
201+ } catch (error) {
202+ // do something with the error, then rethrow
203+ throw error;
204+ }
205+ }
208206```
209207
210208### Structure of the Transaction Context
@@ -222,29 +220,28 @@ The context object contains
222220You are at liberty to create a subclass of the Context to provide additional functions, or per-transaction context storage. For example
223221
224222```
225- /**
226- * Custom context for use within this contract
227- */
228- createContext(){
229- return new ScenarioContext();
230- }
223+ /**
224+ * Custom context for use within this contract
225+ */
226+ createContext() {
227+ return new ScenarioContext();
228+ }
231229```
232230
233231and the Context class itself is
234232
235233```
236234const { Context } = require('fabric-contract-api');
237235
238- class ScenarioContext extends Context{
236+ class ScenarioContext extends Context {
239237
240- constructor(){
241- super();
242- }
243-
244- generateKey(){
245- return this.stub.createCompositeKey('type',['keyvalue']);
246- }
238+ constructor() {
239+ super();
240+ }
247241
242+ generateKey() {
243+ return this.stub.createCompositeKey('type', ['keyvalue']);
244+ }
248245}
249246
250247```
@@ -278,22 +275,14 @@ Hyperledger Fabric's consensus algorithm permits the ability to use general purp
278275may not be read back.
279276
280277```
281- let v1 = getState("key")
282- v1== "hello" // is true
283- putState("key","world")
278+ let v1 = getState("key");
279+ v1 == "hello"; // is true
280+ putState("key", "world");
284281
285- let v2 = getState("key")
286- v2== "world" // is false, v2 is "hello"
282+ let v2 = getState("key");
283+ v2 == "world"; // is false, v2 is "hello"
287284```
288285
289286In any subsequent invocation, the value would be seen to be updated.
290287
291288Note that if you have used any Flux architecture implications such as Redux, the above restrictions will be familiar.
292-
293-
294-
295-
296-
297-
298-
299-
0 commit comments