Skip to content

Commit 8fdf799

Browse files
committed
feat: add block-size subgraph
1 parent 4fa1ac0 commit 8fdf799

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed

block-size-subgraph/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
build/
2+
generated/
3+
node_modules/
4+
5+
package-lock.json
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"anonymous": false,
4+
"inputs": [],
5+
"name": "BlockDataSource",
6+
"type": "event"
7+
}
8+
]

block-size-subgraph/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "block-size-subgraph",
3+
"license": "MIT",
4+
"scripts": {
5+
"codegen": "graph codegen",
6+
"build": "graph build",
7+
"create-local": "graph create --node http://localhost:8020/ block-size-subgraph",
8+
"remove-local": "graph remove --node http://localhost:8020/ block-size-subgraph",
9+
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001/ block-size-subgraph"
10+
},
11+
"devDependencies": {
12+
"@graphprotocol/graph-cli": "0.95.0",
13+
"@graphprotocol/graph-ts": "0.37.0"
14+
}
15+
}

block-size-subgraph/schema.graphql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type BlockSize @entity(immutable: true) {
2+
id: ID!
3+
number: BigInt!
4+
size: BigInt!
5+
}

block-size-subgraph/src/mapping.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ethereum , BigInt} from "@graphprotocol/graph-ts";
2+
import { BlockSize } from "../generated/schema";
3+
4+
export function handleBlock(block: ethereum.Block): void {
5+
let blockSize = new BlockSize(block.hash.toHex());
6+
7+
blockSize.number = block.number;
8+
if (block.size !== null) {
9+
blockSize.size = block.size!;
10+
} else {
11+
blockSize.size = BigInt.fromU64(0);
12+
}
13+
blockSize.save();
14+
}

block-size-subgraph/subgraph.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
specVersion: 1.3.0
2+
description: A subgraph that indexes the size of each block.
3+
schema:
4+
file: ./schema.graphql
5+
dataSources:
6+
- kind: ethereum
7+
name: BlockDataSource
8+
network: mainnet
9+
source:
10+
address: "0x0000000000000000000000000000000000000000"
11+
abi: BlockDataSource
12+
startBlock: 10000000
13+
mapping:
14+
kind: ethereum/events
15+
apiVersion: 0.0.7
16+
language: wasm/assemblyscript
17+
entities:
18+
- BlockSize
19+
abis:
20+
- name: BlockDataSource
21+
file: ./abis/BlockDataSource.json
22+
blockHandlers:
23+
- handler: handleBlock
24+
file: ./src/mapping.ts

0 commit comments

Comments
 (0)