Implement data source templates (#106)

* Implement data source templates

* Remove optional param from wasm instantiate

* Add all types for solidity to typescript mapping

* Set contract address in context for data source templates

* Implement block handlers for data source templates
This commit is contained in:
2022-01-06 18:32:08 +05:30
committed by GitHub
parent 4867530da7
commit aabf9f8e15
35 changed files with 2906 additions and 688 deletions
+14 -12
View File
@@ -335,19 +335,21 @@ function getConfig (configFile: string): any {
subgraphPath = inputConfig.subgraphPath.replace(/^~/, os.homedir());
subgraphConfig = getSubgraphConfig(subgraphPath);
// Add contracts missing for dataSources in subgraph config.
subgraphConfig.dataSources.forEach((dataSource: any) => {
if (!contracts.some((contract: any) => contract.kind === dataSource.name)) {
const abi = dataSource.mapping.abis.find((abi: any) => abi.name === dataSource.source.abi);
const abiPath = path.resolve(subgraphPath, abi.file);
// Add contracts missing for dataSources and templates in subgraph config.
subgraphConfig.dataSources
.concat(subgraphConfig.templates ?? [])
.forEach((dataSource: any) => {
if (!contracts.some((contract: any) => contract.kind === dataSource.name)) {
const abi = dataSource.mapping.abis.find((abi: any) => abi.name === dataSource.source.abi);
const abiPath = path.resolve(subgraphPath, abi.file);
contracts.push({
name: dataSource.name,
kind: dataSource.name,
abiPath
});
}
});
contracts.push({
name: dataSource.name,
kind: dataSource.name,
abiPath
});
}
});
}
const inputFlatten = inputConfig.flatten;
+2 -2
View File
@@ -6,7 +6,6 @@ import assert from 'assert';
import { GraphQLSchema, parse, printSchema, print } from 'graphql';
import { SchemaComposer } from 'graphql-compose';
import { Writable } from 'stream';
import _ from 'lodash';
import { getTsForSol, getGqlForTs } from './utils/type-mappings';
import { Param } from './utils/types';
@@ -156,7 +155,8 @@ export class Schema {
});
// Re-assigning the typeDefs.
const modifiedSchemaDocument = _.cloneDeep(subgraphSchemaDocument);
// Using JSON stringify and parse as lodash cloneDeep throws error.
const modifiedSchemaDocument = JSON.parse(JSON.stringify(subgraphSchemaDocument));
modifiedSchemaDocument.definitions = subgraphTypeDefs;
// Adding subgraph-schema types to the schema composer.
@@ -584,6 +584,10 @@ export class Indexer implements IndexerInterface {
return this._baseIndexer.isWatchedContract(address);
}
getContractsByKind (kind: string): Contract[] {
return this._baseIndexer.getContractsByKind(kind);
}
async getProcessedBlockCountForRange (fromBlockNumber: number, toBlockNumber: number): Promise<{ expected: number, actual: number }> {
return this._baseIndexer.getProcessedBlockCountForRange(fromBlockNumber, toBlockNumber);
}
@@ -59,12 +59,6 @@ export const handler = async (argv: any): Promise<void> => {
graphWatcher.setIndexer(indexer);
await graphWatcher.init();
const syncStatus = await indexer.getSyncStatus();
assert(syncStatus, 'Missing syncStatus');
const ipldStatus = await indexer.getIPLDStatus();
assert(ipldStatus, 'Missing ipldStatus');
const blockProgresses = await indexer.getBlocksAtHeight(argv.blockNumber, false);
assert(blockProgresses.length, `No blocks at specified block number ${argv.blockNumber}`);
assert(!blockProgresses.some(block => !block.isComplete), `Incomplete block at block number ${argv.blockNumber} with unprocessed events`);
@@ -85,6 +79,9 @@ export const handler = async (argv: any): Promise<void> => {
await Promise.all(removeEntitiesPromise);
const syncStatus = await indexer.getSyncStatus();
assert(syncStatus, 'Missing syncStatus');
if (syncStatus.latestIndexedBlockNumber > blockProgress.blockNumber) {
await indexer.updateSyncStatusIndexedBlock(blockProgress.blockHash, blockProgress.blockNumber, true);
}
@@ -93,16 +90,20 @@ export const handler = async (argv: any): Promise<void> => {
await indexer.updateSyncStatusCanonicalBlock(blockProgress.blockHash, blockProgress.blockNumber, true);
}
if (ipldStatus.latestHooksBlockNumber > blockProgress.blockNumber) {
await indexer.updateIPLDStatusHooksBlock(blockProgress.blockNumber, true);
}
const ipldStatus = await indexer.getIPLDStatus();
if (ipldStatus.latestCheckpointBlockNumber > blockProgress.blockNumber) {
await indexer.updateIPLDStatusCheckpointBlock(blockProgress.blockNumber, true);
}
if(ipldStatus) {
if (ipldStatus.latestHooksBlockNumber > blockProgress.blockNumber) {
await indexer.updateIPLDStatusHooksBlock(blockProgress.blockNumber, true);
}
if (ipldStatus.latestIPFSBlockNumber > blockProgress.blockNumber) {
await indexer.updateIPLDStatusIPFSBlock(blockProgress.blockNumber, true);
if (ipldStatus.latestCheckpointBlockNumber > blockProgress.blockNumber) {
await indexer.updateIPLDStatusCheckpointBlock(blockProgress.blockNumber, true);
}
if (ipldStatus.latestIPFSBlockNumber > blockProgress.blockNumber) {
await indexer.updateIPLDStatusIPFSBlock(blockProgress.blockNumber, true);
}
}
await indexer.updateSyncStatusChainHead(blockProgress.blockHash, blockProgress.blockNumber, true);
+112
View File
@@ -0,0 +1,112 @@
//
// Copyright 2022 Vulcanize, Inc.
//
const solToTs: Map<string, string> = new Map();
// Solidity to Typescript type-mapping.
solToTs.set('string', 'string');
solToTs.set('address', 'string');
solToTs.set('bool', 'boolean');
solToTs.set('int8', 'number');
solToTs.set('int16', 'number');
solToTs.set('int24', 'number');
solToTs.set('int32', 'number');
solToTs.set('int48', 'number');
solToTs.set('int56', 'bigint');
solToTs.set('int64', 'bigint');
solToTs.set('int72', 'bigint');
solToTs.set('int80', 'bigint');
solToTs.set('int88', 'bigint');
solToTs.set('int96', 'bigint');
solToTs.set('int104', 'bigint');
solToTs.set('int112', 'bigint');
solToTs.set('int120', 'bigint');
solToTs.set('int128', 'bigint');
solToTs.set('int136', 'bigint');
solToTs.set('int144', 'bigint');
solToTs.set('int152', 'bigint');
solToTs.set('int160', 'bigint');
solToTs.set('int168', 'bigint');
solToTs.set('int176', 'bigint');
solToTs.set('int184', 'bigint');
solToTs.set('int192', 'bigint');
solToTs.set('int200', 'bigint');
solToTs.set('int208', 'bigint');
solToTs.set('int216', 'bigint');
solToTs.set('int224', 'bigint');
solToTs.set('int232', 'bigint');
solToTs.set('int240', 'bigint');
solToTs.set('int248', 'bigint');
solToTs.set('int256', 'bigint');
solToTs.set('int', 'bigint');
solToTs.set('uint8', 'number');
solToTs.set('uint16', 'number');
solToTs.set('uint24', 'number');
solToTs.set('uint32', 'number');
solToTs.set('uint48', 'number');
solToTs.set('uint56', 'bigint');
solToTs.set('uint64', 'bigint');
solToTs.set('uint72', 'bigint');
solToTs.set('uint80', 'bigint');
solToTs.set('uint88', 'bigint');
solToTs.set('uint96', 'bigint');
solToTs.set('uint104', 'bigint');
solToTs.set('uint112', 'bigint');
solToTs.set('uint120', 'bigint');
solToTs.set('uint128', 'bigint');
solToTs.set('uint136', 'bigint');
solToTs.set('uint144', 'bigint');
solToTs.set('uint152', 'bigint');
solToTs.set('uint160', 'bigint');
solToTs.set('uint168', 'bigint');
solToTs.set('uint176', 'bigint');
solToTs.set('uint184', 'bigint');
solToTs.set('uint192', 'bigint');
solToTs.set('uint200', 'bigint');
solToTs.set('uint208', 'bigint');
solToTs.set('uint216', 'bigint');
solToTs.set('uint224', 'bigint');
solToTs.set('uint232', 'bigint');
solToTs.set('uint240', 'bigint');
solToTs.set('uint248', 'bigint');
solToTs.set('uint256', 'bigint');
solToTs.set('uint', 'bigint');
solToTs.set('bytes', 'string');
solToTs.set('bytes1', 'string');
solToTs.set('bytes2', 'string');
solToTs.set('bytes3', 'string');
solToTs.set('bytes4', 'string');
solToTs.set('bytes5', 'string');
solToTs.set('bytes6', 'string');
solToTs.set('bytes7', 'string');
solToTs.set('bytes8', 'string');
solToTs.set('bytes9', 'string');
solToTs.set('bytes10', 'string');
solToTs.set('bytes11', 'string');
solToTs.set('bytes12', 'string');
solToTs.set('bytes13', 'string');
solToTs.set('bytes14', 'string');
solToTs.set('bytes15', 'string');
solToTs.set('bytes16', 'string');
solToTs.set('bytes17', 'string');
solToTs.set('bytes18', 'string');
solToTs.set('bytes19', 'string');
solToTs.set('bytes20', 'string');
solToTs.set('bytes21', 'string');
solToTs.set('bytes22', 'string');
solToTs.set('bytes23', 'string');
solToTs.set('bytes24', 'string');
solToTs.set('bytes25', 'string');
solToTs.set('bytes26', 'string');
solToTs.set('bytes27', 'string');
solToTs.set('bytes28', 'string');
solToTs.set('bytes29', 'string');
solToTs.set('bytes30', 'string');
solToTs.set('bytes31', 'string');
solToTs.set('bytes32', 'string');
export { solToTs };
+3 -17
View File
@@ -2,26 +2,12 @@
// Copyright 2021 Vulcanize, Inc.
//
const _solToTs: Map<string, string> = new Map();
import { solToTs } from './solToTs';
const _tsToGql: Map<string, string> = new Map();
const _tsToPg: Map<string, string> = new Map();
const _gqlToTs: Map<string, string> = new Map();
// TODO Get typemapping from ethersjs.
// Solidity to Typescript type-mapping.
_solToTs.set('string', 'string');
_solToTs.set('uint8', 'number');
_solToTs.set('uint16', 'number');
_solToTs.set('uint64', 'bigint');
_solToTs.set('uint128', 'bigint');
_solToTs.set('uint256', 'bigint');
_solToTs.set('uint', 'bigint');
_solToTs.set('address', 'string');
_solToTs.set('bool', 'boolean');
_solToTs.set('bytes', 'string');
_solToTs.set('bytes4', 'string');
_solToTs.set('bytes32', 'string');
// Typescript to Graphql type-mapping.
_tsToGql.set('string', 'String');
_tsToGql.set('number', 'Int');
@@ -44,7 +30,7 @@ _gqlToTs.set('BigDecimal', 'Decimal');
_gqlToTs.set('Bytes', 'string');
function getTsForSol (solType: string): string | undefined {
return _solToTs.get(solType);
return solToTs.get(solType);
}
function getGqlForTs (tsType: string): string | undefined {