Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let channelObject = this.networkUtil.getNetworkObject().channels[channel];
if (CaliperUtils.checkProperty(channelObject, 'created') && channelObject.created) {
logger.info(`Channel '${channel}' is configured as created, skipping creation`);
continue;
}
if (ConfigUtil.get(ConfigUtil.keys.Fabric.SkipCreateChannelPrefix + channel, false)) {
logger.info(`Creation of Channel '${channel}' is configured to skip`);
continue;
}
channelCreated = true;
let configUpdate;
if (CaliperUtils.checkProperty(channelObject, 'configBinary')) {
logger.info(`Channel '${channel}' definiton being retrieved from file`);
configUpdate = this._getChannelConfigFromFile(channelObject, channel);
}
else {
logger.info(`Channel '${channel}' definiton being generated from description`);
const channelTx = this._createChannelTxEnvelope(channelObject.definition, channel);
const payload = common.Payload.decode(channelTx.getPayload().toBuffer());
const configtx = common.ConfigUpdateEnvelope.decode(payload.getData().toBuffer());
configUpdate = configtx.getConfigUpdate().toBuffer();
}
// NOTE: without knowing the system channel policies, signing with every org admin is a safe bet
let orgs = this.networkUtil.getOrganizationsOfChannel(channel);
let admin; // declared here to keep the admin of the last org of the channel
let signatures = [];
for (let org of orgs) {
if (ccObject.language !== 'golang') {
if (ccObject.language === 'node' && this.networkUtil.isInCompatibilityMode()) {
throw new Error(`${chaincodeInfo.id}@${chaincodeInfo.version} in ${channel}: Node.js chaincodes are supported starting from Fabric v1.1`);
}
if (ccObject.language === 'java' && this.version.lessThan('1.3.0')) {
throw new Error(`${chaincodeInfo.id}@${chaincodeInfo.version} in ${channel}: Java chaincodes are supported starting from Fabric v1.3`);
}
if (!['golang', 'node', 'java'].includes(ccObject.language)) {
throw new Error(`${chaincodeInfo.id}@${chaincodeInfo.version} in ${channel}: unknown chaincode type ${ccObject.language}`);
}
}
// check private collection configuration
if (CaliperUtils.checkProperty(ccObject, 'collections-config')) {
if (this.version.lessThan('1.2.0')) {
throw new Error(`${chaincodeInfo.id}@${chaincodeInfo.version} in ${channel}: private collections are supported from Fabric v1.2`);
}
request['collections-config'] = ccObject['collections-config'];
}
/** @link{ProposalResponseObject} */
let response;
try {
response = await admin.getChannel(channel, true).sendInstantiateProposal(request, this.configChaincodeInstantiateTimeout);
} catch (err) {
throw new Error(`Couldn't endorse ${chaincodeInfo.id}@${chaincodeInfo.version} in ${channel} on peers [${targetPeers.toString()}]: ${err.message}`);
}
CaliperUtils.assertDefined(response);
let results = new Set();
let peers = this.network.channels[channel].peers;
for (let key in peers) {
if (!peers.hasOwnProperty(key)) {
continue;
}
let peer = peers[key];
// if only the peer name is present in the config, then it is a target based on the default values
if (!CaliperUtils.checkDefined(peer)) {
results.add(key.toString());
}
// the default value of 'endorsingPeer' is true, or it's explicitly set to true
if (!CaliperUtils.checkProperty(peer, 'endorsingPeer') ||
(CaliperUtils.checkProperty(peer, 'endorsingPeer') && peer.endorsingPeer)) {
results.add(key.toString());
continue;
}
// the default value of 'chaincodeQuery' is true, or it's explicitly set to true
if (!CaliperUtils.checkProperty(peer, 'chaincodeQuery') ||
(CaliperUtils.checkProperty(peer, 'chaincodeQuery') && peer.chaincodeQuery)) {
results.add(key.toString());
}
}
return results;
}
let admin = this.adminProfiles.get(org);
let txId = admin.newTransactionID(true);
/** @{ChaincodeInstallRequest} */
let request = {
targets: orgPeerTargets,
chaincodePath: ccObject.language === 'golang' ? ccObject.path : CaliperUtils.resolvePath(ccObject.path, this.workspaceRoot),
chaincodeId: ccObject.id,
chaincodeVersion: ccObject.version,
chaincodeType: ccObject.language,
txId: txId
};
// metadata (like CouchDB indices) are only supported since Fabric v1.1
if (CaliperUtils.checkProperty(ccObject, 'metadataPath')) {
if (!this.networkUtil.isInCompatibilityMode()) {
request.metadataPath = CaliperUtils.resolvePath(ccObject.metadataPath, this.workspaceRoot);
} else {
throw new Error(`Installing ${chaincodeInfo.id}@${chaincodeInfo.version} with metadata is not supported in Fabric v1.0`);
}
}
// install to necessary peers of org and process the results
try {
/** @link{ProposalResponseObject} */
let propRespObject = await admin.installChaincode(request);
CaliperUtils.assertDefined(propRespObject);
/** Array of @link{ProposalResponse} objects */
let proposalResponses = propRespObject[0];
CaliperUtils.assertDefined(proposalResponses);
getAdminCryptoContentOfOrganization(org) {
let orgObject = this.network.organizations[org];
// if either is missing, the result is undefined
if (!CaliperUtils.checkAllProperties(orgObject, 'adminPrivateKey', 'signedCert')) {
return undefined;
}
let privateKey = orgObject.adminPrivateKey;
let signedCert = orgObject.signedCert;
let privateKeyPEM;
let signedCertPEM;
if (CaliperUtils.checkProperty(privateKey, 'path')) {
privateKeyPEM = fs.readFileSync(privateKey.path);
} else {
privateKeyPEM = privateKey.pem;
}
if (CaliperUtils.checkProperty(signedCert, 'path')) {
signedCertPEM = fs.readFileSync(signedCert.path);
} else {
signedCertPEM = signedCert.pem;
}
// if either is missing, the result is undefined
if (!privateKeyPEM || !signedCertPEM) {
return undefined;
}
// based on their provided functionality (endorsing and cc query)
let results = new Set();
let peers = this.network.channels[channel].peers;
for (let key in peers) {
if (!peers.hasOwnProperty(key)) {
continue;
}
let peer = peers[key];
// if only the peer name is present in the config, then it is a target based on the default values
if (!CaliperUtils.checkDefined(peer)) {
results.add(key.toString());
}
// the default value of 'endorsingPeer' is true, or it's explicitly set to true
if (!CaliperUtils.checkProperty(peer, 'endorsingPeer') ||
(CaliperUtils.checkProperty(peer, 'endorsingPeer') && peer.endorsingPeer)) {
results.add(key.toString());
continue;
}
// the default value of 'chaincodeQuery' is true, or it's explicitly set to true
if (!CaliperUtils.checkProperty(peer, 'chaincodeQuery') ||
(CaliperUtils.checkProperty(peer, 'chaincodeQuery') && peer.chaincodeQuery)) {
results.add(key.toString());
}
}
return results;
}
let peer = peers[key];
// if only the peer name is present in the config, then it is a target based on the default values
if (!CaliperUtils.checkDefined(peer)) {
results.add(key.toString());
}
// the default value of 'endorsingPeer' is true, or it's explicitly set to true
if (!CaliperUtils.checkProperty(peer, 'endorsingPeer') ||
(CaliperUtils.checkProperty(peer, 'endorsingPeer') && peer.endorsingPeer)) {
results.add(key.toString());
continue;
}
// the default value of 'chaincodeQuery' is true, or it's explicitly set to true
if (!CaliperUtils.checkProperty(peer, 'chaincodeQuery') ||
(CaliperUtils.checkProperty(peer, 'chaincodeQuery') && peer.chaincodeQuery)) {
results.add(key.toString());
}
}
return results;
}
getClientEnrollmentSecret(client) {
if (CaliperUtils.checkProperty(this.network.clients[client].client, 'enrollmentSecret')) {
return this.network.clients[client].client.enrollmentSecret;
}
return undefined;
}
getAttributesOfUser(client) {
if (CaliperUtils.checkProperty(this.clientConfigs[client].client, 'attributes')) {
return this.clientConfigs[client].client.attributes;
}
return [];
}
getTlsCaCertificateOfPeer(peer) {
let peerObject = this.network.peers[peer];
if (!CaliperUtils.checkProperty(peerObject, 'tlsCACerts')) {
return undefined;
}
let tlsCACert = peerObject.tlsCACerts;
let tlsPEM;
if (CaliperUtils.checkProperty(tlsCACert, 'path')) {
tlsPEM = fs.readFileSync(tlsCACert.path).toString();
} else {
tlsPEM = tlsCACert.pem;
}
return tlsPEM;
}