Skip to content

Instantly share code, notes, and snippets.

@DeviateFish
Last active August 24, 2016 19:55
Show Gist options
  • Save DeviateFish/470788ae57610dc5ade75efcf748d650 to your computer and use it in GitHub Desktop.
Save DeviateFish/470788ae57610dc5ade75efcf748d650 to your computer and use it in GitHub Desktop.
Replay-safe refunds for everyone.
contract Owned {
address owner;
modifier onlyOwner {
if (msg.sender != owner)
throw;
_
}
function Owned() {
owner = msg.sender;
}
}
contract SplitProof {
bool notMyChain;
function SplitProof(uint blocknumber, bytes32 blockhash) {
if (blockhash == bytes32(0)) {
throw;
}
if (blocknumber == 0) {
throw;
}
if (blocknumber <= block.number - 256) {
throw;
}
notMyChain = (block.blockhash(blocknumber) != blockhash);
}
}
contract DaoInterface {
function transferFrom(address _from, address _to, uint256 _amount) returns (bool success);
public uint totalSupply;
function balanceOf(address _owner) constant returns (uint256 balance);
}
contract Refund is SplitProof, Owned {
uint public totalSupply;
bool locked;
DaoInterface theDao = DaoInterface(...);
function Refund(uint blocknumber, bytes32 blockhash) SplitProof(blocknumber, blockhash) {
totalSupply = 0;
locked = false;
}
function lockSupply() onlyOwner {
totalSupply = this.balance;
locked = true;
}
function () {
if (notMyChain || locked) {
throw;
}
return true;
}
function refund() {
if (!locked || notMyChain) {
throw;
}
var balance = theDao.balanceOf(msg.sender);
var scaledBalance = balance * totalSupply / theDao.totalSupply();
if (balance == 0 ||
!theDao.transferFrom(msg.sender, address(this), balance) ||
!msg.sender.send(scaledBalance)) {
throw;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment