Skip to content

Instantly share code, notes, and snippets.

@zmitton
Created June 29, 2016 23:46
Show Gist options
  • Save zmitton/4f132e6fb34bc887a9fa131a29130ccf to your computer and use it in GitHub Desktop.
Save zmitton/4f132e6fb34bc887a9fa131a29130ccf to your computer and use it in GitHub Desktop.
contract escrow {
mapping (uint => Holding) public holdings;
uint public numHoldings;
address god;
bool killable = true;
struct Holding {
uint amount;
address receiver;
bool unSpent;
Signer[] signers;
}
struct Signer {
address userAddress;
bool hasSigned;
}
function escrow(){
god = msg.sender;
}
function holdCoin(address _receiver, address[] _signers){
numHoldings++;
holdings[numHoldings].amount = msg.value;
holdings[numHoldings].receiver = _receiver;
holdings[numHoldings].unSpent = true;
for(uint i = 0; i < _signers.length; i++){
holdings[numHoldings].signers.push(Signer({userAddress: _signers[i], hasSigned: false}));
}
}
function signRelease(uint holdingID){
Holding memory holding;
holding = holdings[holdingID];
if(holdings[holdingID].unSpent == true){
bool readyForRelease = true;
for(uint i = 0; i <= holding.signers.length; i++){
if(holding.signers[i].userAddress == msg.sender){
holding.signers[i].hasSigned = true;
}
else if(holding.signers[i].hasSigned == false){
readyForRelease = false;
}
}
if(readyForRelease){
holdings[holdingID].unSpent = false;
if(holdings[holdingID].receiver.send(holdings[holdingID].amount))
throw;
}
}
}
function imortilize(){ if(msg.sender == god){killable = false;}}
function kill(){ if(msg.sender == god && killable )suicide(god);}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment