问题
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