Skip to content

Commit

Permalink
get maual scripts to work with connection profile
Browse files Browse the repository at this point in the history
  • Loading branch information
dshuffma-ibm committed Sep 21, 2017
1 parent 847a2f1 commit 6a93d86
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ app_state*
/utils/fc_wrangler/kvs
/config/blockchain_creds_dev.json
/config/marbles_dev.json
/config/crypto/hsbn
28 changes: 18 additions & 10 deletions scripts/install_chaincode.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
var winston = require('winston'); //logger module
var path = require('path');

// --- Set Our Things --- //
var logger = new (winston.Logger)({
level: 'debug',
transports: [
new (winston.transports.Console)({ colorize: true }),
]
});

// --- Set Details Here --- //
var config_file = 'marbles_local.json'; //set config file name
var chaincode_id = 'marbles01'; //set desired chaincode id to identify this chaincode
var chaincode_ver = 'v4'; //set desired chaincode version

// --- Use (optional) arguments if passed in --- //
var args = process.argv.slice(2);
var config_file = 'marbles_local.json';
if (args[0]) {
config_file = args[0];
logger.info('Config file passed in as argument');
logger.info('Using custom config file', config_file);
} else {
logger.info('Using default config file', config_file);
logger.debug('Using argument for config file', config_file);
}
if (args[1]) {
chaincode_id = args[1];
logger.debug('Using argument for chaincode id');
}
if (args[2]) {
chaincode_ver = args[2];
logger.debug('Using argument for chaincode version');
}

var helper = require(path.join(__dirname, '../utils/helper.js'))(config_file, logger); //set the config file name here
var fcw = require(path.join(__dirname, '../utils/fc_wrangler/index.js'))({ block_delay: helper.getBlockDelay() }, logger);

console.log('---------------------------------------');
logger.info('Lets install some chaincode -', helper.getChaincodeId(), helper.getChaincodeVersion());
logger.info('Lets install some chaincode -', chaincode_id, chaincode_ver);
console.log('---------------------------------------');

logger.info('First we enroll');
Expand All @@ -40,8 +48,8 @@ fcw.enrollWithAdminCert(helper.makeEnrollmentOptionsUsingCert(), function (enrol
var opts = {
peer_urls: [helper.getPeersUrl(first_peer)],
path_2_chaincode: 'marbles', //path to chaincode from <marbles root>/chaincode/src/
chaincode_id: helper.getChaincodeId(),
chaincode_version: helper.getChaincodeVersion(),
chaincode_id: chaincode_id,
chaincode_version: chaincode_ver,
peer_tls_opts: helper.getPeerTlsCertOpts(first_peer)
};
fcw.install_chaincode(enrollResp, opts, function (err, resp) {
Expand Down
28 changes: 18 additions & 10 deletions scripts/instantiate_chaincode.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
var winston = require('winston'); //logger module
var path = require('path');

// --- Set Our Things --- //
var logger = new (winston.Logger)({
level: 'debug',
transports: [
new (winston.transports.Console)({ colorize: true }),
]
});

// --- Set Details Here --- //
var config_file = 'marbles_local.json'; //set config file name
var chaincode_id = 'marbles01'; //use same ID during the INSTALL proposal
var chaincode_ver = 'v4'; //use same version during the INSTALL proposal

// --- Use (optional) arguments if passed in --- //
var args = process.argv.slice(2);
var config_file = 'marbles_local.json';
if (args[0]) {
config_file = args[0];
logger.info('Config file passed in as argument');
logger.info('Using custom config file', config_file);
} else {
logger.info('Using default config file', config_file);
logger.debug('Using argument for config file', config_file);
}
if (args[1]) {
chaincode_id = args[1];
logger.debug('Using argument for chaincode id');
}
if (args[2]) {
chaincode_ver = args[2];
logger.debug('Using argument for chaincode version');
}

var helper = require(path.join(__dirname, '../utils/helper.js'))(config_file, logger); //set the config file name here
var fcw = require(path.join(__dirname, '../utils/fc_wrangler/index.js'))({ block_delay: helper.getBlockDelay() }, logger);

console.log('---------------------------------------');
logger.info('Lets instantiate some chaincode -', helper.getChaincodeId(), helper.getChaincodeVersion());
logger.info('Lets instantiate some chaincode -', chaincode_id, chaincode_ver);
console.log('---------------------------------------');
logger.warn('Note: the chaincode should have been installed before running this script');

Expand All @@ -41,8 +49,8 @@ fcw.enrollWithAdminCert(helper.makeEnrollmentOptionsUsingCert(), function (enrol
var opts = {
peer_urls: [helper.getPeersUrl(first_peer)],
channel_id: helper.getChannelId(),
chaincode_id: helper.getChaincodeId(),
chaincode_version: helper.getChaincodeVersion(),
chaincode_id: chaincode_id,
chaincode_version: chaincode_ver,
cc_args: ['12345'],
peer_tls_opts: helper.getPeerTlsCertOpts(first_peer)
};
Expand Down
41 changes: 30 additions & 11 deletions scripts/upgrade_chaincode.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
var winston = require('winston'); //logger module
var path = require('path');

// --- Set Our Things --- //
var logger = new (winston.Logger)({
level: 'debug',
transports: [
new (winston.transports.Console)({ colorize: true }),
]
});
var helper = require(path.join(__dirname, '../utils/helper.js'))('marbles_local.json', logger); //set the config file name here

// --- Set Details Here --- //
var config_file = 'marbles_local.json'; //set config file name
var chaincode_id = 'marbles01'; //use same ID during the PREVIOUS instantiate proposal
var chaincode_ver = 'v5'; //use same version during the INSTALL proposal

// --- Use (optional) arguments if passed in --- //
var args = process.argv.slice(2);
if (args[0]) {
config_file = args[0];
logger.debug('Using argument for config file', config_file);
}
if (args[1]) {
chaincode_id = args[1];
logger.debug('Using argument for chaincode id');
}
if (args[2]) {
chaincode_ver = args[2];
logger.debug('Using argument for chaincode version');
}

var helper = require(path.join(__dirname, '../utils/helper.js'))(config_file, logger); //set the config file name here
var fcw = require(path.join(__dirname, '../utils/fc_wrangler/index.js'))({ block_delay: helper.getBlockDelay() }, logger);

console.log('---------------------------------------');
logger.info('Lets upgrade some chaincode -', helper.getChaincodeId(), helper.getChaincodeVersion());
logger.info('Lets upgrade some chaincode -', chaincode_id, chaincode_ver);
console.log('---------------------------------------');
logger.warn('Note: the chaincode "' + helper.getChaincodeId() + '" should have been installed AND instantiated before running this script');
let msg = `Note: the chaincode "` + helper.getChaincodeId() + `" and version "` + helper.getChaincodeVersion() + `
logger.warn('Note: the chaincode "' + chaincode_id + '" should have been installed AND instantiated before running this script');
let msg = `Note: the chaincode "` + chaincode_id + `" and version "` + chaincode_ver + `
should have been installed before running this script`;
logger.warn(msg);

Expand All @@ -32,11 +51,11 @@ fcw.enrollWithAdminCert(helper.makeEnrollmentOptionsUsingCert(), function (enrol
const first_peer = helper.getFirstPeerName(channel);
var opts = {
peer_urls: [helper.getPeersUrl(first_peer)],
path_2_chaincode: 'marbles', //same path used to install it
channel_id: helper.getChannelId(), //same ID used that was used in PREVIOUS instantiate
chaincode_id: helper.getChaincodeId(), //same ID used that was used in PREVIOUS instantiate
chaincode_version: helper.getChaincodeVersion(),
peer_tls_opts: helper.getPeerTlsCertOpts(first_peer)
channel_id: helper.getChannelId(),
chaincode_id: chaincode_id,
chaincode_version: chaincode_ver,
peer_tls_opts: helper.getPeerTlsCertOpts(first_peer),
cc_args: ['666666'],
};
fcw.upgrade_chaincode(enrollResp, opts, function (err, resp) {
console.log('---------------------------------------');
Expand Down
16 changes: 12 additions & 4 deletions utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,23 @@ module.exports = function (config_filename, logger) {
// get the chaincode id on network
helper.getChaincodeId = function () {
var channel = helper.getChannelId();
var chaincode = Object.keys(helper.creds.channels[channel].chaincodes);
return chaincode[0];
if (channel && helper.creds.channels[channel] && helper.creds.channels[channel].chaincodes) {
var chaincode = Object.keys(helper.creds.channels[channel].chaincodes);
return chaincode[0];
}
logger.warn('No chaincode ID found in credentials file... might be okay if we haven\'t instantiated marbles yet');
return null;
};

// get the chaincode version on network
helper.getChaincodeVersion = function () {
var channel = helper.getChannelId();
var chaincode = Object.keys(helper.creds.channels[channel].chaincodes);
return helper.creds.channels[channel].chaincodes[chaincode];
var chaincodeId = helper.getChaincodeId();
if (channel && chaincodeId) {
return helper.creds.channels[channel].chaincodes[chaincodeId];
}
logger.warn('No chaincode version found in credentials file... might be okay if we haven\'t instantiated marbles yet');
return null;
};

// get the chaincode id on network
Expand Down

0 comments on commit 6a93d86

Please sign in to comment.