Compare commits

..
26 Commits
Author SHA1 Message Date
Github Actions 878f631745 [CI Skip] release/stable 6.1.1
skip-checks: true
2021-09-27 05:54:41 +00:00
Jaco d7753839a2 6.1.1 (#3994)
* 6.1.1

* bumps
2021-09-27 07:36:47 +02:00
Github Actions fc74d88bbb [CI Skip] release/beta 6.0.6-4
skip-checks: true
2021-09-24 08:24:35 +00:00
HackFisher 47bbeee14b fix OutboundLaneData types (#3992) 2021-09-24 10:05:56 +02:00
Github Actions ba01620ba1 [CI Skip] release/beta 6.0.6-3
skip-checks: true
2021-09-23 09:30:55 +00:00
Jaco 6e66387a8d CHANGELOG (#3986) 2021-09-23 11:10:10 +02:00
Github Actions c58687b3c6 [CI Skip] release/beta 6.0.6-2
skip-checks: true
2021-09-22 09:22:01 +00:00
Jaco 2801088b0a Scale-info v0 -> v1 conversion (as needed by contracts) (#3987)
* Scale-info v0 -> v1 conversion (as needed by contracts)

* Renames

* V1 types same as v0 where applicable
2021-09-22 11:01:39 +02:00
Github Actions fc5af92a03 [CI Skip] release/beta 6.0.6-1
skip-checks: true
2021-09-22 04:07:20 +00:00
Furqan A 8f8bb2aa23 fix: fixed 404 to the docs from the api readme (#3985) 2021-09-22 06:48:18 +03:00
Github Actions 3f69b3fc73 [CI Skip] release/beta 6.0.6-0
skip-checks: true
2021-09-20 18:48:01 +00:00
Jaco 4ea170a83a Add childstate_getStorageEntries RPC (#3980)
* Add `childstate_getStorageEntries` RPC

* Remove extra ,
2021-09-20 20:33:30 +02:00
Github Actions 26649c429a [CI Skip] release/stable 6.0.5
skip-checks: true
2021-09-20 13:57:16 +00:00
Jaco 7c57778389 6.0.5 (#3977) 2021-09-20 15:38:54 +02:00
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
Github Actions f6e50f14b5 [CI Skip] release/stable 6.0.2
skip-checks: true
2021-09-18 09:12:35 +00:00
Jaco caec49a8dc Fix Substrate key generation (#3968)
* Fix Substrate key generation

* 6.0.2
2021-09-18 10:56:35 +02:00
55 changed files with 1262 additions and 1585 deletions
+5
View File
@@ -29,3 +29,8 @@
5.5.2
5.8.2
5.8.3
6.0.2
6.0.3
6.0.4
6.0.5
+52
View File
@@ -1,5 +1,57 @@
# CHANGELOG
## 6.1.1 Sep 27, 2021
Contributed:
- Adjust bridges `OutboundLaneData` type (Thanks to https://github.com/HackFisher)
- Fix README 404 (Thanks to https://github.com/nblogist)
Changes:
- Add `childstate_getStorageEntries` RPC
- Allow for scale-info v0 -> v1 conversion
## 6.0.5 Sep 20, 2021
Upgrade priority: Low. Recommended for all users on 6.0.4 using `api.query.*.*.at` calls
Changes:
- Revert cross-registry (now-inactive) change introduced in 6.0.3
- Ensure `Option` is correctly imported for TS query generation
## 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
Changes:
- Fix `api.query.substrate.*` key generation
## 6.0.1 Sep 18, 2021
Upgrade priority: Low. Recommended for users of the latest Substrate/Polkadot with Metadata v14.
+3 -3
View File
@@ -29,12 +29,12 @@
"@babel/core": "^7.15.5",
"@babel/register": "^7.15.3",
"@babel/runtime": "^7.15.4",
"@polkadot/dev": "^0.62.67",
"@polkadot/dev": "^0.62.68",
"@polkadot/ts": "^0.4.8",
"@polkadot/typegen": "workspace:packages/typegen",
"@types/jest": "^27.0.1",
"@types/jest": "^27.0.2",
"copyfiles": "^2.4.1"
},
"version": "6.0.1",
"version": "6.1.1",
"packageManager": "yarn@3.0.1"
}
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-contract",
"version": "6.0.1",
"version": "6.1.1",
"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.1",
"@polkadot/types": "6.0.1",
"@polkadot/api": "6.1.1",
"@polkadot/types": "6.1.1",
"@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.1' };
export const packageInfo = { name: '@polkadot/api-contract', version: '6.1.1' };
+5 -5
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-derive",
"version": "6.0.1",
"version": "6.1.1",
"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.1",
"@polkadot/rpc-core": "6.0.1",
"@polkadot/types": "6.0.1",
"@polkadot/api": "6.1.1",
"@polkadot/rpc-core": "6.1.1",
"@polkadot/types": "6.1.1",
"@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.1"
"@polkadot/rpc-provider": "6.1.1"
}
}
+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.1' };
export const packageInfo = { name: '@polkadot/api-derive', version: '6.1.1' };
+4 -4
View File
@@ -7,13 +7,13 @@ The API wrappers provide a standard interface for use -
- A static `.create(<optional ApiOptions>)` that returns an API instance when connected, decorated and ready-to use. ApiOptions can include an optional WsProvider and optional custom type definitions `{ provider: <Optional WsProvider>, types: <Optional RegistryTypes> }`.
- The above is just a wrapper for `new Api(<optional ApiOptions>) `, exposing the `isReady` getter
- `api.rpc.<section>.<method>` provides access to actual RPC calls, be it for queries, submission or retrieving chain information
- [RPC (node interface)](https://polkadot.js.org/docs/substrate/rpc.html)
- [RPC (node interface)](https://polkadot.js.org/docs/substrate/rpc)
- `api.query.<section>.<method>` provides access to chain state queries. These are dynamically populated based on what the runtime provides
- [Storage chain state (runtime node interface)](https://polkadot.js.org/docs/substrate/storage.html)
- [Storage chain state (runtime node interface)](https://polkadot.js.org/docs/substrate/storage)
- `api.tx.<section>.<method>` provides the ability to create a transaction, like chain state, this list is populated from a runtime query
- [Extrinsics (runtime node interface)](https://polkadot.js.org/docs/substrate/extrinsics.html)
- [Extrinsics (runtime node interface)](https://polkadot.js.org/docs/substrate/extrinsics)
- `api.consts.<section>.<constant>` provides access to the module constants (parameter types).
- [Constants (runtime node interface)](https://polkadot.js.org/docs/substrate/constants.html)
- [Constants (runtime node interface)](https://polkadot.js.org/docs/substrate/constants)
## API Selection
+6 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api",
"version": "6.0.1",
"version": "6.1.1",
"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.1",
"@polkadot/api-derive": "6.1.1",
"@polkadot/keyring": "^7.4.1",
"@polkadot/rpc-core": "6.0.1",
"@polkadot/rpc-provider": "6.0.1",
"@polkadot/types": "6.0.1",
"@polkadot/types-known": "6.0.1",
"@polkadot/rpc-core": "6.1.1",
"@polkadot/rpc-provider": "6.1.1",
"@polkadot/types": "6.1.1",
"@polkadot/types-known": "6.1.1",
"@polkadot/util": "^7.4.1",
"@polkadot/util-crypto": "^7.4.1",
"eventemitter3": "^4.0.7",
+4
View File
@@ -113,6 +113,10 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
* Returns a child storage entry at a specific block state
**/
getStorage: AugmentedRpc<(childKey: PrefixedStorageKey | string | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: Hash | string | Uint8Array) => Observable<Option<StorageData>>>;
/**
* Returns child storage entries for multiple keys at a specific block state
**/
getStorageEntries: AugmentedRpc<(childKey: PrefixedStorageKey | string | Uint8Array, keys: Vec<StorageKey> | (StorageKey | string | Uint8Array | any)[], at?: Hash | string | Uint8Array) => Observable<Vec<Option<StorageData>>>>;
/**
* Returns the hash of a child storage entry at a block state
**/
+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.1' };
export const packageInfo = { name: '@polkadot/api', version: '6.1.1' };
+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.1",
"version": "6.1.1",
"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.1",
"@polkadot/types": "6.0.1",
"@polkadot/rpc-provider": "6.1.1",
"@polkadot/types": "6.1.1",
"@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.1' };
export const packageInfo = { name: '@polkadot/rpc-core', version: '6.1.1' };
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/rpc-provider",
"version": "6.0.1",
"version": "6.1.1",
"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.1",
"@polkadot/types": "6.1.1",
"@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.1",
"@polkadot/types": "6.1.1",
"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.1' };
export const packageInfo = { name: '@polkadot/rpc-provider', version: '6.1.1' };
+7 -7
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/typegen",
"version": "6.0.1",
"version": "6.1.1",
"type": "module",
"description": "Type generation scripts",
"main": "index.js",
@@ -29,17 +29,17 @@
"@babel/core": "^7.15.5",
"@babel/register": "^7.15.3",
"@babel/runtime": "^7.15.4",
"@polkadot/api": "6.0.1",
"@polkadot/rpc-provider": "6.0.1",
"@polkadot/types": "6.0.1",
"@polkadot/types-support": "6.0.1",
"@polkadot/api": "6.1.1",
"@polkadot/rpc-provider": "6.1.1",
"@polkadot/types": "6.1.1",
"@polkadot/types-support": "6.1.1",
"@polkadot/util": "^7.4.1",
"handlebars": "^4.7.7",
"websocket": "^1.0.34",
"yargs": "^17.1.1"
"yargs": "^17.2.1"
},
"devDependencies": {
"@types/websocket": "^1.0.4",
"@types/yargs": "^17.0.2"
"@types/yargs": "^17.0.3"
}
}
+2 -1
View File
@@ -198,7 +198,8 @@ function generateLookupDefs (registry: Registry, filtered: [PortableType, TypeDe
].map(([n, t]) => `${n}: ${t}`),
docs
};
})
}),
headerType: 'defs'
});
});
}
+9 -22
View File
@@ -21,31 +21,15 @@ 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);
setImports(allDefs, imports, [typeDef.lookupName || typeDef.type]);
setImports(allDefs, imports, [
typeDef.lookupName || typeDef.type,
storageEntry.modifier.isOptional
? 'Option'
: null
]);
return [storageEntry.modifier.isOptional, '', '', formatType(registry, allDefs, outputType, imports)];
} else if (storageEntry.type.isMap) {
@@ -59,6 +43,9 @@ function entrySignature (lookup: PortableRegistry, allDefs: Record<string, Modul
setImports(allDefs, imports, [
...similarTypes.reduce<string[]>((all, t) => all.concat(t), []),
storageEntry.modifier.isOptional
? 'Option'
: null,
defValue.lookupName
? undefined
: defValue.type
+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.1' };
export const packageInfo = { name: '@polkadot/typegen', version: '6.1.1' };
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/types-known",
"version": "6.0.1",
"version": "6.1.1",
"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.1",
"@polkadot/types": "6.1.1",
"@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.1' };
export const packageInfo = { name: '@polkadot/types-known', version: '6.1.1' };
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/types-support",
"version": "6.0.1",
"version": "6.1.1",
"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.1' };
export const packageInfo = { name: '@polkadot/types-support', version: '6.1.1' };
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/types",
"version": "6.0.1",
"version": "6.1.1",
"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.1",
"@polkadot/types-support": "6.1.1",
"@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 */
+19 -2
View File
@@ -32,7 +32,7 @@ import type { AuthorityIndex, AuthorityList, AuthoritySet, AuthoritySetChange, A
import type { IdentityFields, IdentityInfo, IdentityInfoAdditional, IdentityInfoTo198, IdentityJudgement, RegistrarIndex, RegistrarInfo, Registration, RegistrationJudgement, RegistrationTo198 } from '@polkadot/types/interfaces/identity';
import type { AuthIndex, AuthoritySignature, Heartbeat, HeartbeatTo244, OpaqueMultiaddr, OpaqueNetworkState, OpaquePeerId } from '@polkadot/types/interfaces/imOnline';
import type { CallIndex, LotteryConfig } from '@polkadot/types/interfaces/lottery';
import type { ErrorMetadataLatest, ErrorMetadataV10, ErrorMetadataV11, ErrorMetadataV12, ErrorMetadataV13, ErrorMetadataV14, ErrorMetadataV9, EventMetadataLatest, EventMetadataV10, EventMetadataV11, EventMetadataV12, EventMetadataV13, EventMetadataV14, EventMetadataV9, ExtrinsicMetadataLatest, ExtrinsicMetadataV11, ExtrinsicMetadataV12, ExtrinsicMetadataV13, ExtrinsicMetadataV14, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV10, FunctionArgumentMetadataV11, FunctionArgumentMetadataV12, FunctionArgumentMetadataV13, FunctionArgumentMetadataV14, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV10, FunctionMetadataV11, FunctionMetadataV12, FunctionMetadataV13, FunctionMetadataV14, FunctionMetadataV9, MetadataAll, MetadataLatest, MetadataV10, MetadataV11, MetadataV12, MetadataV13, MetadataV14, MetadataV9, ModuleConstantMetadataV10, ModuleConstantMetadataV11, ModuleConstantMetadataV12, ModuleConstantMetadataV13, ModuleConstantMetadataV9, ModuleMetadataV10, ModuleMetadataV11, ModuleMetadataV12, ModuleMetadataV13, ModuleMetadataV9, PalletCallMetadataLatest, PalletCallMetadataV14, PalletConstantMetadataLatest, PalletConstantMetadataV14, PalletErrorMetadataLatest, PalletErrorMetadataV14, PalletEventMetadataLatest, PalletEventMetadataV14, PalletMetadataLatest, PalletMetadataV14, PalletStorageMetadataLatest, PalletStorageMetadataV14, PortableRegistry, PortableType, SignedExtensionMetadataLatest, SignedExtensionMetadataV14, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV11, StorageEntryMetadataV12, StorageEntryMetadataV13, StorageEntryMetadataV14, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV11, StorageEntryModifierV12, StorageEntryModifierV13, StorageEntryModifierV14, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV11, StorageEntryTypeV12, StorageEntryTypeV13, StorageEntryTypeV14, StorageEntryTypeV9, StorageHasher, StorageHasherV10, StorageHasherV11, StorageHasherV12, StorageHasherV13, StorageHasherV14, StorageHasherV9, StorageMetadataV10, StorageMetadataV11, StorageMetadataV12, StorageMetadataV13, StorageMetadataV9 } from '@polkadot/types/interfaces/metadata';
import type { ErrorMetadataLatest, ErrorMetadataV10, ErrorMetadataV11, ErrorMetadataV12, ErrorMetadataV13, ErrorMetadataV14, ErrorMetadataV9, EventMetadataLatest, EventMetadataV10, EventMetadataV11, EventMetadataV12, EventMetadataV13, EventMetadataV14, EventMetadataV9, ExtrinsicMetadataLatest, ExtrinsicMetadataV11, ExtrinsicMetadataV12, ExtrinsicMetadataV13, ExtrinsicMetadataV14, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV10, FunctionArgumentMetadataV11, FunctionArgumentMetadataV12, FunctionArgumentMetadataV13, FunctionArgumentMetadataV14, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV10, FunctionMetadataV11, FunctionMetadataV12, FunctionMetadataV13, FunctionMetadataV14, FunctionMetadataV9, MetadataAll, MetadataLatest, MetadataV10, MetadataV11, MetadataV12, MetadataV13, MetadataV14, MetadataV9, ModuleConstantMetadataV10, ModuleConstantMetadataV11, ModuleConstantMetadataV12, ModuleConstantMetadataV13, ModuleConstantMetadataV9, ModuleMetadataV10, ModuleMetadataV11, ModuleMetadataV12, ModuleMetadataV13, ModuleMetadataV9, PalletCallMetadataLatest, PalletCallMetadataV14, PalletConstantMetadataLatest, PalletConstantMetadataV14, PalletErrorMetadataLatest, PalletErrorMetadataV14, PalletEventMetadataLatest, PalletEventMetadataV14, PalletMetadataLatest, PalletMetadataV14, PalletStorageMetadataLatest, PalletStorageMetadataV14, PortableRegistry, PortableRegistryV14, PortableType, PortableTypeV14, SignedExtensionMetadataLatest, SignedExtensionMetadataV14, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV11, StorageEntryMetadataV12, StorageEntryMetadataV13, StorageEntryMetadataV14, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV11, StorageEntryModifierV12, StorageEntryModifierV13, StorageEntryModifierV14, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV11, StorageEntryTypeV12, StorageEntryTypeV13, StorageEntryTypeV14, StorageEntryTypeV9, StorageHasher, StorageHasherV10, StorageHasherV11, StorageHasherV12, StorageHasherV13, StorageHasherV14, StorageHasherV9, StorageMetadataV10, StorageMetadataV11, StorageMetadataV12, StorageMetadataV13, StorageMetadataV9 } from '@polkadot/types/interfaces/metadata';
import type { MmrLeafProof } from '@polkadot/types/interfaces/mmr';
import type { StorageKind } from '@polkadot/types/interfaces/offchain';
import type { DeferredOffenceOf, Kind, OffenceDetails, Offender, OpaqueTimeSlot, ReportIdOf, Reporter } from '@polkadot/types/interfaces/offences';
@@ -44,7 +44,7 @@ import type { AccountStatus, AccountValidity } from '@polkadot/types/interfaces/
import type { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery';
import type { RpcMethods } from '@polkadot/types/interfaces/rpc';
import type { AccountId, AccountId20, AccountId32, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, BlockNumberFor, BlockNumberOf, Call, CallHash, CallHashOf, ChangesTrieConfiguration, ChangesTrieSignal, CodecHash, Consensus, ConsensusEngineId, Digest, DigestItem, EncodedJustification, ExtrinsicsWeight, Fixed128, Fixed64, FixedI128, FixedI64, FixedU128, FixedU64, H1024, H128, H160, H2048, H256, H32, H512, H64, Hash, Header, HeaderPartial, I32F32, Index, IndicesLookupSource, Justification, Justifications, KeyTypeId, KeyValue, LockIdentifier, LookupSource, LookupTarget, ModuleId, Moment, MultiAddress, MultiSigner, OpaqueCall, Origin, OriginCaller, PalletId, PalletVersion, PalletsOrigin, Pays, PerU16, Perbill, Percent, Permill, Perquintill, Phantom, PhantomData, PreRuntime, Releases, RuntimeDbWeight, Seal, SealV0, SignedBlock, SignedBlockWithJustification, SignedBlockWithJustifications, Slot, StorageData, StorageProof, TransactionInfo, TransactionPriority, TransactionStorageProof, U32F32, ValidatorId, ValidatorIdOf, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime';
import type { Si0Field, Si0LookupTypeId, Si0Path, Si0Type, Si0TypeDef, Si0TypeDefArray, Si0TypeDefBitSequence, Si0TypeDefCompact, Si0TypeDefComposite, Si0TypeDefPhantom, Si0TypeDefPrimitive, Si0TypeDefSequence, Si0TypeDefTuple, Si0TypeDefVariant, Si0TypeParameter, Si0Variant, SiField, SiLookupTypeId, SiPath, SiType, SiTypeDef, SiTypeDefArray, SiTypeDefBitSequence, SiTypeDefCompact, SiTypeDefComposite, SiTypeDefPrimitive, SiTypeDefSequence, SiTypeDefTuple, SiTypeDefVariant, SiTypeParameter, SiVariant } from '@polkadot/types/interfaces/scaleInfo';
import type { Si0Field, Si0LookupTypeId, Si0Path, Si0Type, Si0TypeDef, Si0TypeDefArray, Si0TypeDefBitSequence, Si0TypeDefCompact, Si0TypeDefComposite, Si0TypeDefPhantom, Si0TypeDefPrimitive, Si0TypeDefSequence, Si0TypeDefTuple, Si0TypeDefVariant, Si0TypeParameter, Si0Variant, Si1Field, Si1LookupTypeId, Si1Path, Si1Type, Si1TypeDef, Si1TypeDefArray, Si1TypeDefBitSequence, Si1TypeDefCompact, Si1TypeDefComposite, Si1TypeDefPrimitive, Si1TypeDefSequence, Si1TypeDefTuple, Si1TypeDefVariant, Si1TypeParameter, Si1Variant, SiField, SiLookupTypeId, SiPath, SiType, SiTypeDef, SiTypeDefArray, SiTypeDefBitSequence, SiTypeDefCompact, SiTypeDefComposite, SiTypeDefPrimitive, SiTypeDefSequence, SiTypeDefTuple, SiTypeDefVariant, SiTypeParameter, SiVariant } from '@polkadot/types/interfaces/scaleInfo';
import type { Period, Priority, SchedulePeriod, SchedulePriority, Scheduled, ScheduledTo254, TaskAddress } from '@polkadot/types/interfaces/scheduler';
import type { BeefyKey, FullIdentification, IdentificationTuple, Keys, MembershipProof, SessionIndex, SessionKeys1, SessionKeys10, SessionKeys10B, SessionKeys2, SessionKeys3, SessionKeys4, SessionKeys5, SessionKeys6, SessionKeys6B, SessionKeys7, SessionKeys7B, SessionKeys8, SessionKeys8B, SessionKeys9, SessionKeys9B, ValidatorCount } from '@polkadot/types/interfaces/session';
import type { Bid, BidKind, SocietyJudgement, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society';
@@ -676,7 +676,9 @@ declare module '@polkadot/types/types/registry' {
PhragmenScore: PhragmenScore;
Points: Points;
PortableRegistry: PortableRegistry;
PortableRegistryV14: PortableRegistryV14;
PortableType: PortableType;
PortableTypeV14: PortableTypeV14;
Precommits: Precommits;
PrefabWasmModule: PrefabWasmModule;
PrefixedStorageKey: PrefixedStorageKey;
@@ -813,6 +815,21 @@ declare module '@polkadot/types/types/registry' {
Si0TypeDefVariant: Si0TypeDefVariant;
Si0TypeParameter: Si0TypeParameter;
Si0Variant: Si0Variant;
Si1Field: Si1Field;
Si1LookupTypeId: Si1LookupTypeId;
Si1Path: Si1Path;
Si1Type: Si1Type;
Si1TypeDef: Si1TypeDef;
Si1TypeDefArray: Si1TypeDefArray;
Si1TypeDefBitSequence: Si1TypeDefBitSequence;
Si1TypeDefCompact: Si1TypeDefCompact;
Si1TypeDefComposite: Si1TypeDefComposite;
Si1TypeDefPrimitive: Si1TypeDefPrimitive;
Si1TypeDefSequence: Si1TypeDefSequence;
Si1TypeDefTuple: Si1TypeDefTuple;
Si1TypeDefVariant: Si1TypeDefVariant;
Si1TypeParameter: Si1TypeParameter;
Si1Variant: Si1Variant;
SiField: SiField;
Signature: Signature;
SignedAvailabilityBitfield: SignedAvailabilityBitfield;
@@ -1,19 +1,18 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Vec } from '../codec/Vec';
import type { PortableType } from '../interfaces/metadata';
import type { SiField, SiLookupTypeId, SiPath, SiType, SiTypeDefArray, SiTypeDefBitSequence, SiTypeDefCompact, SiTypeDefComposite, SiTypeDefSequence, SiTypeDefTuple, SiTypeDefVariant, SiTypeParameter, SiVariant } from '../interfaces/scaleInfo';
import type { Text } from '../primitive/Text';
import type { Type } from '../primitive/Type';
import type { Registry, TypeDef } from '../types';
import type { Vec } from '../../codec';
import type { PortableType } from '../../interfaces/metadata';
import type { SiField, SiLookupTypeId, SiPath, SiType, SiTypeDefArray, SiTypeDefBitSequence, SiTypeDefCompact, SiTypeDefComposite, SiTypeDefSequence, SiTypeDefTuple, SiTypeDefVariant, SiTypeParameter, SiVariant } from '../../interfaces/scaleInfo';
import type { Text, Type } from '../../primitive';
import type { Registry, TypeDef } from '../../types';
import { assert, isNumber, isString, stringCamelCase, stringify, stringUpperFirst } from '@polkadot/util';
import { Struct } from '../codec/Struct';
import { withTypeString } from '../create/encodeTypes';
import { getTypeDef } from '../create/getTypeDef';
import { TypeDefInfo } from '../types';
import { Struct } from '../../codec/Struct';
import { withTypeString } from '../../create/encodeTypes';
import { getTypeDef } from '../../create/getTypeDef';
import { TypeDefInfo } from '../../types';
// Just a placeholder for a type.unrwapOr()
const TYPE_UNWRAP = { toNumber: () => -1 };
@@ -0,0 +1,5 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { GenericPortableRegistry } from './PortableRegistry';
export { toV1 as convertSiV0toV1 } from './toV1';
@@ -0,0 +1,133 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { PortableType, Si0Field, Si0LookupTypeId, Si0Path, Si0Type, Si0TypeDefArray, Si0TypeDefBitSequence, Si0TypeDefComposite, Si0TypeDefPrimitive, Si0TypeDefSequence, Si0TypeDefVariant, Si1Field, Si1TypeDef } from '../../interfaces';
import type { Registry } from '../../types';
function convertArray (registry: Registry, { len, type }: Si0TypeDefArray): Si1TypeDef {
return registry.createType('Si1TypeDef', {
Array: {
len,
type: type.toNumber()
}
});
}
function convertBitSequence (registry: Registry, { bitOrderType, bitStoreType }: Si0TypeDefBitSequence): Si1TypeDef {
return registry.createType('Si1TypeDef', {
BitSequence: {
bitOrderType: bitOrderType.toNumber(),
bitStoreType: bitStoreType.toNumber()
}
});
}
function convertCompact (registry: Registry, { type }: Si0TypeDefSequence): Si1TypeDef {
return registry.createType('Si1TypeDef', {
Compact: {
type: type.toNumber()
}
});
}
function convertComposite (registry: Registry, { fields }: Si0TypeDefComposite): Si1TypeDef {
return registry.createType('Si1TypeDef', {
Composite: {
fields: convertFields(registry, fields)
}
});
}
function convertFields (registry: Registry, fields: Si0Field[]): Si1Field[] {
return fields.map(({ docs, name, type, typeName }) =>
registry.createType('Si1Field', {
docs,
name,
type: type.toNumber(),
typeName
})
);
}
function convertPhantom (registry: Registry, path: Si0Path): Si1TypeDef {
console.warn(`Converting phantom type ${path.map((p) => p.toString()).join('::')} to empty tuple`);
return registry.createType('Si1TypeDef', {
Tuple: []
});
}
function convertPrimitive (registry: Registry, prim: Si0TypeDefPrimitive): Si1TypeDef {
return registry.createType('Si1TypeDef', {
Primitive: prim.toString()
});
}
function convertSequence (registry: Registry, { type }: Si0TypeDefSequence): Si1TypeDef {
return registry.createType('Si1TypeDef', {
Sequence: {
type: type.toNumber()
}
});
}
function convertTuple (registry: Registry, types: Si0LookupTypeId[]): Si1TypeDef {
return registry.createType('Si1TypeDef', {
Tuple: types.map((t) => t.toNumber())
});
}
function convertVariant (registry: Registry, { variants }: Si0TypeDefVariant): Si1TypeDef {
return registry.createType('Si1TypeDef', {
Variant: {
variants: variants.map(({ discriminant, docs, fields, name }, index) =>
registry.createType('Si1Variant', {
docs,
fields: convertFields(registry, fields),
index: discriminant.isSome
? discriminant.unwrap().toNumber()
: index,
name
})
)
}
});
}
function convertDef (registry: Registry, { def, path }: Si0Type): Si1TypeDef {
if (def.isArray) {
return convertArray(registry, def.asArray);
} else if (def.isBitSequence) {
return convertBitSequence(registry, def.asBitSequence);
} else if (def.isCompact) {
return convertCompact(registry, def.asCompact);
} else if (def.isComposite) {
return convertComposite(registry, def.asComposite);
} else if (def.isPhantom) {
return convertPhantom(registry, path);
} else if (def.isPrimitive) {
return convertPrimitive(registry, def.asPrimitive);
} else if (def.isSequence) {
return convertSequence(registry, def.asSequence);
} else if (def.isTuple) {
return convertTuple(registry, def.asTuple);
} else if (def.isVariant) {
return convertVariant(registry, def.asVariant);
}
throw new Error(`Cannot convert type ${def.toString()}`);
}
export function toV1 (registry: Registry, types: Si0Type[]): PortableType[] {
return types.map((t, id) =>
registry.createType('PortableType', {
id,
type: {
def: convertDef(registry, t),
docs: [],
params: t.params.map((p) => p.toNumber()),
path: t.path.map((p) => p.toString())
}
})
);
}
@@ -66,9 +66,9 @@ export default {
_enum: ['Normal', 'RejectingOutboundMessages', 'Halted']
},
OutboundLaneData: {
latestGeneratedNonce: 'MessageNonce',
oldestUnprunedNonce: 'MessageNonce',
latestReceivedNonce: 'MessageNonce',
oldestUnprunedNonce: 'MessageNonce'
latestGeneratedNonce: 'MessageNonce'
},
OutboundMessageFee: 'Balance',
OutboundPayload: {
@@ -102,9 +102,9 @@ export interface OperatingMode extends Enum {
/** @name OutboundLaneData */
export interface OutboundLaneData extends Struct {
readonly latestGeneratedNonce: MessageNonce;
readonly latestReceivedNonce: MessageNonce;
readonly oldestUnprunedNonce: MessageNonce;
readonly latestReceivedNonce: MessageNonce;
readonly latestGeneratedNonce: MessageNonce;
}
/** @name OutboundMessageFee */
@@ -78,6 +78,26 @@ export default {
],
type: 'Option<StorageData>'
},
getStorageEntries: {
description: 'Returns child storage entries for multiple keys at a specific block state',
params: [
{
name: 'childKey',
type: 'PrefixedStorageKey'
},
{
name: 'keys',
type: 'Vec<StorageKey>'
},
{
name: 'at',
type: 'Hash',
isHistoric: true,
isOptional: true
}
],
type: 'Vec<Option<StorageData>>'
},
getStorageHash: {
description: 'Returns the hash of a child storage entry at a block state',
params: [
@@ -26,6 +26,10 @@ export default {
...v13,
...v14,
// registry mapping to latest
PortableRegistry: 'PortableRegistryV14',
PortableType: 'PortableTypeV14',
// latest mappings
ErrorMetadataLatest: 'ErrorMetadataV14',
EventMetadataLatest: 'EventMetadataV14',
@@ -2,7 +2,7 @@
/* eslint-disable */
import type { Bytes, Enum, GenericPortableRegistry, Option, Struct, Text, Type, Vec, bool, u8 } from '@polkadot/types';
import type { SiField, SiLookupTypeId, SiType } from '@polkadot/types/interfaces/scaleInfo';
import type { Si1Field, Si1LookupTypeId, Si1Type, SiLookupTypeId } from '@polkadot/types/interfaces/scaleInfo';
/** @name ErrorMetadataLatest */
export interface ErrorMetadataLatest extends ErrorMetadataV14 {}
@@ -22,7 +22,7 @@ export interface ErrorMetadataV13 extends ErrorMetadataV12 {}
/** @name ErrorMetadataV14 */
export interface ErrorMetadataV14 extends Struct {
readonly name: Text;
readonly fields: Vec<SiField>;
readonly fields: Vec<Si1Field>;
readonly index: u8;
readonly docs: Vec<Text>;
readonly args: Vec<Type>;
@@ -52,7 +52,7 @@ export interface EventMetadataV13 extends EventMetadataV12 {}
/** @name EventMetadataV14 */
export interface EventMetadataV14 extends Struct {
readonly name: Text;
readonly fields: Vec<SiField>;
readonly fields: Vec<Si1Field>;
readonly index: u8;
readonly docs: Vec<Text>;
readonly args: Vec<Type>;
@@ -129,10 +129,10 @@ export interface FunctionMetadataV13 extends FunctionMetadataV12 {}
/** @name FunctionMetadataV14 */
export interface FunctionMetadataV14 extends Struct {
readonly name: Text;
readonly fields: Vec<SiField>;
readonly fields: Vec<Si1Field>;
readonly index: u8;
readonly docs: Vec<Text>;
readonly args: Vec<FunctionArgumentMetadataLatest>;
readonly args: Vec<FunctionArgumentMetadataV14>;
}
/** @name FunctionMetadataV9 */
@@ -327,12 +327,18 @@ export interface PalletStorageMetadataV14 extends Struct {
}
/** @name PortableRegistry */
export interface PortableRegistry extends GenericPortableRegistry {}
export interface PortableRegistry extends PortableRegistryV14 {}
/** @name PortableRegistryV14 */
export interface PortableRegistryV14 extends GenericPortableRegistry {}
/** @name PortableType */
export interface PortableType extends Struct {
readonly id: SiLookupTypeId;
readonly type: SiType;
export interface PortableType extends PortableTypeV14 {}
/** @name PortableTypeV14 */
export interface PortableTypeV14 extends Struct {
readonly id: Si1LookupTypeId;
readonly type: Si1Type;
}
/** @name SignedExtensionMetadataLatest */
@@ -6,29 +6,29 @@
import type { DefinitionsTypes } from '../../types';
import { SiVariant } from '../scaleInfo/definitions';
import { Si1Variant } from '../scaleInfo/v1';
export const v14: DefinitionsTypes = {
// registry
PortableRegistry: 'GenericPortableRegistry',
PortableType: {
id: 'SiLookupTypeId',
type: 'SiType'
PortableRegistryV14: 'GenericPortableRegistry',
PortableTypeV14: {
id: 'Si1LookupTypeId',
type: 'Si1Type'
},
// compatibility with earlier layouts, i.e. don't break previous users
ErrorMetadataV14: {
...SiVariant,
...Si1Variant,
args: 'Vec<Type>'
},
EventMetadataV14: {
...SiVariant,
...Si1Variant,
args: 'Vec<Type>'
},
FunctionArgumentMetadataV14: 'FunctionArgumentMetadataV13',
FunctionMetadataV14: {
...SiVariant,
args: 'Vec<FunctionArgumentMetadataLatest>'
...Si1Variant,
args: 'Vec<FunctionArgumentMetadataV14>'
},
// V14
@@ -4,78 +4,32 @@
import type { Definitions } from '../../types';
import { v0 } from './v0';
import { v1 } from './v1';
// order important in structs... :)
/* eslint-disable sort-keys */
export const SiVariant = {
name: 'Text',
fields: 'Vec<SiField>',
index: 'u8',
docs: 'Vec<Text>'
};
export default {
rpc: {},
types: {
...v0,
SiField: {
name: 'Option<Text>',
type: 'SiLookupTypeId',
typeName: 'Option<Text>',
docs: 'Vec<Text>'
},
SiLookupTypeId: 'Compact<u32>',
SiPath: 'Vec<Text>',
SiType: {
path: 'SiPath',
params: 'Vec<SiTypeParameter>',
def: 'SiTypeDef',
docs: 'Vec<Text>'
},
SiTypeDef: {
_enum: {
Composite: 'SiTypeDefComposite',
Variant: 'SiTypeDefVariant',
Sequence: 'SiTypeDefSequence',
Array: 'SiTypeDefArray',
Tuple: 'SiTypeDefTuple',
Primitive: 'SiTypeDefPrimitive',
Compact: 'SiTypeDefCompact',
BitSequence: 'SiTypeDefBitSequence',
// NOTE: This is specific to the implementation for pre-v14 metadata
// compatibility (always keep this as the last entry in the enum)
HistoricMetaCompat: 'Type'
}
},
SiTypeDefArray: {
len: 'u32',
type: 'SiLookupTypeId'
},
SiTypeDefBitSequence: {
bitStoreType: 'SiLookupTypeId',
bitOrderType: 'SiLookupTypeId'
},
SiTypeDefCompact: {
type: 'SiLookupTypeId'
},
SiTypeDefComposite: {
fields: 'Vec<SiField>'
},
SiTypeDefPrimitive: {
_enum: ['Bool', 'Char', 'Str', 'U8', 'U16', 'U32', 'U64', 'U128', 'U256', 'I8', 'I16', 'I32', 'I64', 'I128', 'I256']
},
SiTypeDefSequence: {
type: 'SiLookupTypeId'
},
SiTypeDefTuple: 'Vec<SiLookupTypeId>',
SiTypeParameter: {
name: 'Text',
type: 'Option<SiLookupTypeId>'
},
SiTypeDefVariant: {
variants: 'Vec<SiVariant>'
},
SiVariant
...v1,
// latest mappings
SiField: 'Si1Field',
SiLookupTypeId: 'Si1LookupTypeId',
SiPath: 'Si1Path',
SiType: 'Si1Type',
SiTypeDef: 'Si1TypeDef',
SiTypeDefArray: 'Si1TypeDefArray',
SiTypeDefBitSequence: 'Si1TypeDefBitSequence',
SiTypeDefCompact: 'Si1TypeDefCompact',
SiTypeDefComposite: 'Si1TypeDefComposite',
SiTypeDefPrimitive: 'Si1TypeDefPrimitive',
SiTypeDefSequence: 'Si1TypeDefSequence',
SiTypeDefTuple: 'Si1TypeDefTuple',
SiTypeParameter: 'Si1TypeParameter',
SiTypeDefVariant: 'Si1TypeDefVariant',
SiVariant: 'Si1Variant'
}
} as Definitions;
@@ -118,116 +118,145 @@ export interface Si0Variant extends Struct {
readonly docs: Vec<Text>;
}
/** @name SiField */
export interface SiField extends Struct {
/** @name Si1Field */
export interface Si1Field extends Struct {
readonly name: Option<Text>;
readonly type: SiLookupTypeId;
readonly type: Si1LookupTypeId;
readonly typeName: Option<Text>;
readonly docs: Vec<Text>;
}
/** @name SiLookupTypeId */
export interface SiLookupTypeId extends Compact<u32> {}
/** @name Si1LookupTypeId */
export interface Si1LookupTypeId extends Compact<u32> {}
/** @name SiPath */
export interface SiPath extends Vec<Text> {}
/** @name Si1Path */
export interface Si1Path extends Si0Path {}
/** @name SiType */
export interface SiType extends Struct {
readonly path: SiPath;
readonly params: Vec<SiTypeParameter>;
readonly def: SiTypeDef;
/** @name Si1Type */
export interface Si1Type extends Struct {
readonly path: Si1Path;
readonly params: Vec<Si1TypeParameter>;
readonly def: Si1TypeDef;
readonly docs: Vec<Text>;
}
/** @name SiTypeDef */
export interface SiTypeDef extends Enum {
/** @name Si1TypeDef */
export interface Si1TypeDef extends Enum {
readonly isComposite: boolean;
readonly asComposite: SiTypeDefComposite;
readonly asComposite: Si1TypeDefComposite;
readonly isVariant: boolean;
readonly asVariant: SiTypeDefVariant;
readonly asVariant: Si1TypeDefVariant;
readonly isSequence: boolean;
readonly asSequence: SiTypeDefSequence;
readonly asSequence: Si1TypeDefSequence;
readonly isArray: boolean;
readonly asArray: SiTypeDefArray;
readonly asArray: Si1TypeDefArray;
readonly isTuple: boolean;
readonly asTuple: SiTypeDefTuple;
readonly asTuple: Si1TypeDefTuple;
readonly isPrimitive: boolean;
readonly asPrimitive: SiTypeDefPrimitive;
readonly asPrimitive: Si1TypeDefPrimitive;
readonly isCompact: boolean;
readonly asCompact: SiTypeDefCompact;
readonly asCompact: Si1TypeDefCompact;
readonly isBitSequence: boolean;
readonly asBitSequence: SiTypeDefBitSequence;
readonly asBitSequence: Si1TypeDefBitSequence;
readonly isHistoricMetaCompat: boolean;
readonly asHistoricMetaCompat: Type;
}
/** @name SiTypeDefArray */
export interface SiTypeDefArray extends Struct {
/** @name Si1TypeDefArray */
export interface Si1TypeDefArray extends Struct {
readonly len: u32;
readonly type: SiLookupTypeId;
readonly type: Si1LookupTypeId;
}
/** @name SiTypeDefBitSequence */
export interface SiTypeDefBitSequence extends Struct {
readonly bitStoreType: SiLookupTypeId;
readonly bitOrderType: SiLookupTypeId;
/** @name Si1TypeDefBitSequence */
export interface Si1TypeDefBitSequence extends Struct {
readonly bitStoreType: Si1LookupTypeId;
readonly bitOrderType: Si1LookupTypeId;
}
/** @name SiTypeDefCompact */
export interface SiTypeDefCompact extends Struct {
readonly type: SiLookupTypeId;
/** @name Si1TypeDefCompact */
export interface Si1TypeDefCompact extends Struct {
readonly type: Si1LookupTypeId;
}
/** @name SiTypeDefComposite */
export interface SiTypeDefComposite extends Struct {
readonly fields: Vec<SiField>;
/** @name Si1TypeDefComposite */
export interface Si1TypeDefComposite extends Struct {
readonly fields: Vec<Si1Field>;
}
/** @name SiTypeDefPrimitive */
export interface SiTypeDefPrimitive extends Enum {
readonly isBool: boolean;
readonly isChar: boolean;
readonly isStr: boolean;
readonly isU8: boolean;
readonly isU16: boolean;
readonly isU32: boolean;
readonly isU64: boolean;
readonly isU128: boolean;
readonly isU256: boolean;
readonly isI8: boolean;
readonly isI16: boolean;
readonly isI32: boolean;
readonly isI64: boolean;
readonly isI128: boolean;
readonly isI256: boolean;
/** @name Si1TypeDefPrimitive */
export interface Si1TypeDefPrimitive extends Si0TypeDefPrimitive {}
/** @name Si1TypeDefSequence */
export interface Si1TypeDefSequence extends Struct {
readonly type: Si1LookupTypeId;
}
/** @name SiTypeDefSequence */
export interface SiTypeDefSequence extends Struct {
readonly type: SiLookupTypeId;
/** @name Si1TypeDefTuple */
export interface Si1TypeDefTuple extends Vec<Si1LookupTypeId> {}
/** @name Si1TypeDefVariant */
export interface Si1TypeDefVariant extends Struct {
readonly variants: Vec<Si1Variant>;
}
/** @name SiTypeDefTuple */
export interface SiTypeDefTuple extends Vec<SiLookupTypeId> {}
/** @name SiTypeDefVariant */
export interface SiTypeDefVariant extends Struct {
readonly variants: Vec<SiVariant>;
}
/** @name SiTypeParameter */
export interface SiTypeParameter extends Struct {
/** @name Si1TypeParameter */
export interface Si1TypeParameter extends Struct {
readonly name: Text;
readonly type: Option<SiLookupTypeId>;
readonly type: Option<Si1LookupTypeId>;
}
/** @name SiVariant */
export interface SiVariant extends Struct {
/** @name Si1Variant */
export interface Si1Variant extends Struct {
readonly name: Text;
readonly fields: Vec<SiField>;
readonly fields: Vec<Si1Field>;
readonly index: u8;
readonly docs: Vec<Text>;
}
/** @name SiField */
export interface SiField extends Si1Field {}
/** @name SiLookupTypeId */
export interface SiLookupTypeId extends Si1LookupTypeId {}
/** @name SiPath */
export interface SiPath extends Si1Path {}
/** @name SiType */
export interface SiType extends Si1Type {}
/** @name SiTypeDef */
export interface SiTypeDef extends Si1TypeDef {}
/** @name SiTypeDefArray */
export interface SiTypeDefArray extends Si1TypeDefArray {}
/** @name SiTypeDefBitSequence */
export interface SiTypeDefBitSequence extends Si1TypeDefBitSequence {}
/** @name SiTypeDefCompact */
export interface SiTypeDefCompact extends Si1TypeDefCompact {}
/** @name SiTypeDefComposite */
export interface SiTypeDefComposite extends Si1TypeDefComposite {}
/** @name SiTypeDefPrimitive */
export interface SiTypeDefPrimitive extends Si1TypeDefPrimitive {}
/** @name SiTypeDefSequence */
export interface SiTypeDefSequence extends Si1TypeDefSequence {}
/** @name SiTypeDefTuple */
export interface SiTypeDefTuple extends Si1TypeDefTuple {}
/** @name SiTypeDefVariant */
export interface SiTypeDefVariant extends Si1TypeDefVariant {}
/** @name SiTypeParameter */
export interface SiTypeParameter extends Si1TypeParameter {}
/** @name SiVariant */
export interface SiVariant extends Si1Variant {}
export type PHANTOM_SCALEINFO = 'scaleInfo';
@@ -0,0 +1,73 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { DefinitionsTypes } from '../../types';
// order important in structs... :)
/* eslint-disable sort-keys */
export const Si1Variant = {
name: 'Text',
fields: 'Vec<Si1Field>',
index: 'u8',
docs: 'Vec<Text>'
};
export const v1: DefinitionsTypes = {
Si1Field: {
name: 'Option<Text>',
type: 'Si1LookupTypeId',
typeName: 'Option<Text>',
docs: 'Vec<Text>'
},
Si1LookupTypeId: 'Compact<u32>',
Si1Path: 'Si0Path',
Si1Type: {
path: 'Si1Path',
params: 'Vec<Si1TypeParameter>',
def: 'Si1TypeDef',
docs: 'Vec<Text>'
},
Si1TypeDef: {
_enum: {
Composite: 'Si1TypeDefComposite',
Variant: 'Si1TypeDefVariant',
Sequence: 'Si1TypeDefSequence',
Array: 'Si1TypeDefArray',
Tuple: 'Si1TypeDefTuple',
Primitive: 'Si1TypeDefPrimitive',
Compact: 'Si1TypeDefCompact',
BitSequence: 'Si1TypeDefBitSequence',
// NOTE: This is specific to the implementation for pre-v14 metadata
// compatibility (always keep this as the last entry in the enum)
HistoricMetaCompat: 'Type'
}
},
Si1TypeDefArray: {
len: 'u32',
type: 'Si1LookupTypeId'
},
Si1TypeDefBitSequence: {
bitStoreType: 'Si1LookupTypeId',
bitOrderType: 'Si1LookupTypeId'
},
Si1TypeDefCompact: {
type: 'Si1LookupTypeId'
},
Si1TypeDefComposite: {
fields: 'Vec<Si1Field>'
},
Si1TypeDefPrimitive: 'Si0TypeDefPrimitive',
Si1TypeDefSequence: {
type: 'Si1LookupTypeId'
},
Si1TypeDefTuple: 'Vec<Si1LookupTypeId>',
Si1TypeParameter: {
name: 'Text',
type: 'Option<Si1LookupTypeId>'
},
Si1TypeDefVariant: {
variants: 'Vec<Si1Variant>'
},
Si1Variant
};
@@ -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)
}))
});
@@ -1,13 +1,19 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import metadataStatic from '@polkadot/types-support/metadata/static-substrate';
import { compactAddLength, u8aToU8a } from '@polkadot/util';
import { TypeRegistry } from '../../../create';
import { Metadata } from '../../Metadata';
import { getStorage } from './getStorage';
const registry = new TypeRegistry();
const metadata = new Metadata(registry, metadataStatic);
registry.setMetadata(metadata);
describe('getSorage', (): void => {
const registry = new TypeRegistry();
const storage = getStorage(registry);
it('should return well known keys', (): void => {
@@ -1,19 +1,34 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import metadataStatic from '@polkadot/types-support/metadata/static-substrate';
import { compactAddLength, u8aToU8a } from '@polkadot/util';
import { TypeRegistry } from '../../../create';
import { Metadata } from '../../Metadata';
import { substrate } from './substrate';
const registry = new TypeRegistry();
const metadata = new Metadata(registry, metadataStatic);
registry.setMetadata(metadata);
// console.log(JSON.stringify(registry.lookup.types));
describe('substrate', (): void => {
const code = substrate.code(registry);
it('creates a well-known :code key', (): void => {
expect(
substrate.code(registry)()
code()
).toEqual(
compactAddLength(u8aToU8a(':code'))
);
});
it('has the correct metadata', (): void => {
expect(
code.meta.type.isPlain
).toEqual(true);
});
});
@@ -1,7 +1,7 @@
// Copyright 2017-2021 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { StorageEntryMetadataLatest } from '../../../interfaces';
import type { PortableType } from '../../../interfaces';
import type { StorageEntry } from '../../../primitive/types';
import type { Registry } from '../../../types';
@@ -14,18 +14,60 @@ interface SubstrateMetadata {
type Creator = (registry: Registry) => StorageEntry;
function findSiPrimitive (registry: Registry, _prim: string): PortableType | undefined {
const prim = _prim.toLowerCase();
const portable = registry.lookup.types.find((t) =>
(
t.type.def.isPrimitive &&
t.type.def.asPrimitive.toString().toLowerCase() === prim
) || (
t.type.def.isHistoricMetaCompat &&
t.type.def.asHistoricMetaCompat.toString().toLowerCase() === prim
)
);
return portable;
}
function findSiType (registry: Registry, orig: string): PortableType | undefined {
let portable = findSiPrimitive(registry, orig);
if (!portable && orig === 'Bytes') {
const u8 = findSiPrimitive(registry, 'u8');
if (u8) {
portable = registry.lookup.types.find((t) =>
(
t.type.def.isSequence &&
t.type.def.asSequence.type.eq(u8.id)
) || (
t.type.def.isHistoricMetaCompat &&
t.type.def.asHistoricMetaCompat.eq(orig)
)
);
}
}
if (!portable) {
console.warn(`Unable to map ${orig} to a lookup index`);
}
return portable;
}
// Small helper function to factorize code on this page.
/** @internal */
function createRuntimeFunction (method: string, key: string, { docs, type }: SubstrateMetadata): (registry: Registry) => StorageEntry {
return (registry: Registry): StorageEntry =>
createFunction(registry, {
meta: {
meta: registry.createType('StorageEntryMetadataLatest', {
docs: registry.createType('Vec<Text>', [docs]),
modifier: registry.createType('StorageEntryModifierLatest', 1), // required
modifier: registry.createType('StorageEntryModifierLatest', 'Required'),
name: registry.createType('Text', method),
toJSON: (): any => key,
type: registry.createType('StorageEntryTypeLatest', type, 0)
} as StorageEntryMetadataLatest,
type: registry.createType('StorageEntryTypeLatest', { Plain: findSiType(registry, type)?.id || 0 })
}),
method,
prefix: 'Substrate',
section: 'substrate'
@@ -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';
+58 -47
View File
@@ -10,30 +10,32 @@ import type { OverrideModuleType, Registry } 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[];
value: Type;
}
export interface TypeSpec {
def: {
HistoricMetaCompat?: string;
Tuple?: number[];
Variant?: {
variants: SiVariant[];
}
},
path?: string[];
}
const BOXES = [['<', '>'], ['<', ','], [',', '>'], ['(', ')'], ['(', ','], [',', ','], [',', ')']];
/**
* Creates a compatible type mapping
* @internal
**/
function compatType (types: TypeSpec[], _type: Text | string): number {
function compatType (compatTypes: TypeSpec[], _type: Text | string): number {
const type = _type.toString();
const index = types.findIndex(({ def }) =>
const index = compatTypes.findIndex(({ def }) =>
def.HistoricMetaCompat === type
);
@@ -41,13 +43,23 @@ function compatType (types: TypeSpec[], _type: Text | string): number {
return index;
}
return types.push({
def: { HistoricMetaCompat: type }
return compatTypes.push({
def: {
HistoricMetaCompat: type
}
}) - 1;
}
function variantType (modName: Text, variantType: string, types: TypeSpec[], variants: SiVariant[]): number {
return types.push({
function makeTupleType (compatTypes: TypeSpec[], entries: number[]): number {
return compatTypes.push({
def: {
Tuple: entries
}
}) - 1;
}
function makeVariantType (modName: Text, variantType: string, compatTypes: TypeSpec[], variants: SiVariant[]): number {
return compatTypes.push({
def: {
Variant: { variants }
},
@@ -113,14 +125,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 (compatTypes: TypeSpec[], 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(compatTypes, type) })
),
index,
name
@@ -128,7 +140,7 @@ function convertCalls (registry: Registry, types: TypeSpec[], modName: Text, cal
});
return registry.createType('PalletCallMetadataV14', {
type: variantType(modName, 'Call', types, variants)
type: makeVariantType(modName, 'Call', compatTypes, variants)
});
}
@@ -136,14 +148,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 (compatTypes: TypeSpec[], 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(compatTypes, type),
value
});
});
@@ -154,7 +166,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 (compatTypes: TypeSpec[], registry: Registry, modName: Text, errors: ErrorMetadataV13[], _sectionTypes: OverrideModuleType): PalletErrorMetadataV14 {
const variants = errors.map(({ docs, name }, index): SiVariant =>
registry.createType('SiVariant', {
docs,
@@ -165,7 +177,7 @@ function convertErrors (registry: Registry, types: TypeSpec[], modName: Text, er
);
return registry.createType('PalletErrorMetadataV14', {
type: variantType(modName, 'Error', types, variants)
type: makeVariantType(modName, 'Error', compatTypes, variants)
});
}
@@ -173,14 +185,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 (compatTypes: TypeSpec[], 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(compatTypes, t) })
),
index,
name
@@ -188,20 +200,20 @@ function convertEvents (registry: Registry, types: TypeSpec[], modName: Text, ev
});
return registry.createType('PalletEventMetadataV14', {
type: variantType(modName, 'Event', types, variants)
type: makeVariantType(modName, 'Event', compatTypes, variants)
});
}
function createMapEntry (registry: Registry, sectionTypes: OverrideModuleType, types: TypeSpec[], { hashers, keys, value }: MapDef): StorageEntryTypeV14 {
function createMapEntry (compatTypes: TypeSpec[], 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(compatTypes, keys[0])
: makeTupleType(compatTypes, keys.map((t) => compatType(compatTypes, t))),
value: compatType(compatTypes, value)
}
});
}
@@ -210,7 +222,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 (compatTypes: TypeSpec[], 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 +233,12 @@ function convertStorage (registry: Registry, types: TypeSpec[], { items, prefix
setTypeOverride(sectionTypes, [plain]);
entryType = registry.createType('StorageEntryTypeV14', {
Plain: compatType(types, plain)
Plain: compatType(compatTypes, plain)
});
} else if (type.isMap) {
const map = type.asMap;
entryType = createMapEntry(registry, sectionTypes, types, {
entryType = createMapEntry(compatTypes, registry, sectionTypes, {
hashers: [map.hasher],
keys: [map.key],
value: map.value
@@ -234,7 +246,7 @@ function convertStorage (registry: Registry, types: TypeSpec[], { items, prefix
} else if (type.isDoubleMap) {
const dm = type.asDoubleMap;
entryType = createMapEntry(registry, sectionTypes, types, {
entryType = createMapEntry(compatTypes, registry, sectionTypes, {
hashers: [dm.hasher, dm.key2Hasher],
keys: [dm.key1, dm.key2],
value: dm.value
@@ -242,7 +254,7 @@ function convertStorage (registry: Registry, types: TypeSpec[], { items, prefix
} else {
const nm = type.asNMap;
entryType = createMapEntry(registry, sectionTypes, types, {
entryType = createMapEntry(compatTypes, registry, sectionTypes, {
hashers: nm.hashers,
keys: nm.keyVec,
value: nm.value
@@ -263,7 +275,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 +287,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 (compatTypes: TypeSpec[], 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(compatTypes, registry, mod.name, calls, sectionTypes),
constants: convertConstants(compatTypes, registry, constants, sectionTypes),
errors: errors && convertErrors(compatTypes, registry, mod.name, errors, sectionTypes),
events: events && convertEvents(compatTypes, registry, mod.name, events, sectionTypes),
index: mod.index,
name: mod.name,
storage: storage && convertStorage(registry, types, storage, sectionTypes)
storage: storage && convertStorage(compatTypes, registry, storage, sectionTypes)
});
}
@@ -294,15 +306,14 @@ 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[] = [];
const compatTypes: TypeSpec[] = [];
compatType(types, 'Null'); // position 0 always has Null
compatType(compatTypes, '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(compatTypes, registry, mod, {
calls: mod.calls.unwrapOr(null),
constants: mod.constants,
errors: mod.errors.length ? mod.errors : null,
@@ -314,7 +325,7 @@ export function toV14 (registry: Registry, v13: MetadataV13, metaVersion: number
return registry.createType('MetadataV14', {
extrinsic,
lookup: {
types: types.map((type, id) =>
types: compatTypes.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.1' };
export const packageInfo = { name: '@polkadot/types', version: '6.1.1' };
+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
+529 -1262
View File
File diff suppressed because it is too large Load Diff