-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathbn-connection-util.js
69 lines (58 loc) · 2.03 KB
/
bn-connection-util.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'use strict';
/**
* Part of a course on Hyperledger Fabric:
* http://ACloudFan.com
*
* Last Update: Dec 21, 2018
* Tested with 0.20.5
*
* The modules exposes these functions:
*
* 1. connect - takes a callback function as an argument
* If Success : execute callback()
* Else : execute callback(error)
* 2. disconnect
* 3. ping - takes a callback(response, error) as an argument
* invokes the callback.
*
* Purpose of this utility:
* Boilerplate code to keep the other sample files CLEAN :)
* You may change the constants in this code to connect to
* your apps instead of the default airlinev7
*/
module.exports = {
// Properties used for creating instance of the BN connection
cardStore : require('composer-common').FileSystemCardStore,
BusinessNetworkConnection : require('composer-client').BusinessNetworkConnection,
// Used for connect()
cardName : "admin@airlinev7",
// Holds the Business Network Connection
connection: {},
// 1. This is the function that is called by the app
connect : function(callback) {
// Create instance of file system card store
// Composer 0.19.0 Change
//const cardStore = new this.cardStore();
//this.connection = new this.BusinessNetworkConnection({ cardStore: cardStore });
var cardType = { type: 'composer-wallet-filesystem' }
this.connection = new this.BusinessNetworkConnection(cardType);
// Invoke connect
return this.connection.connect(this.cardName).then(function(){
callback();
}).catch((error)=>{
callback(error);
});
},
// 2. Disconnects the bn connection
disconnect : function(callback) {
this.connection.disconnect();
},
// 3. Pings the network
ping : function(callback){
return this.connection.ping().then((response)=>{
callback(response);
}).catch((error)=>{
callback({}, error);
});
}
}