Drop circular Linkage deps (#1627)

* Drop circular Linkage deps

* Cleanup more circular deps

* IU8a interface
This commit is contained in:
Jaco Greeff
2019-12-03 14:05:50 +01:00
committed by GitHub
parent af76d7fb04
commit 7e1eb0fab0
6 changed files with 34 additions and 15 deletions
+1
View File
@@ -14,6 +14,7 @@
"scripts": {
"build": "yarn build:interfaces && polkadot-dev-build-ts",
"build:interfaces": "node packages/types/src/scripts/interfacesTsWrapper.js",
"circular": "madge --circular --extensions ts ./",
"docs": "node packages/types/src/scripts/MetadataMdWrapper.js && polkadot-dev-build-docs",
"chain:info": "node packages/types/src/scripts/extractChainWrapper.js",
"lint": "eslint --ext .js,.jsx,.ts,.tsx . && tsc --noEmit --pretty",
+2 -2
View File
@@ -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 { AnyNumber, Codec, Constructor, InterfaceTypes, Registry } from '../types';
import { AnyNumber, Codec, Constructor, ICompact, InterfaceTypes, Registry } from '../types';
import BN from 'bn.js';
import { compactAddLength, compactFromU8a, compactStripLength, compactToU8a, isBn, isNumber, isString } from '@polkadot/util';
@@ -26,7 +26,7 @@ export interface CompactEncodable extends Codec {
* used by other types to add length-prefixed encoding, or in the case of wrapped types, taking
* a number and making the compact representation thereof
*/
export default class Compact<T extends CompactEncodable> extends Base<T> {
export default class Compact<T extends CompactEncodable> extends Base<T> implements ICompact<T> {
constructor (registry: Registry, Type: Constructor<T> | InterfaceTypes, value: Compact<T> | AnyNumber = 0) {
super(registry, Compact.decodeCompact<T>(registry, typeToConstructor(registry, Type), value));
}
+2 -2
View File
@@ -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 { AnyU8a, Codec, IHash, Registry } from '../types';
import { AnyU8a, IHash, IU8a, Registry } from '../types';
import { isU8a, isUndefined, u8aToHex, u8aToU8a } from '@polkadot/util';
import { blake2AsU8a } from '@polkadot/util-crypto';
@@ -16,7 +16,7 @@ import { blake2AsU8a } from '@polkadot/util-crypto';
* actual lengths instead of used directly.
* @noInheritDoc
*/
export default class U8a extends Uint8Array implements Codec {
export default class U8a extends Uint8Array implements IU8a {
public readonly registry: Registry;
constructor (registry: Registry, value?: AnyU8a) {
@@ -10,7 +10,6 @@ import { assert } from '@polkadot/util';
import BTreeMap from '../BTreeMap';
import Compact from '../Compact';
import Enum from '../Enum';
import Linkage from '../Linkage';
import Option from '../Option';
import Result from '../Result';
import CodecSet from '../Set';
@@ -67,7 +66,17 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
[TypeDefInfo.Enum]: (registry: Registry, value: TypeDef): Constructor => Enum.with(getTypeClassMap(value)),
[TypeDefInfo.Linkage]: (registry: Registry, value: TypeDef): Constructor => Linkage.withKey(getSubType(value)),
// We have circular deps between Linkage & Struct
[TypeDefInfo.Linkage]: (registry: Registry, value: TypeDef): Constructor => {
const type = `Option<${getSubType(value)}>`;
const Clazz = Struct.with({ previous: type, next: type } as any);
ClassOf.prototype.toRawType = function (): string {
return `Linkage<${this.next.toRawType(true)}>`;
};
return Clazz;
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
[TypeDefInfo.Null]: (registry: Registry, _: TypeDef): Constructor => ClassOf(registry, 'Null'),
@@ -6,7 +6,7 @@ import { Codec, Constructor, InterfaceTypes, Registry } from '../../types';
import { isString } from '@polkadot/util';
import { ClassOf } from '../create';
import { ClassOf } from '../create/createClass';
export function typeToConstructor <T = Codec> (registry: Registry, type: InterfaceTypes | Constructor<T>): Constructor<T> {
return (
+17 -8
View File
@@ -4,15 +4,11 @@
import { SignOptions } from '@polkadot/keyring/types';
import { FunctionMetadataLatest } from './interfaces/metadata';
import { Balance, EcdsaSignature, Ed25519Signature, Index, Sr25519Signature } from './interfaces/runtime';
import { Address, Balance, Call, EcdsaSignature, Ed25519Signature, Index, Sr25519Signature } from './interfaces/runtime';
import BN from 'bn.js';
import Compact from './codec/Compact';
import U8a from './codec/U8a';
import { InterfaceRegistry } from './interfaceRegistry';
import Call from './primitive/Generic/Call';
import Address from './primitive/Generic/Address';
export * from './codec/types';
@@ -125,8 +121,21 @@ export interface Codec {
toU8a (isBare?: BareOpts): Uint8Array;
}
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
export interface IU8a extends Uint8Array, Codec {
bitLength (): number;
toJSON (): any;
}
// eslint-disable-next-line @typescript-eslint/interface-name-prefix,@typescript-eslint/no-empty-interface
export interface IHash extends U8a { }
export interface IHash extends IU8a { }
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
export interface ICompact<T> extends Codec {
toBn (): BN;
toNumber (): number;
unwrap (): T;
}
export type CodecTo = 'toHex' | 'toJSON' | 'toString' | 'toU8a';
@@ -181,10 +190,10 @@ export interface IMethod extends Codec {
interface ExtrinsicSignatureBase {
readonly isSigned: boolean;
readonly era: IExtrinsicEra;
readonly nonce: Compact<Index>;
readonly nonce: ICompact<Index>;
readonly signature: EcdsaSignature | Ed25519Signature | Sr25519Signature;
readonly signer: Address;
readonly tip: Compact<Balance>;
readonly tip: ICompact<Balance>;
}
export interface ExtrinsicPayloadValue {