zoukankan      html  css  js  c++  java
  • [Contract] 一次搞懂 Solidity 的 using xx for xx

    using A for *;     # 把 A 的函数附给任意类型使用

    using A for B;  # 意思是把 A 中的方法附给 B 使用

    使用上面的方式,那么在我们的合约中定义了 B 类型的变量后,就可以像 B.xx() 这样使用 A 库的函数了。

    举个局部例子:_miners 可以直接使用 has 方法。

    library Roles {
        struct Role {
            mapping (address => bool) bearer;
        }
    
        /**
         * @dev Check if an account has this role.
         * @return bool
         */
        function has(Role storage role, address account) internal view returns (bool) {
            require(account != address(0), "Roles: account is the zero address");
            return role.bearer[account];
        }
    }
    
    contract MinterRole is Context {
        using Roles for Roles.Role;
    
        event MinterAdded(address indexed account);
        event MinterRemoved(address indexed account);
    
        Roles.Role private _minters;
    
        constructor () internal {
            _addMinter(_msgSender());
        }
    
        modifier onlyMinter() {
            require(isMinter(_msgSender()), "MinterRole: caller does not have the Minter role");
            _;
        }
    
        function isMinter(address account) public view returns (bool) {
            return _minters.has(account);
        }
    }

    Link:https://www.cnblogs.com/farwish/p/12560568.html

  • 相关阅读:
    GRIDVIEW导出到EXCEL
    .NET GRIDVIEW导出EXCEL
    C#自动列宽
    vue 路由跳转及传值和取值
    vue 部署windows nginx服务上
    vue多个代理配置vue.config
    mock常用规则
    git基础篇-常见错误
    git基础篇-使用教程
    win10 gitserver搭建
  • 原文地址:https://www.cnblogs.com/farwish/p/12560568.html
Copyright © 2011-2022 走看看