Skip to content

Commit

Permalink
cosmos modular
Browse files Browse the repository at this point in the history
  • Loading branch information
jiqiang90 committed Jun 24, 2024
1 parent c2f5055 commit feccd59
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 6 deletions.
3 changes: 3 additions & 0 deletions packages/common-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Add alias follow type of `CosmosNetworkModule`. Also add method `networkCliCodegen` include steps of cosmos codegen. (#267)

## [4.4.0] - 2024-06-21
### Changed
- Add default value in model class to follow ES2022 rule (#264)
Expand Down
2 changes: 1 addition & 1 deletion packages/common-cosmos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@protobufs/google": "^0.0.10",
"@protobufs/ibc": "^0.1.0",
"@protobufs/tendermint": "^0.0.10",
"@subql/common": "^3.8.0",
"@subql/common": "^3.9.1-0",
"@subql/types-cosmos": "workspace:*",
"@subql/x-cosmology-telescope": "^1.4.14",
"fs-extra": "^11.1.1",
Expand Down
33 changes: 31 additions & 2 deletions packages/common-cosmos/src/codegen/codegen-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ import fs from 'fs';
import path from 'path';
import cosmwasmCodegen from '@cosmwasm/ts-codegen';
import {makeTempDir} from '@subql/common';
import {CosmosChaintypes, CustomModule, CosmosRuntimeDatasource} from '@subql/types-cosmos';
import {ProjectManifestV1_0_0} from '@subql/types-core/dist/project/versioned/v1_0_0/types';
import {
CosmosChaintypes,
CustomModule,
CosmosRuntimeDatasource,
CosmosProjectManifestV1_0_0,
} from '@subql/types-cosmos';
import telescope from '@subql/x-cosmology-telescope';
import {Data} from 'ejs';
import {copySync} from 'fs-extra';
import {upperFirst} from 'lodash';
import {IDLObject} from 'wasm-ast-types';
import {isRuntimeCosmosDs} from '../project';
import {COSMWASM_OPTS, TELESCOPE_OPTS} from './constants';
import {loadCosmwasmAbis, tmpProtoDir} from './util';
import {loadCosmwasmAbis, tmpProtoDir, validateCosmosManifest} from './util';

const TYPE_ROOT_DIR = 'src/types';

Expand Down Expand Up @@ -273,3 +279,26 @@ export async function generateProto(
fs.rmSync(tmpPath, {recursive: true, force: true});
}
}

export async function networkCliCodegen(
manifest: ProjectManifestV1_0_0[],
projectPath: string,
prepareDirPath: (path: string, recreate: boolean) => Promise<void>,
renderTemplate: (templatePath: string, outputPath: string, templateData: Data) => Promise<void>,
upperFirst: (string?: string) => string,
datasources: CosmosRuntimeDatasource[]
): Promise<void> {
const chainTypes = getChaintypes(manifest);
if (chainTypes.length) {
await generateProto(chainTypes, projectPath, prepareDirPath, renderTemplate, upperFirst, tempProtoDir);
}
await generateCosmwasm(datasources, projectPath, prepareDirPath, upperFirst, renderTemplate);
}

//Deprecated export in future version
export function getChaintypes(manifest: ProjectManifestV1_0_0[]): Map<string, CustomModule>[] {
return manifest
.filter((m) => validateCosmosManifest(m))
.map((m) => (m as CosmosProjectManifestV1_0_0).network.chaintypes)
.filter((value) => value && Object.keys(value).length !== 0);
}
11 changes: 11 additions & 0 deletions packages/common-cosmos/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,14 @@

export * from './codegen';
export * from './project';

import {CosmosNetworkModule} from '@subql/types-cosmos';
import * as c from './codegen';
import * as p from './project';

// This provides a compiled time check to ensure that the correct exports are provided
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _ = {
...p,
...c,
} satisfies CosmosNetworkModule;
5 changes: 5 additions & 0 deletions packages/common-cosmos/src/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ export * from './models';
export * from './types';
export * from './utils';
export * from './versioned';

import {parseCosmosProjectManifest} from './load';
export {parseCosmosProjectManifest as parseProjectManifest};
import {isRuntimeCosmosDs, isCustomCosmosDs} from './utils';
export {isRuntimeCosmosDs as isRuntimeDs, isCustomCosmosDs as isCustomDs};
3 changes: 3 additions & 0 deletions packages/types/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Add type `CosmosNetworkModule` to support cosmos module (#267)

## [3.4.0] - 2024-05-02
### Changed
- Update `@subql/types-core` and use types from there (#254)
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
"@cosmjs/cosmwasm-stargate": "^0.32.3",
"@cosmjs/proto-signing": "^0.32.3",
"@cosmjs/stargate": "^0.32.3",
"@subql/types-core": "^0.7.0"
"@subql/types-core": "^0.8.1-1"
}
}
1 change: 1 addition & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

export * from './interfaces';
export * from './project';
export * from './modular';
17 changes: 17 additions & 0 deletions packages/types/src/modular.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
// SPDX-License-Identifier: GPL-3.0

import {INetworkCommonModule, ProjectManifestV1_0_0} from '@subql/types-core';
import {Data} from 'ejs';
import {CosmosRuntimeDatasource} from './project';

export interface CosmosNetworkModule extends INetworkCommonModule {
networkCliCodegen(
manifest: ProjectManifestV1_0_0[],
projectPath: string,
prepareDirPath: (path: string, recreate: boolean) => Promise<void>,
renderTemplate: (templatePath: string, outputPath: string, templateData: Data) => Promise<void>,
upperFirst: (string?: string) => string,
datasources: CosmosRuntimeDatasource[]
): Promise<void>;
}
31 changes: 29 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6268,7 +6268,7 @@ __metadata:
"@protobufs/google": ^0.0.10
"@protobufs/ibc": ^0.1.0
"@protobufs/tendermint": ^0.0.10
"@subql/common": ^3.8.0
"@subql/common": ^3.9.1-0
"@subql/types-cosmos": "workspace:*"
"@subql/x-cosmology-telescope": ^1.4.14
"@types/bn.js": 4.11.6
Expand Down Expand Up @@ -6309,6 +6309,24 @@ __metadata:
languageName: node
linkType: hard

"@subql/common@npm:^3.9.1-0":
version: 3.9.1-0
resolution: "@subql/common@npm:3.9.1-0"
dependencies:
"@subql/types-core": 0.8.1-1
axios: ^0.28.0
class-transformer: ^0.5.1
class-validator: ^0.14.0
fs-extra: ^10.1.0
ipfs-http-client: 56
js-yaml: ^4.1.0
reflect-metadata: ^0.1.13
semver: ^7.5.2
update-notifier: 5.1.0
checksum: db23560ee596b590c0a497708c55a8f142af085ad61a42b636624f883b8557e30b0f59cfb8b40870899651df02548ccae6a99778cb303c38a66ad31a496cbd9e
languageName: node
linkType: hard

"@subql/node-core@npm:^10.6.0":
version: 10.6.0
resolution: "@subql/node-core@npm:10.6.0"
Expand Down Expand Up @@ -6400,14 +6418,23 @@ __metadata:
languageName: node
linkType: hard

"@subql/types-core@npm:0.8.1-1, @subql/types-core@npm:^0.8.1-1":
version: 0.8.1-1
resolution: "@subql/types-core@npm:0.8.1-1"
dependencies:
package-json-type: ^1.0.3
checksum: 403ddeb1f3902a3256b67523a297cbadc5b964e07f2c94631554f76c7b14d1780445db6164b01f87113e5e21e4b497ae7f1fb1578d7e508405efc535c92ef1a3
languageName: node
linkType: hard

"@subql/types-cosmos@workspace:*, @subql/types-cosmos@workspace:packages/types":
version: 0.0.0-use.local
resolution: "@subql/types-cosmos@workspace:packages/types"
dependencies:
"@cosmjs/cosmwasm-stargate": ^0.32.3
"@cosmjs/proto-signing": ^0.32.3
"@cosmjs/stargate": ^0.32.3
"@subql/types-core": ^0.7.0
"@subql/types-core": ^0.8.1-1
languageName: unknown
linkType: soft

Expand Down

0 comments on commit feccd59

Please sign in to comment.