Remove circular imports from types (#492)
* Remove circular imports from types - These are creating issues on RN and is not correct - Uint is equivalent to BN (extends it), so remove it. - Don't import all classes (it imports types itself) - CodecTypes can be exposed elsewhere if needed * Cleanup linting & imports * Cleanup compact decoding
This commit is contained in:
@@ -11,9 +11,7 @@ import extrinsicsFromMeta from '@polkadot/extrinsics/fromMetadata';
|
||||
import { Storage } from '@polkadot/storage/types';
|
||||
import storageFromMeta from '@polkadot/storage/fromMetadata';
|
||||
import registry from '@polkadot/types/codec/typeRegistry';
|
||||
import { Hash, Method, RuntimeVersion } from '@polkadot/types/index';
|
||||
import Event from '@polkadot/types/Event';
|
||||
import RuntimeMetadata from '@polkadot/types/Metadata';
|
||||
import { Event, Hash, Metadata, Method, RuntimeVersion } from '@polkadot/types/index';
|
||||
import { Extrinsics } from '@polkadot/types/Method';
|
||||
import { assert, isFunction, isObject, isUndefined, logger } from '@polkadot/util';
|
||||
|
||||
@@ -36,7 +34,7 @@ export default abstract class ApiBase<R, S, E> implements ApiBaseInterface<R, S,
|
||||
protected _query?: S;
|
||||
protected _rpc: R;
|
||||
protected _rpcBase: Rpc;
|
||||
protected _runtimeMetadata?: RuntimeMetadata;
|
||||
protected _runtimeMetadata?: Metadata;
|
||||
protected _runtimeVersion?: RuntimeVersion;
|
||||
|
||||
/**
|
||||
@@ -92,10 +90,10 @@ export default abstract class ApiBase<R, S, E> implements ApiBaseInterface<R, S,
|
||||
/**
|
||||
* @description Yields the current attached runtime metadata. Generally this is only used to construct extrinsics & storage, but is useful for current runtime inspection.
|
||||
*/
|
||||
get runtimeMetadata (): RuntimeMetadata {
|
||||
get runtimeMetadata (): Metadata {
|
||||
assert(!isUndefined(this._runtimeMetadata), INIT_ERROR);
|
||||
|
||||
return this._runtimeMetadata as RuntimeMetadata;
|
||||
return this._runtimeMetadata as Metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { CodecTypes } from '@polkadot/types/types';
|
||||
import { CodecTypes } from '@polkadot/types/classes';
|
||||
import { RpcParam } from '../types';
|
||||
|
||||
type RpcParamOptions = {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { CodecTypes } from '@polkadot/types/types';
|
||||
import { CodecTypes } from '@polkadot/types/classes';
|
||||
|
||||
export type RpcParam = {
|
||||
isOptional: boolean,
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright 2017-2018 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import * as Classes from './index';
|
||||
|
||||
export type CodecTypes = keyof typeof Classes;
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { bnToBn, compactAddLength, compactFromU8a, compactStripLength, compactToU8a, hexToBn, isBn, isHex, isNumber, isString, isU8a } from '@polkadot/util';
|
||||
import { bnToBn, compactAddLength, compactFromU8a, compactStripLength, compactToU8a, hexToBn, isBn, isHex, isNumber, isString } from '@polkadot/util';
|
||||
import { DEFAULT_BITLENGTH } from '@polkadot/util/compact/defaults';
|
||||
|
||||
import { AnyNumber, Codec, Constructor } from '../types';
|
||||
@@ -56,13 +56,11 @@ export default class Compact extends Base<UInt | Moment> implements Codec {
|
||||
);
|
||||
} else if (isNumber(value) || isBn(value)) {
|
||||
return new Type(bnToBn(value));
|
||||
} else if (isU8a(value)) {
|
||||
const [, _value] = Compact.decodeU8a(value, new Type(0).bitLength());
|
||||
|
||||
return new Type(_value);
|
||||
}
|
||||
|
||||
return new Type(value.toBn());
|
||||
const [, _value] = Compact.decodeU8a(value, new Type(0).bitLength());
|
||||
|
||||
return new Type(_value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,11 +3,8 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import BN from 'bn.js';
|
||||
import * as Classes from './index';
|
||||
|
||||
import { UInt } from './codec';
|
||||
|
||||
export type AnyNumber = UInt | BN | Uint8Array | number | string;
|
||||
export type AnyNumber = BN | Uint8Array | number | string;
|
||||
|
||||
export type AnyString = string | String;
|
||||
|
||||
@@ -51,8 +48,6 @@ export interface Codec {
|
||||
|
||||
export type CodecTo = 'toHex' | 'toJSON' | 'toString' | 'toU8a';
|
||||
|
||||
export type CodecTypes = keyof typeof Classes;
|
||||
|
||||
export type Constructor<T = Codec> = { new(value?: any): T };
|
||||
|
||||
export type ConstructorDef<T = Codec> = { [index: string]: Constructor<T> };
|
||||
|
||||
Reference in New Issue
Block a user