Skip to content

Commit

Permalink
Long -> UInt
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogr committed Sep 25, 2018
1 parent e613fd8 commit e9b0090
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions packages/api-codec/src/Header.ts
Expand Up @@ -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';

Expand All @@ -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
};
Expand Down
6 changes: 3 additions & 3 deletions packages/api-codec/src/U128.ts
Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions packages/api-codec/src/U16.ts
Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions packages/api-codec/src/U256.ts
Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions packages/api-codec/src/U32.ts
Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions packages/api-codec/src/U64.ts
Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions packages/api-codec/src/U8.ts
Expand Up @@ -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);
}
}
Expand Up @@ -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<BN> {
export default class UInt extends Base<BN> {
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);
Expand All @@ -48,13 +48,13 @@ export default class Long extends Base<BN> {
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;
Expand Down

0 comments on commit e9b0090

Please sign in to comment.