Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stwiname committed Sep 28, 2023
1 parent 7cda050 commit c8e0a6b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages/common-ethereum/src/codegen/codegen-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import fs from 'fs';
import path from 'path';
import {isCustomDs, isRuntimeDs} from '@subql/common-ethereum';
import {SubqlRuntimeDatasource} from '@subql/types-ethereum';
import {Data} from 'ejs';
import {runTypeChain, glob, parseContractPath} from 'typechain';
import {isCustomDs, isRuntimeDs} from '../project';
import {CUSTOM_EVM_HANDLERS} from './constants';
import {loadReadAbi} from './utils';

Expand Down
23 changes: 0 additions & 23 deletions packages/common-ethereum/src/project/load.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import fs from 'fs';
import path from 'path';
import {loadFromJsonOrYaml} from '@subql/common';
import {EthereumProjectManifestVersioned, VersionedProjectManifest} from './versioned';

export function parseEthereumProjectManifest(raw: unknown): EthereumProjectManifestVersioned {
const projectManifest = new EthereumProjectManifestVersioned(raw as VersionedProjectManifest);
projectManifest.validate();
return projectManifest;
}

export function loadEthereumProjectManifest(file: string): EthereumProjectManifestVersioned {
let manifestPath = file;
if (fs.existsSync(file) && fs.lstatSync(file).isDirectory()) {
const yamlFilePath = path.join(file, 'project.yaml');
const jsonFilePath = path.join(file, 'project.json');
if (fs.existsSync(yamlFilePath)) {
manifestPath = yamlFilePath;
} else if (fs.existsSync(jsonFilePath)) {
manifestPath = jsonFilePath;
} else {
throw new Error(`Could not find project manifest under dir ${file}`);
}
}

const doc = loadFromJsonOrYaml(manifestPath);
const projectManifest = new EthereumProjectManifestVersioned(doc as VersionedProjectManifest);
projectManifest.validate();
return projectManifest;
}
25 changes: 23 additions & 2 deletions packages/common-ethereum/src/project/project.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import fs from 'fs';
import path from 'path';
import {RunnerQueryBaseModel} from '@subql/common';
import {loadFromJsonOrYaml, RunnerQueryBaseModel} from '@subql/common';
import {validateSync} from 'class-validator';
import {DeploymentV1_0_0, EthereumRunnerNodeImpl, EthereumRunnerSpecsImpl} from '../project/versioned/v1_0_0';
import {loadEthereumProjectManifest} from './load';
import {EthereumProjectManifestVersioned, VersionedProjectManifest} from './versioned';

const projectsDir = path.join(__dirname, '../../test');

function loadEthereumProjectManifest(file: string): EthereumProjectManifestVersioned {
let manifestPath = file;
if (fs.existsSync(file) && fs.lstatSync(file).isDirectory()) {
const yamlFilePath = path.join(file, 'project.yaml');
const jsonFilePath = path.join(file, 'project.json');
if (fs.existsSync(yamlFilePath)) {
manifestPath = yamlFilePath;
} else if (fs.existsSync(jsonFilePath)) {
manifestPath = jsonFilePath;
} else {
throw new Error(`Could not find project manifest under dir ${file}`);
}
}

const doc = loadFromJsonOrYaml(manifestPath);
const projectManifest = new EthereumProjectManifestVersioned(doc as VersionedProjectManifest);
projectManifest.validate();
return projectManifest;
}

describe('test eth project.yaml', () => {
it('could get eth project template name from its deployment', () => {
const manifest = loadEthereumProjectManifest(path.join(projectsDir, 'project_1.0.0.yaml'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class EthereumProjectManifestVersioned implements IEthereumProjectManifes
}

toDeployment(): string | undefined {
return this._impl.toDeployment();
return this._impl.deployment.toYaml();
}

validate(): void {
Expand Down
11 changes: 3 additions & 8 deletions packages/common-ethereum/src/project/versioned/v1_0_0/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
SubqlMapping,
SubqlRuntimeDatasource,
} from '@subql/types-ethereum';
import {plainToClass, Transform, TransformFnParams, Type} from 'class-transformer';
import {plainToInstance, Transform, TransformFnParams, Type} from 'class-transformer';
import {
Equals,
IsArray,
Expand All @@ -30,17 +30,12 @@ import {
ValidateNested,
validateSync,
} from 'class-validator';
import {CustomDataSourceBase, EthereumMapping, RuntimeDataSourceBase} from '../../models';
import {CustomDataSourceBase, RuntimeDataSourceBase} from '../../models';
import {SubqlEthereumDataSource, SubqlRuntimeHandler} from '../../types';

const Ethereum_NODE_NAME = `@subql/node-ethereum`;
const Flare_NODE_NAME = `@subql/node-flare`;

export class EthereumProjectMapping extends EthereumMapping {
@IsString()
file: string;
}

export class EthereumRunnerNodeImpl extends RunnerNodeImpl {
@IsIn([Ethereum_NODE_NAME, Flare_NODE_NAME], {
message: `Runner Substrate node name incorrect, suppose be '${Ethereum_NODE_NAME}'`,
Expand Down Expand Up @@ -126,7 +121,7 @@ export class DeploymentV1_0_0 extends BaseDeploymentV1_0_0 {
if (params.value.genesisHash && !params.value.chainId) {
params.value.chainId = params.value.genesisHash;
}
return plainToClass(ProjectNetworkDeploymentV1_0_0, params.value);
return plainToInstance(ProjectNetworkDeploymentV1_0_0, params.value);
})
@ValidateNested()
@Type(() => ProjectNetworkDeploymentV1_0_0)
Expand Down
9 changes: 0 additions & 9 deletions packages/node/src/configure/SubqueryProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { validateSemver } from '@subql/common';
import {
parseEthereumProjectManifest,
SubqlEthereumDataSource,
EthereumBlockFilter,
ProjectManifestV1_0_0Impl,
isRuntimeDs,
EthereumHandlerKind,
Expand All @@ -26,7 +25,6 @@ import {
CustomDatasourceTemplate,
} from '@subql/types-ethereum';
import { buildSchemaFromString } from '@subql/utils';
import Cron from 'cron-converter';
import { GraphQLSchema } from 'graphql';
import { updateDatasourcesFlare } from '../utils/project';

Expand All @@ -38,13 +36,6 @@ export type EthereumProjectDsTemplate =
| SubqlProjectDs<RuntimeDatasourceTemplate>
| SubqlProjectDs<CustomDatasourceTemplate>;

export type SubqlProjectBlockFilter = EthereumBlockFilter & {
cronSchedule?: {
schedule: Cron.Seeker;
next: number;
};
};

const NOT_SUPPORT = (name: string) => {
throw new Error(`Manifest specVersion ${name} is not supported`);
};
Expand Down
2 changes: 0 additions & 2 deletions packages/node/src/indexer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@

import { EthereumBlock, LightEthereumBlock } from '@subql/types-ethereum';

export type BestBlocks = Record<number, string>;

export type BlockContent = EthereumBlock | LightEthereumBlock;

0 comments on commit c8e0a6b

Please sign in to comment.