Skip to content

Instantly share code, notes, and snippets.

@l3gacyb3ta
Created June 2, 2021 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save l3gacyb3ta/017b521380ca449221de6bde6718c0eb to your computer and use it in GitHub Desktop.
Save l3gacyb3ta/017b521380ca449221de6bde6718c0eb to your computer and use it in GitHub Desktop.
//SPDX-License-Identifier: WTFPL
pragma solidity >=0.4.16 <0.9.0;
contract Bet {
address payable person1;
address payable person2;
address arbiter;
event Deposit(address from, uint256 amount);
event Decide(address payee, uint256 amount);
constructor(address payable _person1, address payable _person2) {
arbiter = msg.sender;
person1 = _person1;
person2 = _person2;
}
modifier isArbiter() {
// If the first argument of 'require' evaluates to 'false', execution terminates and all
// changes to the state and to Ether balances are reverted.
// This used to consume all gas in old EVM versions, but not anymore.
// It is often a good idea to use 'require' to check if functions are called correctly.
// As a second argument, you can also provide an explanation about what went wrong.
require(msg.sender == arbiter, "Caller is not owner");
_;
}
function deposit() public payable {
emit Deposit(msg.sender, msg.value);
}
function decide(bool person) public isArbiter {
if (person == true) {
emit Decide(person1, address(this).balance);
person1.transfer(address(this).balance);
}
else {
emit Decide(person2, address(this).balance);
person2.transfer(address(this).balance);
}
}
function getBalance() public view returns(uint256 balance) {return address(this).balance;}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment