diff --git a/.gitignore b/.gitignore index 952bf5dc4b..0c17d4d3f0 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ tmp/ .env.test.local .env.production.local .npmrc +.rpt2_cache cc-test-reporter lerna-debug.log* npm-debug.log* diff --git a/packages/types/src/codec/Compact.ts b/packages/types/src/codec/Compact.ts index a40209022e..3bf7bcae24 100644 --- a/packages/types/src/codec/Compact.ts +++ b/packages/types/src/codec/Compact.ts @@ -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 diff --git a/packages/types/src/primitive/Null.ts b/packages/types/src/primitive/Null.ts index 1bad426d23..f4bffa251e 100644 --- a/packages/types/src/primitive/Null.ts +++ b/packages/types/src/primitive/Null.ts @@ -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'); } /** diff --git a/packages/types/src/scripts/interfacesTs.ts b/packages/types/src/scripts/interfacesTs.ts index 0cfc6dc4ff..c7a7edb827 100644 --- a/packages/types/src/scripts/interfacesTs.ts +++ b/packages/types/src/scripts/interfacesTs.ts @@ -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, Child: Constructor): boole } function isCompactEncodable (Child: Constructor): 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 extends {}