欢迎光临散文网 会员登陆 & 注册

分投趣fintoch系统开发(开发原理)丨fintoch分投趣系统开发(开发案例)

2023-03-10 09:59 作者:bili_33032327742  | 我要投稿

  智能合约是基于事件驱动有状态,可部署共享的分布式数据库上的计算机程序,多用IF-THEN语句。广义来说,智能合约是一种可以实现自我执行和自我验证的计算机协议。


  区块链(Blockchain)是指通过去中心化和去信任的方式集体维护一个可靠数据库的技术方案。该技术方案主要让参与系统中的任意多个节点,通过一串使用密码学方法相关联产生的数据块(block),每个数据块中包含了一定时间内的系统全部信息交流数据,并且生成数据指纹用于验证其信息的有效性和链接(chain)下一个数据库块。


  ///notice calculte exchange rate according to current stage


  ///return exchange rate.zero if not in sale.


  function exchangeRate()constant returns(uint256){


  if(stage()==Stage.Early){


  return venPerEthEarlyStage;


  }


  if(stage()==Stage.Normal){


  return venPerEth;


  }


  return 0;


  }


  ///notice for test purpose


  function blockTime()constant returns(uint32){


  return uint32(block.timestamp);


  }逻辑及需求分析I59详细2OO7开发3O69


  ///notice estimate stage


  ///return current stage


  function stage()constant returns(Stage){


  if(finalized){


  return Stage.Finalized;


  }


  if(!initialized){


  //deployed but not initialized


  return Stage.Created;


  }


  if(blockTime()<startTime){


  //not started yet


  return Stage.Initialized;


  }


  if(uint256(soldOut.official).add(soldOut.channels)>=publicSupply){


  //all sold out


  return Stage.Closed;


  }


  if(blockTime()<endTime){


  //in sale


  if(blockTime()<startTime.add(earlyStageLasts)){


  //early bird stage


  return Stage.Early;


  }


  //normal stage


  return Stage.Normal;


  }


  //closed


  return Stage.Closed;


  }开发源码及功能:yy625019


  function isContract(address _addr)constant internal returns(bool){


  uint size;


  if(_addr==0)return false;


  assembly{


  size:=extcodesize(_addr)


  }


  return size>0;


  }


  ///notice entry to buy tokens


  function()payable{


  buy();


  }


  ///notice entry to buy tokens


  function buy()payable{


  //reject contract buyer to avoid breaking interval limit


  require(!isContract(msg.sender));


  require(msg.value>=0.01 ether);


  uint256 rate=exchangeRate();


  //here don't need to check stage.rate is only valid when in sale


  require(rate>0);


  //each account is allowed once in minBuyInterval


  require(blockTime()>=ven.lastMintedTimestamp(msg.sender)+minBuyInterval);


  uint256 requested;


  //and limited to maxBuyEthAmount


  if(msg.value>maxBuyEthAmount){


  requested=maxBuyEthAmount.mul(rate);


  }else{


  requested=msg.value.mul(rate);


  }


  uint256 remained=officialLimit.sub(soldOut.official);


  if(requested>remained){


  //exceed remained


  requested=remained;


  }


  uint256 ethCost=requested.div(rate);


  if(requested>0){


  ven.mint(msg.sender,requested,true,blockTime());


  //transfer ETH to vault


  ethVault.transfer(ethCost);


  soldOut.official=requested.add(soldOut.official).toUINT120();


  onSold(msg.sender,requested,ethCost);


  }


  uint256 toReturn=msg.value.sub(ethCost);


  if(toReturn>0){


  //return over payed ETH


  msg.sender.transfer(toReturn);


  }


  }


  ///notice returns tokens sold officially


  function officialSold()constant returns(uint256){


  return soldOut.official;


  }


  ///notice returns tokens sold via channels


  function channelsSold()constant returns(uint256){


  return soldOut.channels;


  }


  ///notice manually offer tokens to channel


  function offerToChannel(address _channelAccount,uint256 _venAmount)onlyOwner{


  Stage stg=stage();


  //since the settlement may be delayed,so it's allowed in closed stage


  require(stg==Stage.Early||stg==Stage.Normal||stg==Stage.Closed);


  soldOut.channels=_venAmount.add(soldOut.channels).toUINT120();


  //should not exceed limit


  require(soldOut.channels<=channelsLimit);


  ven.mint(


  _channelAccount,


  _venAmount,


  true,//unsold tokens can be claimed by channels portion


  blockTime()


  );


  onSold(_channelAccount,_venAmount,0);


  }


  ///notice initialize to prepare for sale


  ///param _ven The address VEN token contract following ERC20 standard


  ///param _ethVault The place to store received ETH


  ///param _venVault The place to store non-publicly supplied VEN tokens


  function initialize(


  VEN _ven,


  address _ethVault,


  address _venVault)onlyOwner{


  require(stage()==Stage.Created);


  //ownership of token contract should already be this


  require(_ven.owner()==address(this));


  require(address(_ethVault)!=0);


  require(address(_venVault)!=0);


  ven=_ven;


  ethVault=_ethVault;


  venVault=_venVault;


  ven.mint(


  venVault,


  reservedForTeam.add(reservedForOperations),


  false,//team and operations reserved portion can't share unsold tokens


  blockTime()


  );


  ven.mint(


  venVault,


  privateSupply.add(commercialPlan),


  true,//private ICO and commercial plan can share unsold tokens


  blockTime()


  );


  initialized=true;


  onInitialized();


  }


  ///notice finalize


  function finalize()onlyOwner{


  //only after closed stage


  require(stage()==Stage.Closed);


  uint256 unsold=publicSupply.sub(soldOut.official).sub(soldOut.channels);


  if(unsold>0){


  //unsold VEN as bonus


  ven.offerBonus(unsold);


  }


  ven.seal();


  finalized=true;


  onFinalized();


  }


  event onInitialized();


  event onFinalized();


  event onSold(address indexed buyer,uint256 venAmount,uint256 ethCost);


  }


分投趣fintoch系统开发(开发原理)丨fintoch分投趣系统开发(开发案例)的评论 (共 条)

分享到微博请遵守国家法律