dapp理財分紅返現系統開發模式案例

lxqy1668發表於2023-04-04


可並行鏈(Parachain)是區塊鏈的一種簡化形式,它將安全付諸於由“中繼鏈”提供,而非自身提供。中繼鏈的名稱來自於它不僅為所附著的可並行鏈提供安全,而且為二者間的安全訊息傳遞提供保證。可並行鏈的一個關鍵特性是所執行的計算是天生獨立的,I88智慧合約I928系統開發8024

  

  區塊鏈屬於一種去中心化的記錄技術。參與到系統上的節點,可能不屬於同一組織、彼此無需信任;區塊鏈資料由所有節點共同維護,每個參與維護節點都能複製獲得一份完整記錄的複製,由此可以看出區塊鏈技術的特點:

  

  specVersion:0.0.1

  

  schema:

  

  file:./schema.graphql

  

  dataSources:

  

  -kind:ethereum/contract

  

  name:GravatarRegistry

  

  network:ropsten

  

  source:

  

  address:"0x8CfDDbD441Fc6ffE3c02244a6B93EF9e89FaFA4D"

  

  abi:GravatarRegistry

  

  mapping:

  

  kind:ethereum/events

  

  apiVersion:0.0.2

  

  language:wasm/assemblyscript

  

  entities:

  

  -NewGravatar

  

  -UpdatedGravatar

  

  abis:

  

  -name:GravatarRegistry

  

  file:./abis/GravatarRegistry.json

  

  eventHandlers:

  

  -event:NewGravatar(uint256,address,string,string)

  

  handler:handleNewGravatar

  

  -event:UpdatedGravatar(uint256,address,string,string)

  

  handler:handleUpdatedGravatar

  

  file:./src/mapping.ts

  

  Gravatar[]public gravatars;

  

  mapping(uint=>address)public gravatarToOwner;

  

  mapping(address=>uint)public ownerToGravatar;

  

  function createGravatar(string memory _displayName,string memory _imageUrl)public{

  

  require(ownerToGravatar[msg.sender]==0);

  

  gravatars.push(Gravatar(msg.sender,_displayName,_imageUrl));

  

  uint id=gravatars.length-1;

  

  gravatarToOwner[id]=msg.sender;

  

  ownerToGravatar[msg.sender]=id;

  

  emit NewGravatar(id,msg.sender,_displayName,_imageUrl);

  

  }

  

  function updateGravatarName(string memory _displayName)public{

  

  require(ownerToGravatar[msg.sender]!=0);

  

  require(msg.sender==gravatars[ownerToGravatar[msg.sender]].owner);

  

  uint id=ownerToGravatar[msg.sender];

  

  gravatars[id].displayName=_displayName;

  

  emit UpdatedGravatar(id,msg.sender,_displayName,gravatars[id].imageUrl);

  

  }

  

  }


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

相關文章