Skip to content

Commit

Permalink
Sync @subql dependencies (#130)
Browse files Browse the repository at this point in the history
* Update @subql deps

* Apply sync code changes, enable strict TS, endpoint configs

* Move function to use single api instance

* Fix filtering issue with undefined filter options

---------

Co-authored-by: stwiname <[email protected]>
  • Loading branch information
stwiname and stwiname authored Aug 7, 2024
1 parent c08dce8 commit 742cf0f
Show file tree
Hide file tree
Showing 42 changed files with 453 additions and 1,142 deletions.
5 changes: 5 additions & 0 deletions packages/common-algorand/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Removed
- `apiKey` option from network config, please use endpoint config and specify the `X-Indexer-API-Token` header instead (#130)

### Added
- Suport for network endpoint config providing the ability to set headers (#130)

## [4.0.0] - 2024-07-03
### Added
Expand Down
2 changes: 1 addition & 1 deletion packages/common-algorand/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"main": "dist/index.js",
"license": "GPL-3.0",
"dependencies": {
"@subql/common": "^4.0.0",
"@subql/common": "^5.0.0",
"@subql/types-algorand": "workspace:*"
},
"peerDependencies": {
Expand Down
34 changes: 17 additions & 17 deletions packages/common-algorand/src/project/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ export class TransactionFilter implements AlgorandTransactionFilter {

export class BlockHandler implements AlgorandBlockHandler {
@IsEnum(AlgorandHandlerKind, {groups: [AlgorandHandlerKind.Block]})
kind: AlgorandHandlerKind.Block;
kind!: AlgorandHandlerKind.Block;

@IsString()
handler: string;
handler!: string;

@IsOptional()
@ValidateNested()
Expand All @@ -113,18 +113,18 @@ export class TransactionHandler implements AlgorandTransactionHandler {
filter?: AlgorandTransactionFilter;

@IsEnum(AlgorandHandlerKind, {groups: [AlgorandHandlerKind.Block]})
kind: AlgorandHandlerKind.Transaction;
kind!: AlgorandHandlerKind.Transaction;

@IsString()
handler: string;
handler!: string;
}

export class CustomHandler implements AlgorandCustomHandler {
@IsString()
kind: string;
kind!: string;

@IsString()
handler: string;
handler!: string;

@IsObject()
@IsOptional()
Expand All @@ -147,52 +147,52 @@ export class RuntimeMapping implements BaseMapping<AlgorandRuntimeHandler> {
})
@IsArray()
@ValidateNested()
handlers: AlgorandRuntimeHandler[];
handlers!: AlgorandRuntimeHandler[];

@IsString()
file: string;
file!: string;
}

export class CustomMapping implements BaseMapping<AlgorandCustomHandler> {
@IsArray()
@Type(() => CustomHandler)
@ValidateNested()
handlers: CustomHandler[];
handlers!: CustomHandler[];

@IsString()
file: string;
file!: string;
}

export class RuntimeDataSourceBase extends BaseDataSource implements AlgorandRuntimeDataSource {
@IsEnum(AlgorandDataSourceKind, {groups: [AlgorandDataSourceKind.Runtime]})
kind: AlgorandDataSourceKind.Runtime;
kind!: AlgorandDataSourceKind.Runtime;

@Type(() => RuntimeMapping)
@ValidateNested()
mapping: RuntimeMapping;
mapping!: RuntimeMapping;
}

export class FileReferenceImpl implements FileReference {
@IsString()
file: string;
file!: string;
}

export class CustomDataSourceBase<K extends string, M extends CustomMapping, O = any>
extends BaseDataSource
implements AlgorandCustomDataSource<K, M>
{
@IsString()
kind: K;
kind!: K;

@Type(() => CustomMapping)
@ValidateNested()
mapping: M;
mapping!: M;

@Type(() => FileReferenceImpl)
@ValidateNested({each: true})
assets: Map<string, AlgorandCustomDataSourceAsset>;
assets!: Map<string, AlgorandCustomDataSourceAsset>;

@Type(() => ProcessorImpl)
@IsObject()
processor: Processor<O>;
processor!: Processor<O>;
}
1 change: 0 additions & 1 deletion packages/common-algorand/src/project/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ export {
} from '@subql/types-algorand';

export type IAlgorandProjectManifest = IProjectManifest<AlgorandDataSource>;
export type TokenHeader = Record<string, string>;
5 changes: 3 additions & 2 deletions packages/common-algorand/src/project/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-3.0

import {
SecondLayerHandlerProcessorArray,
SecondLayerHandlerProcessor,
AlgorandCustomDataSource,
AlgorandDataSource,
Expand All @@ -11,13 +12,13 @@ import {
} from '@subql/types-algorand';

export function isBlockHandlerProcessor<F extends Record<string, unknown>, E>(
hp: SecondLayerHandlerProcessor<AlgorandHandlerKind, F, unknown>
hp: SecondLayerHandlerProcessorArray<AlgorandHandlerKind, F, unknown>
): hp is SecondLayerHandlerProcessor<AlgorandHandlerKind.Block, F, E> {
return hp.baseHandlerKind === AlgorandHandlerKind.Block;
}

export function isTransactionHandlerProcessor<F extends Record<string, unknown>, E>(
hp: SecondLayerHandlerProcessor<AlgorandHandlerKind, F, unknown>
hp: SecondLayerHandlerProcessorArray<AlgorandHandlerKind, F, unknown>
): hp is SecondLayerHandlerProcessor<AlgorandHandlerKind.Transaction, F, E> {
return hp.baseHandlerKind === AlgorandHandlerKind.Transaction;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class AlgorandProjectManifestVersioned implements IAlgorandProjectManifes
return this._impl as ProjectManifestV1_0_0Impl;
}

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

Expand All @@ -62,11 +62,11 @@ export class AlgorandProjectManifestVersioned implements IAlgorandProjectManifes
return this._impl.specVersion;
}

get description(): string {
get description(): string | undefined {
return this._impl.description;
}

get repository(): string {
get repository(): string | undefined {
return this._impl.repository;
}
}
38 changes: 16 additions & 22 deletions packages/common-algorand/src/project/versioned/v1_0_0/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ import {plainToInstance, Transform, Type} from 'class-transformer';
import {Equals, IsArray, IsObject, IsOptional, IsString, Validate, ValidateNested, validateSync} from 'class-validator';
import yaml from 'js-yaml';
import {CustomDataSourceBase, RuntimeDataSourceBase} from '../../models';
import {TokenHeader} from '../../types';
import {IsStringOrObject} from '../../validation/is-string-or-object.validation';
const ALGORAND_NODE_NAME = `@subql/node-algorand`;

export class AlgorandRunnerNodeImpl implements NodeSpec {
@Equals(ALGORAND_NODE_NAME, {message: `Runner algorand node name incorrect, suppose be '${ALGORAND_NODE_NAME}'`})
name: string;
name!: string;

@IsString()
@Validate(SemverVersionValidator)
Expand All @@ -40,27 +38,23 @@ export class AlgorandRunnerSpecsImpl implements RunnerSpecs {
@IsObject()
@ValidateNested()
@Type(() => AlgorandRunnerNodeImpl)
node: NodeSpec;
node!: NodeSpec;

@IsObject()
@ValidateNested()
@Type(() => RunnerQueryBaseModel)
query: QuerySpec;
query!: QuerySpec;
}

export class ProjectNetworkDeploymentV1_0_0 {
@IsString()
chainId: string;
chainId!: string;
@IsOptional()
@IsArray()
bypassBlocks?: (number | string)[];
}

export class ProjectNetworkV1_0_0 extends CommonProjectNetworkV1_0_0<FileType> {
@IsStringOrObject()
@IsOptional()
apiKey?: string | TokenHeader;
}
export class ProjectNetworkV1_0_0 extends CommonProjectNetworkV1_0_0<FileType> {}

export class AlgorandRuntimeDataSourceV1_0_0Impl extends RuntimeDataSourceBase {
validate(): void {
Expand All @@ -85,15 +79,15 @@ export class RuntimeDataSourceTemplateImpl
implements RuntimeDatasourceTemplate
{
@IsString()
name: string;
name!: string;
}

export class CustomDataSourceTemplateImpl
extends AlgorandCustomDataSourceV1_0_0Impl
implements CustomDatasourceTemplate
{
@IsString()
name: string;
name!: string;
}

export class DeploymentV1_0_0 extends BaseDeploymentV1_0_0 {
Expand All @@ -105,11 +99,11 @@ export class DeploymentV1_0_0 extends BaseDeploymentV1_0_0 {
})
@ValidateNested()
@Type(() => ProjectNetworkDeploymentV1_0_0)
network: ProjectNetworkDeploymentV1_0_0;
network!: ProjectNetworkDeploymentV1_0_0;
@IsObject()
@ValidateNested()
@Type(() => AlgorandRunnerSpecsImpl)
runner: RunnerSpecs;
runner!: RunnerSpecs;

@IsArray()
@ValidateNested()
Expand All @@ -120,7 +114,7 @@ export class DeploymentV1_0_0 extends BaseDeploymentV1_0_0 {
},
keepDiscriminatorProperty: true,
})
dataSources: (AlgorandCustomDataSource | AlgorandRuntimeDataSource)[];
dataSources!: (AlgorandCustomDataSource | AlgorandRuntimeDataSource)[];
@IsOptional()
@IsArray()
@ValidateNested()
Expand All @@ -146,19 +140,19 @@ export class ProjectManifestV1_0_0Impl
specVersion = '1.0.0';

@IsString()
name: string;
name!: string;

@IsString()
version: string;
version!: string;

@IsObject()
@ValidateNested()
@Type(() => ProjectNetworkV1_0_0)
network: ProjectNetworkV1_0_0;
network!: ProjectNetworkV1_0_0;

@ValidateNested()
@Type(() => FileType)
schema: FileType;
schema!: FileType;

@IsArray()
@ValidateNested()
Expand All @@ -169,7 +163,7 @@ export class ProjectManifestV1_0_0Impl
},
keepDiscriminatorProperty: true,
})
dataSources: (AlgorandRuntimeDataSource | AlgorandCustomDataSource)[];
dataSources!: (AlgorandRuntimeDataSource | AlgorandCustomDataSource)[];

@IsOptional()
@IsArray()
Expand All @@ -186,7 +180,7 @@ export class ProjectManifestV1_0_0Impl
@IsObject()
@ValidateNested()
@Type(() => AlgorandRunnerSpecsImpl)
runner: RunnerSpecs;
runner!: RunnerSpecs;

@IsOptional()
@IsObject()
Expand Down
5 changes: 5 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Update dependencies and apply dependent changes (#130)

### Added
- Support for specifying headers for network endpoints (#130)

## [3.12.0] - 2024-07-03
### Changed
Expand Down
1 change: 1 addition & 0 deletions packages/node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ RUN mkdir -p .monitor && \

# Make the user not ROOT
USER 1000
ENV TZ=utc

# Set Entry point and command
ENTRYPOINT ["/sbin/tini", "--", "/usr/local/lib/node_modules/@subql/node-algorand/bin/run"]
Expand Down
10 changes: 5 additions & 5 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
"@nestjs/event-emitter": "^2.0.0",
"@nestjs/platform-express": "^9.4.0",
"@nestjs/schedule": "^3.0.1",
"@subql/common": "^5.0.0",
"@subql/common-algorand": "workspace:*",
"@subql/node-core": "^10.10.0",
"@subql/node-core": "^14.0.0",
"@subql/types-algorand": "workspace:*",
"algosdk": "^2.2.0",
"axios": "^1.3.4",
"algosdk": "^2.8.0",
"lodash": "^4.17.21",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"yargs": "^16.2.0"
},
"devDependencies": {
Expand All @@ -44,7 +43,8 @@
"@types/tar": "^6.1.1",
"@types/yargs": "^16.0.4",
"dotenv": "^15.0.1",
"nodemon": "^2.0.15"
"nodemon": "^2.0.15",
"rimraf": "^6.0.1"
},
"peerDependencies": {
"@subql/utils": "*"
Expand Down
13 changes: 0 additions & 13 deletions packages/node/src/admin/admin.module.ts

This file was deleted.

5 changes: 2 additions & 3 deletions packages/node/src/algorand/algorand.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,16 @@ describe('Algorand RPC', () => {
});

// This is failing since switching from algo explorer api. This is due to a node configuration limit
it.skip('paginate large blocks', async () => {
it('paginate large blocks', async () => {
[app, apiService] = await prepareApiService(
testnetEndpoint,
testnetChainId,
);
const failingBlock = 27739202; // testnet
const passingBlock = 27739200; // testnet
const api = apiService.api;

const paginateSpy = jest.spyOn(api, 'paginatedTransactions');
const result = await api.getBlockByHeight(failingBlock)();
const result = await api.getBlockByHeight(failingBlock);
expect(paginateSpy).toHaveBeenCalledTimes(3);
expect(result.transactions.length).toEqual(13916);
});
Expand Down
Loading

0 comments on commit 742cf0f

Please sign in to comment.