Skip to content

Commit

Permalink
Merge pull request #3 from blocledger/beta-update
Browse files Browse the repository at this point in the history
Beta update
  • Loading branch information
ericmvaughn authored Jun 15, 2017
2 parents c431ff6 + d5cdd28 commit b5a9dd7
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 99 deletions.
15 changes: 2 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ hash so that its existence can be later proved through transaction queries.
* node - v6.9.5
* Git client
* Windows needs OpenSSL installed into C:/OpenSSL-Win64
* Goto https://slproweb.com/products/Win32OpenSSL.html and pick the full Win64 package
* Goto https://slproweb.com/products/Win32OpenSSL.html and pick the full Win64 package

## Installation

Expand All @@ -24,17 +24,6 @@ npm install -g bower
npm install
```

> **Windows note:** To avoid a problem with the windows style '\\' during
> the chaincode install resulting in the error:
>
> `Promise is rejected: Error: Illegal file detected in payload: "src\github.com\chaincode\poe_chaincode.go"`
>
> per FAB-3975,
> add `.split('\\').join('/')` to the end of line 98 of
> node_modules/fabric-client/lib/packager/Golang.js like this:
>
> `name: path.relative(goPath, entry.path).split('\\').join('/'),`
## Setting up a test blockchain using Docker

A Hyperledger Fabric blockchain network can be run on your local machine
Expand All @@ -48,7 +37,7 @@ The instructions below assume that you already have docker installed and running

Pull the fabric chaincode environment image using the x86_64-1.0.0-alpha tag.
```
docker pull hyperledger/fabric-ccenv:x86_64-1.0.0-alpha2
docker pull hyperledger/fabric-ccenv:x86_64-1.0.0-beta
```
Next give the fabric-ccenv the 'latest' tag so that software can use it.
Replace the image ID (4ac07a26ca7a) in the example command with the image ID
Expand Down
3 changes: 1 addition & 2 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ debug(process.env.GOPATH);
var confidentialSetting = config.confidentialSetting;

// Store the exports from initialize.js in global variables
var chain = init.chain;
var GlobalAppUser = init.GlobalAppUser;

var cred = config.cred;
Expand Down Expand Up @@ -116,7 +115,7 @@ app.get('/chain/transactions/:id', function(req, res) {
init.client.setUserContext(appUser.hfcUser, true)
.then(function(user) {
console.log('user is ', user.getName());
return init.chain.queryTransaction(req.params.id);
return init.channel.queryTransaction(req.params.id);
})
.then(function(result) {
debug(result);
Expand Down
53 changes: 24 additions & 29 deletions createChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ let opts = {path: config.keyPath};
debug(opts);

debug('=============================================================');
var cryptoSuite = client.newCryptoSuite(opts);
var cryptoSuite = HFC.newCryptoSuite();
cryptoSuite.setCryptoKeyStore(HFC.newCryptoKeyStore(opts));
client.setCryptoSuite(cryptoSuite);
debug(cryptoSuite);
debug('=============================================================');
var ca = new FabricCAServices(cred.cas[0].api_url, tlsOptions, '', cryptoSuite); // Create a new CA
var targets = [];
var chain = {};
var channel = {};
var eventhub;
var ehtxid;

Expand Down Expand Up @@ -187,10 +189,8 @@ HFC.newDefaultKeyValueStore({
var signature = client.signChannelConfig(channelConfig);
var signatures = [];
signatures.push(signature);
signatures.push(signature); // this second signature is from the sdk test code. Appears to work around a problem somewhere
let nonce = utils.getNonce();
let txId = HFC.buildTransactionID(nonce, peerorg1Admin);
ehtxid = txId.toString();
let txId = client.newTransactionID();
ehtxid = txId.getTransactionID();

// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
// set up the event hub
Expand All @@ -208,15 +208,15 @@ HFC.newDefaultKeyValueStore({

let ehPromise = new Promise(function(resolve, reject) {
let handle = setTimeout(function() {
if (!config.windows) {eventhub.unregisterTxEvent(ehtxid);}
eventhub.unregisterTxEvent(ehtxid);
reject(new Error('Event hub timed out.'));
}, 10000);
debug('registering for the Tx event');

// Setup event hug to listen for results
eventhub.registerTxEvent(ehtxid, function(txid, code) {
clearTimeout(handle);
if (!config.windows) {eventhub.unregisterTxEvent(txid);}
eventhub.unregisterTxEvent(txid);

if (code !== 'VALID') {
debug('Transaction failed event hub reported:', code);
Expand All @@ -230,12 +230,11 @@ HFC.newDefaultKeyValueStore({

// Create the new form for request...
request = {
name: 'mychannel',
name: config.channelId,
orderer: orderer,
config: channelConfig,
signatures: signatures,
txId: txId,
nonce: nonce
};

debug('============ calling createChannel =====================');
Expand All @@ -244,27 +243,27 @@ HFC.newDefaultKeyValueStore({
.then(function(result) {
debug('--------------------------------------------');
debug('Channel created ', result);
if (!config.windows) {eventhub.disconnect();}
eventhub.disconnect();

chain = client.newChain('mychannel');
chain.addOrderer(orderer);
channel = client.newChannel(config.channelId);
channel.addOrderer(orderer);

// see if the channel has been created
debug(chain);
debug('chain name', chain.getName());
debug('orderers', chain.getOrderers());
debug(channel);
debug('channel name', channel.getName());
debug('orderers', channel.getOrderers());

debug('----------calling getChannelConfig after createChannel succeeded -----------');
return chain.getChannelConfig();
return channel.getChannelConfig();
}, function(err) {
debug('Error creating channel, maybe it is already created, try building it');
debug(err);
if (!config.windows) {eventhub.disconnect();}
eventhub.disconnect();

chain = client.newChain('mychannel');
chain.addOrderer(orderer);
channel = client.newChannel(config.channelId);
channel.addOrderer(orderer);
debug('----------calling getChannelConfig after createChannel fails -----------');
return chain.getChannelConfig();
return channel.getChannelConfig();
})
.then(function(result) {
debug('channel config', result);
Expand All @@ -291,13 +290,11 @@ HFC.newDefaultKeyValueStore({
debug('finished enrolling orderer admin');
debug(admin);

let nonce = utils.getNonce();
let txId = HFC.buildTransactionID(nonce, admin);
let txId = client.newTransactionID();
let request = {
txId: txId,
nonce: nonce
};
return chain.getGenesisBlock(request);
return channel.getGenesisBlock(request);
})
.then(function(block) {
genisisBlock = block;
Expand All @@ -308,15 +305,13 @@ HFC.newDefaultKeyValueStore({

// join the peers to the channel
debug('join the peers to the channel');
let nonce = utils.getNonce();
let txId = HFC.buildTransactionID(nonce, user);
let txId = client.newTransactionID();
var request = {
targets: targets,
block: genisisBlock,
txId: txId,
nonce: nonce
};
return chain.joinChannel(request);
return channel.joinChannel(request);
})
.then(function(result) {
debug('-------- join channel results ---------');
Expand Down
22 changes: 13 additions & 9 deletions initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var cred = config.cred; // Configuration file for the test network from the fab
var client = new HFC();

// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
var chain = client.newChain(config.channelId);
var channel = client.newChannel(config.channelId);
var targets = [];

var tlsOptions = {
Expand All @@ -48,7 +48,9 @@ var tlsOptions = {

debug('ca tls cert', cred.cas[0].tls_cacerts);

var cryptoSuite = client.newCryptoSuite({path: config.keyPath});
var cryptoSuite = HFC.newCryptoSuite();
cryptoSuite.setCryptoKeyStore(HFC.newCryptoKeyStore({path: config.keyPath}));
client.setCryptoSuite(cryptoSuite); // It may not be necessary to set the cryptoSuite here
var ca = new FabricCAServices(cred.cas[0].api_url, tlsOptions, '', cryptoSuite);
var admin;
var member;
Expand All @@ -67,7 +69,7 @@ for (var i = 0; i < cred.peers.length; i++) {
}
for (var i = 0; i < peerList.length; i++) {
targets.push(peerList[i]);
chain.addPeer(peerList[i]);
channel.addPeer(peerList[i]);
}

// Add orderer
Expand All @@ -78,7 +80,7 @@ var orderer = client.newOrderer(
'ssl-target-name-override': cred.orderers[0].common_name
}
);
chain.addOrderer(orderer);
channel.addOrderer(orderer);

// Configure the KeyValStore which is used to store sensitive keys
// check that the ./tmp directory existsSync
Expand Down Expand Up @@ -183,11 +185,13 @@ HFC.newDefaultKeyValueStore({
debug('Finished initializing users');
debug(results);

return client.setUserContext(member);
return client.getUserContext('peerorg1Admin', true);
})
.then(function() {
.then(function(user) {

debug('Channel information ---------------------');
debug('User name ', user.getName());
debug(user.getIdentity());
let promises = [];
targets.forEach(function(target) {
promises.push(client.queryChannels(target));
Expand All @@ -201,8 +205,8 @@ HFC.newDefaultKeyValueStore({
});
debug('-----------------------------------------');

debug('calling chain initialize');
return chain.initialize();
debug('calling channel initialize');
return channel.initialize();
})
.then(function(result) {
debug('initialize success', result);
Expand All @@ -224,7 +228,7 @@ HFC.newDefaultKeyValueStore({
debug('Failed registration or initialization', err);
});

exports.chain = chain;
exports.channel = channel;
exports.GlobalAppUser = GlobalAppUser;
exports.poeChaincode = poeChaincode;
exports.setPoeChaincode = setPoeChaincode;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"debug": "^2.2.0",
"express": "^4.13.4",
"express-session": "^1.15.1",
"fabric-ca-client": "1.0.0-alpha2",
"fabric-client": "1.0.0-alpha2",
"fabric-ca-client": "1.0.0-beta",
"fabric-client": "1.0.0-beta",
"grpc": ">=1.1.2 <1.3.0",
"js-sha256": "^0.5.0",
"morgan": "^1.7.0",
Expand Down
Loading

0 comments on commit b5a9dd7

Please sign in to comment.