繁体   English   中英

提交交易时出错

[英]Error when submitting transaction

我有一些不寻常的问题。 以下代码可在在线游乐场中使用,但是当我在本地部署的其余服务器上使用生成的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
}

chaincode:

/**
 * 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>"
  }
}

有谁知道出什么问题了吗? 我真的很感谢您的帮助。

您的问题是模型文件,而不是事务代码。 您需要在“ Item和“ Trade的关系字段中使用“ Assembler而不是“ BU

  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#1并且它从Itemitems数组中更改了相关Items #1)

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

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

CTO:

/**
 * 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
}

抄送:

/**
 * 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', 'BU', trade.newOwner.getIdentifier());
         // persist the state of the ITEM with new owner as a relationship
         await assetRegistry.update(res);
    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM