hyperledger composer 在交易过程中将参与者添加到参与者数组

hyperledger composer adding Participants to array of Participants in transaction process

我定义了 Participantasset 如下,我想将特定参与者添加到 access[type Participant] 数组中交易。谁能告诉我这是怎么做到的。

如何将参与者标识添加到数组中。我如何需要通过params传递身份,然后将其添加到参与者数组中。我已经根据我之前提出的问题创建了权限。

资产申报

asset Details identified by detailsId {
     o String detailsId
     o String description optional
     --> Bank owner
     o Bank[] access optional
     o String document 
}

参与者声明

participant Bank identified by bankId {
   o String bankId
   o String Name
}

您对 ACL 示例和本示例之间的模型做了一个小改动 - 更改了之前作为关系的访问数组。

--> Bank[] access optional    original
  vs
o Bank[] access optional      here  

基于原始模型,首先将此交易添加到模型中:

transaction AddAccess {
  --> Details details
  --> Bank additionalAccess
}

那么,这个脚本化交易应该适合你:

/**
 * Adding a Bank to an access list
 * @param {org.example.test.AddAccess} addA 
 * @transaction
 */
async function addAccess(addA) { 

  // Add the new access to the array, checking if empty first as it is optional field at creation
  if (typeof addA.details.access == 'undefined') {
    addA.details.access = new Array();
    addA.details.access[0] = addA.additionalAccess;
  } 
  else {
    addA.details.access.push(addA.additionalAccess);
  }

  // get the Registry
  const assetRegistry = await getAssetRegistry('org.example.test.Details');

  // Update the Registry with the new details
  await assetRegistry.update(addA.details);
}

像这样使用 JSON 进行测试:

{
  "$class": "org.example.test.AddAccess",
  "details": "resource:org.example.test.Details#D11",
  "additionalAccess": "resource:org.example.test.Bank#9241"
}