Hyperledger作曲家调用外部REST API

时间:2018-03-30 19:14:31

标签: hyperledger hyperledger-composer

我是hyperledger作曲家的开发人员。我尝试使用Calling an HTTP or REST API from Transaction Processor Functions方法POST和请求正文,但我有错误状态代码500.我想使用带有请求主体的方法POST到我的服务器。

我的代码:

async function testStocks(transaction) {

    const participant = getCurrentParticipant();
    const json = '{"name:tester"}';//my request body

    await request.post({ uri: 'http://www...', json });

    // Update the current participant in the participant registry.
    const participantRegistry = await getParticipantRegistry('org.example.Trader');
    await participantRegistry.update(participant);

}

我的错误:

{
  "error": {
    "statusCode": 500,
    "name": "Error",
    "message": "Error trying invoke business network. Error: No valid responses from any peers.\nResponse from attempted peer comms was an error: Error: 2 UNKNOWN: error executing chaincode: transaction returned with failure: StatusCodeError: 400 - undefined",
    "stack": "Error: Error trying invoke business network. Error: No valid responses from any peers.\nResponse from attempted peer comms was an error: Error: 2 UNKNOWN: error executing chaincode: transaction returned with failure: StatusCodeError: 400 - undefined\n    at _initializeChannel.then.then.then.then.catch (/home/pc/.nvm/versions/node/v8.10.0/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:965:34)\n    at <anonymous>"
  }
}

1 个答案:

答案 0 :(得分:0)

participant变量在await participantRegistry.update(participant);中未定义。

您缺少示例@ https://hyperledger.github.io/composer/latest/integrating/call-out中的代码。

// Get the current participant, and update their stock and balance.
const participant = getCurrentParticipant();
// update participant here...  <<--------------------

// Update the current participant in the participant registry.
const participantRegistry = await getParticipantRegistry('org.example.Trader');
await participantRegistry.update(participant);