mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
Merge "FAB-13372 Fabric-Samples return error msg"
This commit is contained in:
commit
39e8ec4a8a
8 changed files with 184 additions and 139 deletions
|
|
@ -45,19 +45,32 @@ var createChannel = async function(channelName, channelConfigPath, username, org
|
||||||
};
|
};
|
||||||
|
|
||||||
// send to orderer
|
// send to orderer
|
||||||
var response = await client.createChannel(request)
|
const result = await client.createChannel(request)
|
||||||
logger.debug(' response ::%j', response);
|
logger.debug(' result ::%j', result);
|
||||||
if (response && response.status === 'SUCCESS') {
|
if (result) {
|
||||||
logger.debug('Successfully created the channel.');
|
if (result.status === 'SUCCESS') {
|
||||||
let response = {
|
logger.debug('Successfully created the channel.');
|
||||||
success: true,
|
const response = {
|
||||||
message: 'Channel \'' + channelName + '\' created Successfully'
|
success: true,
|
||||||
};
|
message: 'Channel \'' + channelName + '\' created Successfully'
|
||||||
return response;
|
};
|
||||||
|
return response;
|
||||||
|
} else {
|
||||||
|
logger.error('Failed to create the channel. status:' + result.status + ' reason:' + result.info);
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: 'Channel \'' + channelName + '\' failed to create status:' + result.status + ' reason:' + result.info
|
||||||
|
};
|
||||||
|
return response;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.error('\n!!!!!!!!! Failed to create the channel \'' + channelName +
|
logger.error('\n!!!!!!!!! Failed to create the channel \'' + channelName +
|
||||||
'\' !!!!!!!!!\n\n');
|
'\' !!!!!!!!!\n\n');
|
||||||
throw new Error('Failed to create the channel \'' + channelName + '\'');
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: 'Failed to create the channel \'' + channelName + '\'',
|
||||||
|
};
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('Failed to initialize the channel: ' + err.stack ? err.stack : err);
|
logger.error('Failed to initialize the channel: ' + err.stack ? err.stack : err);
|
||||||
|
|
|
||||||
|
|
@ -47,23 +47,17 @@ var installChaincode = async function(peers, chaincodeName, chaincodePath,
|
||||||
// lets have a look at the responses to see if they are
|
// lets have a look at the responses to see if they are
|
||||||
// all good, if good they will also include signatures
|
// all good, if good they will also include signatures
|
||||||
// required to be committed
|
// required to be committed
|
||||||
var all_good = true;
|
for (const i in proposalResponses) {
|
||||||
for (var i in proposalResponses) {
|
if (proposalResponses[i] instanceof Error) {
|
||||||
let one_good = false;
|
error_message = util.format('install proposal resulted in an error :: %s', proposalResponses[i].toString());
|
||||||
if (proposalResponses && proposalResponses[i].response &&
|
logger.error(error_message);
|
||||||
proposalResponses[i].response.status === 200) {
|
} else if (proposalResponses[i].response && proposalResponses[i].response.status === 200) {
|
||||||
one_good = true;
|
|
||||||
logger.info('install proposal was good');
|
logger.info('install proposal was good');
|
||||||
} else {
|
} else {
|
||||||
logger.error('install proposal was bad %j',proposalResponses.toJSON());
|
all_good = false;
|
||||||
|
error_message = util.format('install proposal was bad for an unknown reason %j', proposalResponses[i]);
|
||||||
|
logger.error(error_message);
|
||||||
}
|
}
|
||||||
all_good = all_good & one_good;
|
|
||||||
}
|
|
||||||
if (all_good) {
|
|
||||||
logger.info('Successfully sent install Proposal and received ProposalResponse');
|
|
||||||
} else {
|
|
||||||
error_message = 'Failed to send install Proposal or receive valid response. Response null or status is not 200'
|
|
||||||
logger.error(error_message);
|
|
||||||
}
|
}
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
logger.error('Failed to install due to error: ' + error.stack ? error.stack : error);
|
logger.error('Failed to install due to error: ' + error.stack ? error.stack : error);
|
||||||
|
|
@ -74,7 +68,7 @@ var installChaincode = async function(peers, chaincodeName, chaincodePath,
|
||||||
let message = util.format('Successfully installed chaincode');
|
let message = util.format('Successfully installed chaincode');
|
||||||
logger.info(message);
|
logger.info(message);
|
||||||
// build a response to send back to the REST caller
|
// build a response to send back to the REST caller
|
||||||
let response = {
|
const response = {
|
||||||
success: true,
|
success: true,
|
||||||
message: message
|
message: message
|
||||||
};
|
};
|
||||||
|
|
@ -82,7 +76,11 @@ var installChaincode = async function(peers, chaincodeName, chaincodePath,
|
||||||
} else {
|
} else {
|
||||||
let message = util.format('Failed to install due to:%s',error_message);
|
let message = util.format('Failed to install due to:%s',error_message);
|
||||||
logger.error(message);
|
logger.error(message);
|
||||||
throw new Error(message);
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: message
|
||||||
|
};
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
exports.installChaincode = installChaincode;
|
exports.installChaincode = installChaincode;
|
||||||
|
|
|
||||||
|
|
@ -14,34 +14,35 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
var util = require('util');
|
const util = require('util');
|
||||||
var helper = require('./helper.js');
|
const helper = require('./helper.js');
|
||||||
var logger = helper.getLogger('instantiate-chaincode');
|
const logger = helper.getLogger('instantiate-chaincode');
|
||||||
|
|
||||||
var instantiateChaincode = async function(peers, channelName, chaincodeName, chaincodeVersion, functionName, chaincodeType, args, username, org_name) {
|
const instantiateChaincode = async function(peers, channelName, chaincodeName, chaincodeVersion, functionName, chaincodeType, args, username, org_name) {
|
||||||
logger.debug('\n\n============ Instantiate chaincode on channel ' + channelName +
|
logger.debug('\n\n============ Instantiate chaincode on channel ' + channelName +
|
||||||
' ============\n');
|
' ============\n');
|
||||||
var error_message = null;
|
let error_message = null;
|
||||||
|
let client = null;
|
||||||
|
let channel = null;
|
||||||
try {
|
try {
|
||||||
// first setup the client for this org
|
// first setup the client for this org
|
||||||
var client = await helper.getClientForOrg(org_name, username);
|
client = await helper.getClientForOrg(org_name, username);
|
||||||
logger.debug('Successfully got the fabric client for the organization "%s"', org_name);
|
logger.debug('Successfully got the fabric client for the organization "%s"', org_name);
|
||||||
var channel = client.getChannel(channelName);
|
channel = client.getChannel(channelName);
|
||||||
if(!channel) {
|
if(!channel) {
|
||||||
let message = util.format('Channel %s was not defined in the connection profile', channelName);
|
let message = util.format('Channel %s was not defined in the connection profile', channelName);
|
||||||
logger.error(message);
|
logger.error(message);
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
var tx_id = client.newTransactionID(true); // Get an admin based transactionID
|
const tx_id = client.newTransactionID(true); // Get an admin based transactionID
|
||||||
// An admin based transactionID will
|
// An admin based transactionID will
|
||||||
// indicate that admin identity should
|
// indicate that admin identity should
|
||||||
// be used to sign the proposal request.
|
// be used to sign the proposal request.
|
||||||
// will need the transaction ID string for the event registration later
|
// will need the transaction ID string for the event registration later
|
||||||
var deployId = tx_id.getTransactionID();
|
const deployId = tx_id.getTransactionID();
|
||||||
|
|
||||||
// send proposal to endorser
|
// send proposal to endorser
|
||||||
var request = {
|
const request = {
|
||||||
targets : peers,
|
targets : peers,
|
||||||
chaincodeId: chaincodeName,
|
chaincodeId: chaincodeName,
|
||||||
chaincodeType: chaincodeType,
|
chaincodeType: chaincodeType,
|
||||||
|
|
@ -70,23 +71,24 @@ var instantiateChaincode = async function(peers, channelName, chaincodeName, cha
|
||||||
// the returned object has both the endorsement results
|
// the returned object has both the endorsement results
|
||||||
// and the actual proposal, the proposal will be needed
|
// and the actual proposal, the proposal will be needed
|
||||||
// later when we send a transaction to the orderer
|
// later when we send a transaction to the orderer
|
||||||
var proposalResponses = results[0];
|
const proposalResponses = results[0];
|
||||||
var proposal = results[1];
|
const proposal = results[1];
|
||||||
|
|
||||||
// lets have a look at the responses to see if they are
|
// look at the responses to see if they are all are good
|
||||||
// all good, if good they will also include signatures
|
// response will also include signatures required to be committed
|
||||||
// required to be committed
|
let all_good = true;
|
||||||
var all_good = true;
|
for (const i in proposalResponses) {
|
||||||
for (var i in proposalResponses) {
|
if (proposalResponses[i] instanceof Error) {
|
||||||
let one_good = false;
|
all_good = false;
|
||||||
if (proposalResponses && proposalResponses[i].response &&
|
error_message = util.format('instantiate proposal resulted in an error :: %s', proposalResponses[i].toString());
|
||||||
proposalResponses[i].response.status === 200) {
|
logger.error(error_message);
|
||||||
one_good = true;
|
} else if (proposalResponses[i].response && proposalResponses[i].response.status === 200) {
|
||||||
logger.info('instantiate proposal was good');
|
logger.info('instantiate proposal was good');
|
||||||
} else {
|
} else {
|
||||||
logger.error('instantiate proposal was bad');
|
all_good = false;
|
||||||
|
error_message = util.format('instantiate proposal was bad for an unknown reason %j', proposalResponses[i]);
|
||||||
|
logger.error(error_message);
|
||||||
}
|
}
|
||||||
all_good = all_good & one_good;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (all_good) {
|
if (all_good) {
|
||||||
|
|
@ -97,8 +99,8 @@ var instantiateChaincode = async function(peers, channelName, chaincodeName, cha
|
||||||
|
|
||||||
// wait for the channel-based event hub to tell us that the
|
// wait for the channel-based event hub to tell us that the
|
||||||
// instantiate transaction was committed on the peer
|
// instantiate transaction was committed on the peer
|
||||||
var promises = [];
|
const promises = [];
|
||||||
let event_hubs = channel.getChannelEventHubsForOrg();
|
const event_hubs = channel.getChannelEventHubsForOrg();
|
||||||
logger.debug('found %s eventhubs for this organization %s',event_hubs.length, org_name);
|
logger.debug('found %s eventhubs for this organization %s',event_hubs.length, org_name);
|
||||||
event_hubs.forEach((eh) => {
|
event_hubs.forEach((eh) => {
|
||||||
let instantiateEventPromise = new Promise((resolve, reject) => {
|
let instantiateEventPromise = new Promise((resolve, reject) => {
|
||||||
|
|
@ -138,22 +140,22 @@ var instantiateChaincode = async function(peers, channelName, chaincodeName, cha
|
||||||
promises.push(instantiateEventPromise);
|
promises.push(instantiateEventPromise);
|
||||||
});
|
});
|
||||||
|
|
||||||
var orderer_request = {
|
const orderer_request = {
|
||||||
txId: tx_id, // must include the transaction id so that the outbound
|
txId: tx_id, // must include the transaction id so that the outbound
|
||||||
// transaction to the orderer will be signed by the admin
|
// transaction to the orderer will be signed by the admin id
|
||||||
// id as was the proposal above, notice that transactionID
|
// the same as the proposal above, notice that transactionID
|
||||||
// generated above was based on the admin id not the current
|
// generated above was based on the admin id not the current
|
||||||
// user assigned to the 'client' instance.
|
// user assigned to the 'client' instance.
|
||||||
proposalResponses: proposalResponses,
|
proposalResponses: proposalResponses,
|
||||||
proposal: proposal
|
proposal: proposal
|
||||||
};
|
};
|
||||||
var sendPromise = channel.sendTransaction(orderer_request);
|
const sendPromise = channel.sendTransaction(orderer_request);
|
||||||
// put the send to the orderer last so that the events get registered and
|
// put the send to the orderer last so that the events get registered and
|
||||||
// are ready for the orderering and committing
|
// are ready for the orderering and committing
|
||||||
promises.push(sendPromise);
|
promises.push(sendPromise);
|
||||||
let results = await Promise.all(promises);
|
const results = await Promise.all(promises);
|
||||||
logger.debug(util.format('------->>> R E S P O N S E : %j', results));
|
logger.debug(util.format('------->>> R E S P O N S E : %j', results));
|
||||||
let response = results.pop(); // orderer results are last in the results
|
const response = results.pop(); // orderer results are last in the results
|
||||||
if (response.status === 'SUCCESS') {
|
if (response.status === 'SUCCESS') {
|
||||||
logger.info('Successfully sent transaction to the orderer.');
|
logger.info('Successfully sent transaction to the orderer.');
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -162,9 +164,9 @@ var instantiateChaincode = async function(peers, channelName, chaincodeName, cha
|
||||||
}
|
}
|
||||||
|
|
||||||
// now see what each of the event hubs reported
|
// now see what each of the event hubs reported
|
||||||
for(let i in results) {
|
for(const i in results) {
|
||||||
let event_hub_result = results[i];
|
const event_hub_result = results[i];
|
||||||
let event_hub = event_hubs[i];
|
const event_hub = event_hubs[i];
|
||||||
logger.debug('Event results for event hub :%s',event_hub.getPeerAddr());
|
logger.debug('Event results for event hub :%s',event_hub.getPeerAddr());
|
||||||
if(typeof event_hub_result === 'string') {
|
if(typeof event_hub_result === 'string') {
|
||||||
logger.debug(event_hub_result);
|
logger.debug(event_hub_result);
|
||||||
|
|
@ -173,30 +175,31 @@ var instantiateChaincode = async function(peers, channelName, chaincodeName, cha
|
||||||
logger.debug(event_hub_result.toString());
|
logger.debug(event_hub_result.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
error_message = util.format('Failed to send Proposal and receive all good ProposalResponse');
|
|
||||||
logger.debug(error_message);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to send instantiate due to error: ' + error.stack ? error.stack : error);
|
logger.error('Failed to send instantiate due to error: ' + error.stack ? error.stack : error);
|
||||||
error_message = error.toString();
|
error_message = error.toString();
|
||||||
|
} finally {
|
||||||
|
if (channel) {
|
||||||
|
channel.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!error_message) {
|
let success = true;
|
||||||
let message = util.format(
|
let message = util.format('Successfully instantiate chaincode in organization %s to the channel \'%s\'', org_name, channelName);
|
||||||
'Successfully instantiate chaincode in organization %s to the channel \'%s\'',
|
if (error_message) {
|
||||||
org_name, channelName);
|
message = util.format('Failed to instantiate the chaincode. cause:%s',error_message);
|
||||||
logger.info(message);
|
success = false;
|
||||||
// build a response to send back to the REST caller
|
|
||||||
let response = {
|
|
||||||
success: true,
|
|
||||||
message: message
|
|
||||||
};
|
|
||||||
return response;
|
|
||||||
} else {
|
|
||||||
let message = util.format('Failed to instantiate. cause:%s',error_message);
|
|
||||||
logger.error(message);
|
logger.error(message);
|
||||||
throw new Error(message);
|
} else {
|
||||||
|
logger.info(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// build a response to send back to the REST caller
|
||||||
|
const response = {
|
||||||
|
success: success,
|
||||||
|
message: message
|
||||||
|
};
|
||||||
|
return response;
|
||||||
};
|
};
|
||||||
exports.instantiateChaincode = instantiateChaincode;
|
exports.instantiateChaincode = instantiateChaincode;
|
||||||
|
|
|
||||||
|
|
@ -14,30 +14,32 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
var util = require('util');
|
const util = require('util');
|
||||||
var helper = require('./helper.js');
|
const helper = require('./helper.js');
|
||||||
var logger = helper.getLogger('invoke-chaincode');
|
const logger = helper.getLogger('invoke-chaincode');
|
||||||
|
|
||||||
var invokeChaincode = async function(peerNames, channelName, chaincodeName, fcn, args, username, org_name) {
|
const invokeChaincode = async function(peerNames, channelName, chaincodeName, fcn, args, username, org_name) {
|
||||||
logger.debug(util.format('\n============ invoke transaction on channel %s ============\n', channelName));
|
logger.debug(util.format('\n============ invoke transaction on channel %s ============\n', channelName));
|
||||||
var error_message = null;
|
let error_message = null;
|
||||||
var tx_id_string = null;
|
let tx_id_string = null;
|
||||||
|
let client = null;
|
||||||
|
let channel = null;
|
||||||
try {
|
try {
|
||||||
// first setup the client for this org
|
// first setup the client for this org
|
||||||
var client = await helper.getClientForOrg(org_name, username);
|
client = await helper.getClientForOrg(org_name, username);
|
||||||
logger.debug('Successfully got the fabric client for the organization "%s"', org_name);
|
logger.debug('Successfully got the fabric client for the organization "%s"', org_name);
|
||||||
var channel = client.getChannel(channelName);
|
channel = client.getChannel(channelName);
|
||||||
if(!channel) {
|
if(!channel) {
|
||||||
let message = util.format('Channel %s was not defined in the connection profile', channelName);
|
let message = util.format('Channel %s was not defined in the connection profile', channelName);
|
||||||
logger.error(message);
|
logger.error(message);
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
var tx_id = client.newTransactionID();
|
const tx_id = client.newTransactionID();
|
||||||
// will need the transaction ID string for the event registration later
|
// will need the transaction ID string for the event registration later
|
||||||
tx_id_string = tx_id.getTransactionID();
|
tx_id_string = tx_id.getTransactionID();
|
||||||
|
|
||||||
// send proposal to endorser
|
// send proposal to endorser
|
||||||
var request = {
|
const request = {
|
||||||
targets: peerNames,
|
targets: peerNames,
|
||||||
chaincodeId: chaincodeName,
|
chaincodeId: chaincodeName,
|
||||||
fcn: fcn,
|
fcn: fcn,
|
||||||
|
|
@ -51,23 +53,24 @@ var invokeChaincode = async function(peerNames, channelName, chaincodeName, fcn,
|
||||||
// the returned object has both the endorsement results
|
// the returned object has both the endorsement results
|
||||||
// and the actual proposal, the proposal will be needed
|
// and the actual proposal, the proposal will be needed
|
||||||
// later when we send a transaction to the orderer
|
// later when we send a transaction to the orderer
|
||||||
var proposalResponses = results[0];
|
const proposalResponses = results[0];
|
||||||
var proposal = results[1];
|
const proposal = results[1];
|
||||||
|
|
||||||
// lets have a look at the responses to see if they are
|
// look at the responses to see if they are all are good
|
||||||
// all good, if good they will also include signatures
|
// response will also include signatures required to be committed
|
||||||
// required to be committed
|
let all_good = true;
|
||||||
var all_good = true;
|
for (const i in proposalResponses) {
|
||||||
for (var i in proposalResponses) {
|
if (proposalResponses[i] instanceof Error) {
|
||||||
let one_good = false;
|
all_good = false;
|
||||||
if (proposalResponses && proposalResponses[i].response &&
|
error_message = util.format('invoke chaincode proposal resulted in an error :: %s', proposalResponses[i].toString());
|
||||||
proposalResponses[i].response.status === 200) {
|
logger.error(error_message);
|
||||||
one_good = true;
|
} else if (proposalResponses[i].response && proposalResponses[i].response.status === 200) {
|
||||||
logger.info('invoke chaincode proposal was good');
|
logger.info('invoke chaincode proposal was good');
|
||||||
} else {
|
} else {
|
||||||
logger.error('invoke chaincode proposal was bad');
|
all_good = false;
|
||||||
|
error_message = util.format('invoke chaincode proposal failed for an unknown reason %j', proposalResponses[i]);
|
||||||
|
logger.error(error_message);
|
||||||
}
|
}
|
||||||
all_good = all_good & one_good;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (all_good) {
|
if (all_good) {
|
||||||
|
|
@ -78,7 +81,7 @@ var invokeChaincode = async function(peerNames, channelName, chaincodeName, fcn,
|
||||||
|
|
||||||
// wait for the channel-based event hub to tell us
|
// wait for the channel-based event hub to tell us
|
||||||
// that the commit was good or bad on each peer in our organization
|
// that the commit was good or bad on each peer in our organization
|
||||||
var promises = [];
|
const promises = [];
|
||||||
let event_hubs = channel.getChannelEventHubsForOrg();
|
let event_hubs = channel.getChannelEventHubsForOrg();
|
||||||
event_hubs.forEach((eh) => {
|
event_hubs.forEach((eh) => {
|
||||||
logger.debug('invokeEventPromise - setting up event');
|
logger.debug('invokeEventPromise - setting up event');
|
||||||
|
|
@ -118,12 +121,12 @@ var invokeChaincode = async function(peerNames, channelName, chaincodeName, fcn,
|
||||||
promises.push(invokeEventPromise);
|
promises.push(invokeEventPromise);
|
||||||
});
|
});
|
||||||
|
|
||||||
var orderer_request = {
|
const orderer_request = {
|
||||||
txId: tx_id,
|
txId: tx_id,
|
||||||
proposalResponses: proposalResponses,
|
proposalResponses: proposalResponses,
|
||||||
proposal: proposal
|
proposal: proposal
|
||||||
};
|
};
|
||||||
var sendPromise = channel.sendTransaction(orderer_request);
|
const sendPromise = channel.sendTransaction(orderer_request);
|
||||||
// put the send to the orderer last so that the events get registered and
|
// put the send to the orderer last so that the events get registered and
|
||||||
// are ready for the orderering and committing
|
// are ready for the orderering and committing
|
||||||
promises.push(sendPromise);
|
promises.push(sendPromise);
|
||||||
|
|
@ -149,27 +152,34 @@ var invokeChaincode = async function(peerNames, channelName, chaincodeName, fcn,
|
||||||
logger.debug(event_hub_result.toString());
|
logger.debug(event_hub_result.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
error_message = util.format('Failed to send Proposal and receive all good ProposalResponse');
|
|
||||||
logger.debug(error_message);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Failed to invoke due to error: ' + error.stack ? error.stack : error);
|
logger.error('Failed to invoke due to error: ' + error.stack ? error.stack : error);
|
||||||
error_message = error.toString();
|
error_message = error.toString();
|
||||||
|
} finally {
|
||||||
|
if (channel) {
|
||||||
|
channel.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!error_message) {
|
let success = true;
|
||||||
let message = util.format(
|
let message = util.format(
|
||||||
'Successfully invoked the chaincode %s to the channel \'%s\' for transaction ID: %s',
|
'Successfully invoked the chaincode %s to the channel \'%s\' for transaction ID: %s',
|
||||||
org_name, channelName, tx_id_string);
|
org_name, channelName, tx_id_string);
|
||||||
logger.info(message);
|
if (error_message) {
|
||||||
|
message = util.format('Failed to invoke chaincode. cause:%s',error_message);
|
||||||
return tx_id_string;
|
success = false;
|
||||||
} else {
|
|
||||||
let message = util.format('Failed to invoke chaincode. cause:%s',error_message);
|
|
||||||
logger.error(message);
|
logger.error(message);
|
||||||
throw new Error(message);
|
} else {
|
||||||
|
logger.info(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// build a response to send back to the REST caller
|
||||||
|
const response = {
|
||||||
|
success: success,
|
||||||
|
message: message
|
||||||
|
};
|
||||||
|
return response;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.invokeChaincode = invokeChaincode;
|
exports.invokeChaincode = invokeChaincode;
|
||||||
|
|
|
||||||
|
|
@ -66,12 +66,14 @@ var joinChannel = async function(channel_name, peers, username, org_name) {
|
||||||
// then each peer results
|
// then each peer results
|
||||||
for(let i in peers_results) {
|
for(let i in peers_results) {
|
||||||
let peer_result = peers_results[i];
|
let peer_result = peers_results[i];
|
||||||
if(peer_result.response && peer_result.response.status == 200) {
|
if (peer_result instanceof Error) {
|
||||||
|
error_message = util.format('Failed to join peer to the channel with error :: %s', peer_result.toString());
|
||||||
|
logger.error(error_message);
|
||||||
|
} else if(peer_result.response && peer_result.response.status == 200) {
|
||||||
logger.info('Successfully joined peer to the channel %s',channel_name);
|
logger.info('Successfully joined peer to the channel %s',channel_name);
|
||||||
} else {
|
} else {
|
||||||
let message = util.format('Failed to join peer to the channel %s',channel_name);
|
error_message = util.format('Failed to join peer to the channel %s',channel_name);
|
||||||
error_message = message;
|
logger.error(error_message);
|
||||||
logger.error(message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
|
|
@ -90,7 +92,7 @@ var joinChannel = async function(channel_name, peers, username, org_name) {
|
||||||
org_name, channel_name);
|
org_name, channel_name);
|
||||||
logger.info(message);
|
logger.info(message);
|
||||||
// build a response to send back to the REST caller
|
// build a response to send back to the REST caller
|
||||||
let response = {
|
const response = {
|
||||||
success: true,
|
success: true,
|
||||||
message: message
|
message: message
|
||||||
};
|
};
|
||||||
|
|
@ -98,7 +100,12 @@ var joinChannel = async function(channel_name, peers, username, org_name) {
|
||||||
} else {
|
} else {
|
||||||
let message = util.format('Failed to join all peers to channel. cause:%s',error_message);
|
let message = util.format('Failed to join all peers to channel. cause:%s',error_message);
|
||||||
logger.error(message);
|
logger.error(message);
|
||||||
throw new Error(message);
|
// build a response to send back to the REST caller
|
||||||
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: message
|
||||||
|
};
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
exports.joinChannel = joinChannel;
|
exports.joinChannel = joinChannel;
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,13 @@ var helper = require('./helper.js');
|
||||||
var logger = helper.getLogger('Query');
|
var logger = helper.getLogger('Query');
|
||||||
|
|
||||||
var queryChaincode = async function(peer, channelName, chaincodeName, args, fcn, username, org_name) {
|
var queryChaincode = async function(peer, channelName, chaincodeName, args, fcn, username, org_name) {
|
||||||
|
let client = null;
|
||||||
|
let channel = null;
|
||||||
try {
|
try {
|
||||||
// first setup the client for this org
|
// first setup the client for this org
|
||||||
var client = await helper.getClientForOrg(org_name, username);
|
client = await helper.getClientForOrg(org_name, username);
|
||||||
logger.debug('Successfully got the fabric client for the organization "%s"', org_name);
|
logger.debug('Successfully got the fabric client for the organization "%s"', org_name);
|
||||||
var channel = client.getChannel(channelName);
|
channel = client.getChannel(channelName);
|
||||||
if(!channel) {
|
if(!channel) {
|
||||||
let message = util.format('Channel %s was not defined in the connection profile', channelName);
|
let message = util.format('Channel %s was not defined in the connection profile', channelName);
|
||||||
logger.error(message);
|
logger.error(message);
|
||||||
|
|
@ -51,6 +53,10 @@ var queryChaincode = async function(peer, channelName, chaincodeName, args, fcn,
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
logger.error('Failed to query due to error: ' + error.stack ? error.stack : error);
|
logger.error('Failed to query due to error: ' + error.stack ? error.stack : error);
|
||||||
return error.toString();
|
return error.toString();
|
||||||
|
} finally {
|
||||||
|
if (channel) {
|
||||||
|
channel.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var getBlockByNumber = async function(peer, channelName, blockNumber, username, org_name) {
|
var getBlockByNumber = async function(peer, channelName, blockNumber, username, org_name) {
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ var updateAnchorPeers = async function(channelName, configUpdatePath, username,
|
||||||
event_hubs.forEach((eh) => {
|
event_hubs.forEach((eh) => {
|
||||||
let anchorUpdateEventPromise = new Promise((resolve, reject) => {
|
let anchorUpdateEventPromise = new Promise((resolve, reject) => {
|
||||||
logger.debug('anchorUpdateEventPromise - setting up event');
|
logger.debug('anchorUpdateEventPromise - setting up event');
|
||||||
let event_timeout = setTimeout(() => {
|
const event_timeout = setTimeout(() => {
|
||||||
let message = 'REQUEST_TIMEOUT:' + eh.getPeerAddr();
|
let message = 'REQUEST_TIMEOUT:' + eh.getPeerAddr();
|
||||||
logger.error(message);
|
logger.error(message);
|
||||||
eh.disconnect();
|
eh.disconnect();
|
||||||
|
|
@ -83,8 +83,13 @@ var updateAnchorPeers = async function(channelName, configUpdatePath, username,
|
||||||
logger.debug(util.format('------->>> R E S P O N S E : %j', results));
|
logger.debug(util.format('------->>> R E S P O N S E : %j', results));
|
||||||
let response = results.pop(); // orderer results are last in the results
|
let response = results.pop(); // orderer results are last in the results
|
||||||
|
|
||||||
if (response && response.status === 'SUCCESS') {
|
if (response) {
|
||||||
logger.info('Successfully update anchor peers to the channel %s', channelName);
|
if (response.status === 'SUCCESS') {
|
||||||
|
logger.info('Successfully update anchor peers to the channel %s', channelName);
|
||||||
|
} else {
|
||||||
|
error_message = util.format('Failed to update anchor peers to the channel %s with status: %s reason: %s', channelName, response.status, response.info);
|
||||||
|
logger.error(error_message);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
error_message = util.format('Failed to update anchor peers to the channel %s', channelName);
|
error_message = util.format('Failed to update anchor peers to the channel %s', channelName);
|
||||||
logger.error(error_message);
|
logger.error(error_message);
|
||||||
|
|
@ -99,7 +104,7 @@ var updateAnchorPeers = async function(channelName, configUpdatePath, username,
|
||||||
'Successfully update anchor peers in organization %s to the channel \'%s\'',
|
'Successfully update anchor peers in organization %s to the channel \'%s\'',
|
||||||
org_name, channelName);
|
org_name, channelName);
|
||||||
logger.info(message);
|
logger.info(message);
|
||||||
let response = {
|
const response = {
|
||||||
success: true,
|
success: true,
|
||||||
message: message
|
message: message
|
||||||
};
|
};
|
||||||
|
|
@ -107,7 +112,11 @@ var updateAnchorPeers = async function(channelName, configUpdatePath, username,
|
||||||
} else {
|
} else {
|
||||||
let message = util.format('Failed to update anchor peers. cause:%s',error_message);
|
let message = util.format('Failed to update anchor peers. cause:%s',error_message);
|
||||||
logger.error(message);
|
logger.error(message);
|
||||||
throw new Error(message);
|
const response = {
|
||||||
|
success: false,
|
||||||
|
message: message
|
||||||
|
};
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -185,16 +185,15 @@ echo
|
||||||
|
|
||||||
echo "POST invoke chaincode on peers of Org1 and Org2"
|
echo "POST invoke chaincode on peers of Org1 and Org2"
|
||||||
echo
|
echo
|
||||||
TRX_ID=$(curl -s -X POST \
|
curl -s -X POST \
|
||||||
http://localhost:4000/channels/mychannel/chaincodes/mycc \
|
http://localhost:4000/channels/mychannel/chaincodes/mycc \
|
||||||
-H "authorization: Bearer $ORG1_TOKEN" \
|
-H "authorization: Bearer $ORG1_TOKEN" \
|
||||||
-H "content-type: application/json" \
|
-H "content-type: application/json" \
|
||||||
-d '{
|
-d "{
|
||||||
"peers": ["peer0.org1.example.com","peer0.org2.example.com"],
|
\"peers\": [\"peer0.org1.example.com\",\"peer0.org2.example.com\"],
|
||||||
"fcn":"move",
|
\"fcn\":\"move\",
|
||||||
"args":["a","b","10"]
|
\"args\":[\"a\",\"b\",\"10\"]
|
||||||
}')
|
}"
|
||||||
echo "Transaction ID is $TRX_ID"
|
|
||||||
echo
|
echo
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue