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:
Jaco Greeff
2020-02-23 14:57:30 +01:00
committed by GitHub
parent d09dcb8282
commit 51cb64ade7
5 changed files with 25 additions and 19 deletions
+13 -3
View File
@@ -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
+2 -16
View File
@@ -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
*/