-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtakeItIll_ifYouInList
42 lines (32 loc) · 1.48 KB
/
takeItIll_ifYouInList
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
pragma solidity ^0.4.16;
interface testCoin {
function transfer(address receiver, uint amount) public;
function balance(address owner) public returns (uint256);
} //ERC20 токен
contract test
{
address public owner;
testCoin Coin;
address[] listFund;
function test (address _testCoin, address[] _listFund) public //constructor
{
Coin=testCoin(_testCoin);
owner=msg.sender;
listFund=_listFund;
}
function fund () //owner владеет этим контрактом, токены отправяются с его собственного адреса (предположим, их завели предварительно), только он может вызвать контракт
{
require(msg.sender == owner) ; //без этого условия в общем-то любой может поделиться своими токенами в равных частях - можно убрать, получится такой контракт для благотворительности :)
uint16 i=0;
uint256 tokens=Coin.balance(owner);
uint256 length=listFund.length;
require(length!=0);
tokens=tokens/(length); //без SafeMath, но вообще в курсе :) посчитали, сколько токенов раздаем
while (i!=length)
{
address getter=listFund[i];
i+=1;
Coin.transfer(getter,tokens) ; //отправляем токены с собственного адреса
}
}
}