Skip to content

Commit

Permalink
Unsigned -> Long
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogr committed Sep 25, 2018
1 parent 98f4e9a commit 3d4125f
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
6 changes: 3 additions & 3 deletions packages/api-codec/src/U128.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import BN from 'bn.js';

import Unsigned from './codec/Unsigned';
import Long from '@polkadot/api-codec/codec/Long';

export default class U128 extends Unsigned {
constructor (value?: Unsigned | BN | string | number) {
export default class U128 extends Long {
constructor (value?: Long | BN | string | number) {
super(value, 128);
}
}
6 changes: 3 additions & 3 deletions packages/api-codec/src/U16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import BN from 'bn.js';

import Unsigned from './codec/Unsigned';
import Long from '@polkadot/api-codec/codec/Long';

export default class U16 extends Unsigned {
constructor (value?: Unsigned | BN | string | number) {
export default class U16 extends Long {
constructor (value?: Long | BN | string | number) {
super(value, 16);
}
}
6 changes: 3 additions & 3 deletions packages/api-codec/src/U256.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import BN from 'bn.js';

import Unsigned from './codec/Unsigned';
import Long from '@polkadot/api-codec/codec/Long';

export default class U256 extends Unsigned {
constructor (value?: Unsigned | BN | string | number) {
export default class U256 extends Long {
constructor (value?: Long | BN | string | number) {
super(value, 256);
}
}
6 changes: 3 additions & 3 deletions packages/api-codec/src/U32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import BN from 'bn.js';

import Unsigned from './codec/Unsigned';
import Long from '@polkadot/api-codec/codec/Long';

export default class U32 extends Unsigned {
constructor (value?: Unsigned | BN | string | number) {
export default class U32 extends Long {
constructor (value?: Long | BN | string | number) {
super(value, 32);
}
}
6 changes: 3 additions & 3 deletions packages/api-codec/src/U64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import BN from 'bn.js';

import Unsigned from './codec/Unsigned';
import Long from './codec/Long';

export default class U64 extends Unsigned {
constructor (value?: Unsigned | BN | string | number) {
export default class U64 extends Long {
constructor (value?: Long | BN | string | number) {
super(value, 64);
}
}
6 changes: 3 additions & 3 deletions packages/api-codec/src/U8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import BN from 'bn.js';

import Unsigned from './codec/Unsigned';
import Long from '@polkadot/api-codec/codec/Long';

export default class U8 extends Unsigned {
constructor (value?: Unsigned | BN | string | number) {
export default class U8 extends Long {
constructor (value?: Long | BN | string | number) {
super(value, 8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import bnToU8a from '@polkadot/util/bn/toU8a';
import hexToBn from '@polkadot/util/hex/toBn';
import u8aToBn from '@polkadot/util/u8a/toBn';

import Base from './Base';
import Base from '@polkadot/api-codec/codec/Base';

type BitLength = 8 | 16 | 32 | 64 | 128 | 256;

Expand All @@ -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 Unsigned extends Base<BN> {
export default class Long extends Base<BN> {
private _bitLength: BitLength;

constructor (value: Unsigned | BN | string | number = 0, bitLength: BitLength = 64) {
constructor (value: Long | BN | string | number = 0, bitLength: BitLength = 64) {
super(
Unsigned.decode(value)
Long.decode(value)
);

this._bitLength = bitLength;
}

static decode (value: Unsigned | BN | string | number): BN {
if (value instanceof Unsigned) {
static decode (value: Long | BN | string | number): BN {
if (value instanceof Long) {
return value.raw;
} else if (isHex(value)) {
return hexToBn(value as string);
Expand All @@ -48,13 +48,13 @@ export default class Unsigned extends Base<BN> {
return this._bitLength / 8;
}

fromJSON (input: any): Unsigned {
this.raw = Unsigned.decode(input);
fromJSON (input: any): Long {
this.raw = Long.decode(input);

return this;
}

fromU8a (input: Uint8Array): Unsigned {
fromU8a (input: Uint8Array): Long {
this.raw = u8aToBn(input.subarray(0, this.byteLength()), true);

return this;
Expand Down

0 comments on commit 3d4125f

Please sign in to comment.