将资产添加到hyperledger时会出现特定字段缺失的错误

时间:2018-02-26 08:30:40

标签: hyperledger-fabric hyperledger-composer

我使用hyperledger composer playground创建了一个商业网络我希望在注册表中添加一个资产但是在添加它时说t:实例com.acn.hps.aops.ims.EvidenceDoc#4439缺少必填字段所有者

.cto file
asset EvidenceDoc identified by evidenceId{
  o String evidenceId
  o Owner owner
  }
participant Owner identified by AuthorityId{
  o String AuthorityId

   }
transaction addasset{
o EvidenceDoc evidenceDocJson
 }

.qry file
.qry file

enter code here
query getOwnerbyId{ 
      description: "Get owner of the evidence asset by its ID" 
      statement: 
      SELECT com.acn.hps.aops.ims.Superuser
      WHERE (AuthorityId == _$AuthorityId)

             } 
logic.js file

/**
* @param {com.acn.hps.aops.ims.AddEvidence} addAsset
* @transaction
*/
function AddingEvidence(addAsset){

    return getAssetRegistry('com.acn.hps.aops.ims.EvidenceDoc')
 .then(function (AssetRegistry) {
 // Get the factory for creating new asset instances.
 var factory = getFactory();
  var result = query('getOwnerbyId',

 {AuthorityId:'1'/*addAsset.evidenceDocJson.owner.AuthorityId*/});

// Create the Evidence.
  var evidence = factory.newResource('com.acn.hps.aops.ims', 'EvidenceDoc', 
  addAsset.evidenceDocJson.evidenceId);

     evidence.owner = result[0]

 // Add the asset to the asset registry.
  return AssetRegistry.add(evidence);
   })

   }

2 个答案:

答案 0 :(得分:0)

我不认为这里需要查询。试试这个。

.cto

namespace com.acn.hps.aops.ims
asset EvidenceDoc identified by evidenceId{
  o String evidenceId
  o Owner owner
  }
participant Owner identified by AuthorityId{
  o String AuthorityId
   }
transaction addasset{
o EvidenceDoc evidenceDocJson
 }

script.js

/**
* @param {com.acn.hps.aops.ims.addasset} addAsset
* @transaction
*/
function AddingEvidence(addAsset){

    return getAssetRegistry('com.acn.hps.aops.ims.EvidenceDoc')
 .then(function (AssetRegistry) {
 // Get the factory for creating new asset instances.
 var factory = getFactory();
// Create the Evidence.
  var evidence = factory.newResource('com.acn.hps.aops.ims', 'EvidenceDoc', 
  addAsset.evidenceDocJson.evidenceId);

     evidence.owner = addAsset.evidenceDocJson.owner

 // Add the asset to the asset registry.
  return AssetRegistry.add(evidence);
   })

   }

答案 1 :(得分:0)

因此,您的事务名称需要与事务逻辑中的param部分('addAsset'大写)匹配:

还建议将所有者作为与交易的关系传递

在你的模特中

transaction addAsset {
o String evidenceId
--> Owner owner
}

在您的交易代码中(类似):

/**
* @param {com.acn.hps.aops.ims.addasset} addAsset
* @transaction
*/
function AddingEvidence(addAsset){

console.log('participant is ' + addAsset.owner.AuthorityID);
console.log('getCurrentparticipant is ' + getCurrentParticipant());

// Get the factory for creating new asset instances.
var factory = getFactory();
// Create the Evidence.
var evidence = factory.newResource('com.acn.hps.aops.ims', 'EvidenceDoc', addAsset.evidenceId);

  evidence.owner.ID = addAsset.owner.AuthorityID;

  return getAssetRegistry('com.acn.hps.aops.ims.EvidenceDoc')
     .then(function (registry) {
         return registry.add(evidence );
     });


}