the graph introduction

167 阅读1分钟

What is the graph

是一个查询和索引链上数据的去中心化的协议

motivation

  1. 直接从链上获取包含复杂业务逻辑的数据,是非常困难的(限制于数据量和数据结构)
  2. 为链上数据建立索引是非常困难的(数据量太大了)

achitacture

image.png

the flow interacted with each other

  1. A decentralized application adds data to Ethereum through a transaction on a smart contract. (去中心化的应用通过智能合约中的交易添加数据到以太坊(链上))

  2. The smart contract emits one or more events while processing the transaction.(智能合约在处理交易的过程中会触发一个或者多个事件(日志))

  3. Graph Node continually scans Ethereum for new blocks and the data for your subgraph they may contain.(为了你的subgraph可能包含的数据,Graph node 不断地的查询扫描以太坊上的新块和数据)

  4. Graph Node finds Ethereum events for your subgraph in these blocks and runs the mapping handlers you provided. The mapping is a WASM module that creates or updates the data entities that Graph Node stores in response to Ethereum events.(Graph node为了你的subgraph找到哪些以太坊事件,并且执行你定义的那些事件回调函数。这个mapping文件是一个WASM模块,它会创建或者更新数据实体到graph node store中)

  5. The decentralized application queries the Graph Node for data indexed from the blockchain, using the node's GraphQL endpoint. The Graph Node in turn translates the GraphQL queries into queries for its underlying data store in order to fetch this data, making use of the store's indexing capabilities. The decentralized application displays this data in a rich UI for end-users, which they use to issue new transactions on Ethereum. The cycle repeats.(dapp使用graphql查询或者graph node索引的数据)