Don't try and auto-detect hex Bytes with length (#387)

This commit is contained in:
Jaco Greeff
2018-11-08 15:59:24 +01:00
committed by GitHub
parent 5bdff2cd36
commit 1c1a9dd253
3 changed files with 2 additions and 14 deletions
-6
View File
@@ -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()
+1 -7
View File
@@ -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);
+1 -1
View File
@@ -41,7 +41,7 @@ export default class UInt extends Base<BN> {
} 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);