Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated all chainTypes to chaintypes #180

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/common-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Fixed Missing chainTypes on deployment (#175)

### Changed
- Updated NetworkConfig to use `chaintypes` instead of `chainTypes` (#180)

## [2.5.1] - 2023-09-20
### Changed
- Downgrade `subql/common` due to breaking changes (#176)
Expand Down
16 changes: 8 additions & 8 deletions packages/common-cosmos/src/codegen/codegen-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import telescope from '@cosmology/telescope';
import cosmwasmCodegen from '@cosmwasm/ts-codegen';
import {makeTempDir} from '@subql/common';
import {CosmosChainTypes, CustomModule, SubqlCosmosRuntimeDatasource} from '@subql/types-cosmos';
import {CosmosChaintypes, CustomModule, SubqlCosmosRuntimeDatasource} from '@subql/types-cosmos';
import {Data} from 'ejs';
import {copySync} from 'fs-extra';
import {IDLObject} from 'wasm-ast-types';
Expand All @@ -29,7 +29,7 @@
messageNames: string[]; // all messages
path: string; // should process the file Path and concat with PROTO dir
}
type CosmosChainTypeDataType = CosmosChainTypes | Record<string, CustomModule>;
type CosmosChainTypeDataType = CosmosChaintypes | Record<string, CustomModule>;

interface CosmwasmRenderJobType {
contract: string;
Expand Down Expand Up @@ -144,14 +144,14 @@
}

export function prepareProtobufRenderProps(
chainTypes: (CosmosChainTypeDataType | undefined)[] | undefined,
chaintypes: (CosmosChainTypeDataType | undefined)[] | undefined,
projectPath: string
): ProtobufRenderProps[] {
if (!chainTypes) {
if (!chaintypes) {
return [];
}
return chainTypes.filter(Boolean).flatMap((chainType) => {
return Object.entries(chainType).map(([key, value]) => {
return chaintypes.filter(Boolean).flatMap((chaintype) => {
return Object.entries(chaintype).map(([key, value]) => {
const filePath = path.join(projectPath, value.file);
if (!fs.existsSync(filePath)) {
throw new Error(`Error: chainType ${key}, file ${value.file} does not exist`);
Expand Down Expand Up @@ -193,7 +193,7 @@
}

export async function generateProto(
chainTypes: CosmosChainTypeDataType[],
chaintypes: CosmosChainTypeDataType[],
projectPath: string,
prepareDirPath: (path: string, recreate: boolean) => Promise<void>,
renderTemplate: (templatePath: string, outputPath: string, templateData: Data) => Promise<void>,
Expand All @@ -203,7 +203,7 @@
let tmpPath: string;
try {
tmpPath = await mkdirProto(projectPath);
const protobufRenderProps = prepareProtobufRenderProps(chainTypes, projectPath);
const protobufRenderProps = prepareProtobufRenderProps(chaintypes, projectPath);
const outputPath = path.join(projectPath, PROTO_INTERFACES_ROOT_DIR);
await prepareDirPath(path.join(projectPath, PROTO_INTERFACES_ROOT_DIR), true);

Expand All @@ -223,7 +223,7 @@
}
);
console.log('* Cosmos message wrappers generated !');
} catch (e: any) {

Check warning on line 226 in packages/common-cosmos/src/codegen/codegen-controller.ts

View workflow job for this annotation

GitHub Actions / code-style

Unexpected any. Specify a different type
const errorMessage = e.message.startsWith('Dependency')
? `Please add the missing protobuf file to ./proto directory`
: '';
Expand Down
4 changes: 2 additions & 2 deletions packages/common-cosmos/src/project/project.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@
).toThrow('- property dataSources[0].assets has failed the following constraints: isFileReference');
});
it('Ensure correctness on Cosmos Manifest validate', () => {
const cosmosManifest = loadFromJsonOrYaml(path.join(projectsDir, './protoTest1', 'project.yaml')) as any;

Check warning on line 38 in packages/common-cosmos/src/project/project.spec.ts

View workflow job for this annotation

GitHub Actions / code-style

Unexpected any. Specify a different type
const ethManifest = loadFromJsonOrYaml(path.join(projectsDir, 'project_1.0.0_bad_runner.yaml')) as any;

Check warning on line 39 in packages/common-cosmos/src/project/project.spec.ts

View workflow job for this annotation

GitHub Actions / code-style

Unexpected any. Specify a different type
expect(validateCosmosManifest(cosmosManifest)).toBe(true);
expect(validateCosmosManifest(ethManifest)).toBe(false);
});
it('Validate incorrect chaintypes', () => {
const cosmosManifest = loadFromJsonOrYaml(
path.join(projectsDir, './protoTest1', 'bad-chaintypes-project.yaml')
) as any;

Check warning on line 46 in packages/common-cosmos/src/project/project.spec.ts

View workflow job for this annotation

GitHub Actions / code-style

Unexpected any. Specify a different type
expect(() => parseCosmosProjectManifest(cosmosManifest)).toThrow('failed to parse project.yaml');
});
it('Ensure chainTypes existence on manifest deployment', () => {
it('Ensure chaintypes existence on manifest deployment', () => {
const cosmosManifest = loadFromJsonOrYaml(path.join(projectsDir, './protoTest1', 'project.yaml')) as any;

Check warning on line 50 in packages/common-cosmos/src/project/project.spec.ts

View workflow job for this annotation

GitHub Actions / code-style

Unexpected any. Specify a different type
const manifest = parseCosmosProjectManifest(cosmosManifest);
expect(manifest.asImpl.network.chainTypes.size).toBeGreaterThan(0);
expect(manifest.asImpl.network.chaintypes.size).toBeGreaterThan(0);
});
});
2 changes: 1 addition & 1 deletion packages/common-cosmos/src/project/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ export type CosmosChainType = CustomModule & {

export type CosmosProjectNetConfig = CosmosProjectNetworkConfig & {
chainId: string;
chainTypes: Map<string, CosmosChainType> & {protoRoot: protobuf.Root};
chaintypes: Map<string, CosmosChainType> & {protoRoot: protobuf.Root};
};
8 changes: 4 additions & 4 deletions packages/common-cosmos/src/project/versioned/v1_0_0/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
RuntimeDatasourceTemplate,
CustomDatasourceTemplate,
CosmosProjectManifestV1_0_0,
CosmosChainTypes,
CosmosChaintypes,
} from '@subql/types-cosmos';
import {Transform, TransformFnParams, Type} from 'class-transformer';
import {Equals, IsObject, IsString, ValidateNested, IsOptional, IsArray, IsNotEmpty} from 'class-validator';
Expand Down Expand Up @@ -66,14 +66,14 @@ export class CosmosProjectNetworkDeployment {
@IsOptional()
@Type(() => CosmosCustomModuleImpl)
@ValidateNested({each: true})
chainTypes?: Map<string, CosmosCustomModuleImpl>;
chaintypes?: Map<string, CosmosCustomModuleImpl>;
}

export class CosmosProjectNetwork extends CommonProjectNetworkV1_0_0<CosmosChainTypes> {
export class CosmosProjectNetwork extends CommonProjectNetworkV1_0_0<CosmosChaintypes> {
@Type(() => CosmosCustomModuleImpl)
@IsOptional()
@ValidateNested({each: true})
chainTypes?: Map<string, CosmosCustomModuleImpl>;
chaintypes?: Map<string, CosmosCustomModuleImpl>;
}

export class RuntimeDatasourceTemplateImpl extends CosmosRuntimeDataSourceImpl implements RuntimeDatasourceTemplate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ network:
endpoint:
- https://osmosis.api.onfinality.io/public
dictionary: 'https://api.subquery.network/sq/subquery/cosmos-osmosis-dictionary'
chainTypes:
chaintypes:
osmosis.gamm.v1beta1:
filePath: './proto/osmosis/gamm/v1beta1/tx.proto'
message:
Expand Down
2 changes: 1 addition & 1 deletion packages/common-cosmos/test/protoTest1/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ network:
endpoint:
- https://osmosis.api.onfinality.io/public
dictionary: 'https://api.subquery.network/sq/subquery/cosmos-osmosis-dictionary'
chainTypes:
chaintypes:
osmosis.gamm.v1beta1:
file: './proto/osmosis/gamm/v1beta1/tx.proto'
messages:
Expand Down
2 changes: 2 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ 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
- Updated NetworkConfig to use `chaintypes` instead of `chainTypes` (#180)

## [2.10.3] - 2023-09-20
### Changed
Expand Down
12 changes: 6 additions & 6 deletions packages/node/src/indexer/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class ApiService
}

private async buildRegistry(): Promise<Registry> {
const chainTypes = await this.getChainType(this.project.network);
const chaintypes = await this.getChainType(this.project.network);

const wasmTypes: ReadonlyArray<[string, GeneratedType]> = [
['/cosmwasm.wasm.v1.MsgClearAdmin', MsgClearAdmin],
Expand All @@ -70,8 +70,8 @@ export class ApiService

const registry = new Registry([...defaultRegistryTypes, ...wasmTypes]);

for (const typeurl in chainTypes) {
registry.register(typeurl, chainTypes[typeurl]);
for (const typeurl in chaintypes) {
registry.register(typeurl, chaintypes[typeurl]);
}

return registry;
Expand Down Expand Up @@ -116,19 +116,19 @@ export class ApiService
async getChainType(
network: Partial<CosmosProjectNetConfig>,
): Promise<Record<string, GeneratedType>> {
if (!network.chainTypes) {
if (!network.chaintypes) {
return {};
}

const res: Record<string, GeneratedType> = {};
for (const [
userPackageName,
{ messages, packageName },
] of network.chainTypes) {
] of network.chaintypes) {
const pkgName = packageName ?? userPackageName;
for (const msg of messages) {
logger.info(`Registering chain message type "/${pkgName}.${msg}"`);
const msgObj = network.chainTypes.protoRoot.lookupTypeOrEnum(
const msgObj = network.chaintypes.protoRoot.lookupTypeOrEnum(
`${pkgName}.${msg}`,
);
res[`/${pkgName}.${msg}`] = msgObj;
Expand Down
14 changes: 7 additions & 7 deletions packages/node/src/utils/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@ export async function processNetworkConfig(
}
delete network.genesisHash;

const chainTypes = new Map<string, CosmosChainType>() as Map<
const chaintypes = new Map<string, CosmosChainType>() as Map<
string,
CosmosChainType
> & { protoRoot: protobuf.Root };
if (!network.chainTypes) {
network.chainTypes = chainTypes;
if (!network.chaintypes) {
network.chaintypes = chaintypes;
return network;
}

const protoRoot = new protobuf.Root();
for (const [key, value] of network.chainTypes) {
for (const [key, value] of network.chaintypes) {
const [packageName, proto] = await loadNetworkChainType(reader, value.file);
chainTypes.set(key, { ...value, packageName, proto });
chaintypes.set(key, { ...value, packageName, proto });

protoRoot.add(proto);
}
chainTypes.protoRoot = protoRoot;
network.chainTypes = chainTypes;
chaintypes.protoRoot = protoRoot;
network.chaintypes = chaintypes;
return network;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/types/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Added `cosmwasm` messages types (#168)
### Changed
- Updated NetworkConfig to use `chaintypes` instead of `chainTypes` (#180)

## [2.2.1] - 2023-07-31
### Changed
Expand Down
6 changes: 3 additions & 3 deletions packages/types/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface CustomModule extends FileReference {
messages: string[];
}

export type CosmosChainTypes = Map<string, CustomModule>;
export type CosmosChaintypes = Map<string, CustomModule>;

export type CustomDataSourceAsset = FileReference;

Expand Down Expand Up @@ -93,7 +93,7 @@ export type CosmosNetworkConfig = IProjectNetworkConfig & {
* If filters do not pick up these message types they don't need to be added.
* The key needs to be a unique value, it's good to have the same key as the package but if there are multiple files with the same package then change the name.
* @example
* chainTypes: {
* chaintypes: {
ethermint.evm.v1: {
file: "./proto/ethermint/evm/v1/tx.proto",
messages: [
Expand All @@ -105,7 +105,7 @@ export type CosmosNetworkConfig = IProjectNetworkConfig & {
}
}
* */
chainTypes?: CosmosChainTypes;
chaintypes?: CosmosChaintypes;
};

export type SubqlCosmosBlockFilter = BlockFilter;
Expand Down
Loading