Stepn跑鞋跑步鏈遊系統開發/趣步系統開發/詳情案例/成熟技術/原始碼版

xiaofufu發表於2023-04-24

  區塊鏈技術由此可以從多方面為企業賦能:提供可靠的共享資料,在各方之間建立信任;消除資料孤島,即透過去中心化的,在一個網路享並支援獲許可方訪問的賬本將資料整合到一個系統中;為資料賦予高度安全性


  區塊鏈、人工智慧、數字孿生、人機互動、物聯網等面向資料的新一代資訊科技的演進並非偶然,而是從Web2.0向Web3.0演進的技術準備。從技術上來看,元宇宙是基於Web3.0技術體系和運作機制支撐下的可信數字化價值互動網路,開發:Mrsfu123 是以區塊鏈為核心的Web3.0數字新生態。元宇宙是以區塊鏈為核心的Web3.0技術體系支撐下的新場景、新產業和新生態,將會在數字環境下催生大量創新商業模式,形成數字空間新正規化。


  The specific operation steps are as follows:players first need to download the mobile application STEPN App on the STEPN official website and register their STEPN account through email;After registering and logging in,players can create or import existing Solana wallets in the game and transfer them from the trading platform to the wallet address,so that they can purchase NFT sneakers and receive game rewards in the game.


  In the application market,players can purchase NFT sneakers in four different types:Walker,Jogger,Runner,and Trainer.Different types of shoes have certain restrictions on the player's movement speed.For example,the Walker speed limit is 1-6 km/h,and beyond the corresponding range,movement will not generate token revenue.The prices of different types of shoes also vary,with the Trainer having the highest speed limit as it has the widest range of 1-20 km/h.


  Each type of sneaker is divided into 5 qualities,namely:Common(ordinary,gray),Uncommon(rare,green),Rare(rare,blue),Epic(epic,purple),and Legendary(legendary,orange).Different quality shoes have different attributes and generate different token returns.


  if(approvalCheck){


  if(!_isSenderApprovedOrOwner(approvedAddress,from,_msgSenderERC721A()))


  if(!isApprovedForAll(from,_msgSenderERC721A()))_revert(TransferCallerNotOwnerNorApproved.selector);


  }


  assembly{


  if approvedAddress{


  //This is equivalent to`delete _tokenApprovals[tokenId]`.


  sstore(approvedAddressSlot,0)


  }


  }


  此部分程式碼與transferFrom函式完全一致,不再詳細介紹。


  _packedAddressData[from]+=(1<<_BITPOS_NUMBER_BURNED)-1;


  _packedOwnerships[tokenId]=_packOwnershipData(


  from,


  (_BITMASK_BURNED|_BITMASK_NEXT_INITIALIZED)|_nextExtraData(from,address(0),prevOwnershipPacked)


  );


  此處使用_packedAddressData[from]+=(1<<_BITPOS_NUMBER_BURNED)-1;程式碼將balance-=1和numberBurned+=1合併一起執行。


  其中_BITPOS_NUMBER_BURNED的值為128,為方便讀者理解,我們再次給出_packedAddressData的格式:


  //Bits Layout:


  //-[0..63]`balance`


  //-[64..127]`numberMinted`


  //-[128..191]`numberBurned`


  //-[192..255]`aux`


  mapping(address=>uint256)private _packedAddressData;


  為方便理解,我們將原有程式碼進行重寫:


  _packedAddressData[from]=_packedAddressData[from]+(1<<128)-1


  1


  如此來看,我們首先使用加法完成了numberBurned的更新,然後使用減法完成了balance的更新。


  對於_packOwnershipData函式,最重要的是分析以下部分:


  (_BITMASK_BURNED|_BITMASK_NEXT_INITIALIZED)|_nextExtraData(from,address(0),prevOwnershipPacked)


  我們將burned和_BITMASK_NEXT_INITIALIZED置為True並寫入extraData部分。


  我們將tokenId=3的代幣銷燬,那麼我們需要修正tokenId=4的NFT以避免NFT丟失。這部分程式碼與transferFrom是一致的,實現如下:


  if(prevOwnershipPacked&_BITMASK_NEXT_INITIALIZED==0){


  uint256 nextTokenId=tokenId+1;


  if(_packedOwnerships[nextTokenId]==0){


  if(nextTokenId!=_currentIndex){


  _packedOwnerships[nextTokenId]=prevOwnershipPacked;


  }


  }


  簡單來說,我們只需要將tokenId=2的資料放入tokenId=4的NFT中即可。


  對於釋放事件,使用了emit Transfer(from,address(0),tokenId);語句,較為簡單。


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

相關文章