Skip to content

Commit

Permalink
Remove contract-processors and types improvements (subquery#1012)
Browse files Browse the repository at this point in the history
* Acala evm processor initial implementation

* Acala improvements and datasource processor rework

- Remove duplicate interfaces from common-substrate and use the ones in types
- Update types interfaces to match what was in common-substrate
- Update datasource processing to support transforming from 1 entity to many entities
- Update datasource processing to use a single params object
- Fix up frontier datasource tests
- Add noImplicitThis to ts config
- Various AcalaEvm fixes and improvements

* Fix typos

* Add backwards compatibility to datasource processors, improve error handling

* Fix build issue

* Update types

* Remove contract processors, update types

* Fix tests

* Fix another ds related test

* Add comment about previous datasource versions
  • Loading branch information
stwiname authored May 19, 2022
1 parent d44914e commit 9b5746a
Show file tree
Hide file tree
Showing 40 changed files with 2,436 additions and 6,896 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/gh-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ jobs:
package-path: packages/common-terra
repo-token: ${{ secrets.REPO_TOKEN }}

- uses: ./.github/actions/create-release
with:
package-path: packages/contract-processors
repo-token: ${{ secrets.REPO_TOKEN }}

- uses: ./.github/actions/create-release
with:
package-path: packages/node
Expand Down
12 changes: 0 additions & 12 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ jobs:
with:
paths: packages/common-terra

- uses: marceloprado/has-changed-path@v1
id: changed-contract-processors
with:
paths: packages/contract-processors

- uses: marceloprado/has-changed-path@v1
id: changed-cli
with:
Expand Down Expand Up @@ -143,13 +138,6 @@ jobs:
package-path: packages/common-terra
npm-token: ${{ secrets.NPM_TOKEN }}

- name: Bump contract-processors & deploy
if: steps.changed-contract-processors.outputs.changed == 'true'
uses: ./.github/actions/create-prerelease
with:
package-path: packages/contract-processors
npm-token: ${{ secrets.NPM_TOKEN }}

- name: Bump node & deploy
if: steps.changed-node.outputs.changed == 'true'
uses: ./.github/actions/create-prerelease
Expand Down
13 changes: 0 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ jobs:
with:
paths: packages/common-terra

- uses: marceloprado/has-changed-path@v1
id: changed-contract-processors
with:
paths: packages/contract-processors

- uses: marceloprado/has-changed-path@v1
id: changed-cli
with:
Expand Down Expand Up @@ -150,14 +145,6 @@ jobs:
repo-token: ${{ secrets.REPO_TOKEN }}
npm-token: ${{ secrets.NPM_TOKEN }}

- name: Publish Contract Processors
if: steps.changed-contract-processors.outputs.changed == 'true'
uses: ./.github/actions/create-release
with:
package-path: packages/contract-processors
repo-token: ${{ secrets.REPO_TOKEN }}
npm-token: ${{ secrets.NPM_TOKEN }}

- name: Publish Node
if: steps.changed-node.outputs.changed == 'true'
uses: ./.github/actions/create-release
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ You'll also use our custom-built GraphQL query service [`@subql/query`](https://
* [`@subql/cli`](packages/cli)
* [`@subql/node`](packages/node)
* [`@subql/query`](packages/query)
* [`@subql/contract-processors`](packages/contract-processors)
* [`@subql/common`](packages/common)
* [`@subql/types`](packages/types)
* [`@subql/validator`](packages/validator)
Expand Down
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ module.exports = {
'packages/common/src/**/*.ts',
'packages/common-substrate/src/**/*.ts',
'packages/common-terra/src/**/*.ts',
'packages/contract-processors/src/**/*.ts',
'packages/node/src/**/*.ts',
'packages/node-terra/src/**/*.ts',
'packages/utils/src/**/*.ts',
Expand Down
36 changes: 18 additions & 18 deletions packages/common-substrate/src/project/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,8 @@
import {RegisteredTypes, RegistryTypes, OverrideModuleType, OverrideBundleType} from '@polkadot/types/types';

import {BaseMapping, FileReference} from '@subql/common';
import {plainToClass, Transform, Type} from 'class-transformer';
import {
ArrayMaxSize,
IsArray,
IsBoolean,
IsEnum,
IsInt,
IsOptional,
IsString,
IsObject,
ValidateNested,
} from 'class-validator';
import {
SubstrateCustomDataSourceAsset,
CustomDataSourceAsset as SubstrateCustomDataSourceAsset,
SubstrateBlockFilter,
SubstrateBlockHandler,
SubstrateCallFilter,
Expand All @@ -28,11 +16,23 @@ import {
SubstrateEventHandler,
SubstrateHandlerKind,
SubstrateNetworkFilter,
SubstrateRuntimeDataSource,
SubstrateRuntimeDatasource,
SubstrateRuntimeHandler,
SubstrateRuntimeHandlerFilter,
SubstrateCustomDataSource,
} from './types';
SubstrateCustomDatasource,
} from '@subql/types';
import {plainToClass, Transform, Type} from 'class-transformer';
import {
ArrayMaxSize,
IsArray,
IsBoolean,
IsEnum,
IsInt,
IsOptional,
IsString,
IsObject,
ValidateNested,
} from 'class-validator';

export class BlockFilter implements SubstrateBlockFilter {
@IsOptional()
Expand Down Expand Up @@ -155,7 +155,7 @@ export class SubqlNetworkFilterImpl implements SubstrateNetworkFilter {
specName?: string;
}

export class RuntimeDataSourceBase implements SubstrateRuntimeDataSource {
export class RuntimeDataSourceBase implements SubstrateRuntimeDatasource {
@IsEnum(SubstrateDatasourceKind, {groups: [SubstrateDatasourceKind.Runtime]})
kind: SubstrateDatasourceKind.Runtime;
@Type(() => RuntimeMapping)
Expand All @@ -176,7 +176,7 @@ export class FileReferenceImpl implements FileReference {
}

export class CustomDataSourceBase<K extends string, T extends SubstrateNetworkFilter, M extends CustomMapping, O = any>
implements SubstrateCustomDataSource<K, T, O>
implements SubstrateCustomDatasource<K, T, M, O>
{
@IsString()
kind: K;
Expand Down
156 changes: 20 additions & 136 deletions packages/common-substrate/src/project/types.ts
Original file line number Diff line number Diff line change
@@ -1,148 +1,32 @@
// Copyright 2020-2022 OnFinality Limited authors & contributors
// SPDX-License-Identifier: Apache-2.0

import {ApiPromise} from '@polkadot/api';
import {FileReference, BaseDataSource, BaseHandler, IProjectManifest, ProjectNetworkConfig} from '@subql/common';
import {SubstrateBlock, SubstrateEvent, SubstrateExtrinsic} from '@subql/types';
import {IProjectManifest, ProjectNetworkConfig} from '@subql/common';
import {SubstrateDatasource} from '@subql/types';
import {RuntimeDataSourceV0_0_1} from '../project/versioned/v0_0_1';

export enum SubstrateDatasourceKind {
Runtime = 'substrate/Runtime',
}

export enum SubstrateHandlerKind {
Block = 'substrate/BlockHandler',
Call = 'substrate/CallHandler',
Event = 'substrate/EventHandler',
}

export type SubstrateRuntimeHandlerInputMap = {
[SubstrateHandlerKind.Block]: SubstrateBlock;
[SubstrateHandlerKind.Event]: SubstrateEvent;
[SubstrateHandlerKind.Call]: SubstrateExtrinsic;
};

type SubstrateRuntimeFilterMap = {
[SubstrateHandlerKind.Block]: SubstrateNetworkFilter;
[SubstrateHandlerKind.Event]: SubstrateEventFilter;
[SubstrateHandlerKind.Call]: SubstrateCallFilter;
};
// All of these used to be redefined in this file, re-exporting for simplicity
export {
SubstrateRuntimeHandler,
SubstrateCustomHandler,
SubstrateHandler,
SubstrateHandlerKind,
SubstrateDatasource as SubstrateDataSource,
SubstrateCustomDatasource as SubstrateCustomDataSource,
SubstrateBlockFilter,
SubstrateCallFilter,
SubstrateEventFilter,
SubstrateDatasourceProcessor,
SubstrateNetworkFilter,
SubstrateRuntimeHandlerFilter,
SubstrateDatasourceKind,
RuntimeHandlerInputMap as SubstrateRuntimeHandlerInputMap,
} from '@subql/types';

//make exception for runtime datasource 0.0.1
export type ISubstrateProjectManifest = IProjectManifest<SubstrateDataSource | RuntimeDataSourceV0_0_1>;
export type ISubstrateProjectManifest = IProjectManifest<SubstrateDatasource | RuntimeDataSourceV0_0_1>;

export interface SubstrateProjectNetworkConfig extends ProjectNetworkConfig {
genesisHash?: string;
chainId?: string;
}

export type SpecVersionRange = [number, number];

//Record<string,unknown>

interface SubstrateBaseHandlerFilter {
specVersion?: SpecVersionRange;
}

export type SubstrateBlockFilter = SubstrateBaseHandlerFilter;

export interface SubstrateEventFilter extends SubstrateBaseHandlerFilter {
module?: string;
method?: string;
}

export interface SubstrateCallFilter extends SubstrateEventFilter {
success?: boolean;
}

export type SubstrateRuntimeHandlerFilter = SubstrateBlockFilter | SubstrateCallFilter | SubstrateEventFilter;

export interface SubstrateBlockHandler extends BaseHandler<SubstrateBlockFilter> {
kind: SubstrateHandlerKind.Block;
}

export interface SubstrateCallHandler extends BaseHandler<SubstrateCallFilter> {
kind: SubstrateHandlerKind.Call;
}

export interface SubstrateEventHandler extends BaseHandler<SubstrateEventFilter> {
kind: SubstrateHandlerKind.Event;
}

export type SubstrateHandler = SubstrateRuntimeHandler | SubstrateCustomHandler;

export type SubstrateRuntimeHandler = SubstrateBlockHandler | SubstrateCallHandler | SubstrateEventHandler;

export type SubstrateCustomHandler = BaseHandler<Record<string, unknown>>;

export interface SubstrateNetworkFilter {
specName?: string;
}

export type SubstrateDataSource = SubstrateRuntimeDataSource | SubstrateCustomDataSource; // | SubqlBuiltinDataSource;

export type SubstrateCustomDataSourceAsset = FileReference;

export interface SubstrateRuntimeDataSource
extends BaseDataSource<SubstrateRuntimeHandlerFilter, SubstrateRuntimeHandler> {
kind: SubstrateDatasourceKind.Runtime;
filter?: SubstrateNetworkFilter; //keep network filter for v0.0.1
}

export type Processor<O = any> = FileReference & {options?: O};

export interface SubstrateCustomDataSource<
K extends string = string,
T extends SubstrateNetworkFilter = SubstrateNetworkFilter,
O = any
> extends BaseDataSource {
filter?: T;
kind: K;
assets: Map<string, SubstrateCustomDataSourceAsset>;
processor?: Processor<O>;
}

export interface HandlerInputTransformer<
T extends SubstrateHandlerKind,
U,
DS extends SubstrateCustomDataSource = SubstrateCustomDataSource
> {
(original: SubstrateRuntimeHandlerInputMap[T], ds: DS, api: ApiPromise, assets: Record<string, string>): Promise<U>; // | SubqlBuiltinDataSource
}

///
export interface SubstrateDatasourceProcessor<
K extends string,
F extends SubstrateNetworkFilter,
DS extends SubstrateCustomDataSource<K, F> = SubstrateCustomDataSource<K, F>
> {
kind: K;
validate(ds: DS, assets: Record<string, string>): void;
dsFilterProcessor(ds: DS, api: ApiPromise): boolean;
handlerProcessors: {[kind: string]: SecondLayerHandlerProcessor<SubstrateHandlerKind, unknown, unknown, DS>};
}

export interface DictionaryQueryCondition {
field: string;
value: string;
}

export interface DictionaryQueryEntry {
entity: string;
conditions: DictionaryQueryCondition[];
}

// only allow one custom handler for each baseHandler kind
export interface SecondLayerHandlerProcessor<
K extends SubstrateHandlerKind,
F,
E,
DS extends SubstrateCustomDataSource = SubstrateCustomDataSource
> {
baseHandlerKind: K;
baseFilter: SubstrateRuntimeFilterMap[K] | SubstrateRuntimeFilterMap[K][];
transformer: HandlerInputTransformer<K, E, DS>;
filterProcessor: (filter: F | undefined, input: SubstrateRuntimeHandlerInputMap[K], ds: DS) => boolean;
filterValidator: (filter: F) => void;
dictionaryQuery?: (filter: F, ds: DS) => DictionaryQueryEntry;
}
18 changes: 9 additions & 9 deletions packages/common-substrate/src/project/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
// SPDX-License-Identifier: Apache-2.0

import {CustomDatasourceTemplate, RuntimeDatasourceTemplate} from '@subql/common-substrate/project/versioned';
import {gte} from 'semver';
import {
SecondLayerHandlerProcessor,
SubstrateCustomDataSource,
SubstrateDataSource,
SubstrateCustomDatasource,
SubstrateDatasource,
SubstrateDatasourceKind,
SubstrateHandlerKind,
SubstrateNetworkFilter,
SubstrateRuntimeDataSource,
} from './types';
SubstrateRuntimeDatasource,
} from '@subql/types';
import {gte} from 'semver';

export function isBlockHandlerProcessor<T extends SubstrateNetworkFilter, E>(
hp: SecondLayerHandlerProcessor<SubstrateHandlerKind, T, unknown>
Expand All @@ -32,12 +32,12 @@ export function isCallHandlerProcessor<T extends SubstrateNetworkFilter, E>(
}

export function isCustomDs<F extends SubstrateNetworkFilter>(
ds: SubstrateDataSource
): ds is SubstrateCustomDataSource<string, F> {
return ds.kind !== SubstrateDatasourceKind.Runtime && !!(ds as SubstrateCustomDataSource<string, F>).processor;
ds: SubstrateDatasource
): ds is SubstrateCustomDatasource<string, F> {
return ds.kind !== SubstrateDatasourceKind.Runtime && !!(ds as SubstrateCustomDatasource<string, F>).processor;
}

export function isRuntimeDs(ds: SubstrateDataSource): ds is SubstrateRuntimeDataSource {
export function isRuntimeDs(ds: SubstrateDatasource): ds is SubstrateRuntimeDatasource {
return ds.kind === SubstrateDatasourceKind.Runtime;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2020-2022 OnFinality Limited authors & contributors
// SPDX-License-Identifier: Apache-2.0

import {SubstrateDatasource} from '@subql/types';
import {plainToClass} from 'class-transformer';
import {ISubstrateProjectManifest, SubstrateDataSource} from '../types';
import {ISubstrateProjectManifest} from '../types';
import {ProjectManifestV0_0_1Impl, RuntimeDataSourceV0_0_1} from './v0_0_1';
import {ProjectManifestV0_2_0Impl} from './v0_2_0';
import {ProjectManifestV0_2_1Impl} from './v0_2_1';
Expand Down Expand Up @@ -105,7 +106,7 @@ export class SubstrateProjectManifestVersioned implements ISubstrateProjectManif
return this._impl.validate();
}

get dataSources(): (SubstrateDataSource | RuntimeDataSourceV0_0_1)[] {
get dataSources(): (SubstrateDatasource | RuntimeDataSourceV0_0_1)[] {
return this._impl.dataSources;
}

Expand Down
Loading

0 comments on commit 9b5746a

Please sign in to comment.