Don't try and auto-detect hex Bytes with length (#387)
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user