Skip to content

Commit

Permalink
conform to fcw interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
dshuffma-ibm committed Feb 13, 2017
1 parent d14e962 commit 676fa9c
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 130 deletions.
35 changes: 24 additions & 11 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,18 @@ function wait_to_init(){

//setup marbles library and check if cc is deployed
function setup_marbles_lib(){
chain.addOrderer(new Orderer(helper.getOrderersUrl(0)));
console.log('Setup Marbles Lib...');

try{
chain.addOrderer(new Orderer(helper.getOrderersUrl(0)));
}
catch(e){
//may error with duplicate orderer, thats ok
}
var opts = {
channel_id: helper.getChannelId(),
chaincode_id: helper.getChaincodeId()
chaincode_id: helper.getChaincodeId(),
event_url: helper.getEventUrl()
};
marbles_lib = require('./utils/marbles_cc_lib/index.js')(chain, opts, console);
ws_server.setup(chain, marbles_lib, wss.broadcast, null);
Expand Down Expand Up @@ -372,7 +380,7 @@ function pessimistic_create_owner(attempt, username, cb){
console.log('\n\n\n!', attempt, e);

// --- Does the user exist yet? --- //
if(typeof e === 'string' && e.indexOf('owner already exists')){
if(e && e.parsed && e.parsed.indexOf('owner already exists') >= 0){
console.log('\n\nfinally the user exists, this is a good thing, moving on\n\n');
cb(null);
}
Expand Down Expand Up @@ -476,14 +484,19 @@ function setupWebSocket(){
//deploy chaincode
else if(data.configure === 'deploy_chaincode'){
helper.write(data); //write new config data to file
chain.setOrderer(helper.getOrderersUrl(0));
var temp_marbles_lib = require('./utils/marbles_cc_lib/index.js')(chain, helper.getChaincodeId(), null);
var options = {
channel_id: helper.getChannelId(),
chaincode_id: helper.getChaincodeId(),
peer_urls: [helper.getPeersUrl(0)],
};
temp_marbles_lib.deploy_chaincode(chain, options, function(){
try{
chain.addOrderer(new Orderer(helper.getOrderersUrl(0)));
}
catch(e){
//may error with duplicate orderer, thats ok
}
var opts = {
channel_id: helper.getChannelId(),
chaincode_id: helper.getChaincodeId(),
event_url: helper.getEventUrl()
};
var temp_marbles_lib = require('./utils/marbles_cc_lib/index.js')(chain, opts, null);
temp_marbles_lib.deploy_chaincode(chain, null, function(){
setup_marbles_lib();
});
}
Expand Down
2 changes: 1 addition & 1 deletion busters_js.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"public/js/singlejshash":"158611d7c4c5f15a53f22245ef688e2e"}
{"public/js/singlejshash":"9cee6fcacd7ecf3865903b828dcb0e31"}
101 changes: 51 additions & 50 deletions config/creds_united_marbles.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
{
"credentials": {
"network_id": "asdf",
"channel_id": "myc1",
"peers": [
{
"grpc_host": "192.168.99.100",
"grpc_port": 8051,
"event_host": "192.168.99.100",
"event_port:": 8053,
"type": "peer",
"network_id": "asdf",
"id": "peer0"
}
],
"cas": [
{
"id": "asdf-ca",
"host": "192.168.99.100",
"port": 8054,
"type": "ca",
"network_id": "asdf"
}
],
"orderers": [
{
"host": "192.168.99.100",
"port": 8050,
"type": "orderer",
"network_id": "asdf",
"id": "orderer-01"
}
],
"users": [
{
"enrollId": "admin",
"enrollSecret": "adminpw"
}
],
"cert": "https://blockchain-certs.mybluemix.net/us.blockchain.ibm.com.cert",
"marbles": {
"company": "United Marbles",
"chaincode_id": "marbles",
"usernames": [
"amy",
"alice",
"amber"
],
"port": 3000
}
}
"credentials": {
"network_id": "asdf",
"channel_id": "myc1",
"event_url": "grpc://192.168.99.100:8053",
"peers": [
{
"grpc_host": "192.168.99.100",
"grpc_port": 8051,
"event_host": "192.168.99.100",
"event_port:": 8053,
"type": "peer",
"network_id": "asdf",
"id": "peer0"
}
],
"cas": [
{
"id": "asdf-ca",
"host": "192.168.99.100",
"port": 8054,
"type": "ca",
"network_id": "asdf"
}
],
"orderers": [
{
"host": "192.168.99.100",
"port": 8050,
"type": "orderer",
"network_id": "asdf",
"id": "orderer-01"
}
],
"users": [
{
"enrollId": "admin",
"enrollSecret": "adminpw"
}
],
"cert": "https://blockchain-certs.mybluemix.net/us.blockchain.ibm.com.cert",
"marbles": {
"company": "United Marbles",
"chaincode_id": "marbles",
"usernames": [
"amy",
"alice",
"amber"
],
"port": 3000
}
}
}
1 change: 0 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ gulp.task('watch-js', ['build-js-hash'], function () {
gulp.task('watch-server', function () {
gulp.watch(path.join(__dirname, '/routes/**/*.js'), ['server']);
gulp.watch([path.join(__dirname, '/utils/*.js')], ['server']);
gulp.watch([path.join(__dirname, '/utils/marbles_cc_lib/*.js')], ['server']);
gulp.watch(path.join(__dirname, '/app.js'), ['server']);
});

Expand Down
2 changes: 1 addition & 1 deletion public/js/ui_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var known_companies = {};
var start_up = true;
var lsKey = 'marbles';
var fromLS = {};
var block_delay = 1500;
var block_delay = 10000; //1500;

// =================================================================================
// On Load
Expand Down
5 changes: 4 additions & 1 deletion utils/fc_wrangler/deploy_cc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = function (logger) {
path_2_chaincode: "path to chaincode from proj root",
channel_id: "channel id",
chaincode_id: "chaincode id",
event_url: "event grpc url",
endorsed_hook: function(error, res){},
ordered_hook: function(error, res){},
cc_args: ["argument 1"],
Expand All @@ -44,7 +45,7 @@ module.exports = function (logger) {
}

// fix GOPATH - does not need to be real!
process.env.GOPATH = path.join(__dirname, '../chaincode');
process.env.GOPATH = path.join(__dirname, '../../chaincode');

// send proposal to endorser
var request = {
Expand All @@ -61,6 +62,8 @@ module.exports = function (logger) {
RUN go install build-chaincode && mv $GOPATH/bin/build-chaincode $GOPATH/bin/%s`
};

//console.log('\n\n sending:', request, options);

// Setup EventHub
eventhub = new EventHub();
eventhub.setPeerAddr(options.event_url);
Expand Down
17 changes: 11 additions & 6 deletions utils/fc_wrangler/invoke_cc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var path = require('path');
module.exports = function (logger) {
var common = require(path.join(__dirname, './common.js'))(logger);
var Peer = require('fabric-client/lib/Peer.js');
var EventHub = require('fabric-client/lib/EventHub.js');
//var EventHub = require('fabric-client/lib/EventHub.js');
var utils = require('fabric-client/lib/utils.js');
var invoke_cc = {};

Expand All @@ -18,6 +18,7 @@ module.exports = function (logger) {
peer_urls: [array of peer urls],
channel_id: "channel id",
chaincode_id: "chaincode id",
event_url: "event grpc url",
endorsed_hook: function(error, res){},
ordered_hook: function(error, res){},
cc_function: "function_name"
Expand All @@ -26,7 +27,7 @@ module.exports = function (logger) {
*/
invoke_cc.invoke_chaincode = function (chain, options, cb) {
logger.debug('\nInvoking Chaincode: ' + options.cc_function + '()\n');
var eventhub;
//var eventhub;

try {
for (var i in options.peer_urls) {
Expand All @@ -47,10 +48,12 @@ module.exports = function (logger) {
args: options.cc_args
};

console.log('\n\n sending:', request, options);

// Setup EventHub
eventhub = new EventHub();
/*eventhub = new EventHub();
eventhub.setPeerAddr(options.event_url);
eventhub.connect();
eventhub.connect();*/

// Send Proposal
chain.sendTransactionProposal(request
Expand All @@ -72,7 +75,7 @@ module.exports = function (logger) {
// Call optional order hook
if (options.ordered_hook) options.ordered_hook(null, request.txId.toString());

var watchdog = setTimeout(() => {
/*var watchdog = setTimeout(() => {
var msg = '[fcw] Failed to receive block event within the timeout period';
logger.error(msg);
throw msg;
Expand All @@ -86,7 +89,9 @@ module.exports = function (logger) {
if (cb) return cb(null);
else return;
});
});*/
if (cb) return cb(null);
else return;
}

// No good
Expand Down
4 changes: 4 additions & 0 deletions utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ module.exports = function (config_filename, logger) {
return helper.creds.credentials.channel_id;
};

helper.getEventUrl = function(){
return helper.creds.credentials.event_url;
};

//safely retrieve marbles fields
function getMarblesField(marbles_field){
try{
Expand Down
Loading

0 comments on commit 676fa9c

Please sign in to comment.