Skip to content

Commit

Permalink
Merge ddfe15d into 90cfd34
Browse files Browse the repository at this point in the history
  • Loading branch information
amaury1093 committed Oct 17, 2018
2 parents 90cfd34 + ddfe15d commit 6a384c4
Show file tree
Hide file tree
Showing 20 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions packages/types/src/Address.ts
Expand Up @@ -61,8 +61,8 @@ export default class Address extends Base<AccountId | AccountIndex> {
);
}

byteLength (): number {
return this.raw.byteLength() + (
get encodedLength (): number {
return this.raw.encodedLength + (
this.raw instanceof AccountIndex
? 0
: 1
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/Bool.ts
Expand Up @@ -22,7 +22,7 @@ export default class Bool extends Base<boolean> {
return !!value;
}

byteLength (): number {
get encodedLength (): number {
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/Bytes.ts
Expand Up @@ -46,7 +46,7 @@ export default class Bytes extends U8a {
return this.raw.length;
}

byteLength (): number {
get encodedLength (): number {
return this.length + Compact.encodeU8a(this.length, DEFAULT_LENGTH_BITS).length;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/Extrinsic.ts
Expand Up @@ -105,7 +105,7 @@ export default class Extrinsic extends Struct {
return this.raw.signature as ExtrinsicSignature;
}

byteLength (): number {
get encodedLength (): number {
const length = this.length;

return length + Compact.encodeU8a(length, DEFAULT_LENGTH_BITS).length;
Expand Down
4 changes: 2 additions & 2 deletions packages/types/src/ExtrinsicSignature.ts
Expand Up @@ -61,11 +61,11 @@ export default class ExtrinsicSignature extends Struct {
return value as any;
}

byteLength (): number {
get encodedLength (): number {
// version has 1 byte, signature takes the rest
return 1 + (
this.isSigned
? super.byteLength()
? super.encodedLength
: 0
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/Moment.ts
Expand Up @@ -44,7 +44,7 @@ export default class Moment extends Base<Date> {
);
}

byteLength (): number {
get encodedLength (): number {
return BITLENGTH / 8;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/Null.ts
Expand Up @@ -10,7 +10,7 @@ export default class Null extends Base<null> {
super(null);
}

byteLength (): number {
get encodedLength (): number {
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/Text.ts
Expand Up @@ -49,7 +49,7 @@ export default class Text extends Base<string> {
return this.raw.length;
}

byteLength (): number {
get encodedLength (): number {
return this.length + Compact.encodeU8a(this.length, DEFAULT_LENGTH_BITS).length;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/codec/Base.spec.js
Expand Up @@ -9,7 +9,7 @@ describe('Base', () => {
expect(new Base('foo-bar').raw).toEqual('foo-bar');
});

['byteLength', 'toJSON', 'toString', 'toU8a'].forEach((method) => {
['encodedLength', 'toJSON', 'toString', 'toU8a'].forEach((method) => {
it(`has abstract (?) impl for ${method}`, () => {
expect(
() => new Base()[method]()
Expand Down
4 changes: 2 additions & 2 deletions packages/types/src/codec/Base.ts
Expand Up @@ -22,8 +22,8 @@ export default class Base<T = any> {
this.raw = value;
}

byteLength (): number {
throw new Error('Base::byteLength: unimplemented');
get encodedLength (): number {
throw new Error('Base::encodedLength: unimplemented');
}

toJSON (): any {
Expand Down
8 changes: 4 additions & 4 deletions packages/types/src/codec/Compact.spec.js
Expand Up @@ -90,15 +90,15 @@ describe('Compact', () => {
});
});

it('has the correct byteLength for constructor values (default)', () => {
it('has the correct encodedLength for constructor values (default)', () => {
expect(
new Compact(0xfffffff9, 64).byteLength()
new Compact(0xfffffff9, 64).encodedLength
).toEqual(9);
});

it('has the correct byteLength for constructor values (u32)', () => {
it('has the correct encodedLength for constructor values (u32)', () => {
expect(
new Compact(0xfffffff9, 32).byteLength()
new Compact(0xfffffff9, 32).encodedLength
).toEqual(5);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/codec/Compact.ts
Expand Up @@ -98,7 +98,7 @@ export default class Compact extends UInt {
);
}

byteLength (): number {
get encodedLength (): number {
return this.toU8a().length;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/codec/Enum.ts
Expand Up @@ -38,7 +38,7 @@ export default class Enum extends Base<number> {
}
}

byteLength (): number {
get encodedLength (): number {
return 1;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/types/src/codec/EnumType.ts
Expand Up @@ -86,8 +86,8 @@ export default class EnumType<T> extends Base<Base<T>> {
return this.raw;
}

byteLength (): number {
return 1 + this.raw.byteLength();
get encodedLength (): number {
return 1 + this.raw.encodedLength;
}

setValue (index?: | EnumType<T> | number, value?: any): void {
Expand Down
6 changes: 3 additions & 3 deletions packages/types/src/codec/Option.ts
Expand Up @@ -59,10 +59,10 @@ export default class Option<T> extends Base<Base<T>> {
: this.raw.raw;
}

byteLength (): number {
get encodedLength (): number {
const childLength = this._isEmpty
? 0
: this.raw.byteLength();
: this.raw.encodedLength;

return 1 + childLength;
}
Expand All @@ -78,7 +78,7 @@ export default class Option<T> extends Base<Base<T>> {
return this.raw.toU8a(true);
}

const u8a = new Uint8Array(this.byteLength());
const u8a = new Uint8Array(this.encodedLength);

if (!this._isEmpty) {
u8a.set([1]);
Expand Down
6 changes: 3 additions & 3 deletions packages/types/src/codec/Struct.ts
Expand Up @@ -75,7 +75,7 @@ export default class Struct<

// Move the currentIndex forward
// @ts-ignore FIXME See below
currentIndex += raw[key].byteLength();
currentIndex += raw[key].encodedLength;
// @ts-ignore FIXME See below
} else if (value[jsonKey] instanceof Types[key]) {
// @ts-ignore FIXME See below
Expand Down Expand Up @@ -118,9 +118,9 @@ export default class Struct<
return this._Types;
}

byteLength (): number {
get encodedLength (): number {
return Object.values(this.raw).reduce((length, entry) => {
return length += entry.byteLength();
return length += entry.encodedLength;
}, 0);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/codec/U8a.ts
Expand Up @@ -34,7 +34,7 @@ export default class U8a extends Base<Uint8Array> {
return this.raw.length;
}

byteLength (): number {
get encodedLength (): number {
return this.length;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/codec/U8aFixed.ts
Expand Up @@ -29,7 +29,7 @@ export default class U8aFixed extends U8a {
this.raw = this.raw.subarray(0, this._trimLength());
}

byteLength (): number {
get encodedLength (): number {
return this._trimLength();
}
}
2 changes: 1 addition & 1 deletion packages/types/src/codec/UInt.ts
Expand Up @@ -54,7 +54,7 @@ export default class UInt extends Base<BN> {
return bnToBn(value);
}

byteLength (): number {
get encodedLength (): number {
return this._bitLength / 8;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/types/src/codec/Vector.ts
Expand Up @@ -47,7 +47,7 @@ export default class Vector<
const decoded = new Type(u8a.subarray(offset));

result.push(decoded);
offset += decoded.byteLength();
offset += decoded.encodedLength;
}

return result;
Expand All @@ -69,9 +69,9 @@ export default class Vector<
return this.raw.length;
}

byteLength (): number {
get encodedLength (): number {
return this.raw.reduce((total, raw) => {
return total + raw.byteLength();
return total + raw.encodedLength;
}, Compact.encodeU8a(this.length, DEFAULT_LENGTH_BITS).length);
}

Expand Down

0 comments on commit 6a384c4

Please sign in to comment.