Adjust create imports (#2834)

* Adjust create imports

* Restore create root exports

* Adjust unsafe creation
This commit is contained in:
Jaco Greeff
2020-11-10 11:14:38 +01:00
committed by GitHub
parent 5cf585c8dd
commit af9437f80a
42 changed files with 50 additions and 51 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ import { ContractDisplayName, ChainProperties, SiField, SiLookupTypeId, SiType,
import { InterfaceTypes, TypeDef, TypeDefInfo } from '@polkadot/types/types';
import { assert, isUndefined } from '@polkadot/util';
import { TypeRegistry, withTypeString } from '@polkadot/types';
import { TypeRegistry, withTypeString } from '@polkadot/types/create';
interface PartialTypeSpec {
readonly type: SiLookupTypeId;
+2 -1
View File
@@ -5,7 +5,8 @@ import { SubmittableResult } from '@polkadot/api';
import { EventRecord } from '@polkadot/types/interfaces';
import { Codec, Registry, TypeDef } from '@polkadot/types/types';
import { Raw, createTypeUnsafe } from '@polkadot/types';
import { Raw } from '@polkadot/types';
import { createTypeUnsafe } from '@polkadot/types/create';
type ContractEvents = 'CodeStored' | 'ContractExecution' | 'Instantiated';
+1 -1
View File
@@ -8,7 +8,7 @@
import { Observable, from } from 'rxjs';
import { ApiRx } from '@polkadot/api/rx';
import MockProvider from '@polkadot/rpc-provider/mock';
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import { ExactDerive } from '.';
@@ -3,7 +3,7 @@
import { ApprovalFlag } from '@polkadot/types/interfaces';
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import { approvalFlagsToBools } from './approvalFlagsToBools';
+2 -1
View File
@@ -17,8 +17,9 @@ import { memo } from '@polkadot/api-derive/util';
import { Metadata, expandMetadata } from '@polkadot/metadata';
import { RpcCore } from '@polkadot/rpc-core';
import { WsProvider } from '@polkadot/rpc-provider';
import { Option, Raw, StorageKey, Text, TypeRegistry, u64 } from '@polkadot/types';
import { Option, Raw, StorageKey, Text, u64 } from '@polkadot/types';
import { DEFAULT_VERSION as EXTRINSIC_DEFAULT_VERSION } from '@polkadot/types/extrinsic/constants';
import { TypeRegistry } from '@polkadot/types/create';
import { unwrapStorageType } from '@polkadot/types/primitive/StorageKey';
import { assert, compactStripLength, logger, u8aToHex } from '@polkadot/util';
+2 -1
View File
@@ -10,7 +10,8 @@ import BN from 'bn.js';
import { Observable, Subscription, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { Metadata } from '@polkadot/metadata';
import { Text, TypeRegistry } from '@polkadot/types';
import { Text } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import { LATEST_EXTRINSIC_VERSION } from '@polkadot/types/extrinsic/Extrinsic';
import { getSpecAlias, getSpecTypes, getUpgradeVersion } from '@polkadot/types-known';
import { BN_ZERO, assert, logger, u8aEq, u8aToU8a } from '@polkadot/util';
+1 -1
View File
@@ -9,7 +9,7 @@ import { IExtrinsic, IMethod } from '@polkadot/types/types';
import { ApiPromise } from '@polkadot/api';
import { HeaderExtended } from '@polkadot/api-derive';
import { TestKeyringMap, createTestPairs } from '@polkadot/keyring/testingPairs';
import { createTypeUnsafe, TypeRegistry } from '@polkadot/types';
import { createTypeUnsafe, TypeRegistry } from '@polkadot/types/create';
import { SubmittableResult } from './';
+1 -1
View File
@@ -6,7 +6,7 @@ import { ApiOptions, SubmittableExtrinsic } from '../types';
import { createPair } from '@polkadot/keyring/pair';
import { createTestKeyring } from '@polkadot/keyring/testing';
import Mock from '@polkadot/rpc-provider/mock/index';
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import { hexToU8a } from '@polkadot/util';
import { SingleAccountSigner } from '../../test/util';
+1 -1
View File
@@ -7,7 +7,7 @@ import { Observable } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { createTestPairs } from '@polkadot/keyring/testingPairs';
import Mock from '@polkadot/rpc-provider/mock/index';
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import { SingleAccountSigner } from '../../test/util';
import { ApiRx } from '.';
+1 -1
View File
@@ -5,7 +5,7 @@ import { Storage } from '@polkadot/metadata/decorate/types';
import { Metadata, storageFromMeta } from '@polkadot/metadata';
import metaStatic from '@polkadot/metadata/static';
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import { extractStorageArgs } from './validate';
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import { MagicNumber, MAGIC_NUMBER } from './MagicNumber';
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import substrateData from './static';
import { Metadata } from './Metadata';
@@ -3,7 +3,7 @@
import { Constants } from '../types';
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import { Metadata } from '../../Metadata';
import rpcMetadata from '../../static';
@@ -4,7 +4,6 @@
import { Registry } from '@polkadot/types/types';
import { Constants, ConstantCodec, ModuleConstants } from '../types';
import { createTypeUnsafe } from '@polkadot/types/create';
import { hexToU8a, stringCamelCase } from '@polkadot/util';
import { Metadata } from '../../Metadata';
@@ -22,7 +21,7 @@ export function constantsFromMeta (registry: Registry, metadata: Metadata): Cons
result[stringCamelCase(name)] = moduleMetadata.constants.reduce((newModule: ModuleConstants, meta): ModuleConstants => {
// convert to the natural type as received
const type = meta.type.toString();
const codec: ConstantCodec = createTypeUnsafe(registry, type, [hexToU8a(meta.value.toHex())]);
const codec = registry.createType(type as 'Raw', hexToU8a(meta.value.toHex())) as unknown as ConstantCodec;
codec.meta = meta;
newModule[stringCamelCase(meta.name)] = codec;
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import { Metadata } from '../../Metadata';
import json from '../../static';
@@ -3,7 +3,7 @@
import BN from 'bn.js';
import { createTestPairs } from '@polkadot/keyring/testingPairs';
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import { Metadata } from '../../Metadata';
import metadataStatic from '../../static';
@@ -1,7 +1,8 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Text, TypeRegistry } from '@polkadot/types';
import { Text } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import { u8aToHex } from '@polkadot/util';
import createFunction from './createFunction';
@@ -7,8 +7,7 @@ import { Codec, Registry } from '@polkadot/types/types';
import BN from 'bn.js';
import { Raw } from '@polkadot/types/codec';
import { createTypeUnsafe } from '@polkadot/types/create';
import { StorageKey } from '@polkadot/types';
import { StorageKey } from '@polkadot/types/primitive';
import { assert, compactAddLength, compactStripLength, isNull, isUndefined, stringLowerFirst, u8aConcat } from '@polkadot/util';
import { xxhashAsU8a } from '@polkadot/util-crypto';
@@ -72,8 +71,8 @@ function createKeyDoubleMap (registry: Registry, itemFn: CreateItemFn, args: [Cr
const [key1, key2] = args;
const map = type.asDoubleMap;
const val1 = createTypeUnsafe(registry, map.key1.toString(), [key1]).toU8a();
const val2 = createTypeUnsafe(registry, map.key2.toString(), [key2]).toU8a();
const val1 = registry.createType(map.key1.toString() as 'Raw', key1).toU8a();
const val2 = registry.createType(map.key2.toString() as 'Raw', key2).toU8a();
// as per createKey, always add the length prefix (underlying it is Bytes)
return compactAddLength(u8aConcat(
@@ -94,7 +93,7 @@ function createKey (registry: Registry, itemFn: CreateItemFn, arg: CreateArgType
assert(!isUndefined(arg) && !isNull(arg), `${name.toString()} is a Map and requires one argument`);
param = createTypeUnsafe(registry, map.key.toString(), [arg]).toU8a();
param = registry.createType(map.key.toString() as 'Raw', arg).toU8a();
}
// StorageKey is a Bytes, so is length-prefixed
@@ -136,7 +135,7 @@ function extendHeadMeta (registry: Registry, { meta: { documentation, name, type
// meta fallback only applies to actual entry values, create one for head
(iterFn as IterFn).meta = registry.createType('StorageEntryMetadataLatest', {
documentation,
fallback: registry.createType('Bytes', createTypeUnsafe(registry, outputType).toHex()),
fallback: registry.createType('Bytes', registry.createType(outputType as 'Raw').toHex()),
modifier: registry.createType('StorageEntryModifierLatest', 1), // required
name,
type: registry.createType('StorageEntryTypeLatest', registry.createType('Type', type.isMap ? type.asMap.key : type.asDoubleMap.key1), 0)
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import { createTestPairs } from '@polkadot/keyring/testingPairs';
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import { u8aToHex } from '@polkadot/util';
import { Metadata } from '../../';
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import { stringToU8a } from '@polkadot/util';
import { xxhashAsU8a } from '@polkadot/util-crypto';
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import getStorage from './storage';
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import staticData from '../static';
import { Metadata } from '../Metadata';
+2 -1
View File
@@ -4,7 +4,8 @@
import { FunctionMetadataLatest, MetadataLatest } from '@polkadot/types/interfaces/metadata';
import { AnyJson, Registry } from '@polkadot/types/types';
import { Option, Text, Vec, u8 } from '@polkadot/types';
import { Option, Vec } from '@polkadot/types/codec';
import { Text, u8 } from '@polkadot/types/primitive';
interface ModuleMetadataTrimmed {
calls: Option<Vec<FunctionMetadataLatest>>;
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import substrateJson from './static-substrate.json';
import substrateData from './static';
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import substrateJson from './static-substrate.json';
import substrateData from './static';
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import substrateJson from './static-substrate.json';
import substrateData from './static';
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import substrateJson from './static-substrate.json';
import substrateData from './static';
+1 -1
View File
@@ -3,7 +3,7 @@
import { createTestPairs } from '@polkadot/keyring/testingPairs';
import MockProvider from '@polkadot/rpc-provider/mock';
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import { RpcCore } from '.';
+1 -1
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import MockProvider from '@polkadot/rpc-provider/mock';
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import { isFunction } from '@polkadot/util';
import { RpcCore } from '.';
+2 -1
View File
@@ -10,7 +10,8 @@ import memoizee from 'memoizee';
import { Observable, Observer } from 'rxjs';
import { publishReplay, refCount } from 'rxjs/operators';
import jsonrpc from '@polkadot/types/interfaces/jsonrpc';
import { Option, StorageKey, Vec, createClass, createTypeUnsafe } from '@polkadot/types';
import { Option, StorageKey, Vec } from '@polkadot/types';
import { createClass, createTypeUnsafe } from '@polkadot/types/create';
import { assert, hexToU8a, isFunction, isNull, isUndefined, logger, u8aToU8a } from '@polkadot/util';
import normalizer from './normalizer';
+1 -1
View File
@@ -3,7 +3,7 @@
import { DefinitionRpc } from '@polkadot/types/types';
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import { RpcCore } from '.';
+1 -1
View File
@@ -3,7 +3,7 @@
import { Observable, of } from 'rxjs';
import MockProvider from '@polkadot/rpc-provider/mock';
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import { RpcCore } from '.';
+1 -1
View File
@@ -3,7 +3,7 @@
import { ProviderInterfaceEmitted } from '../types';
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import Mock from './';
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/rpc-provider authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import Mock from './';
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/rpc-provider authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import Mock from './';
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/rpc-provider authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import Mock from './';
+1 -2
View File
@@ -5,8 +5,7 @@ import Handlebars from 'handlebars';
import { TypeDef, TypeDefInfo } from '@polkadot/types/create/types';
import { getTypeDef } from '@polkadot/types/create';
import { paramsNotation } from '@polkadot/types/codec/utils';
import { getTypeDef, paramsNotation } from '@polkadot/types/create';
import { isString } from '@polkadot/util';
import { setImports, ModuleTypes, TypeImports } from './imports';
-3
View File
@@ -27,6 +27,3 @@ export { default as Int } from './Int';
export { default as Raw } from './Raw';
export { default as UInt } from './UInt';
export { default as U8aFixed } from './U8aFixed';
// Type management helper functions
export * from './utils/encodeTypes';
-2
View File
@@ -7,5 +7,3 @@ export { compareSet } from './compareSet';
export { decodeU8a } from './decodeU8a';
export { mapToTypeMap } from './mapToTypeMap';
export { typeToConstructor } from './typeToConstructor';
export * from './encodeTypes';
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { TypeDef, TypeDefInfo } from '../../create/types';
import { TypeDef, TypeDefInfo } from './types';
import { assert, isNumber, isUndefined } from '@polkadot/util';
+1
View File
@@ -5,6 +5,7 @@ import { createType } from './createType';
export * from './createClass';
export * from './createType';
export * from './encodeTypes';
export * from './getTypeDef';
export * from './registry';
export * from './typeSplit';
@@ -3,7 +3,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types/create';
import json from '../../json/StorageChangeSet.001.json';