Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add startBlock parsing to manifest #266

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"devDependencies": {
"@graphprotocol/contracts": "6.2.0",
"@graphprotocol/graph-cli": "0.68.0",
"@graphprotocol/graph-cli": "0.68.5",
"@graphprotocol/graph-ts": "0.32.0",
"@types/node": "^14.0.13",
"@typescript-eslint/eslint-plugin": "^3.3.0",
Expand Down
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ type SubgraphDeploymentManifest @entity(immutable:true) {
network: String
"Whether the subgraph is a SpS/SbS. Null if we can't parse it"
poweredBySubstreams: Boolean
"Start block for the deployment. It's the lowest startBlock found (0 if some data source doesn't contain a start block)"
startBlock: BigInt
}

# TODO - add when we have the ability to parse data sources
Expand Down
23 changes: 21 additions & 2 deletions src/mappings/ipfs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json, Bytes, dataSource, JSONValueKind, log, DataSourceContext } from '@graphprotocol/graph-ts'
import { json, Bytes, dataSource, JSONValueKind, log, DataSourceContext, BigInt } from '@graphprotocol/graph-ts'
import {
SubgraphMeta,
SubgraphVersionMeta,
Expand Down Expand Up @@ -133,6 +133,25 @@ export function handleSubgraphDeploymentManifest(content: Bytes): void {
}
let substreamsSplitTry = manifest.split('- kind: substreams', 2)
subgraphDeploymentManifest.poweredBySubstreams = substreamsSplitTry.length > 1

// startBlock calculation
let templatesSplit = manifest.split("templates:")
let nonTemplateManifestSplit = templatesSplit[0] // we take the left as we want to remove the templates for the source checks.
let sourcesSplit = nonTemplateManifestSplit.split("source:") // We want to know how many source definitions we have
let startBlockSplit = nonTemplateManifestSplit.split("startBlock: ") // And how many startBlock definitions we have to know if we should set startBlock to 0

if (sourcesSplit.length > startBlockSplit.length) {
subgraphDeploymentManifest.startBlock = BigInt.fromI32(0)
} else {
// need to figure the minimum startBlock defined, we skip i = 0 as we know it's not gonna contain a start block num, since it's before the first appearance of "startBlock:"
let min = BigInt.fromI32(0)
for(let i = 1; i < startBlockSplit.length; i++) {
let numString = startBlockSplit[i].split("\n", 1)[0].toString()
let num = BigInt.fromString(numString)
min = min == BigInt.fromI32(0) ? num : min <= num ? min : num
}
subgraphDeploymentManifest.startBlock = min
}
}
subgraphDeploymentManifest.save()
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,10 @@
"@graphprotocol/sdk" "^0.5.0"
console-table-printer "^2.11.1"

"@graphprotocol/[email protected].0":
version "0.68.0"
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-cli/-/graph-cli-0.68.0.tgz#30464a75b7341d6c468f7ff3dba01259efff6b78"
integrity sha512-F3l1t+0qfGAGbD3i/3/qDnwZp8z37OE2PmdQdQkbImq1h34Cy8mjRKvc3ZJ4E2G16JkIevqK2rWwTRHcIGMTNA==
"@graphprotocol/[email protected].5":
version "0.68.5"
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-cli/-/graph-cli-0.68.5.tgz#58cf65d15f41f1a30defe1cd50474d7c1205dd6a"
integrity sha512-3GY2pYr5LksO6JY6s5nvePnSKVdtzDEn1CUGezyjCMR1uq9YIXMPXKqcnrzCX/DLugioEabiEi2+yOg9+rnFDQ==
dependencies:
"@float-capital/float-subgraph-uncrashable" "^0.0.0-alpha.4"
"@oclif/core" "2.8.6"
Expand Down
Loading