Adjust interfaces for cleaner esnext usage (#2833)

* Adjust interfaces for cleaner esnext usage

* Swap out esnext
This commit is contained in:
Jaco Greeff
2020-11-09 23:17:52 +01:00
committed by GitHub
parent 8993844739
commit e6dbbfae34
82 changed files with 242 additions and 348 deletions
+1 -1
View File
@@ -31,7 +31,7 @@
"@babel/runtime": "^7.12.1",
"@polkadot/api": "2.6.2-1",
"@polkadot/types": "2.6.2-1",
"@polkadot/util": "^4.0.2-5",
"@polkadot/util": "^4.0.2-7",
"bn.js": "^5.1.3",
"rxjs": "^6.6.3"
}
+3 -3
View File
@@ -33,14 +33,14 @@
"@polkadot/api": "2.6.2-1",
"@polkadot/rpc-core": "2.6.2-1",
"@polkadot/types": "2.6.2-1",
"@polkadot/util": "^4.0.2-5",
"@polkadot/util-crypto": "^4.0.2-5",
"@polkadot/util": "^4.0.2-7",
"@polkadot/util-crypto": "^4.0.2-7",
"bn.js": "^5.1.3",
"memoizee": "^0.4.14",
"rxjs": "^6.6.3"
},
"devDependencies": {
"@polkadot/keyring": "^4.0.2-5",
"@polkadot/keyring": "^4.0.2-7",
"@polkadot/rpc-provider": "2.6.2-1"
}
}
+3 -3
View File
@@ -30,14 +30,14 @@
"dependencies": {
"@babel/runtime": "^7.12.1",
"@polkadot/api-derive": "2.6.2-1",
"@polkadot/keyring": "^4.0.2-5",
"@polkadot/keyring": "^4.0.2-7",
"@polkadot/metadata": "2.6.2-1",
"@polkadot/rpc-core": "2.6.2-1",
"@polkadot/rpc-provider": "2.6.2-1",
"@polkadot/types": "2.6.2-1",
"@polkadot/types-known": "2.6.2-1",
"@polkadot/util": "^4.0.2-5",
"@polkadot/util-crypto": "^4.0.2-5",
"@polkadot/util": "^4.0.2-7",
"@polkadot/util-crypto": "^4.0.2-7",
"bn.js": "^5.1.3",
"eventemitter3": "^4.0.7",
"rxjs": "^6.6.3"
+1 -1
View File
@@ -1,9 +1,9 @@
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
/* eslint-disable */
import { Codec } from '@polkadot/types/types';
import { Vec } from '@polkadot/types/codec';
import { u16, u32, u64 } from '@polkadot/types/primitive';
import { Codec } from '@polkadot/types/types';
import { Balance, BalanceOf, BlockNumber, LockIdentifier, ModuleId, Moment, Perbill, Percent, Permill, RuntimeDbWeight, Weight } from '@polkadot/types/interfaces/runtime';
import { SessionIndex } from '@polkadot/types/interfaces/session';
import { EraIndex } from '@polkadot/types/interfaces/staking';
+1 -1
View File
@@ -1,9 +1,9 @@
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
/* eslint-disable */
import { AnyNumber, ITuple, Observable } from '@polkadot/types/types';
import { Option, U8aFixed, Vec } from '@polkadot/types/codec';
import { Bytes, Data, bool, u32, u64 } from '@polkadot/types/primitive';
import { AnyNumber, ITuple, Observable } from '@polkadot/types/types';
import { UncleEntryItem } from '@polkadot/types/interfaces/authorship';
import { BabeAuthorityWeight, MaybeRandomness, NextConfigDescriptor, Randomness } from '@polkadot/types/interfaces/babe';
import { AccountData, BalanceLock } from '@polkadot/types/interfaces/balances';
+2 -2
View File
@@ -1,10 +1,10 @@
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
/* eslint-disable */
import { AnyNumber, Codec, IExtrinsic, Observable } from '@polkadot/types/types';
import { Metadata } from '@polkadot/metadata';
import { HashMap, Json, Option, Vec } from '@polkadot/types/codec';
import { Bytes, Null, StorageKey, Text, bool, u32, u64 } from '@polkadot/types/primitive';
import { Metadata } from '@polkadot/types';
import { AnyNumber, Codec, IExtrinsic, Observable } from '@polkadot/types/types';
import { ExtrinsicOrHash, ExtrinsicStatus } from '@polkadot/types/interfaces/author';
import { EpochAuthorship } from '@polkadot/types/interfaces/babe';
import { BlockHash } from '@polkadot/types/interfaces/chain';
+1 -1
View File
@@ -1,9 +1,9 @@
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
/* eslint-disable */
import { AnyNumber, ITuple } from '@polkadot/types/types';
import { Compact, Option, U8aFixed, Vec } from '@polkadot/types/codec';
import { Bytes, Data, bool, u16, u32, u64 } from '@polkadot/types/primitive';
import { AnyNumber, ITuple } from '@polkadot/types/types';
import { BabeEquivocationProof } from '@polkadot/types/interfaces/babe';
import { MemberCount, ProposalIndex } from '@polkadot/types/interfaces/collective';
import { CodeHash, Gas, Schedule } from '@polkadot/types/interfaces/contracts';
+3 -2
View File
@@ -4,6 +4,7 @@
import { Constants, DecoratedMeta } from '@polkadot/metadata/decorate/types';
import { RpcInterface } from '@polkadot/rpc-core/types';
import { Call, Hash, RuntimeVersion } from '@polkadot/types/interfaces';
import { StorageEntry } from '@polkadot/types/primitive/types';
import { AnyFunction, CallFunction, Codec, CodecArg as Arg, InterfaceTypes, Registry, RegistryTypes } from '@polkadot/types/types';
import { SubmittableExtrinsic } from '../submittable/types';
import { ApiInterfaceRx, ApiOptions, ApiTypes, DecorateMethod, DecoratedRpc, DecoratedRpcSection, PaginationOptions, QueryableConsts, QueryableModuleStorage, QueryableStorage, QueryableStorageEntry, QueryableStorageMulti, QueryableStorageMultiArg, SubmittableExtrinsicFunction, SubmittableExtrinsics, SubmittableModuleExtrinsics } from '../types';
@@ -16,9 +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, Text, TypeRegistry, u64 } from '@polkadot/types';
import { Option, Raw, StorageKey, Text, TypeRegistry, u64 } from '@polkadot/types';
import { DEFAULT_VERSION as EXTRINSIC_DEFAULT_VERSION } from '@polkadot/types/extrinsic/constants';
import StorageKey, { StorageEntry, unwrapStorageType } from '@polkadot/types/primitive/StorageKey';
import { unwrapStorageType } from '@polkadot/types/primitive/StorageKey';
import { assert, compactStripLength, logger, u8aToHex } from '@polkadot/util';
import { createSubmittable } from '../submittable';
+2 -1
View File
@@ -5,7 +5,8 @@ import { RpcInterface } from '@polkadot/rpc-core/types';
import { Hash, RuntimeVersion } from '@polkadot/types/interfaces';
import { ApiInterfaceRx, ApiTypes, DecoratedRpc, QueryableConsts, QueryableStorage, QueryableStorageMulti, SubmittableExtrinsics } from '../types';
import { Metadata, Text } from '@polkadot/types';
import { Metadata } from '@polkadot/metadata';
import { Text } from '@polkadot/types';
import { assertReturn } from '@polkadot/util';
import Init from './Init';
+3 -1
View File
@@ -9,7 +9,8 @@ import { VersionedRegistry } from './types';
import BN from 'bn.js';
import { Observable, Subscription, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { Metadata, Text, TypeRegistry } from '@polkadot/types';
import { Metadata } from '@polkadot/metadata';
import { Text, TypeRegistry } from '@polkadot/types';
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';
@@ -317,6 +318,7 @@ export default abstract class Init<ApiType extends ApiTypes> extends Decorate<Ap
const error = new Error(`FATAL: Unable to initialize the API: ${(_error as Error).message}`);
l.error(error);
l.error(_error);
this.emit('error', error);
}
+1 -1
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import { Constants } from '@polkadot/metadata/decorate/types';
import { Metadata } from '@polkadot/types';
import { Metadata } from '@polkadot/metadata';
import { Registry } from '@polkadot/types/types';
import BN from 'bn.js';
+8
View File
@@ -0,0 +1,8 @@
// Copyright 2017-2020 @polkadot/api authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { detectPackage } from '@polkadot/util';
// FIXME This really should be `import(...).then(...)`, but need to check rejections
// eslint-disable-next-line @typescript-eslint/no-var-requires
detectPackage(require('./package.json'), typeof __dirname !== 'undefined' && __dirname);
+1 -5
View File
@@ -1,11 +1,7 @@
// Copyright 2017-2020 @polkadot/api authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { detectPackage } from '@polkadot/util';
// FIXME This really should be `import(...).then(...)`, but need to check rejections
// eslint-disable-next-line @typescript-eslint/no-var-requires
detectPackage(require('./package.json'), typeof __dirname !== 'undefined' && __dirname);
import './detectPackage';
export { Keyring } from '@polkadot/keyring';
export { WsProvider } from '@polkadot/rpc-provider/ws';
+1 -1
View File
@@ -8,7 +8,7 @@ import type BN from 'bn.js';
import { DeriveCustom, ExactDerive } from '@polkadot/api-derive';
import { RpcInterface } from '@polkadot/rpc-core/types';
import { ProviderInterface, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
import { Metadata } from '@polkadot/types';
import { Metadata } from '@polkadot/metadata';
import { Hash, RuntimeVersion } from '@polkadot/types/interfaces';
import { DefinitionRpc, DefinitionRpcSub, Signer, SignatureOptions, Registry, RegisteredTypes } from '@polkadot/types/types';
+4 -3
View File
@@ -1,11 +1,12 @@
// Copyright 2017-2020 @polkadot/api authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Observable } from 'rxjs';
import { u64 } from '@polkadot/types';
import { Hash } from '@polkadot/types/interfaces';
import { AnyFunction, Callback, Codec, CodecArg } from '@polkadot/types/types';
import StorageKey, { StorageEntry } from '@polkadot/types/primitive/StorageKey';
import { StorageEntry } from '@polkadot/types/primitive/types';
import { Observable } from 'rxjs';
import { StorageKey, u64 } from '@polkadot/types';
import { ApiTypes, MethodResult, ObsInnerType, PaginationOptions, PromiseOrObs, UnsubscribePromise } from './base';
+2 -2
View File
@@ -3,9 +3,9 @@
import { EventRecord, ExtrinsicStatus, H256, SignedBlock } from '@polkadot/types/interfaces';
import l from './logging';
import { l } from './logging';
export default function filterEvents (extHash: H256, { block: { extrinsics, header } }: SignedBlock, allEvents: EventRecord[], status: ExtrinsicStatus): EventRecord[] | undefined {
export function filterEvents (extHash: H256, { block: { extrinsics, header } }: SignedBlock, allEvents: EventRecord[], status: ExtrinsicStatus): EventRecord[] | undefined {
// extrinsics to hashes
const myHash = extHash.toHex();
const allHashes = extrinsics.map((ext): string => ext.hash.toHex());
+4 -3
View File
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
export * from './decorate';
export { default as filterEvents } from './filterEvents';
export { default as isKeyringPair } from './isKeyringPair';
export { default as l } from './logging';
export { filterEvents } from './filterEvents';
export { isKeyringPair } from './isKeyringPair';
export { l } from './logging';
+1 -1
View File
@@ -6,6 +6,6 @@ import { IKeyringPair } from '@polkadot/types/types';
import { isFunction } from '@polkadot/util';
export default function isKeyringPair (account: string | IKeyringPair | AccountId | Address): account is IKeyringPair {
export function isKeyringPair (account: string | IKeyringPair | AccountId | Address): account is IKeyringPair {
return isFunction((account as IKeyringPair).sign);
}
+1 -3
View File
@@ -3,6 +3,4 @@
import { logger } from '@polkadot/util';
const l = logger('api/util');
export default l;
export const l = logger('api/util');
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2019 @polkadot/api authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
import { StorageEntry } from '@polkadot/types/primitive/types';
import { Type } from '@polkadot/types';
import { assert, isUndefined } from '@polkadot/util';
+3 -3
View File
@@ -31,11 +31,11 @@
"@babel/runtime": "^7.12.1",
"@polkadot/types": "2.6.2-1",
"@polkadot/types-known": "2.6.2-1",
"@polkadot/util": "^4.0.2-5",
"@polkadot/util-crypto": "^4.0.2-5",
"@polkadot/util": "^4.0.2-7",
"@polkadot/util-crypto": "^4.0.2-7",
"bn.js": "^5.1.3"
},
"devDependencies": {
"@polkadot/keyring": "^4.0.2-5"
"@polkadot/keyring": "^4.0.2-7"
}
}
+1 -1
View File
@@ -5,7 +5,7 @@ import { AnyNumber, Registry } from '@polkadot/types/types';
import { assert } from '@polkadot/util';
import U32 from '@polkadot/types/primitive/U32';
import { u32 as U32 } from '@polkadot/types/primitive';
export const MAGIC_NUMBER = 0x6174656d; // `meta`, reversed for Little Endian encoding
+1 -1
View File
@@ -4,7 +4,7 @@
import { MetadataAll, MetadataLatest, MetadataV9, MetadataV10, MetadataV11, MetadataV12 } from '@polkadot/types/interfaces/metadata';
import { Registry } from '@polkadot/types/types';
import Struct from '@polkadot/types/codec/Struct';
import { Struct } from '@polkadot/types/codec';
import { assert } from '@polkadot/util';
import { MagicNumber } from './MagicNumber';
@@ -3,8 +3,9 @@
import { Constants } from '../types';
import { Metadata, TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types';
import { Metadata } from '../../Metadata';
import rpcMetadata from '../../static';
import rpcMetadataV10 from '../../v10/static';
import { constantsFromMeta } from './fromMetadata';
@@ -7,7 +7,7 @@ import { Constants, ConstantCodec, ModuleConstants } from '../types';
import { createTypeUnsafe } from '@polkadot/types/create';
import { hexToU8a, stringCamelCase } from '@polkadot/util';
import { Metadata } from '../..';
import { Metadata } from '../../Metadata';
/** @internal */
export function constantsFromMeta (registry: Registry, metadata: Metadata): Constants {
@@ -7,7 +7,7 @@ import { AnyJson, CallFunction, Registry, RegistryMetadataCall } from '@polkadot
import { assert, stringCamelCase } from '@polkadot/util';
/** @internal */
export default function createDescriptor (registry: Registry, section: string, callIndex: Uint8Array, callMetadata: RegistryMetadataCall): CallFunction {
export default function createUnchecked (registry: Registry, section: string, callIndex: Uint8Array, callMetadata: RegistryMetadataCall): CallFunction {
const expectedArgs = callMetadata.args;
const funcName = stringCamelCase(callMetadata.name);
@@ -1,8 +1,9 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Metadata, TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types';
import { Metadata } from '../../Metadata';
import json from '../../static';
import { extrinsicsFromMeta } from './fromMetadata';
@@ -3,8 +3,9 @@
import BN from 'bn.js';
import { createTestPairs } from '@polkadot/keyring/testingPairs';
import { Metadata, TypeRegistry } from '@polkadot/types';
import { TypeRegistry } from '@polkadot/types';
import { Metadata } from '../../Metadata';
import metadataStatic from '../../static';
import { extrinsicsFromMeta } from './fromMetadata';
+1 -1
View File
@@ -4,7 +4,7 @@
import { TypeRegistry } from '@polkadot/types/create';
import { u8aToHex } from '@polkadot/util';
import { Metadata } from '..';
import { Metadata } from '../Metadata';
import json from '../static';
import { constantsFromMeta, extrinsicsFromMeta, storageFromMeta } from './';
+1 -1
View File
@@ -6,7 +6,7 @@ import { DecoratedMeta } from './types';
import { assert } from '@polkadot/util';
import { Metadata } from '..';
import { Metadata } from '../Metadata';
import { constantsFromMeta } from './consts/fromMetadata';
import { extrinsicsFromMeta } from './extrinsics/fromMetadata';
import { storageFromMeta } from './storage/fromMetadata';
@@ -2,13 +2,14 @@
// SPDX-License-Identifier: Apache-2.0
import { StorageEntryMetadataLatest } from '@polkadot/types/interfaces/metadata';
import { StorageEntry } from '@polkadot/types/primitive/types';
import { Codec, Registry } from '@polkadot/types/types';
import BN from 'bn.js';
import { Compact, Raw } from '@polkadot/types/codec';
import { Raw } from '@polkadot/types/codec';
import { createTypeUnsafe } from '@polkadot/types/create';
import StorageKey, { StorageEntry } from '@polkadot/types/primitive/StorageKey';
import { assert, compactStripLength, isNull, isUndefined, stringLowerFirst, u8aConcat } from '@polkadot/util';
import { StorageKey } from '@polkadot/types';
import { assert, compactAddLength, compactStripLength, isNull, isUndefined, stringLowerFirst, u8aConcat } from '@polkadot/util';
import { xxhashAsU8a } from '@polkadot/util-crypto';
import getHasher, { HasherFunction } from './getHasher';
@@ -75,7 +76,7 @@ function createKeyDoubleMap (registry: Registry, itemFn: CreateItemFn, args: [Cr
const val2 = createTypeUnsafe(registry, map.key2.toString(), [key2]).toU8a();
// as per createKey, always add the length prefix (underlying it is Bytes)
return Compact.addLengthPrefix(u8aConcat(
return compactAddLength(u8aConcat(
createPrefixedKey(itemFn),
hasher1(val1),
hasher2(val2)
@@ -97,7 +98,7 @@ function createKey (registry: Registry, itemFn: CreateItemFn, arg: CreateArgType
}
// StorageKey is a Bytes, so is length-prefixed
return Compact.addLengthPrefix(u8aConcat(
return compactAddLength(u8aConcat(
createPrefixedKey(itemFn),
param.length
? hasher(param)
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
import { StorageEntry } from '@polkadot/types/primitive/types';
import { Registry } from '@polkadot/types/types';
import { Storage } from '../types';
@@ -1,11 +1,10 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { StorageEntryMetadataLatest } from '@polkadot/types/interfaces/metadata';
import { StorageEntryMetadataLatest } from '@polkadot/types/interfaces';
import { StorageEntry } from '@polkadot/types/primitive/types';
import { Registry } from '@polkadot/types/types';
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
import createFunction from './createFunction';
interface SubstrateMetadata {
+1 -1
View File
@@ -3,7 +3,7 @@
import { AugmentedConst, QueryableConsts, QueryableModuleConsts } from '@polkadot/api/types/consts';
import { Codec, ModulesWithCalls } from '@polkadot/types/types';
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
import { StorageEntry } from '@polkadot/types/primitive/types';
export interface ModuleStorage {
[key: string]: StorageEntry;
+1 -1
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import { Codec } from '@polkadot/types/types';
import Vec from '@polkadot/types/codec/Vec';
import { Vec } from '@polkadot/types/codec';
export interface MetadataInterface<Modules extends Codec> extends Codec {
modules: Vec<Modules>;
+1 -1
View File
@@ -7,7 +7,7 @@ import { MetadataInterface } from '../types';
import { unwrapStorageType } from '@polkadot/types/primitive/StorageKey';
import getUniqTypes from './getUniqTypes';
import { Metadata } from '..';
import { Metadata } from '../Metadata';
/** @internal */
export function decodeLatestSubstrate<Modules extends Codec> (registry: Registry, version: number, rpcData: string, staticSubstrate: Record<string, unknown>): void {
@@ -4,7 +4,7 @@
import { TypeRegistry } from '@polkadot/types';
import staticData from '../static';
import { Metadata } from '..';
import { Metadata } from '../Metadata';
describe('toCallsOnly', (): void => {
const registry = new TypeRegistry();
+2 -2
View File
@@ -32,11 +32,11 @@
"@polkadot/metadata": "2.6.2-1",
"@polkadot/rpc-provider": "2.6.2-1",
"@polkadot/types": "2.6.2-1",
"@polkadot/util": "^4.0.2-5",
"@polkadot/util": "^4.0.2-7",
"memoizee": "^0.4.14",
"rxjs": "^6.6.3"
},
"devDependencies": {
"@polkadot/keyring": "^4.0.2-5"
"@polkadot/keyring": "^4.0.2-7"
}
}
+5 -5
View File
@@ -30,15 +30,15 @@
"dependencies": {
"@babel/runtime": "^7.12.1",
"@polkadot/types": "2.6.2-1",
"@polkadot/util": "^4.0.2-5",
"@polkadot/util-crypto": "^4.0.2-5",
"@polkadot/x-fetch": "^4.0.2-5",
"@polkadot/x-ws": "^4.0.2-5",
"@polkadot/util": "^4.0.2-7",
"@polkadot/util-crypto": "^4.0.2-7",
"@polkadot/x-fetch": "^4.0.2-7",
"@polkadot/x-ws": "^4.0.2-7",
"bn.js": "^5.1.3",
"eventemitter3": "^4.0.7"
},
"devDependencies": {
"@polkadot/keyring": "^4.0.2-5",
"@polkadot/keyring": "^4.0.2-7",
"@polkadot/metadata": "2.6.2-1",
"mock-socket": "^9.0.3",
"nock": "^13.0.4"
+1 -1
View File
@@ -42,7 +42,7 @@
"@polkadot/metadata": "2.6.2-1",
"@polkadot/rpc-provider": "2.6.2-1",
"@polkadot/types": "2.6.2-1",
"@polkadot/util": "^4.0.2-5",
"@polkadot/util": "^4.0.2-7",
"handlebars": "^4.7.6",
"websocket": "^1.0.32",
"yargs": "^16.1.0"
@@ -20,6 +20,7 @@ describe('getSimilarTypes', (): void => {
genericTypes: {},
ignoredTypes: [],
localTypes: {},
metadataTypes: {},
primitiveTypes: {},
typeToModule: {},
typesTypes: {}
@@ -13,6 +13,7 @@ describe('formatType', (): void => {
genericTypes: {},
ignoredTypes: [],
localTypes: {},
metadataTypes: {},
primitiveTypes: {},
typeToModule: {},
typesTypes: {}
+5 -11
View File
@@ -20,8 +20,6 @@ interface This {
}[]
}
const TYPES_NON_PRIMITIVE = ['Metadata'];
export const HEADER = (type: 'chain' | 'defs'): string => `// Auto-generated via \`yarn polkadot-types-from-${type}\`, do not edit\n/* eslint-disable */\n\n`;
Handlebars.registerPartial({
@@ -34,8 +32,8 @@ Handlebars.registerHelper({
const { imports, types } = this as unknown as This;
const defs = [
{
file: '@polkadot/types/types',
types: Object.keys(imports.typesTypes)
file: '@polkadot/metadata',
types: Object.keys(imports.metadataTypes)
},
{
file: '@polkadot/types/codec',
@@ -53,15 +51,11 @@ Handlebars.registerHelper({
},
{
file: '@polkadot/types/primitive',
types: Object
.keys(imports.primitiveTypes)
.filter((name) => !TYPES_NON_PRIMITIVE.includes(name))
types: Object.keys(imports.primitiveTypes)
},
{
file: '@polkadot/types',
types: Object
.keys(imports.primitiveTypes)
.filter((name) => TYPES_NON_PRIMITIVE.includes(name))
file: '@polkadot/types/types',
types: Object.keys(imports.typesTypes)
},
...types
];
+6 -2
View File
@@ -28,6 +28,7 @@ export interface TypeImports {
ignoredTypes: string[]; // No need to import these types
localTypes: TypeExistMap; // `import {} from '../something'`
primitiveTypes: TypeExist; // `import {} from '@polkadot/types/primitive`
metadataTypes: TypeExist; // `import {} from '@polkadot/metadata`
typesTypes: TypeExist; // `import {} from '@polkadot/types/types`
definitions: Record<string, ModuleTypes>; // all definitions
typeToModule: Record<string, string>;
@@ -37,20 +38,22 @@ export interface TypeImports {
// imports in the output file, dep-duped and sorted
/** @internal */
export function setImports (allDefs: Record<string, ModuleTypes>, imports: TypeImports, types: string[]): void {
const { codecTypes, extrinsicTypes, genericTypes, ignoredTypes, localTypes, primitiveTypes, typesTypes } = imports;
const { codecTypes, extrinsicTypes, genericTypes, ignoredTypes, localTypes, metadataTypes, primitiveTypes, typesTypes } = imports;
types.forEach((type): void => {
if (ignoredTypes.includes(type)) {
// do nothing
} else if (['AnyNumber', 'CallFunction', 'Codec', 'IExtrinsic', 'ITuple'].includes(type)) {
typesTypes[type] = true;
} else if (type === 'Metadata') {
metadataTypes[type] = true;
} else if ((codecClasses as Record<string, unknown>)[type]) {
codecTypes[type] = true;
} else if ((extrinsicClasses as Record<string, unknown>)[type]) {
extrinsicTypes[type] = true;
} else if ((genericClasses as Record<string, unknown>)[type]) {
genericTypes[type] = true;
} else if ((primitiveClasses as Record<string, unknown>)[type] || type === 'Metadata') {
} else if ((primitiveClasses as Record<string, unknown>)[type]) {
primitiveTypes[type] = true;
} else if (type.includes('<') || type.includes('(') || (type.includes('[') && !type.includes('|'))) {
// If the type is a bit special (tuple, fixed u8, nested type...), then we
@@ -118,6 +121,7 @@ export function createImports (importDefinitions: Record<string, Record<string,
return local;
}, {}),
metadataTypes: {},
primitiveTypes: {},
typeToModule,
typesTypes: {}
+1 -1
View File
@@ -30,7 +30,7 @@
"dependencies": {
"@babel/runtime": "^7.12.1",
"@polkadot/types": "2.6.2-1",
"@polkadot/util": "^4.0.2-5",
"@polkadot/util": "^4.0.2-7",
"bn.js": "^5.1.3"
},
"devDependencies": {
+3 -3
View File
@@ -30,15 +30,15 @@
"dependencies": {
"@babel/runtime": "^7.12.1",
"@polkadot/metadata": "2.6.2-1",
"@polkadot/util": "^4.0.2-5",
"@polkadot/util-crypto": "^4.0.2-5",
"@polkadot/util": "^4.0.2-7",
"@polkadot/util-crypto": "^4.0.2-7",
"@types/bn.js": "^4.11.6",
"bn.js": "^5.1.3",
"memoizee": "^0.4.14",
"rxjs": "^6.6.3"
},
"devDependencies": {
"@polkadot/keyring": "^4.0.2-5",
"@polkadot/keyring": "^4.0.2-7",
"@types/memoizee": "^0.4.4"
}
}
+3 -4
View File
@@ -4,9 +4,8 @@
import { H256 } from '../interfaces/runtime';
import { AnyJson, Codec, Registry } from '../types';
import { u8aConcat, u8aToHex } from '@polkadot/util';
import { compactToU8a, u8aConcat, u8aToHex } from '@polkadot/util';
import Compact from './Compact';
import { compareArray } from './utils';
/**
@@ -31,7 +30,7 @@ export default abstract class AbstractArray<T extends Codec> extends Array<T> im
public get encodedLength (): number {
return this.reduce((total, raw): number => {
return total + raw.encodedLength;
}, Compact.encodeU8a(this.length).length);
}, compactToU8a(this.length).length);
}
/**
@@ -124,7 +123,7 @@ export default abstract class AbstractArray<T extends Codec> extends Array<T> im
return isBare
? u8aConcat(...encoded)
: u8aConcat(
Compact.encodeU8a(this.length),
compactToU8a(this.length),
...encoded
);
}
+4 -5
View File
@@ -4,9 +4,8 @@
import { H256 } from '../interfaces/runtime';
import { AnyJson, Constructor, Codec, InterfaceTypes, Registry } from '../types';
import { isHex, hexToU8a, isU8a, logger, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
import { isHex, hexToU8a, isU8a, logger, u8aConcat, u8aToHex, u8aToU8a, compactFromU8a, compactToU8a } from '@polkadot/util';
import Compact from './Compact';
import { compareSet, decodeU8a, typeToConstructor } from './utils';
const l = logger('BTreeSet');
@@ -14,7 +13,7 @@ const l = logger('BTreeSet');
/** @internal */
function decodeSetFromU8a<V extends Codec = Codec> (registry: Registry, ValClass: Constructor<V>, u8a: Uint8Array): Set<V> {
const output = new Set<V>();
const [offset, length] = Compact.decodeU8a(u8a);
const [offset, length] = compactFromU8a(u8a);
const types = [];
for (let i = 0; i < length.toNumber(); i++) {
@@ -103,7 +102,7 @@ export default class BTreeSet<V extends Codec = Codec> extends Set<V> implements
* @description The length of the value when encoded as a Uint8Array
*/
public get encodedLength (): number {
let len = Compact.encodeU8a(this.size).length;
let len = compactToU8a(this.size).length;
this.forEach((v: V) => {
len += v.encodedLength;
@@ -188,7 +187,7 @@ export default class BTreeSet<V extends Codec = Codec> extends Set<V> implements
const encoded = new Array<Uint8Array>();
if (!isBare) {
encoded.push(Compact.encodeU8a(this.size));
encoded.push(compactToU8a(this.size));
}
this.forEach((v: V) => {
-102
View File
@@ -7,104 +7,10 @@ import { TypeRegistry } from '../create';
import Moment from './Date';
import U32 from '../primitive/U32';
import Compact from './Compact';
import UInt from './UInt';
describe('Compact', (): void => {
const registry = new TypeRegistry();
describe('encodeU8a', (): void => {
it('encodes short u8', (): void => {
expect(
Compact.encodeU8a(18)
).toEqual(
new Uint8Array([18 << 2])
);
});
it('encodes max u8 values', (): void => {
expect(
Compact.encodeU8a(new (UInt.with(32))(registry, 63))
).toEqual(
new Uint8Array([0b11111100])
);
});
it('encodes basic u16 value', (): void => {
expect(
Compact.encodeU8a(511)
).toEqual(
new Uint8Array([0b11111101, 0b00000111])
);
});
it('encodes basic ua6 (not at edge)', (): void => {
expect(
Compact.encodeU8a(111)
).toEqual(
new Uint8Array([0xbd, 0x01])
);
});
it('encodes basic u32 values (short)', (): void => {
expect(
Compact.encodeU8a(0xffff)
).toEqual(
new Uint8Array([254, 255, 3, 0])
);
});
it('encodes basic u32 values (full)', (): void => {
expect(
Compact.encodeU8a(0xfffffff9)
).toEqual(
new Uint8Array([3, 249, 255, 255, 255])
);
});
it('encondes a large balance', (): void => {
expect(
Compact.encodeU8a(registry.createType('Balance', '0x5af3107a4000'))
).toEqual(
new Uint8Array([
3 + ((6 - 4) << 2),
0x00, 0x40, 0x7a, 0x10, 0xf3, 0x5a
])
);
});
});
describe('decodeU8a', (): void => {
it('decoded u8 value', (): void => {
expect(
Compact.decodeU8a(new Uint8Array([0b11111100]), 32)
).toEqual([1, new BN(63)]);
});
it('decodes from same u16 encoded value', (): void => {
expect(
Compact.decodeU8a(new Uint8Array([0b11111101, 0b00000111]), 32)
).toEqual([2, new BN(511)]);
});
it('decodes from same u32 encoded value (short)', (): void => {
expect(
Compact.decodeU8a(new Uint8Array([254, 255, 3, 0]), 32)
).toEqual([4, new BN(0xffff)]);
});
it('decodes from same u32 encoded value (full)', (): void => {
expect(
Compact.decodeU8a(new Uint8Array([3, 249, 255, 255, 255]), 32)
).toEqual([5, new BN(0xfffffff9)]);
});
it('decodes from same u32 as u64 encoded value (full, default)', (): void => {
expect(
Compact.decodeU8a(new Uint8Array([3, 249, 255, 255, 255]), 64)
).toEqual([5, new BN(0xfffffff9)]);
});
});
describe('constructor', (): void => {
it('has support for BigInt', (): void => {
expect(
@@ -170,12 +76,4 @@ describe('Compact', (): void => {
expect(new (Compact.with('u128'))(registry, 12345678987654321n).toBigInt() === 12345678987654321n).toBe(true);
});
});
describe('helpers', (): void => {
it('correctly adds the length prefix', (): void => {
expect(
Compact.addLengthPrefix(Uint8Array.from([12, 13]))
).toEqual(Uint8Array.from([2 << 2, 12, 13]));
});
});
});
+3 -21
View File
@@ -5,8 +5,7 @@ import { H256 } from '@polkadot/types/interfaces';
import { AnyJson, AnyNumber, Codec, Constructor, ICompact, InterfaceTypes, Registry } from '../types';
import BN from 'bn.js';
import { compactAddLength, compactFromU8a, compactStripLength, compactToU8a, isBigInt, isBn, isNumber, isString } from '@polkadot/util';
import { DEFAULT_BITLENGTH } from '@polkadot/util/compact/defaults';
import { compactFromU8a, compactToU8a, isBigInt, isBn, isNumber, isString } from '@polkadot/util';
import { typeToConstructor } from './utils';
import { UIntBitLength } from './AbstractInt';
@@ -46,23 +45,6 @@ export default class Compact<T extends CompactEncodable> implements ICompact<T>
};
}
/**
* Prepend a Uint8Array with its compact length.
*
* @param u8a - The Uint8Array to be prefixed
*/
public static addLengthPrefix = compactAddLength;
public static decodeU8a = compactFromU8a;
public static encodeU8a = compactToU8a;
public static stripLengthPrefix (u8a: Uint8Array, bitLength: UIntBitLength = DEFAULT_BITLENGTH): Uint8Array {
const [, value] = compactStripLength(u8a, bitLength);
return value;
}
/** @internal */
public static decodeCompact<T extends CompactEncodable> (registry: Registry, Type: Constructor<T>, value: Compact<T> | AnyNumber): CompactEncodable {
if (value instanceof Compact) {
@@ -71,7 +53,7 @@ export default class Compact<T extends CompactEncodable> implements ICompact<T>
return new Type(registry, value);
}
const [, _value] = Compact.decodeU8a(value, new Type(registry, 0).bitLength() as UIntBitLength);
const [, _value] = compactFromU8a(value, new Type(registry, 0).bitLength() as UIntBitLength);
return new Type(registry, _value);
}
@@ -177,7 +159,7 @@ export default class Compact<T extends CompactEncodable> implements ICompact<T>
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public toU8a (isBare?: boolean): Uint8Array {
return Compact.encodeU8a(this.#raw.toBn());
return compactToU8a(this.#raw.toBn());
}
/**
+4 -5
View File
@@ -4,9 +4,8 @@
import { H256 } from '../interfaces/runtime';
import { AnyJson, Constructor, Codec, InterfaceTypes, Registry } from '../types';
import { isHex, hexToU8a, isObject, isU8a, logger, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
import { isHex, hexToU8a, isObject, isU8a, logger, u8aConcat, u8aToHex, u8aToU8a, compactFromU8a, compactToU8a } from '@polkadot/util';
import Compact from './Compact';
import { compareMap, decodeU8a, typeToConstructor } from './utils';
const l = logger('Map');
@@ -14,7 +13,7 @@ const l = logger('Map');
/** @internal */
function decodeMapFromU8a<K extends Codec = Codec, V extends Codec = Codec> (registry: Registry, KeyClass: Constructor<K>, ValClass: Constructor<V>, u8a: Uint8Array): Map<K, V> {
const output = new Map<K, V>();
const [offset, length] = Compact.decodeU8a(u8a);
const [offset, length] = compactFromU8a(u8a);
const types = [];
for (let i = 0; i < length.toNumber(); i++) {
@@ -110,7 +109,7 @@ export default class CodecMap<K extends Codec = Codec, V extends Codec = Codec>
* @description The length of the value when encoded as a Uint8Array
*/
public get encodedLength (): number {
let len = Compact.encodeU8a(this.size).length;
let len = compactToU8a(this.size).length;
this.forEach((v: V, k: K) => {
len += v.encodedLength + k.encodedLength;
@@ -195,7 +194,7 @@ export default class CodecMap<K extends Codec = Codec, V extends Codec = Codec>
const encoded = new Array<Uint8Array>();
if (!isBare) {
encoded.push(Compact.encodeU8a(this.size));
encoded.push(compactToU8a(this.size));
}
this.forEach((v: V, k: K) => {
+1 -1
View File
@@ -96,7 +96,7 @@ export default class Raw extends Uint8Array implements IU8a {
}
/**
* @description Create a new subarray from the actual buffer. This is needed for compat reasons since a new Uint8Array gets returned here
* @description Create a new subarray from the actual buffer. (compat)
* @param begin The position to start at
* @param end The position to end at
*/
+2 -3
View File
@@ -3,9 +3,8 @@
import { Codec, Constructor, InterfaceTypes, Registry } from '../types';
import { assert, logger, u8aToU8a } from '@polkadot/util';
import { assert, compactFromU8a, logger, u8aToU8a } from '@polkadot/util';
import Compact from './Compact';
import { decodeU8a, typeToConstructor } from './utils';
import AbstractArray from './AbstractArray';
@@ -49,7 +48,7 @@ export default class Vec<T extends Codec> extends AbstractArray<T> {
}
const u8a = u8aToU8a(value);
const [offset, length] = Compact.decodeU8a(u8a);
const [offset, length] = compactFromU8a(u8a);
assert(length.lten(MAX_LENGTH), `Vec length ${length.toString()} exceeds ${MAX_LENGTH}`);
+2
View File
@@ -65,6 +65,8 @@ export function createTypeUnsafe<T extends Codec = Codec, K extends string = str
// it provides false warning which is more hinderance than help
return initType(registry, createClass<T, K>(registry, type), params); // , isPedantic);
} catch (error) {
l.error(error);
throw new Error(`createType(${type}):: ${(error as Error).message}`);
}
}
+2 -2
View File
@@ -6,7 +6,7 @@
import { ChainProperties, DispatchErrorModule, H256 } from '../interfaces/types';
import { CallFunction, Codec, Constructor, InterfaceTypes, RegistryError, RegistryTypes, Registry, RegistryMetadata, RegisteredTypes } from '../types';
import { extrinsicsFromMeta } from '@polkadot/metadata';
import { Metadata, extrinsicsFromMeta } from '@polkadot/metadata';
import { BN_ZERO, assert, assertReturn, formatBalance, isFunction, isString, isU8a, logger, stringCamelCase, u8aToHex } from '@polkadot/util';
import { blake2AsU8a } from '@polkadot/util-crypto';
@@ -128,7 +128,7 @@ export class TypeRegistry implements Registry {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const definitions: Record<string, { types: RegistryTypes }> = require('../interfaces/definitions');
this.#knownDefaults = { Json, Raw, ...baseTypes };
this.#knownDefaults = { Json, Metadata, Raw, ...baseTypes };
this.#knownDefinitions = definitions;
this.init();
+8
View File
@@ -0,0 +1,8 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { detectPackage } from '@polkadot/util';
// FIXME This really should be `import(...).then(...)`, but need to check rejections
// eslint-disable-next-line @typescript-eslint/no-var-requires
detectPackage(require('./package.json'), typeof __dirname !== 'undefined' && __dirname);
+3 -3
View File
@@ -6,7 +6,7 @@ import { EcdsaSignature, Ed25519Signature, ExtrinsicUnknown, ExtrinsicV4, Sr2551
import { Address, Balance, Call, Index } from '../interfaces/runtime';
import { AnyJson, AnyU8a, ArgsDef, Codec, ExtrinsicPayloadValue, IExtrinsic, IKeyringPair, InterfaceTypes, Registry, SignatureOptions } from '../types';
import { assert, isHex, isU8a, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
import { assert, compactAddLength, compactFromU8a, isHex, isU8a, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
import Base from '../codec/Base';
import Compact from '../codec/Compact';
@@ -203,7 +203,7 @@ export default class Extrinsic extends ExtrinsicBase implements IExtrinsic {
return Extrinsic._newFromValue(registry, new Uint8Array(), version);
}
const [offset, length] = Compact.decodeU8a(value);
const [offset, length] = compactFromU8a(value);
const total = offset + length.toNumber();
assert(total <= value.length, `Extrinsic: length less than remainder, expected at least ${total}, found ${value.length}`);
@@ -292,6 +292,6 @@ export default class Extrinsic extends ExtrinsicBase implements IExtrinsic {
return isBare
? encoded
: Compact.addLengthPrefix(encoded);
: compactAddLength(encoded);
}
}
+1 -5
View File
@@ -1,11 +1,7 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { detectPackage } from '@polkadot/util';
// FIXME This really should be `import(...).then(...)`, but need to check rejections
// eslint-disable-next-line @typescript-eslint/no-var-requires
detectPackage(require('./package.json'), typeof __dirname !== 'undefined' && __dirname);
import './detectPackage';
export * from './codec';
export * from './create';
-2
View File
@@ -1,8 +1,6 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { Metadata } from '@polkadot/metadata';
export * from './extrinsic';
export * from './generic';
export * from './primitive';
@@ -1,8 +1,8 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import { ITuple } from '@polkadot/types/types';
import { Enum, Option } from '@polkadot/types/codec';
import { ITuple } from '@polkadot/types/types';
import { AccountId, BlockNumber, Hash } from '@polkadot/types/interfaces/runtime';
/** @name UncleEntryItem */
+1 -1
View File
@@ -1,9 +1,9 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import { ITuple } from '@polkadot/types/types';
import { Enum, Option, Struct, U8aFixed, Vec } from '@polkadot/types/codec';
import { u32, u64 } from '@polkadot/types/primitive';
import { ITuple } from '@polkadot/types/types';
import { AuthorityId } from '@polkadot/types/interfaces/consensus';
import { Hash, Header } from '@polkadot/types/interfaces/runtime';
@@ -1,9 +1,9 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import { ITuple } from '@polkadot/types/types';
import { Enum, Struct, Vec } from '@polkadot/types/codec';
import { u32 } from '@polkadot/types/primitive';
import { ITuple } from '@polkadot/types/types';
import { AccountId, BlockNumber } from '@polkadot/types/interfaces/runtime';
/** @name CollectiveOrigin */
@@ -1,9 +1,9 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import { ITuple } from '@polkadot/types/types';
import { Enum, Option, Struct, Vec } from '@polkadot/types/codec';
import { Bytes, bool, u32 } from '@polkadot/types/primitive';
import { ITuple } from '@polkadot/types/types';
import { Vote, VoteThreshold } from '@polkadot/types/interfaces/elections';
import { AccountId, Balance, BlockNumber, Call, Hash } from '@polkadot/types/interfaces/runtime';
@@ -1,9 +1,9 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import { ITuple } from '@polkadot/types/types';
import { BTreeSet, Enum, Struct, Vec } from '@polkadot/types/codec';
import { Bytes, u32, u64 } from '@polkadot/types/primitive';
import { ITuple } from '@polkadot/types/types';
import { AuthorityId } from '@polkadot/types/interfaces/consensus';
import { AuthoritySignature } from '@polkadot/types/interfaces/imOnline';
import { BlockNumber, Hash } from '@polkadot/types/interfaces/runtime';
@@ -1,9 +1,9 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import { ITuple } from '@polkadot/types/types';
import { Enum, Option, Set, Struct, Vec } from '@polkadot/types/codec';
import { Data, u32 } from '@polkadot/types/primitive';
import { ITuple } from '@polkadot/types/types';
import { AccountId, Balance, H160 } from '@polkadot/types/interfaces/runtime';
/** @name IdentityFields */
@@ -1,9 +1,9 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import { ITuple } from '@polkadot/types/types';
import { Struct, U8aFixed, Vec } from '@polkadot/types/codec';
import { Bytes } from '@polkadot/types/primitive';
import { ITuple } from '@polkadot/types/types';
import { AccountId, Hash, Perbill } from '@polkadot/types/interfaces/runtime';
import { IdentificationTuple, SessionIndex } from '@polkadot/types/interfaces/session';
@@ -1,9 +1,9 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import { ITuple } from '@polkadot/types/types';
import { Enum, Option, Struct, U8aFixed, Vec } from '@polkadot/types/codec';
import { BitVec, Bytes, u32 } from '@polkadot/types/primitive';
import { ITuple } from '@polkadot/types/types';
import { Signature } from '@polkadot/types/interfaces/extrinsics';
import { AccountId, Balance, BlockNumber, Hash, ValidatorId } from '@polkadot/types/interfaces/runtime';
import { MembershipProof, SessionIndex } from '@polkadot/types/interfaces/session';
@@ -1,10 +1,10 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import { ITuple } from '@polkadot/types/types';
import { Compact, Enum, Int, Struct, U8aFixed, UInt, Vec } from '@polkadot/types/codec';
import { GenericAccountId, GenericAccountIndex, GenericBlock, GenericCall, GenericConsensusEngineId, GenericLookupSource, GenericMultiAddress } from '@polkadot/types/generic';
import { Bytes, DoNotConstruct, Null, StorageKey, u16, u32, u64, u8 } from '@polkadot/types/primitive';
import { ITuple } from '@polkadot/types/types';
import { AuthorityId } from '@polkadot/types/interfaces/consensus';
import { Signature } from '@polkadot/types/interfaces/extrinsics';
import { SystemOrigin } from '@polkadot/types/interfaces/system';
@@ -1,9 +1,9 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import { ITuple } from '@polkadot/types/types';
import { Option, Struct } from '@polkadot/types/codec';
import { Bytes, u32, u8 } from '@polkadot/types/primitive';
import { ITuple } from '@polkadot/types/types';
import { BlockNumber, Call, PalletsOrigin } from '@polkadot/types/interfaces/runtime';
/** @name Period */
@@ -1,9 +1,9 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import { ITuple } from '@polkadot/types/types';
import { Struct, Vec } from '@polkadot/types/codec';
import { Bytes, u32 } from '@polkadot/types/primitive';
import { ITuple } from '@polkadot/types/types';
import { AccountId, ValidatorId } from '@polkadot/types/interfaces/runtime';
import { Exposure } from '@polkadot/types/interfaces/staking';
@@ -1,9 +1,9 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import { ITuple } from '@polkadot/types/types';
import { Enum, Struct } from '@polkadot/types/codec';
import { u32 } from '@polkadot/types/primitive';
import { ITuple } from '@polkadot/types/types';
import { AccountId, Balance } from '@polkadot/types/interfaces/runtime';
/** @name Bid */
@@ -1,9 +1,9 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import { ITuple } from '@polkadot/types/types';
import { BTreeMap, Compact, Enum, Option, Struct, Vec } from '@polkadot/types/codec';
import { bool, u128, u16, u32 } from '@polkadot/types/primitive';
import { ITuple } from '@polkadot/types/types';
import { AccountId, Balance, BlockNumber, Moment, PerU16, Perbill } from '@polkadot/types/interfaces/runtime';
/** @name ActiveEraInfo */
+1 -1
View File
@@ -1,9 +1,9 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import { ITuple } from '@polkadot/types/types';
import { Option, Struct, U8aFixed, Vec } from '@polkadot/types/codec';
import { Bytes, StorageKey, Text, u32 } from '@polkadot/types/primitive';
import { ITuple } from '@polkadot/types/types';
import { Hash, StorageData } from '@polkadot/types/interfaces/runtime';
/** @name ApiId */
@@ -1,10 +1,10 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import { ITuple } from '@polkadot/types/types';
import { Compact, Enum, HashMap, Option, Result, Struct, U8aFixed, Vec } from '@polkadot/types/codec';
import { GenericEvent } from '@polkadot/types/generic';
import { Bytes, Text, bool, i32, u32, u64, u8 } from '@polkadot/types/primitive';
import { ITuple } from '@polkadot/types/types';
import { AccountData } from '@polkadot/types/interfaces/balances';
import { AccountId, BlockNumber, Digest, Hash, Index, Pays, Weight } from '@polkadot/types/interfaces/runtime';
@@ -1,9 +1,9 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import { ITuple } from '@polkadot/types/types';
import { Enum, Option, Struct, Vec } from '@polkadot/types/codec';
import { bool, u32 } from '@polkadot/types/primitive';
import { ITuple } from '@polkadot/types/types';
import { AccountId, Balance, BlockNumber, Hash } from '@polkadot/types/interfaces/runtime';
/** @name Bounty */
+4 -5
View File
@@ -3,9 +3,8 @@
import { AnyU8a, Registry } from '../types';
import { assert, isString, u8aConcat, u8aToU8a } from '@polkadot/util';
import { assert, compactFromU8a, compactToU8a, isString, u8aConcat, u8aToU8a } from '@polkadot/util';
import Compact from '../codec/Compact';
import Raw from '../codec/Raw';
/** @internal */
@@ -15,7 +14,7 @@ function decodeBitVecU8a (value?: Uint8Array): Uint8Array {
}
// handle all other Uint8Array inputs, these do have a length prefix which is the number of bits encoded
const [offset, length] = Compact.decodeU8a(value);
const [offset, length] = compactFromU8a(value);
const total = offset + Math.ceil(length.toNumber() / 8);
assert(total <= value.length, `BitVec: required length less than remainder, expected at least ${total}, found ${value.length}`);
@@ -47,7 +46,7 @@ export default class BitVec extends Raw {
* @description The length of the value when encoded as a Uint8Array
*/
public get encodedLength (): number {
return this.length + Compact.encodeU8a(this.bitLength()).length;
return this.length + compactToU8a(this.bitLength()).length;
}
/**
@@ -66,6 +65,6 @@ export default class BitVec extends Raw {
return isBare
? bitVec
: u8aConcat(Compact.encodeU8a(this.bitLength()), bitVec);
: u8aConcat(compactToU8a(this.bitLength()), bitVec);
}
}
+4 -5
View File
@@ -3,9 +3,8 @@
import { AnyU8a, Registry } from '../types';
import { assert, isString, isU8a, u8aToU8a } from '@polkadot/util';
import { assert, compactAddLength, compactFromU8a, compactToU8a, isString, isU8a, u8aToU8a } from '@polkadot/util';
import Compact from '../codec/Compact';
import Raw from '../codec/Raw';
// Bytes are used for things like on-chain code, so it has a healthy limit
@@ -18,7 +17,7 @@ function decodeBytesU8a (value: Uint8Array): Uint8Array {
}
// handle all other Uint8Array inputs, these do have a length prefix
const [offset, length] = Compact.decodeU8a(value);
const [offset, length] = compactFromU8a(value);
const total = offset + length.toNumber();
assert(length.lten(MAX_LENGTH), `Bytes length ${length.toString()} exceeds ${MAX_LENGTH}`);
@@ -56,7 +55,7 @@ export default class Bytes extends Raw {
* @description The length of the value when encoded as a Uint8Array
*/
public get encodedLength (): number {
return this.length + Compact.encodeU8a(this.length).length;
return this.length + compactToU8a(this.length).length;
}
/**
@@ -73,6 +72,6 @@ export default class Bytes extends Raw {
public toU8a (isBare?: boolean): Uint8Array {
return isBare
? super.toU8a(isBare)
: Compact.addLengthPrefix(this);
: compactAddLength(this);
}
}
+1 -11
View File
@@ -3,23 +3,13 @@
import { StorageEntryMetadataLatest, StorageEntryTypeLatest, StorageHasher } from '../interfaces/metadata';
import { AnyJson, AnyU8a, Codec, InterfaceTypes, Registry } from '../types';
import { StorageEntry } from './types';
import { assert, isFunction, isString, isU8a } from '@polkadot/util';
import { AllHashers } from '@polkadot/types/interfaces/metadata/definitions';
import Bytes from './Bytes';
export interface StorageEntry {
(arg?: any): Uint8Array;
iterKey?: (arg?: any) => Uint8Array & Codec;
keyPrefix: (arg?: any) => Uint8Array;
meta: StorageEntryMetadataLatest;
method: string;
prefix: string;
section: string;
toJSON: () => any;
}
interface Decoded {
key?: Uint8Array | string;
method?: string;
+3 -4
View File
@@ -4,9 +4,8 @@
import { H256 } from '../interfaces/runtime';
import { AnyU8a, Codec, Registry } from '../types';
import { assert, hexToU8a, isHex, isString, stringToU8a, u8aToString, u8aToHex } from '@polkadot/util';
import { assert, hexToU8a, isHex, isString, stringToU8a, u8aToString, u8aToHex, compactFromU8a, compactAddLength } from '@polkadot/util';
import Compact from '../codec/Compact';
import Raw from '../codec/Raw';
const MAX_LENGTH = 128 * 1024;
@@ -26,7 +25,7 @@ function decodeText (value?: null | Text | string | AnyU8a | { toString: () => s
return u8aToString(value);
}
const [offset, length] = Compact.decodeU8a(value);
const [offset, length] = compactFromU8a(value);
const total = offset + length.toNumber();
assert(length.lten(MAX_LENGTH), `Text length ${length.toString()} exceeds ${MAX_LENGTH}`);
@@ -152,6 +151,6 @@ export default class Text extends String implements Codec {
return isBare
? encoded
: Compact.addLengthPrefix(encoded);
: compactAddLength(encoded);
}
}
+16
View File
@@ -0,0 +1,16 @@
// Copyright 2017-2020 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { StorageEntryMetadataLatest } from '../interfaces/metadata';
import { Codec } from '../types';
export interface StorageEntry {
(arg?: any): Uint8Array;
iterKey?: (arg?: any) => Uint8Array & Codec;
keyPrefix: (arg?: any) => Uint8Array;
meta: StorageEntryMetadataLatest;
method: string;
prefix: string;
section: string;
toJSON: () => any;
}
+68 -68
View File
@@ -1753,7 +1753,7 @@ __metadata:
"@babel/runtime": ^7.12.1
"@polkadot/api": 2.6.2-1
"@polkadot/types": 2.6.2-1
"@polkadot/util": ^4.0.2-5
"@polkadot/util": ^4.0.2-7
bn.js: ^5.1.3
rxjs: ^6.6.3
languageName: unknown
@@ -1765,12 +1765,12 @@ __metadata:
dependencies:
"@babel/runtime": ^7.12.1
"@polkadot/api": 2.6.2-1
"@polkadot/keyring": ^4.0.2-5
"@polkadot/keyring": ^4.0.2-7
"@polkadot/rpc-core": 2.6.2-1
"@polkadot/rpc-provider": 2.6.2-1
"@polkadot/types": 2.6.2-1
"@polkadot/util": ^4.0.2-5
"@polkadot/util-crypto": ^4.0.2-5
"@polkadot/util": ^4.0.2-7
"@polkadot/util-crypto": ^4.0.2-7
bn.js: ^5.1.3
memoizee: ^0.4.14
rxjs: ^6.6.3
@@ -1783,14 +1783,14 @@ __metadata:
dependencies:
"@babel/runtime": ^7.12.1
"@polkadot/api-derive": 2.6.2-1
"@polkadot/keyring": ^4.0.2-5
"@polkadot/keyring": ^4.0.2-7
"@polkadot/metadata": 2.6.2-1
"@polkadot/rpc-core": 2.6.2-1
"@polkadot/rpc-provider": 2.6.2-1
"@polkadot/types": 2.6.2-1
"@polkadot/types-known": 2.6.2-1
"@polkadot/util": ^4.0.2-5
"@polkadot/util-crypto": ^4.0.2-5
"@polkadot/util": ^4.0.2-7
"@polkadot/util-crypto": ^4.0.2-7
bn.js: ^5.1.3
eventemitter3: ^4.0.7
rxjs: ^6.6.3
@@ -1889,17 +1889,17 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/keyring@npm:^4.0.2-5":
version: 4.0.2-5
resolution: "@polkadot/keyring@npm:4.0.2-5"
"@polkadot/keyring@npm:^4.0.2-7":
version: 4.0.2-7
resolution: "@polkadot/keyring@npm:4.0.2-7"
dependencies:
"@babel/runtime": ^7.12.1
"@polkadot/util": 4.0.2-5
"@polkadot/util-crypto": 4.0.2-5
"@polkadot/util": 4.0.2-7
"@polkadot/util-crypto": 4.0.2-7
peerDependencies:
"@polkadot/util": 4.0.2-5
"@polkadot/util-crypto": 4.0.2-5
checksum: 2bb9a76f28f582f410ca5703430be43e99b01c7384a3ddc7511020506fb2a7440739534d804e4a3bedaaf3ce89969670a12398ffe8e6ec8c74cb1a65219870f5
"@polkadot/util": 4.0.2-7
"@polkadot/util-crypto": 4.0.2-7
checksum: 21e0be9ccc5a5adac9ccfaa949c0ff80f1fbc4e171583de631c8a6055f3d91faaccd2dedcd07ee5fce93a4916528deb34dec557bfb2302129f4c09460851e1b6
languageName: node
linkType: hard
@@ -1908,21 +1908,21 @@ __metadata:
resolution: "@polkadot/metadata@workspace:packages/metadata"
dependencies:
"@babel/runtime": ^7.12.1
"@polkadot/keyring": ^4.0.2-5
"@polkadot/keyring": ^4.0.2-7
"@polkadot/types": 2.6.2-1
"@polkadot/types-known": 2.6.2-1
"@polkadot/util": ^4.0.2-5
"@polkadot/util-crypto": ^4.0.2-5
"@polkadot/util": ^4.0.2-7
"@polkadot/util-crypto": ^4.0.2-7
bn.js: ^5.1.3
languageName: unknown
linkType: soft
"@polkadot/networks@npm:4.0.2-5":
version: 4.0.2-5
resolution: "@polkadot/networks@npm:4.0.2-5"
"@polkadot/networks@npm:4.0.2-7":
version: 4.0.2-7
resolution: "@polkadot/networks@npm:4.0.2-7"
dependencies:
"@babel/runtime": ^7.12.1
checksum: 80bcdd6983e74e507bab734a78323b3706ebf470fc56109dcaf248dc9a13797818320d985ce4cf6cd91edcba086e55e2f6671163112ae899dd9b010859713ecd
checksum: 2502c6db7cb7f5a69b54b8eca7f26479b819cf85065df901ec9aea2979a2932521d5c1bb907ea07c68119adefd92bc91817c6d011e7c4098d3ba193d0fedc7b4
languageName: node
linkType: hard
@@ -1931,11 +1931,11 @@ __metadata:
resolution: "@polkadot/rpc-core@workspace:packages/rpc-core"
dependencies:
"@babel/runtime": ^7.12.1
"@polkadot/keyring": ^4.0.2-5
"@polkadot/keyring": ^4.0.2-7
"@polkadot/metadata": 2.6.2-1
"@polkadot/rpc-provider": 2.6.2-1
"@polkadot/types": 2.6.2-1
"@polkadot/util": ^4.0.2-5
"@polkadot/util": ^4.0.2-7
memoizee: ^0.4.14
rxjs: ^6.6.3
languageName: unknown
@@ -1946,13 +1946,13 @@ __metadata:
resolution: "@polkadot/rpc-provider@workspace:packages/rpc-provider"
dependencies:
"@babel/runtime": ^7.12.1
"@polkadot/keyring": ^4.0.2-5
"@polkadot/keyring": ^4.0.2-7
"@polkadot/metadata": 2.6.2-1
"@polkadot/types": 2.6.2-1
"@polkadot/util": ^4.0.2-5
"@polkadot/util-crypto": ^4.0.2-5
"@polkadot/x-fetch": ^4.0.2-5
"@polkadot/x-ws": ^4.0.2-5
"@polkadot/util": ^4.0.2-7
"@polkadot/util-crypto": ^4.0.2-7
"@polkadot/x-fetch": ^4.0.2-7
"@polkadot/x-ws": ^4.0.2-7
bn.js: ^5.1.3
eventemitter3: ^4.0.7
mock-socket: ^9.0.3
@@ -1980,7 +1980,7 @@ __metadata:
"@polkadot/metadata": 2.6.2-1
"@polkadot/rpc-provider": 2.6.2-1
"@polkadot/types": 2.6.2-1
"@polkadot/util": ^4.0.2-5
"@polkadot/util": ^4.0.2-7
"@types/websocket": ^1.0.1
"@types/yargs": ^15.0.9
handlebars: ^4.7.6
@@ -2001,7 +2001,7 @@ __metadata:
dependencies:
"@babel/runtime": ^7.12.1
"@polkadot/types": 2.6.2-1
"@polkadot/util": ^4.0.2-5
"@polkadot/util": ^4.0.2-7
"@types/bn.js": ^4.11.6
bn.js: ^5.1.3
languageName: unknown
@@ -2012,10 +2012,10 @@ __metadata:
resolution: "@polkadot/types@workspace:packages/types"
dependencies:
"@babel/runtime": ^7.12.1
"@polkadot/keyring": ^4.0.2-5
"@polkadot/keyring": ^4.0.2-7
"@polkadot/metadata": 2.6.2-1
"@polkadot/util": ^4.0.2-5
"@polkadot/util-crypto": ^4.0.2-5
"@polkadot/util": ^4.0.2-7
"@polkadot/util-crypto": ^4.0.2-7
"@types/bn.js": ^4.11.6
"@types/memoizee": ^0.4.4
bn.js: ^5.1.3
@@ -2024,15 +2024,15 @@ __metadata:
languageName: unknown
linkType: soft
"@polkadot/util-crypto@npm:4.0.2-5, @polkadot/util-crypto@npm:^4.0.2-5":
version: 4.0.2-5
resolution: "@polkadot/util-crypto@npm:4.0.2-5"
"@polkadot/util-crypto@npm:4.0.2-7, @polkadot/util-crypto@npm:^4.0.2-7":
version: 4.0.2-7
resolution: "@polkadot/util-crypto@npm:4.0.2-7"
dependencies:
"@babel/runtime": ^7.12.1
"@polkadot/networks": 4.0.2-5
"@polkadot/util": 4.0.2-5
"@polkadot/networks": 4.0.2-7
"@polkadot/util": 4.0.2-7
"@polkadot/wasm-crypto": ^2.0.1
"@polkadot/x-randomvalues": 4.0.2-5
"@polkadot/x-randomvalues": 4.0.2-7
base-x: ^3.0.8
blakejs: ^1.1.0
bn.js: ^5.1.3
@@ -2045,23 +2045,23 @@ __metadata:
tweetnacl: ^1.0.3
xxhashjs: ^0.2.2
peerDependencies:
"@polkadot/util": 4.0.2-5
checksum: 376ee7f9d1bd7daa5964b89b7b2b0f301feaee6d169302e405e15beefc6e2499f502425466ead1d8271bdb6e91522cf5330f7cd29390ddfeaf89d01acab34a63
"@polkadot/util": 4.0.2-7
checksum: 74096cd049d7dea7c7ef609f9f9f68bf9374f09f7fa1f6b16132d81c4bcb94f196375fafe84656f4cfdbd471e1112a1895d20ac16e1b08a322aed8f410ffe9ae
languageName: node
linkType: hard
"@polkadot/util@npm:4.0.2-5, @polkadot/util@npm:^4.0.2-5":
version: 4.0.2-5
resolution: "@polkadot/util@npm:4.0.2-5"
"@polkadot/util@npm:4.0.2-7, @polkadot/util@npm:^4.0.2-7":
version: 4.0.2-7
resolution: "@polkadot/util@npm:4.0.2-7"
dependencies:
"@babel/runtime": ^7.12.1
"@polkadot/x-textdecoder": 4.0.2-5
"@polkadot/x-textencoder": 4.0.2-5
"@polkadot/x-textdecoder": 4.0.2-7
"@polkadot/x-textencoder": 4.0.2-7
"@types/bn.js": ^4.11.6
bn.js: ^5.1.3
camelcase: ^5.3.1
ip-regex: ^4.2.0
checksum: be10c8f4c1a3953aaf432d96ad5f0117028bdb48ccd1eb4c3784f0cb24266de632ca8089644f066f37c1f3906845f58f7e7ddc6af6f3c15dfbcea961988f3bd8
checksum: c475919fe9fcf8792eda92f6a89eff82ad593099bf64c562281fee2b71db3767fd7d06c8055138bd63afcacf9c36279b0cb60ff0260db664ba7c9c17eeafef22
languageName: node
linkType: hard
@@ -2075,52 +2075,52 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/x-fetch@npm:^4.0.2-5":
version: 4.0.2-5
resolution: "@polkadot/x-fetch@npm:4.0.2-5"
"@polkadot/x-fetch@npm:^4.0.2-7":
version: 4.0.2-7
resolution: "@polkadot/x-fetch@npm:4.0.2-7"
dependencies:
"@babel/runtime": ^7.12.1
"@types/node-fetch": ^2.5.7
node-fetch: ^2.6.1
checksum: b2fdbd5acdf1dce705a083220cedd266457efa0bdc8a1bf49704fce9ca7e4f02738c76f3d7f25e3c453641bd7006c6eea5ce5d0e57a8a57cb560f6feef480eb9
checksum: d722d22428324f2c8f5fda43617ea791288ca3ffbbe73ddb0b3babb754073fa64e45c9ea6248cedf124ab7a121f16477915fb59c97770929e7656d64ab31aadd
languageName: node
linkType: hard
"@polkadot/x-randomvalues@npm:4.0.2-5":
version: 4.0.2-5
resolution: "@polkadot/x-randomvalues@npm:4.0.2-5"
"@polkadot/x-randomvalues@npm:4.0.2-7":
version: 4.0.2-7
resolution: "@polkadot/x-randomvalues@npm:4.0.2-7"
dependencies:
"@babel/runtime": ^7.12.1
checksum: ec895fc243bafd913818caa5f205c0a644d23ddfb1716296454869f6dc5859ab52b4d3af46fe45c0d92be7f19f21a7533e961109a2f5b18b3d345a07c5282d53
checksum: afc00c24e876ecacbbc8a2f531e8fc98dcb08a8b02558cc46728c24627913a15bcd69bdd90f660d4ad5e2b50cdff58bbb230de9cf9105939429470b936f26a74
languageName: node
linkType: hard
"@polkadot/x-textdecoder@npm:4.0.2-5":
version: 4.0.2-5
resolution: "@polkadot/x-textdecoder@npm:4.0.2-5"
"@polkadot/x-textdecoder@npm:4.0.2-7":
version: 4.0.2-7
resolution: "@polkadot/x-textdecoder@npm:4.0.2-7"
dependencies:
"@babel/runtime": ^7.12.1
checksum: 2d9b4192338b1dd1a7b64c9b3a64302dd22039bd5245434c8dd8ba64332ffcc8ae833431791127644c2911d5c9397d361db488642898c1f033719924c8b022ec
checksum: bcf46de6c280fce2499a623996ef519abefc06bb9a54d42e35fe827495f30e7424dd53ce570627039349e04b6ba942a30e44fcdc163412d04d0c6eafc6cd3bef
languageName: node
linkType: hard
"@polkadot/x-textencoder@npm:4.0.2-5":
version: 4.0.2-5
resolution: "@polkadot/x-textencoder@npm:4.0.2-5"
"@polkadot/x-textencoder@npm:4.0.2-7":
version: 4.0.2-7
resolution: "@polkadot/x-textencoder@npm:4.0.2-7"
dependencies:
"@babel/runtime": ^7.12.1
checksum: fda2c245f7f5413df6f48fb052f6b36484c0942837017707047891959600d327041abb997067fe009d88891541ceabe3a63a9c0076957e2efbc69446a45b87e9
checksum: 535f96fca8c1c206ccb1f7ed4db9b837d9ff766d2481fdab52e9a1dff5bd4488484a17ff2bc0b668a6177dcebc349d9fdcc6804414d880d466a1c759622cb7a7
languageName: node
linkType: hard
"@polkadot/x-ws@npm:^4.0.2-5":
version: 4.0.2-5
resolution: "@polkadot/x-ws@npm:4.0.2-5"
"@polkadot/x-ws@npm:^4.0.2-7":
version: 4.0.2-7
resolution: "@polkadot/x-ws@npm:4.0.2-7"
dependencies:
"@babel/runtime": ^7.12.1
"@types/websocket": ^1.0.1
websocket: ^1.0.32
checksum: 2be445d505d4d7f79734d64248b202d58c9f8ffd2e21f0360094d3f2026721eec8566e6c8e6cb166ef135ae461c5bb2bcf195c76b1fa503d460d5a94085f18aa
checksum: 1d566c09f9931053a851cb51fd1eb1c59341f196b88ab8d6e458c1184c5d495bb5fdf57976ce03e71245d818af1c440cb7792d69da0c6668bc034bc409110e10
languageName: node
linkType: hard