2021-09-29 04:34:09 +00:00
|
|
|
//
|
|
|
|
// Copyright 2021 Vulcanize, Inc.
|
|
|
|
//
|
|
|
|
|
|
|
|
import 'reflect-metadata';
|
|
|
|
import debug from 'debug';
|
|
|
|
|
2022-11-25 06:01:20 +00:00
|
|
|
import { FillCmd } from '@cerc-io/cli';
|
2022-07-22 07:47:56 +00:00
|
|
|
{{#if (subgraphPath)}}
|
2022-11-25 10:24:35 +00:00
|
|
|
import { getContractEntitiesMap } from '@cerc-io/util';
|
|
|
|
import { getGraphDbAndWatcher } from '@cerc-io/graph-node';
|
2022-07-22 07:47:56 +00:00
|
|
|
{{/if}}
|
2021-09-29 04:34:09 +00:00
|
|
|
|
2022-11-23 12:12:25 +00:00
|
|
|
import { Database{{#if (subgraphPath)}}, ENTITY_QUERY_TYPE_MAP, ENTITY_TO_LATEST_ENTITY_MAP{{/if}} } from './database';
|
2021-09-29 04:34:09 +00:00
|
|
|
import { Indexer } from './indexer';
|
|
|
|
|
2022-11-25 06:01:20 +00:00
|
|
|
const log = debug('vulcanize:fill');
|
2021-09-29 04:34:09 +00:00
|
|
|
|
|
|
|
export const main = async (): Promise<any> => {
|
2022-11-25 06:01:20 +00:00
|
|
|
const fillCmd = new FillCmd();
|
2022-11-25 10:24:35 +00:00
|
|
|
await fillCmd.init(Database);
|
2021-09-29 04:34:09 +00:00
|
|
|
|
2022-07-22 07:47:56 +00:00
|
|
|
{{#if (subgraphPath)}}
|
2022-11-25 10:24:35 +00:00
|
|
|
const { graphWatcher } = await getGraphDbAndWatcher(
|
2022-11-25 14:33:58 +00:00
|
|
|
fillCmd.config.server,
|
|
|
|
fillCmd.clients.ethClient,
|
|
|
|
fillCmd.ethProvider,
|
|
|
|
fillCmd.database.baseDatabase,
|
2022-11-25 10:24:35 +00:00
|
|
|
ENTITY_QUERY_TYPE_MAP,
|
|
|
|
ENTITY_TO_LATEST_ENTITY_MAP
|
|
|
|
);
|
2022-09-06 07:49:14 +00:00
|
|
|
|
2022-11-25 10:24:35 +00:00
|
|
|
{{/if}}
|
2022-11-25 11:49:37 +00:00
|
|
|
await fillCmd.initIndexer(Indexer{{#if (subgraphPath)}}, graphWatcher{{/if}});
|
2022-11-25 10:24:35 +00:00
|
|
|
|
|
|
|
{{#if (subgraphPath)}}
|
2022-11-25 06:01:20 +00:00
|
|
|
// Get contractEntitiesMap required for fill-state
|
|
|
|
// NOTE: Assuming each entity type is only mapped to a single contract
|
2022-11-25 10:24:35 +00:00
|
|
|
const contractEntitiesMap = getContractEntitiesMap(graphWatcher.dataSources);
|
2022-09-06 07:49:14 +00:00
|
|
|
|
2022-07-22 07:47:56 +00:00
|
|
|
{{/if}}
|
2022-11-25 06:01:20 +00:00
|
|
|
await fillCmd.exec({{#if (subgraphPath)}}contractEntitiesMap{{/if}});
|
2021-09-29 04:34:09 +00:00
|
|
|
};
|
|
|
|
|
2021-10-20 12:19:44 +00:00
|
|
|
main().catch(err => {
|
2021-09-29 04:34:09 +00:00
|
|
|
log(err);
|
2021-10-20 12:19:44 +00:00
|
|
|
}).finally(() => {
|
|
|
|
process.exit();
|
2021-09-29 04:34:09 +00:00
|
|
|
});
|
2021-12-22 06:25:39 +00:00
|
|
|
|
|
|
|
process.on('SIGINT', () => {
|
|
|
|
log(`Exiting process ${process.pid} with code 0`);
|
|
|
|
process.exit(0);
|
|
|
|
});
|