Hyperledger composer 访问控制,允许在事务中创建

Hyperledger composer Access Control, allow create in transaction

这是我要实现的:

我想允许用户(某种类型的参与者)创建资产,但只能在交易中进行,而在此交易之外我想拒绝所有用户创建资产的权利。

我尝试使用以下函数使用规则 .acl 文件中的条件来解决它:

rule UserCanCreateAssetOnlyInTransaction {
    description: "Deny all participants create access to all userWallets if not in transaction"
    participant(p): "com.example.User"
    operation: CREATE
    resource(r): "com.example.UserAsset"
    condition:(isInTransactionF())
    action: ALLOW 
}

然后在事务中我将变量创建为 var isInTransaction = true;,并在 logic.js 文件中添加:

/**
@returns {boolean} boolean true/false
*/
function isInTransactionF(){
    if(isInTransaction){
      return true; 
    }else{
      return false;
    }   
}

它不起作用,当我调用创建访问权限应该起作用的唯一事务时,它说用户没有创建访问权限来提交此事务。 我想我做错了什么,有什么办法可以解决这个问题吗?

实现你想要的功能 - 你会说:

/**
@returns {boolean} boolean true/false
*/
function isInTransactionF() {
    var isInTransaction = true ;  // Boolean
    if(isInTransaction) {
    // if( Boolean(isInTransaction)) { // alternative
      return true; 
    } else{
      return false;
    }   
}

然后您当前的 ACL 将起作用。

我可以调用console.log查看返回结果

console.log("The return result is " + isInTransactionF() );`  // true

限制参与者只能通过特定交易创建资产 class - 规则看起来像(即只能通过此 class 创建资产 - 隐式应该是假设没有其他资产创建规则,在其他地方被拒绝):

rule CreateAssetThruTxn {
    description: "sample""
    participant(p): "com.example.User"
    operation: CREATE
    resource(r): "com.example.UserAsset"
    transaction(tx): "com.example.AssetCreate"
    condition:(true)
    action: ALLOW 
}

如果您的 ACL 失败,那么您需要查看哪些其他 ACL 规则可能允许通过其他方式创建此资产,但我提供的规则将是控制该资产的常用方式(基于您提供的信息在问题中提供)