mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-07-27 10:42:06 +00:00
Fix codegen for non subgraph watchers (#120)
* Fix codegen for non subgraph watchers * Remove graphWatcher.init from generated non subgraph watcher
This commit is contained in:
parent
b2233e16ef
commit
168689a7c7
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
dist/
|
dist/
|
||||||
out/
|
out/
|
||||||
|
|
||||||
|
.vscode
|
||||||
|
@ -13,9 +13,9 @@ const TEMPLATE_FILE = './templates/checkpoint-template.handlebars';
|
|||||||
* Writes the checkpoint file generated from a template to a stream.
|
* Writes the checkpoint file generated from a template to a stream.
|
||||||
* @param outStream A writable output stream to write the checkpoint file to.
|
* @param outStream A writable output stream to write the checkpoint file to.
|
||||||
*/
|
*/
|
||||||
export function exportCheckpoint (outStream: Writable): void {
|
export function exportCheckpoint (outStream: Writable, subgraphPath: string): void {
|
||||||
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
|
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
|
||||||
const template = Handlebars.compile(templateString);
|
const template = Handlebars.compile(templateString);
|
||||||
const checkpoint = template({});
|
const checkpoint = template({ subgraphPath });
|
||||||
outStream.write(checkpoint);
|
outStream.write(checkpoint);
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,9 @@ const TEMPLATE_FILE = './templates/export-state-template.handlebars';
|
|||||||
* Writes the export-state file generated from a template to a stream.
|
* Writes the export-state file generated from a template to a stream.
|
||||||
* @param outStream A writable output stream to write the export-state file to.
|
* @param outStream A writable output stream to write the export-state file to.
|
||||||
*/
|
*/
|
||||||
export function exportState (outStream: Writable): void {
|
export function exportState (outStream: Writable, subgraphPath: string): void {
|
||||||
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
|
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
|
||||||
const template = Handlebars.compile(templateString);
|
const template = Handlebars.compile(templateString);
|
||||||
const exportState = template({});
|
const exportState = template({ subgraphPath });
|
||||||
outStream.write(exportState);
|
outStream.write(exportState);
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,9 @@ const TEMPLATE_FILE = './templates/fill-template.handlebars';
|
|||||||
* Writes the fill file generated from a template to a stream.
|
* Writes the fill file generated from a template to a stream.
|
||||||
* @param outStream A writable output stream to write the fill file to.
|
* @param outStream A writable output stream to write the fill file to.
|
||||||
*/
|
*/
|
||||||
export function exportFill (outStream: Writable): void {
|
export function exportFill (outStream: Writable, subgraphPath: string): void {
|
||||||
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
|
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
|
||||||
const template = Handlebars.compile(templateString);
|
const template = Handlebars.compile(templateString);
|
||||||
const fill = template({});
|
const fill = template({ subgraphPath });
|
||||||
outStream.write(fill);
|
outStream.write(fill);
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ function generateWatcher (visitor: Visitor, contracts: any[], config: any) {
|
|||||||
outStream = outputDir
|
outStream = outputDir
|
||||||
? fs.createWriteStream(path.join(outputDir, 'src/server.ts'))
|
? fs.createWriteStream(path.join(outputDir, 'src/server.ts'))
|
||||||
: process.stdout;
|
: process.stdout;
|
||||||
exportServer(outStream);
|
exportServer(outStream, config.subgraphPath);
|
||||||
|
|
||||||
outStream = outputDir
|
outStream = outputDir
|
||||||
? fs.createWriteStream(path.join(outputDir, 'environments/local.toml'))
|
? fs.createWriteStream(path.join(outputDir, 'environments/local.toml'))
|
||||||
@ -228,17 +228,17 @@ function generateWatcher (visitor: Visitor, contracts: any[], config: any) {
|
|||||||
outStream = outputDir
|
outStream = outputDir
|
||||||
? fs.createWriteStream(path.join(outputDir, 'src/job-runner.ts'))
|
? fs.createWriteStream(path.join(outputDir, 'src/job-runner.ts'))
|
||||||
: process.stdout;
|
: process.stdout;
|
||||||
exportJobRunner(outStream);
|
exportJobRunner(outStream, config.subgraphPath);
|
||||||
|
|
||||||
outStream = outputDir
|
outStream = outputDir
|
||||||
? fs.createWriteStream(path.join(outputDir, 'src/cli/watch-contract.ts'))
|
? fs.createWriteStream(path.join(outputDir, 'src/cli/watch-contract.ts'))
|
||||||
: process.stdout;
|
: process.stdout;
|
||||||
exportWatchContract(outStream);
|
exportWatchContract(outStream, config.subgraphPath);
|
||||||
|
|
||||||
outStream = outputDir
|
outStream = outputDir
|
||||||
? fs.createWriteStream(path.join(outputDir, 'src/cli/checkpoint.ts'))
|
? fs.createWriteStream(path.join(outputDir, 'src/cli/checkpoint.ts'))
|
||||||
: process.stdout;
|
: process.stdout;
|
||||||
exportCheckpoint(outStream);
|
exportCheckpoint(outStream, config.subgraphPath);
|
||||||
|
|
||||||
outStream = outputDir
|
outStream = outputDir
|
||||||
? fs.createWriteStream(path.join(outputDir, 'src/hooks.ts'))
|
? fs.createWriteStream(path.join(outputDir, 'src/hooks.ts'))
|
||||||
@ -248,7 +248,7 @@ function generateWatcher (visitor: Visitor, contracts: any[], config: any) {
|
|||||||
outStream = outputDir
|
outStream = outputDir
|
||||||
? fs.createWriteStream(path.join(outputDir, 'src/fill.ts'))
|
? fs.createWriteStream(path.join(outputDir, 'src/fill.ts'))
|
||||||
: process.stdout;
|
: process.stdout;
|
||||||
exportFill(outStream);
|
exportFill(outStream, config.subgraphPath);
|
||||||
|
|
||||||
outStream = outputDir
|
outStream = outputDir
|
||||||
? fs.createWriteStream(path.join(outputDir, 'src/types.ts'))
|
? fs.createWriteStream(path.join(outputDir, 'src/types.ts'))
|
||||||
@ -284,22 +284,22 @@ function generateWatcher (visitor: Visitor, contracts: any[], config: any) {
|
|||||||
resetStateOutStream = process.stdout;
|
resetStateOutStream = process.stdout;
|
||||||
}
|
}
|
||||||
|
|
||||||
visitor.exportReset(resetOutStream, resetJQOutStream, resetStateOutStream);
|
visitor.exportReset(resetOutStream, resetJQOutStream, resetStateOutStream, config.subgraphPath);
|
||||||
|
|
||||||
outStream = outputDir
|
outStream = outputDir
|
||||||
? fs.createWriteStream(path.join(outputDir, 'src/cli/export-state.ts'))
|
? fs.createWriteStream(path.join(outputDir, 'src/cli/export-state.ts'))
|
||||||
: process.stdout;
|
: process.stdout;
|
||||||
exportState(outStream);
|
exportState(outStream, config.subgraphPath);
|
||||||
|
|
||||||
outStream = outputDir
|
outStream = outputDir
|
||||||
? fs.createWriteStream(path.join(outputDir, 'src/cli/import-state.ts'))
|
? fs.createWriteStream(path.join(outputDir, 'src/cli/import-state.ts'))
|
||||||
: process.stdout;
|
: process.stdout;
|
||||||
importState(outStream);
|
importState(outStream, config.subgraphPath);
|
||||||
|
|
||||||
outStream = outputDir
|
outStream = outputDir
|
||||||
? fs.createWriteStream(path.join(outputDir, 'src/cli/inspect-cid.ts'))
|
? fs.createWriteStream(path.join(outputDir, 'src/cli/inspect-cid.ts'))
|
||||||
: process.stdout;
|
: process.stdout;
|
||||||
exportInspectCID(outStream);
|
exportInspectCID(outStream, config.subgraphPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getConfig (configFile: string): any {
|
function getConfig (configFile: string): any {
|
||||||
|
@ -13,9 +13,9 @@ const TEMPLATE_FILE = './templates/import-state-template.handlebars';
|
|||||||
* Writes the import-state file generated from a template to a stream.
|
* Writes the import-state file generated from a template to a stream.
|
||||||
* @param outStream A writable output stream to write the import-state file to.
|
* @param outStream A writable output stream to write the import-state file to.
|
||||||
*/
|
*/
|
||||||
export function importState (outStream: Writable): void {
|
export function importState (outStream: Writable, subgraphPath: string): void {
|
||||||
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
|
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
|
||||||
const template = Handlebars.compile(templateString);
|
const template = Handlebars.compile(templateString);
|
||||||
const importState = template({});
|
const importState = template({ subgraphPath });
|
||||||
outStream.write(importState);
|
outStream.write(importState);
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,9 @@ const TEMPLATE_FILE = './templates/inspect-cid-template.handlebars';
|
|||||||
* Writes the inspect-cid file generated from a template to a stream.
|
* Writes the inspect-cid file generated from a template to a stream.
|
||||||
* @param outStream A writable output stream to write the inspect-cid file to.
|
* @param outStream A writable output stream to write the inspect-cid file to.
|
||||||
*/
|
*/
|
||||||
export function exportInspectCID (outStream: Writable): void {
|
export function exportInspectCID (outStream: Writable, subgraphPath: string): void {
|
||||||
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
|
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
|
||||||
const template = Handlebars.compile(templateString);
|
const template = Handlebars.compile(templateString);
|
||||||
const inspectCid = template({});
|
const inspectCid = template({ subgraphPath });
|
||||||
outStream.write(inspectCid);
|
outStream.write(inspectCid);
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,9 @@ const TEMPLATE_FILE = './templates/job-runner-template.handlebars';
|
|||||||
* Writes the job-runner file generated from a template to a stream.
|
* Writes the job-runner file generated from a template to a stream.
|
||||||
* @param outStream A writable output stream to write the events file to.
|
* @param outStream A writable output stream to write the events file to.
|
||||||
*/
|
*/
|
||||||
export function exportJobRunner (outStream: Writable): void {
|
export function exportJobRunner (outStream: Writable, subgraphPath: string): void {
|
||||||
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
|
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
|
||||||
const template = Handlebars.compile(templateString);
|
const template = Handlebars.compile(templateString);
|
||||||
const events = template({});
|
const events = template({ subgraphPath });
|
||||||
outStream.write(events);
|
outStream.write(events);
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ export class Reset {
|
|||||||
* @param resetJQOutStream A writable output stream to write the reset job-queue file to.
|
* @param resetJQOutStream A writable output stream to write the reset job-queue file to.
|
||||||
* @param resetStateOutStream A writable output stream to write the reset state file to.
|
* @param resetStateOutStream A writable output stream to write the reset state file to.
|
||||||
*/
|
*/
|
||||||
exportReset (resetOutStream: Writable, resetJQOutStream: Writable, resetStateOutStream: Writable): void {
|
exportReset (resetOutStream: Writable, resetJQOutStream: Writable, resetStateOutStream: Writable, subgraphPath: string): void {
|
||||||
const resetTemplate = Handlebars.compile(this._resetTemplateString);
|
const resetTemplate = Handlebars.compile(this._resetTemplateString);
|
||||||
const resetString = resetTemplate({});
|
const resetString = resetTemplate({});
|
||||||
resetOutStream.write(resetString);
|
resetOutStream.write(resetString);
|
||||||
@ -86,7 +86,8 @@ export class Reset {
|
|||||||
|
|
||||||
const resetStateTemplate = Handlebars.compile(this._resetStateTemplateString);
|
const resetStateTemplate = Handlebars.compile(this._resetStateTemplateString);
|
||||||
const obj = {
|
const obj = {
|
||||||
queries: this._queries
|
queries: this._queries,
|
||||||
|
subgraphPath
|
||||||
};
|
};
|
||||||
const resetState = resetStateTemplate(obj);
|
const resetState = resetStateTemplate(obj);
|
||||||
resetStateOutStream.write(resetState);
|
resetStateOutStream.write(resetState);
|
||||||
|
@ -13,9 +13,9 @@ const TEMPLATE_FILE = './templates/server-template.handlebars';
|
|||||||
* Writes the server file generated from a template to a stream.
|
* Writes the server file generated from a template to a stream.
|
||||||
* @param outStream A writable output stream to write the server file to.
|
* @param outStream A writable output stream to write the server file to.
|
||||||
*/
|
*/
|
||||||
export function exportServer (outStream: Writable): void {
|
export function exportServer (outStream: Writable, subgraphPath: string): void {
|
||||||
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
|
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
|
||||||
const template = Handlebars.compile(templateString);
|
const template = Handlebars.compile(templateString);
|
||||||
const server = template({});
|
const server = template({ subgraphPath });
|
||||||
outStream.write(server);
|
outStream.write(server);
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,9 @@ const main = async (): Promise<void> => {
|
|||||||
await indexer.init();
|
await indexer.init();
|
||||||
|
|
||||||
graphWatcher.setIndexer(indexer);
|
graphWatcher.setIndexer(indexer);
|
||||||
|
{{#if subgraphPath}}
|
||||||
await graphWatcher.init();
|
await graphWatcher.init();
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
const blockHash = await indexer.processCLICheckpoint(argv.address, argv.blockHash);
|
const blockHash = await indexer.processCLICheckpoint(argv.address, argv.blockHash);
|
||||||
|
|
||||||
|
@ -61,7 +61,9 @@ const main = async (): Promise<void> => {
|
|||||||
await indexer.init();
|
await indexer.init();
|
||||||
|
|
||||||
graphWatcher.setIndexer(indexer);
|
graphWatcher.setIndexer(indexer);
|
||||||
|
{{#if subgraphPath}}
|
||||||
await graphWatcher.init();
|
await graphWatcher.init();
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
const exportData: any = {
|
const exportData: any = {
|
||||||
snapshotBlock: {},
|
snapshotBlock: {},
|
||||||
|
@ -76,7 +76,9 @@ export const main = async (): Promise<any> => {
|
|||||||
await indexer.init();
|
await indexer.init();
|
||||||
|
|
||||||
graphWatcher.setIndexer(indexer);
|
graphWatcher.setIndexer(indexer);
|
||||||
|
{{#if subgraphPath}}
|
||||||
await graphWatcher.init();
|
await graphWatcher.init();
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
|
// Note: In-memory pubsub works fine for now, as each watcher is a single process anyway.
|
||||||
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
|
// Later: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#production-pubsub-libraries
|
||||||
|
@ -69,7 +69,9 @@ export const main = async (): Promise<any> => {
|
|||||||
await indexer.init();
|
await indexer.init();
|
||||||
|
|
||||||
graphWatcher.setIndexer(indexer);
|
graphWatcher.setIndexer(indexer);
|
||||||
|
{{#if subgraphPath}}
|
||||||
await graphWatcher.init();
|
await graphWatcher.init();
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
const eventWatcher = new EventWatcher(config.upstream, ethClient, postgraphileClient, indexer, pubsub, jobQueue);
|
const eventWatcher = new EventWatcher(config.upstream, ethClient, postgraphileClient, indexer, pubsub, jobQueue);
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ import { EthClient } from '@vulcanize/ipld-eth-client';
|
|||||||
import { StorageLayout } from '@vulcanize/solidity-mapper';
|
import { StorageLayout } from '@vulcanize/solidity-mapper';
|
||||||
import {
|
import {
|
||||||
IPLDIndexer as BaseIndexer,
|
IPLDIndexer as BaseIndexer,
|
||||||
IndexerInterface,
|
IPLDIndexerInterface,
|
||||||
ValueResult,
|
ValueResult,
|
||||||
UNKNOWN_EVENT_NAME,
|
UNKNOWN_EVENT_NAME,
|
||||||
ServerConfig,
|
ServerConfig,
|
||||||
@ -26,7 +26,8 @@ import {
|
|||||||
updateStateForMappingType,
|
updateStateForMappingType,
|
||||||
BlockHeight,
|
BlockHeight,
|
||||||
IPFSClient,
|
IPFSClient,
|
||||||
StateKind
|
StateKind,
|
||||||
|
IpldStatus as IpldStatusInterface
|
||||||
} from '@vulcanize/util';
|
} from '@vulcanize/util';
|
||||||
import { GraphWatcher } from '@vulcanize/graph-node';
|
import { GraphWatcher } from '@vulcanize/graph-node';
|
||||||
|
|
||||||
@ -94,7 +95,7 @@ export type ResultIPLDBlock = {
|
|||||||
data: string;
|
data: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Indexer implements IndexerInterface {
|
export class Indexer implements IPLDIndexerInterface {
|
||||||
_db: Database
|
_db: Database
|
||||||
_ethClient: EthClient
|
_ethClient: EthClient
|
||||||
_ethProvider: BaseProvider
|
_ethProvider: BaseProvider
|
||||||
@ -563,11 +564,15 @@ export class Indexer implements IndexerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async watchContract (address: string, kind: string, checkpoint: boolean, startingBlock: number): Promise<void> {
|
async watchContract (address: string, kind: string, checkpoint: boolean, startingBlock: number): Promise<void> {
|
||||||
this._baseIndexer.updateIPLDStatusMap(address, {});
|
await this.updateIPLDStatusMap(address, {});
|
||||||
|
|
||||||
return this._baseIndexer.watchContract(address, kind, checkpoint, startingBlock);
|
return this._baseIndexer.watchContract(address, kind, checkpoint, startingBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateIPLDStatusMap (address: string, ipldStatus: IpldStatusInterface): Promise<void> {
|
||||||
|
await this._baseIndexer.updateIPLDStatusMap(address, ipldStatus);
|
||||||
|
}
|
||||||
|
|
||||||
cacheContract (contract: Contract): void {
|
cacheContract (contract: Contract): void {
|
||||||
return this._baseIndexer.cacheContract(contract);
|
return this._baseIndexer.cacheContract(contract);
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,9 @@ const main = async (): Promise<void> => {
|
|||||||
await indexer.init();
|
await indexer.init();
|
||||||
|
|
||||||
graphWatcher.setIndexer(indexer);
|
graphWatcher.setIndexer(indexer);
|
||||||
|
{{#if subgraphPath}}
|
||||||
await graphWatcher.init();
|
await graphWatcher.init();
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
const ipldBlock = await indexer.getIPLDBlockByCid(argv.cid);
|
const ipldBlock = await indexer.getIPLDBlockByCid(argv.cid);
|
||||||
assert(ipldBlock, 'IPLDBlock for the provided CID doesn\'t exist.');
|
assert(ipldBlock, 'IPLDBlock for the provided CID doesn\'t exist.');
|
||||||
|
@ -271,10 +271,12 @@ export const main = async (): Promise<any> => {
|
|||||||
await indexer.init();
|
await indexer.init();
|
||||||
|
|
||||||
graphWatcher.setIndexer(indexer);
|
graphWatcher.setIndexer(indexer);
|
||||||
|
{{#if subgraphPath}}
|
||||||
await graphWatcher.init();
|
await graphWatcher.init();
|
||||||
|
|
||||||
// Watching all the contracts in the subgraph.
|
// Watching all the contracts in the subgraph.
|
||||||
await graphWatcher.addContracts();
|
await graphWatcher.addContracts();
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
const jobRunner = new JobRunner(jobQueueConfig, indexer, jobQueue);
|
const jobRunner = new JobRunner(jobQueueConfig, indexer, jobQueue);
|
||||||
await jobRunner.start();
|
await jobRunner.start();
|
||||||
|
@ -57,7 +57,9 @@ export const handler = async (argv: any): Promise<void> => {
|
|||||||
await indexer.init();
|
await indexer.init();
|
||||||
|
|
||||||
graphWatcher.setIndexer(indexer);
|
graphWatcher.setIndexer(indexer);
|
||||||
|
{{#if subgraphPath}}
|
||||||
await graphWatcher.init();
|
await graphWatcher.init();
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
const blockProgresses = await indexer.getBlocksAtHeight(argv.blockNumber, false);
|
const blockProgresses = await indexer.getBlocksAtHeight(argv.blockNumber, false);
|
||||||
assert(blockProgresses.length, `No blocks at specified block number ${argv.blockNumber}`);
|
assert(blockProgresses.length, `No blocks at specified block number ${argv.blockNumber}`);
|
||||||
|
@ -64,7 +64,9 @@ export const main = async (): Promise<any> => {
|
|||||||
await indexer.init();
|
await indexer.init();
|
||||||
|
|
||||||
graphWatcher.setIndexer(indexer);
|
graphWatcher.setIndexer(indexer);
|
||||||
|
{{#if subgraphPath}}
|
||||||
await graphWatcher.init();
|
await graphWatcher.init();
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
const eventWatcher = new EventWatcher(config.upstream, ethClient, postgraphileClient, indexer, pubsub, jobQueue);
|
const eventWatcher = new EventWatcher(config.upstream, ethClient, postgraphileClient, indexer, pubsub, jobQueue);
|
||||||
|
|
||||||
|
@ -77,7 +77,9 @@ const main = async (): Promise<void> => {
|
|||||||
await indexer.init();
|
await indexer.init();
|
||||||
|
|
||||||
graphWatcher.setIndexer(indexer);
|
graphWatcher.setIndexer(indexer);
|
||||||
|
{{#if subgraphPath}}
|
||||||
await graphWatcher.init();
|
await graphWatcher.init();
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
await indexer.watchContract(argv.address, argv.kind, argv.checkpoint, argv.startingBlock);
|
await indexer.watchContract(argv.address, argv.kind, argv.checkpoint, argv.startingBlock);
|
||||||
|
|
||||||
|
@ -218,8 +218,8 @@ export class Visitor {
|
|||||||
* @param resetJQOutStream A writable output stream to write the reset job-queue file to.
|
* @param resetJQOutStream A writable output stream to write the reset job-queue file to.
|
||||||
* @param resetStateOutStream A writable output stream to write the reset state file to.
|
* @param resetStateOutStream A writable output stream to write the reset state file to.
|
||||||
*/
|
*/
|
||||||
exportReset (resetOutStream: Writable, resetJQOutStream: Writable, resetStateOutStream: Writable): void {
|
exportReset (resetOutStream: Writable, resetJQOutStream: Writable, resetStateOutStream: Writable, subgraphPath: string): void {
|
||||||
this._reset.exportReset(resetOutStream, resetJQOutStream, resetStateOutStream);
|
this._reset.exportReset(resetOutStream, resetJQOutStream, resetStateOutStream, subgraphPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,9 +13,9 @@ const TEMPLATE_FILE = './templates/watch-contract-template.handlebars';
|
|||||||
* Writes the watch-contract file generated from a template to a stream.
|
* Writes the watch-contract file generated from a template to a stream.
|
||||||
* @param outStream A writable output stream to write the watch-contract file to.
|
* @param outStream A writable output stream to write the watch-contract file to.
|
||||||
*/
|
*/
|
||||||
export function exportWatchContract (outStream: Writable): void {
|
export function exportWatchContract (outStream: Writable, subgraphPath: string): void {
|
||||||
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
|
const templateString = fs.readFileSync(path.resolve(__dirname, TEMPLATE_FILE)).toString();
|
||||||
const template = Handlebars.compile(templateString);
|
const template = Handlebars.compile(templateString);
|
||||||
const events = template({});
|
const events = template({ subgraphPath });
|
||||||
outStream.write(events);
|
outStream.write(events);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ import { EthClient } from '@vulcanize/ipld-eth-client';
|
|||||||
import { StorageLayout } from '@vulcanize/solidity-mapper';
|
import { StorageLayout } from '@vulcanize/solidity-mapper';
|
||||||
import {
|
import {
|
||||||
IPLDIndexer as BaseIndexer,
|
IPLDIndexer as BaseIndexer,
|
||||||
IndexerInterface,
|
|
||||||
UNKNOWN_EVENT_NAME,
|
UNKNOWN_EVENT_NAME,
|
||||||
ServerConfig,
|
ServerConfig,
|
||||||
JobQueue,
|
JobQueue,
|
||||||
@ -23,7 +22,9 @@ import {
|
|||||||
QueryOptions,
|
QueryOptions,
|
||||||
BlockHeight,
|
BlockHeight,
|
||||||
IPFSClient,
|
IPFSClient,
|
||||||
StateKind
|
StateKind,
|
||||||
|
IPLDIndexerInterface,
|
||||||
|
IpldStatus as IpldStatusInterface
|
||||||
} from '@vulcanize/util';
|
} from '@vulcanize/util';
|
||||||
import { GraphWatcher } from '@vulcanize/graph-node';
|
import { GraphWatcher } from '@vulcanize/graph-node';
|
||||||
|
|
||||||
@ -125,7 +126,7 @@ export type ResultIPLDBlock = {
|
|||||||
data: string;
|
data: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Indexer implements IndexerInterface {
|
export class Indexer implements IPLDIndexerInterface {
|
||||||
_db: Database
|
_db: Database
|
||||||
_ethClient: EthClient
|
_ethClient: EthClient
|
||||||
_ethProvider: BaseProvider
|
_ethProvider: BaseProvider
|
||||||
@ -899,11 +900,15 @@ export class Indexer implements IndexerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async watchContract (address: string, kind: string, checkpoint: boolean, startingBlock: number): Promise<void> {
|
async watchContract (address: string, kind: string, checkpoint: boolean, startingBlock: number): Promise<void> {
|
||||||
this._baseIndexer.updateIPLDStatusMap(address, {});
|
await this.updateIPLDStatusMap(address, {});
|
||||||
|
|
||||||
return this._baseIndexer.watchContract(address, kind, checkpoint, startingBlock);
|
return this._baseIndexer.watchContract(address, kind, checkpoint, startingBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateIPLDStatusMap (address: string, ipldStatus: IpldStatusInterface): Promise<void> {
|
||||||
|
await this._baseIndexer.updateIPLDStatusMap(address, ipldStatus);
|
||||||
|
}
|
||||||
|
|
||||||
cacheContract (contract: Contract): void {
|
cacheContract (contract: Contract): void {
|
||||||
return this._baseIndexer.cacheContract(contract);
|
return this._baseIndexer.cacheContract(contract);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ task('token-approve', 'Move tokens to recipient')
|
|||||||
const TransferEvent = receipt.events.find(el => el.event === 'Approval');
|
const TransferEvent = receipt.events.find(el => el.event === 'Approval');
|
||||||
|
|
||||||
if (TransferEvent && TransferEvent.args) {
|
if (TransferEvent && TransferEvent.args) {
|
||||||
console.log('Approval Event');
|
console.log('Approval Event at block:', receipt.blockNumber, receipt.blockHash);
|
||||||
console.log('owner:', TransferEvent.args.owner.toString());
|
console.log('owner:', TransferEvent.args.owner.toString());
|
||||||
console.log('spender:', TransferEvent.args.spender.toString());
|
console.log('spender:', TransferEvent.args.spender.toString());
|
||||||
console.log('value:', TransferEvent.args.value.toString());
|
console.log('value:', TransferEvent.args.value.toString());
|
||||||
|
@ -15,5 +15,7 @@ task('token-deploy', 'Deploys GLD token')
|
|||||||
const Token = await hre.ethers.getContractFactory('GLDToken');
|
const Token = await hre.ethers.getContractFactory('GLDToken');
|
||||||
const token = await Token.deploy(hre.ethers.BigNumber.from(initialSupply));
|
const token = await Token.deploy(hre.ethers.BigNumber.from(initialSupply));
|
||||||
|
|
||||||
|
const receipt = await token.deployTransaction.wait();
|
||||||
console.log('GLD Token deployed to:', token.address);
|
console.log('GLD Token deployed to:', token.address);
|
||||||
|
console.log('Deployed at block:', receipt.blockNumber, receipt.blockHash);
|
||||||
});
|
});
|
||||||
|
@ -28,7 +28,7 @@ task('token-transfer-from', 'Send tokens as spender')
|
|||||||
const TransferEvent = receipt.events.find(el => el.event === 'Transfer');
|
const TransferEvent = receipt.events.find(el => el.event === 'Transfer');
|
||||||
|
|
||||||
if (TransferEvent && TransferEvent.args) {
|
if (TransferEvent && TransferEvent.args) {
|
||||||
console.log('Transfer Event');
|
console.log('Transfer Event at block:', receipt.blockNumber, receipt.blockHash);
|
||||||
console.log('from:', TransferEvent.args.from.toString());
|
console.log('from:', TransferEvent.args.from.toString());
|
||||||
console.log('to:', TransferEvent.args.to.toString());
|
console.log('to:', TransferEvent.args.to.toString());
|
||||||
console.log('value:', TransferEvent.args.value.toString());
|
console.log('value:', TransferEvent.args.value.toString());
|
||||||
|
@ -24,7 +24,7 @@ task('token-transfer', 'Move tokens to recipient')
|
|||||||
const TransferEvent = receipt.events.find(el => el.event === 'Transfer');
|
const TransferEvent = receipt.events.find(el => el.event === 'Transfer');
|
||||||
|
|
||||||
if (TransferEvent && TransferEvent.args) {
|
if (TransferEvent && TransferEvent.args) {
|
||||||
console.log('Transfer Event');
|
console.log('Transfer Event at block:', receipt.blockNumber, receipt.blockHash);
|
||||||
console.log('from:', TransferEvent.args.from.toString());
|
console.log('from:', TransferEvent.args.from.toString());
|
||||||
console.log('to:', TransferEvent.args.to.toString());
|
console.log('to:', TransferEvent.args.to.toString());
|
||||||
console.log('value:', TransferEvent.args.value.toString());
|
console.log('value:', TransferEvent.args.value.toString());
|
||||||
|
@ -15,7 +15,6 @@ import { EthClient } from '@vulcanize/ipld-eth-client';
|
|||||||
import { StorageLayout } from '@vulcanize/solidity-mapper';
|
import { StorageLayout } from '@vulcanize/solidity-mapper';
|
||||||
import {
|
import {
|
||||||
IPLDIndexer as BaseIndexer,
|
IPLDIndexer as BaseIndexer,
|
||||||
IndexerInterface,
|
|
||||||
ValueResult,
|
ValueResult,
|
||||||
UNKNOWN_EVENT_NAME,
|
UNKNOWN_EVENT_NAME,
|
||||||
ServerConfig,
|
ServerConfig,
|
||||||
@ -25,7 +24,9 @@ import {
|
|||||||
QueryOptions,
|
QueryOptions,
|
||||||
BlockHeight,
|
BlockHeight,
|
||||||
IPFSClient,
|
IPFSClient,
|
||||||
StateKind
|
StateKind,
|
||||||
|
IPLDIndexerInterface,
|
||||||
|
IpldStatus as IpldStatusInterface
|
||||||
} from '@vulcanize/util';
|
} from '@vulcanize/util';
|
||||||
import { GraphWatcher } from '@vulcanize/graph-node';
|
import { GraphWatcher } from '@vulcanize/graph-node';
|
||||||
|
|
||||||
@ -92,7 +93,7 @@ export type ResultIPLDBlock = {
|
|||||||
data: string;
|
data: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Indexer implements IndexerInterface {
|
export class Indexer implements IPLDIndexerInterface {
|
||||||
_db: Database
|
_db: Database
|
||||||
_ethClient: EthClient
|
_ethClient: EthClient
|
||||||
_ethProvider: BaseProvider
|
_ethProvider: BaseProvider
|
||||||
@ -592,11 +593,15 @@ export class Indexer implements IndexerInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async watchContract (address: string, kind: string, checkpoint: boolean, startingBlock: number): Promise<void> {
|
async watchContract (address: string, kind: string, checkpoint: boolean, startingBlock: number): Promise<void> {
|
||||||
this._baseIndexer.updateIPLDStatusMap(address, {});
|
await this.updateIPLDStatusMap(address, {});
|
||||||
|
|
||||||
return this._baseIndexer.watchContract(address, kind, checkpoint, startingBlock);
|
return this._baseIndexer.watchContract(address, kind, checkpoint, startingBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateIPLDStatusMap (address: string, ipldStatus: IpldStatusInterface): Promise<void> {
|
||||||
|
await this._baseIndexer.updateIPLDStatusMap(address, ipldStatus);
|
||||||
|
}
|
||||||
|
|
||||||
cacheContract (contract: Contract): void {
|
cacheContract (contract: Contract): void {
|
||||||
return this._baseIndexer.cacheContract(contract);
|
return this._baseIndexer.cacheContract(contract);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import {
|
|||||||
QUEUE_EVENT_PROCESSING
|
QUEUE_EVENT_PROCESSING
|
||||||
} from './constants';
|
} from './constants';
|
||||||
import { JobQueue } from './job-queue';
|
import { JobQueue } from './job-queue';
|
||||||
import { EventInterface, IndexerInterface, SyncStatusInterface } from './types';
|
import { EventInterface, IndexerInterface, IPLDIndexerInterface, SyncStatusInterface } from './types';
|
||||||
import { wait } from './misc';
|
import { wait } from './misc';
|
||||||
import { createPruningJob } from './common';
|
import { createPruningJob } from './common';
|
||||||
import { OrderDirection } from './database';
|
import { OrderDirection } from './database';
|
||||||
@ -28,7 +28,7 @@ const DEFAULT_EVENTS_IN_BATCH = 50;
|
|||||||
const log = debug('vulcanize:job-runner');
|
const log = debug('vulcanize:job-runner');
|
||||||
|
|
||||||
export class JobRunner {
|
export class JobRunner {
|
||||||
_indexer: IndexerInterface
|
_indexer: IndexerInterface | IPLDIndexerInterface
|
||||||
_jobQueue: JobQueue
|
_jobQueue: JobQueue
|
||||||
_jobQueueConfig: JobQueueConfig
|
_jobQueueConfig: JobQueueConfig
|
||||||
_blockProcessStartTime?: Date
|
_blockProcessStartTime?: Date
|
||||||
@ -331,5 +331,10 @@ export class JobRunner {
|
|||||||
|
|
||||||
assert(this._indexer.cacheContract);
|
assert(this._indexer.cacheContract);
|
||||||
this._indexer.cacheContract(contract);
|
this._indexer.cacheContract(contract);
|
||||||
|
|
||||||
|
const ipldIndexer = this._indexer as IPLDIndexerInterface;
|
||||||
|
if (ipldIndexer.updateIPLDStatusMap) {
|
||||||
|
ipldIndexer.updateIPLDStatusMap(contract.address, {});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
import { Connection, DeepPartial, FindConditions, FindManyOptions, QueryRunner } from 'typeorm';
|
import { Connection, DeepPartial, FindConditions, FindManyOptions, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
import { Where, QueryOptions } from './database';
|
import { Where, QueryOptions } from './database';
|
||||||
|
import { IpldStatus } from './ipld-indexer';
|
||||||
|
|
||||||
export enum StateKind {
|
export enum StateKind {
|
||||||
Diff = 'diff',
|
Diff = 'diff',
|
||||||
@ -104,6 +105,10 @@ export interface IndexerInterface {
|
|||||||
processBlock?: (blockHash: string, blockNumber: number) => Promise<void>
|
processBlock?: (blockHash: string, blockNumber: number) => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IPLDIndexerInterface extends IndexerInterface {
|
||||||
|
updateIPLDStatusMap (address: string, ipldStatus: IpldStatus): Promise<void>
|
||||||
|
}
|
||||||
|
|
||||||
export interface EventWatcherInterface {
|
export interface EventWatcherInterface {
|
||||||
getBlockProgressEventIterator (): AsyncIterator<any>
|
getBlockProgressEventIterator (): AsyncIterator<any>
|
||||||
initBlockProcessingOnCompleteHandler (): Promise<void>
|
initBlockProcessingOnCompleteHandler (): Promise<void>
|
||||||
|
Loading…
Reference in New Issue
Block a user