The first starcoin & move hacksong source code analysis - P (a)

Starcoin 2021-09-15 08:20:28
starcoin hacksong source code analysis


Overall introduction

P(A) It's the first Move Hacker song NFT A project of the track , from MemeX Team designed . This year, there are many NFT project , From functional integrity 、 Project completion 、 Creative 、 Comprehensive consideration of display degree and other aspects ,P(A) It's a good one NFT project .NFT It's a very popular track at present , and Move stay NFT The field has great advantages .P(A) Use Move Realization , It can be said that it combines well Move Characteristics of .

Here we analyze the contract source code , Let's learn how to use Move Implement a simple one NFT. Let's see first One Next P(A) The overall design drawing of the project :

You can see some important information from the figure above :

  1. Core data structure :
  • NFT
  • NFT_Info
  • Market
  1. Core function :
  • init_market
  • mint

Logically speaking , Simple and direct , contract Owner adopt init_market Initialize a Market, Ordinary users can mint To buy NFT. Next, let's analyze the source code .

Core data structure

P(A) Contains multiple data structures :Art、NFT、UniqList、NFT_INFO、MARKET, The relationship between them is shown in the figure below :

1. Art

struct Art has store, copy, drop { prob_a: u8, prob_b: u8, param_1: vector<u64>, param_2: vector<u64>}

This is a NFT Metadata information required for rendering , No, key Of ability, Means you can copy 、 Can discard 、 Energy storage . Here's the advice NFT Metadata cannot be copied or discarded .

  1. NFT
struct NFT has store { id: u8,// Unique identification next_nft_id: u8,// Put... In the form of a linked list NFT Identification string , Easy to track next_nft_owner: address,// Put... In the form of a linked list address String together , Easy to track data: Art,// NFT Metadata sell_status: bool,// state price: u128,// Price }

This is a NFT Specific data , Only storage capacity , It means that you can't copy and discard . Very convenient to play Move The advantages of , Use virtual machines to ensure NFT The integrity of 、 Uniqueness, etc .

  1. UniqList
struct UniqList has key { data: vector<NFT> // Store user owned NFT list }

UniqList Although an array is used , But don't worry about large arrays here , Because each user's NFT It's stored under your own account , It won't affect all users .

  1. NFT_INFO
struct NFT_INFO has store, drop { id: u8,// NFT identification next_nft_id: u8, next_nft_owner: address, data: Art, price: u128,// Price }

This is a NFT Generated information , For display . Yes NFT Of id 了 ,Art It's a little redundant here .

  1. Market
struct MARKET has key { head: address, cur_num: u8,// Current quantity min_price: u128,// Minimum price market_nft_info: vector<NFT_INFO>// be-all NFT Information }

All the... Are stored here NFT Information . There seems to be a problem with large arrays , because P(A) It limits the maximum number of 100 individual NFT, So don't worry here . however , Lists like this show data , Recommended by Event The way , Polymerize under the chain .

Function Definition

  1. init_market function
public(script) fun init_market(account: signer)

This is the contract initialization entry , In the contract Owner Initialize a... Under the account Market. The function uses public(script) visibility .

  1. mint function
public(script) fun mint(account: signer, amount: u128) acquires UniqList, MARKET

This is what users buy NFT Entrance , It's also public(script) visibility .acquires Indicates that the current Module Defined UniqList and MARKET Two data structures .

reflection & summary

P(A) In terms of contract implementation details , The code is relatively simple , Make the most of it Move stay NFT The advantages of the scene , It saves a lot of unnecessary security checks , For example, to prevent NFT Lost... Etc . Let's summarize the advantages and disadvantages of contract code implementation .

  1. advantage :
  • NFT Is a hot direction , It's also Move A typical application scenario to give full play to its advantages
  • part Struct In the definition, it skillfully applies Move Of ability To ensure safety and reliability , for example NFT, Cannot copy and discard
  • All functions are public(script) visibility , There is no excess entrance exposed
  • NFT The data is stored under the user's own account ,NFT There will be no problem with large arrays
  • The design of linked list is used , Easy to track
  1. Can further optimize :
  • NFT internal data Art It should also not be copied and discarded , Avoid producing the same content NFT
  • Key data status changes should be defined Event, Convenient offline monitoring
  • Market The array can be stored under the chain , Avoid possible large array problems
  • Some details are optimized , for example Struct The name is in the same case 、 Redundant data, etc
  • Can add richer functions , such as NFT Transfer and so on

in general ,P(A) Cleverly applied Move The advantages of , stay NFT Made a good attempt in the direction of , here Check out the full code .

版权声明
本文为[Starcoin]所创,转载请带上原文链接,感谢
https://javamana.com/2021/09/20210909135404160c.html

  1. Java + SSM Social Insurance Pension System for Computer Graduation Design
  2. Java inheritance
  3. Java method review
  4. java JVM
  5. Java Basics
  6. Java file operation object IO stream
  7. Java console reads multi character input and output
  8. Java simple array sorting
  9. In addition to MySQL master-slave, you have another choice, Galera
  10. Configuration standard dockerfile et docker-composer.yml
  11. 字节大神强推千页PDF学习笔记,2021Java开发学习路线,
  12. 字节大牛耗时八个月又一力作,靠这份Java知识点PDF成功跳槽,
  13. 字节大牛教你手撕Java学习,最新大厂程序员进阶宝典,
  14. Comment l'automne est - il beau?Ces 24 ensembles de modèles d'automne et d'hiver sont grands, minces et vieillissants
  15. 字節大牛教你手撕Java學習,最新大廠程序員進階寶典,
  16. 字節大牛耗時八個月又一力作,靠這份Java知識點PDF成功跳槽,
  17. Byte Bull vous apprend à déchiqueter Java à la main, le dernier dictionnaire avancé des programmeurs de grandes usines,
  18. Byte Bull a pris huit mois à travailler dur et a réussi à changer d'emploi avec ce PDF Java Knowledge point.
  19. Byte God Push 1000 pages PDF Learning notes, 2021 Java Development Learning route,
  20. Five minutes to understand MySQL index push down
  21. Spring中@within与@target的一些区别
  22. 力荐:提高千倍效率的一些 Java 代码小技巧
  23. Redis技术专题系列之帮你从底层彻底吃透RDB技术原理(基础篇)
  24. Juan Benet et vitalik buterin discutent des réflexions sur les médias sociaux décentralisés
  25. Ipfs Weekly Report 152 | pinata launched "submarining"
  26. Performance optimization issue 03 - HTTP request optimization
  27. JavaScript genrator generator
  28. 字节跳动Java面试全套真题解析在互联网火了,面试大厂应该注意哪些问题?
  29. 字节跳动Java社招,2021年阿里 腾讯 快手offer都已拿到!
  30. 用Java实现红黑树
  31. 使用Redis Stream来做消息队列和在Asp.Net Core中的实现
  32. 海量列式非关系数据库HBase 架构,shell与API
  33. Redis Technology Topic Series vous aide à comprendre les principes de la technologie rdb du Bas (Basic)
  34. Conseils: quelques conseils pour améliorer l'efficacité du Code Java
  35. Quelques différences entre @ within et @ Target au printemps
  36. 海量列式非關系數據庫HBase 架構,shell與API
  37. Architecture, Shell et API de base de données non relationnelle à grande échelle
  38. Mise en œuvre de l'arbre Rouge et noir en Java
  39. Byte Hopping Java Service Call, 2021 Alibaba Tencent Express offer a été obtenu!
  40. Byte Jump Java interview Full Set of true Problems Analysis in Internet fire, interview Factory should pay attention to what Problems?
  41. La dernière réponse à l'entrevue de développement Android, l'hiver froid de l'industrie
  42. A young Lexus, the new NX refuses to be mediocre and mature
  43. Interprétation approfondie de l'équipe sin7y: application de plookup dans la conception de zkevm
  44. Java basic knowledge point Combing, redis Common Data Structures and Using scenario Analysis,
  45. Five minutes to understand MySQL index push down
  46. Data structure and algorithm (XI) -- algorithm recursion
  47. Programmation asynchrone Java scirp, développement frontal de base
  48. Java basic knowledge point video, three sides ant Gold Clothing successfully obtained offer,
  49. Oracle Linux bascule le noyau uek vers le noyau rhck pour résoudre les problèmes de compatibilité acfs
  50. After the grand finale of spring in jade mansion, after reading many comments, I began to sympathize with white deer
  51. 字节跳动Java高级工程师,统一命名服务、集群管理、分布式应用?
  52. 字节跳动Java高级工程师,深入分布式缓存从原理到实践技术分享,
  53. 字节跳动第三轮技术面,阿里P8架构师Java大厂面试题总结,
  54. 字节跳动社招Java面试,超通俗解析CountDownLatch用法和源码,
  55. 字节跳动最新开源,最经典的HashMap图文详解,
  56. 字節跳動第三輪技術面,阿裏P8架構師Java大廠面試題總結,
  57. Byte Jumping the Third Third Technical surface, Ali P8 Architect Java Factory Interview Question summary,
  58. L'ingénieur Java senior de Byte Hopping approfondit la mise en cache distribuée, du principe au partage de la technologie pratique.
  59. Byte Jump Java Senior Engineer, Unified Naming service, Cluster Management, Distributed application?
  60. Plusieurs méthodes de transfert de fichiers entre Windows et Linux