用户在生成一个事务时候,被选举成提案者的用户可以对每个事务仅投票一次,该如何实现呢?

//SPDX-License-Identifier: MIT
pragma solidity >=0.7.6;
import "./Dust.sol";
contract timeFlow is dustProtocol{

    //用户
    mapping(address=>bool) private _thisAddressBool; //用户是否注册
    mapping(string=>address)private nameToAddress;
    mapping(address=>uint256)private userAddressToId;
    mapping(uint256=>string)private userIdToName;
    //审查者
    mapping(address=>bool)private addressToBool;
    //role
    mapping(address=>bool) private addressToRole;
    //事务
    mapping(string=>uint256)private contentNameToId;
    mapping(uint256=>address)private contentIdToAddress;

    //审核者是否对某一事件投票
    struct supervisorIfVoted{
        uint256 votedContentId;  //等于事务Id
        address[] voteGroup;     //已经投票的地址          
        address contentSource;   //事务发起者
    }
    supervisorIfVoted[] public _supervisorIfVoted;

    address[] public ballot;

    //注册
    function registered(string memory _thisName,string memory _userProfile)public payable{
        require(_thisAddressBool[msg.sender]!=true,"This address had register!");
        _thisAddressBool[msg.sender]=true;  
        nameToAddress[_thisName]=msg.sender;
        userAddressToId[msg.sender]=_userId;
        userIdToName[_userId]=_thisName;
        signUp(_thisName,_userProfile);
    }

    //添加审查者
    function addSupervisors(address waitAddress,string memory _supervisorName)public onlyOwner{
        require(_thisAddressBool[waitAddress]==true,"This address not register!");
        require(addressToBool[waitAddress]!=true,"This address was a Supervisor!");
        addressToBool[waitAddress]=true;//是否已经为审查者
        addressToRole[waitAddress]=true;//为用户添加role的bool
        addSupervisor(waitAddress,_supervisorName);
    }

    //移除审查者
    function deleteSupervisors(address waitAddress)public onlyOwner{
        require(addressToBool[waitAddress]==true,"This address not a Supervisor!");
        addressToRole[waitAddress]=false;
        //将地址role转移到黑洞地址
        delete addressToRole[waitAddress];
    }

    //创建事务
    function createSomething(string memory _contentName,string memory _willThing,uint256 _tradeMoney,uint256 _endTime,address _pointAddress)public payable{
        require(_thisAddressBool[msg.sender]==true,"This address not register!");
        contentNameToId[_contentName]=_contentId;   //根据事务名字,得到Id
        contentIdToAddress[_contentId]=msg.sender;
        createThing(_contentName,_willThing,_tradeMoney,_endTime,_pointAddress);
        _supervisorIfVoted.push(supervisorIfVoted(_contentId,ballot,msg.sender));
    }

    //用户名字返回地址
    function userNameToAddress(string calldata name)public view returns(address){
        return nameToAddress[name];
    }

    //用户地址返回Id
    function addressToUserId(address userAddress)public view returns(uint256){
        return userAddressToId[userAddress];
    }

    //用户Id返回名字
    function userIdToUserName(uint256 thisUserId)public view returns(string memory){
        return userIdToName[thisUserId];
    }

    //事务名字返回Id
    function contentNameToContentId(string memory name)public view returns(uint256){
        return contentNameToId[name];
    }

    //事务Id返回地址
    function contentIdToContentAddress(uint256 contentId)public view returns(address){
        return contentIdToAddress[contentId];
    }

    //审核者对事务投票
    function voteContent(string memory contentName)public payable{
        //是否是审查者
        require(addressToBool[msg.sender]==true,"This address not a Supervisor!");
         //判断地址是否投票
        _waitContentThing[contentNameToContentId(contentName)].votedSum++;
        //根据输入的name查找相应id
        uint256 getVotedId=contentNameToContentId(contentName);
        //将消息发送者地址push到数组里

        ballot.push(msg.sender);
        supervisorIfVoted memory supervisorBallet=supervisorIfVoted({
            votedContentId:getVotedId,
            voteGroup:ballot,       
            contentSource:contentIdToContentAddress(getVotedId)
        });
        _supervisorIfVoted.push(supervisorBallet);
    }

}

我使用地址数组放到struct里每次仅能push到一个地址到里面,而我要判断已投票的地址肯定是多个的,这样才能使得每个审查者仅能对每个事务投一次票

请先 登录 后评论

1 个回答

Tiny熊
  擅长:智能合约,以太坊
请先 登录 后评论
  • 1 关注
  • 0 收藏,1344 浏览
  • ? or ? 提出于 2022-12-12 11:18