Created
February 7, 2022 19:42
-
-
Save devdevgoat/5c2e2056a850951f02b8fb5f517981b6 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
/** | |
* @title Ballot | |
* @dev Implements voting process along with vote delegation | |
* | |
* uhg, it won't return false if user is a mod or not | |
* it also lets you add duplicate mods | |
* can't use mappings bc i want to iterate over the list of mods | |
* risk of flodding the array with so many mods the contract fails to update | |
* | |
* | |
* | |
*/ | |
contract Modstore { | |
address private owner; | |
string[] public lastModList; | |
string[] public currentModList; | |
// event for EVM logging | |
event OwnerSet(address indexed oldOwner, address indexed newOwner); | |
// modifier to check if caller is owner | |
modifier isOwner() { | |
require(msg.sender == owner, "Bitch, you have no power here...."); | |
_; | |
} | |
/** | |
* @dev Set contract deployer as owner | |
*/ | |
constructor() { | |
owner = msg.sender; // we need to deploy this as the dao agent | |
emit OwnerSet(address(0), owner); | |
} | |
function isUserAMod(string memory username) public view returns (bool out) { | |
out = false; | |
for (uint j = 0; j <= currentModList.length; j++) { //for loop example | |
if (stringsAreEqual(currentModList[j], username)){ | |
out = true; | |
} | |
} | |
return out; | |
} | |
function findModId(string memory username) public view returns (int) { | |
for (uint j = 0; j <= currentModList.length; j++) { //for loop example | |
if (stringsAreEqual(currentModList[j], username)){ | |
return int(j); | |
} | |
} | |
return -1; | |
} | |
function stringsAreEqual(string memory a, string memory b) public pure returns (bool) { | |
return keccak256(abi.encodePacked(a)) == keccak256(abi.encodePacked(b)); | |
} | |
function addMod(string calldata new_mod) public isOwner returns (int) { | |
// require(!isUserAMod(new_mod),"User is already a mod, cannot add."); | |
lastModList = currentModList; | |
currentModList.push(new_mod); | |
return findModId(new_mod); | |
} | |
function removeMod(string memory new_mod) public isOwner { | |
int modId = findModId(new_mod); | |
require(modId != -1,"User is not a mod, cannot remove."); | |
lastModList = currentModList; | |
delete currentModList[uint(modId)]; | |
} | |
function getMods() public view returns (string[] memory) { | |
return currentModList; | |
} | |
function getPreviousMods() public view returns (string[] memory) { | |
return lastModList; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment