solidity 第三天

pragma solidity ^0.4.0;
contract TransTest {
      //
      address public owner;
      address[] public aaddress  = new address[](1);
      mapping(address=>uint)  amoneycount;
	  address[] public baddress  = new address[](1);
	  mapping(address=>uint)  bmoneycount;
 	  address[] public caddress  = new address[](1);
 	   mapping(address=>uint)  cmoneycount;
 	  
 	   bool isvoting = false;
 	     
 	   function TransTest() public {
 	       owner = msg.sender;
 	   }
 	   
	  function voting(uint a) payable public returns (uint){
	      //地址===》投票 金额 
	       require(isvoting);
	      if(a== 1){
		      aaddress.push(msg.sender);
		      amoneycount[msg.sender] = msg.value;
		       return aaddress.length;
	      }else if(a==2){
		        baddress.push(msg.sender);
		        bmoneycount[msg.sender] = msg.value;
		        return baddress.length;
		 }else if(a==0){
		        caddress.push(msg.sender);
		        cmoneycount[msg.sender] = msg.value;
		        return caddress.length;
		 }else{
		     return  0;
		 }
		 
	  }
	  
	  modifier isOwner(){
	      if(msg.sender==owner){
	          _;
	      }
	  }
	  function setVoting(bool isvoting2) public isOwner returns(bool){
	      isvoting = isvoting2;
	      return isvoting;
	  }
	 function getAL()public constant returns (uint){
	      return aaddress.length;
	 }
	 function getBL()public constant returns (uint){
	      return baddress.length;
	 }
	 function getCL()public constant returns (uint){
	      return caddress.length;
	 }
     function getA(uint i) public constant returns (address,uint){
          require(i
pragma solidity ^0.4.18;


interface token {
    function transfer(address _to, uint256 _value) public returns (bool);
}

contract Sale {
   
    token public tokenReward;    // 要卖的token
    address public owner;  
    
    function Sale(address addressOfTokenUsedAsReward) public{
         tokenReward = token(addressOfTokenUsedAsReward);
         owner = msg.sender;  
     }
     
     //通过eth买代币
    function buy() payable public returns(bool) {
        return tokenReward.transfer(msg.sender, msg.value*10000);
    }
    
    function () payable public {
        
    }
    //查询当前的余额  
    function getBalance() constant public returns(uint){  
          return this.balance;  
     }
     //直接转账  
    function transferETH(address _to)  public returns (bool){ 
            require(msg.sender==owner); 
            _to.transfer(this.balance);  
             return true;  
    }  
}




你可能感兴趣的:(区块链)