使用具有参与者关系的交易添加资产

Add asset using a transaction with a participant's relation

我正在尝试使用交易添加资产,在该交易中我试图将资产的字段之一与参与者参考相关联。但是当我尝试使用资产获取参与者的姓名时,它显示 undefined

参与者已经存在。我不想使用此仅交易资产创建新参与者。

asset TestAsset identified by id {
  o String id
  --> TestPart part
}

participant TestPart identified by id {
  o String id
  o String name
}

transaction AddTestAsset {
  o String aId
  o String pId
}

Logic.js

function addTestAsset(tx) {
  var factory = getFactory();
  var NAMESPACE = 'org.acme';
  var newAsset = factory.newResource(NAMESPACE, 'TestAsset', tx.aId);
  newAsset.part = factory.newRelationship(NAMESPACE, 'TestPart', tx.pId);
  console.log(newAsset.part.name); //Showing undefined
  return getAssetRegistry(NAMESPACE + '.TestAsset')
        .then(function (aReg) {
            return aReg.add(newAsset);
        });

我从 UI 表格中得到 aIdpId

还有其他方法吗?

这个问题也在 Rocket.Chat 频道

上被提问和回答

https://chat.hyperledger.org/channel/composer

但这里是摘要:

对于您的 console.log(newAsset.part.name); 语句,name 元素未定义,因为参与者关系尚未解决。如果您使用 console.log(newAsset.part);,您会看到它是一个关系对象,而不是参与者。

可以为不存在的参与者创建关系。这里的设计是通过 ACL 限制你可能无法访问 'see' Participant,所以你可以创建关系。

您可以编写代码来检查 getParticipantRegistry

参与者是否存在