1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | function setup(){ return new Promise(function(resolve, reject){ try{ logHelper.logMethodEntry(logger,"setup"); //Fetch IBM Bluemix Cloudant and Blockchain service instance configuration var cloudantConfig = config.VCAP_SERVICES[constants.VCAP_SERVICES_CLOUDANT][0]; var blockchainConfig = config.VCAP_SERVICES[constants.VCAP_SERVICES_BLOCKCHAIN][0]; //Setup datastore var result = datastore.initSync(cloudantConfig); if(result.statusCode != constants.SUCCESS){ logHelper.logError(logger,'Could not initialize datastore', result); return reject({statusCode: 500, body: ''}); } //Setup Cloudant based KeyValueStore var cloudantSetupDone = false; getCloudantKeyValStore(datastore, config.databases[constants.APP_MASTER_DB]) .then(function(resp){ cloudantKvStore = resp.body; cloudantSetupDone = true; return blockchainNetwork.setupBlockchain({blockchainConfig: blockchainConfig, ccName: constants['BLOCKCHAIN_CHAINCODE_NAME'] , kvStore: cloudantKvStore }) }) .then(function(resp){ return resolve({statusCode: 200, body: ''}); }) .catch(function(err){ if(cloudantSetupDone != true){ logHelper.logError(logger,'Could not initialize CloudantKeyValueStore', err); } else{ logHelper.logError(logger,'Blockchain setup failed. exiting...',err); } return reject(err); }); } catch(err){ logHelper.logError(logger,'Could not complete setup', err); throw reject({statusCode: 500, body: err}); } }) } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | function setupBlockchain(params){ return new Promise(function(resolve,reject){ try{ logHelper.logEntryAndInput(logger, 'setupBlockchain', params); if(!validate.isValidJson(params)){ logHelper.logError(logger, 'setupBlockchain', 'Invalid params'); return reject({statusCode: constants.INVALID_INPUT, body: 'Could not setup blockchain. Invalid params' }); } var goPath = __dirname+'/../../chaincode/'; process.env.GOPATH = goPath; chainInit({ccName: params.ccName, kvStorePath: params.kvStorePath, kvStore: params.kvStore}) .then(function(resp){ return loadNetworkConfiguration(params.blockchainConfig); }) .then(function(resp){ return configureNetwork(); }) .then(function(resp){ logHelper.logMessage(logger, 'setupBlockchain', 'blockchain setup complete'); isSetupComplete = true; return resolve({statusCode: constants.SUCCESS, body: 'blockchain setup complete'}); }) .catch(function(err){ logHelper.logError(logger, 'setupBlockchain', 'Could not setup blockchain', err); return reject({statusCode: constants.INTERNAL_SERVER_ERROR, body: 'Could not setup blockchain', err}); }); } catch(err){ logHelper.logError(logger, 'setupBlockchain', 'Could not setup blockchain', err); return reject({statusCode: constants.INTERNAL_SERVER_ERROR, body: 'Could not setup blockchain', err}); } }); } |
1 2 3 4 5 6 7 8 9 10 11 12 | var kvStore = params.kvStore; if(!validate.isValid(kvStore)){ logHelper.logError(logger, 'chainInit', 'Invalid kvStore'); return reject({statusCode: constants.INVALID_INPUT, body: 'Could not initialize Chain. Invalid kvStore' }) } chain = hfc.newChain(ccName); // Configure the KeyValStore which is used to store sensitive keys // as so it is important to secure this storage. chain.setKeyValStore(kvStore); chain.setECDSAModeForGRPC(true); |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |