Hyperledger Composer通过Javascript API添加Participant

时间:2018-02-26 17:25:23

标签: hyperledger hyperledger-composer

我可以通过下面的命令行命令成功添加参与者。

Exception happened during processing of request from ('127.0.0.1', 40366)
Traceback (most recent call last):
File "/usr/lib/python3.5/socketserver.py", line 625, in process_request_thread
File "/usr/lib/python3.5/socketserver.py", line 354, in finish_request
File "/usr/lib/python3.5/socketserver.py", line 679, in __init__
File "/usr/lib/python3.5/socketserver.py", line 731, in setup
File "/usr/local/lib/python3.5/dist-packages/gevent/_socket3.py", line 229, in makefile
MemoryError

然而,当我尝试javascript API时,我收到此错误。

错误:尝试查询业务网络时出错。错误:链代码错误(状态:500,消息:错误:ID为'$ sysregistries'的集合中具有ID'Participant:org.acme.health'的对象不存在)     在channel.queryByChaincode.then.catch(/home/sara/health-network/angular-app/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:809:34)     在

这是我的javascript代码

composer participant add -c admin@health-network -d '{"$class": "org.acme.health.Patient", "patientId": "10", "firstName": "Mae", "lastName": "smith", "email": "smith@gmail.com"}'

我的.cto文件中有一个名为'Patient'的参与者。

1 个答案:

答案 0 :(得分:0)

@ethertest,我已将您的代码格式化如下。希望它有效。

const BusinessNetworkConnection = require('composer-client').BusinessNetworkConnection;
let businessNetworkConnection = new BusinessNetworkConnection();

return businessNetworkConnection.connect('admin@health-network')
.then((bconnect) => {
    let bfactory = bconnect.getFactory();

    return Promise.all([businessNetworkConnection.getParticipantRegistry('org.acme.health.Patient'), bfactory]);
})
.then((participantRegistry1) => {
    participantRegistry = participantRegistry1[0];
    bfactory = participantRegistry1[1];

    let participant = bfactory.newResource('org.acme.biznet', 'Patient', 'patient1');
    participant.firstName = 'Bob';
    participant.lastName = 'Miller';
    return participantRegistry.add(participant);
})
.then(() => {
    return businessNetworkConnection.disconnect();
})
.catch((error) => {
    console.error(error);
    process.exit(1);
});