错误:hyperledger-fabric !! Error:ID为'X'的集合中ID为'X'的对象不存在

时间:2019-07-18 12:22:02

标签: hyperledger

当我尝试时,

  1. SetupOrder
  2. CreateTransfer

使用以下代码,我得到此错误。

  

错误:不允许尝试在InvalidRelationship上获取属性transfername。由于ID为'Asset:com.biz.Goods'的集合中ID为'20190718200228909'的对象而创建的InvalidRelationship不存在

models.cto:

Functor

js:

namespace com.biz
asset Transfer identified by date
{
    o String cargonum
    o String tranname
    o String date
}

transaction CreateTransfer
{
    --> Goods goodsnum
    o String tranname
}
/**
 * The movement status for a goods
 */
enum MovementStatus {
  o IN_FIELD
  o IN_TRANSIT
}

/**
 *
 */
asset Receiver identified by receiver_id{
  o String receiver_id
}
/**
 * 
 */
asset Goods identified by order_number {
    o String order_number
    o String goodsName
    o String receiver_id
    o MovementStatus movementStatus
    o String transfername
}

/**
 * 
 */
asset Site identified by site_name {
     o String site_name
}

/**
 * An abstract transaction type for goods movements
 */
transaction GoodsMovementArrival {

    --> Receiver receiver
    --> Goods goods
}

transaction SetupOrder  {
    o String goods_name
    o String begin_point_name
    o String end_point_name
}

acl:

'use strict';
/**
 *
 * @param {com.biz.CreateTransfer} transfer - model instance
 * @transaction
 */
async function createTransfer(transfer) 
{
    Date.prototype.format = function(fmt) 
    { 
        var o = 
        { 
            "M+" : this.getMonth()+1,                  
            "d+" : this.getDate(),                     
            "h+" : this.getHours(),                   
            "m+" : this.getMinutes(),                 
            "s+" : this.getSeconds(),                
            "q+" : Math.floor((this.getMonth()+3)/3), 
            "S"  : this.getMilliseconds()             
        }; 
        if(/(y+)/.test(fmt)) 
        {
            fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
        }
        for(var k in o) 
        {
            if(new RegExp("("+ k +")").test(fmt))
            {
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
            }
        }
        return fmt; 
    } 
    const factory = getFactory();
    const NS = 'com.biz';
    const transfers = [
        factory.newResource(NS, 'Transfer', 'TRANSFER'+(new Date()).format("yyyy-MM-dd hh:mm:ss.S"))
    ];
    transfers.forEach(function(trans) {
        trans.cargonum=transfer.goodsnum.order_number;
        trans.tranname=transfer.tranname;
        trans.date=(new Date()).format("yyyy-MM-dd hh:mm:ss.S");
    });
    transfer.goodsnum.transfername=transfer.goodsnum.transfername+'-'+transfer.tranname;
    const transferRegistry = await getAssetRegistry(NS + '.Transfer');
    await transferRegistry.addAll(transfers);
}


/**
 *
 * @param {com.biz.GoodsMovementArrival} movementArrival - model instance
 * @transaction
 */
async function onGoodsMovementArrival(movementArrival) {  // eslint-disable-line no-unused-vars
    console.log('onGoodsMovementArrival');



     // set the movement status of the animal
    if (movementArrival.goods.movementStatus != 'IN_TRANSIT') 
    {
        throw new Error('Animal is not IN_TRANSIT');
    }
    if (movementArrival.receiver.receiver_id==movementArrival.goods.receiver_id)
    {
      movementArrival.goods.movementStatus = 'IN_FIELD';
    }
}

/**
 *
 * @param {com.biz.SetupOrder} setupOrder - SetupOrder instance
 * @transaction
 */
async function SetupOrder(setupOrder) {// eslint-disable-line no-unused-vars

  Date.prototype.format = function(fmt) 
    { 
        var o = 
        { 
            "M+" : this.getMonth()+1,                  
            "d+" : this.getDate(),                    
            "h+" : this.getHours(),                   
            "m+" : this.getMinutes(),                 
            "s+" : this.getSeconds(),                 
            "q+" : Math.floor((this.getMonth()+3)/3), 
            "S"  : this.getMilliseconds()             
        }; 
        if(/(y+)/.test(fmt)) 
        {
            fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
        }
        for(var k in o) 
        {
            if(new RegExp("("+ k +")").test(fmt))
            {
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
            }
        }
        return fmt; 
    } 

    const factory = getFactory();
    const NS = 'com.biz';


    const goods = [
        factory.newResource(NS, 'Goods', 'Goods'+(new Date()).format("yyyyMMddhhmmssS"))
    ];

    const begin = [
        factory.newResource(NS, 'Site', 'begin_point'+(new Date()).format("yyyy-MM-dd hh:mm:ss.S"))
    ];

    const end = [
        factory.newResource(NS, 'Site', 'end_point'+(new Date()).format("yyyy-MM-dd hh:mm:ss.S"))
    ];
    var r_id;
    const receiver = [
        factory.newResource(NS, 'Receiver', 'Receiver'+(new Date()).format("yyyy-MM-dd hh:mm:ss.S"))
    ];
    receiver.forEach(function(receiver) {
        receiver.receiver_id=Math.random().toString(36).slice(-8);
        r_id=receiver.receiver_id;
    });
    const receiverRegistry = await getAssetRegistry(NS + '.Receiver');
    await receiverRegistry.addAll(receiver);  

    goods.forEach(function(good) {
    good.order_number=(new Date()).format("yyyyMMddhhmmssS");
    good.goodsName=setupOrder.goods_name;
    good.receiver_id=r_id;
    good.movementStatus='IN_TRANSIT';
    good.transfername='';
    });
    const goodsRegistry = await getAssetRegistry(NS + '.Goods');
    await goodsRegistry.addAll(goods);

    begin.forEach(function(begin) {
        begin.site_name=setupOrder.begin_point_name+(new Date()).format("yyyy-MM-dd hh:mm:ss.S");
    });
    const beginRegistry = await getAssetRegistry(NS + '.Site');
    await beginRegistry.addAll(begin);

    end.forEach(function(end) {
        end.site_name=setupOrder.end_point_name+(new Date()).format("yyyy-MM-dd hh:mm:ss.S");
    });
    const endRegistry = await getAssetRegistry(NS + '.Site');
    await endRegistry.addAll(end);    

}

请帮助我解决该问题。

0 个答案:

没有答案