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

时间:2018-08-28 08:41:44

标签: hyperledger-fabric hyperledger-composer

我已经如下定义了参与者资产,我想向交易中的访问权限[类型参与者]数组添加特定参与者。有人可以告诉我该怎么做。

如何将参与者身份添加到阵列中。我需要如何通过参数传递身份,然后将其添加到参与者数组中。我已经根据我之前询问的问题创建了权限。 Link to the question for permission

资产声明

List<DbSet<Panel>> dbPanelList = new List<DbSet<Panel>>();
dbPanelList.Add((DbSet<Panel>)Db1Panels.Select(g => g as Panel)); // NOT WORKING! Cast Exception
dbPanelList.Add((DbSet<Panel>)Db2Panels.Cast<DbSet<Panel>>()); // NOT WORKING! Cast Exception
Panels = dbPanelList.ToArray();

参与者声明

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

1 个答案:

答案 0 :(得分:2)

您已在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"
}