Skip to content

Instantly share code, notes, and snippets.

@D-Nice
Last active November 28, 2016 11:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save D-Nice/1e712cc23c28a3d3371f4f9cebe3c0cb to your computer and use it in GitHub Desktop.
Save D-Nice/1e712cc23c28a3d3371f4f9cebe3c0cb to your computer and use it in GitHub Desktop.
Contract for locking a certain amount of ether until a set date
contract DateTime {
/*
* Credit to pipermerriam for this utility contract
*
* Date and Time utilities for ethereum contracts
*
* address: 0x1a6184cd4c5bea62b0116de7962ee7315b7bcbce
*/
function toTimestamp(uint16 year, uint8 month, uint8 day) constant returns (uint timestamp);
}
contract DatePayout {
uint public payoutDate;
address public recipient;
DateTime dateTimeContract = DateTime(0x1a6184cd4c5bea62b0116de7962ee7315b7bcbce);
event LogFundsReceived (address from, uint amount, uint total);
//Constructor function
function DatePayout(address _recipient, uint16 _year, uint8 _month, uint8 _day) {
//Sets the address of the recipient
recipient = _recipient;
//Set the payout date in UNIX timestamp format by providing a numerical year, month, and day.
//e.g. 2016, 8, 9 for today's date, August 9, 2016.
payoutDate = dateTimeContract.toTimestamp(_year, _month, _day);
}
function() {
//Return the transaction as an event to notify how much this sender has sent and the current total balance of the contract
if (msg.value > 0)
LogFundsReceived (msg.sender, msg.value, this.balance);
}
//This function becomes callable on/after the set payout date when the function was created
//selfdestruct disperses the balance of this contract and sends it to recipient, and refunds any storage gas cost
function authorizePayout() {
if(now >= payoutDate)
selfdestruct(recipient);
else
throw;
}
}
@resurtm
Copy link

resurtm commented Nov 28, 2016

@D-Nice, any ideas on how can I lower gas usage of this contract?

image

I'm not even able to deploy it at ROPSTEN test network.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment