forked from olegabu/fabric-starter-rest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
37 lines (31 loc) · 1.24 KB
/
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
const fs = require('fs');
const _ = require('lodash');
const cfg = require('./config.js');
const logger = cfg.log4js.getLogger('RestSocketServer');
class Util {
async retryOperation(nTimes, fn) {
return new Promise(async (resolve, reject) => {
if (nTimes <= 0) return reject('Retried invocation unsuccessful');
try {
let response = await fn();
resolve(response);
} catch (err) {
logger.trace(`Error: `, err, `\nRe-trying invocation: ${nTimes}.`);
this.sleep(cfg.CHANNEL_LISTENER_UPDATE_TIMEOUT);
return this.retryOperation(--nTimes, fn);
}
});
}
filterOrderersOut(organizations) {
let ordererNames = [cfg.HARDCODED_ORDERER_NAME, `${cfg.HARDCODED_ORDERER_NAME}.${cfg.ORDERER_DOMAIN}`, `${cfg.ordererName}.${cfg.ORDERER_DOMAIN}`];
return _.differenceWith(organizations, ordererNames, (org, rejectOrg) => org.id === rejectOrg);
}
loadPemFromFile(pemFilePath) {
let certData = fs.readFileSync(pemFilePath);
return Buffer.from(certData).toString()
}
sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
}
module.exports = new Util();