-
Notifications
You must be signed in to change notification settings - Fork 0
/
queryConsent.js
53 lines (45 loc) · 1.67 KB
/
queryConsent.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
'use strict';
const {Gateway, FileSystemWallet, DefaultQueryHandlerStrategies} = require('fabric-network');
const fs = require('fs');
const path = require('path');
async function main(args) {
try {
const ccpPath = path.resolve(__dirname, 'connection.json');
const ccp = JSON.parse(fs.readFileSync(ccpPath, 'utf8'));
const walletPath = path.resolve(__dirname, 'wallet');
const wallet = new FileSystemWallet(walletPath);
const gateway = new Gateway();
const connectOptions = {
queryHandlerOptions: {
strategy: DefaultQueryHandlerStrategies.MSPID_SCOPE_SINGLE
}
};
await gateway.connect(ccp, {
wallet,
identity: args[0],
discovery: {enabled: true, asLocalhost: false}, ...connectOptions
});
const network = await gateway.getNetwork('channel2');
const contract = network.getContract('consentio');
// const t0 = new Date().getTime();
// const response =
await queryConsent(contract);
// const t1 = new Date().getTime();
// console.log(response.toString('utf8'));
// console.log("Execution time: " + (t1 - t0) + " ms");
await gateway.disconnect();
} catch (error) {
console.error(`Failed to query chaincode: ${error}`);
process.exit(1);
}
}
async function queryConsent(contract) {
return contract.evaluateTransaction("queryConsent",
"{\n" +
" \"selector\": {},\n" +
" \"skip\": 3900,\n" +
" \"use_index\": [\"_design/indexConsentDoc\", \"indexConsent\"]}" +
"}");
}
// args: [user]
main(process.argv.slice(2));