diff --git a/app.js b/app.js index d7de63a7e..0d6821b12 100644 --- a/app.js +++ b/app.js @@ -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); @@ -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), @@ -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()); diff --git a/config/marbles1.json b/config/marbles1.json index d63e277ce..dfc348c36 100644 --- a/config/marbles1.json +++ b/config/marbles1.json @@ -1,5 +1,5 @@ { - "cred_filename": "blockchain_creds3.json", + "cred_filename": "blockchain_creds4.json", "company": "United Marbles", "usernames": [ "amy", diff --git a/utils/fc_wrangler/index.js b/utils/fc_wrangler/index.js index 6bb1cf939..0ab17124c 100644 --- a/utils/fc_wrangler/index.js +++ b/utils/fc_wrangler/index.js @@ -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); diff --git a/utils/fc_wrangler/invoke_cc.js b/utils/fc_wrangler/invoke_cc.js index d2c3ab4d3..34d30442d 100644 --- a/utils/fc_wrangler/invoke_cc.js +++ b/utils/fc_wrangler/invoke_cc.js @@ -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} //------------------------------------------------------------------- @@ -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 = { @@ -71,8 +75,13 @@ 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) => { @@ -80,10 +89,16 @@ module.exports = function (logger) { 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; } }); diff --git a/utils/marbles_cc_lib.js b/utils/marbles_cc_lib.js index 4a5327ff4..1767d986b 100644 --- a/utils/marbles_cc_lib.js +++ b/utils/marbles_cc_lib.js @@ -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 -------------------------------------------------------------------------------