-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathmanage-cards.js
More file actions
48 lines (35 loc) · 1.65 KB
/
manage-cards.js
File metadata and controls
48 lines (35 loc) · 1.65 KB
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
'use strict';
/**
* Part of a Hyperledger Fabric Course : http://ACloudFan.com
*
* Composer 0.19.0
*
* https://hyperledger.github.io/composer/latest//business-network/cloud-wallets
* https://github.com/hyperledger/composer/blob/master/packages/composer-common/lib/cardstore/networkcardstoremanager.js
*
* 1. Get the instance of the NetworkCardStoreManager
* 2. Create instance of BusinessNetworkCardStore for filesystem based wallet
* 3. BusinessNetworkCardStore : Get all cards on file system & print the names on console
* 4. BusinessNetworkCardStore :Get the first card by name
*/
// 1. Get the instance of the NetworkCardStoreManager
const NetworkCardStoreManager= require('composer-common').NetworkCardStoreManager;
// 2. Get instance of BusinessNetworkCardStore for filesystem based wallet
var walletType = { type: 'composer-wallet-filesystem' }
const cardStore = NetworkCardStoreManager.getCardStore( walletType );
// 3. Gets all the card
return cardStore.getAll().then(function(cardMap){
// Print all card names
console.log(cardMap.keys());
// 4. Get the name of the first card & then retrieve it
let firstCard = cardMap.keys().next().value
// Get the firstCard - returns a promise so check .then()
return cardStore.get(firstCard);
}).then(function(idCard){
// get the user and business name
console.log("Pulled First Card from file system: ", idCard.getUserName(),' @ ', idCard.getBusinessNetworkName())
// get the connection profile
console.log("Connection Profile Name: ",idCard.getConnectionProfile().name)
}).catch((error)=>{
console.log(error)
});