Skip to content

Instantly share code, notes, and snippets.

@boska
Created June 21, 2017 10:04
Show Gist options
  • Save boska/708d5c4606aff18dc41d2e34d398b6b0 to your computer and use it in GitHub Desktop.
Save boska/708d5c4606aff18dc41d2e34d398b6b0 to your computer and use it in GitHub Desktop.
Solidity opening application
pragma solidity 0.4.11;
contract Offer {
/* Constructor */
address public employee;
uint public safetyDeposit;
uint public offerStart;
uint public lastWithdraw;
uint public numberBlocksPerDay = 2;
uint public ratePerDay = 0.5 ether;
event Withdraw(address employee, uint amount, uint numberOfDay);
event Deposit(address from, uint amount);
modifier onlyEmployee {
require(msg.sender == employee);
_;
}
function Offer() payable {
safetyDeposit = msg.value;
offerStart = block.number;
lastWithdraw = block.number;
}
function accept() {
if (employee == address(0)) {
employee = msg.sender;
}
}
function withdraw() onlyEmployee {
uint daysToWithdraw = (lastWithdraw - block.number) / numberBlocksPerDay;
uint amountToWithdraw = daysToWithdraw * ratePerDay;
if ((this.balance - safetyDeposit) > amountToWithdraw) {
Withdraw(msg.sender, amountToWithdraw, daysToWithdraw);
msg.sender.transfer(amountToWithdraw);
lastWithdraw = block.number;
} else {
dismiss();
}
}
function () payable {
Deposit(msg.sender, msg.value);
}
function dismiss() onlyEmployee {
selfdestruct(msg.sender);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment