Skip to content

Instantly share code, notes, and snippets.

@rodrigosetti
Created February 9, 2019 05:21
Show Gist options
  • Save rodrigosetti/bbcceecc63f0a1e8522c26cd3332b5de to your computer and use it in GitHub Desktop.
Save rodrigosetti/bbcceecc63f0a1e8522c26cd3332b5de to your computer and use it in GitHub Desktop.
Riddles smart contract
pragma solidity ^0.5.0;
contract Owned {
constructor() public { owner = msg.sender; }
address payable owner;
modifier onlyOwner {
require(
msg.sender == owner,
"Only owner can call this function."
);
_;
}
}
contract Riddles is Owned {
bytes32[] private answerHashes;
uint256 public answerIndex = 0;
constructor(bytes32[] memory _answerHashes) public {
answerHashes = _answerHashes;
}
function sendAnswer(bytes memory answer) public onlyOwner returns (bool) {
require(answerIndex < answerHashes.length);
bytes32 answerHash = sha256(answer);
if (answerHash == answerHashes[answerIndex]) {
// right answer
answerIndex++;
if (answerIndex == answerHashes.length) {
// end of the riddle challenge!
selfdestruct(msg.sender);
}
return true;
} else {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment