Skip to content
Permalink
Browse files

enabled multi channel support

  • Loading branch information...
dpitt committed Aug 26, 2018
1 parent eb16a21 commit 78e404fd96864095116dcc1ea5994a6d215339ac
@@ -22,4 +22,6 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

/ui/node_modules
/ui/node_modules

/hfc-key-store/*
@@ -0,0 +1,4 @@
"search.exclude": {
"**/node_modules": false,
"**/bower_components": true
}
181 app.js
@@ -1,21 +1,21 @@
/**
* Copyright 2017 IBM All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
Copyright 2018 Keyhole Software LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
'use strict';
var log4js = require('log4js');
var logger = log4js.getLogger('SampleWebApp');
var logger = log4js.getLogger('app.js');
var express = require('express');
var session = require('express-session');
var cookieParser = require('cookie-parser');
@@ -27,19 +27,25 @@ var expressJWT = require('express-jwt');
var jwt = require('jsonwebtoken');
var bearerToken = require('express-bearer-token');
var cors = require('cors');
var query = require('./app/query.js');
var lab = require('./app/createLab.js');
var channels = require('./app/channelinfo.js');
var peers = require('./app/peers.js');
var blockinfo = require('./app/blockinfo.js');
var block = require('./app/block.js');
var appconfig = require('./config.js');


require('./config.js');
var hfc = require('fabric-client');
logger.setLevel('debug');

var host = process.env.HOST || hfc.getConfigSetting('host');
var port = process.env.PORT || hfc.getConfigSetting('port');
//var host = process.env.HOST || hfc.getConfigSetting('host');
//var port = process.env.PORT || hfc.getConfigSetting('port');
//var loglevel = process.env.PORT || hfc.getConfigSetting('loglevel');

var host = appconfig.host;
var port = appconfig.port;
var loglevel = appconfig.loglevel;

logger.setLevel(loglevel);

///////////////////////////////////////////////////////////////////////////////
//////////////////////////////// SET CONFIGURATONS ////////////////////////////
///////////////////////////////////////////////////////////////////////////////
@@ -56,146 +62,99 @@ app.use(bodyParser.urlencoded({
///////////////////////////////////////////////////////////////////////////////
//////////////////////////////// START SERVER /////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
var server = http.createServer(app).listen(port, function() {});
var server = http.createServer(app).listen(port, function () { });
logger.info('****************** SERVER STARTED ************************');
logger.info('************** http://' + host + ':' + port +
' ******************');
server.timeout = 240000;



///////////////////////////////////////////////////////////////////////////////
//////////////////////////////// API ENDPOINTS /////////////////////////////////
//////////////////////////////// START WEBSOCKET SERVER /////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Query all
app.get('/queryAllLabs', function(req, res) {
logger.debug('================ Query All ======================');

query.getAllLabs('queryAllLabs')
.then(function(
message) {
res.send(message);
});
var io = require('socket.io')(server);
io.on('connection', function (socket) {
logger.info('A new WebSocket connection has been established');
});


// Query all
app.get('/queryByState', function(req, res) {
logger.debug('================ Query By State ======================');

query.getAllLabs('queryAllLabs')
.then(function(
message) {

var results = JSON.parse(message);
var data = [];
for (var i = 0; i < results.length ; i++) {

if (results[i].Record.state.toUpperCase() == req.query.state.toUpperCase() ) {

data.push(results[i]);

}


}


res.send(JSON.stringify(data));
});
});

// Set global socket
global.socket = io;


// Create Lab
app.post('/createLab', function(req, res) {
logger.debug('================ Create Lab ======================');

// TODO Validate Form values...
var dateTime = req.body.dateTime;
var gender = req.body.gender;
var testType = req.body.testType;
var dob = req.body.dob;
var result = req.body.result;
var city = req.body.city;
var state = req.body.state;


lab.createLab({dateTime: dateTime, gender: gender, testType: testType, dob: dob, result: result, city: city, state: state} )
.then(function(message) {
res.send(message);
});
});
///////////////////////////////////////////////////////////////////////////////
//////////////////////////////// API ENDPOINTS /////////////////////////////////
///////////////////////////////////////////////////////////////////////////////


// get channels
app.post('/channel', function(req, res) {
app.post('/channel', function (req, res) {
logger.debug('================ Create Lab ======================');

// TODO Validate Form values...
var channelid = req.body.channelid;


channels.getChannelInfo(channelid)
.then(function(message) {
res.send(message);
});
.then(function (message) {
res.send(message);
});
});


// get channels
app.post('/peers', function(req, res) {
app.post('/peers', function (req, res) {
logger.debug('================ Peers ======================');

var channelid = req.body.channelid;

peers.getPeers(channelid)
.then(function(message) {
res.send(message);
});
.then(function (message) {
res.send(message);
});
});


// get channels
app.post('/blockinfo', function(req, res) {
app.post('/blockinfo', function (req, res) {
logger.debug('================ Peers ======================');

// TODO Validate Form values...
var channelid = req.body.channelid;

blockinfo.getBlockInfo(channelid)
.then(function(message) {
res.send(message);
});
.then(function (message) {
res.send(message);
});
});


// get block
app.post('/block', function(req, res) {
app.post('/block', function (req, res) {
logger.debug('================ Block ======================');

var channelid = req.body.channelid;
var blocknumber = req.body.blocknumber;
block.getBlock(channelid,blocknumber)
.then(function(message) {
res.send(message);
});

block.getBlock(channelid, blocknumber)
.then(function (message) {
res.send(message);
});
});


// get block hash
app.post('/blockhash', function(req, res) {
app.post('/blockhash', function (req, res) {
logger.debug('================ Block ======================');
var number = req.body.number;

var number = req.body.number;
var prev = req.body.prevhash;
var data = req.body.datahash;
block.getBlockHash({number: number, previous_hash: prev, data_hash: data} )
.then(function(message) {
res.send(message);
});

block.getBlockHash({ number: number, previous_hash: prev, data_hash: data })
.then(function (message) {
res.send(message);
});
});


@@ -1,32 +1,34 @@
'use strict';
/**
* Copyright 2017 IBM All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
Copyright 2018 Keyhole Software LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var path = require('path');
var fs = require('fs');
var util = require('util');
var hfc = require('fabric-client');
var Peer = require('fabric-client/lib/Peer.js');
var EventHub = require('fabric-client/lib/EventHub.js');
var config = require('../config.json');
var config = require('../config.js');
var log4js = require('log4js');
var logger = log4js.getLogger('Helper');
var logger = log4js.getLogger('app/block.js');
var util = require('./util.js');
var sha = require('js-sha256');
var asn = require('asn1.js');

logger.setLevel(config.loglevel);

var getBlock = function(channel_id,blockNumber) {

return Promise.resolve().then(() => {
@@ -35,11 +37,11 @@ return Promise.resolve().then(() => {

return c.queryBlock(blockNumber);
}).then((query_responses) => {
console.log("returned from query"+ JSON.stringify(query_responses));
logger.debug("returned from query"+ JSON.stringify(query_responses));

return JSON.stringify(query_responses);
}).catch((err) => {
console.error("Caught Error", err);
logger.error("Caught Error", err);
});

};

0 comments on commit 78e404f

Please sign in to comment.
You can’t perform that action at this time.