【问题标题】:Getting Error: http: read on closed response body from Transaction Processor function in Hyperledger Composer出现错误:http:从 Hyperledger Composer 中的事务处理器函数读取已关闭的响应正文
【发布时间】:2018-09-07 13:09:48
【问题描述】:

我有一个使用简单 BNA 运行的结构网络。这个 BNA 定义了两种类型的参与者,即。公司和个人。在这里,每个人都与公司有如下关系(cto 文件):

participant Corporate identified by corporateId {
    o String corporateId
    o String corporateName
}
participant Person identified by personId {
    o String personId
    --> Corporate corporate
}

我正在尝试做的事情:

  1. 使用事务处理器功能创建公司:成功
  2. 使用事务处理器函数创建人员:失败

以下是 #2 的事务处理器函数的 sn-p:

let corporateIdExpected = personDetails.corporate;

if(corporateIdExpected && corporateIdExpected != '') {
    let corporateRetrieved = await query("GetCorporateByCorporateId", {corporateId: corporateIdExpected});
    if(!corporateRetrieved || corporateRetrieved == '') {
        throw new Error("Corporate details not valid. Please check if your corporate is present on the network.");
    }
}

来自我的 queries.qry 的片段:

query GetCorporateByCorporateId {
  description: "Returns all corporates in the registry"
  statement:  
      SELECT  org.samplenetwork.participants.Corporate
          WHERE (corporateId == _$corporateId)
}

所以,当我尝试 #2 时出现以下错误:

错误:2 UNKNOWN:错误执行链代码:交易返回失败:错误:错误:http:在关闭的响应正文上读取

但是,当我尝试直接从 swagger 执行查询时,它运行成功。

我正在使用:

超级账本结构:1.1 超级账本作曲家:0.19.8

我是否遗漏了任何检查或步骤?

【问题讨论】:

    标签: hyperledger-fabric hyperledger hyperledger-composer


    【解决方案1】:

    对于第 2 项 - 您实际上并不需要每次都执行命名查询。

    您可以按如下方式进行等效检查(“他是否已经存在?”)(下面的trxn 是您的事务定义等中定义的事务对象):

    const personRegistry = await getParticipantRegistry('org.acme.example.Person');
    console.log("The person identifier to check is " + trxn.corporate.getIdentifier() ) 
    
    const exists = await personRegistry.exists(trxn.corporate.getIdentifier() ) ;
    
    console.log("exists is set to " + exists); // boolean
    
    if (exists)
            console.log("he exists") 
    else
            console.log("he doesn't exist");
    

    【讨论】:

    • 我试过这种方式。它不断抛出:“错误:对象类型或属性不是非零长度字符串”。我已经确保我为这个提供了正确的价值。另外,我相信我需要在很多地方使用命名查询。我重写了函数,现在 TP 中的查询导致:“使用 Serializer.toJSON() 将资源转换为 JSON 对象”。我使用了它,然后它导致“未定义/引用序列化程序”。还尝试使用“getSerializer()”。它也导致“使用 Serializer.toJSON()...
    • 对,我只看到了你的代码的 sn-p。您的函数的其他部分似乎不起作用(听起来您正试图将 Resource 视为 JSON 对象)。如果您想将其作为一个单独的问题发布,请随意,确切地说您想要做什么(即我的结果应该是什么样子)。上面的建议是基于你对最初问题的看法(即检查是否存在)。
    • 完美。得到它与你提到的方式工作。实际上,我来自 Java 背景,所以对于 JavaScript 语义和语法有一点学习曲线。另外,我相信我错误地使用了查询。但是,我会尝试并更新此线程:github.com/hyperledger/composer/issues/4246
    猜你喜欢
    • 2021-04-29
    • 1970-01-01
    • 2014-04-27
    • 2017-12-18
    • 1970-01-01
    • 1970-01-01
    • 2019-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多