我已经在本地设置了超级账本区块链。我在 docker 容器中运行 hyperledger bc 服务。我能够成功启动节点,能够使用示例合约部署和写入 bc 。
但无法从区块链中读回数据。以下是 bc 抛出的错误消息。谁能指导这里有什么问题?
[ibc-js] Deploy Chaincode - Complete
{"query":{},"invoke":{},"details":{"deployed_name":"c123c14a65a511ee79e2a41b23726f473478d002064c01c3ce035cffa1229af083d73f1db220fc2f267b9ae31d66ce2e10113548e7abdf8812986ac3c5770a9c","func":{"invoke":["init","write"],"query":["read"]},"git_url":"https://github.com/IBM-Blockchain/learn-chaincode/finished","options":{"quiet":true,"timeout":60000,"tls":false},"peers":[{"name":"vp0-vp0...:49155","api_host":"127.0.0.1","api_port":49155,"id":"vp0","tls":false}],"timestamp":1470146338831,"users":[],"unzip_dir":"learn-chaincode-master/finished","version":"github.com/hyperledger/fabric/core/chaincode/shim","zip_url":"https://github.com/IBM-Blockchain/learn-chaincode/archive/master.zip"}}
sdk has deployed code and waited
[ibc-js] write - success: { jsonrpc: '2.0',
result:
{ status: 'OK',
message: '8b340e92-f96f-41f6-9b15-6ccb23304360' },
id: 1470146405598 }
write response: { jsonrpc: '2.0',
result:
{ status: 'OK',
message: '8b340e92-f96f-41f6-9b15-6ccb23304360' },
id: 1470146405598 }
[ibc-js] read - success: { jsonrpc: '2.0',
error:
{ code: -32003,
message: 'Query failure',
data: 'Error when querying chaincode: Error:Failed to launch chaincode spec(Could not get deployment transaction for c123c14a65a511ee79e2xxxxxxxxxxxxxxxxe7abdf8812986ac3c5770a9c - LedgerError - ResourceNotFound: ledger: resource not found)' },
id: 1470146405668 }
read response: null { name: 'query() resp error',
code: 400,
details:
{ code: -32003,
message: 'Query failure',
data: 'Error when querying chaincode: Error:Failed to launch chaincode spec(Could not get deployment transaction for c123c14a65a511ee79e2xxxxxxxxxxxxxxxxe7abdf8812986ac3c5770a9c - LedgerError - ResourceNotFound: ledger: resource not found)' } }
我使用 IBM Blockchain JS 与 go 合约进行交互。下面是节点js代码
// Step 1 ==================================
var Ibc1 = require('ibm-blockchain-js');
var ibc = new Ibc1(/*logger*/); //you can pass a logger such as winston here - optional
var chaincode = {};
// ==================================
// configure ibc-js sdk
// ==================================
var options = {
network:{
peers: [{
"api_host": "127.0.0.1",
"api_port": 49155,
//"api_port_tls": 49157,
"id": "vp4"
}],
users: null,
options: {quiet: true, tls:false, maxRetry: 1}
},
chaincode:{
zip_url: 'https://github.com/IBM-Blockchain/learn-chaincode/archive/master.zip',
unzip_dir: 'learn-chaincode-master/finished',
git_url: 'https://github.com/IBM-Blockchain/learn-chaincode/finished'
}
};
// Step 2 ==================================
ibc.load(options, cb_ready);
// Step 3 ==================================
function cb_ready(err, cc){ //response has chaincode functions
chaincode = cc;
console.log(JSON.stringify(cc));
chaincode.deploy('init', ['Hi hyperledger'], null, cb_deployed);
// Step 5 ==================================
function cb_deployed(){
console.log(JSON.stringify(chaincode));
console.log('sdk has deployed code and waited');
console.log('******** Writing to chaincode Now **********');
chaincode.invoke.write(["mykey","Hi Ledger Systems"],function(err,data){
console.log('write response:', data);
readData();
});
}
function readData()
{
console.log('\n\n**** Waiting 7 seconds before reading **** \n\n');
setTimeout(function () {
console.log('\n\n**** Start reading **** \n\n');
chaincode.invoke.read(["mykey"],function(err,data){
console.log('read response:', data);
});
}, 7000)
}
}