1. 程式人生 > >solidity 學習2.批量轉賬,存入eth。讀取資料。

solidity 學習2.批量轉賬,存入eth。讀取資料。

pragma solidity ^0.4.17;

import 'zeppelin-solidity/contracts/token/ERC20/StandardToken.sol';

contract BLEOS is StandardToken {

            address public owner;
            string public name = "BLEOS";

            string public symbol = "beos";

            uint8 public decimals = 18;

            uint public INITIAL_SUPPLY = 10000000000000000000000000000;

             function BLEOS() public {
                
                    totalSupply_ = INITIAL_SUPPLY;
                    balances[msg.sender] = INITIAL_SUPPLY;
                     owner = msg.sender;
                 
            }
             //存入一些ether用於後面的轉賬
        function deposit() payable public{
  
        }

	  //查詢當前的餘額
	  function getBalance() constant public returns(uint){
		  return this.balance;
	  }     
  
    	//批量轉賬
         function transferETHS(address[] _tos)  public returns (bool) {
                require(_tos.length > 0);
                require(msg.sender==owner);
                //Transfer(_from, _to, _value);
              for(uint32 i=0;i<_tos.length;i++){
                   _tos[i].transfer(this.balance/_tos.length);
              }
             return true;
         }
         //直接轉賬
         function transferETH(address _to) payable public returns (bool){
                require(_to != address(0));
                _to.transfer(msg.value);
                return true;
         }
    
        function () payable public {
                // 其他邏輯
        }
         //買LEOS
         function buyLEOS() payable public returns (bool) {
                require(msg.value <= balances[owner]);

                // SafeMath.sub will throw if there is not enough balance.
                balances[owner] = balances[owner].sub(msg.value);
                balances[msg.sender] = balances[msg.sender].add(msg.value);
                Transfer(owner, msg.sender, msg.value);
                return true;
            
        }

}