-
-
Save achiko/419aec1ac5516edc2d2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract owned { | |
address public owner; | |
function owned() { | |
owner = msg.sender; | |
} | |
modifier onlyOwner { | |
if (msg.sender != owner) throw; | |
_ | |
} | |
function transferOwnership(address newOwner) onlyOwner { | |
owner = newOwner; | |
} | |
} | |
contract token { | |
mapping (address => uint256) public balanceOf; | |
function transfer(address _to, uint256 _value); | |
} | |
contract profitSharing { | |
mapping (address => uint) public holderId; | |
ActiveHolder[] public holders; | |
token public sharesTokenAddress; | |
struct ActiveHolder { | |
address holder; | |
string name; | |
uint lastSeen; | |
} | |
function profitSharing(address sharesAddress, string ownerName){ | |
sharesTokenAddress = token(sharesAddress); | |
holders[0] = ActiveHolder({holder: msg.sender, name: ownerName, lastSeen: now}); | |
} | |
/*make active Member*/ | |
function activateMe(string name) { | |
uint id; | |
if (holderId[msg.sender] == 0) { | |
holderId[msg.sender] = holders.length; | |
id = holders.length++; | |
holders[id] = ActiveHolder({holder: msg.sender, name: name, lastSeen: now}); | |
} else { | |
id = holderId[msg.sender]; | |
ActiveHolder h = holders[id]; | |
h.name = name; | |
h.lastSeen = now; | |
} | |
} | |
function (){ | |
uint totalShares = 0; | |
for (uint i = 0; i < holders.length; ++i) { | |
ActiveHolder h = holders[i]; | |
uint holderBalance = sharesTokenAddress.balanceOf(h.holder); | |
totalShares += holderBalance; | |
} | |
for (i = 0; i < holders.length; ++i) { | |
h = holders[i]; | |
holderBalance = sharesTokenAddress.balanceOf(h.holder); | |
h.holder.send(msg.value * holderBalance/totalShares); | |
} | |
} | |
function distributeToken(address tokenToDistributeAddress){ | |
uint totalShares = 0; | |
token tokenToDistribute = token(tokenToDistributeAddress); | |
uint totalBalance = tokenToDistribute.balanceOf(this); | |
for (uint i = 0; i < holders.length; ++i) { | |
ActiveHolder h = holders[i]; | |
uint holderBalance = sharesTokenAddress.balanceOf(h.holder); | |
totalShares += holderBalance; | |
} | |
for (i = 0; i < holders.length; ++i) { | |
h = holders[i]; | |
holderBalance = sharesTokenAddress.balanceOf(h.holder); | |
tokenToDistribute.transfer(h.holder, msg.value * holderBalance/totalShares); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What does "_" operator make?