代码之家  ›  专栏  ›  技术社区  ›  bryniek

提交事务时出错

  •  0
  • bryniek  · 技术社区  · 7 年前

    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);
        }
    
    }
    

    {
    
      "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 回复  |  直到 7 年前
        1
  •  0
  •   Paul O'Mahony    7 年前

    您的问题是模型文件,而不是事务代码。你需要 Assembler BU 在关系领域 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
            }
    
    

    汇编程序 是资源类(而不是BU,这是一个扩展类,没有注册中心)。

    1. 贸易 也应反映相同的资源,即(非业务部门):
         transaction Trade{
                --> Item item
                --> Assembler newOwner
            }
    
    

    贸易 我的REST API中的事务,以前的所有者是 Assembler#1 Items items 数组 #(一)

    {
      "$class": "org.dps.track.Trade",
    "item":"resource:org.dps.track.Item#1",
    "newOwner":"resource:org.dps.track.Assembler#2"
    }
    
        2
  •  0
  •   bryniek    7 年前

    首席技术官:

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