Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
8da28cb
Added unit tests for add file component
liam-grace Mar 20, 2017
31513ad
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 21, 2017
5cc1d6a
Merge branch 'master' into master
Mar 21, 2017
838b047
Finished add-file component test and edit import to clear stubs
liam-grace Mar 21, 2017
e94dfb3
Merge branch 'master' of github.com:14gracel/fabric-composer
liam-grace Mar 21, 2017
4d26bf5
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 21, 2017
a1d4c45
Merge branch 'master' into master
Jakeeyturner Mar 22, 2017
eb68ef7
Bumped up about.service code coverage
liam-grace Mar 22, 2017
4721dea
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 22, 2017
307abce
Fixed minor linting issues
liam-grace Mar 22, 2017
b6995d8
Removed fdescribe
liam-grace Mar 22, 2017
b38ce58
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 23, 2017
69dc287
Increase code coverage of add-file to 100%
liam-grace Mar 23, 2017
859f0fc
Export AssetRegistry and ParticipantRegistry
liam-grace Mar 23, 2017
f70ffa5
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 23, 2017
5aef7cb
Merge branch 'master' into master
Mar 23, 2017
324c43a
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 23, 2017
fa74980
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 24, 2017
24a344a
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 24, 2017
7647174
Registry unit tests
liam-grace Mar 24, 2017
9d35f2a
Merge branch 'master' of github.com:14gracel/fabric-composer
liam-grace Mar 24, 2017
a396468
Merge branch 'master' into master
Mar 24, 2017
fc18a0f
Merge branch 'master' into master
Mar 27, 2017
e5b3286
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 27, 2017
0780bc0
First trasaction component test
liam-grace Mar 27, 2017
ea885e3
Merge branch 'master' of github.com:14gracel/fabric-composer
liam-grace Mar 27, 2017
8146a1d
Merge branch 'master' of https://github.com/fabric-composer/fabric-co…
liam-grace Mar 27, 2017
c9f4766
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Mar 28, 2017
bf41d2e
Transaction component unit tests
liam-grace Mar 28, 2017
c3ab845
Remove fdiscribe
liam-grace Mar 28, 2017
bdaf4c7
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Mar 28, 2017
008d386
Added resource unit tests
liam-grace Mar 28, 2017
351670c
Github components unit tests
liam-grace Mar 29, 2017
d5295fc
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Mar 29, 2017
4c8c021
Added test file
liam-grace Mar 29, 2017
e26e29d
Merge branch 'master' into master
samjsmith Mar 29, 2017
590956f
Merge branch 'master' into master
Mar 30, 2017
e96c67c
Merge branch 'master' into master
Mar 30, 2017
91a5f3f
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Mar 30, 2017
f33e39f
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Mar 31, 2017
9f3f20b
Merge branch 'master' of github.com:14gracel/fabric-composer
liam-grace Mar 31, 2017
75371d5
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Mar 31, 2017
b3cb033
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 3, 2017
3f3e0af
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 3, 2017
3a0fe11
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 5, 2017
6c49e4f
Business network yeoman generator
liam-grace Apr 5, 2017
5f63117
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 5, 2017
690f68f
Clean up template and give transaction template the correct name
liam-grace Apr 5, 2017
ea76594
Added missing semi colon
liam-grace Apr 5, 2017
6808721
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 6, 2017
ff9fa14
Added docs about skeleton business network generator
liam-grace Apr 6, 2017
9e9ebc6
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 6, 2017
02bad51
Added newlines to docs to stop md parse issues
liam-grace Apr 6, 2017
1a6b083
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 6, 2017
9d0dac3
Stop parser accepting floats as string defaults and ranges, and vice …
liam-grace Apr 7, 2017
9b19e8a
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 7, 2017
53f2578
Added option to allow create of models only
liam-grace Apr 7, 2017
40343d9
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 10, 2017
32695db
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 10, 2017
6e13b52
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 11, 2017
da8db71
Fixed truncation of large data when pressing 'Show All'
liam-grace Apr 11, 2017
f679170
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 11, 2017
34ae6b1
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 18, 2017
abfb307
Fixed business network generator issue #668
liam-grace Apr 18, 2017
508678e
Slight imporovement to deploy error message
liam-grace Apr 18, 2017
8340fd1
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 19, 2017
4aa5ddf
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 19, 2017
fc092d8
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 20, 2017
bbbe398
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 21, 2017
0baf213
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 21, 2017
3a449d6
Added checks and tests to solve issue #240
liam-grace Apr 21, 2017
ff593f9
Merge branch 'master' into master
Apr 21, 2017
8556d3b
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 21, 2017
409a544
Merge branch 'master' of github.com:14gracel/fabric-composer
liam-grace Apr 21, 2017
a44d490
Improved code efficiency and robustness
liam-grace Apr 21, 2017
02e6643
Merge branch 'master' into master
Apr 21, 2017
08bdf6f
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 24, 2017
b057b27
Change to open error modal if import fails
liam-grace Apr 24, 2017
2af4f0a
Merge branch 'master' of github.com:14gracel/fabric-composer
liam-grace Apr 24, 2017
f67e266
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 24, 2017
d0cf1cd
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 25, 2017
31a646c
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace Apr 27, 2017
14bad3c
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 2, 2017
4477eda
Fixed issue #792 docs problem
liam-grace May 2, 2017
cf5e7cb
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 3, 2017
6b3a1ab
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 4, 2017
04db842
Added event support to base and web runtime
liam-grace May 4, 2017
31a12df
Rebrand cli readme
liam-grace May 4, 2017
7d14ee0
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 5, 2017
32d317a
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 5, 2017
02f8fc9
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 5, 2017
a4cf5be
Web runtime events
liam-grace May 5, 2017
4fa66b1
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 8, 2017
bc404c7
HLFv1 can now emit events
liam-grace May 8, 2017
b60f828
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 8, 2017
2abf60c
GO event hub changes
liam-grace May 8, 2017
4d307f4
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 9, 2017
9359529
merge commit
liam-grace May 10, 2017
b499eeb
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 10, 2017
86602cc
Events given numbers
liam-grace May 10, 2017
f1e6c7e
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 11, 2017
1e877e7
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 11, 2017
7d5f655
Merge branch 'master' of github.com:fabric-composer/fabric-composer
liam-grace May 12, 2017
91b8403
Stop subscribing to events multiple times
liam-grace May 12, 2017
d8d10f0
Merge branch 'master' of github.com:/hyperledger/composer
May 12, 2017
eed5c91
Merge branch 'master' of github.com:/hyperledger/composer
May 15, 2017
956fd30
Latest events
May 15, 2017
cf7a03f
Merge branch 'master' of github.com:/14gracel/fabric-composer
liam-grace May 15, 2017
1182902
Merge branch 'master' of github.com:/hyperledger/composer
liam-grace May 16, 2017
b722554
Unit tests for events
liam-grace May 17, 2017
ae4bda6
Merge branch 'master' of github.com:/hyperledger/composer
liam-grace May 17, 2017
8379536
Duktape version fix
liam-grace May 17, 2017
cbabd0a
hlf0.6 event support
liam-grace May 18, 2017
ffd9e13
Merge branch 'master' into master
May 18, 2017
dde7a1b
Merge branch 'master' of github.com:/hyperledger/composer
liam-grace May 18, 2017
11b9ef2
Logging updates
liam-grace May 18, 2017
6e335d7
Merge branch 'master' of github.com:/14gracel/fabric-composer
liam-grace May 18, 2017
6e849bc
Merge branch 'master' into master
May 18, 2017
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ packages/composer-website/jekylldocs/jsdoc/
packages/composer-playground/src/assets/npmlist.json

packages/composer-systests/systestv1/tls/ca/fabric-ca-server.db
packages/composer-runtime-hlfv1/vendor/github.com/
packages/composer-runtime-hlfv1/vendor/gopkg.in/sourcemap.v1/

3 changes: 0 additions & 3 deletions packages/composer-admin/lib/adminconnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ class AdminConnection {
if (businessNetworkIdentifier) {
return this.connection.ping(this.securityContext);
}
})
.then(() => {

});
}

Expand Down
15 changes: 15 additions & 0 deletions packages/composer-client/lib/businessnetworkconnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,16 @@ class BusinessNetworkConnection extends EventEmitter {
* @return {Promise} A promise to a BusinessNetworkDefinition that indicates the connection is complete
*/
connect(connectionProfile, businessNetwork, enrollmentID, enrollmentSecret, additionalConnectOptions) {
const method = 'connect';
LOG.entry(method, connectionProfile, businessNetwork, enrollmentID, enrollmentSecret, additionalConnectOptions);
return this.connectionProfileManager.connect(connectionProfile, businessNetwork, additionalConnectOptions)
.then((connection) => {
connection.on('events', (events) => {
events.forEach((event) => {
let serializedEvent = this.getBusinessNetwork().getSerializer().fromJSON(event);
this.emit('event', serializedEvent);
});
});
this.connection = connection;
return connection.login(enrollmentID, enrollmentSecret);
})
Expand All @@ -301,6 +309,7 @@ class BusinessNetworkConnection extends EventEmitter {
})
.then((businessNetwork) => {
this.businessNetwork = businessNetwork;
LOG.exit(method);
return this.businessNetwork;
});
}
Expand All @@ -321,14 +330,20 @@ class BusinessNetworkConnection extends EventEmitter {
* terminated.
*/
disconnect() {
const method = 'disconnect';
LOG.entry(method);
if (!this.connection) {
return Promise.resolve();
}
return this.connection.disconnect()
.then(() => {
this.connection.removeListener('events', () => {
LOG.debug(method, 'removeLisener');
});
this.connection = null;
this.securityContext = null;
this.businessNetwork = null;
LOG.exit(method);
});
}

Expand Down
38 changes: 23 additions & 15 deletions packages/composer-client/scripts/tsgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,30 @@ function renderClass(key, clazz) {
fileContents += ` static ${statick}(${insert}): any;\n`;
}
});
let members = Object.getOwnPropertyNames(clazz.prototype);
members.forEach((member) => {
let func = clazz.prototype[member];
if (typeof func === 'function') {
const args = new Array(func.length).fill('temp');
args.forEach((value, index, array) => {
args[index] = `arg${index}?: any`;
});
const insert = args.join(', ');
if (member === 'constructor') {
fileContents += ` ${member}(${insert});\n`;
} else {
fileContents += ` ${member}(${insert}): any;\n`;
let foundConstructor = false;
let prototype = clazz.prototype;
while(prototype) {
let members = Object.getOwnPropertyNames(prototype);
members.forEach((member) => {
let func = prototype[member];
if (typeof func === 'function') {
const args = new Array(func.length).fill('temp');
args.forEach((value, index, array) => {
args[index] = `arg${index}?: any`;
});
const insert = args.join(', ');
if (member === 'constructor') {
if (!foundConstructor) {
foundConstructor = true;
fileContents += ` ${member}(${insert});\n`;
}
} else {
fileContents += ` ${member}(${insert}): any;\n`;
}
}
}
});
});
prototype = Object.getPrototypeOf(prototype);
}
fileContents += '}\n';
}

Expand Down
24 changes: 24 additions & 0 deletions packages/composer-client/test/businessnetworkconnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,28 @@ describe('BusinessNetworkConnection', () => {
});
});

it('should create a connection, listen for events, and emit the events it detects individually', () => {
sandbox.stub(businessNetworkConnection.connectionProfileManager, 'connect').resolves(mockConnection);
mockConnection.login.resolves(mockSecurityContext);
mockConnection.ping.resolves();
const buffer = Buffer.from(JSON.stringify({
data: 'aGVsbG8='
}));
sandbox.stub(Util, 'queryChainCode').withArgs(mockSecurityContext, 'getBusinessNetwork', []).resolves(buffer);
sandbox.stub(BusinessNetworkDefinition, 'fromArchive').resolves(mockBusinessNetworkDefinition);
const cb = sinon.stub();
businessNetworkConnection.on('event', cb);
mockConnection.on.withArgs('events', sinon.match.func).yields(['event1', 'event2']);
mockSerializer.fromJSON.onCall(0).returns('event1#serialized');
mockSerializer.fromJSON.onCall(1).returns('event2#serialized');

return businessNetworkConnection.connect('testprofile', 'testnetwork', 'enrollmentID', 'enrollmentSecret', { some: 'other', options: true })
.then((result) => {
sinon.assert.calledTwice(cb); // two events
sinon.assert.calledWith(cb, 'event1#serialized');
sinon.assert.calledWith(cb, 'event2#serialized');
});
});
});

describe('#disconnect', () => {
Expand All @@ -169,9 +191,11 @@ describe('BusinessNetworkConnection', () => {
return businessNetworkConnection.disconnect()
.then(() => {
sinon.assert.calledOnce(mockConnection.disconnect);
sinon.assert.calledOnce(mockConnection.removeListener);
return businessNetworkConnection.disconnect();
})
.then(() => {
mockConnection.removeListener.withArgs('events', sinon.match.func).yield(['event1', 'event2']);
should.equal(businessNetworkConnection.connection, null);
sinon.assert.calledOnce(mockConnection.disconnect);
});
Expand Down
1 change: 1 addition & 0 deletions packages/composer-common/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Factory {
+ Resource newConcept(string,string,Object,boolean,string) throws ModelException
+ Relationship newRelationship(string,string,string) throws ModelException
+ Resource newTransaction(string,string,string,Object,string)
+ Resource newEvent(string,string,Object,string)
+ Object toJSON()
}
class FileWallet extends Wallet {
Expand Down
3 changes: 3 additions & 0 deletions packages/composer-common/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# Note that the latest public API is documented using JSDocs and is available in api.txt.
#

Version 0.7.1 {90a630e8b408292357ee801e5b79512c} 2017-05-04
- Added Factory.newEvent

Version 0.7.0 {632a80837e835bbe0343d4b37ce12742} 2017-05-01
- Added Typed.instanceOf

Expand Down
4 changes: 3 additions & 1 deletion packages/composer-common/lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'use strict';

const ConnectionManager = require('./connectionmanager');
const EventEmitter = require('events');

/**
* Base class representing a connection to a business network.
Expand All @@ -23,7 +24,7 @@ const ConnectionManager = require('./connectionmanager');
* @class
* @memberof module:composer-common
*/
class Connection {
class Connection extends EventEmitter {

/**
* Constructor.
Expand All @@ -32,6 +33,7 @@ class Connection {
* @param {string} businessNetworkIdentifier The identifier of the business network for this connection, or null if an admin connection
*/
constructor(connectionManager, connectionProfile, businessNetworkIdentifier) {
super();
if (!(connectionManager instanceof ConnectionManager)) {
throw new Error('connectionManager not specified');
} else if (!connectionProfile) {
Expand Down
31 changes: 31 additions & 0 deletions packages/composer-common/lib/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const Concept = require('./model/concept');
const ValidatedConcept = require('./model/validatedconcept');

const TransactionDeclaration = require('./introspect/transactiondeclaration');
const EventDeclaration = require('./introspect/eventdeclaration');

const uuid = require('uuid');

Expand Down Expand Up @@ -304,6 +305,36 @@ class Factory {
return transaction;
}

/**
* Create a new event object. The identifier of the event is
* set to a UUID.
* @param {string} ns - the namespace of the event.
* @param {string} type - the type of the event.
* @param {Object} [options] - an optional set of options
* @param {string} [options.generate] - Pass one of: <dl>
* <dt>sample</dt><dd>return a resource instance with generated sample data.</dd>
* <dt>empty</dt><dd>return a resource instance with empty property values.</dd></dl>
* @return {Resource} A resource for the new event.
*/
newEvent(ns, type, options) {
if (!ns) {
throw new Error('ns not specified');
} else if (!type) {
throw new Error('type not specified');
}
const id = 'valid';
let event = this.newResource(ns, type, id, options);
const classDeclaration = event.getClassDeclaration();
if (!(classDeclaration instanceof EventDeclaration)) {
throw new Error(event.getClassDeclaration().getFullyQualifiedName() + ' is not an event');
}

// set the timestamp
event.timestamp = new Date();

return event;
}

/**
* Stop serialization of this object.
* @return {Object} An empty object.
Expand Down
37 changes: 37 additions & 0 deletions packages/composer-common/test/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ describe('Factory', () => {
transaction MyTransaction identified by transactionId {
o String transactionId
o String newValue
}
event MyEvent identified by eventId {
o String eventId
o String value
}`);
factory = new Factory(modelManager);
sandbox = sinon.sandbox.create();
Expand Down Expand Up @@ -217,6 +221,39 @@ describe('Factory', () => {

});

describe('#newEvent', () => {
it('should throw if ns not specified', () => {
(() => {
factory.newEvent(null, 'MyEvent');
}).should.throw(/ns not specified/);
});

it('should throw if type not specified', () => {
(() => {
factory.newEvent('org.acme.test', null);
}).should.throw(/type not specified/);
});

it('should throw if a non event type was specified', () => {
(() => {
factory.newEvent('org.acme.test', 'MyTransaction');
}).should.throw(/not an event/);
});

it('should create a new instance with a generated ID', () => {
let resource = factory.newEvent('org.acme.test', 'MyEvent');
resource.eventId.should.equal('valid');
resource.timestamp.should.be.an.instanceOf(Date);
});

it('should pass options onto newEvent', () => {
let spy = sandbox.spy(factory, 'newResource');
factory.newEvent('org.acme.test', 'MyEvent', { hello: 'world' });
sinon.assert.calledOnce(spy);
sinon.assert.calledWith(spy, 'org.acme.test', 'MyEvent', 'valid', { hello: 'world' });
});
});

describe('#toJSON', () => {

it('should return an empty object', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class EmbeddedConnection extends Connection {
let engine = EmbeddedConnection.createEngine(container);
EmbeddedConnection.addBusinessNetwork(businessNetwork.getName(), this.connectionProfile, chaincodeUUID);
EmbeddedConnection.addChaincode(chaincodeUUID, container, engine);
let context = new EmbeddedContext(engine, userID);
let context = new EmbeddedContext(engine, userID, this);
return businessNetwork.toArchive()
.then((businessNetworkArchive) => {
return engine.init(context, 'init', [businessNetworkArchive.toString('base64')]);
Expand Down Expand Up @@ -246,7 +246,7 @@ class EmbeddedConnection extends Connection {
let userID = securityContext.getUserID();
let chaincodeUUID = securityContext.getChaincodeID();
let chaincode = EmbeddedConnection.getChaincode(chaincodeUUID);
let context = new EmbeddedContext(chaincode.engine, userID);
let context = new EmbeddedContext(chaincode.engine, userID, this);
return chaincode.engine.query(context, functionName, args)
.then((data) => {
return Buffer.from(JSON.stringify(data));
Expand All @@ -265,7 +265,7 @@ class EmbeddedConnection extends Connection {
let userID = securityContext.getUserID();
let chaincodeUUID = securityContext.getChaincodeID();
let chaincode = EmbeddedConnection.getChaincode(chaincodeUUID);
let context = new EmbeddedContext(chaincode.engine, userID);
let context = new EmbeddedContext(chaincode.engine, userID, this);
return chaincode.engine.invoke(context, functionName, args)
.then((data) => {
return undefined;
Expand Down
19 changes: 19 additions & 0 deletions packages/composer-connector-hlf/lib/hfcconnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class HFCConnection extends Connection {
LOG.info('constructor', 'Creating connection', this.getIdentifier());
this.chain = chain;
this.connectOptions = connectOptions;

this.composerEventId = null;
}

/**
Expand All @@ -66,6 +68,7 @@ class HFCConnection extends Connection {
* terminated, or rejected with an error.
*/
disconnect() {
// this.chain.getEventHub().unregisterChaincodeEvent(this.composerEventId);
this.chain.eventHubDisconnect();
this.businessNetworkIdentifier = null;
this.connectionProfile = null;
Expand Down Expand Up @@ -99,6 +102,7 @@ class HFCConnection extends Connection {
result.setUser(enrollmentID);
result.setEnrolledMember(enrolledMember);
result.setEventHub(self.chain.getEventHub());

LOG.info('login', 'Successful login', self.getIdentifier());
resolve(result);
});
Expand Down Expand Up @@ -126,6 +130,7 @@ class HFCConnection extends Connection {
}
})
.then(() => {
this.subscribeToEvents(securityContext.getChaincodeID());
return securityContext;
});
});
Expand Down Expand Up @@ -336,6 +341,20 @@ class HFCConnection extends Connection {
});
}

/**
* Subscribe to events emitted by transactions
* @param {String} chaincodeID The chaincode ID
*/
subscribeToEvents(chaincodeID) {
if (this.chain.getEventHub() && chaincodeID) {
LOG.entry('registerChaincodeEvent', chaincodeID, 'composer');
this.composerEventId = this.chain.getEventHub().registerChaincodeEvent(chaincodeID, 'composer', (event) => {
const jsonEvent = JSON.parse(event.payload.toString('utf8'));
this.emit('events', jsonEvent);
});
}
}

}

module.exports = HFCConnection;
13 changes: 12 additions & 1 deletion packages/composer-connector-hlf/test/hfcconnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,28 @@ describe('HFCConnection', () => {
});

it('should enroll against the Hyperledger Fabric', function() {

const events = {
payload: {
toString: () => {
return '{"events": "events"}';
}
}
};
connection.emit = sinon.stub();
// Login to the Hyperledger Fabric using the mock hfc.
let enrollmentID = 'doge';
let enrollmentSecret = 'suchsecret';
return connection
.login('doge', 'suchsecret')
.then(function(securityContext) {
mockEventHub.registerChaincodeEvent.withArgs('123', 'composer', sinon.match.func).yield(events);
sinon.assert.calledOnce(mockChain.enroll);
sinon.assert.calledWith(mockChain.enroll, enrollmentID, enrollmentSecret);
sinon.assert.calledOnce(mockChain.setRegistrar);
sinon.assert.calledWith(mockChain.setRegistrar, mockMember);
sinon.assert.calledOnce(mockEventHub.registerChaincodeEvent);
sinon.assert.calledOnce(connection.emit);
sinon.assert.calledWith(connection.emit, 'events', {'events':'events'});
securityContext.should.be.a.instanceOf(HFCSecurityContext);
securityContext.getEnrolledMember().should.equal(mockMember);
securityContext.getEventHub().should.equal(mockEventHub);
Expand Down
Loading