AssetRegistry.get function is not returning the complete object in Hyperledger Composer

偶尔善良 提交于 2020-01-16 21:56:07

问题


It is an inheritance, Record has a reference of SampleAsset and SampletAsset has a reference of SampleParticipant.
In transaction I am sending record object and when i am printing it on console It is showing complete information of Sample asset and complete information of SampleParticipant,
while I am trying to fetch it using get method it is not returning the complete information of the objects. Please check the screenshot: Record Object getObject
SampleParticipant(owner) reference is not there.

Please check the below chain code:

namespace org.test.network

asset SampleAsset identified by assetId {
  o String assetId
  --> SampleParticipant owner
}

asset Record identified by recordId {
  o String recordId
  --> SampleAsset asset
}

participant SampleParticipant identified by participantId {
  o String participantId
  o Double balance
}

transaction getRecord {
  --> Record record
}

Transaction Function:

async function get(getTx) {
  const record = getTx.record;

  let assetRegistry = await getAssetRegistry('org.test.network.Record');

  let recordFromReg = await assetRegistry.get(record.$identifier);
  console.log(record);
  console.log(recordFromReg);
}

回答1:


When a transaction function is called the 'relationships' are all 'resolved' automatically as explained here.

When you retrieve an Asset you have to 'resolve' the relationship yourself. Ideally there would be a '.resolve' method that would do it for you, but as this issue points out it is not present in the runtime API.

When/if you write any code using the JavaScript API you will find that there is a resolve method.



来源:https://stackoverflow.com/questions/52816276/assetregistry-get-function-is-not-returning-the-complete-object-in-hyperledger-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!