Split base/essential definition handling (#4206)
* Split base/essential definition handling * Adjust
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { ExtDef } from '../extrinsic/signedExtensions/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 { CallFunction, Codec, CodecHasher, Constructor, Definitions, DetectCodec, DetectConstructor, RegisteredTypes, Registry, RegistryError, RegistryTypes } from '../types';
|
||||
import type { CreateOptions, TypeDef } from './types';
|
||||
|
||||
import { assert, assertReturn, BN_ZERO, formatBalance, isFunction, isString, isU8a, lazyMethod, logger, objectSpread, stringCamelCase, stringify } from '@polkadot/util';
|
||||
@@ -158,7 +158,7 @@ export class TypeRegistry implements Registry {
|
||||
|
||||
readonly #knownDefaults: RegistryTypes;
|
||||
|
||||
readonly #knownDefinitions: Record<string, { types: RegistryTypes }>;
|
||||
readonly #knownDefinitions: Record<string, Definitions>;
|
||||
|
||||
#knownTypes: RegisteredTypes = {};
|
||||
|
||||
@@ -170,7 +170,7 @@ export class TypeRegistry implements Registry {
|
||||
|
||||
constructor (createdAtHash?: Hash | Uint8Array | string) {
|
||||
this.#knownDefaults = objectSpread({ Json, Metadata, PortableRegistry, Raw }, baseTypes);
|
||||
this.#knownDefinitions = definitions as unknown as Record<string, { types: RegistryTypes }>;
|
||||
this.#knownDefinitions = definitions;
|
||||
|
||||
this.init();
|
||||
|
||||
@@ -192,7 +192,7 @@ export class TypeRegistry implements Registry {
|
||||
const allKnown = Object.values(this.#knownDefinitions);
|
||||
|
||||
for (let i = 0; i < allKnown.length; i++) {
|
||||
this.register(allKnown[i].types);
|
||||
this.register(allKnown[i].types as unknown as RegistryTypes);
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// technically runtime can go below, but since it is the base, do it first
|
||||
export { default as runtime } from './runtime/definitions';
|
||||
export * from './essentials';
|
||||
|
||||
// substrate types
|
||||
export { default as assets } from './assets/definitions';
|
||||
@@ -53,15 +52,11 @@ export { default as poll } from './poll/definitions';
|
||||
export { default as purchase } from './purchase/definitions';
|
||||
export { default as xcm } from './xcm/definitions';
|
||||
|
||||
// scale-info & contracts
|
||||
export { default as contractsAbi } from './contractsAbi/definitions';
|
||||
export { default as scaleInfo } from './scaleInfo/definitions';
|
||||
|
||||
// other useful types
|
||||
export { default as contractsAbi } from './contractsAbi/definitions';
|
||||
export { default as eth } from './eth/definitions';
|
||||
|
||||
// pull in metadata & rpc last, assuming that is uses info from above
|
||||
export { default as metadata } from './metadata/definitions';
|
||||
// pull in rpc last, assuming that is uses info from above
|
||||
export { default as rpc } from './rpc/definitions';
|
||||
|
||||
// rpc-only definitions
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { default as metadata } from './metadata/definitions';
|
||||
export { default as runtime } from './runtime/definitions';
|
||||
export { default as scaleInfo } from './scaleInfo/definitions';
|
||||
@@ -5,29 +5,26 @@ import type { DefinitionRpcExt, DefinitionRpcSub } from '../types';
|
||||
|
||||
import { objectSpread } from '@polkadot/util';
|
||||
|
||||
import * as definitions from './definitions';
|
||||
import * as defs from './definitions';
|
||||
|
||||
const jsonrpc: Record<string, Record<string, DefinitionRpcExt>> = {};
|
||||
|
||||
Object
|
||||
.keys(definitions)
|
||||
.filter((key) => Object.keys(definitions[key as 'babe'].rpc || {}).length !== 0)
|
||||
.forEach((_section): void => {
|
||||
jsonrpc[_section] = {};
|
||||
Object.keys(defs).forEach((s) =>
|
||||
Object.entries(defs[s as 'babe'].rpc || {}).forEach(([method, def]): void => {
|
||||
// allow for section overrides
|
||||
const section = def.aliasSection || s;
|
||||
|
||||
Object
|
||||
.entries(definitions[_section as 'babe'].rpc)
|
||||
.forEach(([method, def]): void => {
|
||||
const isSubscription = !!(def as DefinitionRpcSub).pubsub;
|
||||
const section = def.aliasSection || _section;
|
||||
if (!jsonrpc[section]) {
|
||||
jsonrpc[section] = {};
|
||||
}
|
||||
|
||||
// allow for section overrides
|
||||
if (!jsonrpc[section]) {
|
||||
jsonrpc[section] = {};
|
||||
}
|
||||
|
||||
jsonrpc[section][method] = objectSpread({}, def, { isSubscription, jsonrpc: `${section}_${method}`, method, section });
|
||||
});
|
||||
});
|
||||
jsonrpc[section][method] = objectSpread({}, def, {
|
||||
isSubscription: !!(def as DefinitionRpcSub).pubsub,
|
||||
jsonrpc: `${section}_${method}`,
|
||||
method,
|
||||
section
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
export default jsonrpc;
|
||||
|
||||
Reference in New Issue
Block a user