Low-hanging circular deps (#1297)
* Low-hanging circular deps * Cleanup Compact check * Null does not allow .hash
This commit is contained in:
@@ -11,6 +11,7 @@ tmp/
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.npmrc
|
||||
.rpt2_cache
|
||||
cc-test-reporter
|
||||
lerna-debug.log*
|
||||
npm-debug.log*
|
||||
|
||||
@@ -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, Constructor, InterfaceTypes } from '../types';
|
||||
import { AnyNumber, Codec, Constructor, InterfaceTypes } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { bnToBn, compactAddLength, compactFromU8a, compactStripLength, compactToU8a, hexToBn, isBn, isHex, isNumber, isString } from '@polkadot/util';
|
||||
@@ -10,13 +10,13 @@ import { DEFAULT_BITLENGTH } from '@polkadot/util/compact/defaults';
|
||||
|
||||
import { typeToConstructor } from './utils';
|
||||
import { UIntBitLength } from './AbstractInt';
|
||||
import CodecDate from './Date';
|
||||
import UInt from './UInt';
|
||||
import Base from './Base';
|
||||
|
||||
// List of codec types that are compact-encodable
|
||||
export const COMPACT_ENCODABLE = [UInt, CodecDate];
|
||||
export type CompactEncodable = UInt | CodecDate; // FIXME is there a way to do it not-manually from the array?
|
||||
export interface CompactEncodable extends Codec {
|
||||
bitLength (): UIntBitLength;
|
||||
toBn (): BN;
|
||||
toNumber (): number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Compact
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
import { Codec, IHash } from '../types';
|
||||
|
||||
import { isNull } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import createType from '../codec/createType';
|
||||
|
||||
/**
|
||||
* @name Null
|
||||
@@ -26,7 +23,7 @@ export default class Null implements Codec {
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): IHash {
|
||||
return createType('Hash', blake2AsU8a(this.toU8a(), 256));
|
||||
throw new Error('.hash is not implemented on Null');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,7 @@ import interfaces from '../../../type-jsonrpc/src';
|
||||
import { ClassOfUnsafe, getTypeDef } from '../codec/createType';
|
||||
import * as codecClasses from '../codec';
|
||||
import AbstractInt from '../codec/AbstractInt';
|
||||
import { COMPACT_ENCODABLE } from '../codec/Compact';
|
||||
import UInt from '../codec/UInt';
|
||||
import Vec from '../codec/Vec';
|
||||
import * as definitions from '../interfaces/definitions';
|
||||
import * as primitiveClasses from '../primitive';
|
||||
@@ -70,10 +70,7 @@ function isChildClass (Parent: Constructor<any>, Child: Constructor<any>): boole
|
||||
}
|
||||
|
||||
function isCompactEncodable (Child: Constructor<any>): boolean {
|
||||
// @ts-ignore AbstractInt is abstract, we shouldn't isChildClass it here, but it works
|
||||
return Object.values(COMPACT_ENCODABLE).some((CompactEncodable): boolean =>
|
||||
isChildClass(CompactEncodable, Child)
|
||||
);
|
||||
return isChildClass(UInt, Child);
|
||||
}
|
||||
|
||||
// helper to generate a `export interface <Name> extends <Base> {<Body>}
|
||||
|
||||
Reference in New Issue
Block a user