-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update codegen with changes implemented in mobymask watcher (#148)
* Update codegen with index-block CLI and remove graph-node * Add filter logs by contract flag * Skip generating GQL API for immutable variables * Add config for maxEventsBlockRange * Add new flags in existing watchers
- Loading branch information
Showing
69 changed files
with
825 additions
and
575 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// Copyright 2022 Vulcanize, Inc. | ||
// | ||
|
||
import fs from 'fs'; | ||
import path from 'path'; | ||
import Handlebars from 'handlebars'; | ||
import { Writable } from 'stream'; | ||
|
||
const TEMPLATE_FILE = './templates/index-block-template.handlebars'; | ||
|
||
/** | ||
* Writes the index-block file generated from a template to a stream. | ||
* @param outStream A writable output stream to write the index-block file to. | ||
*/ | ||
export function exportIndexBlock (outStream: Writable): void { | ||
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString(); | ||
const template = Handlebars.compile(templateString); | ||
const indexBlock = template({}); | ||
outStream.write(indexBlock); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
packages/codegen/src/templates/index-block-template.handlebars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// Copyright 2022 Vulcanize, Inc. | ||
// | ||
|
||
{{#if (subgraphPath)}} | ||
import path from 'path'; | ||
{{/if}} | ||
import yargs from 'yargs'; | ||
import 'reflect-metadata'; | ||
import debug from 'debug'; | ||
import assert from 'assert'; | ||
|
||
import { Config, DEFAULT_CONFIG_PATH, getConfig, initClients, JobQueue, indexBlock } from '@vulcanize/util'; | ||
{{#if (subgraphPath)}} | ||
import { GraphWatcher, Database as GraphDatabase } from '@vulcanize/graph-node'; | ||
{{/if}} | ||
|
||
import { Database } from '../database'; | ||
import { Indexer } from '../indexer'; | ||
|
||
const log = debug('vulcanize:index-block'); | ||
|
||
const main = async (): Promise<void> => { | ||
const argv = await yargs.parserConfiguration({ | ||
'parse-numbers': false | ||
}).options({ | ||
configFile: { | ||
alias: 'f', | ||
type: 'string', | ||
require: true, | ||
demandOption: true, | ||
describe: 'Configuration file path (toml)', | ||
default: DEFAULT_CONFIG_PATH | ||
}, | ||
block: { | ||
type: 'number', | ||
require: true, | ||
demandOption: true, | ||
describe: 'Block number to index' | ||
} | ||
}).argv; | ||
|
||
const config: Config = await getConfig(argv.configFile); | ||
const { ethClient, ethProvider } = await initClients(config); | ||
|
||
const db = new Database(config.database); | ||
await db.init(); | ||
{{#if (subgraphPath)}} | ||
|
||
const graphDb = new GraphDatabase(config.database, path.resolve(__dirname, 'entity/*')); | ||
await graphDb.init(); | ||
|
||
const graphWatcher = new GraphWatcher(graphDb, ethClient, ethProvider, config.server); | ||
{{/if}} | ||
|
||
const jobQueueConfig = config.jobQueue; | ||
assert(jobQueueConfig, 'Missing job queue config'); | ||
|
||
const { dbConnectionString, maxCompletionLagInSecs } = jobQueueConfig; | ||
assert(dbConnectionString, 'Missing job queue db connection string'); | ||
|
||
const jobQueue = new JobQueue({ dbConnectionString, maxCompletionLag: maxCompletionLagInSecs }); | ||
|
||
const indexer = new Indexer(config.server, db, ethClient, ethProvider, jobQueue{{#if (subgraphPath)}}, graphWatcher{{/if}}); | ||
await indexer.init(); | ||
{{#if (subgraphPath)}} | ||
|
||
graphWatcher.setIndexer(indexer); | ||
await graphWatcher.init(); | ||
{{/if}} | ||
|
||
await indexBlock(indexer, jobQueueConfig.eventsInBatch, argv); | ||
|
||
await db.close(); | ||
}; | ||
|
||
main().catch(err => { | ||
log(err); | ||
}).finally(() => { | ||
process.exit(0); | ||
}); |
Oops, something went wrong.