Alias for WrapperOpaque to Opaque (#5039)
This commit is contained in:
@@ -6,7 +6,7 @@ import { AnyString } from '../types';
|
||||
type Mapper = (value: string) => string;
|
||||
|
||||
const BOUNDED = ['BTreeMap', 'BTreeSet', 'HashMap', 'Vec'];
|
||||
const ALLOWED_BOXES = BOUNDED.concat(['Compact', 'DoNotConstruct', 'Int', 'Linkage', 'Range', 'RangeInclusive', 'Result', 'Option', 'UInt', 'WrapperKeepOpaque', 'WrapperOpaque']);
|
||||
const ALLOWED_BOXES = BOUNDED.concat(['Compact', 'DoNotConstruct', 'Int', 'Linkage', 'Range', 'RangeInclusive', 'Result', 'Opaque', 'Option', 'UInt', 'WrapperKeepOpaque', 'WrapperOpaque']);
|
||||
const BOX_PRECEDING = ['<', '(', '[', '"', ',', ' ']; // start of vec, tuple, fixed array, part of struct def or in tuple
|
||||
|
||||
const mappings: Mapper[] = [
|
||||
|
||||
@@ -226,6 +226,7 @@ const wrappedExtraction: [string, string, TypeDefInfo][] = [
|
||||
['BTreeSet<', '>', TypeDefInfo.BTreeSet],
|
||||
['Compact<', '>', TypeDefInfo.Compact],
|
||||
['Linkage<', '>', TypeDefInfo.Linkage],
|
||||
['Opaque<', '>', TypeDefInfo.WrapperOpaque],
|
||||
['Option<', '>', TypeDefInfo.Option],
|
||||
['Range<', '>', TypeDefInfo.Range],
|
||||
['RangeInclusive<', '>', TypeDefInfo.RangeInclusive],
|
||||
|
||||
@@ -24,8 +24,8 @@ export default {
|
||||
sessionIndex: 'SessionIndex',
|
||||
authorityIndex: 'AuthIndex'
|
||||
},
|
||||
OpaqueMultiaddr: 'WrapperOpaque<Bytes>',
|
||||
OpaquePeerId: 'WrapperOpaque<Bytes>',
|
||||
OpaqueMultiaddr: 'Opaque<Bytes>',
|
||||
OpaquePeerId: 'Opaque<Bytes>',
|
||||
OpaqueNetworkState: {
|
||||
peerId: 'OpaquePeerId',
|
||||
externalAddresses: 'Vec<OpaqueMultiaddr>'
|
||||
|
||||
@@ -44,7 +44,7 @@ export default {
|
||||
StorageHasher: 'StorageHasherV14',
|
||||
|
||||
// additional types
|
||||
OpaqueMetadata: 'WrapperOpaque<Bytes>',
|
||||
OpaqueMetadata: 'Opaque<Bytes>',
|
||||
|
||||
// the enum containing all the mappings
|
||||
MetadataAll: {
|
||||
|
||||
@@ -8,22 +8,20 @@ import { isString, isU8a, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { MetadataVersioned } from './MetadataVersioned';
|
||||
|
||||
// magic u32 preceding the version id
|
||||
const VERSION_IDX = 4;
|
||||
|
||||
// magic + lowest supported version
|
||||
const EMPTY_METADATA = new Uint8Array([0x6d, 0x65, 0x74, 0x61, 9]);
|
||||
|
||||
/** @internal */
|
||||
function decodeU8a (registry: Registry, value: Uint8Array): MetadataVersioned | Uint8Array {
|
||||
const u8a = value.length === 0
|
||||
? EMPTY_METADATA
|
||||
: value;
|
||||
// magic u32 preceding the version id
|
||||
const VERSION_IDX = EMPTY_METADATA.length - 1;
|
||||
|
||||
// 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...
|
||||
if (u8a[VERSION_IDX] === 9) {
|
||||
/** @internal */
|
||||
function decodeU8a (registry: Registry, u8a: Uint8Array): MetadataVersioned | Uint8Array {
|
||||
if (u8a.length === 0) {
|
||||
return EMPTY_METADATA;
|
||||
} else if (u8a[VERSION_IDX] === 9) {
|
||||
// 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...
|
||||
try {
|
||||
return new MetadataVersioned(registry, u8a);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user