diff --git a/CHANGELOG.md b/CHANGELOG.md index fa90f9acd3..11b7afc793 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Changes: -- Adjust `Opaque{Metadata, Multiaddr, PeerId}` decoding to `WrapperOpaque` +- Adjust `Opaque{Metadata, Multiaddr, PeerId}` decoding to `Opaque` - Adjust type generation to correctly cater for ambient definitions - Improve type argument generation for `Option<...>` types diff --git a/package.json b/package.json index d7a855223c..26b00fc30c 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "@babel/core": "^7.18.6", "@babel/register": "^7.18.6", "@babel/runtime": "^7.18.6", - "@polkadot/dev": "^0.67.55", + "@polkadot/dev": "^0.67.58", "@polkadot/typegen": "workspace:packages/typegen", "@types/jest": "^28.1.4", "copyfiles": "^2.4.1" diff --git a/packages/types-codec/src/utils/sanitize.ts b/packages/types-codec/src/utils/sanitize.ts index 35a552e1e9..121d7e5c9c 100644 --- a/packages/types-codec/src/utils/sanitize.ts +++ b/packages/types-codec/src/utils/sanitize.ts @@ -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[] = [ diff --git a/packages/types-create/src/util/getTypeDef.ts b/packages/types-create/src/util/getTypeDef.ts index 251cd1d4ed..9d83a986f4 100644 --- a/packages/types-create/src/util/getTypeDef.ts +++ b/packages/types-create/src/util/getTypeDef.ts @@ -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], diff --git a/packages/types/src/interfaces/imOnline/definitions.ts b/packages/types/src/interfaces/imOnline/definitions.ts index a8cd24f7fe..b25dfe1c28 100644 --- a/packages/types/src/interfaces/imOnline/definitions.ts +++ b/packages/types/src/interfaces/imOnline/definitions.ts @@ -24,8 +24,8 @@ export default { sessionIndex: 'SessionIndex', authorityIndex: 'AuthIndex' }, - OpaqueMultiaddr: 'WrapperOpaque', - OpaquePeerId: 'WrapperOpaque', + OpaqueMultiaddr: 'Opaque', + OpaquePeerId: 'Opaque', OpaqueNetworkState: { peerId: 'OpaquePeerId', externalAddresses: 'Vec' diff --git a/packages/types/src/interfaces/metadata/definitions.ts b/packages/types/src/interfaces/metadata/definitions.ts index 473c711265..8327da1d1a 100644 --- a/packages/types/src/interfaces/metadata/definitions.ts +++ b/packages/types/src/interfaces/metadata/definitions.ts @@ -44,7 +44,7 @@ export default { StorageHasher: 'StorageHasherV14', // additional types - OpaqueMetadata: 'WrapperOpaque', + OpaqueMetadata: 'Opaque', // the enum containing all the mappings MetadataAll: { diff --git a/packages/types/src/metadata/Metadata.ts b/packages/types/src/metadata/Metadata.ts index 1fde52e6aa..9f6533c63c 100644 --- a/packages/types/src/metadata/Metadata.ts +++ b/packages/types/src/metadata/Metadata.ts @@ -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) { diff --git a/yarn.lock b/yarn.lock index 8b766693e4..06e7e70f48 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2044,9 +2044,9 @@ __metadata: languageName: unknown linkType: soft -"@polkadot/dev@npm:^0.67.55": - version: 0.67.55 - resolution: "@polkadot/dev@npm:0.67.55" +"@polkadot/dev@npm:^0.67.58": + version: 0.67.58 + resolution: "@polkadot/dev@npm:0.67.58" dependencies: "@babel/cli": ^7.18.6 "@babel/core": ^7.18.6 @@ -2134,7 +2134,7 @@ __metadata: polkadot-exec-rollup: scripts/polkadot-exec-rollup.mjs polkadot-exec-tsc: scripts/polkadot-exec-tsc.mjs polkadot-exec-webpack: scripts/polkadot-exec-webpack.mjs - checksum: 695f7250519af45dd5ef22f8c383033ecf0aacd4c356ab87a5a47e51863f2d44c0283a8ff896e4999923489b8d043e8b36c5f6c53aa912f7c8e2576895ec6083 + checksum: b7f45bb635cdf8734ec9c8410a489a8d8b9667f944a0816d4fb3f0f7bcde0881b74742072df312e990fa59610439a7d52021e215b42879d04338fd1e457497d7 languageName: node linkType: hard @@ -9205,7 +9205,7 @@ resolve@^2.0.0-next.3: "@babel/core": ^7.18.6 "@babel/register": ^7.18.6 "@babel/runtime": ^7.18.6 - "@polkadot/dev": ^0.67.55 + "@polkadot/dev": ^0.67.58 "@polkadot/typegen": "workspace:packages/typegen" "@types/jest": ^28.1.4 copyfiles: ^2.4.1