Compare commits

...
18 Commits
Author SHA1 Message Date
github-actions[bot] 94cbbf5356 [CI Skip] release/stable 10.5.1
skip-checks: true
2023-04-29 08:56:34 +00:00
Jaco c1b1ad7843 10.5.1 (#5623) 2023-04-29 11:48:07 +03:00
github-actions[bot] ce5769471f [CI Skip] bump/beta 10.4.2-7-x
skip-checks: true
2023-04-29 06:40:36 +00:00
Jaco 09222d9055 Bump util (#5622)
* Bump util

* Adjust to fix build
2023-04-29 09:31:52 +03:00
github-actions[bot] 9c4554ddb3 [CI Skip] bump/beta 10.4.2-6-x
skip-checks: true
2023-04-28 07:46:21 +00:00
Jaco 1ba4c0c277 Allow switching on/off of isPedantic checks (#5620)
* Allow switching on/off of isPedantic checks

* CHANGELOG

* typos
2023-04-28 10:37:27 +03:00
github-actions[bot] ac46305d15 [CI Skip] bump/beta 10.4.2-5-x
skip-checks: true
2023-04-28 07:33:46 +00:00
Jaco ad59abfc37 Adjust spread usage in types/interfaces (#5610) 2023-04-28 10:23:04 +03:00
github-actions[bot] 5a48ca3a0a [CI Skip] bump/beta 10.4.2-4-x
skip-checks: true
2023-04-28 06:49:19 +00:00
Jaco d3dabadf95 Bump deps (#5619)
* Bump deps

* CHANGELOG
2023-04-28 09:40:45 +03:00
github-actions[bot] 212d0e33ae [CI Skip] bump/beta 10.4.2-3-x
skip-checks: true
2023-04-26 09:49:32 +00:00
Jaco a6adeb739f Bump deps w/ export ordering (#5614) 2023-04-26 12:40:14 +03:00
github-actions[bot] cd440ea3c4 [CI Skip] bump/beta 10.4.2-2-x
skip-checks: true
2023-04-25 06:05:26 +00:00
Jaco eb480d7ce9 Export & spread cleanups on types-known (#5609) 2023-04-25 08:56:37 +03:00
github-actions[bot] 298397f499 [CI Skip] bump/beta 10.4.2-1-x
skip-checks: true
2023-04-23 13:02:37 +00:00
Jaco 6b17bf5a7a Default to hex-only when number bits > native Rust (#5611)
* Default to hex-only when number bits > native Rust

* CHANGELOG

* Add test for > u128 case
2023-04-23 15:53:32 +03:00
github-actions[bot] 3b3da09f33 [CI Skip] bump/beta 10.4.2-0-x
skip-checks: true
2023-04-23 06:21:56 +00:00
Jaco 976d708fae Adjust Deno WebSocket check (#5608) 2023-04-23 09:13:09 +03:00
189 changed files with 1475 additions and 1330 deletions
+11
View File
@@ -1,5 +1,16 @@
# CHANGELOG
## 10.5.1 Apr 29, 2023
Changes:
- Default to hex-only in `Int/UInt.toJSON` for > 128-bit values
- Allow for disabling of `isPedantic` storage checks in API options
- Adjust usage of `objectSpread`, default to runtime as required
- Adjust compilation output for `__internal__` class fields
- Update to latest Polkadot, Kusama & Substrate metadata
## 10.4.1 Apr 22, 2023
Contributed:
+1 -1
View File
@@ -1,4 +1,4 @@
3440 Jaco 10.4.1 (#5607)
3449 Jaco 10.5.1 (#5623)
83 Amaury Martiny StatementKind: Regular and Saft (#2303)
37 Keith Ingram Update contract types and rpc (#4541)
35 Stefanie Doll Updated child storage parameters (#1709)
+5 -5
View File
@@ -14,10 +14,10 @@
},
"sideEffects": false,
"type": "module",
"version": "10.4.1",
"version": "10.5.1",
"versions": {
"git": "10.4.1",
"npm": "10.4.1"
"git": "10.5.1",
"npm": "10.5.1"
},
"workspaces": [
"packages/*"
@@ -40,9 +40,9 @@
"test:one": "polkadot-dev-run-test --env node"
},
"devDependencies": {
"@polkadot/dev": "^0.73.2",
"@polkadot/dev": "^0.73.6",
"@polkadot/typegen": "workspace:packages/typegen",
"@types/node": "^18.15.13"
"@types/node": "^18.16.3"
},
"resolutions": {
"typescript": "^5.0.4"
+7 -7
View File
@@ -18,15 +18,15 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "10.4.1",
"version": "10.5.1",
"main": "index.js",
"dependencies": {
"@polkadot/api-base": "10.4.1",
"@polkadot/rpc-augment": "10.4.1",
"@polkadot/types": "10.4.1",
"@polkadot/types-augment": "10.4.1",
"@polkadot/types-codec": "10.4.1",
"@polkadot/util": "^12.0.1",
"@polkadot/api-base": "10.5.1",
"@polkadot/rpc-augment": "10.5.1",
"@polkadot/types": "10.5.1",
"@polkadot/types-augment": "10.5.1",
"@polkadot/types-codec": "10.5.1",
"@polkadot/util": "^12.1.1",
"tslib": "^2.5.0"
}
}
+4 -9
View File
@@ -998,15 +998,6 @@ declare module '@polkadot/api-base/types/storage' {
* The primary structure that holds all offence records keyed by report identifiers.
**/
reports: AugmentedQuery<ApiType, (arg: H256 | string | Uint8Array) => Observable<Option<SpStakingOffenceOffenceDetails>>, [H256]> & QueryableStorageEntry<ApiType, [H256]>;
/**
* Enumerates all reports of a kind along with the time they happened.
*
* All reports are sorted by the time of offence.
*
* Note that the actual type of this mapping is `Vec<u8>`, this is because values of
* different types are not supported at the moment so we are doing the manual serialization.
**/
reportsByKindIndex: AugmentedQuery<ApiType, (arg: U8aFixed | string | Uint8Array) => Observable<Bytes>, [U8aFixed]> & QueryableStorageEntry<ApiType, [U8aFixed]>;
/**
* Generic query
**/
@@ -2115,6 +2106,10 @@ declare module '@polkadot/api-base/types/storage' {
* of our versions we informed them of.
**/
versionNotifyTargets: AugmentedQuery<ApiType, (arg1: u32 | AnyNumber | Uint8Array, arg2: XcmVersionedMultiLocation | { V2: any } | { V3: any } | string | Uint8Array) => Observable<Option<ITuple<[u64, SpWeightsWeightV2Weight, u32]>>>, [u32, XcmVersionedMultiLocation]> & QueryableStorageEntry<ApiType, [u32, XcmVersionedMultiLocation]>;
/**
* Global suspension state of the XCM executor.
**/
xcmExecutionSuspended: AugmentedQuery<ApiType, () => Observable<bool>, []> & QueryableStorageEntry<ApiType, []>;
/**
* Generic query
**/
+11 -4
View File
@@ -3875,22 +3875,29 @@ declare module '@polkadot/api-base/types/submittable' {
* Set a safe XCM version (the version that XCM should be encoded with if the most recent
* version a destination can accept is unknown).
*
* - `origin`: Must be Root.
* - `origin`: Must be an origin specified by AdminOrigin.
* - `maybe_xcm_version`: The default XCM encoding version, or `None` to disable.
**/
forceDefaultXcmVersion: AugmentedSubmittable<(maybeXcmVersion: Option<u32> | null | Uint8Array | u32 | AnyNumber) => SubmittableExtrinsic<ApiType>, [Option<u32>]>;
/**
* Ask a location to notify us regarding their XCM version and any changes to it.
*
* - `origin`: Must be Root.
* - `origin`: Must be an origin specified by AdminOrigin.
* - `location`: The location to which we should subscribe for XCM version notifications.
**/
forceSubscribeVersionNotify: AugmentedSubmittable<(location: XcmVersionedMultiLocation | { V2: any } | { V3: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [XcmVersionedMultiLocation]>;
/**
* Set or unset the global suspension state of the XCM executor.
*
* - `origin`: Must be an origin specified by AdminOrigin.
* - `suspended`: `true` to suspend, `false` to resume.
**/
forceSuspension: AugmentedSubmittable<(suspended: bool | boolean | Uint8Array) => SubmittableExtrinsic<ApiType>, [bool]>;
/**
* Require that a particular destination should no longer notify us regarding any XCM
* version changes.
*
* - `origin`: Must be Root.
* - `origin`: Must be an origin specified by AdminOrigin.
* - `location`: The location to which we are currently subscribed for XCM version
* notifications which we no longer desire.
**/
@@ -3899,7 +3906,7 @@ declare module '@polkadot/api-base/types/submittable' {
* Extoll that a particular destination can be communicated with through a particular
* version of XCM.
*
* - `origin`: Must be Root.
* - `origin`: Must be an origin specified by AdminOrigin.
* - `location`: The destination that is being described.
* - `xcm_version`: The latest version of XCM that `location` supports.
**/
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/api-augment', path: 'auto', type: 'auto', version: '10.4.1' };
export const packageInfo = { name: '@polkadot/api-augment', path: 'auto', type: 'auto', version: '10.5.1' };
+4 -9
View File
@@ -950,15 +950,6 @@ declare module '@polkadot/api-base/types/storage' {
* The primary structure that holds all offence records keyed by report identifiers.
**/
reports: AugmentedQuery<ApiType, (arg: H256 | string | Uint8Array) => Observable<Option<SpStakingOffenceOffenceDetails>>, [H256]> & QueryableStorageEntry<ApiType, [H256]>;
/**
* Enumerates all reports of a kind along with the time they happened.
*
* All reports are sorted by the time of offence.
*
* Note that the actual type of this mapping is `Vec<u8>`, this is because values of
* different types are not supported at the moment so we are doing the manual serialization.
**/
reportsByKindIndex: AugmentedQuery<ApiType, (arg: U8aFixed | string | Uint8Array) => Observable<Bytes>, [U8aFixed]> & QueryableStorageEntry<ApiType, [U8aFixed]>;
/**
* Generic query
**/
@@ -2058,6 +2049,10 @@ declare module '@polkadot/api-base/types/storage' {
* of our versions we informed them of.
**/
versionNotifyTargets: AugmentedQuery<ApiType, (arg1: u32 | AnyNumber | Uint8Array, arg2: XcmVersionedMultiLocation | { V2: any } | { V3: any } | string | Uint8Array) => Observable<Option<ITuple<[u64, SpWeightsWeightV2Weight, u32]>>>, [u32, XcmVersionedMultiLocation]> & QueryableStorageEntry<ApiType, [u32, XcmVersionedMultiLocation]>;
/**
* Global suspension state of the XCM executor.
**/
xcmExecutionSuspended: AugmentedQuery<ApiType, () => Observable<bool>, []> & QueryableStorageEntry<ApiType, []>;
/**
* Generic query
**/
+11 -4
View File
@@ -3987,22 +3987,29 @@ declare module '@polkadot/api-base/types/submittable' {
* Set a safe XCM version (the version that XCM should be encoded with if the most recent
* version a destination can accept is unknown).
*
* - `origin`: Must be Root.
* - `origin`: Must be an origin specified by AdminOrigin.
* - `maybe_xcm_version`: The default XCM encoding version, or `None` to disable.
**/
forceDefaultXcmVersion: AugmentedSubmittable<(maybeXcmVersion: Option<u32> | null | Uint8Array | u32 | AnyNumber) => SubmittableExtrinsic<ApiType>, [Option<u32>]>;
/**
* Ask a location to notify us regarding their XCM version and any changes to it.
*
* - `origin`: Must be Root.
* - `origin`: Must be an origin specified by AdminOrigin.
* - `location`: The location to which we should subscribe for XCM version notifications.
**/
forceSubscribeVersionNotify: AugmentedSubmittable<(location: XcmVersionedMultiLocation | { V2: any } | { V3: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [XcmVersionedMultiLocation]>;
/**
* Set or unset the global suspension state of the XCM executor.
*
* - `origin`: Must be an origin specified by AdminOrigin.
* - `suspended`: `true` to suspend, `false` to resume.
**/
forceSuspension: AugmentedSubmittable<(suspended: bool | boolean | Uint8Array) => SubmittableExtrinsic<ApiType>, [bool]>;
/**
* Require that a particular destination should no longer notify us regarding any XCM
* version changes.
*
* - `origin`: Must be Root.
* - `origin`: Must be an origin specified by AdminOrigin.
* - `location`: The location to which we are currently subscribed for XCM version
* notifications which we no longer desire.
**/
@@ -4011,7 +4018,7 @@ declare module '@polkadot/api-base/types/submittable' {
* Extoll that a particular destination can be communicated with through a particular
* version of XCM.
*
* - `origin`: Must be Root.
* - `origin`: Must be an origin specified by AdminOrigin.
* - `location`: The destination that is being described.
* - `xcm_version`: The latest version of XCM that `location` supports.
**/
@@ -209,6 +209,10 @@ declare module '@polkadot/api-base/types/consts' {
[key: string]: Codec;
};
contracts: {
/**
* Fallback value to limit the storage deposit if it's not being set by the caller.
**/
defaultDepositLimit: u128 & AugmentedConst<ApiType>;
/**
* The amount of balance a caller has to pay for each byte of storage.
*
+2 -9
View File
@@ -586,6 +586,8 @@ declare module '@polkadot/api-base/types/storage' {
minimumUntrustedScore: AugmentedQuery<ApiType, () => Observable<Option<SpNposElectionsElectionScore>>, []> & QueryableStorageEntry<ApiType, []>;
/**
* Current best solution, signed or unsigned, queued to be returned upon `elect`.
*
* Always sorted by score.
**/
queuedSolution: AugmentedQuery<ApiType, () => Observable<Option<PalletElectionProviderMultiPhaseReadySolution>>, []> & QueryableStorageEntry<ApiType, []>;
/**
@@ -1150,15 +1152,6 @@ declare module '@polkadot/api-base/types/storage' {
* The primary structure that holds all offence records keyed by report identifiers.
**/
reports: AugmentedQuery<ApiType, (arg: H256 | string | Uint8Array) => Observable<Option<SpStakingOffenceOffenceDetails>>, [H256]> & QueryableStorageEntry<ApiType, [H256]>;
/**
* Enumerates all reports of a kind along with the time they happened.
*
* All reports are sorted by the time of offence.
*
* Note that the actual type of this mapping is `Vec<u8>`, this is because values of
* different types are not supported at the moment so we are doing the manual serialization.
**/
reportsByKindIndex: AugmentedQuery<ApiType, (arg: U8aFixed | string | Uint8Array) => Observable<Bytes>, [U8aFixed]> & QueryableStorageEntry<ApiType, [U8aFixed]>;
/**
* Generic query
**/
+5 -5
View File
@@ -18,13 +18,13 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "10.4.1",
"version": "10.5.1",
"main": "index.js",
"dependencies": {
"@polkadot/rpc-core": "10.4.1",
"@polkadot/types": "10.4.1",
"@polkadot/util": "^12.0.1",
"rxjs": "^7.8.0",
"@polkadot/rpc-core": "10.5.1",
"@polkadot/types": "10.5.1",
"@polkadot/util": "^12.1.1",
"rxjs": "^7.8.1",
"tslib": "^2.5.0"
}
}
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/api-base', path: 'auto', type: 'auto', version: '10.4.1' };
export const packageInfo = { name: '@polkadot/api-base', path: 'auto', type: 'auto', version: '10.5.1' };
+10 -10
View File
@@ -18,20 +18,20 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "10.4.1",
"version": "10.5.1",
"main": "index.js",
"dependencies": {
"@polkadot/api": "10.4.1",
"@polkadot/types": "10.4.1",
"@polkadot/types-codec": "10.4.1",
"@polkadot/types-create": "10.4.1",
"@polkadot/util": "^12.0.1",
"@polkadot/util-crypto": "^12.0.1",
"rxjs": "^7.8.0",
"@polkadot/api": "10.5.1",
"@polkadot/types": "10.5.1",
"@polkadot/types-codec": "10.5.1",
"@polkadot/types-create": "10.5.1",
"@polkadot/util": "^12.1.1",
"@polkadot/util-crypto": "^12.1.1",
"rxjs": "^7.8.1",
"tslib": "^2.5.0"
},
"devDependencies": {
"@polkadot/api-augment": "10.4.1",
"@polkadot/keyring": "^12.0.1"
"@polkadot/api-augment": "10.5.1",
"@polkadot/keyring": "^12.1.1"
}
}
+2
View File
@@ -1,8 +1,10 @@
// Copyright 2017-2023 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
// all named
export { Abi } from './Abi/index.js';
export { packageInfo } from './packageInfo.js';
// all starred
export * from './promise/index.js';
export * from './rx/index.js';
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/api-contract', path: 'auto', type: 'auto', version: '10.4.1' };
export const packageInfo = { name: '@polkadot/api-contract', path: 'auto', type: 'auto', version: '10.5.1' };
@@ -5,7 +5,7 @@ export { default as delegator } from './delegator.json' assert { type: 'json' };
export { default as dns } from './dns.json' assert { type: 'json' };
export { default as erc20 } from './erc20.json' assert { type: 'json' };
export { default as erc721 } from './erc721.json' assert { type: 'json' };
export { default as flipper } from './flipper.json' assert { type: 'json' };
export { default as flipperBundle } from './flipper.contract.json' assert { type: 'json' };
export { default as flipper } from './flipper.json' assert { type: 'json' };
export { default as incrementer } from './incrementer.json' assert { type: 'json' };
export { default as multisigPlain } from './multisig_plain.json' assert { type: 'json' };
+15 -15
View File
@@ -18,25 +18,25 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "10.4.1",
"version": "10.5.1",
"main": "index.js",
"dependencies": {
"@polkadot/api": "10.4.1",
"@polkadot/api-augment": "10.4.1",
"@polkadot/api-base": "10.4.1",
"@polkadot/rpc-core": "10.4.1",
"@polkadot/types": "10.4.1",
"@polkadot/types-codec": "10.4.1",
"@polkadot/util": "^12.0.1",
"@polkadot/util-crypto": "^12.0.1",
"rxjs": "^7.8.0",
"@polkadot/api": "10.5.1",
"@polkadot/api-augment": "10.5.1",
"@polkadot/api-base": "10.5.1",
"@polkadot/rpc-core": "10.5.1",
"@polkadot/types": "10.5.1",
"@polkadot/types-codec": "10.5.1",
"@polkadot/util": "^12.1.1",
"@polkadot/util-crypto": "^12.1.1",
"rxjs": "^7.8.1",
"tslib": "^2.5.0"
},
"devDependencies": {
"@polkadot/api": "10.4.1",
"@polkadot/api-augment": "10.4.1",
"@polkadot/rpc-augment": "10.4.1",
"@polkadot/rpc-provider": "10.4.1",
"@polkadot/types-support": "10.4.1"
"@polkadot/api": "10.5.1",
"@polkadot/api-augment": "10.5.1",
"@polkadot/rpc-augment": "10.5.1",
"@polkadot/rpc-provider": "10.5.1",
"@polkadot/types-support": "10.5.1"
}
}
+1 -1
View File
@@ -55,7 +55,7 @@ export function _flags (instanceId: string, api: DeriveApi): () => Observable<Fl
map((values: Codec[]): FlagsIntermediate => {
let resultIndex = -1;
for (let i = 0; i < calls.length; i++) {
for (let i = 0, count = calls.length; i < count; i++) {
if (isFunction(calls[i])) {
results[i] = values[++resultIndex];
}
+2 -2
View File
@@ -4,8 +4,8 @@
export * from './accountId.js';
export * from './flags.js';
export * from './idAndIndex.js';
export * from './idToIndex.js';
export * from './identity.js';
export * from './indexToId.js';
export * from './idToIndex.js';
export * from './indexes.js';
export * from './indexToId.js';
export * from './info.js';
+1 -1
View File
@@ -119,7 +119,7 @@ function injectFunctions (instanceId: string, api: DeriveApi, derives: DeriveCus
)
));
for (let i = 0; i < names.length; i++) {
for (let i = 0, count = names.length; i < count; i++) {
const name = names[i];
isIncluded(name) &&
+1 -1
View File
@@ -4,9 +4,9 @@
export * from './bestNumber.js';
export * from './bestNumberFinalized.js';
export * from './bestNumberLag.js';
export * from './getHeader.js';
export * from './getBlock.js';
export * from './getBlockByNumber.js';
export * from './getHeader.js';
export * from './subscribeFinalizedHeads.js';
export * from './subscribeNewBlocks.js';
export * from './subscribeNewHeads.js';
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/api-derive', path: 'auto', type: 'auto', version: '10.4.1' };
export const packageInfo = { name: '@polkadot/api-derive', path: 'auto', type: 'auto', version: '10.5.1' };
+1 -1
View File
@@ -3,13 +3,13 @@
export * from './account.js';
export * from './currentPoints.js';
export * from './electedInfo.js';
export * from './erasExposure.js';
export * from './erasHistoric.js';
export * from './erasPoints.js';
export * from './erasPrefs.js';
export * from './erasRewards.js';
export * from './erasSlashes.js';
export * from './electedInfo.js';
export * from './keys.js';
export * from './overview.js';
export * from './ownExposure.js';
+1 -1
View File
@@ -9,8 +9,8 @@ import type { BN } from '@polkadot/util';
import type { ExactDerive } from './derive.js';
export * from './accounts/types.js';
export * from './balances/types.js';
export * from './bagsList/types.js';
export * from './balances/types.js';
export * from './council/types.js';
export * from './crowdloan/types.js';
export * from './democracy/types.js';
@@ -8,7 +8,7 @@ import type { ApprovalFlag } from '@polkadot/types/interfaces/elections';
export function approvalFlagsToBools (flags: Vec<ApprovalFlag> | ApprovalFlag[]): boolean[] {
const bools: boolean[] = [];
for (let i = 0; i < flags.length; i++) {
for (let i = 0, count = flags.length; i < count; i++) {
const str = flags[i].toString(2);
// read from lowest bit to highest
+2
View File
@@ -1,8 +1,10 @@
// Copyright 2017-2023 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
// all named
export { drr, memo } from '@polkadot/rpc-core';
// all starred
export * from './approvalFlagsToBools.js';
export * from './blockNumber.js';
export * from './cache.js';
+18 -18
View File
@@ -18,29 +18,29 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "10.4.1",
"version": "10.5.1",
"main": "index.js",
"dependencies": {
"@polkadot/api-augment": "10.4.1",
"@polkadot/api-base": "10.4.1",
"@polkadot/api-derive": "10.4.1",
"@polkadot/keyring": "^12.0.1",
"@polkadot/rpc-augment": "10.4.1",
"@polkadot/rpc-core": "10.4.1",
"@polkadot/rpc-provider": "10.4.1",
"@polkadot/types": "10.4.1",
"@polkadot/types-augment": "10.4.1",
"@polkadot/types-codec": "10.4.1",
"@polkadot/types-create": "10.4.1",
"@polkadot/types-known": "10.4.1",
"@polkadot/util": "^12.0.1",
"@polkadot/util-crypto": "^12.0.1",
"@polkadot/api-augment": "10.5.1",
"@polkadot/api-base": "10.5.1",
"@polkadot/api-derive": "10.5.1",
"@polkadot/keyring": "^12.1.1",
"@polkadot/rpc-augment": "10.5.1",
"@polkadot/rpc-core": "10.5.1",
"@polkadot/rpc-provider": "10.5.1",
"@polkadot/types": "10.5.1",
"@polkadot/types-augment": "10.5.1",
"@polkadot/types-codec": "10.5.1",
"@polkadot/types-create": "10.5.1",
"@polkadot/types-known": "10.5.1",
"@polkadot/util": "^12.1.1",
"@polkadot/util-crypto": "^12.1.1",
"eventemitter3": "^5.0.0",
"rxjs": "^7.8.0",
"rxjs": "^7.8.1",
"tslib": "^2.5.0"
},
"devDependencies": {
"@polkadot/api-augment": "10.4.1",
"@polkadot/types-support": "10.4.1"
"@polkadot/api-augment": "10.5.1",
"@polkadot/types-support": "10.5.1"
}
}
+24 -20
View File
@@ -139,19 +139,22 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
this._rx.queryAt = (blockHash: Uint8Array | string, knownVersion?: RuntimeVersion) =>
from(this.at(blockHash, knownVersion)).pipe(map((a) => a.rx.query));
this._rx.registry = this.#registry;
this._decorateMethod = decorateMethod;
this._options = options;
this._type = type;
const thisProvider = options.source
const provider = options.source
? options.source._rpcCore.provider.isClonable
? options.source._rpcCore.provider.clone()
: options.source._rpcCore.provider
: (options.provider || new WsProvider());
this._decorateMethod = decorateMethod;
this._options = options;
this._type = type;
// The RPC interface decorates the known interfaces on init
this._rpcCore = new RpcCore(this.#instanceId, this.#registry, thisProvider, this._options.rpc) as (RpcCore & RpcInterface);
this._rpcCore = new RpcCore(this.#instanceId, this.#registry, {
isPedantic: this._options.isPedantic,
provider,
userRpc: this._options.rpc
}) as (RpcCore & RpcInterface);
this._isConnected = new BehaviorSubject(this._rpcCore.provider.isConnected);
this._rx.hasSubscriptions = this._rpcCore.provider.hasSubscriptions;
}
@@ -319,7 +322,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
// we try and create mappings to runtime names via a hash mapping)
const sectionMap: Record<string, boolean> = {};
for (let i = 0; i < methods.length; i++) {
for (let i = 0, count = methods.length; i < count; i++) {
const [section] = methods[i].split('_');
sectionMap[section] = true;
@@ -328,7 +331,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
// convert the actual section names into an easy name lookup
const sections = Object.keys(sectionMap);
for (let i = 0; i < sections.length; i++) {
for (let i = 0, count = sections.length; i < count; i++) {
const nameA = stringUpperFirst(sections[i]);
const nameB = `${nameA}Api`;
@@ -344,8 +347,9 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
const hasResults = exposed.length !== 0;
const allKnown = [...this._rpcCore.mapping.entries()];
const allKeys: string[] = [];
const count = allKnown.length;
for (let i = 0; i < allKnown.length; i++) {
for (let i = 0; i < count; i++) {
const [, { alias, endpoint, method, pubsub, section }] = allKnown[i];
allKeys.push(`${section}_${method}`);
@@ -375,7 +379,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
// loop through all entries we have (populated in decorate) and filter as required
// only remove when we have results and method missing, or with no results if optional
for (let i = 0; i < allKnown.length; i++) {
for (let i = 0; i < count; i++) {
const [k, { method, section }] = allKnown[i];
if (hasResults && !exposed.includes(k) && k !== 'rpc_methods') {
@@ -408,7 +412,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
return fn;
};
for (let s = 0; s < rpc.sections.length; s++) {
for (let s = 0, scount = rpc.sections.length; s < scount; s++) {
const section = rpc.sections[s];
if (!Object.prototype.hasOwnProperty.call(out, section)) {
@@ -417,7 +421,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
const decorateInternal = (method: string) =>
decorateFn(section, method);
for (let m = 0; m < methods.length; m++) {
for (let m = 0, mcount = methods.length; m < mcount; m++) {
const method = methods[m];
// skip subscriptions where we have a non-subscribe interface
@@ -443,13 +447,13 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
const entries = Object.entries(additional);
for (let j = 0; j < entries.length; j++) {
for (let j = 0, ecount = entries.length; j < ecount; j++) {
const [key, defs] = entries[j];
if (result[key]) {
// we have this one already, step through for new versions or
// new methods and add those as applicable
for (let k = 0; k < defs.length; k++) {
for (let k = 0, dcount = defs.length; k < dcount; k++) {
const def = defs[k];
const prev = result[key].find(({ version }) => def.version === version);
@@ -475,7 +479,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
// options > chain/spec > built-in, apply in reverse order with
// methods overriding previous definitions (or interleave missing)
for (let i = 0; i < defValues.length; i++) {
for (let i = 0, count = defValues.length; i < count; i++) {
this._addRuntimeDef(result, defValues[i].runtime);
}
@@ -497,7 +501,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
this.#runtimeLog[implName] = true;
for (let i = 0; i < sections.length; i++) {
for (let i = 0, scount = sections.length; i < scount; i++) {
const [_section, secs] = sections[i];
const sectionHash = blake2AsHex(_section, 64);
const rtApi = apis.find(([a]) => a.eq(sectionHash));
@@ -517,7 +521,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
named[section] = {};
}
for (let m = 0; m < methods.length; m++) {
for (let m = 0, mcount = methods.length; m < mcount; m++) {
const [_method, def] = methods[m];
const method = stringCamelCase(_method);
@@ -557,7 +561,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
const modules = Object.keys(named);
for (let i = 0; i < modules.length; i++) {
for (let i = 0, count = modules.length; i < count; i++) {
lazyMethod(result, modules[i], lazySection);
}
@@ -642,7 +646,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
const sections = Object.keys(tx);
for (let i = 0; i < sections.length; i++) {
for (let i = 0, count = sections.length; i < count; i++) {
lazyMethod(result, sections[i], lazySection);
}
@@ -673,7 +677,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
const sections = Object.keys(query);
for (let i = 0; i < sections.length; i++) {
for (let i = 0, count = sections.length; i < count; i++) {
lazyMethod(result, sections[i], lazySection);
}
+2 -2
View File
@@ -265,11 +265,11 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
const sections = Object.keys(source.rpc);
const rpcs: string[] = [];
for (let s = 0; s < sections.length; s++) {
for (let s = 0, scount = sections.length; s < scount; s++) {
const section = sections[s];
const methods = Object.keys((source.rpc as unknown as Record<string, Record<string, unknown>>)[section]);
for (let m = 0; m < methods.length; m++) {
for (let m = 0, mcount = methods.length; m < mcount; m++) {
rpcs.push(`${section}_${methods[m]}`);
}
}
+3
View File
@@ -3,11 +3,14 @@
import '@polkadot/rpc-augment';
// all external
export { Keyring } from '@polkadot/keyring';
export { HttpProvider, ScProvider, WsProvider } from '@polkadot/rpc-provider';
// all named
export { packageInfo } from './packageInfo.js';
export { SubmittableResult } from './submittable/index.js';
// all starred
export * from './promise/index.js';
export * from './rx/index.js';
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/api', path: 'auto', type: 'auto', version: '10.4.1' };
export const packageInfo = { name: '@polkadot/api', path: 'auto', type: 'auto', version: '10.5.1' };
+1 -1
View File
@@ -14,7 +14,7 @@ import { toRxMethod } from './decorateMethod.js';
/**
* # @polkadot/api/rx
*
* ## Overview
* ## Overview
*
* @name ApiRx
*
+2 -4
View File
@@ -13,7 +13,7 @@ import type { AddressOrPair, SignerOptions, SubmittableDryRunResult, Submittable
import { catchError, first, map, mergeMap, of, switchMap, tap } from 'rxjs';
import { isBn, isFunction, isNumber, isString, isU8a, objectSpread } from '@polkadot/util';
import { identity, isBn, isFunction, isNumber, isString, isU8a, objectSpread } from '@polkadot/util';
import { filterEvents, isKeyringPair } from '../util/index.js';
import { SubmittableResult } from './Result.js';
@@ -30,8 +30,6 @@ interface UpdateInfo {
updateId: number;
}
const identity = <T> (input: T): T => input;
function makeEraOptions (api: ApiInterfaceRx, registry: Registry, partialOptions: Partial<SignerOptions>, { header, mortalLength, nonce }: { header: Header | null; mortalLength: number; nonce: Index }): SignatureOptions {
if (!header) {
if (partialOptions.era && !partialOptions.blockHash) {
@@ -92,7 +90,7 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, blockHas
class Submittable extends ExtrinsicBase implements SubmittableExtrinsic<ApiType> {
readonly #ignoreStatusCb: boolean;
#transformResult: (input: ISubmittableResult) => ISubmittableResult = identity;
#transformResult = identity<ISubmittableResult>;
constructor (registry: Registry, extrinsic: Call | Extrinsic | Uint8Array | string) {
super(registry, extrinsic, { version: api.extrinsicType });
+12 -5
View File
@@ -18,17 +18,20 @@ import type { ApiBase } from '../base/index.js';
import type { SubmittableExtrinsic } from '../types/submittable.js';
import type { AllDerives } from '../util/decorate.js';
export * from '@polkadot/api-base/types';
// types
export type { Signer, SignerResult } from '@polkadot/types/types';
// all named
export { ApiBase } from '../base/index.js';
// all starred
export * from '@polkadot/api/types/calls';
export * from '@polkadot/api/types/consts';
export * from '@polkadot/api/types/errors';
export * from '@polkadot/api/types/events';
export * from '@polkadot/api/types/storage';
export * from '@polkadot/api/types/submittable';
export type { Signer, SignerResult } from '@polkadot/types/types';
export { ApiBase } from '../base/index.js';
export * from '@polkadot/api-base/types';
// A smaller interface of ApiRx, used in derive and in SubmittableExtrinsic
export interface ApiInterfaceRx extends ApiInterfaceBase {
@@ -44,6 +47,10 @@ export interface ApiOptions extends RegisteredTypes {
* @description Control the initialization of the wasm libraries. When not specified, it defaults to `true`, initializing the wasm libraries, set to `false` to not initialize wasm. (No sr25519 support)
*/
initWasm?: boolean;
/**
* @description Controls the checking of storage values once they have been contructed. When not specified this defaults to `true`. Set to `false` to forgo any checking on storage results.
*/
isPedantic?: boolean;
/**
* @description pre-bundles is a map of 'genesis hash and runtime spec version' as key to a metadata hex string
* if genesis hash and runtime spec version matches, then use metadata, else fetch it from chain
+3 -3
View File
@@ -53,12 +53,12 @@ function findMethodExcludes <T> (src: Sections<T>, dst: Sections<T>): string[] {
const dstSections = findSectionIncludes(Object.keys(dst), srcSections);
const excludes: string[] = [];
for (let s = 0; s < dstSections.length; s++) {
for (let s = 0, scount = dstSections.length; s < scount; s++) {
const section = dstSections[s];
const srcMethods = Object.keys(src[section]);
const dstMethods = Object.keys(dst[section]);
for (let d = 0; d < dstMethods.length; d++) {
for (let d = 0, mcount = dstMethods.length; d < mcount; d++) {
const method = dstMethods[d];
if (!srcMethods.includes(method)) {
@@ -95,7 +95,7 @@ export function augmentObject <T> (prefix: string | null, src: Sections<T>, dst:
const sections = Object.keys(src);
for (let i = 0; i < sections.length; i++) {
for (let i = 0, count = sections.length; i < count; i++) {
const section = sections[i];
const methods = src[section];
+1 -1
View File
@@ -35,7 +35,7 @@ export function decorateDeriveSections<ApiType extends ApiTypes> (decorateMethod
const result: AnyDerive = {};
const names = Object.keys(derives);
for (let i = 0; i < names.length; i++) {
for (let i = 0, count = names.length; i < count; i++) {
lazyDeriveSection(result, names[i], getKeys, creator);
}
+4 -2
View File
@@ -1,8 +1,10 @@
// Copyright 2017-2023 @polkadot/api authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from './decorate.js';
// all named
export { filterEvents } from './filterEvents.js';
export { isKeyringPair } from './isKeyringPair.js';
export { l } from './logging.js';
// all starred
export * from './decorate.js';
+5 -5
View File
@@ -18,13 +18,13 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "10.4.1",
"version": "10.5.1",
"main": "index.js",
"dependencies": {
"@polkadot/rpc-core": "10.4.1",
"@polkadot/types": "10.4.1",
"@polkadot/types-codec": "10.4.1",
"@polkadot/util": "^12.0.1",
"@polkadot/rpc-core": "10.5.1",
"@polkadot/types": "10.5.1",
"@polkadot/types-codec": "10.5.1",
"@polkadot/util": "^12.1.1",
"tslib": "^2.5.0"
}
}
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/rpc-augment', path: 'auto', type: 'auto', version: '10.4.1' };
export const packageInfo = { name: '@polkadot/rpc-augment', path: 'auto', type: 'auto', version: '10.5.1' };
+8 -8
View File
@@ -18,18 +18,18 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "10.4.1",
"version": "10.5.1",
"main": "index.js",
"dependencies": {
"@polkadot/rpc-augment": "10.4.1",
"@polkadot/rpc-provider": "10.4.1",
"@polkadot/types": "10.4.1",
"@polkadot/util": "^12.0.1",
"rxjs": "^7.8.0",
"@polkadot/rpc-augment": "10.5.1",
"@polkadot/rpc-provider": "10.5.1",
"@polkadot/types": "10.5.1",
"@polkadot/util": "^12.1.1",
"rxjs": "^7.8.1",
"tslib": "^2.5.0"
},
"devDependencies": {
"@polkadot/keyring": "^12.0.1",
"@polkadot/rpc-augment": "10.4.1"
"@polkadot/keyring": "^12.1.1",
"@polkadot/rpc-augment": "10.5.1"
}
}
+59 -43
View File
@@ -29,6 +29,12 @@ type MemoizedRpcInterfaceMethod = Memoized<RpcInterfaceMethod> & {
meta: DefinitionRpc;
}
interface Options {
isPedantic?: boolean;
provider: ProviderInterface;
userRpc?: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>;
}
const l = logger('rpc-core');
const EMPTY_META = {
@@ -47,11 +53,11 @@ function logErrorMessage (method: string, { noErrorLog, params, type }: Definiti
return;
}
const inputs = params.map(({ isOptional, name, type }): string =>
`${name}${isOptional ? '?' : ''}: ${type}`
).join(', ');
l.error(`${method}(${inputs}): ${type}:: ${error.message}`);
l.error(`${method}(${
params.map(({ isOptional, name, type }): string =>
`${name}${isOptional ? '?' : ''}: ${type}`
).join(', ')
}): ${type}:: ${error.message}`);
}
function isTreatAsHex (key: StorageKey): boolean {
@@ -84,30 +90,31 @@ function isTreatAsHex (key: StorageKey): boolean {
* ```
*/
export class RpcCore {
#instanceId: string;
#registryDefault: Registry;
readonly #instanceId: string;
readonly #isPedantic: boolean;
readonly #registryDefault: Registry;
readonly #storageCache = new Map<string, Codec>();
#getBlockRegistry?: (blockHash: Uint8Array) => Promise<{ registry: Registry }>;
#getBlockHash?: (blockNumber: AnyNumber) => Promise<Uint8Array>;
readonly #storageCache = new Map<string, Codec>();
readonly mapping = new Map<string, DefinitionRpcExt>();
readonly provider: ProviderInterface;
readonly sections: string[] = [];
/**
* @constructor
* Default constructor for the Api Object
* @param {ProviderInterface} provider An API provider using HTTP or WebSocket
* Default constructor for the core RPC handler
* @param {ProviderInterface} provider An API provider using any of the supported providers (HTTP, SC or WebSocket)
*/
constructor (instanceId: string, registry: Registry, provider: ProviderInterface, userRpc: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>> = {}) {
constructor (instanceId: string, registry: Registry, { isPedantic = true, provider, userRpc = {} }: Options) {
// eslint-disable-next-line @typescript-eslint/unbound-method
if (!provider || !isFunction(provider.send)) {
throw new Error('Expected Provider to API create');
}
this.#instanceId = instanceId;
this.#isPedantic = isPedantic;
this.#registryDefault = registry;
this.provider = provider;
@@ -163,12 +170,12 @@ export class RpcCore {
// add any extra user-defined sections
this.sections.push(...Object.keys(userRpc).filter((k) => !this.sections.includes(k)));
for (let s = 0; s < this.sections.length; s++) {
for (let s = 0, scount = this.sections.length; s < scount; s++) {
const section = this.sections[s];
const defs = objectSpread<Record<string, DefinitionRpc | DefinitionRpcSub>>({}, rpcDefinitions[section as 'babe'], userRpc[section]);
const methods = Object.keys(defs);
for (let m = 0; m < methods.length; m++) {
for (let m = 0, mcount = methods.length; m < mcount; m++) {
const method = methods[m];
const def = defs[method];
const jsonrpc = def.endpoint || `${section}_${method}`;
@@ -227,7 +234,7 @@ export class RpcCore {
? await this.#getBlockRegistry(u8aToU8a(blockHash))
: { registry: this.#registryDefault };
const params = this._formatInputs(registry, null, def, values);
const params = this._formatParams(registry, null, def, values);
// only cache .at(<blockHash>) queries, e.g. where valid blockHash was supplied
const result = await this.provider.send<AnyJson>(rpcName, params.map((p) => p.toJSON()), !!blockHash);
@@ -307,8 +314,7 @@ export class RpcCore {
};
try {
const params = this._formatInputs(registry, null, def, values);
const paramsJson = params.map((p) => p.toJSON());
const params = this._formatParams(registry, null, def, values);
const update = (error?: Error | null, result?: unknown): void => {
if (error) {
@@ -324,7 +330,7 @@ export class RpcCore {
}
};
subscriptionPromise = this._createSubscriber({ paramsJson, subName, subType, update }, errorHandler);
subscriptionPromise = this._createSubscriber({ paramsJson: params.map((p) => p.toJSON()), subName, subType, update }, errorHandler);
} catch (error) {
errorHandler(error as Error);
}
@@ -355,19 +361,21 @@ export class RpcCore {
return memoized;
}
private _formatInputs (registry: Registry, blockHash: Uint8Array | string | null | undefined, def: DefinitionRpc, inputs: unknown[]): Codec[] {
const reqArgCount = def.params.filter(({ isOptional }) => !isOptional).length;
const optText = reqArgCount === def.params.length
? ''
: ` (${def.params.length - reqArgCount} optional)`;
private _formatParams (registry: Registry, blockHash: Uint8Array | string | null | undefined, def: DefinitionRpc, inputs: unknown[]): Codec[] {
const count = inputs.length;
const reqCount = def.params.filter(({ isOptional }) => !isOptional).length;
if (inputs.length < reqArgCount || inputs.length > def.params.length) {
throw new Error(`Expected ${def.params.length} parameters${optText}, ${inputs.length} found instead`);
if (count < reqCount || count > def.params.length) {
throw new Error(`Expected ${def.params.length} parameters${reqCount === def.params.length ? '' : ` (${def.params.length - reqCount} optional)`}, ${count} found instead`);
}
return inputs.map((input, index): Codec =>
registry.createTypeUnsafe(def.params[index].type, [input], { blockHash })
);
const params = new Array<Codec>(count);
for (let i = 0; i < count; i++) {
params[i] = registry.createTypeUnsafe(def.params[i].type, [inputs[i]], { blockHash });
}
return params;
}
private _formatOutput (registry: Registry, blockHash: Uint8Array | string | null | undefined, method: string, rpc: DefinitionRpc, params: Codec[], result?: unknown): Codec | Codec[] {
@@ -382,10 +390,18 @@ export class RpcCore {
? this._formatStorageSet(registry, (result as StorageChangeSetJSON).block, keys, (result as StorageChangeSetJSON).changes)
: registry.createType('StorageChangeSet', result);
} else if (rpc.type === 'Vec<StorageChangeSet>') {
const mapped = (result as StorageChangeSetJSON[]).map(({ block, changes }): [Hash, Codec[]] => [
registry.createType('Hash', block),
this._formatStorageSet(registry, block, params[0] as Vec<StorageKey>, changes)
]);
const jsonSet = (result as StorageChangeSetJSON[]);
const count = jsonSet.length;
const mapped = new Array<[Hash, Codec[]]>(count);
for (let i = 0; i < count; i++) {
const { block, changes } = jsonSet[i];
mapped[i] = [
registry.createType('BlockHash', block),
this._formatStorageSet(registry, block, params[0] as Vec<StorageKey>, changes)
];
}
// we only query at a specific block, not a range - flatten
return method === 'queryStorageAt'
@@ -412,17 +428,17 @@ export class RpcCore {
private _formatStorageSet (registry: Registry, blockHash: string, keys: Vec<StorageKey>, changes: [string, string | null][]): Codec[] {
// For StorageChangeSet, the changes has the [key, value] mappings
const withCache = keys.length !== 1;
const count = keys.length;
const withCache = count !== 1;
const values = new Array<Codec>(count);
// multiple return values (via state.storage subscription), decode the values
// one at a time, all based on the query types. Three values can be returned -
// - Codec - There is a valid value, non-empty
// - null - The storage key is empty
return keys.reduce((results: Codec[], key: StorageKey, index): Codec[] => {
results.push(this._formatStorageSetEntry(registry, blockHash, key, changes, withCache, index));
// multiple return values (via state.storage subscription), decode the
// values one at a time, all based on the supplied query types
for (let i = 0; i < count; i++) {
values[i] = this._formatStorageSetEntry(registry, blockHash, keys[i], changes, withCache, i);
}
return results;
}, []);
return values;
}
private _formatStorageSetEntry (registry: Registry, blockHash: string, key: StorageKey, changes: [string, string | null][], withCache: boolean, entryIndex: number): Codec {
@@ -478,9 +494,9 @@ export class RpcCore {
: hexToU8a(meta.fallback.toHex())
: undefined
: meta.modifier.isOptional
? registry.createTypeUnsafe(type, [input], { blockHash, isPedantic: true })
? registry.createTypeUnsafe(type, [input], { blockHash, isPedantic: this.#isPedantic })
: input
], { blockHash, isFallback: isEmpty && !!meta.fallback, isOptional: meta.modifier.isOptional, isPedantic: !meta.modifier.isOptional });
], { blockHash, isFallback: isEmpty && !!meta.fallback, isOptional: meta.modifier.isOptional, isPedantic: this.#isPedantic && !meta.modifier.isOptional });
} catch (error) {
throw new Error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}:${entryNum}: ${(error as Error).message}`);
}
+1 -1
View File
@@ -19,7 +19,7 @@ describe('Cached Observables', (): void => {
beforeEach((): void => {
provider = new MockProvider(registry);
rpc = new RpcCore('123', registry, provider) as (RpcCore & RpcInterface);
rpc = new RpcCore('123', registry, { provider }) as (RpcCore & RpcInterface);
});
afterEach(async () => {
+10 -7
View File
@@ -16,18 +16,21 @@ describe('Api', (): void => {
it('requires a provider with a send method', (): void => {
expect(
() => new RpcCore('234', registry, {} as unknown as ProviderInterface)
() => new RpcCore('234', registry, { provider: {} as unknown as ProviderInterface })
).toThrow(/Expected Provider/);
});
it('allows for the definition of user RPCs', async () => {
const provider = new MockProvider(registry);
const rpc = new RpcCore('567', registry, provider, {
testing: {
foo: {
description: 'foo',
params: [{ name: 'bar', type: 'u32' }],
type: 'Balance'
const rpc = new RpcCore('567', registry, {
provider,
userRpc: {
testing: {
foo: {
description: 'foo',
params: [{ name: 'bar', type: 'u32' }],
type: 'Balance'
}
}
}
});
+1 -1
View File
@@ -38,7 +38,7 @@ describe('methodSend', (): void => {
)
} as unknown as ProviderInterface;
rpc = new RpcCore('987', registry, provider);
rpc = new RpcCore('987', registry, { provider });
});
it('checks for mismatched parameters', async (): Promise<void> => {
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/rpc-core', path: 'auto', type: 'auto', version: '10.4.1' };
export const packageInfo = { name: '@polkadot/rpc-core', path: 'auto', type: 'auto', version: '10.5.1' };
+1 -1
View File
@@ -17,7 +17,7 @@ describe('replay', (): void => {
beforeEach((): void => {
provider = new MockProvider(registry);
rpc = new RpcCore('653', registry, provider) as (RpcCore & RpcInterface);
rpc = new RpcCore('653', registry, { provider }) as (RpcCore & RpcInterface);
});
afterEach(async () => {
+10 -10
View File
@@ -18,20 +18,20 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "10.4.1",
"version": "10.5.1",
"main": "index.js",
"dependencies": {
"@polkadot/keyring": "^12.0.1",
"@polkadot/types": "10.4.1",
"@polkadot/types-support": "10.4.1",
"@polkadot/util": "^12.0.1",
"@polkadot/util-crypto": "^12.0.1",
"@polkadot/x-fetch": "^12.0.1",
"@polkadot/x-global": "^12.0.1",
"@polkadot/x-ws": "^12.0.1",
"@polkadot/keyring": "^12.1.1",
"@polkadot/types": "10.5.1",
"@polkadot/types-support": "10.5.1",
"@polkadot/util": "^12.1.1",
"@polkadot/util-crypto": "^12.1.1",
"@polkadot/x-fetch": "^12.1.1",
"@polkadot/x-global": "^12.1.1",
"@polkadot/x-ws": "^12.1.1",
"eventemitter3": "^5.0.0",
"mock-socket": "^9.2.1",
"nock": "^13.3.0",
"nock": "^13.3.1",
"tslib": "^2.5.0"
},
"devDependencies": {
+1 -2
View File
@@ -1,8 +1,7 @@
// Copyright 2017-2023 @polkadot/rpc-provider authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { packageInfo } from './packageInfo.js';
export { HttpProvider } from './http/index.js';
export { packageInfo } from './packageInfo.js';
export { ScProvider } from './substrate-connect/index.js';
export { WsProvider } from './ws/index.js';
+2 -4
View File
@@ -3,7 +3,7 @@
import type { JsonRpcResponse, ProviderInterface, ProviderInterfaceCallback, ProviderInterfaceEmitCb, ProviderInterfaceEmitted, ProviderStats } from '../types.js';
import { logger } from '@polkadot/util';
import { logger, noop } from '@polkadot/util';
import { fetch } from '@polkadot/x-fetch';
import { RpcCoder } from '../coder/index.js';
@@ -115,9 +115,7 @@ export class HttpProvider implements ProviderInterface {
public on (_type: ProviderInterfaceEmitted, _sub: ProviderInterfaceEmitCb): () => void {
l.error('HTTP Provider does not have \'on\' emitters, use WebSockets instead');
return (): void => {
// noop
};
return noop;
}
/**
+3 -2
View File
@@ -48,9 +48,10 @@ export class LRUCache {
entries (): [string, unknown][] {
const keys = this.keys();
const entries = new Array<[string, unknown]>(keys.length);
const count = keys.length;
const entries = new Array<[string, unknown]>(count);
for (let i = 0; i < keys.length; i++) {
for (let i = 0; i < count; i++) {
const key = keys[i];
entries[i] = [key, this.#data.get(key)];
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/rpc-provider', path: 'auto', type: 'auto', version: '10.4.1' };
export const packageInfo = { name: '@polkadot/rpc-provider', path: 'auto', type: 'auto', version: '10.5.1' };
+14 -9
View File
@@ -1,8 +1,7 @@
// Copyright 2017-2023 @polkadot/rpc-provider authors & contributors
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable camelcase */
import type { Constructor } from '@polkadot/util/types';
import type { EndpointStats, JsonRpcResponse, ProviderInterface, ProviderInterfaceCallback, ProviderInterfaceEmitCb, ProviderInterfaceEmitted, ProviderStats } from '../types.js';
import { EventEmitter } from 'eventemitter3';
@@ -209,8 +208,8 @@ export class WsProvider implements ProviderInterface {
try {
this.#endpointIndex = this.selectEndpointIndex(this.#endpoints);
// the as typeof WebSocket here is Deno-specific - not available on the globalThis
this.#websocket = typeof xglobal.WebSocket !== 'undefined' && isChildClass(xglobal.WebSocket as typeof WebSocket, WebSocket)
// the as here is Deno-specific - not available on the globalThis
this.#websocket = typeof xglobal.WebSocket !== 'undefined' && isChildClass(xglobal.WebSocket as unknown as Constructor, WebSocket)
? new WebSocket(this.endpoint)
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - WS may be an instance of ws, which supports options
@@ -357,8 +356,12 @@ export class WsProvider implements ProviderInterface {
start: Date.now(),
subscription
};
this.#endpointStats.bytesSent += body.length;
this.#stats.total.bytesSent += body.length;
const bytesSent = body.length;
this.#endpointStats.bytesSent += bytesSent;
this.#stats.total.bytesSent += bytesSent;
this.#websocket.send(body);
} catch (error) {
this.#endpointStats.errors++;
@@ -481,8 +484,10 @@ export class WsProvider implements ProviderInterface {
#onSocketMessage = (message: MessageEvent<string>): void => {
l.debug(() => ['received', message.data]);
this.#endpointStats.bytesRecv += message.data.length;
this.#stats.total.bytesRecv += message.data.length;
const bytesRecv = message.data.length;
this.#endpointStats.bytesRecv += bytesRecv;
this.#stats.total.bytesRecv += bytesRecv;
const response = JSON.parse(message.data) as JsonRpcResponse;
@@ -603,7 +608,7 @@ export class WsProvider implements ProviderInterface {
const now = Date.now();
const ids = Object.keys(this.#handlers);
for (let i = 0; i < ids.length; i++) {
for (let i = 0, count = ids.length; i < count; i++) {
const handler = this.#handlers[ids[i]];
if ((now - handler.start) > this.#timeout) {
+14 -14
View File
@@ -18,7 +18,7 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "10.4.1",
"version": "10.5.1",
"main": "index.js",
"bin": {
"polkadot-types-chain-info": "./scripts/polkadot-types-chain-info.mjs",
@@ -28,21 +28,21 @@
"polkadot-types-internal-metadata": "./scripts/polkadot-types-internal-metadata.mjs"
},
"dependencies": {
"@polkadot/api": "10.4.1",
"@polkadot/api-augment": "10.4.1",
"@polkadot/rpc-augment": "10.4.1",
"@polkadot/rpc-provider": "10.4.1",
"@polkadot/types": "10.4.1",
"@polkadot/types-augment": "10.4.1",
"@polkadot/types-codec": "10.4.1",
"@polkadot/types-create": "10.4.1",
"@polkadot/types-support": "10.4.1",
"@polkadot/util": "^12.0.1",
"@polkadot/util-crypto": "^12.0.1",
"@polkadot/x-ws": "^12.0.1",
"@polkadot/api": "10.5.1",
"@polkadot/api-augment": "10.5.1",
"@polkadot/rpc-augment": "10.5.1",
"@polkadot/rpc-provider": "10.5.1",
"@polkadot/types": "10.5.1",
"@polkadot/types-augment": "10.5.1",
"@polkadot/types-codec": "10.5.1",
"@polkadot/types-create": "10.5.1",
"@polkadot/types-support": "10.5.1",
"@polkadot/util": "^12.1.1",
"@polkadot/util-crypto": "^12.1.1",
"@polkadot/x-ws": "^12.1.1",
"handlebars": "^4.7.7",
"tslib": "^2.5.0",
"yargs": "^17.7.1"
"yargs": "^17.7.2"
},
"devDependencies": {
"@types/websocket": "^1.0.5",
+5 -4
View File
@@ -24,13 +24,13 @@ function getDefs (apis: Apis | null, defs: Record<string, Definitions>): Record<
const named: Record<string, Record<string, DefinitionCallNamed>> = {};
const all = Object.values(defs);
for (let j = 0; j < all.length; j++) {
for (let j = 0, jcount = all.length; j < jcount; j++) {
const set = all[j].runtime;
if (set) {
const sections = Object.entries(set);
for (let i = 0; i < sections.length; i++) {
for (let i = 0, scount = sections.length; i < scount; i++) {
const [_section, sec] = sections[i];
const sectionHash = blake2AsHex(_section, 64);
const api = apis && apis.find(([h]) => h === sectionHash);
@@ -40,15 +40,16 @@ function getDefs (apis: Apis | null, defs: Record<string, Definitions>): Record<
if (ver) {
const methods = Object.entries(ver.methods);
const mcount = methods.length;
if (methods.length) {
if (mcount) {
const section = stringCamelCase(_section);
if (!named[section]) {
named[section] = {};
}
for (let m = 0; m < methods.length; m++) {
for (let m = 0; m < mcount; m++) {
const [_method, def] = methods[m];
const method = stringCamelCase(_method);
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/typegen', path: 'auto', type: 'auto', version: '10.4.1' };
export const packageInfo = { name: '@polkadot/typegen', path: 'auto', type: 'auto', version: '10.5.1' };
+1 -1
View File
@@ -41,7 +41,7 @@ function splitAlternatives (type: string): string[] {
let level = 0;
// we assume that the string starts with '['
for (let i = 1; i < type.length; i++) {
for (let i = 1, count = type.length; i < count; i++) {
if (level === 0) {
switch (type[i]) {
case ']':
+4 -4
View File
@@ -18,12 +18,12 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "10.4.1",
"version": "10.5.1",
"main": "index.js",
"dependencies": {
"@polkadot/types": "10.4.1",
"@polkadot/types-codec": "10.4.1",
"@polkadot/util": "^12.0.1",
"@polkadot/types": "10.5.1",
"@polkadot/types-codec": "10.5.1",
"@polkadot/util": "^12.1.1",
"tslib": "^2.5.0"
}
}
@@ -1111,7 +1111,10 @@ export default {
beneficiary: 'XcmVersionedMultiLocation',
assets: 'XcmVersionedMultiAssets',
feeAssetItem: 'u32',
weightLimit: 'XcmV3WeightLimit'
weightLimit: 'XcmV3WeightLimit',
},
force_suspension: {
suspended: 'bool'
}
}
},
@@ -5590,7 +5590,8 @@ export default {
tableSize: 'u32',
brTableSize: 'u32',
subjectLen: 'u32',
payloadLen: 'u32'
payloadLen: 'u32',
runtimeMemory: 'u32'
},
/**
* Lookup552: pallet_contracts::schedule::InstructionWeights<T>
@@ -983,7 +983,11 @@ declare module '@polkadot/types/lookup' {
readonly feeAssetItem: u32;
readonly weightLimit: XcmV3WeightLimit;
} & Struct;
readonly type: 'Send' | 'TeleportAssets' | 'ReserveTransferAssets' | 'Execute' | 'ForceXcmVersion' | 'ForceDefaultXcmVersion' | 'ForceSubscribeVersionNotify' | 'ForceUnsubscribeVersionNotify' | 'LimitedReserveTransferAssets' | 'LimitedTeleportAssets';
readonly isForceSuspension: boolean;
readonly asForceSuspension: {
readonly suspended: bool;
} & Struct;
readonly type: 'Send' | 'TeleportAssets' | 'ReserveTransferAssets' | 'Execute' | 'ForceXcmVersion' | 'ForceDefaultXcmVersion' | 'ForceSubscribeVersionNotify' | 'ForceUnsubscribeVersionNotify' | 'LimitedReserveTransferAssets' | 'LimitedTeleportAssets' | 'ForceSuspension';
}
/** @name XcmVersionedMultiLocation (371) */
@@ -6056,6 +6056,7 @@ declare module '@polkadot/types/lookup' {
readonly brTableSize: u32;
readonly subjectLen: u32;
readonly payloadLen: u32;
readonly runtimeMemory: u32;
}
/** @name PalletContractsScheduleInstructionWeights (552) */
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/types-augment', path: 'auto', type: 'auto', version: '10.4.1' };
export const packageInfo = { name: '@polkadot/types-augment', path: 'auto', type: 'auto', version: '10.5.1' };
+7 -7
View File
@@ -18,17 +18,17 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "10.4.1",
"version": "10.5.1",
"main": "index.js",
"dependencies": {
"@polkadot/util": "^12.0.1",
"@polkadot/x-bigint": "^12.0.1",
"@polkadot/util": "^12.1.1",
"@polkadot/x-bigint": "^12.1.1",
"tslib": "^2.5.0"
},
"devDependencies": {
"@polkadot/types": "10.4.1",
"@polkadot/types-augment": "10.4.1",
"@polkadot/types-support": "10.4.1",
"@polkadot/util-crypto": "^12.0.1"
"@polkadot/types": "10.5.1",
"@polkadot/types-augment": "10.5.1",
"@polkadot/types-support": "10.5.1",
"@polkadot/util-crypto": "^12.1.1"
}
}
+21 -14
View File
@@ -42,9 +42,10 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
public get encodedLength (): number {
// We need to loop through all entries since they may have a variable length themselves,
// e.g. when a Vec or Compact is contained withing, it has a variable length based on data
let total = compactToU8a(this.length).length;
const count = this.length;
let total = compactToU8a(count).length;
for (let i = 0; i < this.length; i++) {
for (let i = 0; i < count; i++) {
total += this[i].encodedLength;
}
@@ -95,9 +96,10 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
* @description Internal per-item inspection of internal values
*/
public inspectInner (): Inspect[] {
const inner = new Array<Inspect>(this.length);
const count = this.length;
const inner = new Array<Inspect>(count);
for (let i = 0; i < this.length; i++) {
for (let i = 0; i < count; i++) {
inner[i] = this[i].inspect();
}
@@ -122,9 +124,10 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
*/
public toHuman (isExtended?: boolean): AnyJson {
const result = new Array<AnyJson>(this.length);
const count = this.length;
const result = new Array<AnyJson>(count);
for (let i = 0; i < this.length; i++) {
for (let i = 0; i < count; i++) {
result[i] = this[i] && this[i].toHuman(isExtended);
}
@@ -135,9 +138,10 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
* @description Converts the Object to JSON, typically used for RPC transfers
*/
public toJSON (): AnyJson {
const result = new Array<AnyJson>(this.length);
const count = this.length;
const result = new Array<AnyJson>(count);
for (let i = 0; i < this.length; i++) {
for (let i = 0; i < count; i++) {
// We actually log inside the U8a decoding and use JSON.stringify(...), which
// means that the Vec may be partially populated (same applies to toHuman, same check)
result[i] = this[i] && this[i].toJSON();
@@ -150,9 +154,10 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
* @description Converts the value in a best-fit primitive form
*/
public toPrimitive (): AnyJson {
const result = new Array<AnyJson>(this.length);
const count = this.length;
const result = new Array<AnyJson>(count);
for (let i = 0; i < this.length; i++) {
for (let i = 0; i < count; i++) {
result[i] = this[i] && this[i].toPrimitive();
}
@@ -168,9 +173,10 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
* @description Returns the string representation of the value
*/
public override toString (): string {
const result = new Array<string>(this.length);
const count = this.length;
const result = new Array<string>(count);
for (let i = 0; i < this.length; i++) {
for (let i = 0; i < count; i++) {
result[i] = this[i].toString();
}
@@ -195,9 +201,10 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
* @param isBare true when the value has none of the type-specific prefixes (internal)
*/
public toU8aInner (isBare?: boolean): Uint8Array[] {
const encoded = new Array<Uint8Array>(this.length);
const count = this.length;
const encoded = new Array<Uint8Array>(count);
for (let i = 0; i < this.length; i++) {
for (let i = 0; i < count; i++) {
encoded[i] = this[i].toU8a(isBare);
}
+3 -3
View File
@@ -221,9 +221,9 @@ export abstract class AbstractInt extends BN implements INumber {
public override toJSON (onlyHex = false): any {
// FIXME this return type should by string | number, however BN returns string
// Options here are
// - super.bitLength() - the actual used bits
// - this.#bitLength - the type bits (this should be used, however contracts RPC is problematic)
return onlyHex || (super.bitLength() > MAX_NUMBER_BITS)
// - super.bitLength() - the actual used bits, use hex when close to MAX_SAFE_INTEGER
// - this.#bitLength - the max used bits, use hex when larger than native Rust type
return onlyHex || (this.#bitLength > 128) || (super.bitLength() > MAX_NUMBER_BITS)
? this.toHex()
: this.toNumber();
}
+2 -6
View File
@@ -5,14 +5,10 @@ import type { BN } from '@polkadot/util';
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, AnyNumber, CodecClass, DefinitionSetter, ICompact, Inspect, INumber, IU8a, Registry } from '../types/index.js';
import { compactFromU8a, compactFromU8aLim, compactToU8a, isU8a } from '@polkadot/util';
import { compactFromU8a, compactFromU8aLim, compactToU8a, identity, isU8a } from '@polkadot/util';
import { typeToConstructor } from '../utils/index.js';
function noopSetDefinition <T> (d: CodecClass<T>): CodecClass<T> {
return d;
}
function decodeCompact<T extends INumber> (registry: Registry, Type: CodecClass<T>, value: Compact<T> | AnyNumber): [T, number] {
if (isU8a(value)) {
const [decodedLength, bn] = (value[0] & 0b11) < 0b11
@@ -51,7 +47,7 @@ export class Compact<T extends INumber> implements ICompact<T> {
readonly #Type: CodecClass<T>;
readonly #raw: T;
constructor (registry: Registry, Type: CodecClass<T> | string, value: Compact<T> | AnyNumber = 0, { definition, setDefinition = noopSetDefinition }: DefinitionSetter<CodecClass<T>> = {}) {
constructor (registry: Registry, Type: CodecClass<T> | string, value: Compact<T> | AnyNumber = 0, { definition, setDefinition = identity }: DefinitionSetter<CodecClass<T>> = {}) {
this.registry = registry;
this.#Type = definition || setDefinition(typeToConstructor(registry, Type));
+9 -12
View File
@@ -4,7 +4,7 @@
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, Codec, CodecClass, DefinitionSetter, IEnum, Inspect, IU8a, Registry } from '../types/index.js';
import { isHex, isNumber, isObject, isString, isU8a, objectProperties, stringCamelCase, stringify, stringPascalCase, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
import { identity, isHex, isNumber, isObject, isString, isU8a, objectProperties, stringCamelCase, stringify, stringPascalCase, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
import { mapToTypeMap, typesToMap } from '../utils/index.js';
import { Null } from './Null.js';
@@ -32,10 +32,6 @@ interface Decoded {
value: Codec;
}
function noopSetDefinition (d: Definition): Definition {
return d;
}
function isRustEnum (def: Record<string, string | CodecClass> | Record<string, number>): def is Record<string, string | CodecClass> {
const defValues = Object.values(def);
@@ -56,7 +52,7 @@ function extractDef (registry: Registry, _def: Record<string, string | CodecClas
let isIndexed: boolean;
if (Array.isArray(_def)) {
for (let i = 0; i < _def.length; i++) {
for (let i = 0, count = _def.length; i < count; i++) {
def[_def[i]] = { Type: Null, index: i };
}
@@ -65,7 +61,7 @@ function extractDef (registry: Registry, _def: Record<string, string | CodecClas
} else if (isRustEnum(_def)) {
const [Types, keys] = mapToTypeMap(registry, _def);
for (let i = 0; i < keys.length; i++) {
for (let i = 0, count = keys.length; i < count; i++) {
def[keys[i]] = { Type: Types[i], index: i };
}
@@ -74,7 +70,7 @@ function extractDef (registry: Registry, _def: Record<string, string | CodecClas
} else {
const entries = Object.entries(_def);
for (let i = 0; i < entries.length; i++) {
for (let i = 0, count = entries.length; i < count; i++) {
const [key, index] = entries[i];
def[key] = { Type: Null, index };
@@ -191,7 +187,7 @@ export class Enum implements IEnum {
readonly #isIndexed: boolean;
readonly #raw: Codec;
constructor (registry: Registry, Types: Record<string, string | CodecClass> | Record<string, number> | string[], value?: unknown, index?: number, { definition, setDefinition = noopSetDefinition }: DefinitionSetter<Definition> = {}) {
constructor (registry: Registry, Types: Record<string, string | CodecClass> | Record<string, number> | string[], value?: unknown, index?: number, { definition, setDefinition = identity }: DefinitionSetter<Definition> = {}) {
const { def, isBasic, isIndexed } = definition || setDefinition(extractDef(registry, Types));
// shortcut isU8a as used in SCALE decoding
@@ -224,10 +220,11 @@ export class Enum implements IEnum {
const keys = Array.isArray(Types)
? Types
: Object.keys(Types);
const asKeys = new Array<string>(keys.length);
const isKeys = new Array<string>(keys.length);
const count = keys.length;
const asKeys = new Array<string>(count);
const isKeys = new Array<string>(count);
for (let i = 0; i < keys.length; i++) {
for (let i = 0; i < count; i++) {
const name = stringPascalCase(keys[i]);
asKeys[i] = `as${name}`;
+2 -6
View File
@@ -4,15 +4,11 @@
import type { HexString } from '@polkadot/util/types';
import type { AnyJson, Codec, CodecClass, DefinitionSetter, Inspect, IOption, IU8a, Registry } from '../types/index.js';
import { isCodec, isNull, isU8a, isUndefined, u8aToHex } from '@polkadot/util';
import { identity, isCodec, isNull, isU8a, isUndefined, u8aToHex } from '@polkadot/util';
import { typeToConstructor } from '../utils/index.js';
import { Null } from './Null.js';
function noopSetDefinition <T extends Codec> (d: CodecClass<T>): CodecClass<T> {
return d;
}
class None extends Null {
/**
* @description Returns the base runtime type name for this instance
@@ -70,7 +66,7 @@ export class Option<T extends Codec> implements IOption<T> {
readonly #Type: CodecClass<T>;
readonly #raw: T;
constructor (registry: Registry, typeName: CodecClass<T> | string, value?: unknown, { definition, setDefinition = noopSetDefinition }: DefinitionSetter<CodecClass<T>> = {}) {
constructor (registry: Registry, typeName: CodecClass<T> | string, value?: unknown, { definition, setDefinition = identity }: DefinitionSetter<CodecClass<T>> = {}) {
const Type = definition || setDefinition(typeToConstructor(registry, typeName));
const decoded = isU8a(value) && value.length && !isCodec(value)
? value[0] === 0
+7 -11
View File
@@ -3,10 +3,10 @@
import type { AnyTupleValue, Codec, CodecClass, DefinitionSetter, Inspect, ITuple, Registry } from '../types/index.js';
import { isFunction, isHex, isString, isU8a, stringify, u8aConcatStrict, u8aToU8a } from '@polkadot/util';
import { identity, isFunction, isHex, isString, isU8a, stringify, u8aConcatStrict, u8aToU8a } from '@polkadot/util';
import { AbstractArray } from '../abstract/Array.js';
import { decodeU8a, mapToTypeMap, typeToConstructor } from '../utils/index.js';
import { decodeU8a, mapToTypeMap, typesToConstructors, typeToConstructor } from '../utils/index.js';
type TupleType = (CodecClass | string);
@@ -16,16 +16,12 @@ type TupleTypes = TupleType[] | {
type Definition = [CodecClass[], string[]];
function noopSetDefinition (d: Definition): Definition {
return d;
}
/** @internal */
function decodeTuple (registry: Registry, result: Codec[], value: Exclude<AnyTupleValue, Uint8Array> | undefined, Classes: Definition): [Codec[], number] {
if (Array.isArray(value)) {
const Types = Classes[0];
for (let i = 0; i < Types.length; i++) {
for (let i = 0, count = Types.length; i < count; i++) {
try {
const entry = value?.[i];
@@ -43,7 +39,7 @@ function decodeTuple (registry: Registry, result: Codec[], value: Exclude<AnyTup
} else if (!value || !result.length) {
const Types = Classes[0];
for (let i = 0; i < Types.length; i++) {
for (let i = 0, count = Types.length; i < count; i++) {
result[i] = new Types[i](registry);
}
@@ -62,10 +58,10 @@ function decodeTuple (registry: Registry, result: Codec[], value: Exclude<AnyTup
export class Tuple extends AbstractArray<Codec> implements ITuple<Codec[]> {
#Types: Definition;
constructor (registry: Registry, Types: TupleTypes | TupleType, value?: AnyTupleValue, { definition, setDefinition = noopSetDefinition }: DefinitionSetter<Definition> = {}) {
constructor (registry: Registry, Types: TupleTypes | TupleType, value?: AnyTupleValue, { definition, setDefinition = identity }: DefinitionSetter<Definition> = {}) {
const Classes = definition || setDefinition(
Array.isArray(Types)
? [Types.map((t) => typeToConstructor(registry, t)), []]
? [typesToConstructors(registry, Types), []]
: isFunction(Types) || isString(Types)
? [[typeToConstructor(registry, Types)], []]
: mapToTypeMap(registry, Types)
@@ -101,7 +97,7 @@ export class Tuple extends AbstractArray<Codec> implements ITuple<Codec[]> {
public override get encodedLength (): number {
let total = 0;
for (let i = 0; i < this.length; i++) {
for (let i = 0, count = this.length; i < count; i++) {
total += this[i].encodedLength;
}
+2 -1
View File
@@ -123,8 +123,9 @@ describe('UInt', (): void => {
it('converts to JSON representation based on size', (): void => {
expect(new UInt(registry, '0x12345678', 32).toJSON()).toEqual(0x12345678);
expect(new UInt(registry, '0x1234567890', 64).toJSON()).toEqual(78187493520); // '0x0000001234567890');
expect(new UInt(registry, '0x1234567890', 64).toJSON()).toEqual(78187493520);
expect(new UInt(registry, '0x1234567890abcdef', 64).toJSON()).toEqual('0x1234567890abcdef');
expect(new UInt(registry, 1, 256).toJSON()).toEqual('0x0000000000000000000000000000000000000000000000000000000000000001');
});
it('has a sane inspect', (): void => {
+3 -7
View File
@@ -4,7 +4,7 @@
import type { HexString } from '@polkadot/util/types';
import type { Codec, CodecClass, DefinitionSetter, Registry } from '../types/index.js';
import { compactFromU8aLim, isHex, isU8a, logger, stringify, u8aToU8a } from '@polkadot/util';
import { compactFromU8aLim, identity, isHex, isU8a, logger, stringify, u8aToU8a } from '@polkadot/util';
import { AbstractArray } from '../abstract/Array.js';
import { decodeU8aVec, typeToConstructor } from '../utils/index.js';
@@ -13,10 +13,6 @@ const MAX_LENGTH = 64 * 1024;
const l = logger('Vec');
function noopSetDefinition <T extends Codec> (d: CodecClass<T>): CodecClass<T> {
return d;
}
function decodeVecLength (value: Uint8Array | HexString | unknown[]): [Uint8Array | unknown[] | null, number, number] {
if (Array.isArray(value)) {
return [value, value.length, 0];
@@ -75,7 +71,7 @@ export function decodeVec<T extends Codec> (registry: Registry, result: T[], val
export class Vec<T extends Codec> extends AbstractArray<T> {
#Type: CodecClass<T>;
constructor (registry: Registry, Type: CodecClass<T> | string, value: Uint8Array | HexString | unknown[] = [], { definition, setDefinition = noopSetDefinition }: DefinitionSetter<CodecClass<T>> = {}) {
constructor (registry: Registry, Type: CodecClass<T> | string, value: Uint8Array | HexString | unknown[] = [], { definition, setDefinition = identity }: DefinitionSetter<CodecClass<T>> = {}) {
const [decodeFrom, length, startAt] = decodeVecLength(value);
super(registry, length);
@@ -119,7 +115,7 @@ export class Vec<T extends Codec> extends AbstractArray<T> {
? other
: new this.#Type(this.registry, other);
for (let i = 0; i < this.length; i++) {
for (let i = 0, count = this.length; i < count; i++) {
if (check.eq(this[i])) {
return i;
}
+3 -7
View File
@@ -4,16 +4,12 @@
import type { HexString } from '@polkadot/util/types';
import type { Codec, CodecClass, DefinitionSetter, Inspect, Registry } from '../types/index.js';
import { isU8a, u8aConcatStrict } from '@polkadot/util';
import { identity, isU8a, u8aConcatStrict } from '@polkadot/util';
import { AbstractArray } from '../abstract/Array.js';
import { decodeU8aVec, typeToConstructor } from '../utils/index.js';
import { decodeVec } from './Vec.js';
function noopSetDefinition <T extends Codec> (d: CodecClass<T>): CodecClass<T> {
return d;
}
/**
* @name VecFixed
* @description
@@ -22,7 +18,7 @@ function noopSetDefinition <T extends Codec> (d: CodecClass<T>): CodecClass<T> {
export class VecFixed<T extends Codec> extends AbstractArray<T> {
#Type: CodecClass<T>;
constructor (registry: Registry, Type: CodecClass<T> | string, length: number, value: Uint8Array | HexString | unknown[] = [] as unknown[], { definition, setDefinition = noopSetDefinition }: DefinitionSetter<CodecClass<T>> = {}) {
constructor (registry: Registry, Type: CodecClass<T> | string, length: number, value: Uint8Array | HexString | unknown[] = [] as unknown[], { definition, setDefinition = identity }: DefinitionSetter<CodecClass<T>> = {}) {
super(registry, length);
this.#Type = definition || setDefinition(typeToConstructor<T>(registry, Type));
@@ -61,7 +57,7 @@ export class VecFixed<T extends Codec> extends AbstractArray<T> {
public override get encodedLength (): number {
let total = 0;
for (let i = 0; i < this.length; i++) {
for (let i = 0, count = this.length; i < count; i++) {
total += this[i].encodedLength;
}
+2
View File
@@ -1,8 +1,10 @@
// Copyright 2017-2023 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
// all named
export { packageInfo } from './packageInfo.js';
// all starred
export * from './abstract/index.js';
export * from './base/index.js';
export * from './extended/index.js';
+3 -2
View File
@@ -87,9 +87,10 @@ export class BitVec extends Raw {
!!(v & 0b0000_0010),
!!(v & 0b0000_0001)
]);
const result = new Array<boolean>(8 * map.length);
const count = map.length;
const result = new Array<boolean>(8 * count);
for (let i = 0; i < map.length; i++) {
for (let i = 0; i < count; i++) {
const off = i * 8;
const v = map[i];
+1 -1
View File
@@ -26,7 +26,7 @@ function decodeMapFromU8a<K extends Codec, V extends Codec> (registry: Registry,
const [values, decodedLength] = decodeU8a(registry, new Array(types.length), u8a.subarray(offset), [types, []]);
for (let i = 0; i < values.length; i += 2) {
for (let i = 0, count = values.length; i < count; i += 2) {
output.set(values[i] as K, values[i + 1] as V);
}
+8 -6
View File
@@ -13,7 +13,7 @@ type SetValues = Record<string, number | BN>;
function encodeSet (setValues: SetValues, values: string[]): BN {
const encoded = new BN(0);
for (let i = 0; i < values.length; i++) {
for (let i = 0, count = values.length; i < count; i++) {
encoded.ior(bnToBn(setValues[values[i]] || 0));
}
@@ -22,9 +22,10 @@ function encodeSet (setValues: SetValues, values: string[]): BN {
/** @internal */
function decodeSetArray (setValues: SetValues, values: string[]): string[] {
const result = new Array<string>(values.length);
const count = values.length;
const result = new Array<string>(count);
for (let i = 0; i < values.length; i++) {
for (let i = 0; i < count; i++) {
const key = values[i];
if (isUndefined(setValues[key])) {
@@ -43,7 +44,7 @@ function decodeSetNumber (setValues: SetValues, _value: BN | number): string[] {
const keys = Object.keys(setValues);
const result: string[] = [];
for (let i = 0; i < keys.length; i++) {
for (let i = 0, count = keys.length; i < count; i++) {
const key = keys[i];
if (bn.and(bnToBn(setValues[key])).eq(bnToBn(setValues[key]))) {
@@ -113,9 +114,10 @@ export class CodecSet extends Set<string> implements ISet<string> {
return class extends CodecSet {
static {
const keys = Object.keys(values);
const isKeys = new Array<string>(keys.length);
const count = keys.length;
const isKeys = new Array<string>(count);
for (let i = 0; i < keys.length; i++) {
for (let i = 0; i < count; i++) {
isKeys[i] = `is${stringPascalCase(keys[i])}`;
}
+6 -5
View File
@@ -21,16 +21,17 @@ function decodeStructFromObject (registry: Registry, [Types, keys]: Definition,
let jsonObj: Record<string, unknown> | undefined;
const typeofArray = Array.isArray(value);
const typeofMap = value instanceof Map;
const count = keys.length;
if (!typeofArray && !typeofMap && !isObject(value)) {
throw new Error(`Struct: Cannot decode value ${stringify(value)} (typeof ${typeof value}), expected an input object, map or array`);
} else if (typeofArray && value.length !== keys.length) {
} else if (typeofArray && value.length !== count) {
throw new Error(`Struct: Unable to map ${stringify(value)} array to object with known keys ${keys.join(', ')}`);
}
const raw = new Array<[string, Codec]>(keys.length);
const raw = new Array<[string, Codec]>(count);
for (let i = 0; i < keys.length; i++) {
for (let i = 0; i < count; i++) {
const key = keys[i];
const jsonKey = jsonMap.get(key) || key;
const Type = Types[i];
@@ -50,7 +51,7 @@ function decodeStructFromObject (registry: Registry, [Types, keys]: Definition,
jsonObj = {};
for (let e = 0; e < entries.length; e++) {
for (let e = 0, ecount = entries.length; e < ecount; e++) {
jsonObj[stringCamelCase(entries[e][0])] = entries[e][1];
}
}
@@ -192,7 +193,7 @@ export class Struct<
const result: Record<string, string> = {};
const [Types, keys] = this.#Types;
for (let i = 0; i < keys.length; i++) {
for (let i = 0, count = keys.length; i < count; i++) {
result[keys[i]] = new Types[i](this.registry).toRawType();
}
+1 -1
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { bool, bool as Bool } from './Bool.js';
export { bool as Bool, bool } from './Bool.js';
export { CodecDate, CodecDate as Date } from './Date.js';
export { Float } from './Float.js';
export { Json } from './Json.js';
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/types-codec', path: 'auto', type: 'auto', version: '10.4.1' };
export const packageInfo = { name: '@polkadot/types-codec', path: 'auto', type: 'auto', version: '10.5.1' };
+16 -16
View File
@@ -1,19 +1,19 @@
// Copyright 2017-2023 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { f32, f32 as F32 } from './F32.js';
export { f64, f64 as F64 } from './F64.js';
export { i8, i8 as I8 } from './I8.js';
export { i16, i16 as I16 } from './I16.js';
export { i32, i32 as I32 } from './I32.js';
export { i64, i64 as I64 } from './I64.js';
export { i128, i128 as I128 } from './I128.js';
export { i256, i256 as I256 } from './I256.js';
export { isize, isize as ISize } from './ISize.js';
export { u8, u8 as U8 } from './U8.js';
export { u16, u16 as U16 } from './U16.js';
export { u32, u32 as U32 } from './U32.js';
export { u64, u64 as U64 } from './U64.js';
export { u128, u128 as U128 } from './U128.js';
export { u256, u256 as U256 } from './U256.js';
export { usize, usize as USize } from './USize.js';
export { f32 as F32, f32 } from './F32.js';
export { f64 as F64, f64 } from './F64.js';
export { i8 as I8, i8 } from './I8.js';
export { i16 as I16, i16 } from './I16.js';
export { i32 as I32, i32 } from './I32.js';
export { i64 as I64, i64 } from './I64.js';
export { i128 as I128, i128 } from './I128.js';
export { i256 as I256, i256 } from './I256.js';
export { isize as ISize, isize } from './ISize.js';
export { u8 as U8, u8 } from './U8.js';
export { u16 as U16, u16 } from './U16.js';
export { u32 as U32, u32 } from './U32.js';
export { u64 as U64, u64 } from './U64.js';
export { u128 as U128, u128 } from './U128.js';
export { u256 as U256, u256 } from './U256.js';
export { usize as USize, usize } from './USize.js';
+4 -3
View File
@@ -13,12 +13,13 @@ const PRE_PAD = 32;
function loop (count: number, inputs: unknown[][], exec: ExecFn): [number, unknown[]] {
const start = performance.now();
const results = new Array<unknown>(inputs.length);
const inputsCount = inputs.length;
const results = new Array<unknown>(inputsCount);
for (let i = 0; i < count; i++) {
const result = exec(...inputs[i % inputs.length]);
const result = exec(...inputs[i % inputsCount]);
if (i < inputs.length) {
if (i < inputsCount) {
results[i] = result;
}
}
@@ -64,6 +64,9 @@ export interface Registry {
createClassUnsafe <T extends Codec = Codec, K extends string = string> (type: K): CodecClass<T>;
createTypeUnsafe <T extends Codec = Codec, K extends string = string> (type: K, params: unknown[], options?: CodecCreateOptions): T;
// get is for Compat, overridden in derived classes
get (...params: never[]): any;
getClassName (clazz: CodecClass): string | undefined;
getOrThrow <T extends Codec = Codec, K extends string = string> (name: K, msg?: string): CodecClass<T>;
getOrUnknown <T extends Codec = Codec, K extends string = string> (name: K): CodecClass<T>;
@@ -5,7 +5,7 @@ import { isUndefined } from '@polkadot/util';
import { hasEq } from './util.js';
// NOTE These are used internally and when comparing objects, expects that
// NOTE These are used internally and when comparing objects, we expect that
// when the second is an Codec[] that the first has to be as well
export function compareArray (a: unknown[], b?: unknown): boolean {
if (Array.isArray(b)) {
+1 -1
View File
@@ -25,7 +25,7 @@ function compareMapArray (a: Map<unknown, unknown>, b: [unknown, unknown][]): bo
);
}
// NOTE These are used internally and when comparing objects, expects that
// NOTE These are used internally and when comparing objects, we expect that
// when the second is an Map<string, Codec> that the first has to be as well
export function compareMap (a: Map<unknown, unknown>, b?: unknown): boolean {
if (Array.isArray(b)) {
+1 -1
View File
@@ -8,7 +8,7 @@ function compareSetArray (a: Set<unknown>, b: any[]): boolean {
return (a.size === b.length) && !b.some((e) => !a.has(e));
}
// NOTE These are used internally and when comparing objects, expects that
// NOTE These are used internally and when comparing objects, we expect that
// when the second is an Set<string, Codec> that the first has to be as well
export function compareSet (a: Set<unknown>, b?: unknown): boolean {
if (Array.isArray(b)) {
+2 -3
View File
@@ -5,8 +5,7 @@ export { compareArray } from './compareArray.js';
export { compareMap } from './compareMap.js';
export { compareSet } from './compareSet.js';
export { decodeU8a, decodeU8aStruct, decodeU8aVec } from './decodeU8a.js';
export { mapToTypeMap } from './mapToTypeMap.js';
export { typeToConstructor } from './typeToConstructor.js';
export { sanitize } from './sanitize.js';
export { sortAsc, sortSet, sortMap } from './sortValues.js';
export { sortAsc, sortMap, sortSet } from './sortValues.js';
export { mapToTypeMap, typesToConstructors, typeToConstructor } from './toConstructors.js';
export { typesToMap } from './typesToMap.js';
@@ -1,22 +0,0 @@
// Copyright 2017-2023 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CodecClass, Registry } from '../types/index.js';
import { typeToConstructor } from './typeToConstructor.js';
/**
* @description takes an input map of the form `{ [string]: string | CodecClass }` and returns a map of `{ [string]: CodecClass }`
*/
export function mapToTypeMap (registry: Registry, input: Record<string, string | CodecClass>): [CodecClass[], string[]] {
const entries = Object.entries(input);
const count = entries.length;
const output: [CodecClass[], string[]] = [new Array<CodecClass>(count), new Array<string>(count)];
for (let i = 0; i < count; i++) {
output[1][i] = entries[i][0];
output[0][i] = typeToConstructor(registry, entries[i][1]);
}
return output;
}
+16 -16
View File
@@ -58,14 +58,14 @@ export function trim (): Mapper {
export function findClosing (value: string, start: number): number {
let depth = 0;
for (let index = start; index < value.length; index++) {
if (value[index] === '>') {
for (let i = start, count = value.length; i < count; i++) {
if (value[i] === '>') {
if (!depth) {
return index;
return i;
}
depth--;
} else if (value[index] === '<') {
} else if (value[i] === '<') {
depth++;
}
}
@@ -91,12 +91,12 @@ export function alias (src: string, dest: string, withChecks = true): Mapper {
export function cleanupCompact (): Mapper {
return (value: string): string => {
if (value.includes(' as HasCompact')) {
for (let index = 0; index < value.length; index++) {
if (value[index] === '<') {
const end = findClosing(value, index + 1) - 14;
for (let i = 0, count = value.length; i < count; i++) {
if (value[i] === '<') {
const end = findClosing(value, i + 1) - 14;
if (value.substring(end, end + 14) === ' as HasCompact') {
value = `Compact<${value.substring(index + 1, end)}>`;
value = `Compact<${value.substring(i + 1, end)}>`;
}
}
}
@@ -141,7 +141,7 @@ function replaceTagWith (value: string, matcher: string, replacer: (inner: strin
// remove the Bounded* or Weak* wrappers
export function removeExtensions (type: string, isSized: boolean): Mapper {
return (value: string): string => {
for (let i = 0; i < BOUNDED.length; i++) {
for (let i = 0, count = BOUNDED.length; i < count; i++) {
const tag = BOUNDED[i];
value = replaceTagWith(value, `${type}${tag}<`, (v: string): string => {
@@ -188,16 +188,16 @@ export function removeColons (): Mapper {
export function removeGenerics (): Mapper {
return (value: string): string => {
for (let index = 0; index < value.length; index++) {
if (value[index] === '<') {
for (let i = 0, count = value.length; i < count; i++) {
if (value[i] === '<') {
// check against the allowed wrappers, be it Vec<..>, Option<...> ...
const box = ALLOWED_BOXES.find((box): boolean => {
const start = index - box.length;
const start = i - box.length;
return (
(
start >= 0 &&
value.substring(start, index) === box
value.substring(start, i) === box
) && (
// make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
start === 0 ||
@@ -208,9 +208,9 @@ export function removeGenerics (): Mapper {
// we have not found anything, unwrap generic innards
if (!box) {
const end = findClosing(value, index + 1);
const end = findClosing(value, i + 1);
value = `${value.substring(0, index)}${value.substring(end + 1)}`;
value = `${value.substring(0, i)}${value.substring(end + 1)}`;
}
}
}
@@ -280,7 +280,7 @@ export function sanitize (value: AnyString): string {
let result = startValue;
for (let i = 0; i < mappings.length; i++) {
for (let i = 0, count = mappings.length; i < count; i++) {
result = mappings[i](result);
}
+3 -8
View File
@@ -5,7 +5,7 @@ import type { BN } from '@polkadot/util';
import type { Enum } from '../base/Enum.js';
import type { Codec } from '../types/index.js';
import { bnToBn, isBigInt, isBn, isFunction, isNumber, stringify } from '@polkadot/util';
import { bnToBn, isBigInt, isBn, isCodec, isNumber, stringify } from '@polkadot/util';
type SortArg = Codec | Codec[] | number[] | BN | bigint | number | Uint8Array;
@@ -14,14 +14,9 @@ function isArrayLike (arg: SortArg): arg is Uint8Array | Codec[] | number[] {
return arg instanceof Uint8Array || Array.isArray(arg);
}
/** @internal **/
function isCodec (arg: SortArg): arg is Codec {
return isFunction(arg && (arg as Codec).toU8a);
}
/** @internal **/
function isEnum (arg: SortArg): arg is Enum {
return isCodec(arg) && isNumber((arg as Enum).index) && isCodec((arg as Enum).value);
return isCodec<Codec>(arg) && isNumber((arg as Enum).index) && isCodec((arg as Enum).value);
}
/** @internal */
@@ -60,7 +55,7 @@ export function sortAsc<V extends SortArg = Codec> (a: V, b: V): number {
return sortAsc(a.index, b.index) || sortAsc(a.value, b.value);
} else if (isArrayLike(a) && isArrayLike(b)) {
return sortArray(a, b);
} else if (isCodec(a) && isCodec(b)) {
} else if (isCodec<Codec>(a) && isCodec<Codec>(b)) {
// Text, Bool etc.
return sortAsc(a.toU8a(true), b.toU8a(true));
}
@@ -0,0 +1,46 @@
// Copyright 2017-2023 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Codec, CodecClass, Registry } from '../types/index.js';
/**
* @internal
* From a type string or class, return the associated type class
*/
export function typeToConstructor <T extends Codec = Codec> (registry: Registry, type: string | CodecClass<T>): CodecClass<T> {
return typeof type === 'function'
? type
: registry.createClassUnsafe(type);
}
/**
* @internal
* Takes an input array of types and returns the associated classes for it
*/
export function typesToConstructors <T extends Codec = Codec> (registry: Registry, types: (string | CodecClass<T>)[]): CodecClass<T>[] {
const count = types.length;
const result = new Array<CodecClass<T>>(count);
for (let i = 0; i < count; i++) {
result[i] = typeToConstructor(registry, types[i]);
}
return result;
}
/**
* @internal
* Takes an input map of the form `{ [string]: string | CodecClass }` and returns a map of `{ [string]: CodecClass }`
*/
export function mapToTypeMap (registry: Registry, input: Record<string, string | CodecClass>): [CodecClass[], string[]] {
const entries = Object.entries(input);
const count = entries.length;
const output: [CodecClass[], string[]] = [new Array<CodecClass>(count), new Array<string>(count)];
for (let i = 0; i < count; i++) {
output[1][i] = entries[i][0];
output[0][i] = typeToConstructor(registry, entries[i][1]);
}
return output;
}
@@ -1,14 +0,0 @@
// Copyright 2017-2023 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Codec, CodecClass, Registry } from '../types/index.js';
import { isString } from '@polkadot/util';
export function typeToConstructor <T extends Codec = Codec> (registry: Registry, type: string | CodecClass<T>): CodecClass<T> {
return (
isString(type)
? registry.createClassUnsafe(type)
: type
);
}
+1 -1
View File
@@ -6,7 +6,7 @@ import type { CodecClass, Registry } from '../types/index.js';
export function typesToMap (registry: Registry, [Types, keys]: [CodecClass[], string[]]): Record<string, string> {
const result: Record<string, string> = {};
for (let i = 0; i < keys.length; i++) {
for (let i = 0, count = keys.length; i < count; i++) {
result[keys[i]] = registry.getClassName(Types[i]) || new Types[i](registry).toRawType();
}
+4 -4
View File
@@ -18,14 +18,14 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "10.4.1",
"version": "10.5.1",
"main": "index.js",
"dependencies": {
"@polkadot/types-codec": "10.4.1",
"@polkadot/util": "^12.0.1",
"@polkadot/types-codec": "10.5.1",
"@polkadot/util": "^12.1.1",
"tslib": "^2.5.0"
},
"devDependencies": {
"@polkadot/types": "10.4.1"
"@polkadot/types": "10.5.1"
}
}
+2
View File
@@ -1,8 +1,10 @@
// Copyright 2017-2023 @polkadot/types-codec authors & contributors
// SPDX-License-Identifier: Apache-2.0
// all named
export { packageInfo } from './packageInfo.js';
export { TypeDefInfo } from './types/index.js';
// all starred
export * from './create/index.js';
export * from './util/index.js';
+1 -1
View File
@@ -39,7 +39,7 @@ function getTypeClassMap (value: TypeDef): Record<string, string> {
const subs = getSubDefArray(value);
const map: Record<string, string> = {};
for (let i = 0; i < subs.length; i++) {
for (let i = 0, count = subs.length; i < count; i++) {
map[subs[i].name as string] = getTypeDefType(subs[i]);
}
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/types-create', path: 'auto', type: 'auto', version: '10.4.1' };
export const packageInfo = { name: '@polkadot/types-create', path: 'auto', type: 'auto', version: '10.5.1' };
+2
View File
@@ -3,7 +3,9 @@
import './augmentRegistry.js';
// all types
export type { CodecCreateOptions as CreateOptions } from '@polkadot/types-codec/types';
// all starred
export * from './lookup.js';
export * from './types.js';
@@ -53,7 +53,7 @@ function encodeSubTypes (registry: Registry, sub: TypeDef[], asEnum?: boolean, e
const inner: Record<string, string> = objectSpread({}, extra);
for (let i = 0; i < sub.length; i++) {
for (let i = 0, count = sub.length; i < count; i++) {
const def = sub[i];
inner[def.name as string] = encodeTypeDef(registry, def);
+1 -1
View File
@@ -14,7 +14,7 @@ export function typeSplit (type: string): string[] {
// current start position
let start = 0;
for (let i = 0; i < type.length; i++) {
for (let i = 0, count = type.length; i < count; i++) {
switch (type[i]) {
// if we are not nested, add the type
case ',': {

Some files were not shown because too many files have changed in this diff Show More