Compare commits

..
30 Commits
Author SHA1 Message Date
github-actions[bot] a2ff40f735 [CI Skip] release/stable 8.14.1
skip-checks: true
2022-07-23 14:56:53 +00:00
Jaco 9c51ea14be 8.14.1 (#5102) 2022-07-23 17:48:54 +03:00
github-actions[bot] e3f912cef5 [CI Skip] bump/beta 8.13.2-13-x
skip-checks: true
2022-07-22 14:41:02 +00:00
Jaco 21808f0283 Auto-extract Meta* interface types based on version list (#5100)
* Auto-extract Meta* interface types based on version list

* Additional dedupe

* s/ALL_VERSIONS/KNOWN_VERSIONS/

* Restore type addition

* Additional <const> specifiers

* Handle contracts similar to metadata
2022-07-22 17:30:12 +03:00
github-actions[bot] 714380575c [CI Skip] bump/beta 8.13.2-12-x
skip-checks: true
2022-07-22 04:17:30 +00:00
Jaco ec76f2cefd Shortcut balance instances check (#5099) 2022-07-22 07:06:55 +03:00
github-actions[bot] 2121a1eea0 [CI Skip] bump/beta 8.13.2-11-x
skip-checks: true
2022-07-21 18:14:01 +00:00
Jaco c0e0346987 Fix for derive.balances.account (instances check) (#5098) 2022-07-21 21:06:02 +03:00
github-actions[bot] 9b5004df9b [CI Skip] bump/beta 8.13.2-10-x
skip-checks: true
2022-07-21 09:14:03 +00:00
Jaco dd7ad37dbf Bump Kusama metadata (#5096) 2022-07-21 12:05:19 +03:00
github-actions[bot] 92d6f6b98f [CI Skip] bump/beta 8.13.2-9-x
skip-checks: true
2022-07-21 06:03:26 +00:00
Jaco fcb317d65b Bump common (#5095) 2022-07-21 08:54:49 +03:00
github-actions[bot] b8d4b034ab [CI Skip] bump/beta 8.13.2-8-x
skip-checks: true
2022-07-21 04:27:26 +00:00
Jaco 60398d9f47 TransactionPaymentCallApi runtime definition (#5094) 2022-07-21 07:18:52 +03:00
github-actions[bot] 7a1525d3e2 [CI Skip] bump/beta 8.13.2-7-x
skip-checks: true
2022-07-20 11:02:12 +00:00
Jaco 1ee461dd59 Adjust CHANGELOG (#5091)
* Adjust CHANGELOG

* Bump deps
2022-07-20 13:51:23 +03:00
github-actions[bot] cfa15f98f7 [CI Skip] bump/beta 8.13.2-6-x
skip-checks: true
2022-07-20 09:21:26 +00:00
Jaco 18671cc650 Apply objectSpread on metadata conversion (as missing) (#5090) 2022-07-20 12:12:53 +03:00
github-actions[bot] a790e8c3ee [CI Skip] bump/beta 8.13.2-5-x
skip-checks: true
2022-07-19 18:39:45 +00:00
Nikos Kontakis bb6e16eac7 Bump substrate connect to 0.7.9 (Add CommonJS Support) (#5088)
* Bump substrate connect to 0.7.9

* Remove comment about ESM-only at bundle
2022-07-19 21:31:52 +03:00
github-actions[bot] 23e191eaf7 [CI Skip] bump/beta 8.13.2-4-x
skip-checks: true
2022-07-19 05:53:58 +00:00
Jaco cec0325820 Bump dev deps (#5084) 2022-07-19 08:44:10 +03:00
github-actions[bot] ffd8d74e3a [CI Skip] bump/beta 8.13.2-3-x
skip-checks: true
2022-07-18 11:19:15 +00:00
Jaco 91a04ad159 Add Codec toPrimitive (#5080) 2022-07-18 14:10:46 +03:00
github-actions[bot] 434f969208 [CI Skip] bump/beta 8.13.2-2-x
skip-checks: true
2022-07-18 07:42:59 +00:00
Jaco 34a5cbed90 Adjust instance check to handle Call paths (#5082) 2022-07-18 10:35:14 +03:00
github-actions[bot] 72469ae6da [CI Skip] bump/beta 8.13.2-1-x
skip-checks: true
2022-07-18 06:22:21 +00:00
Jaco 14f2a9da39 Adjust lazyVariants with internal $type (#5081)
* Adjust lazyVariants with internal $type

* Adjust

* Allow for empty paths

* Allow any $ override

* Adjust

* Small usage fixes, dedupe
2022-07-18 09:12:14 +03:00
github-actions[bot] 12750bc83d [CI Skip] bump/beta 8.13.2-0-x
skip-checks: true
2022-07-16 11:24:15 +00:00
Jaco 9a2b67aa25 Adjust CodecMap toHuman key representation (Bytes, if isAscii) (#5079)
* Adjust CodecMap toHuman key representation (Bytes, if isAscii)

* Use Raw instead of Bytes

* old typo
2022-07-16 14:16:29 +03:00
84 changed files with 1346 additions and 1019 deletions
+18 -1
View File
@@ -1,5 +1,22 @@
# CHANGELOG
## 8.14.1 Jul 23, 2022
Contributed:
- Update `@substrate/connect` with dual ESM/CJS support (Thanks to https://github.com/wirednkod)
Changes:
- `{BTree|Hash}Map.toHuman()` now display `Raw` keys as ascii (if detected)
- Add `toPrimitive()` to all base `Codec` interfaces (string/boolean/number)
- Adjust metadata conversion with `objectSpread` (where missing)
- Support for `TransactionPaymentCallApi` runtime interface
- Check `registry.getModuleInstances` against metadata paths (fallback)
- Update to `@polkadot/util` 10.1.1
- Update to latest Kusama metadata (Substrate & Polkadot are current)
## 8.13.1 Jul 16, 2022
Changes:
@@ -332,7 +349,7 @@ Changes:
- Only explicitly support LSB on `BitVec` types
- Change `toHuman()` on `BitVec` to output default LSB
- Add `bytes{Sent, Recv}` to provider stats
- Clear connection timout on provider `disconnect()`
- Clear connection timeout on provider `disconnect()`
- Add support for `dev_getBlockStats` RPC
+2 -2
View File
@@ -1,4 +1,4 @@
3136 Jaco 8.13.1 (#5078)
3150 Jaco 8.14.1 (#5102)
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)
@@ -7,7 +7,7 @@
15 Jeremías Díaz feat(types): add correct tuple type to storage key (#3054)
11 Ian He HttpProvider support clone() (#3949)
10 Axel Chalon Make Enum/Tuple constructor use value directly if instance (#1954)
6 Nikos Kontakis Bump substrate connect to 0.7.8 (#5058)
7 Nikos Kontakis Bump substrate connect to 0.7.9 (Add CommonJS Support) (#5088)
5 Chevdor Fix metadata package link (#3458)
5 Jake Naviasky Fixing approvalFlagsToBools. (#1250)
4 Alex D Use derive customAccount and customLocks for balance overrides (#3248)
+7 -7
View File
@@ -11,10 +11,10 @@
},
"sideEffects": false,
"type": "module",
"version": "8.13.1",
"version": "8.14.1",
"versions": {
"git": "8.13.1",
"npm": "8.13.1"
"git": "8.14.1",
"npm": "8.14.1"
},
"workspaces": [
"packages/*"
@@ -34,10 +34,10 @@
"test:one": "NODE_OPTIONS=--experimental-vm-modules polkadot-dev-run-test --detectOpenHandles --forceExit"
},
"devDependencies": {
"@babel/core": "^7.18.6",
"@babel/register": "^7.18.6",
"@babel/runtime": "^7.18.6",
"@polkadot/dev": "^0.67.79",
"@babel/core": "^7.18.9",
"@babel/register": "^7.18.9",
"@babel/runtime": "^7.18.9",
"@polkadot/dev": "^0.67.84",
"@polkadot/typegen": "workspace:packages/typegen",
"@types/jest": "^28.1.6",
"copyfiles": "^2.4.1"
+9 -9
View File
@@ -20,18 +20,18 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "8.13.1",
"version": "8.14.1",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.18.6",
"@polkadot/api-base": "8.13.1",
"@polkadot/rpc-augment": "8.13.1",
"@polkadot/types": "8.13.1",
"@polkadot/types-augment": "8.13.1",
"@polkadot/types-codec": "8.13.1",
"@polkadot/util": "^10.0.2"
"@babel/runtime": "^7.18.9",
"@polkadot/api-base": "8.14.1",
"@polkadot/rpc-augment": "8.14.1",
"@polkadot/types": "8.14.1",
"@polkadot/types-augment": "8.14.1",
"@polkadot/types-codec": "8.14.1",
"@polkadot/util": "^10.1.1"
},
"devDependencies": {
"@polkadot/types-support": "8.13.1"
"@polkadot/types-support": "8.14.1"
}
}
+4 -9
View File
@@ -945,6 +945,10 @@ declare module '@polkadot/api-base/types/errors' {
MetadataExceedsMaxLen: AugmentedError<ApiType>;
/**
* The amount does not meet the minimum bond to either join or create a pool.
*
* The depositor can never unbond to a value less than
* `Pallet::depositor_min_bond`. The caller does not have nominating
* permissions for the pool. Members can never unbond to a value below `MinJoinBond`.
**/
MinimumBondNotMet: AugmentedError<ApiType>;
/**
@@ -952,10 +956,6 @@ declare module '@polkadot/api-base/types/errors' {
* other members to be permissionlessly unbonded.
**/
NotDestroying: AugmentedError<ApiType>;
/**
* Not enough points. Ty unbonding less.
**/
NotEnoughPointsToUnbond: AugmentedError<ApiType>;
/**
* Either a) the caller cannot make a valid kick or b) the pool is not destroying.
**/
@@ -964,11 +964,6 @@ declare module '@polkadot/api-base/types/errors' {
* The caller does not have nominating permissions for the pool.
**/
NotNominator: AugmentedError<ApiType>;
/**
* The depositor must be the only member in the bonded pool in order to unbond. And the
* depositor must be the only member in the sub pools in order to withdraw unbonded.
**/
NotOnlyPoolMember: AugmentedError<ApiType>;
/**
* The pool is not open to join
**/
+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: '8.13.1' };
export const packageInfo = { name: '@polkadot/api-augment', path: 'auto', type: 'auto', version: '8.14.1' };
+5 -5
View File
@@ -20,13 +20,13 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "8.13.1",
"version": "8.14.1",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.18.6",
"@polkadot/rpc-core": "8.13.1",
"@polkadot/types": "8.13.1",
"@polkadot/util": "^10.0.2",
"@babel/runtime": "^7.18.9",
"@polkadot/rpc-core": "8.14.1",
"@polkadot/types": "8.14.1",
"@polkadot/util": "^10.1.1",
"rxjs": "^7.5.6"
}
}
+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: '8.13.1' };
export const packageInfo = { name: '@polkadot/api-base', path: 'auto', type: 'auto', version: '8.14.1' };
+10 -10
View File
@@ -20,20 +20,20 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "8.13.1",
"version": "8.14.1",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.18.6",
"@polkadot/api": "8.13.1",
"@polkadot/types": "8.13.1",
"@polkadot/types-codec": "8.13.1",
"@polkadot/types-create": "8.13.1",
"@polkadot/util": "^10.0.2",
"@polkadot/util-crypto": "^10.0.2",
"@babel/runtime": "^7.18.9",
"@polkadot/api": "8.14.1",
"@polkadot/types": "8.14.1",
"@polkadot/types-codec": "8.14.1",
"@polkadot/types-create": "8.14.1",
"@polkadot/util": "^10.1.1",
"@polkadot/util-crypto": "^10.1.1",
"rxjs": "^7.5.6"
},
"devDependencies": {
"@polkadot/api-augment": "8.13.1",
"@polkadot/keyring": "^10.0.2"
"@polkadot/api-augment": "8.14.1",
"@polkadot/keyring": "^10.1.1"
}
}
+5 -5
View File
@@ -8,7 +8,11 @@ import { v0ToV1 } from './toV1';
import { v1ToV2 } from './toV2';
import { v2ToV3 } from './toV3';
type Versions = 'V3' | 'V2' | 'V1' | 'V0';
// The versions where an enum is used, aka V0 is missing
// (Order from newest, i.e. we expect more on newest vs oldest)
export const enumVersions = <const> ['V3', 'V2', 'V1'];
type Versions = typeof enumVersions[number] | 'V0';
type Converter = (registry: Registry, vx: any) => ContractMetadataLatest;
@@ -26,10 +30,6 @@ export const v2ToLatest = createConverter(v3ToLatest, v2ToV3);
export const v1ToLatest = createConverter(v2ToLatest, v1ToV2);
export const v0ToLatest = createConverter(v1ToLatest, v0ToV1);
// The versions where an enum is used, aka V0 is missing
// (Order from newest, i.e. we expect more on newest vs oldest)
export const enumVersions = ['V3', 'V2', 'V1'];
export const convertVersions: [Versions, Converter][] = [
['V3', v3ToLatest],
['V2', v2ToLatest],
+1 -1
View File
@@ -23,7 +23,7 @@ interface ArgsEntry <T extends WithArgs> extends NamedEntry {
args: GetArgsType<T>['args'][0][];
}
const ARG_TYPES = {
const ARG_TYPES = <const> {
ContractConstructorSpec: 'ContractMessageParamSpecV2',
ContractEventSpec: 'ContractEventParamSpecV2',
ContractMessageSpec: 'ContractMessageParamSpecV2'
+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: '8.13.1' };
export const packageInfo = { name: '@polkadot/api-contract', path: 'auto', type: 'auto', version: '8.14.1' };
+15 -15
View File
@@ -20,25 +20,25 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "8.13.1",
"version": "8.14.1",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.18.6",
"@polkadot/api": "8.13.1",
"@polkadot/api-augment": "8.13.1",
"@polkadot/api-base": "8.13.1",
"@polkadot/rpc-core": "8.13.1",
"@polkadot/types": "8.13.1",
"@polkadot/types-codec": "8.13.1",
"@polkadot/util": "^10.0.2",
"@polkadot/util-crypto": "^10.0.2",
"@babel/runtime": "^7.18.9",
"@polkadot/api": "8.14.1",
"@polkadot/api-augment": "8.14.1",
"@polkadot/api-base": "8.14.1",
"@polkadot/rpc-core": "8.14.1",
"@polkadot/types": "8.14.1",
"@polkadot/types-codec": "8.14.1",
"@polkadot/util": "^10.1.1",
"@polkadot/util-crypto": "^10.1.1",
"rxjs": "^7.5.6"
},
"devDependencies": {
"@polkadot/api": "8.13.1",
"@polkadot/api-augment": "8.13.1",
"@polkadot/rpc-augment": "8.13.1",
"@polkadot/rpc-provider": "8.13.1",
"@polkadot/types-support": "8.13.1"
"@polkadot/api": "8.14.1",
"@polkadot/api-augment": "8.14.1",
"@polkadot/rpc-augment": "8.14.1",
"@polkadot/rpc-provider": "8.14.1",
"@polkadot/types-support": "8.14.1"
}
}
+3 -2
View File
@@ -150,7 +150,8 @@ function querySystemAccount (api: DeriveApi, accountId: AccountId): Observable<R
* ```
*/
export function account (instanceId: string, api: DeriveApi): (address: AccountIndex | AccountId | Address | string) => Observable<DeriveBalancesAccount> {
const balanceInstances = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), 'balances');
const balanceInstances = api.registry.getModuleInstances(api.runtimeVersion.specName, 'balances');
const nonDefaultBalances = balanceInstances && (balanceInstances.length !== 1 || balanceInstances[0] !== 'balances');
return memo(instanceId, (address: AccountIndex | AccountId | Address | string): Observable<DeriveBalancesAccount> =>
api.derive.accounts.accountId(address).pipe(
@@ -158,7 +159,7 @@ export function account (instanceId: string, api: DeriveApi): (address: AccountI
(accountId
? combineLatest([
of(accountId),
balanceInstances
nonDefaultBalances
? queryBalancesAccount(api, accountId, balanceInstances)
: isFunction(api.query.system?.account)
? querySystemAccount(api, accountId)
+1 -1
View File
@@ -211,7 +211,7 @@ function queryCurrent (api: DeriveApi, accountId: AccountId | string, balanceIns
* ```
*/
export function all (instanceId: string, api: DeriveApi): (address: AccountId | string) => Observable<DeriveBalancesAll> {
const balanceInstances = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), 'balances');
const balanceInstances = api.registry.getModuleInstances(api.runtimeVersion.specName, 'balances');
return memo(instanceId, (address: AccountId | string): Observable<DeriveBalancesAll> =>
combineLatest([
+3 -3
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import type { DeriveCustom } from '@polkadot/api-base/types';
import type { AnyFunction } from '@polkadot/types/types';
import type { AnyFunction, AnyString } from '@polkadot/types/types';
import type { ExactDerive } from './derive';
import type { DeriveApi } from './types';
@@ -84,7 +84,7 @@ const checks: Record<string, Avail> = {
}
};
function getModuleInstances (api: DeriveApi, specName: string, moduleName: string): string[] {
function getModuleInstances (api: DeriveApi, specName: AnyString, moduleName: string): string[] {
return api.registry.getModuleInstances(specName, moduleName) || [];
}
@@ -97,7 +97,7 @@ function injectFunctions (instanceId: string, api: DeriveApi, derives: DeriveCus
const result: Record<string, Record<string, AnyFunction>> = {};
const names = Object.keys(derives);
const keys = Object.keys(api.query);
const specName = api.runtimeVersion.specName.toString();
const specName = api.runtimeVersion.specName;
const filterKeys = (q: string) => keys.includes(q);
const filterInstances = (q: string) => getModuleInstances(api, specName, q).some(filterKeys);
@@ -12,7 +12,7 @@ import { isFunction } from '@polkadot/util';
import { memo } from '../util';
export function getInstance (api: DeriveApi, section: string): DeriveApi['query']['council'] {
const instances = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), section);
const instances = api.registry.getModuleInstances(api.runtimeVersion.specName, section);
const name = instances && instances.length
? instances[0]
: section;
+1 -1
View File
@@ -55,7 +55,7 @@ function getConstants (api: DeriveApi, elections: string | null): Partial<Derive
}
function getModules (api: DeriveApi): [string, string | null] {
const [council] = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), 'council') || ['council'];
const [council] = api.registry.getModuleInstances(api.runtimeVersion.specName, 'council') || ['council'];
const elections = api.query.phragmenElection
? 'phragmenElection'
: api.query.electionsPhragmen
+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: '8.13.1' };
export const packageInfo = { name: '@polkadot/api-derive', path: 'auto', type: 'auto', version: '8.14.1' };
+18 -18
View File
@@ -20,29 +20,29 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "8.13.1",
"version": "8.14.1",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.18.6",
"@polkadot/api-augment": "8.13.1",
"@polkadot/api-base": "8.13.1",
"@polkadot/api-derive": "8.13.1",
"@polkadot/keyring": "^10.0.2",
"@polkadot/rpc-augment": "8.13.1",
"@polkadot/rpc-core": "8.13.1",
"@polkadot/rpc-provider": "8.13.1",
"@polkadot/types": "8.13.1",
"@polkadot/types-augment": "8.13.1",
"@polkadot/types-codec": "8.13.1",
"@polkadot/types-create": "8.13.1",
"@polkadot/types-known": "8.13.1",
"@polkadot/util": "^10.0.2",
"@polkadot/util-crypto": "^10.0.2",
"@babel/runtime": "^7.18.9",
"@polkadot/api-augment": "8.14.1",
"@polkadot/api-base": "8.14.1",
"@polkadot/api-derive": "8.14.1",
"@polkadot/keyring": "^10.1.1",
"@polkadot/rpc-augment": "8.14.1",
"@polkadot/rpc-core": "8.14.1",
"@polkadot/rpc-provider": "8.14.1",
"@polkadot/types": "8.14.1",
"@polkadot/types-augment": "8.14.1",
"@polkadot/types-codec": "8.14.1",
"@polkadot/types-create": "8.14.1",
"@polkadot/types-known": "8.14.1",
"@polkadot/util": "^10.1.1",
"@polkadot/util-crypto": "^10.1.1",
"eventemitter3": "^4.0.7",
"rxjs": "^7.5.6"
},
"devDependencies": {
"@polkadot/api-augment": "8.13.1",
"@polkadot/types-support": "8.13.1"
"@polkadot/api-augment": "8.14.1",
"@polkadot/types-support": "8.14.1"
}
}
+3 -1
View File
@@ -626,7 +626,9 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
const lazySection = (section: string) =>
lazyMethods({}, Object.keys(tx[section]), (method: string) =>
this._decorateExtrinsicEntry(tx[section][method], result)
method.startsWith('$')
? tx[section][method]
: this._decorateExtrinsicEntry(tx[section][method], result)
);
const sections = Object.keys(tx);
+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: '8.13.1' };
export const packageInfo = { name: '@polkadot/api', path: 'auto', type: 'auto', version: '8.14.1' };
+6 -6
View File
@@ -20,13 +20,13 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "8.13.1",
"version": "8.14.1",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.18.6",
"@polkadot/rpc-core": "8.13.1",
"@polkadot/types": "8.13.1",
"@polkadot/types-codec": "8.13.1",
"@polkadot/util": "^10.0.2"
"@babel/runtime": "^7.18.9",
"@polkadot/rpc-core": "8.14.1",
"@polkadot/types": "8.14.1",
"@polkadot/types-codec": "8.14.1",
"@polkadot/util": "^10.1.1"
}
}
+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: '8.13.1' };
export const packageInfo = { name: '@polkadot/rpc-augment', path: 'auto', type: 'auto', version: '8.14.1' };
+8 -8
View File
@@ -20,18 +20,18 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "8.13.1",
"version": "8.14.1",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.18.6",
"@polkadot/rpc-augment": "8.13.1",
"@polkadot/rpc-provider": "8.13.1",
"@polkadot/types": "8.13.1",
"@polkadot/util": "^10.0.2",
"@babel/runtime": "^7.18.9",
"@polkadot/rpc-augment": "8.14.1",
"@polkadot/rpc-provider": "8.14.1",
"@polkadot/types": "8.14.1",
"@polkadot/util": "^10.1.1",
"rxjs": "^7.5.6"
},
"devDependencies": {
"@polkadot/keyring": "^10.0.2",
"@polkadot/rpc-augment": "8.13.1"
"@polkadot/keyring": "^10.1.1",
"@polkadot/rpc-augment": "8.14.1"
}
}
+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: '8.13.1' };
export const packageInfo = { name: '@polkadot/rpc-core', path: 'auto', type: 'auto', version: '8.14.1' };
+12 -12
View File
@@ -20,21 +20,21 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "8.13.1",
"version": "8.14.1",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.18.6",
"@polkadot/keyring": "^10.0.2",
"@polkadot/types": "8.13.1",
"@polkadot/types-support": "8.13.1",
"@polkadot/util": "^10.0.2",
"@polkadot/util-crypto": "^10.0.2",
"@polkadot/x-fetch": "^10.0.2",
"@polkadot/x-global": "^10.0.2",
"@polkadot/x-ws": "^10.0.2",
"@substrate/connect": "0.7.8",
"@babel/runtime": "^7.18.9",
"@polkadot/keyring": "^10.1.1",
"@polkadot/types": "8.14.1",
"@polkadot/types-support": "8.14.1",
"@polkadot/util": "^10.1.1",
"@polkadot/util-crypto": "^10.1.1",
"@polkadot/x-fetch": "^10.1.1",
"@polkadot/x-global": "^10.1.1",
"@polkadot/x-ws": "^10.1.1",
"@substrate/connect": "0.7.9",
"eventemitter3": "^4.0.7",
"mock-socket": "^9.1.5",
"nock": "^13.2.8"
"nock": "^13.2.9"
}
}
+1 -3
View File
@@ -4,6 +4,4 @@
export { HttpProvider } from './http';
export { packageInfo } from './packageInfo';
export { WsProvider } from './ws';
// ESM-only, only export top-level when we have dual versions
// export { ScProvider } from './substrate-connect';
export { ScProvider } from './substrate-connect';
+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: '8.13.1' };
export const packageInfo = { name: '@polkadot/rpc-provider', path: 'auto', type: 'auto', version: '8.14.1' };
+16 -16
View File
@@ -20,7 +20,7 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "8.13.1",
"version": "8.14.1",
"main": "index.js",
"bin": {
"polkadot-types-chain-info": "./scripts/polkadot-types-chain-info.cjs",
@@ -30,21 +30,21 @@
"polkadot-types-internal-metadata": "./scripts/polkadot-types-internal-metadata.cjs"
},
"dependencies": {
"@babel/core": "^7.18.6",
"@babel/register": "^7.18.6",
"@babel/runtime": "^7.18.6",
"@polkadot/api": "8.13.1",
"@polkadot/api-augment": "8.13.1",
"@polkadot/rpc-augment": "8.13.1",
"@polkadot/rpc-provider": "8.13.1",
"@polkadot/types": "8.13.1",
"@polkadot/types-augment": "8.13.1",
"@polkadot/types-codec": "8.13.1",
"@polkadot/types-create": "8.13.1",
"@polkadot/types-support": "8.13.1",
"@polkadot/util": "^10.0.2",
"@polkadot/util-crypto": "^10.0.2",
"@polkadot/x-ws": "^10.0.2",
"@babel/core": "^7.18.9",
"@babel/register": "^7.18.9",
"@babel/runtime": "^7.18.9",
"@polkadot/api": "8.14.1",
"@polkadot/api-augment": "8.14.1",
"@polkadot/rpc-augment": "8.14.1",
"@polkadot/rpc-provider": "8.14.1",
"@polkadot/types": "8.14.1",
"@polkadot/types-augment": "8.14.1",
"@polkadot/types-codec": "8.14.1",
"@polkadot/types-create": "8.14.1",
"@polkadot/types-support": "8.14.1",
"@polkadot/util": "^10.1.1",
"@polkadot/util-crypto": "^10.1.1",
"@polkadot/x-ws": "^10.1.1",
"handlebars": "^4.7.7",
"websocket": "^1.0.34",
"yargs": "^17.5.1"
+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: '8.13.1' };
export const packageInfo = { name: '@polkadot/typegen', path: 'auto', type: 'auto', version: '8.14.1' };
+5 -5
View File
@@ -20,12 +20,12 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "8.13.1",
"version": "8.14.1",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.18.6",
"@polkadot/types": "8.13.1",
"@polkadot/types-codec": "8.13.1",
"@polkadot/util": "^10.0.2"
"@babel/runtime": "^7.18.9",
"@polkadot/types": "8.14.1",
"@polkadot/types-codec": "8.14.1",
"@polkadot/util": "^10.1.1"
}
}
+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: '8.13.1' };
export const packageInfo = { name: '@polkadot/types-augment', path: 'auto', type: 'auto', version: '8.14.1' };
+8 -8
View File
@@ -20,17 +20,17 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "8.13.1",
"version": "8.14.1",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.18.6",
"@polkadot/util": "^10.0.2",
"@polkadot/x-bigint": "^10.0.2"
"@babel/runtime": "^7.18.9",
"@polkadot/util": "^10.1.1",
"@polkadot/x-bigint": "^10.1.1"
},
"devDependencies": {
"@polkadot/types": "8.13.1",
"@polkadot/types-augment": "8.13.1",
"@polkadot/types-support": "8.13.1",
"@polkadot/util-crypto": "^10.0.2"
"@polkadot/types": "8.14.1",
"@polkadot/types-augment": "8.14.1",
"@polkadot/types-support": "8.14.1",
"@polkadot/util-crypto": "^10.1.1"
}
}
@@ -140,6 +140,19 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
return result;
}
/**
* @description Converts the value in a best-fit primitive form
*/
public toPrimitive (): AnyJson {
const result = new Array<AnyJson>(this.length);
for (let i = 0; i < this.length; i++) {
result[i] = this[i] && this[i].toPrimitive();
}
return result;
}
/**
* @description Returns the base runtime type name for this instance
*/
@@ -83,6 +83,13 @@ export abstract class AbstractBase<T extends Codec> implements Codec {
return this.#raw.toJSON();
}
/**
* @description Converts the value in a best-fit primitive form
*/
public toPrimitive (): AnyJson {
return this.#raw.toPrimitive();
}
/**
* @description Returns the string representation of the value
*/
+9
View File
@@ -207,6 +207,15 @@ export abstract class AbstractInt extends BN implements INumber {
: this.toNumber();
}
/**
* @description Returns the value in a primitive form, either number when <= 52 bits, or string otherwise
*/
public toPrimitive (): number | string {
return super.bitLength() > MAX_NUMBER_BITS
? this.toString()
: this.toNumber();
}
/**
* @description Returns the base runtime type name for this instance
*/
+7
View File
@@ -171,6 +171,13 @@ export class Compact<T extends INumber> implements ICompact<T> {
return this.#raw.toNumber();
}
/**
* @description Converts the value in a best-fit primitive form
*/
public toPrimitive (): string | number {
return this.#raw.toPrimitive();
}
/**
* @description Returns the base runtime type name for this instance
*/
@@ -72,6 +72,10 @@ export class DoNotConstruct implements Codec {
throw this.#neverError;
}
toPrimitive (): AnyJson {
throw this.#neverError;
}
toRawType (): string {
throw this.#neverError;
}
+9
View File
@@ -414,6 +414,15 @@ export class Enum implements IEnum {
return this.index;
}
/**
* @description Converts the value in a best-fit primitive form
*/
public toPrimitive (): AnyJson {
return this.#isBasic
? this.type
: { [stringCamelCase(this.type)]: this.#raw.toPrimitive() };
}
/**
* @description Returns a raw struct representation of the enum types
*/
+7
View File
@@ -69,6 +69,13 @@ export class Null implements Codec {
return null;
}
/**
* @description Converts the value in a best-fit primitive form
*/
public toPrimitive (): null {
return null;
}
/**
* @description Returns the base runtime type name for this instance
*/
+9
View File
@@ -206,6 +206,15 @@ export class Option<T extends Codec> implements IOption<T> {
: this.#raw.toJSON();
}
/**
* @description Converts the value in a best-fit primitive form
*/
public toPrimitive (): AnyJson {
return this.isNone
? null
: this.#raw.toPrimitive();
}
/**
* @description Returns the base runtime type name for this instance
*/
@@ -193,6 +193,19 @@ export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V>
return `BTreeSet<${this.registry.getClassName(this.#ValClass) || new this.#ValClass(this.registry).toRawType()}>`;
}
/**
* @description Converts the value in a best-fit primitive form
*/
public toPrimitive (): AnyJson {
const json: AnyJson = [];
for (const v of this.values()) {
json.push(v.toPrimitive());
}
return json;
}
/**
* @description Returns the string representation of the value
*/
+23 -1
View File
@@ -8,6 +8,7 @@ import { compactFromU8aLim, compactToU8a, isHex, isObject, isU8a, logger, string
import { AbstractArray } from '../abstract/Array';
import { Enum } from '../base/Enum';
import { Raw } from '../native/Raw';
import { Struct } from '../native/Struct';
import { compareMap, decodeU8a, sortMap, typeToConstructor } from '../utils';
@@ -182,7 +183,11 @@ export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends
const json: Record<string, AnyJson> = {};
for (const [k, v] of this.entries()) {
json[k.toString()] = v.toHuman(isExtended);
json[
k instanceof Raw && k.isAscii
? k.toUtf8()
: k.toString()
] = v.toHuman(isExtended);
}
return json;
@@ -201,6 +206,23 @@ export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends
return json;
}
/**
* @description Converts the value in a best-fit primitive form
*/
public toPrimitive (): AnyJson {
const json: Record<string, AnyJson> = {};
for (const [k, v] of this.entries()) {
json[
k instanceof Raw && k.isAscii
? k.toUtf8()
: k.toString()
] = v.toPrimitive();
}
return json;
}
/**
* @description Returns the base runtime type name for this instance
*/
@@ -92,6 +92,15 @@ export class WrapperKeepOpaque<T extends Codec> extends Bytes {
: super.toHuman();
}
/**
* @description Converts the value in a best-fit primitive form
*/
public override toPrimitive (): any {
return this.#decoded
? this.#decoded.toPrimitive()
: super.toPrimitive();
}
/**
* @description Returns the base runtime type name for this instance
*/
+7
View File
@@ -105,6 +105,13 @@ export class bool extends Boolean implements Codec {
return this.valueOf();
}
/**
* @description Converts the value in a best-fit primitive form
*/
public toPrimitive (): boolean {
return this.toJSON();
}
/**
* @description Returns the base runtime type name for this instance
*/
+7
View File
@@ -136,6 +136,13 @@ export class CodecDate extends Date implements INumber {
return Math.ceil(this.getTime() / 1000);
}
/**
* @description Converts the value in a best-fit primitive form
*/
public toPrimitive (): number {
return this.toNumber();
}
/**
* @description Returns the base runtime type name for this instance
*/
+7
View File
@@ -112,6 +112,13 @@ export class Float extends Number implements IFloat {
return this.valueOf();
}
/**
* @description Converts the value in a best-fit primitive form
*/
public toPrimitive (): number {
return this.toNumber();
}
/**
* @description Returns the base runtime type name for this instance
*/
+13
View File
@@ -109,6 +109,19 @@ export class Json extends Map<string, any> implements Codec {
}, {});
}
/**
* @description Converts the value in a best-fit primitive form
*/
public toPrimitive (): Record<string, AnyJson> {
return [...this.entries()].reduce<Record<string, AnyJson>>((json, [key, value]): Record<string, AnyJson> => {
json[key] = isFunction((value as Codec).toHuman)
? (value as Codec).toPrimitive()
: value as AnyJson;
return json;
}, {});
}
/**
* @description Returns the base runtime type name for this instance
*/
@@ -36,6 +36,7 @@ describe('Raw', (): void => {
testEncode('toJSON', '0x0102030405');
testEncode('toHex', '0x0102030405');
testEncode('toPrimitive', '0x0102030405');
testEncode('toString', '0x0102030405');
testEncode('toU8a', Uint8Array.from([1, 2, 3, 4, 5]));
@@ -79,6 +80,11 @@ describe('Raw', (): void => {
expect(new Raw(registry, '0x2021222324').isAscii).toBe(true);
});
it('has valid toPrimitive', (): void => {
expect(new Raw(registry, 'testing').toPrimitive()).toEqual('testing');
expect(new Raw(registry, '0xe4bda0e5a5bd').toPrimitive()).toEqual('0xe4bda0e5a5bd');
});
it('has valid toUtf8', (): void => {
expect(new Raw(registry, 'Приветствую, ми').toUtf8()).toEqual('Приветствую, ми');
expect(new Raw(registry, '0xe4bda0e5a5bd').toUtf8()).toEqual('你好');
+14 -7
View File
@@ -111,6 +111,20 @@ export class Raw extends Uint8Array implements IU8a {
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
*/
public toHuman (): AnyJson {
return this.toPrimitive();
}
/**
* @description Converts the Object to JSON, typically used for RPC transfers
*/
public toJSON (): string {
return this.toHex();
}
/**
* @description Converts the value in a best-fit primitive form
*/
public toPrimitive (): AnyJson {
if (this.isAscii) {
const text = this.toUtf8();
@@ -123,13 +137,6 @@ export class Raw extends Uint8Array implements IU8a {
return this.toJSON();
}
/**
* @description Converts the Object to JSON, typically used for RPC transfers
*/
public toJSON (): string {
return this.toHex();
}
/**
* @description Returns the base runtime type name for this instance
*/
+7
View File
@@ -229,6 +229,13 @@ export class CodecSet extends Set<string> implements ISet<string> {
return this.valueEncoded.toNumber();
}
/**
* @description Converts the value in a best-fit primitive form
*/
public toPrimitive (): string[] {
return this.toJSON();
}
/**
* @description Returns the base runtime type name for this instance
*/
+187 -146
View File
@@ -33,6 +33,116 @@ describe('Struct', (): void => {
testDecode('hex', '0x1c62617a7a696e6745000000');
testDecode('object', { foo: 'bazzing', bar: 69 });
testDecode('Uint8Array', Uint8Array.from([28, 98, 97, 122, 122, 105, 110, 103, 69, 0, 0, 0]));
it('decodes null/undefined/empty correctly (& equivalent)', (): void => {
const Clazz = Struct.with({
txt: Text,
u32: U32
});
const expected = { txt: '', u32: '0' };
expect(new Clazz(registry, {}).toHuman()).toEqual(expected);
expect(new Clazz(registry, null).toHuman()).toEqual(expected);
expect(new Clazz(registry, undefined).toHuman()).toEqual(expected);
});
it('decodes with Optionals', (): void => {
const Clazz = Struct.with({
a: 'Option<Bool>',
b: 'Option<Bool>'
});
const c = new Clazz(registry, { a: false }) as unknown as { a: Option<Bool>, b: Option<Bool> };
expect(c.a.isSome).toEqual(true);
expect(c.a.unwrap().isTrue).toEqual(false);
expect(c.b.isSome).toEqual(false);
});
it('decodes reusing instantiated inputs', (): void => {
const foo = new Text(registry, 'bar');
expect(
(new Struct(
registry,
{ foo: Text },
{ foo }
)).get('foo')
).toBe(foo);
});
it('decodes a more complicated type', (): void => {
const s = new Struct(registry, {
foo: Vec.with(Struct.with({
bar: Text
}))
}, { foo: [{ bar: 1 }, { bar: 2 }] });
expect(s.toString()).toBe('{"foo":[{"bar":"1"},{"bar":"2"}]}');
});
it('decodes a previously problematic input', (): void => {
let data;
try {
data = new Struct(registry, {
a: 'u32',
b: 'H256',
c: 'H256',
swap: Enum.with({
A: 'u256',
B: 'u256'
}),
d: Vec.with('u8'),
e: 'u8'
}, TEST_A);
} catch (error) {
console.error(error);
throw error;
}
expect(data.get('d')).toHaveLength(50000);
});
it('decodes from a Map input', (): void => {
const s = new Struct(registry, {
txt: Text,
foo: U32,
bar: U32
}, new Map<string, unknown>([['a', 42], ['txt', 'fubar']]));
expect(s.toString()).toEqual('{"txt":"fubar","foo":0,"bar":0}');
});
it('decodes from a snake_case input', (): void => {
const input = new Struct(registry, {
snakeCaseA: U32,
snakeCaseB: Text,
other: U32
}, { snake_case_a: 42, snake_case_b: 'fubar', other: 69 } as any);
expect(input.toString()).toEqual('{"snakeCaseA":42,"snakeCaseB":"fubar","other":69}');
});
it('throws when it cannot decode', (): void => {
expect(
(): Struct<any> => new (
Struct.with({
txt: Text,
u32: U32
})
)(registry, 'ABC')
).toThrowError(/Cannot decode value/);
});
it('throws a sensical error on incorrect array values passed to structs', (): void => {
expect(
() => new Struct(registry, {
_: 'Vec<u32>'
}, [123, 456])
).toThrow(/array to object with known keys/);
});
});
describe('encoding', (): void => {
@@ -52,116 +162,6 @@ describe('Struct', (): void => {
testEncode('toString', '{"foo":"bazzing","bar":69}');
});
it('decodes null/undefined/empty correctly (& equivalently)', (): void => {
const Clazz = Struct.with({
txt: Text,
u32: U32
});
const expected = { txt: '', u32: '0' };
expect(new Clazz(registry, {}).toHuman()).toEqual(expected);
expect(new Clazz(registry, null).toHuman()).toEqual(expected);
expect(new Clazz(registry, undefined).toHuman()).toEqual(expected);
});
it('decodes with Optionals', (): void => {
const Clazz = Struct.with({
a: 'Option<Bool>',
b: 'Option<Bool>'
});
const c = new Clazz(registry, { a: false }) as unknown as { a: Option<Bool>, b: Option<Bool> };
expect(c.a.isSome).toEqual(true);
expect(c.a.unwrap().isTrue).toEqual(false);
expect(c.b.isSome).toEqual(false);
});
it('decodes reusing instantiated inputs', (): void => {
const foo = new Text(registry, 'bar');
expect(
(new Struct(
registry,
{ foo: Text },
{ foo }
)).get('foo')
).toBe(foo);
});
it('decodes a more complicated type', (): void => {
const s = new Struct(registry, {
foo: Vec.with(Struct.with({
bar: Text
}))
}, { foo: [{ bar: 1 }, { bar: 2 }] });
expect(s.toString()).toBe('{"foo":[{"bar":"1"},{"bar":"2"}]}');
});
it('decodes a previously problematic input', (): void => {
let data;
try {
data = new Struct(registry, {
a: 'u32',
b: 'H256',
c: 'H256',
swap: Enum.with({
A: 'u256',
B: 'u256'
}),
d: Vec.with('u8'),
e: 'u8'
}, TEST_A);
} catch (error) {
console.error(error);
throw error;
}
expect(data.get('d')).toHaveLength(50000);
});
it('decodes from a Map input', (): void => {
const s = new Struct(registry, {
txt: Text,
foo: U32,
bar: U32
}, new Map<string, unknown>([['a', 42], ['txt', 'fubar']]));
expect(s.toString()).toEqual('{"txt":"fubar","foo":0,"bar":0}');
});
it('decodes from a snake_case input', (): void => {
const input = new Struct(registry, {
snakeCaseA: U32,
snakeCaseB: Text,
other: U32
}, { snake_case_a: 42, snake_case_b: 'fubar', other: 69 } as any);
expect(input.toString()).toEqual('{"snakeCaseA":42,"snakeCaseB":"fubar","other":69}');
});
it('throws when it cannot decode', (): void => {
expect(
(): Struct<any> => new (
Struct.with({
txt: Text,
u32: U32
})
)(registry, 'ABC')
).toThrowError(/Cannot decode value/);
});
it('throws a sensical error on incorrect array values passed to structs', (): void => {
expect(
() => new Struct(registry, {
_: 'Vec<u32>'
}, [123, 456])
).toThrow(/array to object with known keys/);
});
it('provides a clean toString()', (): void => {
expect(
new (
@@ -257,6 +257,83 @@ describe('Struct', (): void => {
}, test).eq(test)
).toBe(true);
});
it('has a sane toPrimitive', (): void => {
const S = Struct.with({
name: 'Text',
description: 'Vec<Text>',
fooA: 'Bytes',
fooB: 'Bytes',
fooC: Struct.with({
a: 'u32',
b: 'u128',
c: 'Compact<u128>',
d: 'bool'
})
});
expect(
new S(registry, {
name: 'Something',
description: ['One line', 'Another line'],
fooA: 'hello world!',
fooB: '0x123456',
fooC: {
a: 1234,
b: BigInt('1234567890111213141516'),
c: 123456,
d: true
}
}).toPrimitive()
).toEqual({
name: 'Something',
description: ['One line', 'Another line'],
fooA: 'hello world!',
fooB: '0x123456',
fooC: {
a: 1234,
b: '1234567890111213141516',
c: 123456,
d: true
}
});
});
it('generates sane toRawType', (): void => {
expect(
new Struct(registry, {
accountId: 'AccountId',
balanceCompact: registry.createClass('Compact<Balance>'),
blockNumber: registry.createClass('BlockNumber'),
compactNumber: registry.createClass('Compact<BlockNumber>'),
optionNumber: registry.createClass('Option<BlockNumber>'),
counter: U32,
vector: Vec.with('AccountId')
}).toRawType()
).toEqual(JSON.stringify({
accountId: 'AccountId',
balanceCompact: 'Compact<Balance>', // Override in Uint
blockNumber: 'BlockNumber',
compactNumber: 'Compact<BlockNumber>',
optionNumber: 'Option<BlockNumber>',
counter: 'u32',
vector: 'Vec<AccountId>'
}));
});
it('generates sane toRawType (via with)', (): void => {
const Type = Struct.with({
accountId: 'AccountId',
balance: registry.createClass('Balance')
});
expect(
new Type(registry).toRawType()
).toEqual(JSON.stringify({
accountId: 'AccountId',
balance: 'Balance' // Override in Uint
}));
});
});
it('allows toString with large numbers', (): void => {
@@ -268,42 +345,6 @@ describe('Struct', (): void => {
).toEqual('{"blockNumber":279694831}');
});
it('generates sane toRawType', (): void => {
expect(
new Struct(registry, {
accountId: 'AccountId',
balanceCompact: registry.createClass('Compact<Balance>'),
blockNumber: registry.createClass('BlockNumber'),
compactNumber: registry.createClass('Compact<BlockNumber>'),
optionNumber: registry.createClass('Option<BlockNumber>'),
counter: U32,
vector: Vec.with('AccountId')
}).toRawType()
).toEqual(JSON.stringify({
accountId: 'AccountId',
balanceCompact: 'Compact<Balance>', // Override in Uint
blockNumber: 'BlockNumber',
compactNumber: 'Compact<BlockNumber>',
optionNumber: 'Option<BlockNumber>',
counter: 'u32',
vector: 'Vec<AccountId>'
}));
});
it('generates sane toRawType (via with)', (): void => {
const Type = Struct.with({
accountId: 'AccountId',
balance: registry.createClass('Balance')
});
expect(
new Type(registry).toRawType()
).toEqual(JSON.stringify({
accountId: 'AccountId',
balance: 'Balance' // Override in Uint
}));
});
describe('toU8a', (): void => {
const def: Record<string, any> = {
foo: 'Bytes',
+17
View File
@@ -293,6 +293,23 @@ export class Struct<
return json;
}
/**
* @description Converts the value in a best-fit primitive form
*/
public toPrimitive (): Record<string, AnyJson> {
const json: Record<string, AnyJson> = {};
for (const [k, v] of this.entries()) {
const jsonKey = this.#jsonMap.get(k) || k;
// 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)
json[jsonKey as string] = v && v.toPrimitive();
}
return json;
}
/**
* @description Returns the base runtime type name for this instance
*/
+7
View File
@@ -147,6 +147,13 @@ export class Text extends String implements IText {
return this.toString();
}
/**
* @description Converts the value in a best-fit primitive form
*/
public toPrimitive (): string {
return this.toJSON();
}
/**
* @description Returns the base runtime type name for this instance
*/
+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: '8.13.1' };
export const packageInfo = { name: '@polkadot/types-codec', path: 'auto', type: 'auto', version: '8.14.1' };
+6 -1
View File
@@ -77,6 +77,11 @@ export interface Codec {
*/
toJSON (): AnyJson;
/**
* @description Converts the value in a best-fit primitive form
*/
toPrimitive (): AnyJson;
/**
* @description Returns the base runtime type name for this instance
*/
@@ -105,6 +110,6 @@ export interface CodecClass<T = Codec> {
new(registry: Registry, ...args: any[]): T;
}
export type CodecTo = 'toHex' | 'toJSON' | 'toString' | 'toU8a';
export type CodecTo = 'toHex' | 'toJSON' | 'toPrimitive' | 'toString' | 'toU8a';
export type ArgsDef = Record<string, CodecClass | string>;
@@ -31,6 +31,7 @@ export interface INumber extends Codec {
toBigInt (): bigint;
toBn (): BN;
toNumber (): number;
toPrimitive (): string | number;
}
export interface IFloat extends Codec {
+5 -5
View File
@@ -20,14 +20,14 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "8.13.1",
"version": "8.14.1",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.18.6",
"@polkadot/types-codec": "8.13.1",
"@polkadot/util": "^10.0.2"
"@babel/runtime": "^7.18.9",
"@polkadot/types-codec": "8.14.1",
"@polkadot/util": "^10.1.1"
},
"devDependencies": {
"@polkadot/types": "8.13.1"
"@polkadot/types": "8.14.1"
}
}
+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: '8.13.1' };
export const packageInfo = { name: '@polkadot/types-create', path: 'auto', type: 'auto', version: '8.14.1' };
+7 -7
View File
@@ -20,14 +20,14 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "8.13.1",
"version": "8.14.1",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.18.6",
"@polkadot/networks": "^10.0.2",
"@polkadot/types": "8.13.1",
"@polkadot/types-codec": "8.13.1",
"@polkadot/types-create": "8.13.1",
"@polkadot/util": "^10.0.2"
"@babel/runtime": "^7.18.9",
"@polkadot/networks": "^10.1.1",
"@polkadot/types": "8.14.1",
"@polkadot/types-codec": "8.14.1",
"@polkadot/types-create": "8.14.1",
"@polkadot/util": "^10.1.1"
}
}
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/types-known', path: 'auto', type: 'auto', version: '8.13.1' };
export const packageInfo = { name: '@polkadot/types-known', path: 'auto', type: 'auto', version: '8.14.1' };
+3 -3
View File
@@ -20,10 +20,10 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "8.13.1",
"version": "8.14.1",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.18.6",
"@polkadot/util": "^10.0.2"
"@babel/runtime": "^7.18.9",
"@polkadot/util": "^10.1.1"
}
}
File diff suppressed because one or more lines are too long
@@ -41967,7 +41967,11 @@
"fields": [],
"index": 8,
"docs": [
"The amount does not meet the minimum bond to either join or create a pool."
"The amount does not meet the minimum bond to either join or create a pool.",
"",
"The depositor can never unbond to a value less than",
"`Pallet::depositor_min_bond`. The caller does not have nominating",
"permissions for the pool. Members can never unbond to a value below `MinJoinBond`."
]
},
{
@@ -41987,19 +41991,10 @@
"other members to be permissionlessly unbonded."
]
},
{
"name": "NotOnlyPoolMember",
"fields": [],
"index": 11,
"docs": [
"The depositor must be the only member in the bonded pool in order to unbond. And the",
"depositor must be the only member in the sub pools in order to withdraw unbonded."
]
},
{
"name": "NotNominator",
"fields": [],
"index": 12,
"index": 11,
"docs": [
"The caller does not have nominating permissions for the pool."
]
@@ -42007,7 +42002,7 @@
{
"name": "NotKickerOrDestroying",
"fields": [],
"index": 13,
"index": 12,
"docs": [
"Either a) the caller cannot make a valid kick or b) the pool is not destroying."
]
@@ -42015,7 +42010,7 @@
{
"name": "NotOpen",
"fields": [],
"index": 14,
"index": 13,
"docs": [
"The pool is not open to join"
]
@@ -42023,7 +42018,7 @@
{
"name": "MaxPools",
"fields": [],
"index": 15,
"index": 14,
"docs": [
"The system is maxed out on pools."
]
@@ -42031,7 +42026,7 @@
{
"name": "MaxPoolMembers",
"fields": [],
"index": 16,
"index": 15,
"docs": [
"Too many members in the pool or system."
]
@@ -42039,7 +42034,7 @@
{
"name": "CanNotChangeState",
"fields": [],
"index": 17,
"index": 16,
"docs": [
"The pools state cannot be changed."
]
@@ -42047,7 +42042,7 @@
{
"name": "DoesNotHavePermission",
"fields": [],
"index": 18,
"index": 17,
"docs": [
"The caller does not have adequate permissions."
]
@@ -42055,7 +42050,7 @@
{
"name": "MetadataExceedsMaxLen",
"fields": [],
"index": 19,
"index": 18,
"docs": [
"Metadata exceeds [`Config::MaxMetadataLen`]"
]
@@ -42070,24 +42065,16 @@
"docs": []
}
],
"index": 20,
"index": 19,
"docs": [
"Some error occurred that should never happen. This should be reported to the",
"maintainers."
]
},
{
"name": "NotEnoughPointsToUnbond",
"fields": [],
"index": 21,
"docs": [
"Not enough points. Ty unbonding less."
]
},
{
"name": "PartialUnbondNotAllowedPermissionlessly",
"fields": [],
"index": 22,
"index": 20,
"docs": [
"Partial unbonding now allowed permissionlessly."
]
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/types-support', path: 'auto', type: 'auto', version: '8.13.1' };
export const packageInfo = { name: '@polkadot/types-support', path: 'auto', type: 'auto', version: '8.14.1' };
+10 -10
View File
@@ -20,20 +20,20 @@
"./detectPackage.cjs"
],
"type": "module",
"version": "8.13.1",
"version": "8.14.1",
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.18.6",
"@polkadot/keyring": "^10.0.2",
"@polkadot/types-augment": "8.13.1",
"@polkadot/types-codec": "8.13.1",
"@polkadot/types-create": "8.13.1",
"@polkadot/util": "^10.0.2",
"@polkadot/util-crypto": "^10.0.2",
"@babel/runtime": "^7.18.9",
"@polkadot/keyring": "^10.1.1",
"@polkadot/types-augment": "8.14.1",
"@polkadot/types-codec": "8.14.1",
"@polkadot/types-create": "8.14.1",
"@polkadot/util": "^10.1.1",
"@polkadot/util-crypto": "^10.1.1",
"rxjs": "^7.5.6"
},
"devDependencies": {
"@polkadot/keyring": "^10.0.2",
"@polkadot/types-support": "8.13.1"
"@polkadot/keyring": "^10.1.1",
"@polkadot/types-support": "8.14.1"
}
}
+37 -7
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2022 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Codec, CodecClass, IU8a } from '@polkadot/types-codec/types';
import type { AnyString, Codec, CodecClass, IU8a } from '@polkadot/types-codec/types';
import type { CreateOptions, TypeDef } from '@polkadot/types-create/types';
import type { ExtDef } from '../extrinsic/signedExtensions/types';
import type { ChainProperties, DispatchErrorModule, DispatchErrorModuleU8, DispatchErrorModuleU8a, EventMetadataLatest, Hash, MetadataLatest, SiField, SiLookupTypeId, SiVariant } from '../interfaces/types';
@@ -105,20 +105,48 @@ function injectEvents (registry: TypeRegistry, { lookup, pallets }: MetadataLate
}
// create extrinsic mapping from metadata
function injectExtrinsics (registry: TypeRegistry, { lookup, pallets }: MetadataLatest, version: number, result: Record<string, Record<string, CallFunction>>): void {
function injectExtrinsics (registry: TypeRegistry, { lookup, pallets }: MetadataLatest, version: number, result: Record<string, Record<string, CallFunction>>, mapping: Record<string, string[]>): void {
const filtered = pallets.filter(filterCallsSome);
clearRecord(result);
clearRecord(mapping);
for (let i = 0; i < filtered.length; i++) {
const { calls, index, name } = filtered[i];
const sectionIndex = version >= 12 ? index.toNumber() : i;
const sectionName = stringCamelCase(name);
const allCalls = calls.unwrap();
lazyMethod(result, sectionIndex, () =>
lazyVariants(lookup, calls.unwrap(), getVariantStringIdx, (variant: SiVariant) =>
createCallFunction(registry, lookup, variant, stringCamelCase(name), sectionIndex)
lazyVariants(lookup, allCalls, getVariantStringIdx, (variant: SiVariant) =>
createCallFunction(registry, lookup, variant, sectionName, sectionIndex)
)
);
const { path } = registry.lookup.getSiType(allCalls.type);
// frame_system::pallet::Call / pallet_balances::pallet::Call / polkadot_runtime_parachains::configuration::pallet::Call /
const palletIdx = path.findIndex((v) => v.eq('pallet'));
if (palletIdx !== -1) {
const name = stringCamelCase(
path
.slice(0, palletIdx)
.map((p, i) =>
i === 0
// frame_system || pallet_balances
? p.replace(/^(frame|pallet)_/, '')
: p
)
.join(' ')
);
if (!mapping[name]) {
mapping[name] = [sectionName];
} else {
mapping[name].push(sectionName);
}
}
}
}
@@ -156,6 +184,8 @@ export class TypeRegistry implements Registry {
readonly #metadataEvents: Record<string, Record<string, CodecClass<GenericEventData>>> = {};
readonly #moduleMap: Record<string, string[]> = {};
#unknownTypes = new Map<string, boolean>();
#chainProperties?: ChainProperties;
@@ -403,8 +433,8 @@ export class TypeRegistry implements Registry {
return this.#definitions.get(typeName);
}
public getModuleInstances (specName: string, moduleName: string): string[] | undefined {
return this.#knownTypes?.typesBundle?.spec?.[specName]?.instances?.[moduleName];
public getModuleInstances (specName: AnyString, moduleName: string): string[] | undefined {
return this.#knownTypes?.typesBundle?.spec?.[specName.toString()]?.instances?.[moduleName] || this.#moduleMap[moduleName];
}
public getOrThrow <T extends Codec = Codec, K extends string = string, R = DetectCodec<T, K>> (name: K, msg?: string): CodecClass<R> {
@@ -527,7 +557,7 @@ export class TypeRegistry implements Registry {
// attach the lookup at this point (before injecting)
this.setLookup(this.#metadata.lookup);
injectExtrinsics(this, this.#metadata, this.#metadataVersion, this.#metadataCalls);
injectExtrinsics(this, this.#metadata, this.#metadataVersion, this.#metadataCalls, this.#moduleMap);
injectErrors(this, this.#metadata, this.#metadataVersion, this.#metadataErrors);
injectEvents(this, this.#metadata, this.#metadataVersion, this.#metadataEvents);
+7
View File
@@ -53,6 +53,13 @@ export class GenericEthereumAccountId extends U8aFixed {
return this.toString();
}
/**
* @description Converts the value in a best-fit primitive form
*/
public override toPrimitive (): string {
return this.toJSON();
}
/**
* @description Returns the string representation of the value
*/
@@ -43,6 +43,7 @@ describe('Extrinsic', (): void => {
expect(extrinsic.callIndex).toEqual(new Uint8Array([6, 0]));
expect(extrinsic.args[0].toHex()).toEqual('0x00495e1e506f266418af07fa0c5c108dd436f2faa59fe7d9e54403779f5bbd7718');
expect(extrinsic.args[1].toHuman()).toEqual('104,560,923,320,000'); // ('104.5609 Unit');
expect(extrinsic.toPrimitive()).toEqual({ method: { args: { dest: { id: '5DiuK2zR4asj2CEh77SKtUgTswTLkD8eiAKrByg5G3wL5w9b' }, value: 104560923320000 }, callIndex: '0x0600' }, signature: { era: { mortalEra: [1024, 186] }, nonce: 68, signature: { ed25519: '0xd99ffe3e610ad234e1414bda5831395a6df9098bf80b01561ce89a5065ae89d5c10e1619c6c99131b0bea4fb73ef04d07c07770e2ae9df5c325c331769ccb300' }, signer: { id: '5Hn8KKEp8qruCGWaN9MEsjTs4FXB4wv9xn7g1RWkNeKKNXCr' }, tip: 30000000000 } });
});
});
});
+7
View File
@@ -62,6 +62,13 @@ export class GenericAccountId extends U8aFixed {
return this.toString();
}
/**
* @description Converts the value in a best-fit primitive form
*/
public override toPrimitive (): string {
return this.toJSON();
}
/**
* @description Returns the string representation of the value
*/
@@ -104,6 +104,13 @@ export class GenericAccountIndex extends u32 {
return this.toString();
}
/**
* @description Converts the value in a best-fit primitive form
*/
public override toPrimitive (): string {
return this.toJSON();
}
/**
* @description Returns the string representation of the value
*/
+7
View File
@@ -104,6 +104,13 @@ export class GenericCallIndex extends U8aFixed {
constructor (registry: Registry, value?: AnyU8a) {
super(registry, value, 16);
}
/**
* @description Converts the value in a best-fit primitive form
*/
public override toPrimitive (): string {
return this.toHex();
}
}
/**
+14 -6
View File
@@ -7,7 +7,7 @@ import { GenericVote } from '.';
describe('GenericVote', (): void => {
const registry = new TypeRegistry();
describe.only('construction', (): void => {
describe('construction', (): void => {
it('constructs via boolean true', (): void => {
expect(new GenericVote(registry, true).toU8a()).toEqual(new Uint8Array([128]));
expect(new GenericVote(registry, true).isAye).toBe(true);
@@ -58,7 +58,7 @@ describe('GenericVote', (): void => {
expect(new GenericVote(registry, new Uint8Array([1])).isNay).toBe(true);
});
it.only('constructs via Uint8Array (aye)', (): void => {
it('constructs via Uint8Array (aye)', (): void => {
const test = new GenericVote(registry, new Uint8Array([0b10000010]));
expect(test.isNay).toBe(false);
@@ -68,12 +68,20 @@ describe('GenericVote', (): void => {
describe('Vote with conviction', (): void => {
it('constructs Vote with raw boolean', (): void => {
const vote = new GenericVote(registry, {
aye: true,
conviction: 'Locked1x'
});
expect(
new GenericVote(registry, {
aye: true,
conviction: 'Locked1x'
}).toU8a()
vote.toU8a()
).toEqual(new Uint8Array([0b10000001]));
expect(
vote.toPrimitive()
).toEqual({
aye: true,
conviction: 'Locked1x'
});
});
it('constructs with Vote aye is false, conviction is None', (): void => {
+10
View File
@@ -115,6 +115,16 @@ export class GenericVote extends U8aFixed {
};
}
/**
* @description Converts the value in a best-fit primitive form
*/
public override toPrimitive (): any {
return {
aye: this.isAye,
conviction: this.conviction.toPrimitive()
};
}
/**
* @description Returns the base runtime type name for this instance
*/
@@ -4,7 +4,7 @@
// order important in structs... :)
/* eslint-disable sort-keys */
export const AllHashers = {
export const AllHashers = <const> {
Blake2_128: null, // eslint-disable-line camelcase
Blake2_256: null, // eslint-disable-line camelcase
Blake2_128Concat: null, // eslint-disable-line camelcase
@@ -38,5 +38,40 @@ export const runtime: DefinitionsCall = {
},
version: 1
}
],
TransactionPaymentCallApi: [
{
methods: {
query_call_fee_details: {
description: 'The call fee details',
params: [
{
name: 'call',
type: 'Call'
},
{
name: 'len',
type: 'u32'
}
],
type: 'FeeDetails'
},
query_call_info: {
description: 'The call info',
params: [
{
name: 'call',
type: 'Call'
},
{
name: 'len',
type: 'u32'
}
],
type: 'RuntimeDispatchInfo'
}
},
version: 1
}
]
};
@@ -17,11 +17,15 @@ import { toLatest } from './v14/toLatest';
import { MagicNumber } from './MagicNumber';
import { getUniqTypes, toCallsOnly } from './util';
type MetaMapped = MetadataV9 | MetadataV10 | MetadataV11 | MetadataV12 | MetadataV13 | MetadataV14;
type MetaAsX = 'asV9' | 'asV10' | 'asV11' | 'asV12' | 'asV13' | 'asV14';
type MetaVersions = 'latest' | 9 | 10 | 11 | 12 | 13 | 14;
// Use these to generate all the Meta* types below via template keys
// NOTE: Keep from latest -> earliest, see the LATEST_VERSION 0 index
const KNOWN_VERSIONS = <const> [14, 13, 12, 11, 10, 9];
const LATEST_VERSION = KNOWN_VERSIONS[0];
const LATEST_VERSION = 14;
type MetaAll = typeof KNOWN_VERSIONS[number];
type MetaAsX = `asV${MetaAll}`;
type MetaMapped = MetadataAll[MetaAsX];
type MetaVersions = MetaAll | 'latest';
/**
* @name MetadataVersioned
@@ -5,6 +5,7 @@ import type { AnyJson, Registry } from '@polkadot/types-codec/types';
import type { MetadataLatest, PalletCallMetadataLatest } from '../../interfaces/metadata';
import { Option, Text, u8 } from '@polkadot/types-codec';
import { objectSpread } from '@polkadot/util';
interface ModuleMetadataTrimmed {
calls: Option<PalletCallMetadataLatest>;
@@ -29,10 +30,7 @@ export function toCallsOnly (registry: Registry, { extrinsic, lookup, pallets }:
types: lookup.types.map(({ id, type }) =>
registry.createTypeUnsafe('PortableType', [{
id,
type: {
...type,
docs: trimDocs(type.docs)
}
type: objectSpread({}, type, { docs: trimDocs(type.docs) })
}])
)
},
+3 -4
View File
@@ -4,6 +4,8 @@
import type { Registry } from '@polkadot/types-codec/types';
import type { MetadataV11, MetadataV12, ModuleMetadataV12 } from '../../interfaces/metadata';
import { objectSpread } from '@polkadot/util';
/**
* @internal
**/
@@ -11,10 +13,7 @@ export function toV12 (registry: Registry, { extrinsic, modules }: MetadataV11):
return registry.createTypeUnsafe('MetadataV12', [{
extrinsic,
modules: modules.map((mod): ModuleMetadataV12 =>
registry.createTypeUnsafe('ModuleMetadataV12', [{
...mod,
index: 255
}])
registry.createTypeUnsafe('ModuleMetadataV12', [objectSpread({}, mod, { index: 255 })])
)
}]);
}
+15 -16
View File
@@ -4,6 +4,8 @@
import type { Registry } from '@polkadot/types-codec/types';
import type { MetadataV9, MetadataV10, ModuleMetadataV9, ModuleMetadataV10, StorageEntryMetadataV9, StorageEntryTypeV9, StorageHasherV9, StorageHasherV10 } from '../../interfaces/metadata';
import { objectSpread } from '@polkadot/util';
// migrate a storage hasher type
// see https://github.com/paritytech/substrate/pull/4462
/** @internal */
@@ -20,18 +22,16 @@ function createStorageHasher (registry: Registry, hasher: StorageHasherV9): Stor
/** @internal */
function createStorageType (registry: Registry, entryType: StorageEntryTypeV9): [any, number] {
if (entryType.isMap) {
return [{
...entryType.asMap,
return [objectSpread({}, entryType.asMap, {
hasher: createStorageHasher(registry, entryType.asMap.hasher)
}, 1];
}), 1];
}
if (entryType.isDoubleMap) {
return [{
...entryType.asDoubleMap,
return [objectSpread({}, entryType.asDoubleMap, {
hasher: createStorageHasher(registry, entryType.asDoubleMap.hasher),
key2Hasher: createStorageHasher(registry, entryType.asDoubleMap.key2Hasher)
}, 2];
}), 2];
}
return [entryType.asPlain, 0];
@@ -41,18 +41,17 @@ function createStorageType (registry: Registry, entryType: StorageEntryTypeV9):
function convertModule (registry: Registry, mod: ModuleMetadataV9): ModuleMetadataV10 {
const storage = mod.storage.unwrapOr(null);
return registry.createTypeUnsafe('ModuleMetadataV10', [{
...mod,
return registry.createTypeUnsafe('ModuleMetadataV10', [objectSpread({}, mod, {
storage: storage
? {
...storage,
items: storage.items.map((item: StorageEntryMetadataV9): any => ({
...item,
type: registry.createTypeUnsafe('StorageEntryTypeV10', createStorageType(registry, item.type))
}))
}
? objectSpread({}, storage, {
items: storage.items.map((item: StorageEntryMetadataV9): any =>
objectSpread({}, item, {
type: registry.createTypeUnsafe('StorageEntryTypeV10', createStorageType(registry, item.type))
})
)
})
: null
}]);
})]);
}
/** @internal */
+1 -1
View File
@@ -3,4 +3,4 @@
// Do not edit, auto-generated by @polkadot/dev
export const packageInfo = { name: '@polkadot/types', path: 'auto', type: 'auto', version: '8.13.1' };
export const packageInfo = { name: '@polkadot/types', path: 'auto', type: 'auto', version: '8.14.1' };
+2 -2
View File
@@ -6,7 +6,7 @@
import '@polkadot/types-codec/types/registry';
import '@polkadot/types-create/types/augmentRegistry';
import type { Codec, CodecClass } from '@polkadot/types-codec/types';
import type { AnyString, Codec, CodecClass } from '@polkadot/types-codec/types';
import type { TypeDef } from '@polkadot/types-create/types';
import type { ExtDef } from '../extrinsic/signedExtensions/types';
import type { MetadataLatest } from '../interfaces/metadata';
@@ -41,7 +41,7 @@ declare module '@polkadot/types-codec/types/registry' {
get <T extends Codec = Codec, K extends string = string> (name: K, withUnknown?: boolean, knownTypeDef?: TypeDef): CodecClass<DetectCodec<T, K>> | undefined;
getChainProperties (): ChainProperties | undefined;
getDefinition (typeName: string): string | undefined;
getModuleInstances (specName: string, moduleName: string): string[] | undefined;
getModuleInstances (specName: AnyString, moduleName: string): string[] | undefined;
setKnownTypes (types: RegisteredTypes): void;
setChainProperties (properties?: ChainProperties): void;
+583 -602
View File
File diff suppressed because it is too large Load Diff