关灯

Passing enum argument to function

  [复制链接]
区块链技术 发表于 2019-1-1 02:33:24 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
 

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x

So i have this enum, which is later used in struct definition in another contract. i wonder if this is a correct way to use enums in solidity?

Additionally, when i run this in remix, addRight function of RightsRegistry contract expects an address as _rightsType parameter. Which i suppose means that reference to the rights contract was created instead.

Question: what is the correct way to implement this logic?

enum:

contract RightsEnum {

  enum Rights {
      VIEWER,
      OWNER,
      CARETAKER
  }
  Rights rights;

    constructor() public {
        rights = Rights.VIEWER;
    }

  function setValues(uint _value) public {
      require(uint(Rights.OWNER) >= _value);
      rights = Rights(_value);
  }

  function getValue() public view returns (uint){
      return uint(rights);
  }

}

usage:

contract RightsRegistry {

    struct Right 
    {
        address holderEntity;
        address targetEntity;
        RightsEnum rightsType;
        address rightsContract;
        string infoUrl;
        uint status;
        uint startTime;
        uint expireTime;
    }

    Right[] rights;

    function addRight(address _targetEntity, address _holderEntity, RightsEnum _rightsType) 
        public
    {
    }
}



上一篇:web3js 1.0 fromWei throwing although passing correct type
下一篇:How to check Balance & send ERC721 Tokens
回复

使用道具 举报

 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

排行榜

关注我们:微信订阅号

官方微信

APP下载

全国服务邮箱:

admin@xuesq.cn

公司地址:重庆南岸区学府大道

运营中心:重庆微生派网络工作室

邮编:610066 Email:1401171837#qq.com

Copyright   ©2017-2018  中比特Powered by©xuesq.cn!技术支持:中比特    ( 蜀ICP备16009247号-1 )