hyperledger-fabric - eventthub 的 Hyperledger Fabric 错误:未实现:未知服务原型。交付
问题描述
我正在使用带有 Angular 6 + NodeJs + Blockchain + CouchDB 的Hyperledger Fabric fabcar“ https://github.com/hyperledger/fabric-samples/tree/master ”示例,并进行了一些修改。
我正在尝试使用此架构执行 CRUD 操作。GET 操作我做的很成功,但是在做 POST 操作(更改所有权或向分类帐中添加一些数据)时出现错误。
错误:
gtpl@gtpl-ThinkPad-T430s:~/Music/fabcar/fabcar$ node server.js
running on port8000
Chnaging the car owner { Key: 'CAR0', owner: 'Pampa' }
Store path:/home/gtpl/Music/fabcar/fabcar/hfc-key-store
Successfully loaded user1 from persistence
Assigning transaction_id: 07fb8c531615c4c5bd4668ecf5cb99c3135679eabf98a1d9c97d9ed0e8e56470
Transaction proposal was good
Successfully sent Proposal and received ProposalResponse: Status - 200, message - "OK"
Failed to invoke successfully :: Error: There was a problem with the eventhub ::Error: 12 UNIMPLEMENTED: unknown service protos.Deliver"
我的 controller.js 文件是这样的..
` router.post('/changeOwner',function(req, res){
var key = req.body.Key;
var owner = req.body.owner;
var fabric_client = new Fabric_Client();
var channel = fabric_client.newChannel('mychannel');
var peer = fabric_client.newPeer('grpc://localhost:7051');
channel.addPeer(peer);
var order = fabric_client.newOrderer('grpc://localhost:7050')
channel.addOrderer(order);
var member_user = null;
var store_path = path.join(os.homedir(), './Music/fabcar/fabcar/hfc-key-store');
console.log('Store path:'+store_path);
var tx_id = null;
Fabric_Client.newDefaultKeyValueStore({ path: store_path
}).then((state_store) => {
fabric_client.setStateStore(state_store);
var crypto_suite = Fabric_Client.newCryptoSuite();
var crypto_store = Fabric_Client.newCryptoKeyStore({path: store_path});
crypto_suite.setCryptoKeyStore(crypto_store);
fabric_client.setCryptoSuite(crypto_suite);
return fabric_client.getUserContext('user1', true);
}).then((user_from_store) => {
if (user_from_store && user_from_store.isEnrolled()) {
console.log('Successfully loaded user1 from persistence');
member_user = user_from_store;
} else {
throw new Error('Failed to get user1.... run registerUser.js');
}
tx_id = fabric_client.newTransactionID();
console.log("Assigning transaction_id: ", tx_id._transaction_id);
var request = {
chaincodeId: 'fabcar',
fcn: 'changeCarOwner',
args: [key,owner],
chainId: 'mychannel',
txId: tx_id
};
return channel.sendTransactionProposal(request);
}).then((results) => {
var proposalResponses = results[0];
var proposal = results[1];
let isProposalGood = false;
if (proposalResponses && proposalResponses[0].response &&
proposalResponses[0].response.status === 200) {
isProposalGood = true;
console.log('Transaction proposal was good');
} else {
console.error('Transaction proposal was bad');
}
if (isProposalGood) {
console.log(util.format(
'Successfully sent Proposal and received ProposalResponse: Status - %s, message - "%s"',
proposalResponses[0].response.status, proposalResponses[0].response.message));
var request = {
proposalResponses: proposalResponses,
proposal: proposal
};
var transaction_id_string = tx_id.getTransactionID();
var sendPromise = channel.sendTransaction(request);
promises.push(sendPromise);
let event_hub = channel.newChannelEventHub('localhost:7051');
let txPromise = new Promise((resolve, reject) => {
let handle = setTimeout(() => {
event_hub.disconnect();
resolve({event_status : 'TIMEOUT'});
}, 3000);
event_hub.connect();
event_hub.registerTxEvent(transaction_id_string, (tx, code) => {
clearTimeout(handle);
event_hub.unregisterTxEvent(transaction_id_string);
event_hub.disconnect();
var return_status = {event_status : code, tx_id : transaction_id_string};
if (code !== 'VALID') {
console.error('The transaction was invalid, code = ' + code);
resolve(return_status); // we could use reject(new Error('Problem with the tranaction, event status ::'+code));
} else {
console.log('The transaction has been committed on peer ' + event_hub.getPeerAddr());
resolve(return_status);
}
}, (err) => {
reject(new Error('There was a problem with the eventhub ::'+err));
});
});
promises.push(txPromise);
return Promise.all(promises);
} else {
console.error('Failed to send Proposal or receive valid response. Response null or status is not 200. exiting...');
res.send("Error: no car found");
}
}).then((results) => {
console.log('Send transaction promise and event listener promise have completed');
if (results && results[0] && results[0].status === 'SUCCESS') {
console.log('Successfully sent transaction to the orderer.');
res.json(tx_id.getTransactionID())
} else {
console.error('Failed to order the transaction. Error code: ' + response.status);
res.send("Error: no tuna catch found");
}
if(results && results[1] && results[1].event_status === 'VALID') {
console.log('Successfully committed the change to the ledger by the peer');
res.json(tx_id.getTransactionID())
} else {
console.log('Transaction failed to be committed to the ledger due to ::'+results[1].event_status);
}
}).catch((err) => {
console.error('Failed to invoke successfully :: ' + err);
res.send("Error: no car found");
});
})`
无法弄清楚我错过了什么。需要澄清这一点。
解决方案
有不同版本的示例会定期更新以反映 Fabric 版本的更新。你不能总是混合和匹配版本。另请注意,您在 Fabric 上的水平非常低…… Fabric 刚刚发布了 1.4.0 版。
我建议您从https://hyperledger-fabric.readthedocs.io/en/release-1.4/install.html开始获取最新版本的 Fabric 和 fabric-samples。
curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh | bash -s 1.4.0
将下载两者的 1.4 版。
推荐阅读
- python - 如果条件满足 else [],如何用 [element] 替换系列中的每个元素?
- python - TypeError:JSON 对象必须是 str,而不是 'DetailedResponse'
- python - 深度学习:如何处理缺失的标签值
- c# - 如何以编程方式退出正在运行的单元测试(使用 Visual Studio c# 和单元测试框架)
- c# - 像 PDF 签名一样使用 iTextSharp 签署 PDF 表单
- elasticsearch - Logstash 每日索引下个月的日期格式错误
- gitlab - GitLab CI:YAML 未运行
- neo4j - 为什么 Neo4j 检查点时间会随着图形大小的增加而增加?
- javascript - 宿主函数返回后的事件中可用的 JavaScript 局部范围变量。为什么?
- java - 一些Ashot策略有“模拟器”字样,它们之间有什么区别?