Split @polkadot/types-known (#4342)

* Re-split types-known correctly

* yarn install

* circular :(

* combine?

* It builds... ship it ...
This commit is contained in:
Jaco
2021-12-17 06:38:54 +02:00
committed by GitHub
parent 43203195b4
commit 85e13cc2b1
31 changed files with 89 additions and 79 deletions
+19
View File
@@ -0,0 +1,19 @@
// Copyright 2017-2021 @polkadot/typegen authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable sort-keys */
module.exports = {
alias: {
'^@polkadot/api-derive(.*)': './packages/api-derive/src\\1',
'^@polkadot/api(.*)': './packages/api/src/\\1',
'^@polkadot/rpc-core(.*)': './packages/rpc-core/src\\1',
'^@polkadot/rpc-provider(.*)': './packages/rpc-provider/src\\1',
'^@polkadot/types-codec(.*)': './packages/types-codec/src\\1',
'^@polkadot/types-create(.*)': './packages/types-create/src\\1',
'^@polkadot/types-known(.*)': './packages/types-known/src\\1',
'^@polkadot/types-metadata(.*)': './packages/types-metadata/src\\1',
'^@polkadot/types-support(.*)': './packages/types-support/src\\1',
'^@polkadot/types(.*)': './packages/types/src\\1'
}
};
+1
View File
@@ -4,3 +4,4 @@
export * from './encodeTypes';
export * from './getTypeDef';
export * from './typeSplit';
export * from './xcm';
@@ -1,4 +1,4 @@
// Copyright 2017-2021 @polkadot/types-known authors & contributors
// Copyright 2017-2021 @polkadot/types-create authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { objectSpread } from '@polkadot/util';
+3 -1
View File
@@ -1,6 +1,8 @@
// Copyright 2017-2021 @polkadot/types-known authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { getSpecAlias, getSpecExtensions, getSpecHasher, getSpecRpc, getSpecTypes, getUpgradeVersion } from '@polkadot/types';
export { mapXcmTypes } from '@polkadot/types-create';
export { packageInfo } from './packageInfo';
export * from './util';
@@ -1,7 +1,7 @@
// Copyright 2017-2021 @polkadot/types-known authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { OverrideVersionedType } from '../../types';
import type { OverrideVersionedType } from '@polkadot/types/types';
// Type overrides based on specific nodes
const typesChain: Record<string, OverrideVersionedType[]> = {};
@@ -3,7 +3,7 @@
/* eslint-disable sort-keys */
import type { OverrideVersionedType } from '../../types';
import type { OverrideVersionedType } from '@polkadot/types/types';
import { objectSpread } from '@polkadot/util';
@@ -1,7 +1,7 @@
// Copyright 2017-2021 @polkadot/types-known authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { OverrideVersionedType } from '../../types';
import type { OverrideVersionedType } from '@polkadot/types/types';
import centrifugeChain from './centrifuge-chain';
import kusama from './kusama';
@@ -3,12 +3,11 @@
/* eslint-disable sort-keys */
import type { OverrideVersionedType } from '../../types';
import type { OverrideVersionedType } from '@polkadot/types/types';
import { mapXcmTypes } from '@polkadot/types-create';
import { objectSpread } from '@polkadot/util';
import { mapXcmTypes } from '../xcm';
const sharedTypes = {
CompactAssignments: 'CompactAssignmentsWith24',
RawSolution: 'RawSolutionWith24',
@@ -3,7 +3,7 @@
/* eslint-disable sort-keys */
import type { OverrideVersionedType } from '../../types';
import type { OverrideVersionedType } from '@polkadot/types/types';
const versioned: OverrideVersionedType[] = [
{
@@ -3,7 +3,7 @@
/* eslint-disable sort-keys */
import type { OverrideVersionedType } from '../../types';
import type { OverrideVersionedType } from '@polkadot/types/types';
const versioned: OverrideVersionedType[] = [
{
@@ -3,7 +3,7 @@
/* eslint-disable sort-keys */
import type { OverrideVersionedType } from '../../types';
import type { OverrideVersionedType } from '@polkadot/types/types';
import { objectSpread } from '@polkadot/util';
@@ -3,12 +3,11 @@
/* eslint-disable sort-keys */
import type { OverrideVersionedType } from '../../types';
import type { OverrideVersionedType } from '@polkadot/types/types';
import { mapXcmTypes } from '@polkadot/types-create';
import { objectSpread } from '@polkadot/util';
import { mapXcmTypes } from '../xcm';
// structs need to be in order
/* eslint-disable sort-keys */
@@ -3,7 +3,7 @@
/* eslint-disable sort-keys */
import type { OverrideVersionedType } from '../../types';
import type { OverrideVersionedType } from '@polkadot/types/types';
const versioned: OverrideVersionedType[] = [
{
@@ -3,12 +3,11 @@
/* eslint-disable sort-keys */
import type { OverrideVersionedType } from '../../types';
import type { OverrideVersionedType } from '@polkadot/types/types';
import { mapXcmTypes } from '@polkadot/types-create';
import { objectSpread } from '@polkadot/util';
import { mapXcmTypes } from '../xcm';
const sharedTypes = {
TAssetBalance: 'u128',
ProxyType: {
@@ -3,12 +3,11 @@
/* eslint-disable sort-keys */
import type { OverrideVersionedType } from '../../types';
import type { OverrideVersionedType } from '@polkadot/types/types';
import { mapXcmTypes } from '@polkadot/types-create';
import { objectSpread } from '@polkadot/util';
import { mapXcmTypes } from '../xcm';
const sharedTypes = {
// 16 validators
CompactAssignments: 'CompactAssignmentsWith16',
@@ -1,7 +1,7 @@
// Copyright 2017-2021 @polkadot/types-known authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ChainUpgrades } from '../../types';
import type { ChainUpgrades } from '@polkadot/types/types';
import type { ChainUpgradesRaw } from './types';
import { selectableNetworks } from '@polkadot/networks';
@@ -1,22 +1,18 @@
// Copyright 2017-2021 @polkadot/types-known authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
import type { Hash } from '@polkadot/types/interfaces';
import type { ChainUpgradeVersion, CodecHasher, DefinitionRpc, DefinitionRpcSub, OverrideModuleType, OverrideVersionedType, Registry, RegistryTypes } from '@polkadot/types/types';
import type { Text } from '@polkadot/types-codec';
import type { BN } from '@polkadot/util';
import type { ExtDef } from '../extrinsic/signedExtensions/types';
import type { Hash } from '../interfaces';
import type { ChainUpgradeVersion, CodecHasher, DefinitionRpc, DefinitionRpcSub, OverrideModuleType, OverrideVersionedType, Registry, RegistryTypes } from '../types';
import { bnToBn, isNull, isUndefined, objectSpread } from '@polkadot/util';
import typesChain from './chain';
import typesModules from './modules';
import typesSpec from './spec';
import upgrades from './upgrades';
export { knownOrigins } from './knownOrigins';
export { mapXcmTypes } from './xcm';
function withNames <T> (chainName: Text | string, specName: Text | string, fn: (c: string, s: string) => T): T {
return fn(chainName.toString(), specName.toString());
}
@@ -34,16 +30,6 @@ function filterVersions (versions: OverrideVersionedType[] = [], specVersion: nu
);
}
/**
* @description Get types for specific modules (metadata override)
*/
export function getModuleTypes ({ knownTypes }: Registry, section: string): OverrideModuleType {
return objectSpread({},
typesModules[section],
knownTypes.typesAlias?.[section]
);
}
/**
* @description Based on the chain and runtimeVersion, get the applicable signed extensions (ready for registration)
*/
+2 -1
View File
@@ -6,6 +6,7 @@
"rootDir": "./src"
},
"references": [
{ "path": "../types" }
{ "path": "../types" },
{ "path": "../types-create" }
]
}
-1
View File
@@ -7,7 +7,6 @@ import rpcDefinitions from './interfaces/jsonrpc';
export * from './codec';
export * from './create';
export * from './index.types';
export * from './known';
export * from './metadata';
export { TypeDefInfo } from '@polkadot/types-create';
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import { TypeRegistry } from '../create/registry';
import { getModuleTypes } from '.';
import { getAliasTypes } from './alias';
const registry = new TypeRegistry();
@@ -22,25 +22,25 @@ registry.setKnownTypes({
describe('getModuleTypes', (): void => {
it('collects the pre-defined types for contracts', (): void => {
expect(getModuleTypes(registry, 'contracts')).toEqual({
expect(getAliasTypes(registry, 'contracts')).toEqual({
StorageKey: 'ContractStorageKey'
});
});
it('collects the user-defined types for testModule', (): void => {
expect(getModuleTypes(registry, 'testModule')).toEqual({
expect(getAliasTypes(registry, 'testModule')).toEqual({
Proposal: 'TestProposal'
});
});
it('overrides pre-defined with user-defined for treasury', (): void => {
expect(getModuleTypes(registry, 'treasury')).toEqual({
expect(getAliasTypes(registry, 'treasury')).toEqual({
Proposal: 'TreasuryProposals2'
});
});
it('merges pre-defined and user-defined for identity', (): void => {
expect(getModuleTypes(registry, 'identity')).toEqual({
expect(getAliasTypes(registry, 'identity')).toEqual({
Id: 'IdentityId',
Judgement: 'IdentityJudgement'
});
@@ -1,10 +1,12 @@
// Copyright 2017-2021 @polkadot/types-known authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { OverrideModuleType } from '../types';
import type { OverrideModuleType, Registry } from '../types';
import { objectSpread } from '@polkadot/util';
// type overrides for modules (where duplication between modules exist)
const typesModules: Record<string, OverrideModuleType> = {
const typesAlias: Record<string, OverrideModuleType> = {
assets: {
Approval: 'AssetApproval',
ApprovalKey: 'AssetApprovalKey',
@@ -105,4 +107,12 @@ const typesModules: Record<string, OverrideModuleType> = {
}
};
export default typesModules;
/**
* @description Get types for specific modules (metadata override)
*/
export function getAliasTypes ({ knownTypes }: Registry, section: string): OverrideModuleType {
return objectSpread({},
typesAlias[section],
knownTypes.typesAlias?.[section]
);
}
@@ -24,6 +24,27 @@ const numberTypes = {
Perquintill: 'UInt<64, Perquintill>'
};
// Since we don't have insight into the origin specification, we can only define what we know about
// in a pure Substrate/Polkadot implementation, any other custom origins won't be handled at all
export const knownOrigins: Record<string, string> = {
//
// (1) Defaults from Substrate
//
Council: 'CollectiveOrigin',
System: 'SystemOrigin',
TechnicalCommittee: 'CollectiveOrigin',
//
// (2) Defaults from Polkadot
//
Xcm: 'XcmOrigin',
XcmPallet: 'XcmOrigin',
//
// (3) Defaults from Acala
//
Authority: 'AuthorityOrigin',
GeneralCouncil: 'CollectiveOrigin'
};
export default {
rpc: {},
types: objectSpread({}, numberTypes, {
@@ -6,9 +6,9 @@
import type { Definitions } from '../../types';
import { mapXcmTypes } from '@polkadot/types-create';
import { objectSpread } from '@polkadot/util';
import { mapXcmTypes } from '../../known';
import { v0 } from './v0';
import { v1 } from './v1';
import { v2 } from './v2';
-26
View File
@@ -1,26 +0,0 @@
// Copyright 2017-2021 @polkadot/types-known authors & contributors
// SPDX-License-Identifier: Apache-2.0
// We want predictive ordering (manually managed)
/* eslint-disable sort-keys */
// Since we don't have insight into the origin specification, we can only define what we know about
// in a pure Substrate/Polkadot implementation, any other custom origins won't be handled at all
export const knownOrigins: Record<string, string> = {
//
// (1) Defaults from Substrate
//
Council: 'CollectiveOrigin',
System: 'SystemOrigin',
TechnicalCommittee: 'CollectiveOrigin',
//
// (2) Defaults from Polkadot
//
Xcm: 'XcmOrigin',
XcmPallet: 'XcmOrigin',
//
// (3) Defaults from Acala
//
Authority: 'AuthorityOrigin',
GeneralCouncil: 'CollectiveOrigin'
};
+3 -2
View File
@@ -9,7 +9,8 @@ import type { OverrideModuleType, Registry } from '../../types';
import { stringCamelCase } from '@polkadot/util';
import { getModuleTypes, knownOrigins } from '../../known';
import { getAliasTypes } from '../../interfaces/alias';
import { knownOrigins } from '../../interfaces/runtime/definitions';
interface MapDef {
hashers: StorageHasherV13[];
@@ -289,7 +290,7 @@ function convertExtrinsic (registry: CodecRegistry, { signedExtensions, version
/** @internal */
function createPallet (compatTypes: TypeSpec[], registry: CodecRegistry, mod: ModuleMetadataV13, { calls, constants, errors, events, storage }: { calls: FunctionMetadataV13[] | null, constants: ModuleConstantMetadataV13[], errors: ErrorMetadataV13[] | null, events: EventMetadataV13[] | null, storage: StorageMetadataV13 | null }): PalletMetadataV14 {
const sectionTypes = getModuleTypes(registry as Registry, stringCamelCase(mod.name));
const sectionTypes = getAliasTypes(registry as Registry, stringCamelCase(mod.name));
return registry.createTypeUnsafe('PalletMetadataV14', [{
calls: calls && convertCalls(compatTypes, registry, mod.name, calls, sectionTypes),
+1 -1
View File
@@ -25,7 +25,7 @@ function expand (prefix, all) {
const entries = [
'api-derive',
...expand('rpc', ['core', 'provider']),
...expand('types', ['codec', 'create', 'known'])
...expand('types', ['codec', 'create', 'helpers', 'known'])
].reduce((all, p) => ({
...all,
[`@polkadot/${p}`]: path.resolve(process.cwd(), `packages/${p}/build/bundle.js`)