Remove metadata index hack... and add another one (#1935)
* Remove metadata index hack * Parse v9 and V10 upon failure
This commit is contained in:
@@ -9,6 +9,8 @@ import { bnToU8a, isHex, hexToU8a, u8aConcat } from '@polkadot/util';
|
||||
import { MAGIC_NUMBER } from './MagicNumber';
|
||||
import MetadataVersioned from './MetadataVersioned';
|
||||
|
||||
const VERSION_IDX = 4; // magic u32 preceding
|
||||
|
||||
// first we try and parse using the versioned structure, if this does fail,
|
||||
// we adjust with the magic number and a manual version and re-try. As soon as
|
||||
// we remove support for V0, we will just do a new here
|
||||
@@ -16,11 +18,21 @@ function decodeMetadata (registry: Registry, _value: Uint8Array | string = new U
|
||||
const value = isHex(_value)
|
||||
? hexToU8a(_value)
|
||||
: _value;
|
||||
const version = value[VERSION_IDX];
|
||||
|
||||
try {
|
||||
return new MetadataVersioned(registry, value);
|
||||
} catch (error) {
|
||||
if (error.message.indexOf('MagicNumber mismatch') === -1) {
|
||||
if (!error.message.includes('MagicNumber mismatch')) {
|
||||
// This is an f-ing hack as a follow-up to another ugly hack
|
||||
// https://github.com/polkadot-js/api/commit/a9211690be6b68ad6c6dad7852f1665cadcfa5b2
|
||||
// when we fail on V9, try to re-parse it as v10... yes... HACK
|
||||
if (version === 9) {
|
||||
value[VERSION_IDX] = 10;
|
||||
|
||||
return decodeMetadata(registry, value);
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,11 +223,7 @@ export default {
|
||||
Blake2_256: null, // eslint-disable-line @typescript-eslint/camelcase
|
||||
Twox128: null,
|
||||
Twox256: null,
|
||||
Twox64Concat: null,
|
||||
// We had a bug in some versions of V9, where it was not bumped - V10 fixed (add invalid for this range)
|
||||
// At this point, things won't work anyway (indexes mismatched, but at least allow for parsing)
|
||||
// (Technically this should be on V9, however then we need code as well...)
|
||||
InvalidEntry: null
|
||||
Twox64Concat: null
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user