solidity

2018-03-01  本文已影响0人  遥望泰山
BufferedReader br = new BufferedReader(new InputStreamReader(
                    req.getInputStream(), "UTF-8")); // 编码
            String line = null;
            StringBuilder sb = new StringBuilder();
            while ((line = br.readLine()) != null) {
                sb.append(line);
                sb.append("\r\n");
            }
            br.close();
contract Config{
   struct configInfo{
        string sys;
        string name;
        string detail;

    }
    mapping(string=>configInfo) configInfos;
       
function setInfo(string sys, string name,string detail){
    configInfo  memory inf = configInfo(sys,name,detail);
    configInfos[name]= inf;

}
function getInfo(string name) constant returns(string ,string){
   return (configInfos[name].sys, configInfos[name].detail);
}   

}

pragma solidity ^0.4.0;
/*
contract ERC20 {
      function totalSupply() constant returns (uint totalSupply);
      function balanceOf(address _owner) constant returns (uint balance);
      function transfer(address _to, uint _value) returns (bool success);
      function transferFrom(address _from, address _to, uint _value) returns (bool success);
      function approve(address _spender, uint _value) returns (bool success);
      function allowance(address _owner, address _spender) constant returns (uint remaining);
      event Transfer(address indexed _from, address indexed _to, uint _value);
      event Approval(address indexed _owner, address indexed _spender, uint _value);
    }
*/
contract red {

    address god;
    uint    money;
   
   
   
   

    struct redStruct{
        string giveRedID;
        string getRedID;
      
        uint redMoney;
        address from;
        address to;
    }
    
    struct user{
        address addr;
        uint amount;
      }
      
    struct redEnvelope{
        address redAdd;
        uint    redAmount;
    }
    
    mapping (address => uint)  users;
    mapping (string =>uint) giveRedsForMoney;
     mapping (string =>address) giveRedsForAddress;
    mapping (string=>mapping(string=>redStruct))giveRedsDetail;   //抢完红包后的明细
    function red(){
        god =  msg.sender;
        money =  10000000000;    //100亿
    }



    modifier onlyOwner {
        require(msg.sender == god);
        _;
    }    
       modifier onlyUsers {
        require(msg.sender != god);
        _;
    }  
    
    function buyCoin(uint transMon) onlyUsers{
        uint tmp = users[msg.sender];
        users[msg.sender] = transMon + tmp;
        money = money-transMon;
        
    
    }
  function getCoin()onlyUsers returns(uint){
  
      
      return users[msg.sender];
  }
  




    function trans(address from,address to,uint transMoney)internal{
         users[from]=users[from] - transMoney;
         users[to]=users[to] + transMoney;
    }
 function giveRed(uint redMoney,uint presonNum,string id){
     uint tmpMoney = redMoney*presonNum;
      trans(msg.sender,god,tmpMoney);
      giveRedsForMoney[id] = tmpMoney;
      giveRedsForAddress[id] =msg.sender;
 }
 function whoGetRed(string giveRedID,string getRedID,address from,address to,uint redMoney){
   //  redStruct tmp = redStruct(giveRedID,getRedID,redMoney,from,to);
     //  mapping (string=>mapping(string=>redStruct))giveRedsDetail;
     giveRedsDetail[getRedID][giveRedID] =redStruct(giveRedID,getRedID,redMoney,from,to);
    trans(from,to,redMoney);
 }

}

pragma solidity ^0.4.0;


import "./Test2.sol";
contract Test1{
     event setStringEvent(string str1,string str2, string str3, string str4);
     event getStringEvent(string str1,string str2, string str3,string str4);
     
     string a ;
     string b ;
    function getBalance() public{
         getStringEvent("获得数值是多少-----a",a,"----b---",b);
       
    }
    function setBalance( string aa,string bb)  public {
        setStringEvent("设置数值是多少-----a",a,"----b---",b);
        a = aa;
        b = bb;
    }
}



pragma solidity ^0.4.0;

contract Test1ABI{ 

    function getBalance()public {}
    
    function setBalance( string aa,string bb)public {}
   
}


contract Test2{ 
      address public signersAddr;
      
      
    function setit(string aa,string bb){
       Test1ABI(signersAddr).setBalance(aa,bb);
    }
}

调用之前

pragma solidity ^0.4.0;



contract Test1{
     event setStringEvent(string str1,string str2, string str3, string str4);
     event getStringEvent(string str1,string str2, string str3,string str4);
     
     string a ;
     string b ;
    function getBalance() public{
         getStringEvent("获得数值是多少-----a",a,"----b---",b);
       
    }
    function setBalance( string aa,string bb)  public {
        setStringEvent("设置数值是多少-----a",a,"----b---",b);
        a = aa;
        b = bb;
    }
}




pragma solidity ^0.4.0;
import "./Test1.sol";
contract Test1ABI{ 

    function getBalance()public {}
    
    function setBalance( string aa,string bb)public {}
   
}


contract Test2{ 
      address public signersAddr;
      
      function getit(){
          signersAddr = to.address;
        //  signersAddr =0x692a70d2e424a56d2c6c27aa97d1a86395877b3a;
      }
    function setit(string aa,string bb){
       Test1ABI(signersAddr).setBalance(aa,bb);
    }
}
上一篇下一篇

猜你喜欢

热点阅读