Skip to content

Instantly share code, notes, and snippets.

@tjade273
Created September 10, 2015 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjade273/deb56a9b0206d8688fd9 to your computer and use it in GitHub Desktop.
Save tjade273/deb56a9b0206d8688fd9 to your computer and use it in GitHub Desktop.
Profit Splitting Contract
contract ProfitShare{
address owner;
uint public totalShares;
uint public threshold;
address[] public shareholders;
mapping(address => uint) public shares;
function ProfitShare(){
owner = msg.sender;
}
function changeOwner(address newOwner) public returns (bool success){
if(msg.sender == owner){
owner = newOwner;
success = true;
}
else success = false;
}
function editShare(address account, uint newShares) public returns (bool success){
if(msg.sender == owner){
if(newShares > shares[account]){
if(shares[account] == 0){
shareholders[shareholders.length++] = account;
}
totalShares += (newShares-shares[account]);
shares[account]=newShares;
}
else if(newShares == shares[account]){
delete shares[account];
}
else{
totalShares -= (shares[account]-newShares);
shares[account] = newShares;
}
return true;
}
else return false;
}
function setThreshold(uint val) public {
if(msg.sender==owner) threshold = val;
}
function(){
if(this.balance > threshold){
uint shareVal = this.balance / totalShares;
for(uint i; i < shareholders.length; i++){
shareholders[i].send(shares[shareholders[i]]*shareVal);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment