forked from horeaporutiu/commercialPaperLoopback
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.js
66 lines (50 loc) · 1.79 KB
/
query.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
'use strict';
const yaml = require('js-yaml');
const { FileSystemWallet, Gateway } = require('fabric-network');
const fs = require('fs');
// A wallet stores a collection of identities for use
const wallet = new FileSystemWallet('./local_fabric/wallet');
async function main() {
// A gateway defines the peers used to access Fabric networks
const gateway = new Gateway();
// Main try/catch block
try {
const identityLabel = 'Admin@org1.example.com';
let connectionProfile = yaml.safeLoad(fs.readFileSync('./network.yaml', 'utf8'));
let connectionOptions = {
identity: identityLabel,
wallet: wallet,
discovery: {
asLocalhost: true
}
};
// Connect to gateway using network.yaml file and our certificates in _idwallet directory
await gateway.connect(connectionProfile, connectionOptions);
console.log('Connected to Fabric gateway.');
// Connect to our local fabric
const network = await gateway.getNetwork('mychannel');
console.log('Connected to mychannel. ');
// Get the contract we have installed on the peer
const contract = await network.getContract('papercontract');
console.log('\nSubmit hello world transaction.');
let response = await contract.evaluateTransaction('queryAll');
console.log(response.toString())
return response;
} catch (error) {
console.log(`Error processing transaction. ${error}`);
console.log(error.stack);
} finally {
// Disconnect from the gateway
console.log('Disconnect from Fabric gateway.');
gateway.disconnect();
}
}
// invoke the main function, can catch any error that might escape
main().then(() => {
console.log('done');
}).catch((e) => {
console.log('Final error checking.......');
console.log(e);
console.log(e.stack);
process.exit(-1);
});