Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"graphiql": "0.5.0",
"graphql": "0.4.18",
"history": "2.0.1",
"ibm-blockchain-js": "^1.2.1",
"isomorphic-style-loader": "0.0.12",
"jade": "1.11.0",
"jsonwebtoken": "5.7.0",
Expand Down
90 changes: 88 additions & 2 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import passport from './core/passport';
import schema from './data/schema';
import Router from './routes';
import assets from './assets';
import Ibc1 from 'ibm-blockchain-js';
import { port, auth, analytics } from './config';

const server = global.server = express();
Expand All @@ -40,15 +41,100 @@ server.use(cookieParser());
server.use(bodyParser.urlencoded({ extended: true }));
server.use(bodyParser.json());

//
// ibm-blockchain-js initialization
// -----------------------------------------------------------------------------
var ibc = new Ibc1();
var chaincode = {};

// ==================================
// configure ibc-js sdk
// currently configured to...
// - Emmanuel's blockchain service, and
// - marbles demo chaincode
// ==================================
var options = {
network:{
'peers': [
{
'api_host': 'aaa58403-33ee-41b1-9ec0-45f3ec4c7f96_vp1-api.blockchain.ibm.com',
'api_port_tls': 443,
'api_port': 80,
'id': 'aaa58403-33ee-41b1-9ec0-45f3ec4c7f96'
},
{
'api_host': 'aaa58403-33ee-41b1-9ec0-45f3ec4c7f96_vp2-api.blockchain.ibm.com',
'api_port_tls': 443,
'api_port': 80,
'id': 'aaa58403-33ee-41b1-9ec0-45f3ec4c7f96'
}
],
users: [
{
'enrollId': 'dashboarduser_type0_f51ef4cefc',
'enrollSecret': 'f9953b6b5e'
},
{
"enrollId": "user_type1_cbd1460197",
"enrollSecret": "00aeacd492"
}
]
},
options: {
quiet: true,
tls:false,
maxRetry: 1
},
chaincode:{
// marbles chaincode repository
zip_url: 'https://github.com/ibm-blockchain/marbles-chaincode/archive/master.zip',
unzip_dir: 'marbles-chaincode-master/hyperledger/part1', //subdirectroy name of chaincode after unzipped
git_url: 'https://github.com/ibm-blockchain/marbles-chaincode/hyperledger/part1', //GO get http url

// emmanuel's test chaincode repository
// zip_url: 'https://github.com/eman3220/emanschaincodetest/archive/master.zip',
// unzip_dir: 'emanschaincodetest-master/hyperledger/part1', //subdirectroy name of chaincode after unzipped
// git_url: 'https://github.com/eman3220/emanschaincodetest/hyperledger/part1', //GO get http url
}
};

ibc.load(options, cb_ready);

function cb_ready(err, cc){
chaincode = cc;
console.log("The chaincode is: "+JSON.stringify(chaincode));
if(cc.details.deployed_name === ""){ //decide if I need to deploy or not
cc.deploy('init', ['99'], null, cb_deployed);
}
else {
console.log("NAME IS: "+cc.details.deployed_name);
console.log('chaincode summary file indicates chaincode has been previously deployed');
cb_deployed();
}
}

function cb_deployed(err){
console.log('sdk has deployed code and waited');
chaincode.query.read(['a']);
}


//
// API endpoints
// -----------------------------------------------------------------------------
server.get('/api', function (req, res) {
res.send(getWelcome());
});

server.post('/api/election/vote/v1', function(req, res) {
// get information for block

// chaincode.invoke.init_marble(function() {
// return {"eman", "red", "20", "bob"}
var election_id,
vote_id,
voter_token;

// chaincode.invoke.OUR_FUNCTION([arg1, arg2, ...], function() {
// console.log('OUR_FUNCTION response:', data, err);
// });

res.sendStatus(200);
Expand Down