diff --git a/CHANGELOG.md b/CHANGELOG.md index 2beda74dde..7904db922b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Add `LookupSource` and `LookupTarget` types instead of mapping these directly for aliassing - Add support for `system.account` for balance & nonce queries in derives (Substrate composites) - Add `BitVec` type primitive +- Updated types for Polkadot parachains # 1.1.1 diff --git a/package.json b/package.json index 5ba618b4f9..a07babba7d 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "@babel/core": "^7.8.3", "@babel/register": "^7.8.3", "@babel/runtime": "^7.8.3", - "@polkadot/dev": "^0.33.3", + "@polkadot/dev": "^0.33.5", "@polkadot/ts": "^0.2.1" } } diff --git a/packages/types/src/codec/create/sanitize.ts b/packages/types/src/codec/create/sanitize.ts index 76a7260fb9..885cb3a521 100644 --- a/packages/types/src/codec/create/sanitize.ts +++ b/packages/types/src/codec/create/sanitize.ts @@ -10,7 +10,7 @@ const BOX_PRECEDING = ['<', '(', '[', '"', ',', ' ']; // start of vec, tuple, fi const mappings: Mapper[] = [ // alias ::Inherent -> InherentOfflineReport - _alias('::Inherent', 'InherentOfflineReport'), + _alias(['::Inherent'], 'InherentOfflineReport'), // _cleanupCompact(), // Remove all the trait prefixes @@ -22,30 +22,21 @@ const mappings: Mapper[] = [ // remove generics, `MisbehaviorReport` -> `MisbehaviorReport` _removeGenerics(), // alias String -> Text (compat with jsonrpc methods) - _alias('String', 'Text'), + _alias(['String'], 'Text'), // alias Vec -> Bytes - _alias('Vec', 'Bytes'), - // alias &[u8] -> Bytes - _alias('&\\[u8\\]', 'Bytes'), + _alias(['Vec', '&\\[u8\\]'], 'Bytes'), // alias RawAddress -> Address - _alias('RawAddress', 'Address'), + _alias(['RawAddress'], 'Address'), // lookups, mapped to Address/AccountId as appropriate in runtime - _alias('Lookup::Source', 'LookupSource'), - _alias('Lookup::Target', 'LookupTarget'), - // alias for grandpa internal, as used in polkadot - _alias('grandpa::', ''), - // specific for session internal - _alias('session::', ''), - // specific for staking/slashing.rs internal - _alias('slashing::', ''), + _alias(['Lookup::Source'], 'LookupSource'), + _alias(['Lookup::Target'], 'LookupTarget'), // HACK duplication between contracts & primitives, however contracts prefixed with exec - _alias('exec::StorageKey', 'ContractStorageKey'), - // Phantom - _alias('rstd::marker::PhantomData', 'PhantomData'), - _alias('sp_std::marker::PhantomData', 'PhantomData'), + _alias(['exec::StorageKey'], 'ContractStorageKey'), + // alias for internal module mappings + _alias(['exec', 'grandpa', 'marker', 'session', 'slashing'].map((s) => `${s}::`), ''), // flattens tuples with one value, `(AccountId)` -> `AccountId` _flattenSingleTuple(), - // converts ::Type to Type, >::Proposal -> ::Proposal + // converts ::Type to Type, >::Proposal -> Proposal _removeColonPrefix() ]; @@ -68,11 +59,11 @@ function _findClosing (value: string, start: number): number { throw new Error(`Unable to find closing matching <> on '${value}' (start ${start})`); } -function _alias (src: string, dest: string): Mapper { +function _alias (src: string[], dest: string): Mapper { return (value: string): string => { - return value.replace( - new RegExp(src, 'g'), dest - ); + return src.reduce((value, src): string => { + return value.replace(new RegExp(src, 'g'), dest); + }, value); }; } @@ -157,25 +148,17 @@ function _removeTraits (): Mapper { // remove all whitespaces .replace(/\s/g, '') // anything `T::` to end up as `` - .replace(/T::/g, '') - // anything `Self::` to end up as `` - .replace(/Self::/g, '') - // `system::` with `` - basically we find `` - .replace(/system::/g, '') + .replace(/(T|Self|wasm)::/g, '') // replace `::` (whitespaces were removed above) - .replace(/::/g, '') + .replace(/<(T|Self)asTrait>::/g, '') // replace `::` (whitespaces were removed above) .replace(/::/g, '') - // replace `::` (whitespaces were removed above) - .replace(/::/g, '') // replace .replace(//g, 'Lookup') // replace `<...>::Type` .replace(/::Type/g, '') - // replace `wasm::*` eg. `wasm::PrefabWasmModule` - .replace(/wasm::/g, '') // `sr_std::marker::` - .replace(/sr_std::marker::/g, ''); + .replace(/(sp_std|sr_std|rstd)::/g, ''); }; } diff --git a/packages/types/src/known/overrides.ts b/packages/types/src/known/overrides.ts index 0b9d01171a..c681ff30a5 100644 --- a/packages/types/src/known/overrides.ts +++ b/packages/types/src/known/overrides.ts @@ -30,16 +30,15 @@ const TYPES_MODULES: Record = { // definition as applicable. (4 keys in substrate vs 5 in Polkadot/CC3). const TYPES_POLKADOT_VERSIONED: OverrideVersionedType[] = [ { - minmax: [1000, undefined], // from launch + minmax: [1000, undefined], types: { - // Indices optional, not in transaction Address: 'GenericAddress', BalanceLock: 'BalanceLockTo212', Keys: 'SessionKeys5' } }, { - minmax: [1003, undefined], // from launch + minmax: [1003, undefined], types: { // Indices optional, not in transaction Address: 'AccountId', diff --git a/yarn.lock b/yarn.lock index bd21ae6fb0..59eb1b7932 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1965,10 +1965,10 @@ dependencies: "@types/node" ">= 8" -"@polkadot/dev@^0.33.3": - version "0.33.3" - resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.33.3.tgz#a5ee8990ea240c655b0b1c065a53518d0fab3c86" - integrity sha512-AruWNAIAjbweoDUJAX4SSSgzbtsxZkociPAitcXBFul6XSU4eMJiyc68o0ZiQOXt/T9TWUjuVMSLEkcuNh536Q== +"@polkadot/dev@^0.33.5": + version "0.33.5" + resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.33.5.tgz#3327a1ee996092aa3921c314c642cafc58fd9027" + integrity sha512-S03kn/WFj9bHFIQ9EN5aoyCk2jORsAU3Ux9pg+2FnK5vf4Et9fFfEp0TKjjxJ+AoItalUhjvV13YGBkLThnm9w== dependencies: "@babel/cli" "^7.8.3" "@babel/core" "^7.8.3"