Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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(header.getSignatureHeader());
transactionAction.setPayload(chaincodeActionPayload.toBuffer());
const actions = [];
actions.push(transactionAction);
const transaction = new fabprotos.protos.Transaction();
transaction.setActions(actions);
const payload = new fabprotos.common.Payload();
payload.setHeader(header);
payload.setData(transaction.toBuffer());
return payload;
}
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());
this._payload = this._action.payload.toBuffer();
return this._payload;
}
deliver.on('data', (response) => {
logger.debug('sendDeliver - on data'); // response: %j', response);
// check the type of the response
if (response.Type === 'block') {
const blockHeader = new fabprotos.common.BlockHeader();
blockHeader.setNumber(response.block.header.number);
blockHeader.setPreviousHash(response.block.header.previous_hash);
blockHeader.setDataHash(response.block.header.data_hash);
const blockData = new fabprotos.common.BlockData();
blockData.setData(response.block.data.data);
const blockMetadata = new fabprotos.common.BlockMetadata();
blockMetadata.setMetadata(response.block.metadata.metadata);
const block = new fabprotos.common.Block();
block.setHeader(blockHeader);
block.setData(blockData);
block.setMetadata(blockMetadata);
return_block = block;
logger.debug('sendDeliver - wait for success, keep this block number %s', return_block.header.number);
} else if (response.Type === 'status') {
module.exports.buildChannelHeader = (type, channel_id, tx_id, epoch, chaincode_id, time_stamp, client_cert_hash) => {
logger.debug(
'buildChannelHeader - type %s channel_id %s tx_id %d epoch %s chaincode_id %s',
type, channel_id, tx_id, epoch, chaincode_id);
const channelHeader = new fabprotos.common.ChannelHeader();
channelHeader.setType(type); // int32
channelHeader.setVersion(1); // int32
if (!time_stamp) {
time_stamp = module.exports.buildCurrentTimestamp();
}
channelHeader.setChannelId(channel_id); // string
channelHeader.setTxId(tx_id.toString()); // string
if (epoch) {
channelHeader.setEpoch(epoch); // uint64
}
if (chaincode_id) {
const chaincodeID = new fabprotos.protos.ChaincodeID();
chaincodeID.setName(chaincode_id);
const headerExt = new fabprotos.protos.ChaincodeHeaderExtension();
headerExt.setChaincodeId(chaincodeID);
static buildPolicy(msps, policy, returnProto) {
const principals = [];
const envelope = new fabprotos.common.SignaturePolicyEnvelope();
if (!policy) {
// no policy was passed in, construct a 'Signed By any member of an organization by mspid' policy
// construct a list of msp principals to select from using the 'n out of' operator
const signedBys = [];
let index = 0;
for (const name in msps) {
if (Object.prototype.hasOwnProperty.call(msps, name)) {
const onePrn = new fabprotos.common.MSPPrincipal();
onePrn.setPrincipalClassification(fabprotos.common.MSPPrincipal.Classification.ROLE);
const memberRole = new fabprotos.common.MSPRole();
memberRole.setRole(fabprotos.common.MSPRole.MSPRoleType.MEMBER);
memberRole.setMspIdentifier(name);
onePrn.setPrincipal(memberRole.toBuffer());
function decodeMSPPrincipal(proto_msp_principal) {
let msp_principal = {};
msp_principal.principal_classification = proto_msp_principal.getPrincipalClassification();
let proto_principal = null;
switch (msp_principal.principal_classification) {
case fabprotos.common.MSPPrincipal.Classification.ROLE:
proto_principal = fabprotos.common.MSPRole.decode(proto_msp_principal.getPrincipal());
msp_principal.msp_identifier = proto_principal.getMspIdentifier();
if (proto_principal.getRole() === 0) {
msp_principal.Role = 'MEMBER';
} else if (proto_principal.getRole() === 1) {
msp_principal.Role = 'ADMIN';
}
break;
case fabprotos.common.MSPPrincipal.Classification.ORGANIZATION_UNIT:
proto_principal = fabprotos.common.OrganizationUnit.decode(proto_msp_principal.getPrincipal());
msp_principal.msp_identifier = proto_principal.getMspIdentifier(); // string
msp_principal.organizational_unit_identifier = proto_principal.getOrganizationalUnitIdentifier(); // string
msp_principal.certifiers_identifier = proto_principal.getCertifiersIdentifier().toBuffer(); // bytes
break;
case fabprotos.common.MSPPrincipal.Classification.IDENTITY:
msp_principal = decodeIdentity(proto_msp_principal.getPrincipal());
break;
}
return msp_principal;
}
function decodeBlockDataEnvelope(proto_envelope) {
const envelope = {};
envelope.signature = proto_envelope.getSignature().toBuffer(); // leave as bytes
envelope.payload = {};
const proto_payload = fabprotos.common.Payload.decode(proto_envelope.getPayload().toBuffer());
envelope.payload.header = decodeHeader(proto_payload.getHeader());
envelope.payload.data = HeaderType.decodePayloadBasedOnType(proto_payload.getData().toBuffer(), envelope.payload.header.channel_header.type);
// let's also have the type as the enum string value so it is easier to read
envelope.payload.header.channel_header.typeString = HeaderType.convertToString(envelope.payload.header.channel_header.type);
return envelope;
}
const input = new fabprotos.protos.ChaincodeInput();
input.setArgs(args);
if (request.is_init) {
input.setIsInit(true);
}
chaincodeSpec.setInput(input);
let signer = null;
if (request.signer) {
signer = request.signer;
} else {
signer = client_context._getSigningIdentity(request.txId.isAdmin());
}
const channelHeader = module.exports.buildChannelHeader(
fabprotos.common.HeaderType.ENDORSER_TRANSACTION,
channelId,
request.txId.getTransactionID(),
null,
request.chaincodeId,
module.exports.buildCurrentTimestamp(),
client_context.getClientCertHash()
);
const header = module.exports.buildHeader(signer, channelHeader, request.txId.getNonce());
const proposal = module.exports.buildProposal(chaincodeSpec, header, request.transientMap);
const signed_proposal = module.exports.signProposal(signer, proposal);
return {signed: signed_proposal, source: proposal};
};
logger.debug(`${method} - no tx listeners`);
return;
}
if (filtered_block) {
logger.debug(`${method} filtered block number=${filtered_block.number}`);
if (filtered_block.filtered_transactions) {
for (const filtered_transaction of filtered_block.filtered_transactions) {
this._callTransactionListener(filtered_transaction.txid,
filtered_transaction.tx_validation_code,
filtered_block.number);
}
}
} else {
logger.debug(`${method} full block number=${full_block.header.number}`);
const txStatusCodes = full_block.metadata.metadata[fabprotos.common.BlockMetadataIndex.TRANSACTIONS_FILTER];
for (let index = 0; index < full_block.data.data.length; index++) {
const channel_header = full_block.data.data[index].payload.header.channel_header;
this._callTransactionListener(channel_header.tx_id,
txStatusCodes[index],
full_block.header.number);
}
}
}
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';
/**
* Eventer is used to monitor for new blocks on a peer's ledger.
* The class supports the connection to the service to the Peer's event service.
* @class
* @extends ServiceEndpoint
*/
class Eventer extends ServiceEndpoint {