diff --git a/packages/api-codec/src/Header.ts b/packages/api-codec/src/Header.ts index 5e3c4307bd45..1082bc59fb93 100644 --- a/packages/api-codec/src/Header.ts +++ b/packages/api-codec/src/Header.ts @@ -6,7 +6,7 @@ import BN from 'bn.js'; import blake2Asu8a from '@polkadot/util-crypto/blake2/asU8a'; import Bytes from './codec/Bytes'; -import Long from './codec/Long'; +import UInt from './codec/UInt'; import Struct from './codec/Struct'; import Vector from './codec/Vector'; @@ -20,7 +20,7 @@ type DigestStruct = { type HeaderStruct = { digest?: DigestStruct, extrinsicsRoot?: Hash | Uint8Array | string, - number?: Long | BN | number | string, + number?: UInt | BN | number | string, parentHash?: Hash | Uint8Array | string, stateRoot?: Hash | Uint8Array | string }; diff --git a/packages/api-codec/src/U128.ts b/packages/api-codec/src/U128.ts index ac1708999d1d..3720ff935e10 100644 --- a/packages/api-codec/src/U128.ts +++ b/packages/api-codec/src/U128.ts @@ -4,10 +4,10 @@ import BN from 'bn.js'; -import Long from './codec/Long'; +import UInt from './codec/UInt'; -export default class U128 extends Long { - constructor (value?: Long | BN | string | number) { +export default class U128 extends UInt { + constructor (value?: UInt | BN | string | number) { super(value, 128); } } diff --git a/packages/api-codec/src/U16.ts b/packages/api-codec/src/U16.ts index 7b401f597277..a64cbdf28715 100644 --- a/packages/api-codec/src/U16.ts +++ b/packages/api-codec/src/U16.ts @@ -4,10 +4,10 @@ import BN from 'bn.js'; -import Long from './codec/Long'; +import UInt from './codec/UInt'; -export default class U16 extends Long { - constructor (value?: Long | BN | string | number) { +export default class U16 extends UInt { + constructor (value?: UInt | BN | string | number) { super(value, 16); } } diff --git a/packages/api-codec/src/U256.ts b/packages/api-codec/src/U256.ts index 4ddf61933431..6edcaefac973 100644 --- a/packages/api-codec/src/U256.ts +++ b/packages/api-codec/src/U256.ts @@ -4,10 +4,10 @@ import BN from 'bn.js'; -import Long from './codec/Long'; +import UInt from './codec/UInt'; -export default class U256 extends Long { - constructor (value?: Long | BN | string | number) { +export default class U256 extends UInt { + constructor (value?: UInt | BN | string | number) { super(value, 256); } } diff --git a/packages/api-codec/src/U32.ts b/packages/api-codec/src/U32.ts index 362e4d02f4ea..2f1453b1a23e 100644 --- a/packages/api-codec/src/U32.ts +++ b/packages/api-codec/src/U32.ts @@ -4,10 +4,10 @@ import BN from 'bn.js'; -import Long from './codec/Long'; +import UInt from './codec/UInt'; -export default class U32 extends Long { - constructor (value?: Long | BN | string | number) { +export default class U32 extends UInt { + constructor (value?: UInt | BN | string | number) { super(value, 32); } } diff --git a/packages/api-codec/src/U64.ts b/packages/api-codec/src/U64.ts index aa20d9a3e535..56770ca2f620 100644 --- a/packages/api-codec/src/U64.ts +++ b/packages/api-codec/src/U64.ts @@ -4,10 +4,10 @@ import BN from 'bn.js'; -import Long from './codec/Long'; +import UInt from './codec/UInt'; -export default class U64 extends Long { - constructor (value?: Long | BN | string | number) { +export default class U64 extends UInt { + constructor (value?: UInt | BN | string | number) { super(value, 64); } } diff --git a/packages/api-codec/src/U8.ts b/packages/api-codec/src/U8.ts index d0b75b5d3648..0860b5e4b6f4 100644 --- a/packages/api-codec/src/U8.ts +++ b/packages/api-codec/src/U8.ts @@ -4,10 +4,10 @@ import BN from 'bn.js'; -import Long from './codec/Long'; +import UInt from './codec/UInt'; -export default class U8 extends Long { - constructor (value?: Long | BN | string | number) { +export default class U8 extends UInt { + constructor (value?: UInt | BN | string | number) { super(value, 8); } } diff --git a/packages/api-codec/src/codec/Long.ts b/packages/api-codec/src/codec/UInt.ts similarity index 84% rename from packages/api-codec/src/codec/Long.ts rename to packages/api-codec/src/codec/UInt.ts index 9c479fa250b8..06de236be28e 100644 --- a/packages/api-codec/src/codec/Long.ts +++ b/packages/api-codec/src/codec/UInt.ts @@ -21,19 +21,19 @@ type BitLength = 8 | 16 | 32 | 64 | 128 | 256; // // TODO: // - Apart from encoding/decoding we don't actuall keep check on the sizes, is this good enough? -export default class Long extends Base { +export default class UInt extends Base { private _bitLength: BitLength; - constructor (value: Long | BN | string | number = 0, bitLength: BitLength = 64) { + constructor (value: UInt | BN | string | number = 0, bitLength: BitLength = 64) { super( - Long.decode(value) + UInt.decode(value) ); this._bitLength = bitLength; } - static decode (value: Long | BN | string | number): BN { - if (value instanceof Long) { + static decode (value: UInt | BN | string | number): BN { + if (value instanceof UInt) { return value.raw; } else if (isHex(value)) { return hexToBn(value as string); @@ -48,13 +48,13 @@ export default class Long extends Base { return this._bitLength / 8; } - fromJSON (input: any): Long { - this.raw = Long.decode(input); + fromJSON (input: any): UInt { + this.raw = UInt.decode(input); return this; } - fromU8a (input: Uint8Array): Long { + fromU8a (input: Uint8Array): UInt { this.raw = u8aToBn(input.subarray(0, this.byteLength()), true); return this;