6 dakika
Arweave Üzerinde Subgraphlar Oluşturma
Arweave support in Graph Node and on Subgraph Studio is in beta: please reach us on Discord with any questions about building Arweave Subgraphs!
Bu rehberde, Arweave blok zincirini indekslemek için nasıl Subgraphs oluşturacağınızı ve dağıtacağınızı öğreneceksiniz.
Arweave Nedir?
Arweave protokolü geliştiricilere verileri kalıcı olarak depolama imkanı sağlar ve bu, Arweave ile IPFS arasındaki temel farktır. IPFS’de böyle bir özellik bulunmaz; yani IPFS’te depolanan dosyalar kalıcı değildir ve Arweave’de depolanan dosyalar değiştirilemez veya silinemez.
Arweave, protokolü farklı programlama dillerine entegre etmek için halihazırda çok sayıda kütüphane oluşturmuştur. Daha fazla bilgi için şurayı kontrol edebilirsiniz:
Arweave Subgraphları Nedir?
The Graph, “Subgraph” adı verilen özel açık API’ler oluşturmanıza olanak tanır. Subgraph’ler, endeksleyicilere (sunucu operatörleri) bir blokzincirinde hangi verilerin endeksleneceğini ve sunucularında saklanacağını belirtmek için kullanılır. Böylece GraphQL kullanarak bu verilere istediğiniz zaman sorgu yapabilirsiniz.
Graph Düğümü artık Arweave protokolündeki verileri endeksleyebiliyor. Mevcut entegrasyon yalnızca Arweave’i bir blokzinciri olarak (bloklar ve işlemler) endekslemekte olup, henüz depolanan dosyaları endekslememektedir.
Bir Arweave Subgraph’ı Oluşturma
Arweave Subgraphları oluşturabilmek ve dağıtabilmek için iki pakete ihtiyacınız vardır:
@graphprotocol/graph-cli
above version 0.30.2 - This is a command-line tool for building and deploying Subgraphs. Click here to download usingnpm
.@graphprotocol/graph-ts
above version 0.27.0 - This is library of Subgraph-specific types. Click here to download usingnpm
.
Subgraph’ın bileşenleri
There are three components of a Subgraph:
1. Manifesto - subgraph.yaml
İlgilenilen veri kaynaklarını ve bunların nasıl işlenmesi gerektiğini tanımlar. Arweave yeni bir veri kaynağı türüdür.
2. Şema - schema.graphql
Burada, GraphQL kullanarak Subgraph’ınızı indeksledikten sonra hangi verileri sorgulayabilmek istediğinizi tanımlarsınız. Bu aslında, modelin bir istek gövdesinin yapısını tanımladığı bir API modeline benzer.
The requirements for Arweave Subgraphs are covered by the existing documentation.
3. AssemblyScript Eşlemeleri - mapping.ts
Bu, birisi sizin etkinliklerini gözlemlediğiniz veri kaynaklarıyla etkileşimde bulunduğunda verinin nasıl alınması ve depolanması gerektiğini belirleyen mantıktır. Veri çevrilir ve belirttiğiniz şemaya göre depolanır.
During Subgraph development there are two key commands:
1$ graph codegen # generates types from the schema file identified in the manifest2$ graph build # generates Web Assembly from the AssemblyScript files, and prepares all the Subgraph files in a /build folder
Subgraph Manifest Tanımı
The Subgraph manifest subgraph.yaml
identifies the data sources for the Subgraph, the triggers of interest, and the functions that should be run in response to those triggers. See below for an example Subgraph manifest for an Arweave Subgraph:
1specVersion: 1.3.02description: Arweave Blocks Indexing3schema:4 file: ./schema.graphql # link to the schema file5dataSources:6 - kind: arweave7 name: arweave-blocks8 network: arweave-mainnet # The Graph only supports Arweave Mainnet9 source:10 owner: 'ID-OF-AN-OWNER' # The public key of an Arweave wallet11 startBlock: 0 # set this to 0 to start indexing from chain genesis12 mapping:13 apiVersion: 0.0.914 language: wasm/assemblyscript15 file: ./src/blocks.ts # link to the file with the Assemblyscript mappings16 entities:17 - Block18 - Transaction19 blockHandlers:20 - handler: handleBlock # the function name in the mapping file21 transactionHandlers:22 - handler: handleTx # the function name in the mapping file
- Arweave Subgraphs introduce a new kind of data source (
arweave
) - Ağ, sağlayıcı Graph Düğümü üzerindeki bir ağa karşılık gelmelidir. Subgraph Studio’da, Arweave’in ana ağı
arweave-mainnet
olarak tanımlanır - Arweave veri kaynakları, bir Arweave cüzdanının genel anahtarı olan opsiyonel bir source.owner alanı sunar
Arweave veri kaynakları iki tür işleyiciyi destekler:
blockHandlers
- Her yeni Arweave blokunda çalıştırılır. source.owner belirtilmesi gerekmez.transactionHandlers
- Veri kaynağının sahibinin source.owner olduğu her işlemde çalıştırılır. Şu andatransactionHandlers
için bir sahip (owner) gereklidir. Kullanıcılar tüm işlemleri gerçekleştirmek istiyorlarsasource.owner
olarak boş dize "" sağlamalıdırlar
source.owner, sahibin adresi veya Genel Anahtarı olabilir.
İşlemler Arweave permaweb’in yapı taşlarıdır ve son kullanıcılar tarafından oluşturulan nesnelerdir.
Not: Irys (önceden Bundlr) işlemleri henüz desteklenmemektedir.
Şema Tanımı
Schema definition describes the structure of the resulting Subgraph database and the relationships between entities. This is agnostic of the original data source. There are more details on the Subgraph schema definition here.
AssemblyScript Eşlemeleri
Olayları işlemek için kullanılan işleyiciler AssemblyScript ile yazılmıştır.
Arweave endeksleme, AssemblyScript API için Arweave’e özgü veri türlerini tanıtır.
1class Block {2 timestamp: u643 lastRetarget: u644 height: u645 indepHash: Bytes6 nonce: Bytes7 previousBlock: Bytes8 diff: Bytes9 hash: Bytes10 txRoot: Bytes11 txs: Bytes[]12 walletList: Bytes13 rewardAddr: Bytes14 tags: Tag[]15 rewardPool: Bytes16 weaveSize: Bytes17 blockSize: Bytes18 cumulativeDiff: Bytes19 hashListMerkle: Bytes20 poa: ProofOfAccess21}2223class Transaction {24 format: u3225 id: Bytes26 lastTx: Bytes27 owner: Bytes28 tags: Tag[]29 target: Bytes30 quantity: Bytes31 data: Bytes32 dataSize: Bytes33 dataRoot: Bytes34 signature: Bytes35 reward: Bytes36}
Blok işleyiciler bir Block
alırken, işlemler bir Transaction
alır.
Arweave Subgraph’inin eşleştirmelerini yazmak, bir Ethereum Subgraph’inin eşleştirmelerini yazmaya oldukça benzerdir. Daha fazla bilgi için buraya tıklayın.
Subgraph Studio’da Arweave Subgraph’i Dağıtma
Once your Subgraph has been created on your Subgraph Studio dashboard, you can deploy by using the graph deploy
CLI command.
1graph deploy --access-token <erişim-jetonunuz>
Arweave Subgraph’ını Sorgulama
The GraphQL endpoint for Arweave Subgraphs is determined by the schema definition, with the existing API interface. Please visit the GraphQL API documentation for more information.
Örnek Subgraph’ler
Here is an example Subgraph for reference:
FAQ
Can a Subgraph index Arweave and other chains?
No, a Subgraph can only support data sources from one chain/network.
Depolanmış dosyaları Arweave üzerinde indeksleyebilir miyim?
Şu anda Graph, Arweave’yi yalnızca bir blok zinciri (blokları ve işlemleri) olarak indekslemektedir.
Can I identify Bundlr bundles in my Subgraph?
Bu şu anda desteklenmemektedir.
İşlemleri belirli bir hesaba özel olarak nasıl filtreleyebilirim?
source.owner kullanıcının genel anahtarı veya hesap adresi olabilir.
Mevcut şifreleme formatı nedir?
Data is generally passed into the mappings as Bytes, which if stored directly is returned in the Subgraph in a hex
format (ex. block and transaction hashes). You may want to convert to a base64
or base64 URL
-safe format in your mappings, in order to match what is displayed in block explorers like Arweave Explorer.
Aşağıdaki bytesToBase64(bytes: Uint8Array, urlSafe: boolean): string
yardımcı fonksiyonu kullanılabilir. Bu fonksiyon, graph-ts
’e eklenecektir:
1const base64Alphabet = [2 "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",3 "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",4 "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",5 "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",6 "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/"7];89const base64UrlAlphabet = [10 "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",11 "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",12 "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",13 "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",14 "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "_"15];1617function bytesToBase64(bytes: Uint8Array, urlSafe: boolean): string {18 let alphabet = urlSafe? base64UrlAlphabet : base64Alphabet;1920 let result = '', i: i32, l = bytes.length;21 for (i = 2; i < l; i += 3) {22 result += alphabet[bytes[i - 2] >> 2];23 result += alphabet[((bytes[i - 2] & 0x03) << 4) | (bytes[i - 1] >> 4)];24 result += alphabet[((bytes[i - 1] & 0x0F) << 2) | (bytes[i] >> 6)];25 result += alphabet[bytes[i] & 0x3F];26 }27 if (i === l + 1) { // 1 octet yet to write28 result += alphabet[bytes[i - 2] >> 2];29 result += alphabet[(bytes[i - 2] & 0x03) << 4];30 if (!urlSafe) {31 result += "==";32 }33 }34 if (!urlSafe && i === l) { // 2 octets yet to write35 result += alphabet[bytes[i - 2] >> 2];36 result += alphabet[((bytes[i - 2] & 0x03) << 4) | (bytes[i - 1] >> 4)];37 result += alphabet[(bytes[i - 1] & 0x0F) << 2];38 if (!urlSafe) {39 result += "=";40 }41 }42 return result;43}