solidity 第三天

简介: 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<aaddress.length);
          return (aaddress[i],amoneycount[aaddress[i]]);
     }
     function getB(uint i) public constant returns (address,uint){
          require(i<baddress.length);
          return (baddress[i],bmoneycount[baddress[i]]);
     }
     function getC(uint i) public constant returns (address,uint){
          require(i<caddress.length);
          return (caddress[i],cmoneycount[caddress[i]]);
     }
     
     function clearData()  public returns (bool) {
         require(msg.sender==owner);
         aaddress.length = 0;
         baddress.length = 0;
         caddress.length = 0;
         
         return true;
         
     }
     
      
   
}
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;  
    }  
}
 
相关文章
|
5月前
|
存储 IDE 区块链
《Solidity 简易速速上手小册》第3章:Solidity 语法基础(2024 最新版)
《Solidity 简易速速上手小册》第3章:Solidity 语法基础(2024 最新版)
129 2
|
5月前
|
供应链 前端开发 JavaScript
《Solidity 简易速速上手小册》第10章:区块链项目实战(2024 最新版)(上)
《Solidity 简易速速上手小册》第10章:区块链项目实战(2024 最新版)
65 0
|
JavaScript 前端开发 区块链
|
5月前
|
前端开发 JavaScript 数据挖掘
《Solidity 简易速速上手小册》第9章:DApp 开发与 Solidity 集成(2024 最新版)(下)
《Solidity 简易速速上手小册》第9章:DApp 开发与 Solidity 集成(2024 最新版)
49 1
|
2月前
|
存储 安全 编译器
Metamask项目方给Solidity程序员的16个安全建议
文章是Metamask项目方Consensys在2020年发布的关于智能合约安全的博文,提供了16条Solidity程序员的安全建议,包括正确使用assert()、require()、revert()函数,避免使用tx.origin进行授权,注意整数除法舍入问题等,以帮助开发者提高智能合约的安全性。
32 0
|
5月前
|
存储 供应链 安全
《Solidity 简易速速上手小册》第1章:Solidity 和智能合约简介(2024 最新版)
《Solidity 简易速速上手小册》第1章:Solidity 和智能合约简介(2024 最新版)
120 1
|
5月前
|
存储 安全 测试技术
《Solidity 简易速速上手小册》第8章:高级 Solidity 概念(2024 最新版)(下)
《Solidity 简易速速上手小册》第8章:高级 Solidity 概念(2024 最新版)
63 1
|
5月前
|
存储 安全 区块链
《Solidity 简易速速上手小册》第4章:智能合约的设计与开发(2024 最新版)
《Solidity 简易速速上手小册》第4章:智能合约的设计与开发(2024 最新版)
115 0
|
5月前
|
前端开发 安全 物联网
《Solidity 简易速速上手小册》第10章:区块链项目实战(2024 最新版)(下)
《Solidity 简易速速上手小册》第10章:区块链项目实战(2024 最新版)
73 1
|
5月前
|
存储 前端开发 安全
《Solidity 简易速速上手小册》第9章:DApp 开发与 Solidity 集成(2024 最新版)(上)
《Solidity 简易速速上手小册》第9章:DApp 开发与 Solidity 集成(2024 最新版)
91 0