Move PortableRegistry alongside metadata (#4172)

This commit is contained in:
Jaco
2021-11-05 17:47:02 +02:00
committed by GitHub
parent ed384666ee
commit d98d4d6908
23 changed files with 34 additions and 37 deletions
+1
View File
@@ -5,6 +5,7 @@
Changes:
- Convert metadata & API to use lazy decoration
- Move PortableRegistry location inside `@polkadot/types/metadata`
## 6.6.1 Nov 1, 2021
+2 -2
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Bytes } from '@polkadot/types';
import type { Bytes, PortableRegistry } from '@polkadot/types';
import type { ChainProperties, ContractConstructorSpec, ContractEventSpec, ContractMessageParamSpec, ContractMessageSpec, ContractMetadataLatest, ContractProjectInfo } from '@polkadot/types/interfaces';
import type { AnyJson, Codec, Registry } from '@polkadot/types/types';
import type { AbiConstructor, AbiEvent, AbiMessage, AbiParam, DecodedEvent, DecodedMessage } from '../types';
@@ -45,7 +45,7 @@ function parseJson (json: AnyJson, chainProperties?: ChainProperties): [AnyJson,
const latest = metadata.isV0
? toLatest(registry, metadata.asV0)
: metadata.asV1;
const lookup = registry.createType('PortableRegistry', { types: latest.types });
const lookup = registry.createType<PortableRegistry>('PortableRegistry', { types: latest.types });
// attach the lookup to the registry - now the types are known
registry.setLookup(lookup);
+2 -1
View File
@@ -1,7 +1,8 @@
// Copyright 2017-2021 @polkadot/typegen authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { PortableRegistry, PortableType, SiLookupTypeId, SiPath, SiTypeParameter } from '@polkadot/types/interfaces';
import type { PortableType, SiLookupTypeId, SiPath, SiTypeParameter } from '@polkadot/types/interfaces';
import type { PortableRegistry } from '@polkadot/types/metadata';
import type { TypeDef } from '@polkadot/types/types';
import Handlebars from 'handlebars';
+2 -2
View File
@@ -1,8 +1,8 @@
// Copyright 2017-2021 @polkadot/typegen authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { PortableRegistry, StorageEntryMetadataLatest } from '@polkadot/types/interfaces/metadata';
import type { Metadata } from '@polkadot/types/metadata/Metadata';
import type { StorageEntryMetadataLatest } from '@polkadot/types/interfaces';
import type { Metadata, PortableRegistry } from '@polkadot/types/metadata';
import type { Registry } from '@polkadot/types/types';
import type { ExtraTypes } from './types';
+2 -1
View File
@@ -1,7 +1,8 @@
// Copyright 2017-2021 @polkadot/typegen authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { MetadataLatest, PortableRegistry, SiLookupTypeId } from '@polkadot/types/interfaces';
import type { MetadataLatest, SiLookupTypeId } from '@polkadot/types/interfaces';
import type { PortableRegistry } from '@polkadot/types/metadata';
import type { Codec, DefinitionRpcParam } from '@polkadot/types/types';
import fs from 'fs';
+1 -1
View File
@@ -44,7 +44,7 @@ export function setImports (allDefs: Record<string, ModuleTypes>, imports: TypeI
// do nothing
} else if (['AnyNumber', 'CallFunction', 'Codec', 'IExtrinsic', 'ITuple'].includes(type)) {
typesTypes[type] = true;
} else if (type === 'Metadata') {
} else if (['Metadata', 'PortableRegistry'].includes(type)) {
metadataTypes[type] = true;
} else if ((codecClasses as Record<string, unknown>)[type]) {
codecTypes[type] = true;
+1 -3
View File
@@ -32,7 +32,7 @@ import type { AuthorityIndex, AuthorityList, AuthoritySet, AuthoritySetChange, A
import type { IdentityFields, IdentityInfo, IdentityInfoAdditional, IdentityInfoTo198, IdentityJudgement, RegistrarIndex, RegistrarInfo, Registration, RegistrationJudgement, RegistrationTo198 } from '@polkadot/types/interfaces/identity';
import type { AuthIndex, AuthoritySignature, Heartbeat, HeartbeatTo244, OpaqueMultiaddr, OpaqueNetworkState, OpaquePeerId } from '@polkadot/types/interfaces/imOnline';
import type { CallIndex, LotteryConfig } from '@polkadot/types/interfaces/lottery';
import type { ErrorMetadataLatest, ErrorMetadataV10, ErrorMetadataV11, ErrorMetadataV12, ErrorMetadataV13, ErrorMetadataV14, ErrorMetadataV9, EventMetadataLatest, EventMetadataV10, EventMetadataV11, EventMetadataV12, EventMetadataV13, EventMetadataV14, EventMetadataV9, ExtrinsicMetadataLatest, ExtrinsicMetadataV11, ExtrinsicMetadataV12, ExtrinsicMetadataV13, ExtrinsicMetadataV14, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV10, FunctionArgumentMetadataV11, FunctionArgumentMetadataV12, FunctionArgumentMetadataV13, FunctionArgumentMetadataV14, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV10, FunctionMetadataV11, FunctionMetadataV12, FunctionMetadataV13, FunctionMetadataV14, FunctionMetadataV9, MetadataAll, MetadataLatest, MetadataV10, MetadataV11, MetadataV12, MetadataV13, MetadataV14, MetadataV9, ModuleConstantMetadataV10, ModuleConstantMetadataV11, ModuleConstantMetadataV12, ModuleConstantMetadataV13, ModuleConstantMetadataV9, ModuleMetadataV10, ModuleMetadataV11, ModuleMetadataV12, ModuleMetadataV13, ModuleMetadataV9, PalletCallMetadataLatest, PalletCallMetadataV14, PalletConstantMetadataLatest, PalletConstantMetadataV14, PalletErrorMetadataLatest, PalletErrorMetadataV14, PalletEventMetadataLatest, PalletEventMetadataV14, PalletMetadataLatest, PalletMetadataV14, PalletStorageMetadataLatest, PalletStorageMetadataV14, PortableRegistry, PortableRegistryV14, PortableType, PortableTypeV14, SignedExtensionMetadataLatest, SignedExtensionMetadataV14, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV11, StorageEntryMetadataV12, StorageEntryMetadataV13, StorageEntryMetadataV14, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV11, StorageEntryModifierV12, StorageEntryModifierV13, StorageEntryModifierV14, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV11, StorageEntryTypeV12, StorageEntryTypeV13, StorageEntryTypeV14, StorageEntryTypeV9, StorageHasher, StorageHasherV10, StorageHasherV11, StorageHasherV12, StorageHasherV13, StorageHasherV14, StorageHasherV9, StorageMetadataV10, StorageMetadataV11, StorageMetadataV12, StorageMetadataV13, StorageMetadataV9 } from '@polkadot/types/interfaces/metadata';
import type { ErrorMetadataLatest, ErrorMetadataV10, ErrorMetadataV11, ErrorMetadataV12, ErrorMetadataV13, ErrorMetadataV14, ErrorMetadataV9, EventMetadataLatest, EventMetadataV10, EventMetadataV11, EventMetadataV12, EventMetadataV13, EventMetadataV14, EventMetadataV9, ExtrinsicMetadataLatest, ExtrinsicMetadataV11, ExtrinsicMetadataV12, ExtrinsicMetadataV13, ExtrinsicMetadataV14, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV10, FunctionArgumentMetadataV11, FunctionArgumentMetadataV12, FunctionArgumentMetadataV13, FunctionArgumentMetadataV14, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV10, FunctionMetadataV11, FunctionMetadataV12, FunctionMetadataV13, FunctionMetadataV14, FunctionMetadataV9, MetadataAll, MetadataLatest, MetadataV10, MetadataV11, MetadataV12, MetadataV13, MetadataV14, MetadataV9, ModuleConstantMetadataV10, ModuleConstantMetadataV11, ModuleConstantMetadataV12, ModuleConstantMetadataV13, ModuleConstantMetadataV9, ModuleMetadataV10, ModuleMetadataV11, ModuleMetadataV12, ModuleMetadataV13, ModuleMetadataV9, PalletCallMetadataLatest, PalletCallMetadataV14, PalletConstantMetadataLatest, PalletConstantMetadataV14, PalletErrorMetadataLatest, PalletErrorMetadataV14, PalletEventMetadataLatest, PalletEventMetadataV14, PalletMetadataLatest, PalletMetadataV14, PalletStorageMetadataLatest, PalletStorageMetadataV14, PortableType, PortableTypeV14, SignedExtensionMetadataLatest, SignedExtensionMetadataV14, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV11, StorageEntryMetadataV12, StorageEntryMetadataV13, StorageEntryMetadataV14, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV11, StorageEntryModifierV12, StorageEntryModifierV13, StorageEntryModifierV14, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV11, StorageEntryTypeV12, StorageEntryTypeV13, StorageEntryTypeV14, StorageEntryTypeV9, StorageHasher, StorageHasherV10, StorageHasherV11, StorageHasherV12, StorageHasherV13, StorageHasherV14, StorageHasherV9, StorageMetadataV10, StorageMetadataV11, StorageMetadataV12, StorageMetadataV13, StorageMetadataV9 } from '@polkadot/types/interfaces/metadata';
import type { MmrLeafProof } from '@polkadot/types/interfaces/mmr';
import type { StorageKind } from '@polkadot/types/interfaces/offchain';
import type { DeferredOffenceOf, Kind, OffenceDetails, Offender, OpaqueTimeSlot, ReportIdOf, Reporter } from '@polkadot/types/interfaces/offences';
@@ -698,8 +698,6 @@ declare module '@polkadot/types/types/registry' {
Phase: Phase;
PhragmenScore: PhragmenScore;
Points: Points;
PortableRegistry: PortableRegistry;
PortableRegistryV14: PortableRegistryV14;
PortableType: PortableType;
PortableTypeV14: PortableTypeV14;
Precommits: Precommits;
+1 -1
View File
@@ -10,7 +10,7 @@ export * from './index.types';
export * from './metadata';
export { TypeDefInfo } from './create/types';
export { convertSiV0toV1 } from './generic/PortableRegistry';
export { convertSiV0toV1 } from './metadata/PortableRegistry';
export { packageInfo } from './packageInfo';
export { unwrapStorageType } from './primitive/StorageKey';
+2 -1
View File
@@ -1,7 +1,8 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { PortableRegistry, SiLookupTypeId, SiVariant } from '../interfaces';
import type { SiLookupTypeId, SiVariant } from '../interfaces';
import type { PortableRegistry } from '../metadata';
import { lazyMethod } from '@polkadot/util';
+3 -2
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { ExtDef } from '../extrinsic/signedExtensions/types';
import type { ChainProperties, CodecHash, DispatchErrorModule, Hash, MetadataLatest, PortableRegistry, SiField, SiLookupTypeId, SiVariant } from '../interfaces/types';
import type { ChainProperties, CodecHash, DispatchErrorModule, Hash, MetadataLatest, SiField, SiLookupTypeId, SiVariant } from '../interfaces/types';
import type { CallFunction, Codec, CodecHasher, Constructor, DetectCodec, DetectConstructor, RegisteredTypes, Registry, RegistryError, RegistryTypes } from '../types';
import type { CreateOptions } from './types';
@@ -19,6 +19,7 @@ import * as definitions from '../interfaces/definitions';
import { decorateConstants, filterCallsSome, filterEventsSome } from '../metadata/decorate';
import { createCallFunction } from '../metadata/decorate/extrinsics';
import { Metadata } from '../metadata/Metadata';
import { PortableRegistry } from '../metadata/PortableRegistry';
import { createClass } from './createClass';
import { createTypeUnsafe } from './createType';
import { lazyVariants } from './lazy';
@@ -168,7 +169,7 @@ export class TypeRegistry implements Registry {
public createdAtHash?: Hash;
constructor (createdAtHash?: Hash | Uint8Array | string) {
this.#knownDefaults = objectSpread({ Json, Metadata, Raw }, baseTypes);
this.#knownDefaults = objectSpread({ Json, Metadata, PortableRegistry, Raw }, baseTypes);
this.#knownDefinitions = definitions as unknown as Record<string, { types: RegistryTypes }>;
this.init();
-1
View File
@@ -12,5 +12,4 @@ export { GenericConsensusEngineId } from './ConsensusEngineId';
export { GenericEvent, GenericEventData } from './Event';
export { GenericLookupSource } from './LookupSource';
export { GenericMultiAddress, GenericMultiAddress as GenericAddress } from './MultiAddress';
export { GenericPortableRegistry } from './PortableRegistry';
export { GenericVote } from './Vote';
@@ -21,10 +21,6 @@ export { AllHashers };
export default {
rpc: {},
types: objectSpread({}, v9, v10, v11, v12, v13, v14, {
// registry mapping to latest
PortableRegistry: 'PortableRegistryV14',
PortableType: 'PortableTypeV14',
// latest mappings
ErrorMetadataLatest: 'ErrorMetadataV14',
EventMetadataLatest: 'EventMetadataV14',
@@ -38,6 +34,7 @@ export default {
PalletEventMetadataLatest: 'PalletEventMetadataV14',
PalletMetadataLatest: 'PalletMetadataV14',
PalletStorageMetadataLatest: 'PalletStorageMetadataV14',
PortableType: 'PortableTypeV14',
SignedExtensionMetadataLatest: 'SignedExtensionMetadataV14',
StorageEntryMetadataLatest: 'StorageEntryMetadataV14',
StorageEntryModifierLatest: 'StorageEntryModifierV14',
@@ -1,7 +1,7 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import type { Bytes, Enum, GenericPortableRegistry, Option, Struct, Text, Type, Vec, bool, u8 } from '@polkadot/types';
import type { Bytes, Enum, Option, PortableRegistry, Struct, Text, Type, Vec, bool, u8 } from '@polkadot/types';
import type { Si1Field, Si1LookupTypeId, Si1Type, SiLookupTypeId } from '@polkadot/types/interfaces/scaleInfo';
/** @name ErrorMetadataLatest */
@@ -331,12 +331,6 @@ export interface PalletStorageMetadataV14 extends Struct {
readonly items: Vec<StorageEntryMetadataV14>;
}
/** @name PortableRegistry */
export interface PortableRegistry extends PortableRegistryV14 {}
/** @name PortableRegistryV14 */
export interface PortableRegistryV14 extends GenericPortableRegistry {}
/** @name PortableType */
export interface PortableType extends PortableTypeV14 {}
@@ -12,7 +12,6 @@ import { Si1Variant } from '../scaleInfo/v1';
export const v14: DefinitionsTypes = {
// registry
PortableRegistryV14: 'GenericPortableRegistry',
PortableTypeV14: {
id: 'Si1LookupTypeId',
type: 'Si1Type'
@@ -98,7 +98,7 @@ function getPrimitivePath (path: SiPath): string | null {
: null;
}
function removeDuplicateNames (lookup: GenericPortableRegistry, names: [number, string | null, SiTypeParameter[]][]): [number, string][] {
function removeDuplicateNames (lookup: PortableRegistry, names: [number, string | null, SiTypeParameter[]][]): [number, string][] {
const rewrite: Record<number, string> = {};
return names
@@ -219,7 +219,7 @@ function extractName (types: PortableType[], { id, type: { params, path } }: Por
return [lookupIndex, typeName, params];
}
function extractNames (lookup: GenericPortableRegistry, types: PortableType[]): Record<number, string> {
function extractNames (lookup: PortableRegistry, types: PortableType[]): Record<number, string> {
const dedup = removeDuplicateNames(lookup, types.map((t) =>
extractName(types, t)
));
@@ -253,7 +253,7 @@ function extractTypeMap (types: PortableType[]): Record<number, PortableType> {
return result;
}
export class GenericPortableRegistry extends Struct {
export class PortableRegistry extends Struct {
#names: Record<number, string>;
#typeDefs: Record<number, TypeDef> = {};
#types: Record<number, PortableType>;
@@ -1,5 +1,5 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { GenericPortableRegistry } from './PortableRegistry';
export { PortableRegistry } from './PortableRegistry';
export { toV1 as convertSiV0toV1 } from './toV1';
@@ -1,7 +1,8 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { DispatchErrorModule, MetadataLatest, PortableRegistry, SiField, SiVariant } from '../../../interfaces';
import type { DispatchErrorModule, MetadataLatest, SiField, SiVariant } from '../../../interfaces';
import type { PortableRegistry } from '../../../metadata';
import type { Text, u8 } from '../../../primitive';
import type { Registry } from '../../../types';
import type { Errors, IsError } from '../types';
@@ -1,7 +1,8 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { MetadataLatest, PalletMetadataLatest, PortableRegistry, SiVariant } from '../../../interfaces';
import type { MetadataLatest, PalletMetadataLatest, SiVariant } from '../../../interfaces';
import type { PortableRegistry } from '../../../metadata';
import type { CallFunction, Registry } from '../../../types';
import type { Extrinsics } from '../types';
+1
View File
@@ -2,4 +2,5 @@
// SPDX-License-Identifier: Apache-2.0
export { Metadata } from './Metadata';
export { PortableRegistry } from './PortableRegistry';
export { decorateConstants, decorateExtrinsics, decorateStorage, expandMetadata } from './decorate';
@@ -1,7 +1,8 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { PortableRegistry, SiLookupTypeId } from '../../interfaces';
import type { SiLookupTypeId } from '../../interfaces';
import type { PortableRegistry } from '../../metadata';
export function getSiName (lookup: PortableRegistry, type: SiLookupTypeId): string {
const typeDef = lookup.getTypeDef(type);
@@ -1,7 +1,8 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { MetadataLatest, PortableRegistry, SiLookupTypeId } from '../../interfaces';
import type { MetadataLatest, SiLookupTypeId } from '../../interfaces';
import type { PortableRegistry } from '../../metadata';
import type { Registry } from '../../types';
import { flattenUniq } from './flattenUniq';
+2 -2
View File
@@ -5,11 +5,11 @@ import type { Observable } from 'rxjs';
import type { BN } from '@polkadot/util';
import type { CreateOptions } from '../create/types';
import type { ExtDef } from '../extrinsic/signedExtensions/types';
import type { MetadataLatest, PortableRegistry } from '../interfaces/metadata';
import type { MetadataLatest } from '../interfaces/metadata';
import type { CodecHash, Hash } from '../interfaces/runtime';
import type { SiField, SiLookupTypeId } from '../interfaces/scaleInfo';
import type { ChainProperties } from '../interfaces/system';
import type { Metadata } from '../metadata';
import type { Metadata, PortableRegistry } from '../metadata';
import type { CallFunction } from './calls';
import type { Codec, Constructor } from './codec';
import type { DefinitionRpc, DefinitionRpcSub } from './definitions';