Last active
November 19, 2018 19:19
-
-
Save noman-land/ce4c940bca841c6c2057df4fabd98d94 to your computer and use it in GitHub Desktop.
This file contains 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
pragma solidity ^0.4.24; | |
contract IdeaRegistry { | |
function registerIdea(uint hash) public; | |
} | |
contract IdeaValidator { | |
address owner; | |
address registryAddress; | |
mapping (address => bool) validators; | |
mapping (uint => Idea) pendingIdeas; | |
struct Idea { | |
address owner; | |
bool isValid; | |
} | |
modifier ownerOnly() { | |
require(msg.sender == owner); | |
_; | |
} | |
modifier validatorOnly(address user) { | |
require(validators[user] == true); | |
_; | |
} | |
constructor() public { | |
owner = msg.sender; | |
} | |
function addRegistryAddress(address _registryAddress) public ownerOnly { | |
registryAddress = _registryAddress; | |
} | |
function submitIdea(uint hash) public { | |
// Ensure idea hasn't been submitted already | |
require(pendingIdeas[hash].owner == address(0)); | |
// Check that idea isn't already registered in the official IdeaRegistry | |
require(registryAddress != address(0)); | |
contract registry = IdeaRegistry(registryAddress); | |
require(registry.getIdea(hash).owner == address(0)); | |
pendingIdeas[hash] = Idea(msg.sender, false); | |
} | |
function acceptIdea(uint hash, bool isValid) public validatorOnly(msg.sender) { | |
pendingIdeas[hash].isValid = isValid; | |
// go to the other contract and add this idea to it | |
if (isValid == true) { | |
require(registryAddress != address(0)) | |
contract registry = IdeaRegistry(registryAddress); | |
registry.registerIdea(hash); | |
} | |
} | |
function addValidator(address newValidator) public ownerOnly { | |
validators[newValidator] = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment