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 | function configureNetwork() { return new Promise(function(resolve, reject){ try{ logHelper.logEntryAndInput(logger, 'configureNetwork'); var pem; fs.readFile(constants['BLOCKCHAIN_NW_CERT_PATH'], function(err, data){ if(validate.isValid(err)){ logHelper.logError(logger,'configureNetwork', 'Could not read cert: '+constants['BLOCKCHAIN_NW_CERT_PATH']); return reject({statusCode: constants.INTERNAL_SERVER_ERROR, body: 'Could not read cert: '+constants['BLOCKCHAIN_NW_CERT_PATH'] }); } else{ pem = data; chain.setMemberServicesUrl(caURL, { pem: pem }); for (var i in peerURLs) { chain.addPeer(peerURLs, { pem: pem }); } recursiveLogin({username: constants['BLOCKCHAIN_REGISTRAR_ID'], password: registrarPassword, chain: chain }) .then(function(resp){ logHelper.logMessage(logger,'configureNetwork', 'Successfully enrolled registrar: '+constants['BLOCKCHAIN_REGISTRAR_ID']); var registrarMember = resp.body; chain.setRegistrar(registrarMember); return resolve({statusCode: constants.SUCCESS, body: 'Network configuration complete'}); }) .catch(function(err){ return reject({statusCode: constants.INTERNAL_SERVER_ERROR, body: 'Could not enroll registrar: '+constants['BLOCKCHAIN_REGISTRAR_ID'] }); }) } }); } catch(err){ logHelper.logError(logger, 'configureNetwork', 'Could not configure network', err); return reject({statusCode: constants.INTERNAL_SERVER_ERROR, body: 'Could not configure network', err}); } }); } |
{"name":"WebAppAdmin","enrollment":{"key":"f4b19c7195d2da0ea 02a47fa8e2aabdc0b4ba610720a696e895b400fb81cb9be","cert":"d2 d2d2d454e44204543445341205055424c4943204b45592d2d2d2d2d 0a","queryStateKey":{"type":"Buffer","data":[91,181,140,162,159,21 8,158,144,230,192,52,99,100,155,235,23,72,242,97,158,82,29,54,22 2]}}} |
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 | var roles = params.roles; if(!validate.isValidArray(roles)){ roles = ['client']; } var enrollsecret var chain = bcNetwork.getChain(); var reg = chain.getRegistrar(); var chainAsync = Promise.promisifyAll(chain); chainAsync.getMemberAsync(username) .then(function(member){ var memberAsync = Promise.promisifyAll(member); var registrationRequest = { enrollmentID: username, attributes: [ {name: 'role', value: affiliation}, {name: 'username', value: username} ], affiliation: 'group1', registrar: reg, roles: roles }; return memberAsync.registerAsync(registrationRequest); }) .then(function(enrollsec){ logHelper.logMessage(logger, 'registerUser', 'Successfully registered user on blockchain: '+username); enrollsecret = enrollsec; return resolve({statusCode: constants.SUCCESS, body: {password: enrollsecret}}); }) |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |