Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for (let i=0; i
async _installChaincodes() {
if (this.configOverwriteGopath) {
process.env.GOPATH = CaliperUtils.resolvePath('.', this.workspaceRoot);
}
let errors = [];
let channels = this.networkUtil.getChannels();
for (let channel of channels) {
logger.info(`Installing chaincodes for ${channel}...`);
// proceed cc by cc for the channel
let chaincodeInfos = this.networkUtil.getChaincodesOfChannel(channel);
for (let chaincodeInfo of chaincodeInfos) {
let ccObject = this.networkUtil.getNetworkObject().channels[channel].chaincodes.find(
cc => cc.id === chaincodeInfo.id && cc.version === chaincodeInfo.version);
let targetPeers = this.networkUtil.getTargetPeersOfChaincodeOfChannel(chaincodeInfo, channel);
if (targetPeers.size < 1) {
domain: args.domain,
id: args.id,
pubKey: args.pubKey,
privKey: args.privKey,
txCounter: 1,
queryCounter: 1
};
let config = require(this.configPath);
// find callbacks for simulated smart contract
let fc = config.iroha.fakecontract;
let fakeContracts = {};
for(let i = 0 ; i < fc.length ; i++) {
let contract = fc[i];
//load the fakeContract.
let facPath = CaliperUtils.resolvePath(contract.factory,this.workspaceRoot);
let factory = require(facPath);
for(let j = 0 ; j < contract.id.length ; j++) {
let id = contract.id[j];
if(!factory.contracts.hasOwnProperty(id)) {
throw new Error('Could not get function "' + id + '" in ' + facPath);
}
else {
if(fakeContracts.hasOwnProperty(id)) {
logger.warn('WARNING: multiple callbacks for ' + id + ' have been found');
}
else {
fakeContracts[id] = factory.contracts[id];
}
}
}
}
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);
proposalResponses.forEach((propResponse, index) => {
_getChannelConfigFromFile(channelObject, channelName) {
// extracting the config from the binary file
let binaryPath = CaliperUtils.resolvePath(channelObject.configBinary, this.workspaceRoot);
let envelopeBytes;
try {
envelopeBytes = fs.readFileSync(binaryPath);
} catch (err) {
throw new Error(`Couldn't read configuration binary for ${channelName}: ${err.message}`);
}
try {
return new FabricClient().extractChannelConfig(envelopeBytes);
} catch (err) {
throw new Error(`Couldn't extract configuration object for ${channelName}: ${err.message}`);
}
}
let org = orgs[i];
let profile = createCommonConnectionProfile(org.name, config, workspacepath);
// set metadata options
let metadata = {
version: 1,
userName : `${org.name}@${config.composer.network['x-type']}`,
roles : 'PeerAdmin',
};
// base card
let idCard = new IdCard(metadata, profile);
// certificates & privateKey
let certpath = CaliperUtils.resolvePath(org.adminCert, workspacepath);
let keyPath = CaliperUtils.resolvePath(org.adminKey, workspacepath);
let cert = fs.readFileSync(certpath).toString();
let key = fs.readFileSync(keyPath).toString();
const newCredentials = {};
newCredentials.certificate = cert;
newCredentials.privateKey = key;
idCard.setCredentials(newCredentials);
let cardName = `PerfPeerAdmin@${org.name}`;
let exists = await adminConnection.hasCard(cardName);
if (exists) {
await adminConnection.deleteCard(cardName);
await adminConnection.importCard(cardName, idCard);
} else {
await adminConnection.importCard(cardName, idCard);
async prepareClients(number) {
try{
// get admin info
let config = require(this.configPath);
let admin = config.iroha.admin;
let domain = admin.domain;
let adminAccount = admin.account + '@' + admin.domain;
let privPath = CaliperUtils.resolvePath(admin['key-priv'], this.workspaceRoot);
let pubPath = CaliperUtils.resolvePath(admin['key-pub'], this.workspaceRoot);
let adminPriv = fs.readFileSync(privPath).toString();
let adminPub = fs.readFileSync(pubPath).toString();
// test
logger.info(`Admin's private key: ${adminPriv}`);
logger.info(`Admin's public key: ${adminPub}`);
// create account for each client
let result = [];
let node = this._findNode();
logger.info('node: ' + node.torii);
let commandService = new CommandService_v1Client(
node.torii,
grpc.credentials.createInsecure()
);
static getBatchBuilder(familyName, familyVersion, config, workspaceRoot) {
if (familyVersion === 'v0') {
familyVersion = '1.0';
}
if (!config.sawtooth.batchBuilders) {
throw new Error('There are no batch builders defined in the configuration');
}
if (!config.sawtooth.batchBuilders[familyName]) {
throw new Error('There is no batch builder for ' + familyName);
}
if (!config.sawtooth.batchBuilders[familyName][familyVersion]) {
throw new Error('There is no batch builder for ' + familyName + '[' + familyVersion + ']');
}
const handlerPath = config.sawtooth.batchBuilders[familyName][familyVersion];
try {
const handler = require(CaliperUtils.resolvePath(handlerPath, workspaceRoot));
return new handler(familyName, familyVersion);
} catch (err) {
throw new Error('Unable to load batch builder for ' + familyName + '[' + familyVersion +
'] at ' + handlerPath + '::' + err.message);
}
}
}
function burrowConnect(config, workspace_root) {
let host = config.burrow.network.validator.host;
if (host === null) {
throw new Error('host url not set');
}
let port = config.burrow.network.validator.port;
if (port === null) {
throw new Error('grpc port not set');
}
let account;
try {
account = fs.readFileSync(CaliperUtils.resolvePath(config.burrow.network.validator.address, workspace_root)).toString();
} catch (err) {
account = config.burrow.network.validator.address.toString();
}
logger.info(`Account: ${account}`);
if (account === null) {
throw new Error('no validator account found');
}
return {
url: host + ':' + port,
account: account,
};
}