@subql/common-stellar 2.2.1-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE +674 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/project/index.d.ts +5 -0
- package/dist/project/index.js +24 -0
- package/dist/project/index.js.map +1 -0
- package/dist/project/load.d.ts +3 -0
- package/dist/project/load.js +40 -0
- package/dist/project/load.js.map +1 -0
- package/dist/project/models.d.ts +46 -0
- package/dist/project/models.js +183 -0
- package/dist/project/models.js.map +1 -0
- package/dist/project/project.spec.d.ts +1 -0
- package/dist/project/project.spec.js +71 -0
- package/dist/project/project.spec.js.map +1 -0
- package/dist/project/types.d.ts +8 -0
- package/dist/project/types.js +10 -0
- package/dist/project/types.js.map +1 -0
- package/dist/project/utils.d.ts +4 -0
- package/dist/project/utils.js +19 -0
- package/dist/project/utils.js.map +1 -0
- package/dist/project/versioned/ProjectManifestVersioned.d.ts +26 -0
- package/dist/project/versioned/ProjectManifestVersioned.js +55 -0
- package/dist/project/versioned/ProjectManifestVersioned.js.map +1 -0
- package/dist/project/versioned/index.d.ts +2 -0
- package/dist/project/versioned/index.js +21 -0
- package/dist/project/versioned/index.js.map +1 -0
- package/dist/project/versioned/v1_0_0/index.d.ts +2 -0
- package/dist/project/versioned/v1_0_0/index.js +21 -0
- package/dist/project/versioned/v1_0_0/index.js.map +1 -0
- package/dist/project/versioned/v1_0_0/model.d.ts +56 -0
- package/dist/project/versioned/v1_0_0/model.js +226 -0
- package/dist/project/versioned/v1_0_0/model.js.map +1 -0
- package/dist/project/versioned/v1_0_0/types.d.ts +7 -0
- package/dist/project/versioned/v1_0_0/types.js +5 -0
- package/dist/project/versioned/v1_0_0/types.js.map +1 -0
- package/package.json +31 -0
- package/src/index.ts +4 -0
- package/src/project/index.ts +8 -0
- package/src/project/load.ts +33 -0
- package/src/project/models.ts +135 -0
- package/src/project/project.spec.ts +83 -0
- package/src/project/types.ts +28 -0
- package/src/project/utils.ts +25 -0
- package/src/project/versioned/ProjectManifestVersioned.ts +71 -0
- package/src/project/versioned/index.ts +5 -0
- package/src/project/versioned/v1_0_0/index.ts +5 -0
- package/src/project/versioned/v1_0_0/model.ts +202 -0
- package/src/project/versioned/v1_0_0/types.ts +13 -0
- package/test/project_1.0.0.yaml +34 -0
- package/tsconfig.json +11 -0
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@subql/common-stellar",
|
|
3
|
+
"version": "2.2.1-1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "rm -rf dist && tsc -b",
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"format": "prettier --write \"src/**/*.ts\""
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/subquery/subql-stellar",
|
|
11
|
+
"repository": "github:subquery/subql-stellar",
|
|
12
|
+
"author": "Ian He",
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"license": "GPL-3.0",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@subql/common": "^2.3.1-1",
|
|
17
|
+
"@subql/types-stellar": "2.2.3-3",
|
|
18
|
+
"js-yaml": "^4.1.0",
|
|
19
|
+
"pino": "^6.13.3",
|
|
20
|
+
"reflect-metadata": "^0.1.13"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"class-transformer": "*",
|
|
24
|
+
"class-validator": "*"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/js-yaml": "^4.0.4",
|
|
28
|
+
"@types/pino": "^6.3.12"
|
|
29
|
+
},
|
|
30
|
+
"stableVersion": "2.2.1-0"
|
|
31
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
3
|
+
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import {loadFromJsonOrYaml} from '@subql/common';
|
|
7
|
+
import {StellarProjectManifestVersioned, VersionedProjectManifest} from './versioned';
|
|
8
|
+
|
|
9
|
+
export function parseStellarProjectManifest(raw: unknown): StellarProjectManifestVersioned {
|
|
10
|
+
const projectManifest = new StellarProjectManifestVersioned(raw as VersionedProjectManifest);
|
|
11
|
+
projectManifest.validate();
|
|
12
|
+
return projectManifest;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function loadStellarProjectManifest(file: string): StellarProjectManifestVersioned {
|
|
16
|
+
let manifestPath = file;
|
|
17
|
+
if (fs.existsSync(file) && fs.lstatSync(file).isDirectory()) {
|
|
18
|
+
const yamlFilePath = path.join(file, 'project.yaml');
|
|
19
|
+
const jsonFilePath = path.join(file, 'project.json');
|
|
20
|
+
if (fs.existsSync(yamlFilePath)) {
|
|
21
|
+
manifestPath = yamlFilePath;
|
|
22
|
+
} else if (fs.existsSync(jsonFilePath)) {
|
|
23
|
+
manifestPath = jsonFilePath;
|
|
24
|
+
} else {
|
|
25
|
+
throw new Error(`Could not find project manifest under dir ${file}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const doc = loadFromJsonOrYaml(manifestPath);
|
|
30
|
+
const projectManifest = new StellarProjectManifestVersioned(doc as VersionedProjectManifest);
|
|
31
|
+
projectManifest.validate();
|
|
32
|
+
return projectManifest;
|
|
33
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
3
|
+
|
|
4
|
+
import {forbidNonWhitelisted} from '@subql/common';
|
|
5
|
+
import {
|
|
6
|
+
StellarHandlerKind,
|
|
7
|
+
StellarDatasourceKind,
|
|
8
|
+
StellarEventFilter,
|
|
9
|
+
SubqlCustomHandler,
|
|
10
|
+
SubqlMapping,
|
|
11
|
+
SubqlHandler,
|
|
12
|
+
SubqlRuntimeHandler,
|
|
13
|
+
SubqlRuntimeDatasource,
|
|
14
|
+
SubqlCustomDatasource,
|
|
15
|
+
FileReference,
|
|
16
|
+
CustomDataSourceAsset,
|
|
17
|
+
SubqlEventHandler,
|
|
18
|
+
} from '@subql/types-stellar';
|
|
19
|
+
import {plainToClass, Transform, Type} from 'class-transformer';
|
|
20
|
+
import {IsArray, IsEnum, IsInt, IsOptional, IsString, IsObject, ValidateNested} from 'class-validator';
|
|
21
|
+
import {SubqlStellarProcessorOptions} from './types';
|
|
22
|
+
|
|
23
|
+
export class EventFilter implements StellarEventFilter {
|
|
24
|
+
@IsOptional()
|
|
25
|
+
@IsString()
|
|
26
|
+
contractId?: string;
|
|
27
|
+
@IsOptional()
|
|
28
|
+
@IsArray()
|
|
29
|
+
topics?: string[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class EventHandler implements SubqlEventHandler {
|
|
33
|
+
@forbidNonWhitelisted({topics: '', contractId: ''})
|
|
34
|
+
@IsOptional()
|
|
35
|
+
@ValidateNested()
|
|
36
|
+
@Type(() => EventFilter)
|
|
37
|
+
filter?: StellarEventFilter;
|
|
38
|
+
@IsEnum(StellarHandlerKind, {groups: [StellarHandlerKind.Event]})
|
|
39
|
+
kind: StellarHandlerKind.Event;
|
|
40
|
+
@IsString()
|
|
41
|
+
handler: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class CustomHandler implements SubqlCustomHandler {
|
|
45
|
+
@IsString()
|
|
46
|
+
kind: string;
|
|
47
|
+
@IsString()
|
|
48
|
+
handler: string;
|
|
49
|
+
@IsObject()
|
|
50
|
+
@IsOptional()
|
|
51
|
+
filter?: Record<string, unknown>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export class StellarMapping implements SubqlMapping {
|
|
55
|
+
@Transform((params) => {
|
|
56
|
+
const handlers: SubqlHandler[] = params.value;
|
|
57
|
+
return handlers.map((handler) => {
|
|
58
|
+
switch (handler.kind) {
|
|
59
|
+
case StellarHandlerKind.Event:
|
|
60
|
+
return plainToClass(EventHandler, handler);
|
|
61
|
+
default:
|
|
62
|
+
throw new Error(`handler ${(handler as any).kind} not supported`);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
})
|
|
66
|
+
@IsArray()
|
|
67
|
+
@ValidateNested()
|
|
68
|
+
handlers: SubqlHandler[];
|
|
69
|
+
@IsString()
|
|
70
|
+
file: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export class CustomMapping implements SubqlMapping<SubqlCustomHandler> {
|
|
74
|
+
@IsArray()
|
|
75
|
+
@Type(() => CustomHandler)
|
|
76
|
+
@ValidateNested()
|
|
77
|
+
handlers: CustomHandler[];
|
|
78
|
+
@IsString()
|
|
79
|
+
file: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export class StellarProcessorOptions implements SubqlStellarProcessorOptions {
|
|
83
|
+
@IsOptional()
|
|
84
|
+
@IsString()
|
|
85
|
+
abi?: string;
|
|
86
|
+
@IsOptional()
|
|
87
|
+
@IsString()
|
|
88
|
+
address?: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export class RuntimeDataSourceBase<M extends SubqlMapping<SubqlRuntimeHandler>> implements SubqlRuntimeDatasource<M> {
|
|
92
|
+
@IsEnum(StellarDatasourceKind, {
|
|
93
|
+
groups: [StellarDatasourceKind.Runtime],
|
|
94
|
+
})
|
|
95
|
+
kind: StellarDatasourceKind.Runtime;
|
|
96
|
+
@Type(() => StellarMapping)
|
|
97
|
+
@ValidateNested()
|
|
98
|
+
mapping: M;
|
|
99
|
+
@IsOptional()
|
|
100
|
+
@IsInt()
|
|
101
|
+
startBlock?: number;
|
|
102
|
+
@IsOptional()
|
|
103
|
+
assets?: Map<string, FileReference>;
|
|
104
|
+
@IsOptional()
|
|
105
|
+
@ValidateNested()
|
|
106
|
+
@Type(() => StellarProcessorOptions)
|
|
107
|
+
options?: StellarProcessorOptions;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export class FileReferenceImpl implements FileReference {
|
|
111
|
+
@IsString()
|
|
112
|
+
file: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export class CustomDataSourceBase<K extends string, M extends SubqlMapping = SubqlMapping<SubqlCustomHandler>>
|
|
116
|
+
implements SubqlCustomDatasource<K, M>
|
|
117
|
+
{
|
|
118
|
+
@IsString()
|
|
119
|
+
kind: K;
|
|
120
|
+
@Type(() => CustomMapping)
|
|
121
|
+
@ValidateNested()
|
|
122
|
+
mapping: M;
|
|
123
|
+
@IsOptional()
|
|
124
|
+
@IsInt()
|
|
125
|
+
startBlock?: number;
|
|
126
|
+
@Type(() => FileReferenceImpl)
|
|
127
|
+
@ValidateNested({each: true})
|
|
128
|
+
assets: Map<string, CustomDataSourceAsset>;
|
|
129
|
+
@Type(() => FileReferenceImpl)
|
|
130
|
+
@IsObject()
|
|
131
|
+
processor: FileReference;
|
|
132
|
+
@IsOptional()
|
|
133
|
+
@ValidateNested()
|
|
134
|
+
options?: StellarProcessorOptions;
|
|
135
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
3
|
+
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import {RunnerQueryBaseModel} from '@subql/common';
|
|
6
|
+
import {validateSync} from 'class-validator';
|
|
7
|
+
import {DeploymentV1_0_0, StellarRunnerNodeImpl, StellarRunnerSpecsImpl} from '../project/versioned/v1_0_0';
|
|
8
|
+
import {loadStellarProjectManifest} from './load';
|
|
9
|
+
|
|
10
|
+
const projectsDir = path.join(__dirname, '../../test');
|
|
11
|
+
|
|
12
|
+
describe('project.yaml', () => {
|
|
13
|
+
it('can validate project.yaml', () => {
|
|
14
|
+
expect(() => loadStellarProjectManifest(path.join(projectsDir, 'project_falsy.yaml'))).toThrow();
|
|
15
|
+
expect(() => loadStellarProjectManifest(path.join(projectsDir, 'project_falsy_array.yaml'))).toThrow();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('can fail validation if version not supported', () => {
|
|
19
|
+
expect(() => loadStellarProjectManifest(path.join(projectsDir, 'project_invalid_version.yaml'))).toThrow();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('can validate a v1.0.0 project.yaml with templates', () => {
|
|
23
|
+
expect(() => loadStellarProjectManifest(path.join(projectsDir, 'project_1.0.0.yaml'))).not.toThrow();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('get v1.0.0 deployment mapping filter', () => {
|
|
27
|
+
const manifestVersioned = loadStellarProjectManifest(path.join(projectsDir, 'project_1.0.0.yaml'));
|
|
28
|
+
|
|
29
|
+
const deployment = manifestVersioned.asV1_0_0.deployment;
|
|
30
|
+
const filter = deployment.dataSources[0].mapping.handlers[0].filter;
|
|
31
|
+
const deploymentString = manifestVersioned.toDeployment();
|
|
32
|
+
expect(filter).not.toBeNull();
|
|
33
|
+
expect(deploymentString).toContain('COUNTER');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('can convert genesis hash in v1.0.0 to chainId in deployment', () => {
|
|
37
|
+
const deployment = loadStellarProjectManifest(path.join(projectsDir, 'project_1.0.0.yaml')).asV1_0_0.deployment;
|
|
38
|
+
expect(deployment.network.chainId).not.toBeNull();
|
|
39
|
+
console.log(deployment.network.chainId);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it.skip('can get chainId for deployment', () => {
|
|
43
|
+
const deployment = loadStellarProjectManifest(path.join(projectsDir, 'project_1.0.0_chainId.yaml')).asV1_0_0
|
|
44
|
+
.deployment;
|
|
45
|
+
expect(deployment.network.chainId).toBe('moonbeamChainId');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('can validate deployment runner versions', () => {
|
|
49
|
+
const deployment = new DeploymentV1_0_0();
|
|
50
|
+
const nodeImp = new StellarRunnerNodeImpl();
|
|
51
|
+
const queryImp = new RunnerQueryBaseModel();
|
|
52
|
+
deployment.specVersion = '1.0.0';
|
|
53
|
+
deployment.runner = new StellarRunnerSpecsImpl();
|
|
54
|
+
|
|
55
|
+
nodeImp.name = '@subql/node-stellar';
|
|
56
|
+
nodeImp.version = '0.29.1';
|
|
57
|
+
deployment.runner.node = nodeImp;
|
|
58
|
+
|
|
59
|
+
queryImp.name = '@subql/query';
|
|
60
|
+
queryImp.version = '0.213.1';
|
|
61
|
+
|
|
62
|
+
deployment.runner.query = queryImp;
|
|
63
|
+
|
|
64
|
+
validateSync(deployment.runner, {whitelist: true, forbidNonWhitelisted: true});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('can validate a v1.0.0 project.yaml with unsupported runner node', () => {
|
|
68
|
+
expect(() => loadStellarProjectManifest(path.join(projectsDir, 'project_1.0.0_bad_runner.yaml'))).toThrow();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
//TODO, pre-release should be excluded
|
|
72
|
+
it.skip('can throw error with unsupported runner version', () => {
|
|
73
|
+
expect(() => loadStellarProjectManifest(path.join(projectsDir, 'project_1.0.0_bad_runner_version.yaml'))).toThrow();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('can validate a v1.0.0 project.yaml runner and datasource mismatches', () => {
|
|
77
|
+
expect(() => loadStellarProjectManifest(path.join(projectsDir, 'project_1.0.0_runner_ds_mismatch.yaml'))).toThrow();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('can fail validation if custom ds missing processor', () => {
|
|
81
|
+
expect(() => loadStellarProjectManifest(path.join(projectsDir, 'project_0.2.0_invalid_custom_ds.yaml'))).toThrow();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
3
|
+
|
|
4
|
+
import {IProjectManifest, ProjectNetworkConfig} from '@subql/common';
|
|
5
|
+
import {SubqlDatasource} from '@subql/types-stellar';
|
|
6
|
+
|
|
7
|
+
// All of these used to be redefined in this file, re-exporting for simplicity
|
|
8
|
+
export {
|
|
9
|
+
SubqlStellarProcessorOptions,
|
|
10
|
+
SubqlRuntimeHandler,
|
|
11
|
+
SubqlCustomHandler,
|
|
12
|
+
SubqlHandler,
|
|
13
|
+
StellarHandlerKind,
|
|
14
|
+
SubqlDatasource as SubqlStellarDataSource,
|
|
15
|
+
SubqlCustomDatasource as SubqlStellarCustomDataSource,
|
|
16
|
+
StellarEventFilter,
|
|
17
|
+
SubqlDatasourceProcessor,
|
|
18
|
+
SubqlHandlerFilter,
|
|
19
|
+
StellarDatasourceKind,
|
|
20
|
+
StellarRuntimeHandlerInputMap as StellarRuntimeHandlerInputMap,
|
|
21
|
+
} from '@subql/types-stellar';
|
|
22
|
+
|
|
23
|
+
export type IStellarProjectManifest = IProjectManifest<SubqlDatasource>;
|
|
24
|
+
|
|
25
|
+
export interface StellarProjectNetworkConfig extends ProjectNetworkConfig {
|
|
26
|
+
genesisHash?: string;
|
|
27
|
+
chainId?: string;
|
|
28
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
SecondLayerHandlerProcessor,
|
|
6
|
+
SubqlCustomDatasource,
|
|
7
|
+
SubqlDatasource,
|
|
8
|
+
StellarDatasourceKind,
|
|
9
|
+
StellarHandlerKind,
|
|
10
|
+
SubqlRuntimeDatasource,
|
|
11
|
+
} from '@subql/types-stellar';
|
|
12
|
+
|
|
13
|
+
export function isEventHandlerProcessor<E>(
|
|
14
|
+
hp: SecondLayerHandlerProcessor<StellarHandlerKind, unknown, unknown>
|
|
15
|
+
): hp is SecondLayerHandlerProcessor<StellarHandlerKind.Event, unknown, E> {
|
|
16
|
+
return hp.baseHandlerKind === StellarHandlerKind.Event;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function isCustomDs(ds: SubqlDatasource): ds is SubqlCustomDatasource<string> {
|
|
20
|
+
return ds.kind !== StellarDatasourceKind.Runtime && !!(ds as SubqlCustomDatasource<string>).processor;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function isRuntimeDs(ds: SubqlDatasource): ds is SubqlRuntimeDatasource {
|
|
24
|
+
return ds.kind === StellarDatasourceKind.Runtime;
|
|
25
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
3
|
+
|
|
4
|
+
import {plainToClass} from 'class-transformer';
|
|
5
|
+
import {IStellarProjectManifest, SubqlStellarDataSource} from '../types';
|
|
6
|
+
import {ProjectManifestV1_0_0Impl} from './v1_0_0';
|
|
7
|
+
export type VersionedProjectManifest = {specVersion: string};
|
|
8
|
+
|
|
9
|
+
const SOROBAN_SUPPORTED_VERSIONS = {
|
|
10
|
+
'1.0.0': ProjectManifestV1_0_0Impl,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type Versions = keyof typeof SOROBAN_SUPPORTED_VERSIONS;
|
|
14
|
+
|
|
15
|
+
type ProjectManifestImpls = InstanceType<(typeof SOROBAN_SUPPORTED_VERSIONS)[Versions]>;
|
|
16
|
+
|
|
17
|
+
export function manifestIsV1_0_0(manifest: IStellarProjectManifest): manifest is ProjectManifestV1_0_0Impl {
|
|
18
|
+
return manifest.specVersion === '1.0.0';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class StellarProjectManifestVersioned implements IStellarProjectManifest {
|
|
22
|
+
private _impl: ProjectManifestImpls;
|
|
23
|
+
|
|
24
|
+
constructor(projectManifest: VersionedProjectManifest) {
|
|
25
|
+
const klass = SOROBAN_SUPPORTED_VERSIONS[projectManifest.specVersion as Versions];
|
|
26
|
+
if (!klass) {
|
|
27
|
+
throw new Error('specVersion not supported for project manifest file');
|
|
28
|
+
}
|
|
29
|
+
this._impl = plainToClass<ProjectManifestImpls, VersionedProjectManifest>(klass, projectManifest);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get asImpl(): ProjectManifestImpls {
|
|
33
|
+
return this._impl;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get isV1_0_0(): boolean {
|
|
37
|
+
return this.specVersion === '1.0.0';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get asV1_0_0(): ProjectManifestV1_0_0Impl {
|
|
41
|
+
return this._impl as ProjectManifestV1_0_0Impl;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
toDeployment(): string | undefined {
|
|
45
|
+
return this._impl.toDeployment();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
validate(): void {
|
|
49
|
+
return this._impl.validate();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get dataSources(): SubqlStellarDataSource[] {
|
|
53
|
+
return this._impl.dataSources;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get schema(): string {
|
|
57
|
+
return this._impl.schema.file;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get specVersion(): string {
|
|
61
|
+
return this._impl.specVersion;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
get description(): string {
|
|
65
|
+
return this._impl.description;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get repository(): string {
|
|
69
|
+
return this._impl.repository;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
BaseMapping,
|
|
6
|
+
FileType,
|
|
7
|
+
NodeSpec,
|
|
8
|
+
ProjectManifestBaseImpl,
|
|
9
|
+
QuerySpec,
|
|
10
|
+
RunnerNodeImpl,
|
|
11
|
+
RunnerQueryBaseModel,
|
|
12
|
+
RunnerSpecs,
|
|
13
|
+
validateObject,
|
|
14
|
+
} from '@subql/common';
|
|
15
|
+
import {SubqlCustomDatasource, SubqlMapping, SubqlRuntimeDatasource} from '@subql/types-stellar';
|
|
16
|
+
import {plainToClass, Transform, TransformFnParams, Type} from 'class-transformer';
|
|
17
|
+
import {
|
|
18
|
+
Equals,
|
|
19
|
+
IsArray,
|
|
20
|
+
IsIn,
|
|
21
|
+
IsNotEmpty,
|
|
22
|
+
IsObject,
|
|
23
|
+
IsOptional,
|
|
24
|
+
IsString,
|
|
25
|
+
ValidateNested,
|
|
26
|
+
validateSync,
|
|
27
|
+
} from 'class-validator';
|
|
28
|
+
import {CustomDataSourceBase, StellarMapping, RuntimeDataSourceBase} from '../../models';
|
|
29
|
+
import {SubqlStellarDataSource, SubqlRuntimeHandler} from '../../types';
|
|
30
|
+
import {CustomDatasourceTemplate, StellarProjectManifestV1_0_0, RuntimeDatasourceTemplate} from './types';
|
|
31
|
+
|
|
32
|
+
const Stellar_NODE_NAME = `@subql/node-stellar`;
|
|
33
|
+
|
|
34
|
+
export class StellarProjectMapping extends StellarMapping {
|
|
35
|
+
@IsString()
|
|
36
|
+
file: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class StellarRunnerNodeImpl extends RunnerNodeImpl {
|
|
40
|
+
@IsIn([Stellar_NODE_NAME], {
|
|
41
|
+
message: `Runner Substrate node name incorrect, suppose be '${Stellar_NODE_NAME}'`,
|
|
42
|
+
})
|
|
43
|
+
name: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class StellarRuntimeDataSourceImpl
|
|
47
|
+
extends RuntimeDataSourceBase<SubqlMapping<SubqlRuntimeHandler>>
|
|
48
|
+
implements SubqlRuntimeDatasource
|
|
49
|
+
{
|
|
50
|
+
validate(): void {
|
|
51
|
+
return validateObject(this, 'failed to validate runtime datasource.');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export class StellarCustomDataSourceImpl<
|
|
56
|
+
K extends string = string,
|
|
57
|
+
M extends BaseMapping<any, any> = BaseMapping<Record<string, unknown>, any>
|
|
58
|
+
>
|
|
59
|
+
extends CustomDataSourceBase<K, M>
|
|
60
|
+
implements SubqlCustomDatasource<K, M>
|
|
61
|
+
{
|
|
62
|
+
validate(): void {
|
|
63
|
+
return validateObject(this, 'failed to validate custom datasource.');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export class RuntimeDatasourceTemplateImpl extends StellarRuntimeDataSourceImpl implements RuntimeDatasourceTemplate {
|
|
68
|
+
@IsString()
|
|
69
|
+
name: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export class CustomDatasourceTemplateImpl extends StellarCustomDataSourceImpl implements CustomDatasourceTemplate {
|
|
73
|
+
@IsString()
|
|
74
|
+
name: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export class StellarRunnerSpecsImpl implements RunnerSpecs {
|
|
78
|
+
@IsObject()
|
|
79
|
+
@ValidateNested()
|
|
80
|
+
@Type(() => StellarRunnerNodeImpl)
|
|
81
|
+
node: NodeSpec;
|
|
82
|
+
@IsObject()
|
|
83
|
+
@ValidateNested()
|
|
84
|
+
@Type(() => RunnerQueryBaseModel)
|
|
85
|
+
query: QuerySpec;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export class ProjectNetworkDeploymentV1_0_0 {
|
|
89
|
+
@IsNotEmpty()
|
|
90
|
+
@Transform(({value}: TransformFnParams) => value.trim())
|
|
91
|
+
@IsString()
|
|
92
|
+
chainId: string;
|
|
93
|
+
@ValidateNested()
|
|
94
|
+
@Type(() => FileType)
|
|
95
|
+
@IsOptional()
|
|
96
|
+
chaintypes?: FileType;
|
|
97
|
+
@IsOptional()
|
|
98
|
+
@IsArray()
|
|
99
|
+
bypassBlocks?: (number | string)[];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export class ProjectNetworkV1_0_0 extends ProjectNetworkDeploymentV1_0_0 {
|
|
103
|
+
@IsString({each: true})
|
|
104
|
+
@IsOptional()
|
|
105
|
+
endpoint?: string | string[];
|
|
106
|
+
@IsString()
|
|
107
|
+
@IsOptional()
|
|
108
|
+
dictionary?: string;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export class DeploymentV1_0_0 {
|
|
112
|
+
@Transform((params) => {
|
|
113
|
+
if (params.value.genesisHash && !params.value.chainId) {
|
|
114
|
+
params.value.chainId = params.value.genesisHash;
|
|
115
|
+
}
|
|
116
|
+
return plainToClass(ProjectNetworkDeploymentV1_0_0, params.value);
|
|
117
|
+
})
|
|
118
|
+
@ValidateNested()
|
|
119
|
+
@Type(() => ProjectNetworkDeploymentV1_0_0)
|
|
120
|
+
network: ProjectNetworkDeploymentV1_0_0;
|
|
121
|
+
@Equals('1.0.0')
|
|
122
|
+
@IsString()
|
|
123
|
+
specVersion: string;
|
|
124
|
+
@IsObject()
|
|
125
|
+
@ValidateNested()
|
|
126
|
+
@Type(() => StellarRunnerSpecsImpl)
|
|
127
|
+
runner: RunnerSpecs;
|
|
128
|
+
@ValidateNested()
|
|
129
|
+
@Type(() => FileType)
|
|
130
|
+
schema: FileType;
|
|
131
|
+
@IsArray()
|
|
132
|
+
@ValidateNested()
|
|
133
|
+
@Type(() => StellarCustomDataSourceImpl, {
|
|
134
|
+
discriminator: {
|
|
135
|
+
property: 'kind',
|
|
136
|
+
subTypes: [{value: StellarRuntimeDataSourceImpl, name: 'stellar/Runtime'}],
|
|
137
|
+
},
|
|
138
|
+
keepDiscriminatorProperty: true,
|
|
139
|
+
})
|
|
140
|
+
dataSources: (SubqlRuntimeDatasource | SubqlCustomDatasource)[];
|
|
141
|
+
@IsOptional()
|
|
142
|
+
@IsArray()
|
|
143
|
+
@ValidateNested()
|
|
144
|
+
@Type(() => CustomDatasourceTemplateImpl, {
|
|
145
|
+
discriminator: {
|
|
146
|
+
property: 'kind',
|
|
147
|
+
subTypes: [{value: RuntimeDatasourceTemplateImpl, name: 'stellar/Runtime'}],
|
|
148
|
+
},
|
|
149
|
+
keepDiscriminatorProperty: true,
|
|
150
|
+
})
|
|
151
|
+
templates?: (RuntimeDatasourceTemplate | CustomDatasourceTemplate)[];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export class ProjectManifestV1_0_0Impl<D extends object = DeploymentV1_0_0>
|
|
155
|
+
extends ProjectManifestBaseImpl<D>
|
|
156
|
+
implements StellarProjectManifestV1_0_0
|
|
157
|
+
{
|
|
158
|
+
@Equals('1.0.0')
|
|
159
|
+
specVersion: string;
|
|
160
|
+
@Type(() => StellarCustomDataSourceImpl, {
|
|
161
|
+
discriminator: {
|
|
162
|
+
property: 'kind',
|
|
163
|
+
subTypes: [{value: StellarRuntimeDataSourceImpl, name: 'stellar/Runtime'}],
|
|
164
|
+
},
|
|
165
|
+
keepDiscriminatorProperty: true,
|
|
166
|
+
})
|
|
167
|
+
dataSources: SubqlStellarDataSource[];
|
|
168
|
+
@Type(() => ProjectNetworkV1_0_0)
|
|
169
|
+
network: ProjectNetworkV1_0_0;
|
|
170
|
+
@IsString()
|
|
171
|
+
name: string;
|
|
172
|
+
@IsString()
|
|
173
|
+
version: string;
|
|
174
|
+
@ValidateNested()
|
|
175
|
+
@Type(() => FileType)
|
|
176
|
+
schema: FileType;
|
|
177
|
+
@IsOptional()
|
|
178
|
+
@IsArray()
|
|
179
|
+
@ValidateNested()
|
|
180
|
+
@Type(() => CustomDatasourceTemplateImpl, {
|
|
181
|
+
discriminator: {
|
|
182
|
+
property: 'kind',
|
|
183
|
+
subTypes: [{value: RuntimeDatasourceTemplateImpl, name: 'stellar/Runtime'}],
|
|
184
|
+
},
|
|
185
|
+
keepDiscriminatorProperty: true,
|
|
186
|
+
})
|
|
187
|
+
templates?: (RuntimeDatasourceTemplate | CustomDatasourceTemplate)[];
|
|
188
|
+
@IsObject()
|
|
189
|
+
@ValidateNested()
|
|
190
|
+
@Type(() => StellarRunnerSpecsImpl)
|
|
191
|
+
runner: RunnerSpecs;
|
|
192
|
+
protected _deployment: D;
|
|
193
|
+
|
|
194
|
+
get deployment(): D {
|
|
195
|
+
if (!this._deployment) {
|
|
196
|
+
this._deployment = plainToClass(DeploymentV1_0_0, this) as unknown as D;
|
|
197
|
+
//validateSync(this._deployment.)
|
|
198
|
+
validateSync(this._deployment, {whitelist: true});
|
|
199
|
+
}
|
|
200
|
+
return this._deployment;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
3
|
+
|
|
4
|
+
import {ProjectManifestV1_0_0, TemplateBase} from '@subql/common';
|
|
5
|
+
import {SubqlCustomDatasource, SubqlRuntimeDatasource} from '@subql/types-stellar';
|
|
6
|
+
|
|
7
|
+
export interface RuntimeDatasourceTemplate extends Omit<SubqlRuntimeDatasource, 'name'>, TemplateBase {}
|
|
8
|
+
export interface CustomDatasourceTemplate extends Omit<SubqlCustomDatasource, 'name'>, TemplateBase {}
|
|
9
|
+
|
|
10
|
+
export type StellarProjectManifestV1_0_0 = ProjectManifestV1_0_0<
|
|
11
|
+
RuntimeDatasourceTemplate | CustomDatasourceTemplate,
|
|
12
|
+
SubqlRuntimeDatasource | SubqlCustomDatasource
|
|
13
|
+
>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
specVersion: '1.0.0'
|
|
2
|
+
|
|
3
|
+
name: 'stellar-subql-starter'
|
|
4
|
+
version: '0.0.1'
|
|
5
|
+
runner:
|
|
6
|
+
node:
|
|
7
|
+
name: '@subql/node-stellar'
|
|
8
|
+
version: '*'
|
|
9
|
+
query:
|
|
10
|
+
name: '@subql/query'
|
|
11
|
+
version: '*'
|
|
12
|
+
description: 'This project can be use as a starting point for developing your new Stellar SubQuery project'
|
|
13
|
+
repository: 'https://github.com/subquery/stellar-subql-starter'
|
|
14
|
+
|
|
15
|
+
schema:
|
|
16
|
+
file: './schema.graphql'
|
|
17
|
+
|
|
18
|
+
network:
|
|
19
|
+
chainId: 'Test SDF Future Network ; October 2022'
|
|
20
|
+
endpoint: ['https://rpc-futurenet.stellar.org:443']
|
|
21
|
+
|
|
22
|
+
dataSources:
|
|
23
|
+
- kind: stellar/Runtime
|
|
24
|
+
startBlock: 52400
|
|
25
|
+
mapping:
|
|
26
|
+
file: './dist/index.js'
|
|
27
|
+
handlers:
|
|
28
|
+
- handler: handleEvent
|
|
29
|
+
kind: stellar/EventHandler
|
|
30
|
+
filter:
|
|
31
|
+
contractId: '34799b3411940249e73d21def8eb2c2b56b285ab8d1ca76d6780ec10a0e8f02e'
|
|
32
|
+
topics:
|
|
33
|
+
- 'COUNTER'
|
|
34
|
+
- 'increment'
|