-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathchangeCarOwner.js
44 lines (39 loc) · 1.12 KB
/
changeCarOwner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
module.exports.info = 'Fabcar: Changing Car Owners.';
let txIndex = 0;
let carOwners = ["David", "Sahil", "Philip", "Andrea", "Max", "Zack", "Tom", "Sam", "Akash"];
let bc, contx;
module.exports.init = function (blockchain, context, args) {
bc = blockchain;
contx = context;
return Promise.resolve();
};
module.exports.run = function () {
let args;
if (bc.bcType === 'fabric-ccp') {
args = {
chaincodeFunction: 'changeCarOwner',
chaincodeArguments: [
'CAR' + (txIndex % 10).toString(),
carOwners[Math.floor(Math.random() * carOwners.length)] + process.pid.toString()
]
};
} else {
args = {
transaction_type: "changeCarOwner",
CarID: 'CAR' + (txIndex % 10).toString(),
Owner: carOwners[Math.floor(Math.random() * carOwners.length)] + process.pid.toString()
};
}
txIndex++;
return bc.invokeSmartContract(
contx,
'fabcar',
'v1',
[args],
30
);
};
module.exports.end = function () {
return Promise.resolve();
};