Skip to content

Instantly share code, notes, and snippets.

@saintbyte
Created July 8, 2018 20:43
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 saintbyte/a6032114396220a545a809d24976d6a8 to your computer and use it in GitHub Desktop.
Save saintbyte/a6032114396220a545a809d24976d6a8 to your computer and use it in GitHub Desktop.
pragma solidity ^0.4.24;
contract Test3
{
address public owner;
mapping(address => uint) private holders;
address[] holders_addrs;
uint256 totalWei;
function Ownable() public {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
constructor() public {
totalWei = 0;
}
function buy() public payable {
if (holders[msg.sender] > 0)
{
holders[msg.sender] = holders[msg.sender] + msg.value;
} else {
holders[msg.sender] = msg.value;
holders_addrs.push(msg.sender);
}
totalWei = totalWei + msg.value;
}
function sendHalf() public onlyOwner payable
{
for(uint i = 0; i < holders_addrs.length ; i++){
holders_addrs[i].transfer(holders[holders_addrs[i]] / 2);
}
totalWei = totalWei / 2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment