forked from pranikamassey/FabricCare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-bna.js
82 lines (69 loc) · 2.64 KB
/
update-bna.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
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict';
/**
* Part of a course on Hyperledger Fabric:
* http://ACloudFan.com
*
* Composer 0.19.0 : Update not valid anymore
*
* https://hyperledger.github.io/composer/latest//api/common-businessnetworkdefinition
* https://hyperledger.github.io/composer/latest//api/admin-adminconnection
*
* Demonstrates the use of admin connection to update an app
*
**** Runtime has already been installed
**** [email protected] deployed and currently active
*
* 1. Create the Admin Connection instance
* 2. Connect
* 3. Create the Business Network Definition Object
* 4. Update the airlinev7 model in runtime
* 5. Disconnect
*/
const FileSystemCardStore = require('composer-common').FileSystemCardStore;
const AdminConnection = require('composer-admin').AdminConnection;
const BusinessNetworkDefinition = require('composer-common').BusinessNetworkDefinition;
const cardNameForPeerAdmin = "PeerAdmin@hlfv1";
const appName = "test-bna";
// This where I have the archive file for v2.0 of airlinev7
// CHANGE THIS DIRECTORY FOR YOUR Model Project
const bnaDirectory = "./test-bna/";
const bnaArchive = "./test-bna/dist/[email protected]";
// 1. Create the AdminConnection instance
// Composer 0.19.0 change
// const cardStore = new FileSystemCardStore();
// const cardStoreObj = { cardStore: cardStore };
// const adminConnection = new AdminConnection(cardStoreObj);
var cardType = { type: 'composer-wallet-filesystem' }
const adminConnection = new AdminConnection(cardType);
// 2. Connect using the card for the Network Admin
return adminConnection.connect(cardNameForPeerAdmin).then(function(){
console.log("Admin Connection Successful!!!");
// Update the BNA
upgradeApp();
}).catch(function(error){
console.log(error);
});
/**
* Deploys a network app using the admin connection
*/
function upgradeApp(){
// 3. Create a Business Network Definition object from directory
var bnaDef = {}
BusinessNetworkDefinition.fromDirectory(bnaDirectory).then(function(definition){
bnaDef = definition;
console.log("Successfully created the definition!!! ",bnaDef.getName())
// Install the new version of the BNA
return adminConnection.install(bnaDef);
}).then(()=>{
// 4. Update the application
// If you do not have the app installed, you will get an error
console.log("Install successful")
return adminConnection.upgrade(appName, '0.0.2');
}).then(()=>{
console.log('App updated successfully!! ', bnaDef.getName(),' ',bnaDef.getVersion());
// 5. Disconnect
adminConnection.disconnect();
}).catch(function(error){
console.log(error);
});
}