提交交易时出错

时间:2018-08-16 13:29:17

标签: hyperledger-fabric hyperledger blockchain hyperledger-composer

我有一些不寻常的问题。以下代码可在在线游乐场中使用,但是当我在本地部署的其余服务器上使用生成的API时,id无效。尝试过帐交易时出现错误。 cto文件:

namespace org.dps.track

asset Item identified by itemId{
    o String itemId
    o String name
    o String idgId
    o String serialNumber
    o String comment
    --> BU owner
    --> Item [] items optional
}

participant BU identified by buId{
    o String buId
    o String name
    o String country
    o String city
}

participant Assembler extends BU{
}

participant Manufacturer extends BU{
}

transaction Trade{
    --> Item item
    --> BU newOwner
}

enum status{
  o IN_TRANSIT
  o DEPARTURED
  o DELIVERED
}

链码:

/**
 * Sample transaction processor function.
 * @param {org.dps.track.Trade } trade - the sample transaction instance.
 * @transaction
 */
async function tradeCommodity(trade) {

    const factory = getFactory();
    trade.item.owner = trade.newOwner;
    var list = [];
    if (trade.item.items && trade.item.items.length > 0) {
        trade.item.items.forEach((asset) => {
        list.push(asset);
        });
    }  


    const assetRegistry = await getAssetRegistry('org.dps.track.Item');


    // persist the state of the current ITEM
    await assetRegistry.update(trade.item);

    for (var i = 0; i < list.length; ++i) {

         let res = await assetRegistry.get(list[i].getIdentifier());
         res.owner = factory.newRelationship('org.dps.track', 'Assembler', trade.newOwner.getIdentifier());
         // persist the state of the ITEM with new owner as a relationship
         await assetRegistry.update(res);
    }

}

当尝试通过Rest API发布交易时,出现错误:

{

  "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: transaction returned with failure: Error: Could not find any functions to execute for transaction org.dps.track.Trade#e4764be8e037c7186774512860c0cde6d7eaed5c301ddf36c4c1ab560577861a",
    "stack": "Error: Error trying invoke business network. Error: No valid responses from any peers.\nResponse from attempted peer comms was an error: Error: transaction returned with failure: Error: Could not find any functions to execute for transaction org.dps.track.Trade#e4764be8e037c7186774512860c0cde6d7eaed5c301ddf36c4c1ab560577861a\n    at HLFConnection.invokeChainCode (/home/bryczek/.nvm/versions/node/v8.11.3/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:1002:30)\n    at <anonymous>"
  }
}

有人知道错在哪里吗?我真的很感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

您的问题是您的模型文件,而不是交易代码。对于AssemblerBU

,在关系字段中需要Item而不是Trade
  1. 您的资产应为:

    asset Item identified by itemId{
            o String itemId
            o String name
            o String idgId
            o String serialNumber
            o String comment
            --> Assembler owner
            --> Item [] items optional
        }

Assembler是资源类(不是BU,它是扩展类-对此没有注册表)。

  1. 您的交易Trade也应反映相同的资源,即(不是BU):

     transaction Trade{
            --> Item item
            --> Assembler newOwner
        }

除此之外,它应该可以与您现有的代码配合使用(已在Fabric网络上对其进行了测试,并使用我的REST API中的以下示例Trade事务(其中先前的所有者为Assembler#1Items#1)的items数组中与Item相关的更改

{
  "$class": "org.dps.track.Trade",
"item":"resource:org.dps.track.Item#1",
"newOwner":"resource:org.dps.track.Assembler#2"
}

答案 1 :(得分:0)

我修改了模型文件,现在尝试生成其余的API,但我只获得System(常规业务网络方法),没有Item,BU和Trade API,为什么会这样?

cto:

select skuid, description
from ((select skuid, description, 1 as priority
       from skus
      ) union all
      (select distinct left(skuid, 12) as skuid, 'New', 2
       from skus
      )
     ) sd
order by skuid, priority;

cc:

/**
 * New model file
 */

namespace org.dps.track


//asset section
asset Item identified by itemId{
    o String itemId
    o String name
    o String idgId
    o String serialNumber
    o String comment
    --> BU owner
    --> Item [] items optional

} 

//participant section
participant BU identified by buId{
    o String buId
    o String name
    o String country
    o String city
    o participantType type
}


//tranasaction section

transaction Trade{
    -->Item item
    -->BU newOwner
}

enum status {
    o IN_TRANSIT
    o DEPARTURED
    o DELIVERED
}

enum participantType{
    o Manufacturer
    o Assembler
}