//Write your own contracts here. Currently compiles using solc v0.4.15+commit.bbb8e64f. pragma solidity ^0.4.21; /** * @title ERC20Basic * @dev Simpler version of ERC20 interface * @dev see https://github.com/ethereum/EIPs/issues/179 */ contract ERC20Basic { function totalSupply() public view returns (uint256); function balanceOf(address who) public view returns (uint256); function transfer(address to, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); } contract BatchOverFlowToken is ERC20Basic { using SafeMath for uint256; uint256 totalSupply_; mapping(address => uint256) balances; modifier whenNotPaused() { _; } function BatchOverFlowToken() public { totalSupply_ = 10000; balances[msg.sender] = totalSupply_; } /** * @dev total number of tokens in existence */ function totalSupply() public view returns (uint256) { return totalSupply_; } /** * @dev transfer token for a specified address * @param _to The address to transfer to. * @param _value The amount to be transferred. */ function transfer(address _to, uint256 _value) public returns (bool) { require(_to != address(0)); require(_value <= balances[msg.sender]); balances[msg.sender] = balances[msg.sender].sub(_value); balances[_to] = balances[_to].add(_value); emit Transfer(msg.sender, _to, _value); return true; } /** * @dev Gets the balance of the specified address. * @param _owner The address to query the the balance of. * @return An uint256 representing the amount owned by the passed address. */ function balanceOf(address _owner) public view returns (uint256) { return balances[_owner]; } // 複数のアカウントに同一のトークン量を付与する関数 // _receivers は送信先アカウントアドレスの配列 // _value は送信量 // 返り値はbool型 function batchTransfer(address[] _receivers, uint256 _value) public whenNotPaused returns (bool) { // 送金先の数をlengthで取得しcnt変数に格納 uint cnt = _receivers.length; // cnt(送金先数)×送金額で額を算出 // このタイミングでオーバーフローを発生させる uint256 amount = uint256(cnt) * _value; require(cnt > 0 && cnt <= 20); // cnt(送信先アドレス数)が0以上で、20以下であるか判定 require(_value > 0 && balances[msg.sender] >= amount); // 送信額が0以上で、送信元アカウントが所有する額が送信総額以上であるか判定 // balanceという状態変数(key => value)のmapping型を更新する // subはSafeMath関数として定義されたもの差し引いた後の額を返り値として返す balances[msg.sender] = balances[msg.sender].sub(amount); // for文で送信先数実行 for (uint i = 0; i < cnt; i++) { // 送信先アカウントのbalances状態変数の値を更新する balances[_receivers[i]] = balances[_receivers[i]].add(_value); // 送信完了を伝えるイベント発火 emit Transfer(msg.sender, _receivers[i], _value); } return true; } } /** * @title SafeMath * @dev Math operations with safety checks that throw on error */ library SafeMath { /** * @dev Multiplies two numbers, throws on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { if (a == 0) { return 0; } c = a * b; assert(c / a == b); return c; } /** * @dev Integer division of two numbers, truncating the quotient. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // assert(b > 0); // Solidity automatically throws when dividing by 0 // uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return a / b; } /** * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { assert(b <= a); return a - b; } /** * @dev Adds two numbers, throws on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256 c) { c = a + b; assert(c >= a); return c; } }
0.4.21