Skip to content

Instantly share code, notes, and snippets.

@tyrion70
Created September 9, 2017 21:35
Show Gist options
  • Select an option

  • Save tyrion70/91c3afad9f57b05c21612468d02838a6 to your computer and use it in GitHub Desktop.

Select an option

Save tyrion70/91c3afad9f57b05c21612468d02838a6 to your computer and use it in GitHub Desktop.
LockFunds
pragma solidity ^0.4.13;
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
if (msg.sender != owner) {
revert();
}
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) onlyOwner {
if (newOwner != address(0)) {
owner = newOwner;
}
}
}
/**
* @title LockFunds
* @dev The LockFunds contract is used to store tokens and eth for a fixed amount of time
* ABI: [{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"expiration","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"addr","type":"address"}],"name":"redeemToken","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"fund","outputs":[{"name":"success","type":"bool"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"_days","type":"uint256"}],"name":"lock","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"payable":true,"stateMutability":"payable","type":"fallback"}]
*/
contract LockFunds is Ownable {
uint public expiration; // Timestamp in # of seconds.
function () payable {}
// Only allow the lock to be extended and set to a date > 6 months ahead
function lock(uint _days) onlyOwner returns (bool) {
if (now + (_days * 1 days) < expiration) {
return false;
}
expiration = now + (_days * 1 minutes);
return true;
}
function fund() payable returns (bool success) {
return true;
}
function redeemToken(address addr) onlyOwner {
if (now > expiration) {
ERC20Basic token = ERC20Basic(addr);
uint256 balance = token.balanceOf(this);
if (balance > 0) {
token.transfer(owner, balance);
}
}
}
function kill() onlyOwner {
if (now > expiration) {
suicide(owner);
}
}
}
/**
* @title ERC20Basic
* @dev Simpler version of ERC20 interface
* @dev see https://github.com/ethereum/EIPs/issues/20
*/
contract ERC20Basic {
uint public totalSupply;
function balanceOf(address who) constant returns (uint);
function transfer(address to, uint value);
event Transfer(address indexed from, address indexed to, uint value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment