Stepn跑鞋跑步鏈遊趣步模式系統開發詳情規則/方案詳細/原始碼案例

xiaofufu發表於2023-04-24

  


  Web3.0的特點是使用區塊鏈和其他賦能技術,如AI和密碼學,以建立一個更公平、安全和私有的線上生態系統。


  web3.0的發展趨勢是建立分散的網路、協議和應用程式,以無信任和安全的方式促進價值和資訊的交換。


  智慧合約dapp開發技術主要由以太坊區塊鏈網路提供支援,搭建原始碼案例:Mrsfu123 該網路提供了一系列的智慧合約技術,這些智慧合約可以讓開發者快速、安全地構建出功能強大的dapp。智慧合約dapp開發技術主要包括以太坊智慧合約語言Solidity,以太坊智慧合約框架Truffle,Web3.js,以太坊區塊鏈瀏覽器Mist等


  Single player mode is currently the only mode that has been activated.In this mode,users can generate GST and GMT based on the number of steps they take(GMT acquisition has not yet been enabled).The conversion ratio of steps and tokens is influenced by a series of parameters:the higher the"efficiency"coefficient of running shoes,the more GST generated per step;The higher the'comfort'coefficient,the more GMT generated per step.In addition,the speed of walking also has an impact.Only when the speed reaches a certain level can income be generated,and the faster the speed,the higher the income.Users may also obtain a"mysterious box"during the running process,from which they can randomly draw different levels of gemstones.Users can embed gemstones on running shoes by consuming GST to enhance their attributes.


  (1)The Game Mechanism of StepN


  The main concept of StepN is"Move to Earn"(M2E).When it comes to this concept,veteran readers should easily associate it with the metaverse product Axie Infinity that I mentioned in my column-the main concept of this product is"Play to Earn"(P2E),which means that users can earn income while playing.To a large extent,StepN is actually an Axie Infinity with a sports vest.


  In Axie Infinity,players need to first purchase an NFT for their pet(Axie),and then they can cultivate the pet and engage it in battles and competitions to earn income.In StepN,this design was basically followed,except that the pet Axie in Axie Infinity was replaced with running shoes,and the method of earning income changed from virtual battles in the game to running in reality.


  According to StepN's settings,users need to have a pair of"running shoes"NFTs before entering the game.In the game,there are multiple types of running shoes initially provided,and each type of running shoe has corresponding"efficiency"and"comfort"attributes,which will affect the number of tokens players will obtain from sports in the future.Of course,the more advanced the properties of running shoes,the better,and the more expensive the price.Players can directly purchase according to their own needs,or they can purchase a blind box and randomly select a pair of running shoes from it.


  After the player has a pair of running shoes,they can start the game.In the StepN white paper,three game modes are listed:Solo Mode,Marathon Mode,and Background Mode.


  Single player mode is currently the only mode that has been activated.In this mode,users can generate GST and GMT based on the number of steps they take(GMT acquisition has not yet been enabled).The conversion ratio of steps and tokens is influenced by a series of parameters:the higher the"efficiency"coefficient of running shoes,the more GST generated per step;The higher the'comfort'coefficient,the more GMT generated per step.In addition,the speed of walking also has an impact.Only when the speed reaches a certain level can income be generated,and the faster the speed,the higher the income.Users may also obtain a"mysterious box"during the running process,from which they can randomly draw different levels of gemstones.Users can embed gemstones on running shoes by consuming GST to enhance their attributes.


  NFT轉移階段,該階段的邏輯大致如下:


  修正轉移雙方的balance引數


  --_packedAddressData[from];


  ++_packedAddressData[to];


  更新tokenId對應的_packedOwnerships資料:


  _packedOwnerships[tokenId]=_packOwnershipData(


  to,


  _BITMASK_NEXT_INITIALIZED|_nextExtraData(from,to,prevOwnershipPacked)


  );


  由於轉移過程必須進行初始化,所以此處將轉移的NFT的nextInitialized設定為True


  考慮下一個NFT是否被初始化,


  如轉移下圖中tokenId=3的NFT:


  [外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片儲存下來直接上傳(img-wKsxnwNP-1675684640935)


  該NFT轉移後,由於破壞了擁有者0x2的連續性,所以我們需要重寫tokenId=4的對應資料,程式碼如下:


  if(prevOwnershipPacked&_BITMASK_NEXT_INITIALIZED==0){


  uint256 nextTokenId=tokenId+1;


  if(_packedOwnerships[nextTokenId]==0){


  if(nextTokenId!=_currentIndex){


  _packedOwnerships[nextTokenId]=prevOwnershipPacked;


  }


  }


  此處使用了_packedOwnerships[nextTokenId]==0排除了tokenId=4轉移的特殊情況。該NFT位於連續NFT的末尾,轉移此NFT不會破環連續性


  至此,我們完成了NFT的轉移的核心流程。接下來就是已經介紹過的Transfer釋放流程:


  uint256 toMasked=uint256(uint160(to))&_BITMASK_ADDRESS;


  assembly{


  //Emit the`Transfer`event.


  log4(


  0,//Start of data(0,since no data).


  0,//End of data(0,since no data).


  _TRANSFER_EVENT_SIGNATURE,//Signature.


  from,//`from`.


  toMasked,//`to`.


  tokenId//`tokenId`.


  )


  }


  if(toMasked==0)_revert(TransferToZeroAddress.selector);


  safeTransferFrom作為transferFrom的安全版本,該函式只是增加了_checkContractOnERC721Received檢測,此檢測函式已在上文進行了介紹,此處不再贅述。


  銷燬


  burn銷燬的核心函式為_burn函式,由於銷燬事實上相當於將NFT轉移給0地址,所以其大量邏輯與transfer類似。


  _burn函式定義如下:


  function _burn(uint256 tokenId,bool approvalCheck)internal virtual


  1


  引數含義如下:


  tokenId待銷燬NFT的tokenId


  approvalCheck是否檢測函式呼叫者的許可權


  大致流程如下:


  獲取待銷燬NFT擁有者的資訊


  如果設定approvalCheck為true則檢測函式呼叫者的相關許可權


  清空待銷燬NFT的授權approve資料


  減少擁有者的balance


  在_packedOwnerships中寫入銷燬資訊


  恢復代幣連續性


  釋放事件


  接下來,我們詳細分析具體的程式碼實現:


  uint256 prevOwnershipPacked=_packedOwnershipOf(tokenId);


  address from=address(uint160(prevOwnershipPacked));


  (uint256 approvedAddressSlot,address approvedAddress)=_getApprovedSlotAndAddress(tokenId);


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

相關文章