我在这里尝试遵循教程:
hyperledger-chaincode-for-developers
但当我尝试构建这样的链码时:
node main-chaincode.js --peer.address peer:7052
我收到以下错误消息:
错误:字符串类型的namevalue元素的值非法:未定义(不是字符串)at fail(/opt/gopath/src/chaincode/lavinias\u chaincode/node/node\u modules/protobufjs/dist/protobuf.js:1817:23)at元素。ProtoBuf。反映ElementPrototype。验证字段中的值(/opt/gopath/src/chaincode/lavinias\u chaincode/node/node\u modules/protobufjs/dist/protobuf.js:1879:25)。ProtoBuf。反映FieldPrototype。消息中的验证值(/opt/gopath/src/chaincode/lavinias\u chaincode/node/node\u modules/protobufjs/dist/protobuf.js:3499:33)。函数处的setter(/opt/gopath/src/chaincode/lavinias\u chaincode/node/node\u modules/protobufjs/dist/protobuf.js:2582:77)。在对象的开始处(/opt/gopath/src/chaincode/lavinias\u chaincode/node/node\u modules/fabric shim/lib/chaincode.js:118:15)启动(/opt/gopath/src/chaincode/lavinias\u chaincode/node/main chaincode.js:46:8)。(/opt/gopath/src/chaincode/lavinias\u chaincode/node/main chaincode.js:49:1)at模块_在对象处编译(module.js:643:30)。模块_扩展。。模块处的js(模块js:654:10)。在模块处加载(模块js:556:32):654:10)。加载(模块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文档表示,只有对等方。地址参数是必需的:
shim.start
任何帮助都将不胜感激