-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored utils to make them more generic
- Loading branch information
Showing
15 changed files
with
261 additions
and
214 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
const invoke = require('./invoke'); | ||
const query = require('./query'); | ||
const baseService = require('./lib/baseService'); | ||
const createFabricClient = require('./lib/createFabricClient'); | ||
const invoke = require('./lib/invoke'); | ||
const query = require('./lib/query'); | ||
const registerChaincodeEventListener = require('./lib/registerChaincodeEventListener'); | ||
|
||
module.exports = { | ||
baseService, | ||
createFabricClient, | ||
invoke, | ||
query | ||
query, | ||
registerChaincodeEventListener | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const FabricClient = require('fabric-client'); | ||
const logger = require('../logging/logger').getLogger('lib/createFabricClient'); | ||
|
||
module.exports = function createFabricClient(keyStorePath) { | ||
const fabricClient = new FabricClient(); | ||
|
||
return new Promise((resolve, reject) => { | ||
Promise.resolve() | ||
.then(() => { | ||
logger.info('Create a fabric client and set the keystore location'); | ||
return FabricClient.newDefaultKeyValueStore({path: keyStorePath}); | ||
}) | ||
.then((stateStore) => { | ||
logger.info('Set fabric client crypto suite'); | ||
|
||
// assign the store to the fabric client | ||
fabricClient.setStateStore(stateStore); | ||
const cryptoSuite = FabricClient.newCryptoSuite(); | ||
// use the same location for the state store (where the users' certificate are kept) | ||
// and the crypto store (where the users' keys are kept) | ||
const cryptoStore = FabricClient.newCryptoKeyStore({path: keyStorePath}); | ||
cryptoSuite.setCryptoKeyStore(cryptoStore); | ||
fabricClient.setCryptoSuite(cryptoSuite); | ||
|
||
logger.info('Fabric client initialized'); | ||
resolve(fabricClient); | ||
}) | ||
.catch((err) => { | ||
logger.error(`Failed to initialize fabric client: ${err.message}`); | ||
reject(err); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.