This repository has been archived by the owner on Feb 17, 2020. It is now read-only.
forked from olegabu/fabric-starter-rest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabric-cli.js
60 lines (46 loc) · 2 KB
/
fabric-cli.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
const fs = require('fs'),
_ = require('lodash'),
envsub = require('envsub'),
shell = require('shelljs');
const cfg = require('./config.js');
const certPaths = {
'admincerts': 'Admin@',
'cacerts': 'ca.',
'tlscacerts': 'tlsca.'
};
const WGET_OPTS = process.env.WGET_OPTS || '';
class FabricCLI {
downloadOrdererMSP() {
_.forEach(_.keys(certPaths), key => {
let certFileName = `${certPaths[key]}${cfg.domain}-cert.pem`;
let directoryPrefix = `${cfg.ORDERER_CRYPTO_DIR}/msp/${key}`;
shell.exec(`/usr/bin/wget ${WGET_OPTS} --directory-prefix ${directoryPrefix} http://www.${cfg.domain}/msp/${key}/${certFileName}`);
});
}
envSubst(templateFile, outputFile) {
return envsub({templateFile, outputFile, options: {diff: false}});
}
generateConfigTxForChannel(channelName, configDir, profile, outputTxFile) {
shell.exec(`configtxgen -channelID ${channelName} -configPath ${configDir} -profile ${profile} -outputCreateChannelTx ${outputTxFile}`)
}
execPeerCommand(command, paramsStr) {
shell.exec(`peer ${command} -o ${cfg.ORDERER_ADDR} --tls --cafaile /etc/hyperledger/crypto/orderer/tls/ca.crt ${paramsStr}`)
}
generateChannelConfigTx(channelName) {
return this.envSubst("templates/configtx-template.yaml", "crypto-config/configtx.yaml")
.then(envObj => {
let outputTxFile = `crypto-config/configtx/channel_${channelName}.tx`;
this.generateConfigTxForChannel(channelName, "crypto-config", "CHANNEL", outputTxFile);
return outputTxFile;
});
}
async generateChannelConfigTxContent(channelName) {
let channelTxFile = await this.generateChannelConfigTx(channelName);
return new Promise((resolve, reject) => {
fs.readFile(channelTxFile, (err, data) => {
!err ? resolve(data) : reject(err);
})
}).catch(console.log)
}
}
module.exports = new FabricCLI();