0
pragma solidity ^0.8.0;

contract EvacDAO {
    struct EvacuationMap {
        address submitter;
        string mapData;
        bool isValid;
    }

    mapping(uint256 => EvacuationMap) public maps;
    mapping(address => uint256) public stakes;
    mapping(address => bool) public hasSubmitted;

    uint256 public mapCount;
    uint256 public votingPeriod;
    uint256 public feePercentage;
    uint256 public slashingPercentage;

    constructor(uint256 _votingPeriod, uint256 _feePercentage, uint256 _slashingPercentage) {
        votingPeriod = _votingPeriod;
        feePercentage = _feePercentage;
        slashingPercentage = _slashingPercentage;
    }

    function submitMap(string memory _mapData) external {
        require(!hasSubmitted[msg.sender], "You have already submitted a map.");
        
        uint256 currentMapCount = mapCount;
        maps[currentMapCount] = EvacuationMap(msg.sender, _mapData, false);
        hasSubmitted[msg.sender] = true;
        mapCount++;

        // Stake funds
        stakes[msg.sender] += 1 ether;
    }

    function validateMap(uint256 _mapId, bool _isValid) external {
        require(msg.sender != maps[_mapId].submitter, "Cannot validate your own map.");

        // Update map validity
        maps[_mapId].isValid = _isValid;

        // Pay rewards to validator
        if (_isValid) {
            uint256 fee = (feePercentage * 1 ether) / 100;
            uint256 reward = fee * (stakes[msg.sender] / totalStakes());
            payable(msg.sender).transfer(reward);
        } else {
            // Slash funds for submitting an invalid map
            uint256 slashingFee = (slashingPercentage * 1 ether) / 100;
            uint256 slashAmount = slashingFee * stakes[msg.sender];
            stakes[msg.sender] -= slashAmount;
        }
    }

    function totalStakes() internal view returns (uint256) {
        uint256 total = 0;
        for (uint256 i = 0; i < mapCount; i++) {
            total += stakes[maps[i].submitter];
        }
        return total;
    }

    function executeVoting(uint256 _mapId) external {
        require(!maps[_mapId].isValid, "Map is already approved.");
        require(block.timestamp >= votingPeriod, "Voting period has not ended.");

        uint256 approvalVotes;
        uint256 rejectionVotes;

        // Count votes
        for (uint256 i = 0; i < mapCount; i++) {
            if (i != _mapId) {
                if (maps[i].isValid) {
                    approvalVotes += stakes[maps[i].submitter];
                } else {
                    rejectionVotes += stakes[maps[i].submitter];
                }
            }
        }

        // Determine consensus
if (approvalVotes > rejectionVotes) {
    maps[_mapId].isValid = true;

    // Pay rewards to submitter
    uint256 fee = (feePercentage * 1 ether) / 100;
    uint256 reward = fee * (stakes[maps[_mapId].submitter] / totalStakes());
    payable(maps[_mapId].submitter).transfer(reward);
} else {
    // Slash funds for submitting an invalid map
    uint256 slashingFee = (slashingPercentage * 1 ether) / 100;
    uint256 slashAmount = slashingFee * stakes[maps[_mapId].submitter];
    stakes[maps[_mapId].submitter] -= slashAmount;
}

// Correcting and validating map fees to DAO members
function correctMap(uint256 _mapId) external {
    require(maps[_mapId].isValid, "Map is not approved.");

    // Pay fees to corrector
    uint256 fee = (feePercentage * 1 ether) / 100;
    uint256 reward = (fee * stakes[msg.sender]) / totalStakes();
    payable(msg.sender).transfer(reward);
}

// Slashing fee for not reporting valid maps/invalid maps correctly
function reportInvalidMap(uint256 _mapId) external {
    require(maps[_mapId].isValid, "Map is not approved.");

    // Slash funds for not reporting correctly
    uint256 slashingFee = (slashingPercentage * 1 ether) / 100;
    uint256 slashAmount = (slashingFee * stakes[msg.sender]) / totalStakes();
    stakes[msg.sender] -= slashAmount;
}
2
  • There isn't any error in this code. I copy pasted it and this seems okay. Jun 3 at 3:24
  • ParserError: Expected '(' but got identifier --> dao.sol:98:10: | 98 | function correctMap(uint256 _mapId) external { | ^^^^^^^^^^ both in remix and truffle i got this error Jun 3 at 3:43

1 Answer 1

0

Try this

 // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.0;
    
    contract EvacDAO {
        struct EvacuationMap {
            address submitter;
            string mapData;
            bool isValid;
        }
    
        mapping(uint256 => EvacuationMap) public maps;
        mapping(address => uint256) public stakes;
        mapping(address => bool) public hasSubmitted;
    
        uint256 public mapCount;
        uint256 public votingPeriod;
        uint256 public feePercentage;
        uint256 public slashingPercentage;
    
        constructor(uint256 _votingPeriod, uint256 _feePercentage, uint256 _slashingPercentage) {
            votingPeriod = _votingPeriod;
            feePercentage = _feePercentage;
            slashingPercentage = _slashingPercentage;
        }
    
        function submitMap(string memory _mapData) external {
            require(!hasSubmitted[msg.sender], "You have already submitted a map.");
    
            uint256 currentMapCount = mapCount;
            maps[currentMapCount] = EvacuationMap(msg.sender, _mapData, false);
            hasSubmitted[msg.sender] = true;
            mapCount++;
    
            // Stake funds
            stakes[msg.sender] += 1 ether;
        }
    
        function validateMap(uint256 _mapId, bool _isValid) external {
            require(msg.sender != maps[_mapId].submitter, "Cannot validate your own map.");
    
            // Update map validity
            maps[_mapId].isValid = _isValid;
    
            // Pay rewards to validator
            if (_isValid) {
                uint256 fee = (feePercentage * 1 ether) / 100;
                uint256 reward = (fee * stakes[msg.sender]) / totalStakes();
                payable(msg.sender).transfer(reward);
            } else {
                // Slash funds for submitting an invalid map
                uint256 slashingFee = (slashingPercentage * 1 ether) / 100;
                uint256 slashAmount = (slashingFee * stakes[msg.sender]) / totalStakes();
                stakes[msg.sender] -= slashAmount;
            }
        }
    
        function totalStakes() internal view returns (uint256) {
            uint256 total = 0;
            for (uint256 i = 0; i < mapCount; i++) {
                total += stakes[maps[i].submitter];
            }
            return total;
        }
    
        function executeVoting(uint256 _mapId) external {
            require(!maps[_mapId].isValid, "Map is already approved.");
            require(block.timestamp >= votingPeriod, "Voting period has not ended.");
    
            uint256 approvalVotes;
            uint256 rejectionVotes;
    
            // Count votes
            for (uint256 i = 0; i < mapCount; i++) {
                if (i != _mapId) {
                    if (maps[i].isValid) {
                        approvalVotes += stakes[maps[i].submitter];
                    } else {
                        rejectionVotes += stakes[maps[i].submitter];
                    }
                }
            }
    
            // Determine consensus
            if (approvalVotes > rejectionVotes) {
                maps[_mapId].isValid = true;
    
                // Pay rewards to submitter
                uint256 fee = (feePercentage * 1 ether) / 100;
                uint256 reward = (fee * stakes[maps[_mapId].submitter]) / totalStakes();
                payable(maps[_mapId].submitter).transfer(reward);
            } else {
                // Slash funds for submitting an invalid map
                uint256 slashingFee = (slashingPercentage * 1 ether) / 100;
                uint256 slashAmount = (slashingFee * stakes[maps[_mapId].submitter]) / totalStakes();
                stakes[maps[_mapId].submitter] -= slashAmount;
            }
    
        }
        // Correcting and validating map fees to DAO members
        function correctMap(uint256 _mapId) external {
            require(maps[_mapId].isValid, "Map is not approved.");
    
            // Pay fees to corrector
            uint256 fee = (feePercentage * 1 ether) / 100;
            uint256 reward = (fee * stakes[msg.sender]) / totalStakes();
            payable(msg.sender).transfer(reward);
        }
    
        // Slashing fee for not reporting valid maps/invalid maps correctly
        function reportInvalidMap(uint256 _mapId) external {
            require(maps[_mapId].isValid, "Map is not approved.");
    
            // Slash funds for not reporting correctly
            uint256 slashingFee = (slashingPercentage * 1 ether) / 100;
            uint256 slashAmount = (slashingFee * stakes[msg.sender]) / totalStakes();
            stakes[msg.sender] -= slashAmount;
        }
    }
2
  • Please do explain the changes as well. Jun 3 at 9:54
  • thank you, of course it was the // SPDX-License-Identifier: MIT .. -.-.- Jun 3 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.