From 1c1a9dd253c43205995a7985296be3cca37dd801 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 8 Nov 2018 15:59:24 +0100 Subject: [PATCH] Don't try and auto-detect hex Bytes with length (#387) --- packages/types/src/Bytes.spec.ts | 6 ------ packages/types/src/Bytes.ts | 8 +------- packages/types/src/codec/UInt.ts | 2 +- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/packages/types/src/Bytes.spec.ts b/packages/types/src/Bytes.spec.ts index 5db9a53c02..29283705f8 100644 --- a/packages/types/src/Bytes.spec.ts +++ b/packages/types/src/Bytes.spec.ts @@ -8,12 +8,6 @@ describe('Bytes', () => { describe('hex decoding', () => { const CODE = new Uint8Array([0x14, 0x3a, 0x63, 0x6f, 0x64, 0x65]); - it('decodes when hex is length prefixed', () => { - expect( - new Bytes('0x143a636f6465').toU8a() - ).toEqual(CODE); - }); - it('decodes when hex is not length prefixed', () => { expect( new Bytes('0x3a636f6465').toU8a() diff --git a/packages/types/src/Bytes.ts b/packages/types/src/Bytes.ts index 59b715e145..688ab7f133 100644 --- a/packages/types/src/Bytes.ts +++ b/packages/types/src/Bytes.ts @@ -22,16 +22,10 @@ export default class Bytes extends U8a { } else if (isHex(value)) { // FIXME We manually add the length prefix for hex for now // https://github.com/paritytech/substrate/issues/889 - // HACK 7 Nov 2018 Some Bytes values are properly encoded, i.e. when - // querying storage for code, others are not (yet), i.e. extrinsics. - // Here we pull the length, check for matches and add when not const u8a = hexToU8a(value as string); - const [offset, length] = Compact.decodeU8a(u8a, DEFAULT_LENGTH_BITS); return Bytes.decodeBytes( - u8a.length === (offset + length.toNumber()) - ? u8a - : Compact.addLengthPrefix(u8a) + Compact.addLengthPrefix(u8a) ); } else if (isU8a(value)) { const [offset, length] = Compact.decodeU8a(value, DEFAULT_LENGTH_BITS); diff --git a/packages/types/src/codec/UInt.ts b/packages/types/src/codec/UInt.ts index e80376f844..56da6d31c7 100644 --- a/packages/types/src/codec/UInt.ts +++ b/packages/types/src/codec/UInt.ts @@ -41,7 +41,7 @@ export default class UInt extends Base { } else if (isHex(value)) { return hexToBn(value as string); } else if (isU8a(value)) { - // NOTE When passing u8a in (typically from decoded data), it is always u8a + // NOTE When passing u8a in (typically from decoded data), it is always LE return u8aToBn(value.subarray(0, bitLength / 8), true); } else if (isString(value)) { return new BN(value, 10);