我正在尝试创建一个动态规则构建器,我有一个角色管理器合同,看起来像这样:
import "@openzeppelin/contracts/access/Ownable.sol";
// The Ownable contract to manage the contract owner
contract RoleManager is Ownable {
mapping(bytes32 => function(bytes32, address, address[] memory, uint256[] memory, bytes[] memory, string memory) external view returns (bool)) public rules;
// Set the rule for the given role
function setRule(bytes32 role, function(bytes32, address, address[] memory, uint256[] memory, bytes[] memory, string memory) external view returns (bool) rule) public onlyOwner {
rules[role] = rule;
}
//...
}
也许我对function
参数的理解是错误的,我想建立一个动态函数,我如何在醚上生成一个函数来传递给这个?
使用界面:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/access/Ownable.sol";
interface IRule {
function rule (bytes32 data, address addr,
address[] memory addrArr, uint256[] memory uintArr,
bytes[] memory dataArr, string memory str)
external view returns (bool);
}
contract Demo is Ownable {
mapping(bytes32 => IRule) public rules;
function setRule(bytes32 role, IRule rule) public onlyOwner {
rules[role] = rule;
}
}