Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const tape = require('tape');
const _test = require('tape-promise').default;
const test = _test(tape);
const util = require('util');
const fs = require('fs');
const path = require('path');
const e2eUtils = require('../e2e/e2eUtils.js');
const Client = require('fabric-client');
const testUtil = require('../../unit/util.js');
let ORGS;
const commonProto = require('fabric-protos').common;
const ccProto = require('fabric-protos').protos;
const client = new Client();
const org = 'org1';
const total = 1000;
const proposals = [];
const DESC = '\n\n** gRPC peer client low-level API performance **';
test(DESC, (t) => {
perfTest3(t);
t.end();
});
async function perfTest3(t) {
testUtil.resetDefaults();
Client.setConfigSetting('key-value-store', 'fabric-ca-client/lib/impl/FileKeyValueStore.js');// force for 'gulp test'
buildChannelHeader(type = checkParameter('type'), chaincode_id = checkParameter('chaincode_id'), tx_id = checkParameter('tx_id')) {
const method = `buildChannelHeader[${this.name}]`;
logger.debug(`${method} - start - type ${type} chaincode_id ${chaincode_id} tx_id ${tx_id}`);
const channelHeader = new fabprotos.common.ChannelHeader();
channelHeader.setType(type); // int32
channelHeader.setVersion(1); // int32
channelHeader.setChannelId(this.name); // string
channelHeader.setTxId(tx_id.toString()); // string
// channelHeader.setEpoch(epoch); // uint64
const chaincodeID = new fabprotos.protos.ChaincodeID();
chaincodeID.setName(chaincode_id);
const headerExt = new fabprotos.protos.ChaincodeHeaderExtension();
headerExt.setChaincodeId(chaincodeID);
channelHeader.setExtension(headerExt.toBuffer());
channelHeader.setTimestamp(buildCurrentTimestamp()); // google.protobuf.Timestamp
channelHeader.setTlsCertHash(this.client.getClientCertHash());
return channelHeader;
}
const proposalResponse = this._endorsement._proposalResponses[0];
const chaincodeEndorsedAction = new fabprotos.protos.ChaincodeEndorsedAction();
chaincodeEndorsedAction.setProposalResponsePayload(proposalResponse.payload);
chaincodeEndorsedAction.setEndorsements(endorsements);
const chaincodeActionPayload = new fabprotos.protos.ChaincodeActionPayload();
chaincodeActionPayload.setAction(chaincodeEndorsedAction);
// the TransientMap field inside the original proposal payload is only meant for the
// endorsers to use from inside the chaincode. This must be taken out before sending
// to the committer, otherwise the transaction will be rejected by the validators when
// it compares the proposal hash calculated by the endorsers and returned in the
// proposal response, which was calculated without the TransientMap
const originalChaincodeProposalPayload = fabprotos.protos.ChaincodeProposalPayload.decode(this._endorsement._action.proposal.getPayload());
const chaincodeProposalPayloadNoTrans = new fabprotos.protos.ChaincodeProposalPayload();
chaincodeProposalPayloadNoTrans.setInput(originalChaincodeProposalPayload.input); // only set the input field, skipping the TransientMap
chaincodeActionPayload.setChaincodeProposalPayload(chaincodeProposalPayloadNoTrans.toBuffer());
const transactionAction = new fabprotos.protos.TransactionAction();
transactionAction.setHeader(this._endorsement._action.header.getSignatureHeader());
transactionAction.setPayload(chaincodeActionPayload.toBuffer());
const actions = [];
actions.push(transactionAction);
const transaction = new fabprotos.protos.Transaction();
transaction.setActions(actions);
this._action.payload = new fabprotos.common.Payload();
this._action.payload.setHeader(this._endorsement._action.header);
this._action.payload.setData(transaction.toBuffer());
function buildTransactionProposal(chaincodeProposal, endorsements, proposalResponse) {
const header = fabprotos.common.Header.decode(chaincodeProposal.getHeader());
const chaincodeEndorsedAction = new fabprotos.protos.ChaincodeEndorsedAction();
chaincodeEndorsedAction.setProposalResponsePayload(proposalResponse.payload);
chaincodeEndorsedAction.setEndorsements(endorsements);
const chaincodeActionPayload = new fabprotos.protos.ChaincodeActionPayload();
chaincodeActionPayload.setAction(chaincodeEndorsedAction);
// the TransientMap field inside the original proposal payload is only meant for the
// endorsers to use from inside the chaincode. This must be taken out before sending
// to the orderer, otherwise the transaction will be rejected by the validators when
// it compares the proposal hash calculated by the endorsers and returned in the
// proposal response, which was calculated without the TransientMap
const originalChaincodeProposalPayload = fabprotos.protos.ChaincodeProposalPayload.decode(chaincodeProposal.payload);
const chaincodeProposalPayloadNoTrans = new fabprotos.protos.ChaincodeProposalPayload();
chaincodeProposalPayloadNoTrans.setInput(originalChaincodeProposalPayload.input); // only set the input field, skipping the TransientMap
chaincodeActionPayload.setChaincodeProposalPayload(chaincodeProposalPayloadNoTrans.toBuffer());
/**
* Copyright 2019 IBM All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
const TYPE = 'Eventer';
const {checkParameter, getLogger} = require('./Utils.js');
const logger = getLogger(TYPE);
const ServiceEndpoint = require('./ServiceEndpoint.js');
const fabprotos = require('fabric-protos');
const _validation_codes = {};
let keys = Object.keys(fabprotos.protos.TxValidationCode);
for (const key of keys) {
const new_key = fabprotos.protos.TxValidationCode[key];
_validation_codes[new_key] = key;
}
const _header_types = {};
keys = Object.keys(fabprotos.common.HeaderType);
for (const key of keys) {
const new_key = fabprotos.common.HeaderType[key];
_header_types[new_key] = key;
}
const FILTERED_BLOCK = 'filtered';
const FULL_BLOCK = 'full';
const PRIVATE_BLOCK = 'private';
function decodeProposalResponsePayload(proposal_response_payload_bytes) {
const proposal_response_payload = {};
const proto_proposal_response_payload = fabprotos.protos.ProposalResponsePayload.decode(proposal_response_payload_bytes);
proposal_response_payload.proposal_hash = proto_proposal_response_payload.getProposalHash().toBuffer().toString('hex');
proposal_response_payload.extension = decodeChaincodeAction(proto_proposal_response_payload.getExtension());
return proposal_response_payload;
}
function decodeConfigValueAnchorPeers(proto_config_value, config_value) {
const anchor_peers = [];
const proto_anchor_peers = fabprotos.protos.AnchorPeers.decode(proto_config_value.value.value);
if (proto_anchor_peers && proto_anchor_peers.anchor_peers) {
for (const i in proto_anchor_peers.anchor_peers) {
const anchor_peer = {
host : proto_anchor_peers.anchor_peers[i].host,
port : proto_anchor_peers.anchor_peers[i].port
};
anchor_peers.push(anchor_peer);
}
}
config_value.value.anchor_peers = anchor_peers;
return config_value;
}
const deserializeRemoteProposal = (proposalBytes) => fabproto6.protos.Proposal.decode(proposalBytes);
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
const {format} = require('util');
const Long = require('long');
const {Utils: utils} = require('fabric-common');
const client_utils = require('./client-utils.js');
const logger = utils.getLogger('Chaincode.js');
const Packager = require('./Packager.js');
const Policy = require('./Policy.js');
const CollectionConfig = require('./SideDB.js');
const TransactionID = require('./TransactionID');
const fabric_protos = require('fabric-protos').protos;
const fabric_common_protos = require('fabric-protos').common;
const lifecycle_protos = require('fabric-protos').lifecycle;
/**
* @classdesc
* The Chaincode class represents an Chaincode definition.
* <br><br>
* see the tutorial {@tutorial chaincode-lifecycle}
* <br><br>
* This class allows an application to contain all chaincode attributes and
* artifacts in one place during runtime. This will assist the administration
* of the chaincode's lifecycle.
*
* From your {@link Client} instance use the {@link Client#newChaincode} method.
* This will return a Chaincode object instance that has been associated with
* that client. This will provide access to user credentials used for signing
constructor(name = checkParameter('name'), client = checkParameter('client'), mspid) {
logger.debug(`${TYPE}.constructor[${name}] - start `);
super(name, client, mspid);
this.type = TYPE;
this.serviceClass = fabprotos.protos.Endorser;
}