我正在尝试按照此处的教程:hyperledger-chaincode-for-developers 但是当我尝试像这样构建我的链代码时:
node main-chaincode.js --peer.address peer:7052
我收到以下错误消息:
错误:string类型的namevalue元素的值非法:undefined(不是字符串)失败(/opt/gopath/src/chaincode/lavinias_chaincode/node/node_modules/protobufjs/dist/protobuf.js:1817:23)在Field.ProtoBuf.Reflect.FieldPrototype.verifyValue(/)的Element.ProtoBuf.Reflect.ElementPrototype.verifyValue(/opt/gopath/src/chaincode/lavinias_chaincode/node/node_modules/protobufjs/dist/protobuf.js:1879:25)在Message.setter上的opt / gopath / src / chaincode / lavinias_chaincode / node / node_modules / protobufjs / dist / protobuf.js:3499:33)(/ opt / gopath / src / chaincode / lavinias_chaincode / node / node_modules / protobufjs / dist / protobuf.js:2582:77)在Function.start(/ opt / gopath / sr c / chaincode / lavinias_chaincode / node / node_modules / fabric -shim / lib / chaincode.js:118:15)at start(/opt/gopath/src/chaincode/lavinias_chaincode/node/main-chaincode.js:46:8)在对象。 (/opt/gopath/src/chaincode/lavinias_chaincode/node/main-chaincode.js:49:1)在Module._compile(module.js:643:30)处于Object.Module._extensions..js(module.js) :模块载荷(module.js:556:32):654:10)在Module.load(module.js:556:32)
这是我的链码:
'use strict';
const shim = require('fabric-shim');
const Chaincode = class {
async Init(stub) {
let ret = stub.getFunctionAndParameters();
let args = ret.params;
if(args.length != 2) {
return shim.error("Error. Invalid call arguments.")
}
await stub.putState(args[0], Buffer.from(args[1]));
return shim.success('Initialized Successfully!');
}
async Invoke(stub) {
let functionAndParams = stub.getFunctionAndParameters();
if(functionAndParams.fcn === 'get') {
return get(stub, functionAndParams.params);
}
else if(functionAndParams.fcn === 'set'){
return set(stub, functionAndParams.params);
}
return shim.error("Error. Invalid invocation.");
}
};
function get(stub, params) {
if(params.length != 1) {
return shim.error("Error. Invalid invocation call.");
}
return stub.getState(params[0]);
}
function set(stub, params) {
if(params.length != 2) {
return shim.error("Error. Invalid number of arguments.");
}
return stub.putState(params[0], params[1]);
}
var start = function start(){
var cc = new Chaincode();
shim.start(cc);
}
start();
hyperledger shim docs说只需要peer.address参数:shim.start
任何帮助都会得到真正的赞赏
答案 0 :(得分:0)
我通过观看此视频来解决这个问题:node chaincode
你应该像这样构建它:
CORE_CHAINCODE_ID_NAME="mycc:v0" node main-chaincode.js --peer.address peer:7052