github.com/iotexproject/iotex-core@v1.14.1-rc1/action/protocol/execution/testdata/multisend2.sol (about) 1 pragma solidity ^0.4.24; 2 3 import './math/SafeMath.sol'; 4 import './ownership/Ownable.sol'; 5 6 contract ERC20Basic { 7 function totalSupply() public view returns (uint256); 8 function balanceOf(address who) public view returns (uint256); 9 function transfer(address to, uint256 value) public returns (bool); 10 event Transfer(address indexed from, address indexed to, uint256 value); 11 } 12 13 contract ERC20 is ERC20Basic { 14 function allowance(address owner, address spender) public view returns (uint256); 15 function transferFrom(address from, address to, uint256 value) public returns (bool); 16 function approve(address spender, uint256 value) public returns (bool); 17 event Approval(address indexed owner, address indexed spender, uint256 value); 18 } 19 20 contract Multisend is Ownable { 21 using SafeMath for uint256; 22 23 uint256 public minTips; 24 uint256 public limit; 25 26 event Transfer(address indexed from, address indexed to, uint256 value); 27 event Receipt(address _token, uint256 _totalAmount, uint256 _tips, string _payload); 28 event Withdraw(address _owner, uint256 _balance); 29 30 constructor(uint256 _minTips, uint256 _limit) public { 31 minTips = _minTips; 32 limit = _limit; 33 } 34 35 function sendCoin(address[] recipients, uint256[] amounts, string payload) public payable { 36 require(recipients.length == amounts.length); 37 require(recipients.length <= limit); 38 uint256 totalAmount = minTips; 39 for (uint256 i = 0; i < recipients.length; i++) { 40 totalAmount = SafeMath.add(totalAmount, amounts[i]); 41 require(msg.value >= totalAmount); 42 recipients[i].transfer(amounts[i]); 43 emit Transfer(msg.sender, recipients[i], amounts[i]); 44 } 45 emit Receipt(address(this), SafeMath.sub(totalAmount, minTips), SafeMath.add(minTips, SafeMath.sub(msg.value, totalAmount)), payload); 46 } 47 48 function sendToken(address token, address[] recipients, uint256[] amounts, string payload) public payable { 49 require(msg.value >= minTips); 50 require(recipients.length == amounts.length); 51 require(recipients.length <= limit); 52 uint256 totalAmount = 0; 53 ERC20 erc20token = ERC20(token); 54 for (uint256 i = 0; i < recipients.length; i++) { 55 totalAmount = SafeMath.add(totalAmount, amounts[i]); 56 erc20token.transferFrom(msg.sender, recipients[i], amounts[i]); 57 } 58 emit Receipt(token, totalAmount, msg.value, payload); 59 } 60 61 function withdraw() public onlyOwner { 62 uint256 balance = address(this).balance; 63 owner.transfer(balance); 64 emit Withdraw(owner, balance); 65 } 66 67 function setMinTips(uint256 _minTips) public onlyOwner { 68 minTips = _minTips; 69 } 70 71 function setLimit(uint256 _limit) public onlyOwner { 72 limit = _limit; 73 } 74 }