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 | function getRequestSpec(params){ if(!validate.isValidJson(params)){ logHelper.logError(logger, 'getRequestSpec', 'Invalid params'); throw new Error("Invalid params"); } var chaincodeID = config['chaincode']['id'] if(!validate.isValidString(chaincodeID)){ logHelper.logError(logger, 'getRequestSpec', 'Invalid chaincodeID'); throw new Error("Invalid chaincodeID"); } var functionName = params.functionName; if(!validate.isValidString(functionName)){ logHelper.logError(logger, 'getRequestSpec', 'Invalid function name'); throw new Error("Invalid function name"); } var args = [] if(validate.isValidArray(params.args)){ args = params.args; } var attributes = ['username', 'role'] if(validate.isValidArray(params.attributes)){ attributes = params.attributes; } var spec = { chaincodeID: chaincodeID, fcn: functionName, args: args, attrs: attributes } return spec; } |
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 | var chain = bcNetwork.getChain(); var chainAsync = Promise.promisifyAll(chain); chainAsync.getMemberAsync(user) .then(function(member){ var tx = member.invoke(requestSpec); tx.on('submitted', function(data) { logHelper.logMessage(logger, 'doInvoke', 'Transaction for invoke submitted ',requestSpec); return resolve({statusCode: constants.SUCCESS, body: data}); }); tx.on('complete', function(data) { //logHelper.logMessage(logger, 'doInvoke', 'Transaction for invoke complete ',data); }); tx.on('error', function (err) { logHelper.logError(logger, 'doInvoke', 'Could not perform invoke ',err); return reject({statusCode: constants.INTERNAL_SERVER_ERROR, body: 'Could not perform invoke ' }); }); }) |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |