首页 > 解决方案 > 检测到循环 ACL 规则,规则条件正在调用相同的规则

问题描述

在超级账本中添加新数据时出现错误。

更新工作正常。

这是我面临问题的一​​些代码

if(isExist) {
                const oldProOwnVal =  await PropertyOwnersRegistry.get(isExist.ownershipId);

                owners.ownership_start_date = oldProOwnVal.ownership_start_date;
                owners.created_at = oldProOwnVal.created_at;
                owners.updated_at = updatedProperty.timestamp;
                const mergeOwner = Object.assign(oldProOwnVal, owners);
                await PropertyOwnersRegistry.update(mergeOwner);
            } else {
                newKey =  'xxxx-xxxx-4xxx-yxxx-xxxx'.replace(/[xy]/g, function(c) {
                    var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
                    return v.toString(16);
                });
                const newOwnerRes = factory.newResource(NS, 'PropertyOwners', newKey);


                owners.ownership_start_date = updatedProperty.timestamp;
                owners.created_at = updatedProperty.timestamp;
                owners.updated_at = updatedProperty.timestamp;
                const newOwner = Object.assign(newOwnerRes, owners);
                await PropertyOwnersRegistry.add(newOwner);
            }

问题只发生在行中

await PropertyOwnersRegistry.add(newOwner);

不知道这里发生了什么。

标签: hyperledger-fabrichyperledgerhyperledger-composer

解决方案


这可能是您在调用 Composer API 之前的设置方式 - 例如getAssetRegistry(资产)或getParticipantRegistry(参与者) - 否则它超出了add第 2 部分的范围。我没有看到您的模型或之前的代码 -所以在下面酌情补充:

这应该有效(未尝试过) - 注意 - 如果您正在测试背书等,您有不确定的代码:

const NS = 'org.acme.example';
var factory = getFactory();

const  propRegistry = await  getAssetRegistry(NS+ '.PropertyOwners'');

if(isExist) {
    const oldProOwnVal =  await propRegistry.get(isExist.ownershipId);

    owners.ownership_start_date = oldProOwnVal.ownership_start_date;
    owners.created_at = oldProOwnVal.created_at;
    const mergeOwner = Object.assign(oldProOwnVal, owners);
   //etc

    await propRegistry.update(mergeOwner);
 } else {           
     newKey =  'xxxx-xxxx-4xxx-yxxx-xxxx'.replace(/[xy]/g, function(c) {
                    var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);  // this code is non-deterministic
                    return v.toString(16);
                });
     const newOwnerRes = factory.newResource(NS, 'PropertyOwners', newKey);
     owners.ownership_start_date = updatedProperty.timestamp;
     owners.created_at = updatedProperty.timestamp;
     owners.updated_at = updatedProperty.timestamp;

     const newOwner = Object.assign(newOwnerRes, owners);

     await propRegistry.add(newOwner);
 }

推荐阅读