Cleanup api.createType d.ts, add createType to registry (#1929)
* Cleanup api.createType d.ts, add createType to registry * CHANGELOG
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
- Add `api.rpc.chain.subscribeAllHeads` (not just best) (Thanks to https://github.com/jak-pan)
|
||||
- Add `api.rpc.engine.*` for manual seal support
|
||||
- Registry now exposes `.createType(<type>, ...args)` as well
|
||||
- Support types & interfaces required for lazy reaping & offchain phragmen
|
||||
- Support JS `BigInt` inputs in any `UInt` and `Int` object, `api.tx.balances.transfer(..., 9876543210123456789n)`
|
||||
- Expand `.toHuman` on `ExtrinsicEra`, `SubmittableResult` & `Vote`
|
||||
|
||||
@@ -17,7 +17,7 @@ import DecoratedMeta from '@polkadot/metadata/Decorated';
|
||||
import getHasher from '@polkadot/metadata/Decorated/storage/fromMetadata/getHasher';
|
||||
import RpcCore from '@polkadot/rpc-core';
|
||||
import { WsProvider } from '@polkadot/rpc-provider';
|
||||
import { Metadata, Null, Option, Text, TypeRegistry, u64, Vec } from '@polkadot/types';
|
||||
import { createType, Metadata, Null, Option, Text, TypeRegistry, u64, Vec } from '@polkadot/types';
|
||||
import Linkage, { LinkageResult } from '@polkadot/types/codec/Linkage';
|
||||
import { DEFAULT_VERSION as EXTRINSIC_DEFAULT_VERSION } from '@polkadot/types/extrinsic/constants';
|
||||
import StorageKey, { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
@@ -136,9 +136,19 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
this._rx.registry = this.registry;
|
||||
}
|
||||
|
||||
public abstract createType <K extends keyof InterfaceTypes> (type: K, ...params: any[]): InterfaceTypes[K];
|
||||
/**
|
||||
* @description Creates an instance of a type as registered
|
||||
*/
|
||||
public createType <K extends keyof InterfaceTypes> (type: K, ...params: any[]): InterfaceTypes[K] {
|
||||
return createType(this.registry, type, ...params);
|
||||
}
|
||||
|
||||
public abstract registerTypes (types?: RegistryTypes): void;
|
||||
/**
|
||||
* @description Register additional user-defined of chain-specific types in the type registry
|
||||
*/
|
||||
public registerTypes (types?: RegistryTypes): void {
|
||||
types && this.registry.register(types);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns `true` if the API operates with subscriptions
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
import { Constants } from '@polkadot/metadata/Decorated/types';
|
||||
import { RpcInterface } from '@polkadot/rpc-core/types';
|
||||
import { Hash, RuntimeVersion } from '@polkadot/types/interfaces';
|
||||
import { CallFunction, InterfaceTypes, RegistryError, RegistryTypes, SignerPayloadRawBase } from '@polkadot/types/types';
|
||||
import { CallFunction, RegistryError, SignerPayloadRawBase } from '@polkadot/types/types';
|
||||
import { ApiInterfaceRx, ApiOptions, ApiTypes, DecoratedRpc, DecorateMethod, QueryableStorage, QueryableStorageMulti, SubmittableExtrinsics, Signer } from '../types';
|
||||
|
||||
import { Metadata, createType } from '@polkadot/types';
|
||||
import { Metadata } from '@polkadot/types';
|
||||
import { assert, isString, isUndefined, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import Init from './Init';
|
||||
@@ -233,13 +233,6 @@ export default abstract class ApiBase<ApiType extends ApiTypes> extends Init<Api
|
||||
return assertResult(this._extrinsics);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Creates an instance of a type as registered
|
||||
*/
|
||||
public createType = <K extends keyof InterfaceTypes> (type: K, ...params: any[]): InterfaceTypes[K] => {
|
||||
return createType(this.registry, type, ...params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Disconnect from the underlying provider, halting all network traffic
|
||||
*/
|
||||
@@ -261,13 +254,6 @@ export default abstract class ApiBase<ApiType extends ApiTypes> extends Init<Api
|
||||
return this.registry.findMetaError(u8aToU8a(errorIndex));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Register additional user-defined of chain-specific types in the type registry
|
||||
*/
|
||||
public registerTypes (types?: RegistryTypes): void {
|
||||
types && this.registry.register(types);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Set an external signer which will be used to sign extrinsic when account passed in is not KeyringPair
|
||||
*/
|
||||
|
||||
@@ -14,6 +14,7 @@ import { defaultExtensions, expandExtensionTypes, findUnknownExtensions } from '
|
||||
import { EventData } from '../generic/Event';
|
||||
import Unconstructable from '../primitive/Unconstructable';
|
||||
import { createClass, getTypeClass } from './createClass';
|
||||
import { createType } from './createType';
|
||||
import { getTypeDef } from './getTypeDef';
|
||||
|
||||
// create error mapping from metadata
|
||||
@@ -127,6 +128,13 @@ export class TypeRegistry implements Registry {
|
||||
: formatBalance.getDefaults().unit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Creates an instance of a type as registered
|
||||
*/
|
||||
public createType <K extends keyof InterfaceTypes> (type: K, ...params: any[]): InterfaceTypes[K] {
|
||||
return createType(this, type, ...params);
|
||||
}
|
||||
|
||||
// find a specific call
|
||||
public findMetaCall (callIndex: Uint8Array): CallFunction {
|
||||
const hexIndex = u8aToHex(callIndex);
|
||||
|
||||
@@ -92,6 +92,7 @@ export interface Registry {
|
||||
// keep this as a generic Codec, however the actual impl. returns the correct
|
||||
findMetaEvent (eventIndex: Uint8Array): Constructor<any>;
|
||||
|
||||
createType <K extends keyof InterfaceTypes> (type: K, ...params: any[]): InterfaceTypes[K];
|
||||
get <T extends Codec = Codec> (name: string, withUnknown?: boolean): Constructor<T> | undefined;
|
||||
getChainProperties (): ChainProperties | undefined;
|
||||
getDefinition (name: string): string | undefined;
|
||||
|
||||
Reference in New Issue
Block a user