Compare commits

...
10 Commits
Author SHA1 Message Date
Github Actions dbb5d66de3 [CI Skip] release/stable 6.0.4
skip-checks: true
2021-09-20 09:10:12 +00:00
Jaco 6bc92a6d31 6.0.4 (#3975)
* 6.0.4

* Update CHANGELOG.md
2021-09-20 10:53:34 +02:00
Github Actions 6462327ea5 [CI Skip] release/beta 6.0.4-1
skip-checks: true
2021-09-20 06:17:50 +00:00
Jaco 3b4c2ac323 Extract getSiName conversion (#3974) 2021-09-20 07:56:33 +02:00
Github Actions d0ecfdafc1 [CI Skip] release/beta 6.0.4-0
skip-checks: true
2021-09-20 05:19:55 +00:00
Jaco 870bb8d3cb User api.at for all .at queries (#3973) 2021-09-20 06:59:35 +02:00
Github Actions 2fdb68d3bc [CI Skip] release/stable 6.0.3
skip-checks: true
2021-09-19 19:47:24 +00:00
Jaco 6ef410e375 Share TypeSpec between registry instances (#3972)
* Share TypeSpec between registry instances

* 6.0.3
2021-09-19 21:29:11 +02:00
Github Actions 962c741139 [CI Skip] release/beta 6.0.3-0
skip-checks: true
2021-09-19 06:38:13 +00:00
Jaco 598e69002a Formatting for metadata documentation (#3969)
* Formatting for metadata documentation

* unwrap
2021-09-19 08:18:13 +02:00
41 changed files with 218 additions and 167 deletions
+3 -1
View File
@@ -30,4 +30,6 @@
5.8.2
5.8.3
6.0.2
6.0.2
6.0.3
6.0.4
+20
View File
@@ -1,5 +1,25 @@
# CHANGELOG
## 6.0.4 Sep 20, 2021
Upgrade priority: Low. Recommended for all users on 6.0.3 using `api.query.*.*.at` calls
Changes:
- `api.query.<module>.<method>.at` will now use `at.at(<hash>)`
- Use and expose `metadata/util/getSiName` to get human type names
## 6.0.3 Sep 19, 2021
Upgrade priority: Low. Recommended for all users on 6.0.2 using `api.query.*.*.at` calls
Changes:
- Fix `api.query.<module>.<method>.at` queries
- Adjust typegen formatting for metadata documentation
## 6.0.2 Sep 18, 2021
Upgrade priority: Low. Recommended for all users on 6.0.1, especially those using `api.query.substrate.*` calls
+1 -1
View File
@@ -35,6 +35,6 @@
"@types/jest": "^27.0.1",
"copyfiles": "^2.4.1"
},
"version": "6.0.2",
"version": "6.0.4",
"packageManager": "yarn@3.0.1"
}
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-contract",
"version": "6.0.2",
"version": "6.0.4",
"type": "module",
"description": "Interfaces for interacting with contracts and contract ABIs",
"main": "index.js",
@@ -20,8 +20,8 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
"dependencies": {
"@babel/runtime": "^7.15.4",
"@polkadot/api": "6.0.2",
"@polkadot/types": "6.0.2",
"@polkadot/api": "6.0.4",
"@polkadot/types": "6.0.4",
"@polkadot/util": "^7.4.1",
"rxjs": "^7.3.0"
}
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/api-contract', version: '6.0.2' };
export const packageInfo = { name: '@polkadot/api-contract', version: '6.0.4' };
+5 -5
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-derive",
"version": "6.0.2",
"version": "6.0.4",
"type": "module",
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
"main": "index.js",
@@ -20,15 +20,15 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
"dependencies": {
"@babel/runtime": "^7.15.4",
"@polkadot/api": "6.0.2",
"@polkadot/rpc-core": "6.0.2",
"@polkadot/types": "6.0.2",
"@polkadot/api": "6.0.4",
"@polkadot/rpc-core": "6.0.4",
"@polkadot/types": "6.0.4",
"@polkadot/util": "^7.4.1",
"@polkadot/util-crypto": "^7.4.1",
"rxjs": "^7.3.0"
},
"devDependencies": {
"@polkadot/keyring": "^7.4.1",
"@polkadot/rpc-provider": "6.0.2"
"@polkadot/rpc-provider": "6.0.4"
}
}
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/api-derive', version: '6.0.2' };
export const packageInfo = { name: '@polkadot/api-derive', version: '6.0.4' };
+6 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api",
"version": "6.0.2",
"version": "6.0.4",
"type": "module",
"description": "Promise and RxJS wrappers around the Polkadot JS RPC",
"main": "index.js",
@@ -20,12 +20,12 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api#readme",
"dependencies": {
"@babel/runtime": "^7.15.4",
"@polkadot/api-derive": "6.0.2",
"@polkadot/api-derive": "6.0.4",
"@polkadot/keyring": "^7.4.1",
"@polkadot/rpc-core": "6.0.2",
"@polkadot/rpc-provider": "6.0.2",
"@polkadot/types": "6.0.2",
"@polkadot/types-known": "6.0.2",
"@polkadot/rpc-core": "6.0.4",
"@polkadot/rpc-provider": "6.0.4",
"@polkadot/types": "6.0.4",
"@polkadot/types-known": "6.0.4",
"@polkadot/util": "^7.4.1",
"@polkadot/util-crypto": "^7.4.1",
"eventemitter3": "^4.0.7",
+30 -13
View File
@@ -12,7 +12,7 @@ import type { SubmittableExtrinsic } from '../submittable/types';
import type { ApiDecoration, ApiInterfaceRx, ApiOptions, ApiTypes, DecoratedErrors, DecoratedEvents, DecoratedRpc, DecoratedRpcSection, DecorateMethod, PaginationOptions, QueryableConsts, QueryableModuleStorage, QueryableModuleStorageAt, QueryableStorage, QueryableStorageAt, QueryableStorageEntry, QueryableStorageEntryAt, QueryableStorageMulti, QueryableStorageMultiArg, SubmittableExtrinsicFunction, SubmittableExtrinsics, SubmittableModuleExtrinsics } from '../types';
import type { VersionedRegistry } from './types';
import { BehaviorSubject, combineLatest, map, of, switchMap, tap, toArray } from 'rxjs';
import { BehaviorSubject, combineLatest, from, map, of, switchMap, tap, toArray } from 'rxjs';
import { decorateDerive, ExactDerive } from '@polkadot/api-derive';
import { memo, RpcCore } from '@polkadot/rpc-core';
@@ -154,6 +154,8 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
this._rx.hasSubscriptions = this._rpcCore.provider.hasSubscriptions;
}
public abstract at (blockHash: Uint8Array | string): Promise<ApiDecoration<ApiType>>;
/**
* @description Return the current used registry
*/
@@ -195,7 +197,10 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
consts: {},
errors: {},
events: {},
query: {}
query: {},
rx: {
query: {}
}
} as ApiDecoration<ApiType>;
}
@@ -211,8 +216,12 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
const storage = blockHash
? this._decorateStorageAt(registry.decoratedMeta, this._decorateMethod, blockHash)
: this._decorateStorage(registry.decoratedMeta, this._decorateMethod);
const storageRx = blockHash
? this._decorateStorageAt(registry.decoratedMeta, this._rxDecorateMethod, blockHash)
: this._decorateStorage(registry.decoratedMeta, this._rxDecorateMethod);
augmentObject('query', storage, decoratedApi.query, fromEmpty);
augmentObject('query', storageRx, decoratedApi.rx.query, fromEmpty);
return {
decoratedApi,
@@ -227,7 +236,10 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
consts: {},
errors: {},
events: {},
query: {}
query: {},
rx: {
query: {}
}
} as ApiDecoration<ApiType>;
}
@@ -237,6 +249,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
this._errors = decoratedApi.errors;
this._events = decoratedApi.events;
this._query = decoratedApi.query;
this._rx.query = decoratedApi.rx.query;
if (fromEmpty || !this._extrinsics) {
this._extrinsics = this._decorateExtrinsics(decoratedMeta, this._decorateMethod);
@@ -246,8 +259,6 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
augmentObject(null, this._decorateExtrinsics(decoratedMeta, this._rxDecorateMethod), this._rx.tx, false);
}
// rx
augmentObject(null, this._decorateStorage(decoratedMeta, this._rxDecorateMethod), this._rx.query, fromEmpty);
augmentObject(null, decoratedMeta.consts, this._rx.consts, fromEmpty);
}
@@ -358,12 +369,12 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
(this.hasSubscriptions
? this._rpcCore.state.subscribeStorage
: this._rpcCore.state.queryStorageAt)(
calls.map((arg: QueryableStorageMultiArg<ApiType>) =>
Array.isArray(arg)
? arg[0].creator.meta.type.asMap.hashers.length === 1
? [arg[0].creator, arg.slice(1)]
: [arg[0].creator, ...arg.slice(1)]
: [arg.creator])));
calls.map((args: QueryableStorageMultiArg<ApiType>) =>
Array.isArray(args)
? args[0].creator.meta.type.asMap.hashers.length === 1
? [args[0].creator, args.slice(1)]
: [args[0].creator, ...args.slice(1)]
: [args.creator])));
}
protected _decorateExtrinsics<ApiType extends ApiTypes> ({ tx }: DecoratedMeta, decorateMethod: DecorateMethod<ApiType>): SubmittableExtrinsics<ApiType> {
@@ -418,7 +429,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
private _decorateStorageEntry<ApiType extends ApiTypes> (creator: StorageEntry, decorateMethod: DecorateMethod<ApiType>): QueryableStorageEntry<ApiType> {
// get the storage arguments, with DoubleMap as an array entry, otherwise spread
const getArgs = (args: unknown[]): unknown[] => extractStorageArgs(this.#registry, creator, args);
const getArgs = (args: unknown[]) => extractStorageArgs(this.#registry, creator, args);
// Disable this where it occurs for each field we are decorating
/* eslint-disable @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment */
@@ -428,7 +439,13 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
decorated.creator = creator;
decorated.at = decorateMethod((hash: Hash, ...args: unknown[]): Observable<Codec> =>
this._rpcCore.state.getStorage(getArgs(args), hash));
from(this.at(hash)).pipe(
switchMap((api): Observable<Codec> => {
assert(api.rx.query[creator.section] && api.rx.query[creator.section][creator.method], () => `query.${creator.section}.${creator.method} is not available in this version of the metadata`);
return api.rx.query[creator.section][creator.method](...args);
})
));
decorated.hash = decorateMethod((...args: unknown[]): Observable<Hash> =>
this._rpcCore.state.getStorageHash(getArgs(args)));
+2 -2
View File
@@ -182,8 +182,8 @@ export abstract class Getters<ApiType extends ApiTypes> extends Init<ApiType> im
/**
* @description The underlying Rx API interface
*/
public get rx (): Pick<ApiInterfaceRx, 'tx' | 'rpc'> {
return assertResult(this._rx as Pick<ApiInterfaceRx, 'tx' | 'rpc'>);
public get rx (): Pick<ApiInterfaceRx, 'tx' | 'rpc' | 'query'> {
return assertResult(this._rx as Pick<ApiInterfaceRx, 'tx' | 'rpc' | 'query'>);
}
/**
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/api', version: '6.0.2' };
export const packageInfo = { name: '@polkadot/api', version: '6.0.4' };
+3
View File
@@ -112,4 +112,7 @@ export interface ApiDecoration<ApiType extends ApiTypes> {
errors: DecoratedErrors<ApiType>;
events: DecoratedEvents<ApiType>;
query: QueryableStorage<ApiType>;
rx: {
query: QueryableStorage<'rxjs'>;
}
}
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/rpc-core",
"version": "6.0.2",
"version": "6.0.4",
"type": "module",
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
"main": "index.js",
@@ -20,8 +20,8 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-core#readme",
"dependencies": {
"@babel/runtime": "^7.15.4",
"@polkadot/rpc-provider": "6.0.2",
"@polkadot/types": "6.0.2",
"@polkadot/rpc-provider": "6.0.4",
"@polkadot/types": "6.0.4",
"@polkadot/util": "^7.4.1",
"rxjs": "^7.3.0"
},
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/rpc-core', version: '6.0.2' };
export const packageInfo = { name: '@polkadot/rpc-core', version: '6.0.4' };
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/rpc-provider",
"version": "6.0.2",
"version": "6.0.4",
"type": "module",
"description": "Transport providers for the API",
"main": "index.js",
@@ -20,7 +20,7 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme",
"dependencies": {
"@babel/runtime": "^7.15.4",
"@polkadot/types": "6.0.2",
"@polkadot/types": "6.0.4",
"@polkadot/util": "^7.4.1",
"@polkadot/util-crypto": "^7.4.1",
"@polkadot/x-fetch": "^7.4.1",
@@ -30,7 +30,7 @@
},
"devDependencies": {
"@polkadot/keyring": "^7.4.1",
"@polkadot/types": "6.0.2",
"@polkadot/types": "6.0.4",
"mock-socket": "^9.0.3",
"nock": "^13.1.3"
}
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/rpc-provider', version: '6.0.2' };
export const packageInfo = { name: '@polkadot/rpc-provider', version: '6.0.4' };
+5 -5
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/typegen",
"version": "6.0.2",
"version": "6.0.4",
"type": "module",
"description": "Type generation scripts",
"main": "index.js",
@@ -29,10 +29,10 @@
"@babel/core": "^7.15.5",
"@babel/register": "^7.15.3",
"@babel/runtime": "^7.15.4",
"@polkadot/api": "6.0.2",
"@polkadot/rpc-provider": "6.0.2",
"@polkadot/types": "6.0.2",
"@polkadot/types-support": "6.0.2",
"@polkadot/api": "6.0.4",
"@polkadot/rpc-provider": "6.0.4",
"@polkadot/types": "6.0.4",
"@polkadot/types-support": "6.0.4",
"@polkadot/util": "^7.4.1",
"handlebars": "^4.7.7",
"websocket": "^1.0.34",
+2 -1
View File
@@ -198,7 +198,8 @@ function generateLookupDefs (registry: Registry, filtered: [PortableType, TypeDe
].map(([n, t]) => `${n}: ${t}`),
docs
};
})
}),
headerType: 'defs'
});
});
}
-21
View File
@@ -21,27 +21,6 @@ import { ModuleTypes } from '../util/imports';
function entrySignature (lookup: PortableRegistry, allDefs: Record<string, ModuleTypes>, registry: Registry, storageEntry: StorageEntryMetadataLatest, imports: TypeImports): [boolean, string, string, string] {
const outputType = lookup.getTypeDef(unwrapStorageSi(storageEntry.type));
// else if (storageEntry.type.isMap) {
// const map = storageEntry.type.asMap;
// const keyDef = lookup.getTypeDef(map.key);
// const valDef = lookup.getTypeDef(map.value);
// // Find similar types of the `key` type
// const similarTypes = getSimilarTypes(registry, allDefs, keyDef.lookupName || keyDef.type, imports);
// setImports(allDefs, imports, [
// ...similarTypes,
// valDef.lookupName || valDef.type
// ]);
// return [
// storageEntry.modifier.isOptional,
// formatType(registry, allDefs, keyDef.lookupName || keyDef.type, imports),
// `arg: ${similarTypes.join(' | ')}`,
// formatType(registry, allDefs, outputType, imports)
// ];
// }
if (storageEntry.type.isPlain) {
const typeDef = lookup.getTypeDef(storageEntry.type.asPlain);
+20 -8
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2021 @polkadot/typegen authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { MetadataLatest } from '@polkadot/types/interfaces/metadata';
import type { MetadataLatest, PortableRegistry, SiLookupTypeId } from '@polkadot/types/interfaces';
import type { Codec, DefinitionRpcParam } from '@polkadot/types/types';
import fs from 'fs';
@@ -118,6 +118,12 @@ function sortByName<T extends { name: Codec | string }> (a: T, b: T): number {
return a.name.toString().toUpperCase().localeCompare(b.name.toString().toUpperCase());
}
function getSiName (lookup: PortableRegistry, type: SiLookupTypeId): string {
const typeDef = lookup.getTypeDef(type);
return typeDef.lookupName || typeDef.type;
}
/** @internal */
function addRpc (): string {
const sections = Object
@@ -185,7 +191,7 @@ function addConstants ({ lookup, pallets }: MetadataLatest): string {
return {
interface: '`' + `api.consts.${sectionName}.${methodName}` + '`',
name: `${methodName}: ` + '`' + lookup.getTypeDef(type).type + '`',
name: `${methodName}: ` + '`' + getSiName(lookup, type) + '`',
...(docs.length && { summary: docs })
};
}),
@@ -214,9 +220,11 @@ function addStorage ({ lookup, pallets, registry }: MetadataLatest): string {
if (func.type.isMap) {
const { hashers, key } = func.type.asMap;
arg = hashers.length === 1
? ('`' + key.toString() + '`')
: ('`' + lookup.getSiType(key).def.asTuple.map((t) => t).join(', ') + '`');
arg = '`' + (
hashers.length === 1
? getSiName(lookup, key)
: lookup.getSiType(key).def.asTuple.map((t) => getSiName(lookup, t)).join(', ')
) + '`';
}
const methodName = stringLowerFirst(func.name);
@@ -238,7 +246,7 @@ function addStorage ({ lookup, pallets, registry }: MetadataLatest): string {
description: 'These are well-known keys that are always available to the runtime implementation of any Substrate-based network.',
items: Object.entries(substrate).map(([name, { meta }]) => {
const arg = meta.type.isMap
? ('`' + lookup.getTypeDef(meta.type.asMap.key).type + '`')
? ('`' + getSiName(lookup, meta.type.asMap.key) + '`')
: '';
const methodName = stringLowerFirst(name);
const outputType = unwrapStorageType(registry, meta.type, meta.modifier.isOptional);
@@ -270,7 +278,9 @@ function addExtrinsics ({ lookup, pallets }: MetadataLatest): string {
.sort(sortByName)
.map(({ docs, fields, name }, index) => {
const methodName = stringCamelCase(name);
const args = fields.map(({ name, type }) => `${name.isSome ? name.toString() : `param${index}`}: ` + '`' + lookup.getTypeDef(type).type + '`').join(', ');
const args = fields.map(({ name, type }) =>
`${name.isSome ? name.toString() : `param${index}`}: ` + '`' + getSiName(lookup, type) + '`'
).join(', ');
return {
interface: '`' + `api.tx.${sectionName}.${methodName}` + '`',
@@ -297,7 +307,9 @@ function addEvents ({ lookup, pallets }: MetadataLatest): string {
.sort(sortByName)
.map(({ docs, fields, name }) => {
const methodName = name.toString();
const args = fields.map(({ type }) => '`' + lookup.getTypeDef(type).type + '`').join(', ');
const args = fields.map(({ type }) =>
'`' + getSiName(lookup, type) + '`'
).join(', ');
return {
interface: '`' + `api.events.${stringCamelCase(meta.name)}.${methodName}.is` + '`',
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/typegen', version: '6.0.2' };
export const packageInfo = { name: '@polkadot/typegen', version: '6.0.4' };
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/types-known",
"version": "6.0.2",
"version": "6.0.4",
"type": "module",
"description": "Known type definitions",
"main": "index.js",
@@ -21,7 +21,7 @@
"dependencies": {
"@babel/runtime": "^7.15.4",
"@polkadot/networks": "^7.4.1",
"@polkadot/types": "6.0.2",
"@polkadot/types": "6.0.4",
"@polkadot/util": "^7.4.1"
}
}
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/types-known', version: '6.0.2' };
export const packageInfo = { name: '@polkadot/types-known', version: '6.0.4' };
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/types-support",
"version": "6.0.2",
"version": "6.0.4",
"type": "module",
"description": "Supporting files for types, mostly for testing",
"main": "index.js",
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/types-support', version: '6.0.2' };
export const packageInfo = { name: '@polkadot/types-support', version: '6.0.4' };
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/types",
"version": "6.0.2",
"version": "6.0.4",
"type": "module",
"description": "Implementation of the Parity codec",
"main": "index.js",
@@ -26,7 +26,7 @@
},
"devDependencies": {
"@polkadot/keyring": "^7.4.1",
"@polkadot/types-support": "6.0.2",
"@polkadot/types-support": "6.0.4",
"@types/bn.js": "^4.11.6",
"bn.js": "^4.12.0"
}
@@ -10,8 +10,10 @@ import substrate from './substrate';
export default {
rpc: {},
types: {
// Not 100% sure it is relevant, however the order here is the same
// as exposed in the typegen lookup order
...substrate,
...polkadot,
...kusama,
...substrate
...kusama
}
} as Definitions;
+1 -1
View File
@@ -1,4 +1,4 @@
// Auto-generated via `yarn polkadot-types-from-`, do not edit
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
/* eslint-disable sort-keys */
@@ -1,4 +1,4 @@
// Auto-generated via `yarn polkadot-types-from-`, do not edit
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
/* eslint-disable sort-keys */
@@ -1,4 +1,4 @@
// Auto-generated via `yarn polkadot-types-from-`, do not edit
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
/* eslint-disable sort-keys */
+3 -1
View File
@@ -3,7 +3,7 @@
import type { ExtDef } from '../extrinsic/signedExtensions/types';
import type { ChainProperties, CodecHash, DispatchErrorModule, Hash, MetadataLatest, PortableRegistry, SiLookupTypeId } from '../interfaces/types';
import type { CallFunction, Codec, CodecHasher, Constructor, DetectCodec, DetectConstructor, RegisteredTypes, Registry, RegistryError, RegistryTypes } from '../types';
import type { CallFunction, Codec, CodecHasher, Constructor, DetectCodec, DetectConstructor, RegisteredTypes, Registry, RegistryError, RegistryTypes, TypeSpec } from '../types';
import type { CreateOptions } from './types';
import { assert, assertReturn, BN_ZERO, formatBalance, isFunction, isString, isU8a, logger, stringCamelCase, stringify, u8aToHex } from '@polkadot/util';
@@ -145,6 +145,8 @@ export class TypeRegistry implements Registry {
#userExtensions?: ExtDef;
public compatSpecs: TypeSpec[] = [];
public createdAtHash?: Hash;
constructor (createdAtHash?: Hash | Uint8Array | string) {
@@ -132,7 +132,7 @@ export interface FunctionMetadataV14 extends Struct {
readonly fields: Vec<SiField>;
readonly index: u8;
readonly docs: Vec<Text>;
readonly args: Vec<FunctionArgumentMetadataLatest>;
readonly args: Vec<FunctionArgumentMetadataV14>;
}
/** @name FunctionMetadataV9 */
@@ -28,7 +28,7 @@ export const v14: DefinitionsTypes = {
FunctionArgumentMetadataV14: 'FunctionArgumentMetadataV13',
FunctionMetadataV14: {
...SiVariant,
args: 'Vec<FunctionArgumentMetadataLatest>'
args: 'Vec<FunctionArgumentMetadataV14>'
},
// V14
@@ -7,6 +7,7 @@ import type { Extrinsics, ModuleExtrinsics } from '../types';
import { stringCamelCase } from '@polkadot/util';
import { getSiName } from '../../util';
import { createUnchecked } from './createUnchecked';
/** @internal */
@@ -25,7 +26,7 @@ export function decorateExtrinsics (registry: Registry, { lookup, pallets }: Met
...variant,
args: variant.fields.map(({ name, type }, index) => ({
name: stringCamelCase(name.unwrapOr(`param${index}`)),
type: lookup.getTypeDef(type).type
type: getSiName(lookup, type)
}))
});
@@ -0,0 +1,10 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { PortableRegistry, SiLookupTypeId } from '../../interfaces';
export function getSiName (lookup: PortableRegistry, type: SiLookupTypeId): string {
const typeDef = lookup.getTypeDef(type);
return typeDef.lookupName || typeDef.type;
}
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
export { flattenUniq } from './flattenUniq';
export { getSiName } from './getSiName';
export { getUniqTypes } from './getUniqTypes';
export { toCallsOnly } from './toCallsOnly';
export { validateTypes } from './validateTypes';
+31 -43
View File
@@ -5,20 +5,11 @@ import type { ErrorMetadataV13, EventMetadataV13, ExtrinsicMetadataV13, Extrinsi
import type { SiVariant } from '../../interfaces/scaleInfo';
import type { Text } from '../../primitive/Text';
import type { Type } from '../../primitive/Type';
import type { OverrideModuleType, Registry } from '../../types';
import type { OverrideModuleType, Registry, TypeSpec } from '../../types';
import { getModuleTypes, knownOrigins } from '@polkadot/types-known';
import { stringCamelCase } from '@polkadot/util';
interface TypeSpec {
def: {
HistoricMetaCompat?: string;
Tuple?: number[];
Variant?: { variants: SiVariant[] }
},
path?: string[];
}
interface MapDef {
hashers: StorageHasherV13[];
keys: Type[];
@@ -113,14 +104,14 @@ function setTypeOverride (sectionTypes: OverrideModuleType, types: Type[]): void
* Apply module-specific type overrides (always be done as part of toV14)
* @internal
**/
function convertCalls (registry: Registry, types: TypeSpec[], modName: Text, calls: FunctionMetadataV13[], sectionTypes: OverrideModuleType): PalletCallMetadataV14 {
function convertCalls (registry: Registry, modName: Text, calls: FunctionMetadataV13[], sectionTypes: OverrideModuleType): PalletCallMetadataV14 {
const variants = calls.map(({ args, docs, name }, index): SiVariant => {
setTypeOverride(sectionTypes, args.map(({ type }) => type));
return registry.createType('SiVariant', {
docs,
fields: args.map(({ name, type }) =>
registry.createType('SiField', { name, type: compatType(types, type) })
registry.createType('SiField', { name, type: compatType(registry.compatSpecs, type) })
),
index,
name
@@ -128,7 +119,7 @@ function convertCalls (registry: Registry, types: TypeSpec[], modName: Text, cal
});
return registry.createType('PalletCallMetadataV14', {
type: variantType(modName, 'Call', types, variants)
type: variantType(modName, 'Call', registry.compatSpecs, variants)
});
}
@@ -136,14 +127,14 @@ function convertCalls (registry: Registry, types: TypeSpec[], modName: Text, cal
* Apply module-specific type overrides (always be done as part of toV14)
* @internal
*/
function convertConstants (registry: Registry, types: TypeSpec[], constants: ModuleConstantMetadataV13[], sectionTypes: OverrideModuleType): PalletConstantMetadataV14[] {
function convertConstants (registry: Registry, constants: ModuleConstantMetadataV13[], sectionTypes: OverrideModuleType): PalletConstantMetadataV14[] {
return constants.map(({ docs, name, type, value }): PalletConstantMetadataV14 => {
setTypeOverride(sectionTypes, [type]);
return registry.createType('PalletConstantMetadataV14', {
docs,
name,
type: compatType(types, type),
type: compatType(registry.compatSpecs, type),
value
});
});
@@ -154,7 +145,7 @@ function convertConstants (registry: Registry, types: TypeSpec[], constants: Mod
* @internal
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function convertErrors (registry: Registry, types: TypeSpec[], modName: Text, errors: ErrorMetadataV13[], _sectionTypes: OverrideModuleType): PalletErrorMetadataV14 {
function convertErrors (registry: Registry, modName: Text, errors: ErrorMetadataV13[], _sectionTypes: OverrideModuleType): PalletErrorMetadataV14 {
const variants = errors.map(({ docs, name }, index): SiVariant =>
registry.createType('SiVariant', {
docs,
@@ -165,7 +156,7 @@ function convertErrors (registry: Registry, types: TypeSpec[], modName: Text, er
);
return registry.createType('PalletErrorMetadataV14', {
type: variantType(modName, 'Error', types, variants)
type: variantType(modName, 'Error', registry.compatSpecs, variants)
});
}
@@ -173,14 +164,14 @@ function convertErrors (registry: Registry, types: TypeSpec[], modName: Text, er
* Apply module-specific type overrides (always be done as part of toV14)
* @internal
**/
function convertEvents (registry: Registry, types: TypeSpec[], modName: Text, events: EventMetadataV13[], sectionTypes: OverrideModuleType): PalletEventMetadataV14 {
function convertEvents (registry: Registry, modName: Text, events: EventMetadataV13[], sectionTypes: OverrideModuleType): PalletEventMetadataV14 {
const variants = events.map(({ args, docs, name }, index): SiVariant => {
setTypeOverride(sectionTypes, args);
return registry.createType('SiVariant', {
docs,
fields: args.map((t) =>
registry.createType('SiField', { type: compatType(types, t) })
registry.createType('SiField', { type: compatType(registry.compatSpecs, t) })
),
index,
name
@@ -188,20 +179,20 @@ function convertEvents (registry: Registry, types: TypeSpec[], modName: Text, ev
});
return registry.createType('PalletEventMetadataV14', {
type: variantType(modName, 'Event', types, variants)
type: variantType(modName, 'Event', registry.compatSpecs, variants)
});
}
function createMapEntry (registry: Registry, sectionTypes: OverrideModuleType, types: TypeSpec[], { hashers, keys, value }: MapDef): StorageEntryTypeV14 {
function createMapEntry (registry: Registry, sectionTypes: OverrideModuleType, { hashers, keys, value }: MapDef): StorageEntryTypeV14 {
setTypeOverride(sectionTypes, [value, ...(Array.isArray(keys) ? keys : [keys])]);
return registry.createType('StorageEntryTypeV14', {
Map: {
hashers,
key: hashers.length === 1
? compatType(types, keys[0])
: (types.push({ def: { Tuple: keys.map((t) => compatType(types, t)) } }) - 1),
value: compatType(types, value)
? compatType(registry.compatSpecs, keys[0])
: (registry.compatSpecs.push({ def: { Tuple: keys.map((t) => compatType(registry.compatSpecs, t)) } }) - 1),
value: compatType(registry.compatSpecs, value)
}
});
}
@@ -210,7 +201,7 @@ function createMapEntry (registry: Registry, sectionTypes: OverrideModuleType, t
* Apply module-specific storage type overrides (always part of toV14)
* @internal
**/
function convertStorage (registry: Registry, types: TypeSpec[], { items, prefix }: StorageMetadataV13, sectionTypes: OverrideModuleType): PalletStorageMetadataV14 {
function convertStorage (registry: Registry, { items, prefix }: StorageMetadataV13, sectionTypes: OverrideModuleType): PalletStorageMetadataV14 {
return registry.createType('PalletStorageMetadataV14', {
items: items.map(({ docs, fallback, modifier, name, type }): StorageEntryMetadataV14 => {
let entryType: StorageEntryTypeV14;
@@ -221,12 +212,12 @@ function convertStorage (registry: Registry, types: TypeSpec[], { items, prefix
setTypeOverride(sectionTypes, [plain]);
entryType = registry.createType('StorageEntryTypeV14', {
Plain: compatType(types, plain)
Plain: compatType(registry.compatSpecs, plain)
});
} else if (type.isMap) {
const map = type.asMap;
entryType = createMapEntry(registry, sectionTypes, types, {
entryType = createMapEntry(registry, sectionTypes, {
hashers: [map.hasher],
keys: [map.key],
value: map.value
@@ -234,7 +225,7 @@ function convertStorage (registry: Registry, types: TypeSpec[], { items, prefix
} else if (type.isDoubleMap) {
const dm = type.asDoubleMap;
entryType = createMapEntry(registry, sectionTypes, types, {
entryType = createMapEntry(registry, sectionTypes, {
hashers: [dm.hasher, dm.key2Hasher],
keys: [dm.key1, dm.key2],
value: dm.value
@@ -242,7 +233,7 @@ function convertStorage (registry: Registry, types: TypeSpec[], { items, prefix
} else {
const nm = type.asNMap;
entryType = createMapEntry(registry, sectionTypes, types, {
entryType = createMapEntry(registry, sectionTypes, {
hashers: nm.hashers,
keys: nm.keyVec,
value: nm.value
@@ -263,7 +254,7 @@ function convertStorage (registry: Registry, types: TypeSpec[], { items, prefix
/** @internal */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function convertExtrinsic (registry: Registry, _types: TypeSpec[], { signedExtensions, version }: ExtrinsicMetadataV13): ExtrinsicMetadataV14 {
function convertExtrinsic (registry: Registry, { signedExtensions, version }: ExtrinsicMetadataV13): ExtrinsicMetadataV14 {
return registry.createType('ExtrinsicMetadataV14', {
signedExtensions: signedExtensions.map((identifier) => ({
identifier,
@@ -275,17 +266,17 @@ function convertExtrinsic (registry: Registry, _types: TypeSpec[], { signedExten
}
/** @internal */
function createPallet (registry: Registry, types: TypeSpec[], mod: ModuleMetadataV13, { calls, constants, errors, events, storage }: { calls: FunctionMetadataV13[] | null, constants: ModuleConstantMetadataV13[], errors: ErrorMetadataV13[] | null, events: EventMetadataV13[] | null, storage: StorageMetadataV13 | null }): PalletMetadataV14 {
function createPallet (registry: Registry, mod: ModuleMetadataV13, { calls, constants, errors, events, storage }: { calls: FunctionMetadataV13[] | null, constants: ModuleConstantMetadataV13[], errors: ErrorMetadataV13[] | null, events: EventMetadataV13[] | null, storage: StorageMetadataV13 | null }): PalletMetadataV14 {
const sectionTypes = getModuleTypes(registry, stringCamelCase(mod.name));
return registry.createType('PalletMetadataV14', {
calls: calls && convertCalls(registry, types, mod.name, calls, sectionTypes),
constants: convertConstants(registry, types, constants, sectionTypes),
errors: errors && convertErrors(registry, types, mod.name, errors, sectionTypes),
events: events && convertEvents(registry, types, mod.name, events, sectionTypes),
calls: calls && convertCalls(registry, mod.name, calls, sectionTypes),
constants: convertConstants(registry, constants, sectionTypes),
errors: errors && convertErrors(registry, mod.name, errors, sectionTypes),
events: events && convertEvents(registry, mod.name, events, sectionTypes),
index: mod.index,
name: mod.name,
storage: storage && convertStorage(registry, types, storage, sectionTypes)
storage: storage && convertStorage(registry, storage, sectionTypes)
});
}
@@ -294,15 +285,12 @@ function createPallet (registry: Registry, types: TypeSpec[], mod: ModuleMetadat
* @internal
**/
export function toV14 (registry: Registry, v13: MetadataV13, metaVersion: number): MetadataV14 {
// the types that we will pass
const types: TypeSpec[] = [];
compatType(types, 'Null'); // position 0 always has Null
compatType(registry.compatSpecs, 'Null'); // position 0 always has Null
registerOriginCaller(registry, v13.modules, metaVersion);
const extrinsic = convertExtrinsic(registry, types, v13.extrinsic);
const extrinsic = convertExtrinsic(registry, v13.extrinsic);
const pallets = v13.modules.map((mod) =>
createPallet(registry, types, mod, {
createPallet(registry, mod, {
calls: mod.calls.unwrapOr(null),
constants: mod.constants,
errors: mod.errors.length ? mod.errors : null,
@@ -314,7 +302,7 @@ export function toV14 (registry: Registry, v13: MetadataV13, metaVersion: number
return registry.createType('MetadataV14', {
extrinsic,
lookup: {
types: types.map((type, id) =>
types: registry.compatSpecs.map((type, id) =>
registry.createType('PortableType', { id, type })
)
},
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/types', version: '6.0.2' };
export const packageInfo = { name: '@polkadot/types', version: '6.0.4' };
+2 -1
View File
@@ -9,6 +9,7 @@ import type { StorageEntry } from './types';
import { assert, isFunction, isString, isU8a } from '@polkadot/util';
import { getSiName } from '../metadata/util';
import { Bytes } from './Bytes';
interface Decoded {
@@ -42,7 +43,7 @@ export function unwrapStorageSi (type: StorageEntryTypeLatest): SiLookupTypeId {
/** @internal */
export function unwrapStorageType (registry: Registry, type: StorageEntryTypeLatest, isOptional?: boolean): keyof InterfaceTypes {
const outputType = registry.lookup.getTypeDef(unwrapStorageSi(type)).type;
const outputType = getSiName(registry.lookup, unwrapStorageSi(type));
return isOptional
? `Option<${outputType}>` as keyof InterfaceTypes
+13 -1
View File
@@ -7,7 +7,7 @@ import type { CreateOptions } from '../create/types';
import type { ExtDef } from '../extrinsic/signedExtensions/types';
import type { MetadataLatest, PortableRegistry } from '../interfaces/metadata';
import type { CodecHash, Hash } from '../interfaces/runtime';
import type { SiField, SiLookupTypeId } from '../interfaces/scaleInfo';
import type { SiField, SiLookupTypeId, SiVariant } from '../interfaces/scaleInfo';
import type { ChainProperties } from '../interfaces/system';
import type { Metadata } from '../metadata';
import type { CallFunction } from './calls';
@@ -47,6 +47,17 @@ export interface RegistryError {
section: string;
}
export interface TypeSpec {
def: {
HistoricMetaCompat?: string;
Tuple?: number[];
Variant?: {
variants: SiVariant[];
}
},
path?: string[];
}
export interface OverrideVersionedType {
// min (v >= min) and max (v <= max)
minmax: [number | undefined | null, number | undefined | null] | [number?, number?] | (number | undefined | null)[];
@@ -112,6 +123,7 @@ export interface Registry {
readonly unknownTypes: string[];
readonly signedExtensions: string[];
compatSpecs: TypeSpec[];
createdAtHash?: Hash;
findMetaCall (callIndex: Uint8Array): CallFunction;
+27 -27
View File
@@ -1854,40 +1854,40 @@ __metadata:
resolution: "@polkadot/api-contract@workspace:packages/api-contract"
dependencies:
"@babel/runtime": ^7.15.4
"@polkadot/api": 6.0.2
"@polkadot/types": 6.0.2
"@polkadot/api": 6.0.4
"@polkadot/types": 6.0.4
"@polkadot/util": ^7.4.1
rxjs: ^7.3.0
languageName: unknown
linkType: soft
"@polkadot/api-derive@6.0.2, @polkadot/api-derive@workspace:packages/api-derive":
"@polkadot/api-derive@6.0.4, @polkadot/api-derive@workspace:packages/api-derive":
version: 0.0.0-use.local
resolution: "@polkadot/api-derive@workspace:packages/api-derive"
dependencies:
"@babel/runtime": ^7.15.4
"@polkadot/api": 6.0.2
"@polkadot/api": 6.0.4
"@polkadot/keyring": ^7.4.1
"@polkadot/rpc-core": 6.0.2
"@polkadot/rpc-provider": 6.0.2
"@polkadot/types": 6.0.2
"@polkadot/rpc-core": 6.0.4
"@polkadot/rpc-provider": 6.0.4
"@polkadot/types": 6.0.4
"@polkadot/util": ^7.4.1
"@polkadot/util-crypto": ^7.4.1
rxjs: ^7.3.0
languageName: unknown
linkType: soft
"@polkadot/api@6.0.2, @polkadot/api@workspace:packages/api":
"@polkadot/api@6.0.4, @polkadot/api@workspace:packages/api":
version: 0.0.0-use.local
resolution: "@polkadot/api@workspace:packages/api"
dependencies:
"@babel/runtime": ^7.15.4
"@polkadot/api-derive": 6.0.2
"@polkadot/api-derive": 6.0.4
"@polkadot/keyring": ^7.4.1
"@polkadot/rpc-core": 6.0.2
"@polkadot/rpc-provider": 6.0.2
"@polkadot/types": 6.0.2
"@polkadot/types-known": 6.0.2
"@polkadot/rpc-core": 6.0.4
"@polkadot/rpc-provider": 6.0.4
"@polkadot/types": 6.0.4
"@polkadot/types-known": 6.0.4
"@polkadot/util": ^7.4.1
"@polkadot/util-crypto": ^7.4.1
eventemitter3: ^4.0.7
@@ -2012,26 +2012,26 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/rpc-core@6.0.2, @polkadot/rpc-core@workspace:packages/rpc-core":
"@polkadot/rpc-core@6.0.4, @polkadot/rpc-core@workspace:packages/rpc-core":
version: 0.0.0-use.local
resolution: "@polkadot/rpc-core@workspace:packages/rpc-core"
dependencies:
"@babel/runtime": ^7.15.4
"@polkadot/keyring": ^7.4.1
"@polkadot/rpc-provider": 6.0.2
"@polkadot/types": 6.0.2
"@polkadot/rpc-provider": 6.0.4
"@polkadot/types": 6.0.4
"@polkadot/util": ^7.4.1
rxjs: ^7.3.0
languageName: unknown
linkType: soft
"@polkadot/rpc-provider@6.0.2, @polkadot/rpc-provider@workspace:packages/rpc-provider":
"@polkadot/rpc-provider@6.0.4, @polkadot/rpc-provider@workspace:packages/rpc-provider":
version: 0.0.0-use.local
resolution: "@polkadot/rpc-provider@workspace:packages/rpc-provider"
dependencies:
"@babel/runtime": ^7.15.4
"@polkadot/keyring": ^7.4.1
"@polkadot/types": 6.0.2
"@polkadot/types": 6.0.4
"@polkadot/util": ^7.4.1
"@polkadot/util-crypto": ^7.4.1
"@polkadot/x-fetch": ^7.4.1
@@ -2059,10 +2059,10 @@ __metadata:
"@babel/core": ^7.15.5
"@babel/register": ^7.15.3
"@babel/runtime": ^7.15.4
"@polkadot/api": 6.0.2
"@polkadot/rpc-provider": 6.0.2
"@polkadot/types": 6.0.2
"@polkadot/types-support": 6.0.2
"@polkadot/api": 6.0.4
"@polkadot/rpc-provider": 6.0.4
"@polkadot/types": 6.0.4
"@polkadot/types-support": 6.0.4
"@polkadot/util": ^7.4.1
"@types/websocket": ^1.0.4
"@types/yargs": ^17.0.2
@@ -2078,18 +2078,18 @@ __metadata:
languageName: unknown
linkType: soft
"@polkadot/types-known@6.0.2, @polkadot/types-known@workspace:packages/types-known":
"@polkadot/types-known@6.0.4, @polkadot/types-known@workspace:packages/types-known":
version: 0.0.0-use.local
resolution: "@polkadot/types-known@workspace:packages/types-known"
dependencies:
"@babel/runtime": ^7.15.4
"@polkadot/networks": ^7.4.1
"@polkadot/types": 6.0.2
"@polkadot/types": 6.0.4
"@polkadot/util": ^7.4.1
languageName: unknown
linkType: soft
"@polkadot/types-support@6.0.2, @polkadot/types-support@workspace:packages/types-support":
"@polkadot/types-support@6.0.4, @polkadot/types-support@workspace:packages/types-support":
version: 0.0.0-use.local
resolution: "@polkadot/types-support@workspace:packages/types-support"
dependencies:
@@ -2098,13 +2098,13 @@ __metadata:
languageName: unknown
linkType: soft
"@polkadot/types@6.0.2, @polkadot/types@workspace:packages/types":
"@polkadot/types@6.0.4, @polkadot/types@workspace:packages/types":
version: 0.0.0-use.local
resolution: "@polkadot/types@workspace:packages/types"
dependencies:
"@babel/runtime": ^7.15.4
"@polkadot/keyring": ^7.4.1
"@polkadot/types-support": 6.0.2
"@polkadot/types-support": 6.0.4
"@polkadot/util": ^7.4.1
"@polkadot/util-crypto": ^7.4.1
"@types/bn.js": ^4.11.6