Skip to content

Commit

Permalink
added polygon subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
ShuaJJ committed Oct 21, 2023
1 parent bb1f6e1 commit 00abbe7
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 36 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ coverage
node_modules
out

#subgraph
generated
subgraph/tests/
subgraph/abis/
subgraph/build/

# files
*.env
*.log
Expand Down
2 changes: 1 addition & 1 deletion frontend/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ export const contractPostType = (type: string) => {

export const ipfsDomain = "ipfs.w3s.link";

export const graphUri = "https://api.studio.thegraph.com/query/49276/cryptopia-sepolia/v0.0.1";
export const graphUri = "https://api.studio.thegraph.com/query/49276/cryptopia-polygon/v0.0.1";
3 changes: 3 additions & 0 deletions subgraph/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"User": {
"address": "0xC97d5D78E72f9e782559274BE158aEb30cab8a8C",
"startBlock": 41466117
},
"Post": {
"address": "0x235cddbf69af897C3299083642450740871251D8"
}
}
}
29 changes: 17 additions & 12 deletions subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,36 @@ type OwnershipTransferred @entity(immutable: true) {
transactionHash: Bytes!
}

type ResponseVerified @entity(immutable: true) {
type VerificationReceived @entity(immutable: true) {
id: Bytes!
result_appId: Bytes! # bytes16
result_namespace: Bytes! # bytes16
result_version: Bytes! # bytes32
result_auths: [Bytes!]! # tuple[]
result_claims: [Bytes!]! # tuple[]
result_signedMessage: Bytes! # bytes
sender: Bytes! # address
sourceChain: Int! # uint16
blockNumber: BigInt!
blockTimestamp: BigInt!
transactionHash: Bytes!
}

type VerificationReceived @entity(immutable: true) {
type Verify @entity(immutable: true) {
id: Bytes!
sender: Bytes! # address
sourceChain: Int! # uint16
user: Bytes! # address
cid: String! # string
blockNumber: BigInt!
blockTimestamp: BigInt!
transactionHash: Bytes!
}

type Verify @entity(immutable: true) {
type Comment @entity(immutable: true) {
id: Bytes!
user: Bytes! # address
content: String! # string
blockNumber: BigInt!
blockTimestamp: BigInt!
transactionHash: Bytes!
}

type CreatePost @entity(immutable: true) {
id: Bytes!
author: Bytes! # address
postType: Int! # uint8
cid: String! # string
blockNumber: BigInt!
blockTimestamp: BigInt!
Expand Down
34 changes: 34 additions & 0 deletions subgraph/src/post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
Comment as CommentEvent,
CreatePost as CreatePostEvent
} from "../generated/Post/Post"
import { Comment, CreatePost } from "../generated/schema"

export function handleComment(event: CommentEvent): void {
let entity = new Comment(
event.transaction.hash.concatI32(event.logIndex.toI32())
)
entity.user = event.params.user
entity.content = event.params.content

entity.blockNumber = event.block.number
entity.blockTimestamp = event.block.timestamp
entity.transactionHash = event.transaction.hash

entity.save()
}

export function handleCreatePost(event: CreatePostEvent): void {
let entity = new CreatePost(
event.transaction.hash.concatI32(event.logIndex.toI32())
)
entity.author = event.params.author
entity.postType = event.params.postType
entity.cid = event.params.cid

entity.blockNumber = event.block.number
entity.blockTimestamp = event.block.timestamp
entity.transactionHash = event.transaction.hash

entity.save()
}
20 changes: 0 additions & 20 deletions subgraph/src/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import {
ApplyVerify as ApplyVerifyEvent,
Follow as FollowEvent,
OwnershipTransferred as OwnershipTransferredEvent,
ResponseVerified as ResponseVerifiedEvent,
VerificationReceived as VerificationReceivedEvent,
Verify as VerifyEvent
} from "../generated/User/User"
import {
ApplyVerify,
Follow,
OwnershipTransferred,
ResponseVerified,
VerificationReceived,
Verify
} from "../generated/schema"
Expand Down Expand Up @@ -60,24 +58,6 @@ export function handleOwnershipTransferred(
entity.save()
}

export function handleResponseVerified(event: ResponseVerifiedEvent): void {
let entity = new ResponseVerified(
event.transaction.hash.concatI32(event.logIndex.toI32())
)
entity.result_appId = event.params.result.appId
entity.result_namespace = event.params.result.namespace
entity.result_version = event.params.result.version
entity.result_auths = event.params.result.auths
entity.result_claims = event.params.result.claims
entity.result_signedMessage = event.params.result.signedMessage

entity.blockNumber = event.block.number
entity.blockTimestamp = event.block.timestamp
entity.transactionHash = event.transaction.hash

entity.save()
}

export function handleVerificationReceived(
event: VerificationReceivedEvent
): void {
Expand Down
26 changes: 23 additions & 3 deletions subgraph/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ dataSources:
- ApplyVerify
- Follow
- OwnershipTransferred
- ResponseVerified
- VerificationReceived
- Verify
abis:
Expand All @@ -30,10 +29,31 @@ dataSources:
handler: handleFollow
- event: OwnershipTransferred(indexed address,indexed address)
handler: handleOwnershipTransferred
- event: ResponseVerified((bytes16,bytes16,bytes32,(uint8,bool,uint256,bytes,bytes)[],(uint8,bytes16,bytes16,uint256,bytes,uint256,bytes)[],bytes))
handler: handleResponseVerified
- event: VerificationReceived(address,uint16)
handler: handleVerificationReceived
- event: Verify(address,string)
handler: handleVerify
file: ./src/user.ts
- kind: ethereum
name: Post
network: mumbai
source:
address: "0x235cddbf69af897C3299083642450740871251D8"
abi: Post
startBlock: 41466156
mapping:
kind: ethereum/events
apiVersion: 0.0.7
language: wasm/assemblyscript
entities:
- Comment
- CreatePost
abis:
- name: Post
file: ./abis/Post.json
eventHandlers:
- event: Comment(address,string)
handler: handleComment
- event: CreatePost(indexed address,indexed uint8,string)
handler: handleCreatePost
file: ./src/post.ts

0 comments on commit 00abbe7

Please sign in to comment.