@subql/common-solana 0.0.0-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/codegen/codegen.d.ts +4 -0
- package/dist/codegen/codegen.js +68 -0
- package/dist/codegen/codegen.js.map +1 -0
- package/dist/codegen/codegen.spec.d.ts +1 -0
- package/dist/codegen/codegen.spec.js +130 -0
- package/dist/codegen/codegen.spec.js.map +1 -0
- package/dist/codegen/idl.d.ts +11 -0
- package/dist/codegen/idl.js +88 -0
- package/dist/codegen/idl.js.map +1 -0
- package/dist/codegen/index.d.ts +2 -0
- package/dist/codegen/index.js +21 -0
- package/dist/codegen/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/project/index.d.ts +7 -0
- package/dist/project/index.js +27 -0
- package/dist/project/index.js.map +1 -0
- package/dist/project/load.d.ts +2 -0
- package/dist/project/load.js +12 -0
- package/dist/project/load.js.map +1 -0
- package/dist/project/models.d.ts +81 -0
- package/dist/project/models.js +270 -0
- package/dist/project/models.js.map +1 -0
- package/dist/project/project.spec.d.ts +1 -0
- package/dist/project/project.spec.js +109 -0
- package/dist/project/project.spec.js.map +1 -0
- package/dist/project/types.d.ts +4 -0
- package/dist/project/types.js +5 -0
- package/dist/project/types.js.map +1 -0
- package/dist/project/utils.d.ts +9 -0
- package/dist/project/utils.js +30 -0
- package/dist/project/utils.js.map +1 -0
- package/dist/project/versioned/ProjectManifestVersioned.d.ts +26 -0
- package/dist/project/versioned/ProjectManifestVersioned.js +56 -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 +1 -0
- package/dist/project/versioned/v1_0_0/index.js +20 -0
- package/dist/project/versioned/v1_0_0/index.js.map +1 -0
- package/dist/project/versioned/v1_0_0/model.d.ts +52 -0
- package/dist/project/versioned/v1_0_0/model.js +236 -0
- package/dist/project/versioned/v1_0_0/model.js.map +1 -0
- package/package.json +40 -0
- package/src/codegen/codegen.spec.ts +145 -0
- package/src/codegen/codegen.ts +90 -0
- package/src/codegen/idl.ts +89 -0
- package/src/codegen/index.ts +5 -0
- package/src/index.ts +16 -0
- package/src/project/index.ts +11 -0
- package/src/project/load.ts +10 -0
- package/src/project/models.ts +213 -0
- package/src/project/project.spec.ts +123 -0
- package/src/project/types.ts +19 -0
- package/src/project/utils.ts +50 -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 +4 -0
- package/src/project/versioned/v1_0_0/model.ts +200 -0
- package/templates/idl.ts.ejs +10 -0
- package/test/abiTest/project.yaml +51 -0
- package/test/project_1.0.0.yaml +91 -0
- package/tsconfig.json +12 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
3
|
+
|
|
4
|
+
export * from './codegen';
|
|
5
|
+
export * from './project';
|
|
6
|
+
|
|
7
|
+
import {SolanaNetworkModule} from '@subql/types-solana';
|
|
8
|
+
import * as c from './codegen';
|
|
9
|
+
import * as p from './project';
|
|
10
|
+
|
|
11
|
+
// This provides a compiled time check to ensure that the correct exports are provided
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
13
|
+
const _ = {
|
|
14
|
+
...p,
|
|
15
|
+
...c,
|
|
16
|
+
} satisfies SolanaNetworkModule;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
3
|
+
|
|
4
|
+
export * from './load';
|
|
5
|
+
export * from './models';
|
|
6
|
+
export * from './types';
|
|
7
|
+
export * from './utils';
|
|
8
|
+
export * from './versioned';
|
|
9
|
+
|
|
10
|
+
import { parseSolanaProjectManifest } from './load';
|
|
11
|
+
export { parseSolanaProjectManifest as parseProjectManifest };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
3
|
+
|
|
4
|
+
import { SolanaProjectManifestVersioned, VersionedProjectManifest } from './versioned';
|
|
5
|
+
|
|
6
|
+
export function parseSolanaProjectManifest(raw: unknown): SolanaProjectManifestVersioned {
|
|
7
|
+
const projectManifest = new SolanaProjectManifestVersioned(raw as VersionedProjectManifest);
|
|
8
|
+
projectManifest.validate();
|
|
9
|
+
return projectManifest;
|
|
10
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
3
|
+
|
|
4
|
+
import {BaseDataSource, BlockFilterImpl, forbidNonWhitelisted} from '@subql/common';
|
|
5
|
+
import {FileReference} from '@subql/types-core';
|
|
6
|
+
import {
|
|
7
|
+
SolanaHandlerKind,
|
|
8
|
+
SolanaDatasourceKind,
|
|
9
|
+
SolanaLogFilter,
|
|
10
|
+
SubqlCustomHandler,
|
|
11
|
+
SubqlMapping,
|
|
12
|
+
SubqlHandler,
|
|
13
|
+
SubqlRuntimeHandler,
|
|
14
|
+
SubqlRuntimeDatasource,
|
|
15
|
+
SubqlCustomDatasource,
|
|
16
|
+
SubqlBlockHandler,
|
|
17
|
+
SubqlTransactionHandler,
|
|
18
|
+
SolanaTransactionFilter,
|
|
19
|
+
SolanaBlockFilter,
|
|
20
|
+
SolanaInstructionFilter,
|
|
21
|
+
SubqlInstructionHandler,
|
|
22
|
+
SubqlLogHandler,
|
|
23
|
+
InstructionAccountFilter,
|
|
24
|
+
} from '@subql/types-solana';
|
|
25
|
+
import {plainToClass, Transform, Type} from 'class-transformer';
|
|
26
|
+
import {
|
|
27
|
+
IsArray,
|
|
28
|
+
IsEnum,
|
|
29
|
+
IsOptional,
|
|
30
|
+
IsString,
|
|
31
|
+
IsObject,
|
|
32
|
+
ValidateNested,
|
|
33
|
+
ValidateIf,
|
|
34
|
+
IsDefined,
|
|
35
|
+
IsBoolean,
|
|
36
|
+
} from 'class-validator';
|
|
37
|
+
|
|
38
|
+
export class BlockFilter extends BlockFilterImpl implements SolanaBlockFilter {}
|
|
39
|
+
|
|
40
|
+
export class TransactionFilter implements SolanaTransactionFilter {
|
|
41
|
+
@IsOptional()
|
|
42
|
+
@IsString()
|
|
43
|
+
signerAccountKey?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class InstructionFilter implements SolanaInstructionFilter {
|
|
47
|
+
@ValidateIf((o) => o.discriminator !== undefined)
|
|
48
|
+
@IsDefined({message: 'programId is required if discriminator is set'})
|
|
49
|
+
@IsString()
|
|
50
|
+
programId?: string;
|
|
51
|
+
|
|
52
|
+
@IsOptional()
|
|
53
|
+
@IsString()
|
|
54
|
+
discriminator?: string;
|
|
55
|
+
|
|
56
|
+
@IsOptional()
|
|
57
|
+
@IsArray()
|
|
58
|
+
accounts?: [
|
|
59
|
+
InstructionAccountFilter,
|
|
60
|
+
InstructionAccountFilter?,
|
|
61
|
+
InstructionAccountFilter?,
|
|
62
|
+
InstructionAccountFilter?,
|
|
63
|
+
InstructionAccountFilter?,
|
|
64
|
+
InstructionAccountFilter?,
|
|
65
|
+
InstructionAccountFilter?,
|
|
66
|
+
InstructionAccountFilter?,
|
|
67
|
+
InstructionAccountFilter?,
|
|
68
|
+
InstructionAccountFilter?,
|
|
69
|
+
InstructionAccountFilter?,
|
|
70
|
+
InstructionAccountFilter?,
|
|
71
|
+
InstructionAccountFilter?,
|
|
72
|
+
InstructionAccountFilter?,
|
|
73
|
+
InstructionAccountFilter?,
|
|
74
|
+
InstructionAccountFilter?
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
@IsOptional()
|
|
78
|
+
@IsBoolean()
|
|
79
|
+
includeFalied?: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export class LogFilter implements SolanaLogFilter {
|
|
83
|
+
@IsOptional()
|
|
84
|
+
@IsString()
|
|
85
|
+
programId?: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export class BlockHandler implements SubqlBlockHandler {
|
|
89
|
+
@IsObject()
|
|
90
|
+
@IsOptional()
|
|
91
|
+
@Type(() => BlockFilter)
|
|
92
|
+
filter?: BlockFilter;
|
|
93
|
+
@IsEnum(SolanaHandlerKind, {groups: [SolanaHandlerKind.Block]})
|
|
94
|
+
kind!: SolanaHandlerKind.Block;
|
|
95
|
+
@IsString()
|
|
96
|
+
handler!: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export class TransactionHandler implements SubqlTransactionHandler {
|
|
100
|
+
@IsOptional()
|
|
101
|
+
@ValidateNested()
|
|
102
|
+
@Type(() => TransactionFilter)
|
|
103
|
+
filter?: SolanaTransactionFilter;
|
|
104
|
+
@IsEnum(SolanaHandlerKind, {groups: [SolanaHandlerKind.Transaction]})
|
|
105
|
+
kind!: SolanaHandlerKind.Transaction;
|
|
106
|
+
@IsString()
|
|
107
|
+
handler!: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export class InstructionHandler implements SubqlInstructionHandler {
|
|
111
|
+
@IsOptional()
|
|
112
|
+
@ValidateNested()
|
|
113
|
+
@Type(() => InstructionFilter)
|
|
114
|
+
filter?: SolanaInstructionFilter;
|
|
115
|
+
@IsEnum(SolanaHandlerKind, {groups: [SolanaHandlerKind.Instruction]})
|
|
116
|
+
kind!: SolanaHandlerKind.Instruction;
|
|
117
|
+
@IsString()
|
|
118
|
+
handler!: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export class LogHandler implements SubqlLogHandler {
|
|
122
|
+
@IsOptional()
|
|
123
|
+
@ValidateNested()
|
|
124
|
+
@Type(() => LogFilter)
|
|
125
|
+
filter?: SolanaLogFilter;
|
|
126
|
+
@IsEnum(SolanaHandlerKind, {groups: [SolanaHandlerKind.Log]})
|
|
127
|
+
kind!: SolanaHandlerKind.Log;
|
|
128
|
+
@IsString()
|
|
129
|
+
handler!: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export class CustomHandler implements SubqlCustomHandler {
|
|
133
|
+
@IsString()
|
|
134
|
+
kind!: string;
|
|
135
|
+
@IsString()
|
|
136
|
+
handler!: string;
|
|
137
|
+
@IsObject()
|
|
138
|
+
@IsOptional()
|
|
139
|
+
filter?: Record<string, unknown>;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export class SolanaMapping implements SubqlMapping {
|
|
143
|
+
@Transform((params) => {
|
|
144
|
+
const handlers: SubqlHandler[] = params.value;
|
|
145
|
+
return handlers.map((handler) => {
|
|
146
|
+
switch (handler.kind) {
|
|
147
|
+
case SolanaHandlerKind.Log:
|
|
148
|
+
return plainToClass(LogHandler, handler);
|
|
149
|
+
case SolanaHandlerKind.Instruction:
|
|
150
|
+
return plainToClass(InstructionHandler, handler);
|
|
151
|
+
case SolanaHandlerKind.Transaction:
|
|
152
|
+
return plainToClass(TransactionHandler, handler);
|
|
153
|
+
case SolanaHandlerKind.Block:
|
|
154
|
+
return plainToClass(BlockHandler, handler);
|
|
155
|
+
default:
|
|
156
|
+
throw new Error(`handler ${(handler as any).kind} not supported`);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
})
|
|
160
|
+
@IsArray()
|
|
161
|
+
@ValidateNested()
|
|
162
|
+
handlers!: SubqlHandler[];
|
|
163
|
+
@IsString()
|
|
164
|
+
file!: string;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export class CustomMapping implements SubqlMapping<SubqlCustomHandler> {
|
|
168
|
+
@IsArray()
|
|
169
|
+
@Type(() => CustomHandler)
|
|
170
|
+
@ValidateNested()
|
|
171
|
+
handlers!: CustomHandler[];
|
|
172
|
+
@IsString()
|
|
173
|
+
file!: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export class RuntimeDataSourceBase<M extends SubqlMapping<SubqlRuntimeHandler>>
|
|
177
|
+
extends BaseDataSource
|
|
178
|
+
implements SubqlRuntimeDatasource<M>
|
|
179
|
+
{
|
|
180
|
+
@IsEnum(SolanaDatasourceKind, {
|
|
181
|
+
groups: [SolanaDatasourceKind.Runtime],
|
|
182
|
+
})
|
|
183
|
+
kind!: SolanaDatasourceKind.Runtime;
|
|
184
|
+
@Type(() => SolanaMapping)
|
|
185
|
+
@ValidateNested()
|
|
186
|
+
mapping!: M;
|
|
187
|
+
@Type(() => FileReferenceImpl)
|
|
188
|
+
@ValidateNested({each: true})
|
|
189
|
+
@IsOptional()
|
|
190
|
+
assets?: Map<string, FileReference>;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export class FileReferenceImpl implements FileReference {
|
|
194
|
+
@IsString()
|
|
195
|
+
file!: string;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export class CustomDataSourceBase<K extends string, M extends SubqlMapping = SubqlMapping<SubqlCustomHandler>>
|
|
199
|
+
extends BaseDataSource
|
|
200
|
+
implements SubqlCustomDatasource<K, M>
|
|
201
|
+
{
|
|
202
|
+
@IsString()
|
|
203
|
+
kind!: K;
|
|
204
|
+
@Type(() => CustomMapping)
|
|
205
|
+
@ValidateNested()
|
|
206
|
+
mapping!: M;
|
|
207
|
+
@Type(() => FileReferenceImpl)
|
|
208
|
+
@ValidateNested({each: true})
|
|
209
|
+
assets!: Map<string, FileReference>;
|
|
210
|
+
@Type(() => FileReferenceImpl)
|
|
211
|
+
@IsObject()
|
|
212
|
+
processor!: FileReference;
|
|
213
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Copyright 2020-2025 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, RunnerQueryBaseModel} from '@subql/common';
|
|
7
|
+
import {validateSync} from 'class-validator';
|
|
8
|
+
import {DeploymentV1_0_0, SolanaRunnerNodeImpl, SolanaRunnerSpecsImpl} from '../project/versioned/v1_0_0';
|
|
9
|
+
import {SolanaProjectManifestVersioned, VersionedProjectManifest} from './versioned';
|
|
10
|
+
|
|
11
|
+
const projectsDir = path.join(__dirname, '../../test');
|
|
12
|
+
|
|
13
|
+
function loadSolanaProjectManifest(file: string): SolanaProjectManifestVersioned {
|
|
14
|
+
let manifestPath = file;
|
|
15
|
+
if (fs.existsSync(file) && fs.lstatSync(file).isDirectory()) {
|
|
16
|
+
const yamlFilePath = path.join(file, 'project.yaml');
|
|
17
|
+
const jsonFilePath = path.join(file, 'project.json');
|
|
18
|
+
if (fs.existsSync(yamlFilePath)) {
|
|
19
|
+
manifestPath = yamlFilePath;
|
|
20
|
+
} else if (fs.existsSync(jsonFilePath)) {
|
|
21
|
+
manifestPath = jsonFilePath;
|
|
22
|
+
} else {
|
|
23
|
+
throw new Error(`Could not find project manifest under dir ${file}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const doc = loadFromJsonOrYaml(manifestPath);
|
|
28
|
+
const projectManifest = new SolanaProjectManifestVersioned(doc as VersionedProjectManifest);
|
|
29
|
+
projectManifest.validate();
|
|
30
|
+
return projectManifest;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe('test solana project.yaml', () => {
|
|
34
|
+
it('could get solana project template name from its deployment', () => {
|
|
35
|
+
const manifest = loadSolanaProjectManifest(path.join(projectsDir, 'project_1.0.0.yaml'));
|
|
36
|
+
const deployment = manifest.toDeployment();
|
|
37
|
+
expect(deployment).toContain('name: Pool');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('could get options in template from its deployment', () => {
|
|
41
|
+
const manifest = loadSolanaProjectManifest(path.join(projectsDir, 'project_1.0.0.yaml'));
|
|
42
|
+
const deployment = manifest.toDeployment();
|
|
43
|
+
expect(deployment).toContain('abi: Pool');
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('project.yaml', () => {
|
|
48
|
+
it('can validate project.yaml', () => {
|
|
49
|
+
// TODO this should catch a specific error, the file doesn't currently exist
|
|
50
|
+
throw new Error('Not implemented');
|
|
51
|
+
expect(() => loadSolanaProjectManifest(path.join(projectsDir, 'project_falsy.yaml'))).toThrow();
|
|
52
|
+
expect(() => loadSolanaProjectManifest(path.join(projectsDir, 'project_falsy_array.yaml'))).toThrow();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('can fail validation if version not supported', () => {
|
|
56
|
+
// TODO this should catch a specific error, the file doesn't currently exist
|
|
57
|
+
throw new Error('Not implemented');
|
|
58
|
+
expect(() => loadSolanaProjectManifest(path.join(projectsDir, 'project_invalid_version.yaml'))).toThrow('');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('can validate a v1.0.0 project.yaml with templates', () => {
|
|
62
|
+
expect(() => loadSolanaProjectManifest(path.join(projectsDir, 'project_1.0.0.yaml'))).not.toThrow();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('get v1.0.0 deployment mapping filter', () => {
|
|
66
|
+
const manifestVersioned = loadSolanaProjectManifest(path.join(projectsDir, 'project_1.0.0.yaml'));
|
|
67
|
+
|
|
68
|
+
const deployment = manifestVersioned.asV1_0_0.deployment;
|
|
69
|
+
const filter = deployment.dataSources[0].mapping.handlers[0].filter;
|
|
70
|
+
const deploymentString = manifestVersioned.toDeployment();
|
|
71
|
+
expect(filter).not.toBeNull();
|
|
72
|
+
expect(deploymentString).toContain('Transfer (address from, address to, uint256 tokenId)');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('can convert genesis hash in v1.0.0 to chainId in deployment', () => {
|
|
76
|
+
const deployment = loadSolanaProjectManifest(path.join(projectsDir, 'project_1.0.0.yaml')).asV1_0_0.deployment;
|
|
77
|
+
expect(deployment.network.chainId).not.toBeNull();
|
|
78
|
+
console.log(deployment.network.chainId);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it.skip('can get chainId for deployment', () => {
|
|
82
|
+
const deployment = loadSolanaProjectManifest(path.join(projectsDir, 'project_1.0.0_chainId.yaml')).asV1_0_0
|
|
83
|
+
.deployment;
|
|
84
|
+
expect(deployment.network.chainId).toBe('moonbeamChainId');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('can validate deployment runner versions', () => {
|
|
88
|
+
const deployment = new DeploymentV1_0_0();
|
|
89
|
+
const nodeImp = new SolanaRunnerNodeImpl();
|
|
90
|
+
const queryImp = new RunnerQueryBaseModel();
|
|
91
|
+
deployment.specVersion = '1.0.0';
|
|
92
|
+
deployment.runner = new SolanaRunnerSpecsImpl();
|
|
93
|
+
|
|
94
|
+
nodeImp.name = '@subql/node-solana';
|
|
95
|
+
nodeImp.version = '*';
|
|
96
|
+
deployment.runner.node = nodeImp;
|
|
97
|
+
|
|
98
|
+
queryImp.name = '@subql/query';
|
|
99
|
+
queryImp.version = '0.213.1';
|
|
100
|
+
|
|
101
|
+
deployment.runner.query = queryImp;
|
|
102
|
+
|
|
103
|
+
const errors = validateSync(deployment.runner, {whitelist: true, forbidNonWhitelisted: true});
|
|
104
|
+
expect(errors.length).toBe(0);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('can validate a v1.0.0 project.yaml with unsupported runner node', () => {
|
|
108
|
+
expect(() => loadSolanaProjectManifest(path.join(projectsDir, 'project_1.0.0_bad_runner.yaml'))).toThrow();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
//TODO, pre-release should be excluded
|
|
112
|
+
it.skip('can throw error with unsupported runner version', () => {
|
|
113
|
+
expect(() => loadSolanaProjectManifest(path.join(projectsDir, 'project_1.0.0_bad_runner_version.yaml'))).toThrow();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('can validate a v1.0.0 project.yaml runner and datasource mismatches', () => {
|
|
117
|
+
expect(() => loadSolanaProjectManifest(path.join(projectsDir, 'project_1.0.0_runner_ds_mismatch.yaml'))).toThrow();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('can fail validation if custom ds missing processor', () => {
|
|
121
|
+
expect(() => loadSolanaProjectManifest(path.join(projectsDir, 'project_0.2.0_invalid_custom_ds.yaml'))).toThrow();
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
3
|
+
|
|
4
|
+
import { IProjectManifest } from '@subql/types-core';
|
|
5
|
+
import { SubqlDatasource } from '@subql/types-solana';
|
|
6
|
+
|
|
7
|
+
// All of these used to be redefined in this file, re-exporting for simplicity
|
|
8
|
+
export {
|
|
9
|
+
SubqlRuntimeHandler,
|
|
10
|
+
SubqlCustomHandler,
|
|
11
|
+
SubqlHandler,
|
|
12
|
+
SubqlDatasource as SubqlSolanaDataSource,
|
|
13
|
+
SubqlCustomDatasource as SubqlSolanaCustomDataSource,
|
|
14
|
+
SubqlDatasourceProcessor,
|
|
15
|
+
SubqlHandlerFilter,
|
|
16
|
+
} from '@subql/types-solana';
|
|
17
|
+
|
|
18
|
+
export type ISolanaProjectManifest = IProjectManifest<SubqlDatasource>;
|
|
19
|
+
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
SecondLayerHandlerProcessor,
|
|
6
|
+
SubqlCustomDatasource,
|
|
7
|
+
SubqlDatasource,
|
|
8
|
+
SolanaDatasourceKind,
|
|
9
|
+
SolanaHandlerKind,
|
|
10
|
+
SubqlRuntimeDatasource,
|
|
11
|
+
SecondLayerHandlerProcessorArray,
|
|
12
|
+
SubqlCustomHandler,
|
|
13
|
+
SubqlMapping,
|
|
14
|
+
} from '@subql/types-solana';
|
|
15
|
+
|
|
16
|
+
type DefaultFilter = Record<string, unknown>;
|
|
17
|
+
|
|
18
|
+
export function isBlockHandlerProcessor<E>(
|
|
19
|
+
hp: SecondLayerHandlerProcessorArray<SolanaHandlerKind, DefaultFilter, unknown>
|
|
20
|
+
): hp is SecondLayerHandlerProcessor<SolanaHandlerKind.Block, DefaultFilter, E> {
|
|
21
|
+
return hp.baseHandlerKind === SolanaHandlerKind.Block;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function isTransactionHandlerProcessor<E>(
|
|
25
|
+
hp: SecondLayerHandlerProcessorArray<SolanaHandlerKind, DefaultFilter, unknown>
|
|
26
|
+
): hp is SecondLayerHandlerProcessor<SolanaHandlerKind.Transaction, DefaultFilter, E> {
|
|
27
|
+
return hp.baseHandlerKind === SolanaHandlerKind.Transaction;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function isInstructionHandlerProcessor<E>(
|
|
31
|
+
hp: SecondLayerHandlerProcessorArray<SolanaHandlerKind, DefaultFilter, unknown>
|
|
32
|
+
): hp is SecondLayerHandlerProcessor<SolanaHandlerKind.Instruction, DefaultFilter, E> {
|
|
33
|
+
return hp.baseHandlerKind === SolanaHandlerKind.Instruction;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function isLogHandlerProcessor<E>(
|
|
37
|
+
hp: SecondLayerHandlerProcessorArray<SolanaHandlerKind, DefaultFilter, unknown>
|
|
38
|
+
): hp is SecondLayerHandlerProcessor<SolanaHandlerKind.Log, DefaultFilter, E> {
|
|
39
|
+
return hp.baseHandlerKind === SolanaHandlerKind.Log;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function isCustomDs<F extends SubqlMapping<SubqlCustomHandler>>(
|
|
43
|
+
ds: SubqlDatasource
|
|
44
|
+
): ds is SubqlCustomDatasource<string, F> {
|
|
45
|
+
return ds.kind !== SolanaDatasourceKind.Runtime && !!(ds as SubqlCustomDatasource<string>).processor;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function isRuntimeDs(ds: SubqlDatasource): ds is SubqlRuntimeDatasource {
|
|
49
|
+
return ds.kind === SolanaDatasourceKind.Runtime;
|
|
50
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Copyright 2020-2025 SubQuery Pte Ltd authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
3
|
+
|
|
4
|
+
import { plainToClass } from 'class-transformer';
|
|
5
|
+
import { ISolanaProjectManifest, SubqlSolanaDataSource } from '../types';
|
|
6
|
+
import { ProjectManifestV1_0_0Impl } from './v1_0_0';
|
|
7
|
+
export type VersionedProjectManifest = { specVersion: string };
|
|
8
|
+
|
|
9
|
+
const SOLANA_SUPPORTED_VERSIONS = {
|
|
10
|
+
'1.0.0': ProjectManifestV1_0_0Impl,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type Versions = keyof typeof SOLANA_SUPPORTED_VERSIONS;
|
|
14
|
+
|
|
15
|
+
type ProjectManifestImpls = InstanceType<(typeof SOLANA_SUPPORTED_VERSIONS)[Versions]>;
|
|
16
|
+
|
|
17
|
+
export function manifestIsV1_0_0(manifest: ISolanaProjectManifest): manifest is ProjectManifestV1_0_0Impl {
|
|
18
|
+
return manifest.specVersion === '1.0.0';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class SolanaProjectManifestVersioned implements ISolanaProjectManifest {
|
|
22
|
+
private _impl: ProjectManifestImpls;
|
|
23
|
+
|
|
24
|
+
constructor(projectManifest: VersionedProjectManifest) {
|
|
25
|
+
const klass = SOLANA_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 {
|
|
45
|
+
return this._impl.deployment.toYaml();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
validate(): void {
|
|
49
|
+
return this._impl.validate();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get dataSources(): SubqlSolanaDataSource[] {
|
|
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 | undefined {
|
|
65
|
+
return this._impl.description;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get repository(): string | undefined {
|
|
69
|
+
return this._impl.repository;
|
|
70
|
+
}
|
|
71
|
+
}
|