Skip to content

Commit

Permalink
faster initial startup
Browse files Browse the repository at this point in the history
  • Loading branch information
dshuffma-ibm committed Mar 19, 2017
1 parent 2bcee37 commit c1da6ad
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
7 changes: 4 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var logger = { //overwrite console to work with info/warn/debug
warn: console.log,
debug: console.log
};
var fcw = require('./utils/fc_wrangler/index.js')(logger);
var fcw = require('./utils/fc_wrangler/index.js')({block_delay: block_delay}, logger);

var more_entropy = randStr(32);
var ws_server = require('./utils/websocket_server_side.js')(null, null, null);
Expand Down Expand Up @@ -173,6 +173,7 @@ function setup_marbles_lib(){
console.log('Setup Marbles Lib...');

var opts = {
block_delay: block_delay,
channel_id: helper.getChannelId(),
chaincode_id: helper.getChaincodeId(),
event_url: helper.getPeerEventUrl(0),
Expand Down Expand Up @@ -353,9 +354,9 @@ function create_marbles(username, cb){
args: randOptions
};
marbles_lib.create_a_marble(options, function(){
setTimeout(function(){
//setTimeout(function(){
marble_cb();
}, block_delay);
//}, block_delay);
});
}, function() {
console.log('debug 2 - ok returning', Date.now());
Expand Down
2 changes: 1 addition & 1 deletion config/marbles1.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"cred_filename": "blockchain_creds3.json",
"cred_filename": "blockchain_creds4.json",
"company": "United Marbles",
"usernames": [
"amy",
Expand Down
4 changes: 2 additions & 2 deletions utils/fc_wrangler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Fabric Client Wrangler - Wrapper for the Hyperledger Fabric SDK
//-------------------------------------------------------------------

module.exports = function (logger) {
module.exports = function (g_options, logger) {
var deploy_cc = require('./deploy_cc.js')(logger);
var invoke_cc = require('./invoke_cc.js')(logger);
var invoke_cc = require('./invoke_cc.js')(g_options, logger);
var query_cc = require('./query_cc.js')(logger);
var query_peer = require('./query_peer.js')(logger);
var enrollment = require('./enrollment.js')(logger);
Expand Down
25 changes: 20 additions & 5 deletions utils/fc_wrangler/invoke_cc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
//-------------------------------------------------------------------
var path = require('path');

module.exports = function (logger) {
module.exports = function (g_options, logger) {
var common = require(path.join(__dirname, './common.js'))(logger);
var EventHub = require('fabric-client/lib/EventHub.js');
var utils = require('fabric-client/lib/utils.js');
var invoke_cc = {};

if(!g_options) g_options = {};
if(!g_options.block_delay) g_options.block_delay = 10000;

//-------------------------------------------------------------------
// Create User - options are {username: bob}
//-------------------------------------------------------------------
Expand All @@ -29,6 +32,7 @@ module.exports = function (logger) {
var eventhub;
var chain = obj.chain;
var nonce = utils.getNonce();
var cbCalled = false;

// send proposal to endorser
var request = {
Expand Down Expand Up @@ -71,19 +75,30 @@ module.exports = function (logger) {
var watchdog = setTimeout(() => {
var msg = '[fcw] Failed to receive block event within the timeout period';
logger.error(msg);
throw msg;
}, 120000);

if (cb && !cbCalled) {
cbCalled = true;
return cb(null); //timeout pass it back
}
else return;
}, g_options.block_delay + 2000);

// Wait for block event
eventhub.registerTxEvent(request.txId.toString(), (tx, code) => {
logger.info('[fcw] The chaincode transaction has been committed, success:', code);
clearTimeout(watchdog);

if(code !== 'VALID') {
if (cb) return cb(code); //pass error back
if (cb && !cbCalled) {
cbCalled = true;
return cb(code); //pass error back
}
else return;
} else {
if (cb) return cb(null); //all good, pass it back
if (cb && !cbCalled) {
cbCalled = true;
return cb(null); //all good, pass it back
}
else return;
}
});
Expand Down
2 changes: 1 addition & 1 deletion utils/marbles_cc_lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = function (enrollObj, g_options, logger) {
l_logger.log = console.log;
l_logger.debug = console.log;
l_logger.error = console.log;
var fcw = require(path.join(__dirname, './fc_wrangler/index.js'))(l_logger);
var fcw = require(path.join(__dirname, './fc_wrangler/index.js'))(g_options, l_logger);


// Chaincode -------------------------------------------------------------------------------
Expand Down

0 comments on commit c1da6ad

Please sign in to comment.