2017-09-28 16 views
0

私は、作者のGoLangで書かれたチェーンコードを再作成しようとしています。 Model.ctoHyperLedger Composer:Tranaction error TypeError:getAssetRegistry(...)。getが関数ではありません

asset Carton identified by cartonId { 
o String cartonId 
o String manufacturerId 
o String dateOfDeparture optional 
o String recipient optional 
o String currentOwner 
o String status 
--> Unit[] units optional 
o Trackrecord[] trackrecord optional 
} 
transaction MakeCarton { 
--> Unit[] unit 
o String Id 
} 
asset Unit identified by unitId { 
o String unitId 
o String cartonId 
o String manufacturerId 
o String dateOfDeparture 
o String recipient 
o Trackrecord[] trackrecord 
o String currentOwner 
o String status 
    } 

だから私は1個のカートンを作成し、単位とcartonIdの配列を受け取り、トランザクションを作成する必要があります。すべてのカートンにはいくつかのユニットが含まれており、ユニットも資産ですので、私は世界のユニット資産のカートンIDを更新する必要があります。このトランザクションを提出

function makeCarton(make) { 
    var carton = getFactory().newResource('org.acme.mynetwork','Carton',make.Id); 
    //carton.cartonId = make.Id ; 
    var unitobjs = new Array() ; 
    for(var i=0; i < make.unit.length ; i++) { 
    var unitobj = getFactory().newResource('org.acme.mynetwork','Unit',make.unit[i].unitId) ; 
    unitobj.cartonId = make.Id ;  
    unitobj = getFactory().newRelationship('org.acme.mynetwork','Unit',make.unit[i].unitId) ; 
    unitobjs.push(unitobj) ; 
    } 

    carton.units = unitobjs ; 

    // getFactory().newRelationship('org.acme.mynetwork','Unit',make.unit[i].unitId) 
    for(var i=0; i < make.unit.length ; i++) { 
    carton.manufacturerId= make.unit[i].manufacturerId ; 
    carton.currentOwner = make.unit[i].currentOwner ; 
    carton.status = 'At '+ make.unit[i].currentOwner ; 
     } 

     return getAssetRegistry('org.acme.mynetwork.Carton').then(function (assetRegistry) { 
    // Update the asset in the asset registry. 
     return assetRegistry.add(carton).then(function() { 
     for(var i=0; i < make.unit.length ; i++) { 
     return getAssetRegistry('org.acme.mynetwork.Unit').then(function (unitRegistry) { 

     // var unitobj = getFactory().newResource('org.acme.mynetwork','Unit',make.unit[i].unitId) ; 
      var unitobj = getAssetRegistry('org.acme.mynetwork.Unit').get(make.unit[i].unitId); 
      //unitRegistry.get(make.unit[i].unitId); 
    unitobj.cartonId = make.Id ;  
     return unitRegistry.update(unitobj); 
    }) 
     //.then(function(unitobj){ 
    //unitobj.cartonId = make.Id; 
    //untiRegistry.update(unitobj);}); 
    } 
}); 
}); 
} 

はTypeError生成します。getAssetRegistry(...)を取得資産レジストリにPromiseを返すvar unitobj = getAssetRegistry('org.acme.mynetwork.Unit').get(make.unit[i].unitId);

答えて

0

ライン機能ではないので、あなたはあなたのような.thenを必要としますあなたの他のgetAssetRegistry()を呼び出す必要があります。

これは役立つかもしれない:私は(コメントを参照)、それはエラーを与えていた原因それも試すが、後でそれをコメントしなかった https://github.com/hyperledger/composer-sample-networks/blob/master/packages/perishable-network/lib/logic.js#L89

+0

:未定義unitobj。 –

+0

'var unitobj'は当時の' {} 'スコープの中で定義されています。したがって、その後の「当時」の範囲外である。それをより高い範囲に移動する必要があります。 –

関連する問題