DAPP商城開發詳細丨DAPP商城系統開發(方案及規則)丨DAPP商城原始碼部署

xiaofufu發表於2023-02-20

  內部函式(僅合約內部可以呼叫)


  _update


  程式碼速覽


  function _update(uint balance0,uint balance1,uint112 _reserve0,uint112 _reserve1)private{


  require(balance0<=uint112(-1)&&balance1<=uint112(-1),'UniswapV2:OVERFLOW');


  uint32 blockTimestamp=uint32(block.timestamp%2**32);


  uint32 timeElapsed=blockTimestamp-blockTimestampLast;


  if(timeElapsed>0&&_reserve0!=0&&_reserve1!=0){


  price0CumulativeLast+=uint(UQ112x112.encode(_reserve1).uqdiv(_reserve0))*timeElapsed;


  price1CumulativeLast+=uint(UQ112x112.encode(_reserve0).uqdiv(_reserve1))*timeElapsed;


  }


  reserve0=uint112(balance0);


  reserve1=uint112(balance1);


  blockTimestampLast=blockTimestamp;


  emit Sync(reserve0,reserve1);


  }


  引數分析


  函式_update的入參有4個,出參有0個,對應的解釋如下:


  function _update(


  uint balance0,//token0的餘額


  uint balance1,//token1的餘額


  uint112 _reserve0,//token0的資金池庫存數量


  uint112 _reserve1//token1的資金池庫存數量


  )private{


  ...


  }


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69956839/viewspace-2936027/,如需轉載,請註明出處,否則將追究法律責任。

相關文章