Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a63026b14 | ||
|
|
a40ce72298 | ||
|
|
f302d8de69 | ||
|
|
fcaebbdbb2 | ||
|
|
9e7037af04 | ||
|
|
68efac60df | ||
|
|
d763f49e8b | ||
|
|
77ffd7c153 | ||
|
|
d1506154bd | ||
|
|
b1254685da | ||
|
|
81a2a2c688 | ||
|
|
1fed997080 | ||
|
|
6e620e3bb3 | ||
|
|
6e4c62ea99 | ||
|
|
8972d2ffe9 | ||
|
|
091d2d30e0 | ||
|
|
ae7ded1767 | ||
|
|
8aa3550354 | ||
|
|
196d3c5995 | ||
|
|
592407d691 | ||
|
|
1e3a1bb51c | ||
|
|
2ca23a85d0 | ||
|
|
1a04b4a72e | ||
|
|
6dfe7c4f56 | ||
|
|
3f9f7bd649 | ||
|
|
e02e1302b2 | ||
|
|
a64dec3487 | ||
|
|
3415fbd121 | ||
|
|
0be1d46be9 | ||
|
|
9309e9f3a1 | ||
|
|
6dd019343d |
@@ -1,7 +1,25 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 5.2.1 Jul 26, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended for users of `BTreeMap` and `BTreeSet`
|
||||
|
||||
Contributed:
|
||||
|
||||
- Perform sorting on `BTree{Map, Set}`, aligning with Substrate (Thanks to https://github.com/Lezek123)
|
||||
|
||||
Changes:
|
||||
|
||||
- Adjust RPC to use registry.createType with optionality (required for metadata v14)
|
||||
- Adjust alphabetical sorting for TS type generation
|
||||
- Adjustments for upcoming metadata v14 in type creation & `PortableRegistry`
|
||||
- Provide the capability to convert v13 Metadata to upcoming v14
|
||||
|
||||
|
||||
## 5.1.1 Jul 19, 2021
|
||||
|
||||
Upgrade priority: Low. Recommended for users of XCM with type fixes.
|
||||
|
||||
- **Breaking changes** With the support for v14 metadata parsing, the `documentation` fields on metadata was renamed to `docs` for consistency, aligning with the SCALE type generators.
|
||||
|
||||
Contributed:
|
||||
|
||||
+4
-4
@@ -26,14 +26,14 @@
|
||||
"test:watch": "polkadot-dev-run-test --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.14.6",
|
||||
"@babel/core": "^7.14.8",
|
||||
"@babel/register": "^7.14.5",
|
||||
"@babel/runtime": "^7.14.6",
|
||||
"@babel/runtime": "^7.14.8",
|
||||
"@polkadot/dev": "^0.62.57",
|
||||
"@polkadot/ts": "^0.4.4",
|
||||
"@polkadot/typegen": "workspace:packages/typegen",
|
||||
"@types/jest": "^26.0.23",
|
||||
"@types/jest": "^26.0.24",
|
||||
"copyfiles": "^2.4.1"
|
||||
},
|
||||
"version": "5.1.1"
|
||||
"version": "5.2.1"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/api-contract",
|
||||
"version": "5.1.1",
|
||||
"version": "5.2.1",
|
||||
"type": "module",
|
||||
"description": "Interfaces for interacting with contracts and contract ABIs",
|
||||
"main": "index.js",
|
||||
@@ -19,10 +19,10 @@
|
||||
"bugs": "https://github.com/polkadot-js/api/issues",
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.6",
|
||||
"@polkadot/api": "5.1.1",
|
||||
"@polkadot/types": "5.1.1",
|
||||
"@polkadot/util": "^7.0.2",
|
||||
"@babel/runtime": "^7.14.8",
|
||||
"@polkadot/api": "5.2.1",
|
||||
"@polkadot/types": "5.2.1",
|
||||
"@polkadot/util": "^7.0.3",
|
||||
"rxjs": "^7.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ export class MetaRegistry extends TypeRegistry {
|
||||
|
||||
const displayName = path.pop()?.toString();
|
||||
|
||||
return withTypeString({
|
||||
return withTypeString(this, {
|
||||
...(displayName
|
||||
? { displayName }
|
||||
: {}
|
||||
@@ -243,7 +243,7 @@ export class MetaRegistry extends TypeRegistry {
|
||||
name: name.toString(),
|
||||
type: 'Null'
|
||||
}))
|
||||
: variants.map(({ fields, name }) => withTypeString({
|
||||
: variants.map(({ fields, name }) => withTypeString(this, {
|
||||
...this.#extractFields(fields),
|
||||
name: name.toString()
|
||||
}));
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/api-contract', version: '5.1.1' };
|
||||
export const packageInfo = { name: '@polkadot/api-contract', version: '5.2.1' };
|
||||
|
||||
@@ -158,12 +158,12 @@
|
||||
"type": "AccountId"
|
||||
}
|
||||
],
|
||||
"type": "(AccountId, AccountId)",
|
||||
"type": "(AccountId,AccountId)",
|
||||
"name": "Occupied"
|
||||
}
|
||||
],
|
||||
"info": 3,
|
||||
"type": "{\"_enum\":{\"Vacant\":\"VacantEntry\",\"Occupied\":\"(AccountId, AccountId)\"}}"
|
||||
"type": "{\"_enum\":{\"Vacant\":\"VacantEntry\",\"Occupied\":\"(AccountId,AccountId)\"}}"
|
||||
},
|
||||
{
|
||||
"info": 10,
|
||||
@@ -181,7 +181,7 @@
|
||||
"type": "AccountId"
|
||||
}
|
||||
],
|
||||
"type": "(AccountId, AccountId)"
|
||||
"type": "(AccountId,AccountId)"
|
||||
},
|
||||
{
|
||||
"info": 6,
|
||||
@@ -198,4 +198,4 @@
|
||||
"info": 5,
|
||||
"type": "Option<AccountId>"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
@@ -206,12 +206,12 @@
|
||||
"type": "AccountId"
|
||||
}
|
||||
],
|
||||
"type": "(AccountId, AccountId)",
|
||||
"type": "(AccountId,AccountId)",
|
||||
"name": "Occupied"
|
||||
}
|
||||
],
|
||||
"info": 3,
|
||||
"type": "{\"_enum\":{\"Vacant\":\"VacantEntry\",\"Occupied\":\"(AccountId, AccountId)\"}}"
|
||||
"type": "{\"_enum\":{\"Vacant\":\"VacantEntry\",\"Occupied\":\"(AccountId,AccountId)\"}}"
|
||||
},
|
||||
{
|
||||
"info": 10,
|
||||
@@ -229,7 +229,7 @@
|
||||
"type": "AccountId"
|
||||
}
|
||||
],
|
||||
"type": "(AccountId, AccountId)"
|
||||
"type": "(AccountId,AccountId)"
|
||||
},
|
||||
{
|
||||
"displayName": "ValueEntry",
|
||||
@@ -427,4 +427,4 @@
|
||||
],
|
||||
"type": "{\"_enum\":[\"NotOwner\",\"NotApproved\",\"TokenExists\",\"TokenNotFound\",\"CannotInsert\",\"CannotRemove\",\"CannotFetchValue\",\"NotAllowed\"]}"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
@@ -63,12 +63,12 @@
|
||||
"type": "AccountId"
|
||||
}
|
||||
],
|
||||
"type": "(u32, AccountId)",
|
||||
"type": "(u32,AccountId)",
|
||||
"name": "Occupied"
|
||||
}
|
||||
],
|
||||
"info": 3,
|
||||
"type": "{\"_enum\":{\"Vacant\":\"VacantEntry\",\"Occupied\":\"(u32, AccountId)\"}}"
|
||||
"type": "{\"_enum\":{\"Vacant\":\"VacantEntry\",\"Occupied\":\"(u32,AccountId)\"}}"
|
||||
},
|
||||
{
|
||||
"info": 10,
|
||||
@@ -84,7 +84,7 @@
|
||||
"type": "AccountId"
|
||||
}
|
||||
],
|
||||
"type": "(u32, AccountId)"
|
||||
"type": "(u32,AccountId)"
|
||||
},
|
||||
{
|
||||
"displayName": "AccountId",
|
||||
@@ -409,7 +409,7 @@
|
||||
"type": "{\"_enum\":{\"Confirmed\":\"()\",\"ConfirmationsNeeded\":\"u32\"}}"
|
||||
}
|
||||
],
|
||||
"type": "(u32, ConfirmationStatus)"
|
||||
"type": "(u32,ConfirmationStatus)"
|
||||
},
|
||||
{
|
||||
"displayName": "ConfirmationStatus",
|
||||
@@ -511,4 +511,4 @@
|
||||
"info": 5,
|
||||
"type": "Option<Vec<u8>>"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
@@ -158,12 +158,12 @@
|
||||
"type": "AccountId"
|
||||
}
|
||||
],
|
||||
"type": "(AccountId, AccountId)",
|
||||
"type": "(AccountId,AccountId)",
|
||||
"name": "Occupied"
|
||||
}
|
||||
],
|
||||
"info": 3,
|
||||
"type": "{\"_enum\":{\"Vacant\":\"VacantEntry\",\"Occupied\":\"(AccountId, AccountId)\"}}"
|
||||
"type": "{\"_enum\":{\"Vacant\":\"VacantEntry\",\"Occupied\":\"(AccountId,AccountId)\"}}"
|
||||
},
|
||||
{
|
||||
"info": 10,
|
||||
@@ -181,7 +181,7 @@
|
||||
"type": "AccountId"
|
||||
}
|
||||
],
|
||||
"type": "(AccountId, AccountId)"
|
||||
"type": "(AccountId,AccountId)"
|
||||
},
|
||||
{
|
||||
"info": 6,
|
||||
@@ -202,4 +202,4 @@
|
||||
"info": 5,
|
||||
"type": "Option<AccountId>"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/api-derive",
|
||||
"version": "5.1.1",
|
||||
"version": "5.2.1",
|
||||
"type": "module",
|
||||
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
|
||||
"main": "index.js",
|
||||
@@ -19,16 +19,16 @@
|
||||
"bugs": "https://github.com/polkadot-js/api/issues",
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.6",
|
||||
"@polkadot/api": "5.1.1",
|
||||
"@polkadot/rpc-core": "5.1.1",
|
||||
"@polkadot/types": "5.1.1",
|
||||
"@polkadot/util": "^7.0.2",
|
||||
"@polkadot/util-crypto": "^7.0.2",
|
||||
"@babel/runtime": "^7.14.8",
|
||||
"@polkadot/api": "5.2.1",
|
||||
"@polkadot/rpc-core": "5.2.1",
|
||||
"@polkadot/types": "5.2.1",
|
||||
"@polkadot/util": "^7.0.3",
|
||||
"@polkadot/util-crypto": "^7.0.3",
|
||||
"rxjs": "^7.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^7.0.2",
|
||||
"@polkadot/rpc-provider": "5.1.1"
|
||||
"@polkadot/keyring": "^7.0.3",
|
||||
"@polkadot/rpc-provider": "5.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/api-derive', version: '5.1.1' };
|
||||
export const packageInfo = { name: '@polkadot/api-derive', version: '5.2.1' };
|
||||
|
||||
+10
-10
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/api",
|
||||
"version": "5.1.1",
|
||||
"version": "5.2.1",
|
||||
"type": "module",
|
||||
"description": "Promise and RxJS wrappers around the Polkadot JS RPC",
|
||||
"main": "index.js",
|
||||
@@ -19,15 +19,15 @@
|
||||
"bugs": "https://github.com/polkadot-js/api/issues",
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.6",
|
||||
"@polkadot/api-derive": "5.1.1",
|
||||
"@polkadot/keyring": "^7.0.2",
|
||||
"@polkadot/rpc-core": "5.1.1",
|
||||
"@polkadot/rpc-provider": "5.1.1",
|
||||
"@polkadot/types": "5.1.1",
|
||||
"@polkadot/types-known": "5.1.1",
|
||||
"@polkadot/util": "^7.0.2",
|
||||
"@polkadot/util-crypto": "^7.0.2",
|
||||
"@babel/runtime": "^7.14.8",
|
||||
"@polkadot/api-derive": "5.2.1",
|
||||
"@polkadot/keyring": "^7.0.3",
|
||||
"@polkadot/rpc-core": "5.2.1",
|
||||
"@polkadot/rpc-provider": "5.2.1",
|
||||
"@polkadot/types": "5.2.1",
|
||||
"@polkadot/types-known": "5.2.1",
|
||||
"@polkadot/util": "^7.0.3",
|
||||
"@polkadot/util-crypto": "^7.0.3",
|
||||
"eventemitter3": "^4.0.7",
|
||||
"rxjs": "^7.2.0"
|
||||
}
|
||||
|
||||
@@ -4413,24 +4413,6 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* # </weight>
|
||||
**/
|
||||
vest: AugmentedSubmittable<() => SubmittableExtrinsic<ApiType>, []>;
|
||||
/**
|
||||
* Unlock any vested funds of a `target` account.
|
||||
*
|
||||
* The dispatch origin for this call must be _Signed_.
|
||||
*
|
||||
* - `target`: The account whose vested funds should be unlocked. Must have funds still
|
||||
* locked under this pallet.
|
||||
*
|
||||
* Emits either `VestingCompleted` or `VestingUpdated`.
|
||||
*
|
||||
* # <weight>
|
||||
* - `O(1)`.
|
||||
* - DbWeight: 3 Reads, 3 Writes
|
||||
* - Reads: Vesting Storage, Balances Locks, Target Account
|
||||
* - Writes: Vesting Storage, Balances Locks, Target Account
|
||||
* # </weight>
|
||||
**/
|
||||
vestOther: AugmentedSubmittable<(target: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [LookupSource]>;
|
||||
/**
|
||||
* Create a vested transfer.
|
||||
*
|
||||
@@ -4450,6 +4432,24 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* # </weight>
|
||||
**/
|
||||
vestedTransfer: AugmentedSubmittable<(target: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array, schedule: VestingInfo | { locked?: any; perBlock?: any; startingBlock?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [LookupSource, VestingInfo]>;
|
||||
/**
|
||||
* Unlock any vested funds of a `target` account.
|
||||
*
|
||||
* The dispatch origin for this call must be _Signed_.
|
||||
*
|
||||
* - `target`: The account whose vested funds should be unlocked. Must have funds still
|
||||
* locked under this pallet.
|
||||
*
|
||||
* Emits either `VestingCompleted` or `VestingUpdated`.
|
||||
*
|
||||
* # <weight>
|
||||
* - `O(1)`.
|
||||
* - DbWeight: 3 Reads, 3 Writes
|
||||
* - Reads: Vesting Storage, Balances Locks, Target Account
|
||||
* - Writes: Vesting Storage, Balances Locks, Target Account
|
||||
* # </weight>
|
||||
**/
|
||||
vestOther: AugmentedSubmittable<(target: LookupSource | { Id: any } | { Index: any } | { Raw: any } | { Address32: any } | { Address20: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>, [LookupSource]>;
|
||||
/**
|
||||
* Generic tx
|
||||
**/
|
||||
|
||||
@@ -405,7 +405,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(creator, args);
|
||||
const getArgs = (args: unknown[]): 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 */
|
||||
@@ -488,7 +488,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
|
||||
private _decorateStorageEntryAt<ApiType extends ApiTypes> (creator: StorageEntry, decorateMethod: DecorateMethod<ApiType>, blockHash: Uint8Array): QueryableStorageEntryAt<ApiType> {
|
||||
// get the storage arguments, with DoubleMap as an array entry, otherwise spread
|
||||
const getArgs = (args: unknown[]): unknown[] => extractStorageArgs(creator, args);
|
||||
const getArgs = (args: unknown[]): 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 */
|
||||
@@ -545,18 +545,18 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return decorateMethod((...args: unknown[]): Observable<Codec> => {
|
||||
return this.hasSubscriptions
|
||||
? this._rpcCore.state.subscribeStorage<[Codec]>([extractStorageArgs(creator, args)]).pipe(
|
||||
? this._rpcCore.state.subscribeStorage<[Codec]>([extractStorageArgs(this.#registry, creator, args)]).pipe(
|
||||
map(([data]) => data) // extract first/only result from list
|
||||
)
|
||||
: this._rpcCore.state.getStorage(extractStorageArgs(creator, args));
|
||||
: this._rpcCore.state.getStorage(extractStorageArgs(this.#registry, creator, args));
|
||||
}, {
|
||||
methodName: creator.method,
|
||||
overrideNoSub: (...args: unknown[]) => this._rpcCore.state.getStorage(extractStorageArgs(creator, args))
|
||||
overrideNoSub: (...args: unknown[]) => this._rpcCore.state.getStorage(extractStorageArgs(this.#registry, creator, args))
|
||||
});
|
||||
}
|
||||
|
||||
private _decorateStorageRange<ApiType extends ApiTypes> (decorated: QueryableStorageEntry<ApiType>, args: Arg[], range: [Hash, Hash?]): Observable<[Hash, Codec][]> {
|
||||
const outputType = unwrapStorageType(decorated.creator.meta.type, decorated.creator.meta.modifier.isOptional);
|
||||
const outputType = unwrapStorageType(this.#registry, decorated.creator.meta.type, decorated.creator.meta.modifier.isOptional);
|
||||
|
||||
return this._rpcCore.state
|
||||
.queryStorage<[Option<Raw>]>([decorated.key(...args)], ...range)
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/api', version: '5.1.1' };
|
||||
export const packageInfo = { name: '@polkadot/api', version: '5.2.1' };
|
||||
|
||||
@@ -20,79 +20,79 @@ describe('extractStorageArgs', (): void => {
|
||||
|
||||
it('validates no-arg plain', (): void => {
|
||||
expect(
|
||||
extractStorageArgs(storage.timestamp.now, [])
|
||||
extractStorageArgs(registry, storage.timestamp.now, [])
|
||||
).toEqual([storage.timestamp.now]);
|
||||
});
|
||||
|
||||
it('validates no-arg plain (with undefined, undefined)', (): void => {
|
||||
expect(
|
||||
extractStorageArgs(storage.timestamp.now, [undefined, undefined])
|
||||
extractStorageArgs(registry, storage.timestamp.now, [undefined, undefined])
|
||||
).toEqual([storage.timestamp.now]);
|
||||
});
|
||||
|
||||
it('validates no-arg plain (failing when there are args)', (): void => {
|
||||
expect(
|
||||
(): unknown => extractStorageArgs(storage.timestamp.now, [123, 456])
|
||||
(): unknown => extractStorageArgs(registry, storage.timestamp.now, [123, 456])
|
||||
).toThrow('timestamp.now() does not take any arguments, 2 found');
|
||||
});
|
||||
|
||||
it('validates map, 1 arg', (): void => {
|
||||
expect(
|
||||
extractStorageArgs(storage.staking.payee, ['abc'])
|
||||
extractStorageArgs(registry, storage.staking.payee, ['abc'])
|
||||
).toEqual([storage.staking.payee, 'abc']);
|
||||
});
|
||||
|
||||
it('validates map, 1 arg (failing with no args)', (): void => {
|
||||
expect(
|
||||
(): any =>
|
||||
extractStorageArgs(storage.staking.payee, [])
|
||||
extractStorageArgs(registry, storage.staking.payee, [])
|
||||
).toThrow('staking.payee(AccountId) is a map, requiring 1 argument, 0 found');
|
||||
});
|
||||
|
||||
it('validates map, 1 arg (failing with no args)', (): void => {
|
||||
expect(
|
||||
(): any =>
|
||||
extractStorageArgs(storage.staking.payee, ['abc', 'def'])
|
||||
extractStorageArgs(registry, storage.staking.payee, ['abc', 'def'])
|
||||
).toThrow('staking.payee(AccountId) is a map, requiring 1 argument, 2 found');
|
||||
});
|
||||
|
||||
it('validates doublemap, 2 args', (): void => {
|
||||
expect(
|
||||
extractStorageArgs(storage.staking.erasStakers, [1, '0x1234'])
|
||||
extractStorageArgs(registry, storage.staking.erasStakers, [1, '0x1234'])
|
||||
).toEqual([storage.staking.erasStakers, [1, '0x1234']]);
|
||||
});
|
||||
|
||||
it('validates doublemap, 2 args (failing with no args)', (): void => {
|
||||
expect(
|
||||
(): any =>
|
||||
extractStorageArgs(storage.staking.erasStakers, [])
|
||||
extractStorageArgs(registry, storage.staking.erasStakers, [])
|
||||
).toThrow('staking.erasStakers(EraIndex, AccountId) is a double map, requiring 2 arguments, 0 found');
|
||||
});
|
||||
|
||||
it('validates doublemap, 2 args (failing with 1 arg)', (): void => {
|
||||
expect(
|
||||
(): any =>
|
||||
extractStorageArgs(storage.staking.erasStakers, [123])
|
||||
extractStorageArgs(registry, storage.staking.erasStakers, [123])
|
||||
).toThrow('staking.erasStakers(EraIndex, AccountId) is a double map, requiring 2 arguments, 1 found');
|
||||
});
|
||||
|
||||
// Linked maps have been removed
|
||||
it.skip('validates linked map, no args', (): void => {
|
||||
expect(
|
||||
extractStorageArgs(storage.staking.validators, [])
|
||||
extractStorageArgs(registry, storage.staking.validators, [])
|
||||
).toEqual([storage.staking.validators]);
|
||||
});
|
||||
|
||||
it.skip('validates linked map, single arg', (): void => {
|
||||
expect(
|
||||
extractStorageArgs(storage.staking.validators, [123])
|
||||
extractStorageArgs(registry, storage.staking.validators, [123])
|
||||
).toEqual([storage.staking.validators, 123]);
|
||||
});
|
||||
|
||||
it.skip('validates linked map (failing with extra args)', (): void => {
|
||||
expect(
|
||||
(): any[] =>
|
||||
extractStorageArgs(storage.staking.validators, [123, 456])
|
||||
extractStorageArgs(registry, storage.staking.validators, [123, 456])
|
||||
).toThrow('staking.validators(AccountId) is a linked map, requiring either 0 arguments (retrieving all) or 1 argument, 2 found');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,26 +3,27 @@
|
||||
|
||||
import type { Type } from '@polkadot/types';
|
||||
import type { StorageEntry } from '@polkadot/types/primitive/types';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
|
||||
import { assert, isUndefined } from '@polkadot/util';
|
||||
|
||||
function sig ({ method, section }: StorageEntry, args: Type[]): string {
|
||||
function sig (_: Registry, { method, section }: StorageEntry, args: Type[]): string {
|
||||
return `${section}.${method}(${args.join(', ')})`;
|
||||
}
|
||||
|
||||
function doDoubleMap (creator: StorageEntry, args: unknown[]): [StorageEntry, [any, any]] {
|
||||
function doDoubleMap (registry: Registry, creator: StorageEntry, args: unknown[]): [StorageEntry, [any, any]] {
|
||||
const { key1, key2 } = creator.meta.type.asDoubleMap;
|
||||
|
||||
assert(args.length === 2, () => `${sig(creator, [key1, key2])} is a double map, requiring 2 arguments, ${args.length} found`);
|
||||
assert(args.length === 2, () => `${sig(registry, creator, [key1, key2])} is a double map, requiring 2 arguments, ${args.length} found`);
|
||||
|
||||
// pass as tuple
|
||||
return [creator, args as [any, any]];
|
||||
}
|
||||
|
||||
function doMap (creator: StorageEntry, args: unknown[]): [StorageEntry] | [StorageEntry, any] {
|
||||
function doMap (registry: Registry, creator: StorageEntry, args: unknown[]): [StorageEntry] | [StorageEntry, any] {
|
||||
const { key } = creator.meta.type.asMap;
|
||||
|
||||
assert(args.length === 1, () => `${sig(creator, [key])} is a map, requiring 1 argument, ${args.length} found`);
|
||||
assert(args.length === 1, () => `${sig(registry, creator, [key])} is a map, requiring 1 argument, ${args.length} found`);
|
||||
|
||||
// expand
|
||||
return args.length
|
||||
@@ -30,10 +31,10 @@ function doMap (creator: StorageEntry, args: unknown[]): [StorageEntry] | [Stora
|
||||
: [creator];
|
||||
}
|
||||
|
||||
function doNMap (creator: StorageEntry, args: unknown[]): [StorageEntry, any[]] {
|
||||
function doNMap (registry: Registry, creator: StorageEntry, args: unknown[]): [StorageEntry, any[]] {
|
||||
const { keyVec } = creator.meta.type.asNMap;
|
||||
|
||||
assert(args.length === keyVec.length, () => `${sig(creator, keyVec)} is a multi map, requiring ${keyVec.length} arguments, ${args.length} found`);
|
||||
assert(args.length === keyVec.length, () => `${sig(registry, creator, keyVec)} is a multi map, requiring ${keyVec.length} arguments, ${args.length} found`);
|
||||
|
||||
// pass as tuple
|
||||
return [creator, args];
|
||||
@@ -41,18 +42,18 @@ function doNMap (creator: StorageEntry, args: unknown[]): [StorageEntry, any[]]
|
||||
|
||||
// sets up the arguments in the form of [creator, args] ready to be used in a storage
|
||||
// call. Additionally, it verifies that the correct number of arguments have been passed
|
||||
export function extractStorageArgs (creator: StorageEntry, _args: unknown[]): [StorageEntry, any[]] | [StorageEntry] | [StorageEntry, any] {
|
||||
export function extractStorageArgs (registry: Registry, creator: StorageEntry, _args: unknown[]): [StorageEntry, any[]] | [StorageEntry] | [StorageEntry, any] {
|
||||
const args = _args.filter((arg) => !isUndefined(arg));
|
||||
|
||||
if (creator.meta.type.isDoubleMap) {
|
||||
return doDoubleMap(creator, args);
|
||||
return doDoubleMap(registry, creator, args);
|
||||
} else if (creator.meta.type.isMap) {
|
||||
return doMap(creator, args);
|
||||
return doMap(registry, creator, args);
|
||||
} else if (creator.meta.type.isNMap) {
|
||||
return doNMap(creator, args);
|
||||
return doNMap(registry, creator, args);
|
||||
}
|
||||
|
||||
assert(args.length === 0, () => `${sig(creator, [])} does not take any arguments, ${args.length} found`);
|
||||
assert(args.length === 0, () => `${sig(registry, creator, [])} does not take any arguments, ${args.length} found`);
|
||||
|
||||
// no args
|
||||
return [creator];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/rpc-core",
|
||||
"version": "5.1.1",
|
||||
"version": "5.2.1",
|
||||
"type": "module",
|
||||
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
|
||||
"main": "index.js",
|
||||
@@ -19,13 +19,13 @@
|
||||
"bugs": "https://github.com/polkadot-js/api/issues",
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-core#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.6",
|
||||
"@polkadot/rpc-provider": "5.1.1",
|
||||
"@polkadot/types": "5.1.1",
|
||||
"@polkadot/util": "^7.0.2",
|
||||
"@babel/runtime": "^7.14.8",
|
||||
"@polkadot/rpc-provider": "5.2.1",
|
||||
"@polkadot/types": "5.2.1",
|
||||
"@polkadot/util": "^7.0.3",
|
||||
"rxjs": "^7.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^7.0.2"
|
||||
"@polkadot/keyring": "^7.0.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import type { RpcInterface, RpcInterfaceMethod } from './types';
|
||||
|
||||
import { Observable, publishReplay, refCount } from 'rxjs';
|
||||
|
||||
import { createClass, createTypeUnsafe, Option, rpcDefinitions } from '@polkadot/types';
|
||||
import { rpcDefinitions } from '@polkadot/types';
|
||||
import { assert, hexToU8a, isFunction, isNull, isUndefined, logger, memoize, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { drr, refCountDelay } from './util';
|
||||
@@ -339,7 +339,7 @@ export class RpcCore {
|
||||
assert(inputs.length >= reqArgCount && inputs.length <= def.params.length, () => `Expected ${def.params.length} parameters${optText}, ${inputs.length} found instead`);
|
||||
|
||||
return inputs.map((input, index): Codec =>
|
||||
createTypeUnsafe(registry, def.params[index].type, [input], { blockHash })
|
||||
registry.createTypeUnsafe(def.params[index].type, [input], { blockHash })
|
||||
);
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ export class RpcCore {
|
||||
: mapped as unknown as Codec[];
|
||||
}
|
||||
|
||||
return createTypeUnsafe(registry, rpc.type, [result], { blockHash });
|
||||
return registry.createTypeUnsafe(rpc.type, [result], { blockHash });
|
||||
}
|
||||
|
||||
private _formatStorageData (registry: Registry, blockHash: Uint8Array | string | null | undefined, key: StorageKey, value: string | null): Codec {
|
||||
@@ -432,29 +432,15 @@ export class RpcCore {
|
||||
: ` entry ${entryIndex}:`;
|
||||
|
||||
try {
|
||||
if (meta.modifier.isOptional) {
|
||||
let inner = null;
|
||||
|
||||
if (!isEmpty) {
|
||||
inner = createTypeUnsafe(registry, type, [input], { blockHash, isPedantic: true });
|
||||
}
|
||||
|
||||
const option = new Option(registry, createClass(registry, type), inner);
|
||||
|
||||
if (blockHash) {
|
||||
option.createdAtHash = registry.createType('Hash', blockHash);
|
||||
}
|
||||
|
||||
return option;
|
||||
}
|
||||
|
||||
return createTypeUnsafe(registry, type, [
|
||||
return registry.createTypeUnsafe(type, [
|
||||
isEmpty
|
||||
? meta.fallback
|
||||
? hexToU8a(meta.fallback.toHex())
|
||||
: undefined
|
||||
: input
|
||||
], { blockHash, isPedantic: true });
|
||||
: meta.modifier.isOptional
|
||||
? registry.createTypeUnsafe(type, [input], { blockHash, isPedantic: true })
|
||||
: input
|
||||
], { blockHash, isOptional: meta.modifier.isOptional, isPedantic: !meta.modifier.isOptional });
|
||||
} catch (error) {
|
||||
throw new Error(`Unable to decode storage ${key.section || 'unknown'}.${key.method || 'unknown'}:${entryNum}: ${(error as Error).message}`);
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/rpc-core', version: '5.1.1' };
|
||||
export const packageInfo = { name: '@polkadot/rpc-core', version: '5.2.1' };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/rpc-provider",
|
||||
"version": "5.1.1",
|
||||
"version": "5.2.1",
|
||||
"type": "module",
|
||||
"description": "Transport providers for the API",
|
||||
"main": "index.js",
|
||||
@@ -19,18 +19,18 @@
|
||||
"bugs": "https://github.com/polkadot-js/api/issues",
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.6",
|
||||
"@polkadot/types": "5.1.1",
|
||||
"@polkadot/util": "^7.0.2",
|
||||
"@polkadot/util-crypto": "^7.0.2",
|
||||
"@polkadot/x-fetch": "^7.0.2",
|
||||
"@polkadot/x-global": "^7.0.2",
|
||||
"@polkadot/x-ws": "^7.0.2",
|
||||
"@babel/runtime": "^7.14.8",
|
||||
"@polkadot/types": "5.2.1",
|
||||
"@polkadot/util": "^7.0.3",
|
||||
"@polkadot/util-crypto": "^7.0.3",
|
||||
"@polkadot/x-fetch": "^7.0.3",
|
||||
"@polkadot/x-global": "^7.0.3",
|
||||
"@polkadot/x-ws": "^7.0.3",
|
||||
"eventemitter3": "^4.0.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^7.0.2",
|
||||
"@polkadot/types": "5.1.1",
|
||||
"@polkadot/keyring": "^7.0.3",
|
||||
"@polkadot/types": "5.2.1",
|
||||
"mock-socket": "^9.0.3",
|
||||
"nock": "^13.1.1"
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/rpc-provider', version: '5.1.1' };
|
||||
export const packageInfo = { name: '@polkadot/rpc-provider', version: '5.2.1' };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/typegen",
|
||||
"version": "5.1.1",
|
||||
"version": "5.2.1",
|
||||
"type": "module",
|
||||
"description": "Type generation scripts",
|
||||
"main": "index.js",
|
||||
@@ -26,13 +26,13 @@
|
||||
"bugs": "https://github.com/polkadot-js/api/issues",
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/typegen#readme",
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.14.6",
|
||||
"@babel/core": "^7.14.8",
|
||||
"@babel/register": "^7.14.5",
|
||||
"@babel/runtime": "^7.14.6",
|
||||
"@polkadot/api": "5.1.1",
|
||||
"@polkadot/rpc-provider": "5.1.1",
|
||||
"@polkadot/types": "5.1.1",
|
||||
"@polkadot/util": "^7.0.2",
|
||||
"@babel/runtime": "^7.14.8",
|
||||
"@polkadot/api": "5.2.1",
|
||||
"@polkadot/rpc-provider": "5.2.1",
|
||||
"@polkadot/types": "5.2.1",
|
||||
"@polkadot/util": "^7.0.3",
|
||||
"handlebars": "^4.7.7",
|
||||
"websocket": "^1.0.34",
|
||||
"yargs": "^17.0.1"
|
||||
|
||||
@@ -24,7 +24,6 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes,
|
||||
}, {});
|
||||
|
||||
const modules = meta.asLatest.modules
|
||||
.sort(compareName)
|
||||
.filter((mod) => mod.constants.length > 0)
|
||||
.map(({ constants, name }) => {
|
||||
if (!isStrict) {
|
||||
@@ -32,9 +31,8 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes,
|
||||
}
|
||||
|
||||
const items = constants
|
||||
.sort(compareName)
|
||||
.map(({ docs, name, type }) => {
|
||||
const returnType = formatType(allDefs, type.toString(), imports);
|
||||
const returnType = formatType(meta.registry, allDefs, type.toString(), imports);
|
||||
|
||||
setImports(allDefs, imports, [returnType]);
|
||||
|
||||
@@ -43,13 +41,15 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes,
|
||||
name: stringCamelCase(name),
|
||||
type: returnType
|
||||
};
|
||||
});
|
||||
})
|
||||
.sort(compareName);
|
||||
|
||||
return {
|
||||
items,
|
||||
name: stringCamelCase(name)
|
||||
};
|
||||
});
|
||||
})
|
||||
.sort(compareName);
|
||||
|
||||
const types = [
|
||||
...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
|
||||
|
||||
@@ -19,17 +19,17 @@ function generateForMeta (meta: Metadata, dest: string, isStrict: boolean): void
|
||||
const imports = createImports({});
|
||||
|
||||
const modules = meta.asLatest.modules
|
||||
.sort(compareName)
|
||||
.filter((mod) => mod.errors.length > 0)
|
||||
.map(({ errors, name }) => ({
|
||||
items: errors
|
||||
.sort(compareName)
|
||||
.map(({ docs, name }) => ({
|
||||
docs,
|
||||
name: name.toString()
|
||||
})),
|
||||
}))
|
||||
.sort(compareName),
|
||||
name: stringCamelCase(name)
|
||||
}));
|
||||
}))
|
||||
.sort(compareName);
|
||||
|
||||
const types = [
|
||||
{
|
||||
|
||||
@@ -24,14 +24,13 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes,
|
||||
}, {});
|
||||
|
||||
const modules = meta.asLatest.modules
|
||||
.sort(compareName)
|
||||
.filter((mod) => mod.events.isSome)
|
||||
.map(({ events, name }) => ({
|
||||
items: events
|
||||
.unwrap()
|
||||
.sort(compareName)
|
||||
.map(({ args, docs, name }) => {
|
||||
const types = args.map((type) => formatType(allDefs, type.toString(), imports));
|
||||
const types = args.map((type) => formatType(meta.registry, allDefs, type.toString(), imports));
|
||||
|
||||
setImports(allDefs, imports, types);
|
||||
|
||||
@@ -40,9 +39,10 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes,
|
||||
name: name.toString(),
|
||||
type: types.join(', ')
|
||||
};
|
||||
}),
|
||||
}).sort(compareName),
|
||||
name: stringCamelCase(name)
|
||||
}));
|
||||
}))
|
||||
.sort(compareName);
|
||||
|
||||
const types = [
|
||||
...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
|
||||
|
||||
@@ -18,12 +18,12 @@ import { ModuleTypes } from '../util/imports';
|
||||
// From a storage entry metadata, we return [args, returnType]
|
||||
/** @internal */
|
||||
function entrySignature (allDefs: Record<string, ModuleTypes>, registry: Registry, storageEntry: StorageEntryMetadataLatest, imports: TypeImports): [string, string, string] {
|
||||
const outputType = unwrapStorageType(storageEntry.type, storageEntry.modifier.isOptional);
|
||||
const outputType = unwrapStorageType(registry, storageEntry.type, storageEntry.modifier.isOptional);
|
||||
|
||||
if (storageEntry.type.isPlain) {
|
||||
setImports(allDefs, imports, [storageEntry.type.asPlain.toString()]);
|
||||
|
||||
return ['', '', formatType(allDefs, outputType, imports)];
|
||||
return ['', '', formatType(registry, allDefs, outputType, imports)];
|
||||
} else if (storageEntry.type.isMap) {
|
||||
const map = storageEntry.type.asMap;
|
||||
|
||||
@@ -36,9 +36,9 @@ function entrySignature (allDefs: Record<string, ModuleTypes>, registry: Registr
|
||||
]);
|
||||
|
||||
return [
|
||||
formatType(allDefs, map.key.toString(), imports),
|
||||
formatType(registry, allDefs, map.key.toString(), imports),
|
||||
`arg: ${similarTypes.join(' | ')}`,
|
||||
formatType(allDefs, outputType, imports)
|
||||
formatType(registry, allDefs, outputType, imports)
|
||||
];
|
||||
} else if (storageEntry.type.isDoubleMap) {
|
||||
const dm = storageEntry.type.asDoubleMap;
|
||||
@@ -57,9 +57,12 @@ function entrySignature (allDefs: Record<string, ModuleTypes>, registry: Registr
|
||||
const key2Types = similarTypes2.join(' | ');
|
||||
|
||||
return [
|
||||
[formatType(allDefs, dm.key1.toString(), imports), formatType(allDefs, dm.key2.toString(), imports)].join(', '),
|
||||
[
|
||||
formatType(registry, allDefs, dm.key1.toString(), imports),
|
||||
formatType(registry, allDefs, dm.key2.toString(), imports)
|
||||
].join(', '),
|
||||
`arg1: ${key1Types}, arg2: ${key2Types}`,
|
||||
formatType(allDefs, outputType, imports)
|
||||
formatType(registry, allDefs, outputType, imports)
|
||||
];
|
||||
} else if (storageEntry.type.isNMap) {
|
||||
const nmap = storageEntry.type.asNMap;
|
||||
@@ -75,9 +78,9 @@ function entrySignature (allDefs: Record<string, ModuleTypes>, registry: Registr
|
||||
const keyTypes = similarTypes.map((t) => t.join(' | '));
|
||||
|
||||
return [
|
||||
nmap.keyVec.map((k) => formatType(allDefs, k.toString(), imports)).join(', '),
|
||||
nmap.keyVec.map((k) => formatType(registry, allDefs, k.toString(), imports)).join(', '),
|
||||
keyTypes.map((t, i) => `arg${i + 1}: ${t}`).join(', '),
|
||||
formatType(allDefs, outputType, imports)
|
||||
formatType(registry, allDefs, outputType, imports)
|
||||
];
|
||||
}
|
||||
|
||||
@@ -101,7 +104,6 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
|
||||
.filter((mod) => !mod.storage.isNone)
|
||||
.map(({ name, storage }) => {
|
||||
const items = storage.unwrap().items
|
||||
.sort(compareName)
|
||||
.map((storageEntry) => {
|
||||
const [args, params, returnType] = entrySignature(allDefs, registry, storageEntry, imports);
|
||||
|
||||
@@ -113,13 +115,15 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
|
||||
params,
|
||||
returnType
|
||||
};
|
||||
});
|
||||
})
|
||||
.sort(compareName);
|
||||
|
||||
return {
|
||||
items,
|
||||
name: stringCamelCase(name)
|
||||
};
|
||||
});
|
||||
})
|
||||
.sort(compareName);
|
||||
|
||||
imports.typesTypes.Observable = true;
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ export function generateRpcTypes (registry: TypeRegistry, importDefinitions: Rec
|
||||
return `${param.name}${param.isOptional ? '?' : ''}: ${similarTypes.join(' | ')}`;
|
||||
});
|
||||
|
||||
type = formatType(allDefs, def.type, imports);
|
||||
type = formatType(registry, allDefs, def.type, imports);
|
||||
generic = '';
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { TypeDef } from '@polkadot/types/create/types';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
import type { ModuleTypes } from '../util/imports';
|
||||
|
||||
import Handlebars from 'handlebars';
|
||||
import path from 'path';
|
||||
|
||||
import { getTypeDef } from '@polkadot/types/create';
|
||||
import { getTypeDef, TypeRegistry } from '@polkadot/types/create';
|
||||
import { TypeDefInfo } from '@polkadot/types/create/types';
|
||||
import * as defaultDefinitions from '@polkadot/types/interfaces/definitions';
|
||||
import { assert, isString, stringCamelCase, stringify, stringUpperFirst } from '@polkadot/util';
|
||||
@@ -28,13 +29,13 @@ export function createGetter (definitions: Record<string, ModuleTypes>, name = '
|
||||
|
||||
/** @internal */
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function errorUnhandled (definitions: Record<string, ModuleTypes>, def: TypeDef, imports: TypeImports): string {
|
||||
function errorUnhandled (_: Registry, definitions: Record<string, ModuleTypes>, def: TypeDef, imports: TypeImports): string {
|
||||
throw new Error(`Generate: ${def.name || ''}: Unhandled type ${TypeDefInfo[def.info]}`);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function tsExport (definitions: Record<string, ModuleTypes>, def: TypeDef, imports: TypeImports): string {
|
||||
return exportInterface(def.name, formatType(definitions, def, imports));
|
||||
function tsExport (registry: Registry, definitions: Record<string, ModuleTypes>, def: TypeDef, imports: TypeImports): string {
|
||||
return exportInterface(def.name, formatType(registry, definitions, def, imports));
|
||||
}
|
||||
|
||||
const tsBTreeMap = tsExport;
|
||||
@@ -47,7 +48,7 @@ const tsPlain = tsExport;
|
||||
const tsTuple = tsExport;
|
||||
|
||||
/** @internal */
|
||||
function tsEnum (definitions: Record<string, ModuleTypes>, { name: enumName, sub }: TypeDef, imports: TypeImports): string {
|
||||
function tsEnum (registry: Registry, definitions: Record<string, ModuleTypes>, { name: enumName, sub }: TypeDef, imports: TypeImports): string {
|
||||
setImports(definitions, imports, ['Enum']);
|
||||
|
||||
const keys = (sub as TypeDef[]).map((def, index): string => {
|
||||
@@ -56,7 +57,7 @@ function tsEnum (definitions: Record<string, ModuleTypes>, { name: enumName, sub
|
||||
const isComplex = [TypeDefInfo.Struct, TypeDefInfo.Tuple, TypeDefInfo.Vec, TypeDefInfo.VecFixed].includes(info);
|
||||
const asGetter = type === 'Null' || info === TypeDefInfo.DoNotConstruct
|
||||
? ''
|
||||
: createGetter(definitions, `as${getter}`, isComplex ? formatType(definitions, info === TypeDefInfo.Struct ? def : type, imports) : type, imports);
|
||||
: createGetter(definitions, `as${getter}`, isComplex ? formatType(registry, definitions, info === TypeDefInfo.Struct ? def : type, imports) : type, imports);
|
||||
const isGetter = info === TypeDefInfo.DoNotConstruct
|
||||
? ''
|
||||
: createGetter(definitions, `is${getter}`, 'boolean', imports);
|
||||
@@ -82,18 +83,18 @@ function tsEnum (definitions: Record<string, ModuleTypes>, { name: enumName, sub
|
||||
return exportInterface(enumName, 'Enum', keys.join(''));
|
||||
}
|
||||
|
||||
function tsInt (definitions: Record<string, ModuleTypes>, def: TypeDef, imports: TypeImports, type: 'Int' | 'UInt' = 'Int'): string {
|
||||
function tsInt (_: Registry, definitions: Record<string, ModuleTypes>, def: TypeDef, imports: TypeImports, type: 'Int' | 'UInt' = 'Int'): string {
|
||||
setImports(definitions, imports, [type]);
|
||||
|
||||
return exportInterface(def.name, type);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function tsResultGetter (definitions: Record<string, ModuleTypes>, resultName = '', getter: 'Ok' | 'Err' | 'Error', def: TypeDef, imports: TypeImports): string {
|
||||
function tsResultGetter (registry: Registry, definitions: Record<string, ModuleTypes>, resultName = '', getter: 'Ok' | 'Err' | 'Error', def: TypeDef, imports: TypeImports): string {
|
||||
const { info, type } = def;
|
||||
const asGetter = type === 'Null'
|
||||
? ''
|
||||
: (getter === 'Error' ? ' /** @deprecated Use asErr */\n' : '') + createGetter(definitions, `as${getter}`, info === TypeDefInfo.Tuple ? formatType(definitions, def, imports) : type, imports);
|
||||
: (getter === 'Error' ? ' /** @deprecated Use asErr */\n' : '') + createGetter(definitions, `as${getter}`, info === TypeDefInfo.Tuple ? formatType(registry, definitions, def, imports) : type, imports);
|
||||
const isGetter = (getter === 'Error' ? ' /** @deprecated Use isErr */\n' : '') + createGetter(definitions, `is${getter}`, 'boolean', imports);
|
||||
|
||||
switch (info) {
|
||||
@@ -109,28 +110,28 @@ function tsResultGetter (definitions: Record<string, ModuleTypes>, resultName =
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function tsResult (definitions: Record<string, ModuleTypes>, def: TypeDef, imports: TypeImports): string {
|
||||
function tsResult (registry: Registry, definitions: Record<string, ModuleTypes>, def: TypeDef, imports: TypeImports): string {
|
||||
const [okDef, errorDef] = (def.sub as TypeDef[]);
|
||||
const inner = [
|
||||
tsResultGetter(definitions, def.name, 'Err', errorDef, imports),
|
||||
tsResultGetter(registry, definitions, def.name, 'Err', errorDef, imports),
|
||||
// @deprecated, use Err
|
||||
tsResultGetter(definitions, def.name, 'Error', errorDef, imports),
|
||||
tsResultGetter(definitions, def.name, 'Ok', okDef, imports)
|
||||
tsResultGetter(registry, definitions, def.name, 'Error', errorDef, imports),
|
||||
tsResultGetter(registry, definitions, def.name, 'Ok', okDef, imports)
|
||||
].join('');
|
||||
|
||||
setImports(definitions, imports, [def.type]);
|
||||
|
||||
return exportInterface(def.name, formatType(definitions, def, imports), inner);
|
||||
return exportInterface(def.name, formatType(registry, definitions, def, imports), inner);
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function tsSi (definitions: Record<string, ModuleTypes>, { type }: TypeDef, imports: TypeImports): string {
|
||||
function tsSi (registry: Registry, definitions: Record<string, ModuleTypes>, { type }: TypeDef, imports: TypeImports): string {
|
||||
throw new Error('Unable to generate string definition from TypeDefInfo.Si');
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function tsSet (definitions: Record<string, ModuleTypes>, { name: setName, sub }: TypeDef, imports: TypeImports): string {
|
||||
function tsSet (_: Registry, definitions: Record<string, ModuleTypes>, { name: setName, sub }: TypeDef, imports: TypeImports): string {
|
||||
setImports(definitions, imports, ['Set']);
|
||||
|
||||
const types = (sub as TypeDef[]).map(({ name }): string => {
|
||||
@@ -143,11 +144,11 @@ function tsSet (definitions: Record<string, ModuleTypes>, { name: setName, sub }
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function tsStruct (definitions: Record<string, ModuleTypes>, { name: structName, sub }: TypeDef, imports: TypeImports): string {
|
||||
function tsStruct (registry: Registry, definitions: Record<string, ModuleTypes>, { name: structName, sub }: TypeDef, imports: TypeImports): string {
|
||||
setImports(definitions, imports, ['Struct']);
|
||||
|
||||
const keys = (sub as TypeDef[]).map((typedef): string => {
|
||||
const returnType = formatType(definitions, typedef, imports);
|
||||
const returnType = formatType(registry, definitions, typedef, imports);
|
||||
|
||||
return createGetter(definitions, typedef.name, returnType, imports);
|
||||
});
|
||||
@@ -156,12 +157,12 @@ function tsStruct (definitions: Record<string, ModuleTypes>, { name: structName,
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function tsUInt (definitions: Record<string, ModuleTypes>, def: TypeDef, imports: TypeImports): string {
|
||||
return tsInt(definitions, def, imports, 'UInt');
|
||||
function tsUInt (registry: Registry, definitions: Record<string, ModuleTypes>, def: TypeDef, imports: TypeImports): string {
|
||||
return tsInt(registry, definitions, def, imports, 'UInt');
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function tsVec (definitions: Record<string, ModuleTypes>, def: TypeDef, imports: TypeImports): string {
|
||||
function tsVec (registry: Registry, definitions: Record<string, ModuleTypes>, def: TypeDef, imports: TypeImports): string {
|
||||
const type = (def.sub as TypeDef).type;
|
||||
|
||||
if (def.info === TypeDefInfo.VecFixed && type === 'u8') {
|
||||
@@ -170,13 +171,13 @@ function tsVec (definitions: Record<string, ModuleTypes>, def: TypeDef, imports:
|
||||
return exportType(def.name, 'U8aFixed');
|
||||
}
|
||||
|
||||
return exportInterface(def.name, formatType(definitions, def, imports));
|
||||
return exportInterface(def.name, formatType(registry, definitions, def, imports));
|
||||
}
|
||||
|
||||
// handlers are defined externally to use - this means that when we do a
|
||||
// `generators[typedef.info](...)` TS will show any unhandled types. Rather
|
||||
// we are being explicit in having no handlers where we do not support (yet)
|
||||
const encoders: Record<TypeDefInfo, (definitions: Record<string, ModuleTypes>, def: TypeDef, imports: TypeImports) => string> = {
|
||||
const encoders: Record<TypeDefInfo, (registry: Registry, definitions: Record<string, ModuleTypes>, def: TypeDef, imports: TypeImports) => string> = {
|
||||
[TypeDefInfo.BTreeMap]: tsBTreeMap,
|
||||
[TypeDefInfo.BTreeSet]: tsBTreeSet,
|
||||
[TypeDefInfo.Compact]: tsCompact,
|
||||
@@ -199,11 +200,11 @@ const encoders: Record<TypeDefInfo, (definitions: Record<string, ModuleTypes>, d
|
||||
};
|
||||
|
||||
/** @internal */
|
||||
function generateInterfaces (definitions: Record<string, ModuleTypes>, { types }: { types: Record<string, any> }, imports: Imports): [string, string][] {
|
||||
function generateInterfaces (registry: Registry, definitions: Record<string, ModuleTypes>, { types }: { types: Record<string, any> }, imports: Imports): [string, string][] {
|
||||
return Object.entries(types).map(([name, type]): [string, string] => {
|
||||
const def = getTypeDef(isString(type) ? type : stringify(type), { name });
|
||||
|
||||
return [name, encoders[def.info](definitions, def, imports)];
|
||||
return [name, encoders[def.info](registry, definitions, def, imports)];
|
||||
});
|
||||
}
|
||||
|
||||
@@ -217,10 +218,10 @@ const templateTypes = readTemplate('tsDef/types');
|
||||
const generateTsDefTypesTemplate = Handlebars.compile(templateTypes);
|
||||
|
||||
/** @internal */
|
||||
function generateTsDefFor (importDefinitions: { [importPath: string]: Record<string, ModuleTypes> }, defName: string, { types }: { types: Record<string, any> }, outputDir: string): void {
|
||||
function generateTsDefFor (registry: Registry, importDefinitions: { [importPath: string]: Record<string, ModuleTypes> }, defName: string, { types }: { types: Record<string, any> }, outputDir: string): void {
|
||||
const imports = { ...createImports(importDefinitions, { types }), interfaces: [] } as Imports;
|
||||
const definitions = imports.definitions;
|
||||
const interfaces = generateInterfaces(definitions, { types }, imports);
|
||||
const interfaces = generateInterfaces(registry, definitions, { types }, imports);
|
||||
const items = interfaces.sort((a, b): number => a[0].localeCompare(b[0])).map(([, definition]): string => definition);
|
||||
|
||||
const importTypes = [
|
||||
@@ -242,13 +243,15 @@ function generateTsDefFor (importDefinitions: { [importPath: string]: Record<str
|
||||
|
||||
/** @internal */
|
||||
export function generateTsDef (importDefinitions: { [importPath: string]: Record<string, ModuleTypes> }, outputDir: string, generatingPackage: string): void {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
writeFile(path.join(outputDir, 'types.ts'), (): string => {
|
||||
const definitions = importDefinitions[generatingPackage];
|
||||
|
||||
Object.entries(definitions).forEach(([defName, obj]): void => {
|
||||
console.log(`\tExtracting interfaces for ${defName}`);
|
||||
|
||||
generateTsDefFor(importDefinitions, defName, obj, outputDir);
|
||||
generateTsDefFor(registry, importDefinitions, defName, obj, outputDir);
|
||||
});
|
||||
|
||||
return generateTsDefTypesTemplate({
|
||||
|
||||
@@ -37,13 +37,11 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
|
||||
}, {});
|
||||
|
||||
const modules = meta.asLatest.modules
|
||||
.sort(compareName)
|
||||
.filter(({ calls }) => calls.unwrapOr([]).length !== 0)
|
||||
.map(({ calls, name }) => {
|
||||
setImports(allDefs, imports, ['Call', 'Extrinsic', 'SubmittableExtrinsic']);
|
||||
|
||||
const items = calls.unwrap()
|
||||
.sort(compareName)
|
||||
.map(({ args, docs, name }) => {
|
||||
const params = args
|
||||
.map(({ name, type }) => {
|
||||
@@ -57,18 +55,20 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
|
||||
.join(', ');
|
||||
|
||||
return {
|
||||
args: args.map(({ type }) => formatType(allDefs, type.toString(), imports)).join(', '),
|
||||
args: args.map(({ type }) => formatType(registry, allDefs, type.toString(), imports)).join(', '),
|
||||
docs,
|
||||
name: stringCamelCase(name),
|
||||
params
|
||||
};
|
||||
});
|
||||
})
|
||||
.sort(compareName);
|
||||
|
||||
return {
|
||||
items,
|
||||
name: stringCamelCase(name)
|
||||
};
|
||||
});
|
||||
})
|
||||
.sort(compareName);
|
||||
|
||||
const types = [
|
||||
...Object.keys(imports.localTypes).sort().map((packagePath): { file: string; types: string[] } => ({
|
||||
|
||||
@@ -211,7 +211,7 @@ function addStorage (metadata: MetadataLatest): string {
|
||||
? ('`' + func.type.asNMap.keyVec.map((k) => k.toString()).join(', ') + '`')
|
||||
: '';
|
||||
const methodName = stringLowerFirst(func.name);
|
||||
const outputType = unwrapStorageType(func.type, func.modifier.isOptional);
|
||||
const outputType = unwrapStorageType(metadata.registry, func.type, func.modifier.isOptional);
|
||||
|
||||
return {
|
||||
interface: '`' + `api.query.${sectionName}.${methodName}` + '`',
|
||||
@@ -234,7 +234,7 @@ function addStorage (metadata: MetadataLatest): string {
|
||||
? ('`' + meta.type.asDoubleMap.key1.toString() + ', ' + meta.type.asDoubleMap.key2.toString() + '`')
|
||||
: '';
|
||||
const methodName = stringLowerFirst(name);
|
||||
const outputType = unwrapStorageType(meta.type, meta.modifier.isOptional);
|
||||
const outputType = unwrapStorageType(metadata.registry, meta.type, meta.modifier.isOptional);
|
||||
|
||||
return {
|
||||
interface: '`' + `api.query.substrate.${methodName}` + '`',
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/typegen', version: '5.1.1' };
|
||||
export const packageInfo = { name: '@polkadot/typegen', version: '5.2.1' };
|
||||
|
||||
@@ -54,7 +54,7 @@ export function getDerivedTypes (registry: Registry, definitions: Record<string,
|
||||
});
|
||||
}
|
||||
|
||||
const result = types.map((t) => formatType(definitions, t, imports)).map((t) => `'${t}': ${t};`);
|
||||
const result = types.map((t) => formatType(registry, definitions, t, imports)).map((t) => `'${t}': ${t};`);
|
||||
|
||||
result.unshift(`${type}: ${type};`);
|
||||
|
||||
@@ -68,7 +68,7 @@ export function getDerivedTypes (registry: Registry, definitions: Record<string,
|
||||
export function getSimilarTypes (registry: Registry, definitions: Record<string, ModuleTypes>, _type: string, imports: TypeImports): string[] {
|
||||
const typeParts = _type.split('::');
|
||||
const type = typeParts[typeParts.length - 1];
|
||||
const possibleTypes = [formatType(definitions, type, imports)];
|
||||
const possibleTypes = [formatType(registry, definitions, type, imports)];
|
||||
|
||||
if (type === 'Extrinsic') {
|
||||
setImports(definitions, imports, ['IExtrinsic']);
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
// Copyright 2017-2021 @polkadot/typegen authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TypeRegistry } from '@polkadot/types';
|
||||
|
||||
import { formatType } from './formatting';
|
||||
|
||||
describe('formatType', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
it('handles nested Tuples', (): void => {
|
||||
expect(
|
||||
formatType({}, '(AccountId, (Balance, u32), u64)', {
|
||||
formatType(registry, {}, '(AccountId, (Balance, u32), u64)', {
|
||||
codecTypes: {},
|
||||
definitions: {},
|
||||
extrinsicTypes: {},
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/typegen authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
|
||||
import type { TypeDef } from '@polkadot/types/create/types';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
|
||||
import Handlebars from 'handlebars';
|
||||
|
||||
@@ -83,100 +86,126 @@ export function exportType (name = '', base: string): string {
|
||||
return exportInterface(name, base);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the inner `K` & `V`, return a `BTreeMap<K, V>` string
|
||||
*/
|
||||
/** @internal */
|
||||
function formatBTreeMap (key: string, val: string): string {
|
||||
return `BTreeMap<${key}, ${val}>`;
|
||||
}
|
||||
const formatters: Record<TypeDefInfo, (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => string> = {
|
||||
[TypeDefInfo.Compact]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => {
|
||||
setImports(definitions, imports, ['Compact']);
|
||||
|
||||
/**
|
||||
* Given the inner `V`, return a `BTreeSet<V>` string
|
||||
*/
|
||||
/** @internal */
|
||||
function formatBTreeSet (val: string): string {
|
||||
return `BTreeSet<${val}>`;
|
||||
}
|
||||
return paramsNotation('Compact', formatType(registry, definitions, (typeDef.sub as TypeDef).type, imports));
|
||||
},
|
||||
[TypeDefInfo.DoNotConstruct]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => {
|
||||
setImports(definitions, imports, ['DoNotConstruct']);
|
||||
|
||||
/**
|
||||
* Given the inner `T`, return a `Compact<T>` string
|
||||
*/
|
||||
/** @internal */
|
||||
function formatCompact (inner: string): string {
|
||||
return paramsNotation('Compact', inner);
|
||||
}
|
||||
return 'DoNotConstruct';
|
||||
},
|
||||
[TypeDefInfo.Enum]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => {
|
||||
throw new Error(`TypeDefInfo.Enum: Not implemented on ${stringify(typeDef)}`);
|
||||
},
|
||||
[TypeDefInfo.Int]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => {
|
||||
throw new Error(`TypeDefInfo.Int: Not implemented on ${stringify(typeDef)}`);
|
||||
},
|
||||
[TypeDefInfo.UInt]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => {
|
||||
throw new Error(`TypeDefInfo.UInt: Not implemented on ${stringify(typeDef)}`);
|
||||
},
|
||||
[TypeDefInfo.Null]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => {
|
||||
setImports(definitions, imports, ['Null']);
|
||||
|
||||
/**
|
||||
* Simple return
|
||||
*/
|
||||
/** @internal */
|
||||
function formatDoNoConstruct (): string {
|
||||
return 'DoNotConstruct';
|
||||
}
|
||||
return 'Null';
|
||||
},
|
||||
[TypeDefInfo.Option]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => {
|
||||
setImports(definitions, imports, ['Option']);
|
||||
|
||||
/**
|
||||
* Given the inner `K` & `V`, return a `BTreeMap<K, V>` string
|
||||
*/
|
||||
/** @internal */
|
||||
function formatHashMap (key: string, val: string): string {
|
||||
return `HashMap<${key}, ${val}>`;
|
||||
}
|
||||
return paramsNotation('Option', formatType(registry, definitions, (typeDef.sub as TypeDef).type, imports));
|
||||
},
|
||||
[TypeDefInfo.Plain]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => {
|
||||
return typeDef.type;
|
||||
},
|
||||
[TypeDefInfo.Set]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => {
|
||||
throw new Error(`TypeDefInfo.Set: Not implemented on ${stringify(typeDef)}`);
|
||||
},
|
||||
[TypeDefInfo.Si]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => {
|
||||
throw new Error(`TypeDefInfo.Si: Not implemented on ${stringify(typeDef)}`);
|
||||
},
|
||||
[TypeDefInfo.Struct]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => {
|
||||
setImports(definitions, imports, ['Struct']);
|
||||
|
||||
/**
|
||||
* Given the inner `T`, return a `Vec<T>` string
|
||||
*/
|
||||
/** @internal */
|
||||
function formatLinkage (inner: string): string {
|
||||
return paramsNotation('Linkage', inner);
|
||||
}
|
||||
return `{ ${
|
||||
((typeDef.sub as TypeDef[]).map(({ name, type }, index) => [
|
||||
name || `unknown${index}`,
|
||||
formatType(registry, definitions, type, imports)
|
||||
])).map(([k, t]) => `${k}: ${t};`).join(' ')
|
||||
} } & Struct`;
|
||||
},
|
||||
[TypeDefInfo.Tuple]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => {
|
||||
setImports(definitions, imports, ['ITuple']);
|
||||
|
||||
/**
|
||||
* Given the inner `T`, return a `Option<T>` string
|
||||
*/
|
||||
/** @internal */
|
||||
function formatOption (inner: string): string {
|
||||
return paramsNotation('Option', inner);
|
||||
}
|
||||
// `(a,b)` gets transformed into `ITuple<[a, b]>`
|
||||
return paramsNotation('ITuple', `[${
|
||||
((typeDef.sub as TypeDef[]).map(({ type }) =>
|
||||
formatType(registry, definitions, type, imports))
|
||||
).join(', ')
|
||||
}]`);
|
||||
},
|
||||
[TypeDefInfo.Vec]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => {
|
||||
setImports(definitions, imports, ['Vec']);
|
||||
|
||||
/**
|
||||
* Given the inner `O` & `E`, return a `Result<O, E>` string
|
||||
*/
|
||||
/** @internal */
|
||||
function formatResult (innerOk: string, innerError: string): string {
|
||||
return `Result<${innerOk}, ${innerError}>`;
|
||||
}
|
||||
return paramsNotation('Vec', formatType(registry, definitions, (typeDef.sub as TypeDef).type, imports));
|
||||
},
|
||||
[TypeDefInfo.VecFixed]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => {
|
||||
const type = (typeDef.sub as TypeDef).type;
|
||||
|
||||
/**
|
||||
* Given the entries `[string, T][]`, return a `{ name: T; ... }` string
|
||||
*/
|
||||
/** @internal */
|
||||
function formatStruct (inners: [string, string][]): string {
|
||||
return `{ ${inners.map(([k, t]) => `${k}: ${t};`).join(' ')} } & Struct`;
|
||||
}
|
||||
if (type === 'u8') {
|
||||
setImports(definitions, imports, ['U8aFixed']);
|
||||
|
||||
/**
|
||||
* Given the inners `T[]`, return a `ITuple<...T>` string
|
||||
*/
|
||||
/** @internal */
|
||||
function formatTuple (inners: string[]): string {
|
||||
return paramsNotation('ITuple', `[${inners.join(', ')}]`);
|
||||
}
|
||||
return 'U8aFixed';
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the inner `T`, return a `Vec<T>` string
|
||||
*/
|
||||
/** @internal */
|
||||
function formatVec (inner: string): string {
|
||||
return paramsNotation('Vec', inner);
|
||||
}
|
||||
setImports(definitions, imports, ['Vec']);
|
||||
|
||||
return paramsNotation('Vec', formatType(registry, definitions, type, imports));
|
||||
},
|
||||
[TypeDefInfo.BTreeMap]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => {
|
||||
setImports(definitions, imports, ['BTreeMap']);
|
||||
|
||||
const [keyDef, valDef] = (typeDef.sub as TypeDef[]);
|
||||
|
||||
return `BTreeMap<${formatType(registry, definitions, keyDef.type, imports)}, ${formatType(registry, definitions, valDef.type, imports)}>`;
|
||||
},
|
||||
[TypeDefInfo.BTreeSet]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => {
|
||||
setImports(definitions, imports, ['BTreeSet']);
|
||||
|
||||
const valDef = typeDef.sub as TypeDef;
|
||||
|
||||
return `BTreeSet<${formatType(registry, definitions, valDef.type, imports)}>`;
|
||||
},
|
||||
[TypeDefInfo.HashMap]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => {
|
||||
setImports(definitions, imports, ['HashMap']);
|
||||
|
||||
const [keyDef, valDef] = (typeDef.sub as TypeDef[]);
|
||||
|
||||
return `HashMap<${formatType(registry, definitions, keyDef.type, imports)}, ${formatType(registry, definitions, valDef.type, imports)}>`;
|
||||
},
|
||||
[TypeDefInfo.Linkage]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => {
|
||||
const type = (typeDef.sub as TypeDef).type;
|
||||
|
||||
setImports(definitions, imports, ['Linkage']);
|
||||
|
||||
return paramsNotation('Linkage', formatType(registry, definitions, type, imports));
|
||||
},
|
||||
[TypeDefInfo.Result]: (registry: Registry, typeDef: TypeDef, definitions: Record<string, ModuleTypes>, imports: TypeImports) => {
|
||||
setImports(definitions, imports, ['Result']);
|
||||
|
||||
const [okDef, errorDef] = (typeDef.sub as TypeDef[]);
|
||||
|
||||
return `Result<${formatType(registry, definitions, okDef.type, imports)}, ${formatType(registry, definitions, errorDef.type, imports)}>`;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Correctly format a given type
|
||||
*/
|
||||
/** @internal */
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
export function formatType (definitions: Record<string, ModuleTypes>, type: string | String | TypeDef, imports: TypeImports): string {
|
||||
export function formatType (registry: Registry, definitions: Record<string, ModuleTypes>, type: string | String | TypeDef, imports: TypeImports): string {
|
||||
let typeDef: TypeDef;
|
||||
|
||||
if (isString(type)) {
|
||||
@@ -195,112 +224,5 @@ export function formatType (definitions: Record<string, ModuleTypes>, type: stri
|
||||
|
||||
setImports(definitions, imports, [typeDef.type]);
|
||||
|
||||
// FIXME Swap to Record<TypeDefInfo, fn> to check all types
|
||||
switch (typeDef.info) {
|
||||
case TypeDefInfo.Compact: {
|
||||
setImports(definitions, imports, ['Compact']);
|
||||
|
||||
return formatCompact(formatType(definitions, (typeDef.sub as TypeDef).type, imports));
|
||||
}
|
||||
|
||||
case TypeDefInfo.DoNotConstruct: {
|
||||
setImports(definitions, imports, ['DoNotConstruct']);
|
||||
|
||||
return formatDoNoConstruct();
|
||||
}
|
||||
|
||||
case TypeDefInfo.Option: {
|
||||
setImports(definitions, imports, ['Option']);
|
||||
|
||||
return formatOption(formatType(definitions, (typeDef.sub as TypeDef).type, imports));
|
||||
}
|
||||
|
||||
case TypeDefInfo.Plain: {
|
||||
return typeDef.type;
|
||||
}
|
||||
|
||||
case TypeDefInfo.Struct: {
|
||||
setImports(definitions, imports, ['Struct']);
|
||||
|
||||
return formatStruct(
|
||||
((typeDef.sub as TypeDef[]).map(({ name, type }, index) => [
|
||||
name || `unknown${index}`,
|
||||
formatType(definitions, type, imports)
|
||||
]))
|
||||
);
|
||||
}
|
||||
|
||||
case TypeDefInfo.Tuple: {
|
||||
setImports(definitions, imports, ['ITuple']);
|
||||
|
||||
// `(a,b)` gets transformed into `ITuple<[a, b]>`
|
||||
return formatTuple(
|
||||
((typeDef.sub as TypeDef[]).map(({ type }) => formatType(definitions, type, imports)))
|
||||
);
|
||||
}
|
||||
|
||||
case TypeDefInfo.Vec: {
|
||||
setImports(definitions, imports, ['Vec']);
|
||||
|
||||
return formatVec(formatType(definitions, (typeDef.sub as TypeDef).type, imports));
|
||||
}
|
||||
|
||||
case TypeDefInfo.VecFixed: {
|
||||
const type = (typeDef.sub as TypeDef).type;
|
||||
|
||||
if (type === 'u8') {
|
||||
setImports(definitions, imports, ['U8aFixed']);
|
||||
|
||||
return 'U8aFixed';
|
||||
}
|
||||
|
||||
setImports(definitions, imports, ['Vec']);
|
||||
|
||||
return formatVec(formatType(definitions, type, imports));
|
||||
}
|
||||
|
||||
case TypeDefInfo.BTreeMap: {
|
||||
setImports(definitions, imports, ['BTreeMap']);
|
||||
|
||||
const [keyDef, valDef] = (typeDef.sub as TypeDef[]);
|
||||
|
||||
return formatBTreeMap(formatType(definitions, keyDef.type, imports), formatType(definitions, valDef.type, imports));
|
||||
}
|
||||
|
||||
case TypeDefInfo.BTreeSet: {
|
||||
setImports(definitions, imports, ['BTreeSet']);
|
||||
|
||||
const valDef = typeDef.sub as TypeDef;
|
||||
|
||||
return formatBTreeSet(formatType(definitions, valDef.type, imports));
|
||||
}
|
||||
|
||||
case TypeDefInfo.HashMap: {
|
||||
setImports(definitions, imports, ['HashMap']);
|
||||
|
||||
const [keyDef, valDef] = (typeDef.sub as TypeDef[]);
|
||||
|
||||
return formatHashMap(formatType(definitions, keyDef.type, imports), formatType(definitions, valDef.type, imports));
|
||||
}
|
||||
|
||||
case TypeDefInfo.Linkage: {
|
||||
const type = (typeDef.sub as TypeDef).type;
|
||||
|
||||
setImports(definitions, imports, ['Linkage']);
|
||||
|
||||
return formatLinkage(formatType(definitions, type, imports));
|
||||
}
|
||||
|
||||
case TypeDefInfo.Result: {
|
||||
setImports(definitions, imports, ['Result']);
|
||||
|
||||
const [okDef, errorDef] = (typeDef.sub as TypeDef[]);
|
||||
|
||||
return formatResult(formatType(definitions, okDef.type, imports), formatType(definitions, errorDef.type, imports));
|
||||
}
|
||||
|
||||
default: {
|
||||
throw new Error(`Cannot format ${stringify(type)}`);
|
||||
}
|
||||
}
|
||||
return formatters[typeDef.info](registry, typeDef, definitions, imports);
|
||||
}
|
||||
|
||||
@@ -9,5 +9,8 @@ export * from './imports';
|
||||
export * from './initMeta';
|
||||
export * from './register';
|
||||
|
||||
export const compareName = (a: { name: { toString(): string } }, b: { name: { toString(): string } }): number =>
|
||||
a.name.toString().localeCompare(b.name.toString());
|
||||
type Cmp = { name: { toString(): string } };
|
||||
|
||||
export function compareName (a: Cmp, b: Cmp): number {
|
||||
return a.name.toString().localeCompare(b.name.toString());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/types-known",
|
||||
"version": "5.1.1",
|
||||
"version": "5.2.1",
|
||||
"type": "module",
|
||||
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
|
||||
"main": "index.js",
|
||||
@@ -19,9 +19,9 @@
|
||||
"bugs": "https://github.com/polkadot-js/api/issues",
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types-known#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.6",
|
||||
"@polkadot/networks": "^7.0.2",
|
||||
"@polkadot/types": "5.1.1",
|
||||
"@polkadot/util": "^7.0.2"
|
||||
"@babel/runtime": "^7.14.8",
|
||||
"@polkadot/networks": "^7.0.3",
|
||||
"@polkadot/types": "5.2.1",
|
||||
"@polkadot/util": "^7.0.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import typesModules from './modules';
|
||||
import typesSpec from './spec';
|
||||
import upgrades from './upgrades';
|
||||
|
||||
export { knownOrigins } from './knownOrigins';
|
||||
export { packageInfo } from './packageInfo';
|
||||
|
||||
// flatten a VersionedType[] into a Record<string, string>
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// We want predictive ordering (manually managed)
|
||||
/* eslint-disable sort-keys */
|
||||
|
||||
// FIXME: Need some sort of solution for specifying these
|
||||
// Since we don't have insight into the origin specification, we can only define what we know about
|
||||
// in a pure Substrate/Polkadot implementation, any other custom origins won't be handled at all
|
||||
export const knownOrigins: Record<string, string> = {
|
||||
//
|
||||
// (1) Defaults from Substrate
|
||||
//
|
||||
Council: 'CollectiveOrigin',
|
||||
System: 'SystemOrigin',
|
||||
TechnicalCommittee: 'CollectiveOrigin',
|
||||
//
|
||||
// (2) Defaults from Polkadot
|
||||
//
|
||||
Xcm: 'XcmOrigin',
|
||||
XcmPallet: 'XcmOrigin',
|
||||
//
|
||||
// (3) Defaults from Acala
|
||||
//
|
||||
Authority: 'AuthorityOrigin',
|
||||
GeneralCouncil: 'CollectiveOrigin'
|
||||
};
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/types-known', version: '5.1.1' };
|
||||
export const packageInfo = { name: '@polkadot/types-known', version: '5.2.1' };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/types",
|
||||
"version": "5.1.1",
|
||||
"version": "5.2.1",
|
||||
"type": "module",
|
||||
"description": "Implementation of the Parity codec",
|
||||
"main": "index.js",
|
||||
@@ -19,13 +19,13 @@
|
||||
"bugs": "https://github.com/polkadot-js/api/issues",
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.14.6",
|
||||
"@polkadot/util": "^7.0.2",
|
||||
"@polkadot/util-crypto": "^7.0.2",
|
||||
"@babel/runtime": "^7.14.8",
|
||||
"@polkadot/util": "^7.0.3",
|
||||
"@polkadot/util-crypto": "^7.0.3",
|
||||
"rxjs": "^7.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^7.0.2",
|
||||
"@polkadot/keyring": "^7.0.3",
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"bn.js": "^4.11.9"
|
||||
}
|
||||
|
||||
@@ -2,15 +2,52 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import { Text, U32 } from '../primitive';
|
||||
import { BTreeMap, Struct } from '.';
|
||||
import { I32, Text, U32 } from '../primitive';
|
||||
import { Constructor } from '../types';
|
||||
import { ITuple } from '../types/interfaces';
|
||||
import { BTreeMap, Enum, Struct, Tuple } from '.';
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
class U32TextTuple extends (Tuple.with([U32, Text]) as unknown as Constructor<ITuple<[U32, Text]>>) {}
|
||||
// Reason: We purposefully want `text` to be the first key of the struct and take priority during sorting
|
||||
// eslint-disable-next-line sort-keys
|
||||
class MockStruct extends Struct.with({ text: Text, int: I32 }) {}
|
||||
class MockEnum extends Enum.with({
|
||||
Key1: MockStruct,
|
||||
Key2: MockStruct,
|
||||
Key3: U32TextTuple
|
||||
}) {}
|
||||
|
||||
const mockU32TextMap = new Map<Text, U32>();
|
||||
const mockU32TupleMap = new Map<ITuple<[U32, Text]>, U32>();
|
||||
const mockU32I32Map = new Map<I32, U32>();
|
||||
const mockU32StructMap = new Map<MockStruct, U32>();
|
||||
const mockU32EnumMap = new Map<MockEnum, U32>();
|
||||
|
||||
mockU32TextMap.set(new Text(registry, 'bazzing'), new U32(registry, 69));
|
||||
|
||||
mockU32TupleMap.set((new U32TextTuple(registry, [2, 'ba'])), new U32(registry, 42));
|
||||
mockU32TupleMap.set((new U32TextTuple(registry, [2, 'b'])), new U32(registry, 7));
|
||||
mockU32TupleMap.set((new U32TextTuple(registry, [1, 'baz'])), new U32(registry, 13));
|
||||
|
||||
mockU32I32Map.set(new I32(registry, 255), new U32(registry, 69));
|
||||
mockU32I32Map.set(new I32(registry, -255), new U32(registry, 42));
|
||||
mockU32I32Map.set(new I32(registry, 1000), new U32(registry, 7));
|
||||
mockU32I32Map.set(new I32(registry, -1000), new U32(registry, 25));
|
||||
mockU32I32Map.set(new I32(registry, 0), new U32(registry, 13));
|
||||
|
||||
mockU32StructMap.set(new MockStruct(registry, { int: 1, text: 'b' }), new U32(registry, 42));
|
||||
mockU32StructMap.set(new MockStruct(registry, { int: -1, text: 'b' }), new U32(registry, 7));
|
||||
mockU32StructMap.set(new MockStruct(registry, { int: -1, text: 'ba' }), new U32(registry, 25));
|
||||
mockU32StructMap.set(new MockStruct(registry, { int: -2, text: 'baz' }), new U32(registry, 13));
|
||||
|
||||
mockU32EnumMap.set(new MockEnum(registry, { Key3: new U32TextTuple(registry, [2, 'ba']) }), new U32(registry, 13));
|
||||
mockU32EnumMap.set(new MockEnum(registry, { Key3: new U32TextTuple(registry, [2, 'b']) }), new U32(registry, 42));
|
||||
mockU32EnumMap.set(new MockEnum(registry, { Key2: new MockStruct(registry, { int: -1, text: 'b' }) }), new U32(registry, 7));
|
||||
mockU32EnumMap.set(new MockEnum(registry, { Key1: new MockStruct(registry, { int: 1, text: 'b' }) }), new U32(registry, 25));
|
||||
mockU32EnumMap.set(new MockEnum(registry, { Key1: new MockStruct(registry, { int: -1, text: 'b' }) }), new U32(registry, 69));
|
||||
|
||||
describe('BTreeMap', (): void => {
|
||||
it('decodes null', (): void => {
|
||||
expect(
|
||||
@@ -54,6 +91,97 @@ describe('BTreeMap', (): void => {
|
||||
).toEqual(13);
|
||||
});
|
||||
|
||||
it('correctly sorts simple keys', (): void => {
|
||||
expect(
|
||||
Array.from(new (BTreeMap.with(I32, U32))(registry, mockU32I32Map).keys()).map((k) => k.toNumber())
|
||||
).toEqual([-1000, -255, 0, 255, 1000]);
|
||||
});
|
||||
|
||||
it('correctly sorts tuple keys', (): void => {
|
||||
expect(
|
||||
Array.from(new (BTreeMap.with(U32TextTuple, U32))(registry, mockU32TupleMap).keys()).map((k) => k.toJSON())
|
||||
).toEqual([[1, 'baz'], [2, 'b'], [2, 'ba']]);
|
||||
});
|
||||
|
||||
it('correctly sorts struct keys', (): void => {
|
||||
expect(
|
||||
Array.from(new (BTreeMap.with(MockStruct, U32))(registry, mockU32StructMap).keys()).map((k) => k.toJSON())
|
||||
).toEqual([
|
||||
{ int: -1, text: 'b' },
|
||||
{ int: 1, text: 'b' },
|
||||
{ int: -1, text: 'ba' },
|
||||
{ int: -2, text: 'baz' }
|
||||
]);
|
||||
});
|
||||
|
||||
it('correctly sorts enum keys', (): void => {
|
||||
expect(
|
||||
Array.from(new (BTreeMap.with(MockEnum, U32))(registry, mockU32EnumMap).keys()).map((k) => k.toJSON())
|
||||
).toEqual([
|
||||
{ key1: { int: -1, text: 'b' } },
|
||||
{ key1: { int: 1, text: 'b' } },
|
||||
{ key2: { int: -1, text: 'b' } },
|
||||
{ key3: [2, 'b'] },
|
||||
{ key3: [2, 'ba'] }
|
||||
]);
|
||||
});
|
||||
|
||||
it('correctly serializes/deserializes to/from json with numeric keys', (): void => {
|
||||
expect(
|
||||
new (BTreeMap.with(I32, U32))(
|
||||
registry,
|
||||
new (BTreeMap.with(I32, U32))(registry, mockU32I32Map).toJSON()
|
||||
).toJSON()
|
||||
).toEqual({ '-1000': 25, '-255': 42, 0: 13, 1000: 7, 255: 69 });
|
||||
});
|
||||
|
||||
it('correctly serializes/deserializes to/from json with text keys', (): void => {
|
||||
expect(
|
||||
new (BTreeMap.with(Text, U32))(
|
||||
registry,
|
||||
new (BTreeMap.with(Text, U32))(registry, mockU32TextMap).toJSON()
|
||||
).toJSON()
|
||||
).toEqual({ bazzing: 69 });
|
||||
});
|
||||
|
||||
it('correctly serializes/deserializes to/from json with tuple keys', (): void => {
|
||||
expect(
|
||||
new (BTreeMap.with(U32TextTuple, U32))(
|
||||
registry,
|
||||
new (BTreeMap.with(U32TextTuple, U32))(registry, mockU32TupleMap).toJSON()
|
||||
).toJSON()
|
||||
).toEqual({ '[1,"baz"]': 13, '[2,"b"]': 7, '[2,"ba"]': 42 });
|
||||
});
|
||||
|
||||
it('correctly serializes/deserializes to/from json with struct keys', (): void => {
|
||||
expect(
|
||||
new (BTreeMap.with(MockStruct, U32))(
|
||||
registry,
|
||||
new (BTreeMap.with(MockStruct, U32))(registry, mockU32StructMap).toJSON()
|
||||
).toJSON()
|
||||
).toEqual({
|
||||
'{"text":"b","int":-1}': 7,
|
||||
'{"text":"b","int":1}': 42,
|
||||
'{"text":"ba","int":-1}': 25,
|
||||
'{"text":"baz","int":-2}': 13
|
||||
});
|
||||
});
|
||||
|
||||
it('correctly serializes/deserializes to/from json with enum keys', (): void => {
|
||||
expect(
|
||||
new (BTreeMap.with(MockEnum, U32))(
|
||||
registry,
|
||||
new (BTreeMap.with(MockEnum, U32))(registry, mockU32EnumMap).toJSON()
|
||||
).toJSON()
|
||||
).toEqual({
|
||||
'{"key1":{"text":"b","int":-1}}': 69,
|
||||
'{"key1":{"text":"b","int":1}}': 25,
|
||||
'{"key2":{"text":"b","int":-1}}': 7,
|
||||
'{"key3":[2,"b"]}': 42,
|
||||
'{"key3":[2,"ba"]}': 13
|
||||
});
|
||||
});
|
||||
|
||||
it('generates sane toRawTypes', (): void => {
|
||||
expect(new (BTreeMap.with(Text, U32))(registry).toRawType()).toBe('BTreeMap<Text,u32>');
|
||||
expect(new (BTreeMap.with(Text, Text))(registry).toRawType()).toBe('BTreeMap<Text,Text>');
|
||||
|
||||
@@ -4,11 +4,24 @@
|
||||
import type { CodecTo } from '../types';
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import { Text, U32 } from '../primitive';
|
||||
import { BTreeSet, Struct } from '.';
|
||||
import { I32, Text, U32 } from '../primitive';
|
||||
import { Constructor } from '../types';
|
||||
import { ITuple } from '../types/interfaces';
|
||||
import { Enum } from './Enum';
|
||||
import { BTreeSet, Struct, Tuple } from '.';
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
class U32TextTuple extends (Tuple.with([U32, Text]) as unknown as Constructor<ITuple<[U32, Text]>>) {}
|
||||
// Reason: We purposefully want `text` to be the first key of the struct and take priority during sorting
|
||||
// eslint-disable-next-line sort-keys
|
||||
class MockStruct extends Struct.with({ text: Text, int: I32 }) {}
|
||||
class MockEnum extends Enum.with({
|
||||
Key1: MockStruct,
|
||||
Key2: MockStruct,
|
||||
Key3: U32TextTuple
|
||||
}) {}
|
||||
|
||||
const mockU32Set = new Set<U32>();
|
||||
|
||||
mockU32Set.add(new U32(registry, 2));
|
||||
@@ -21,6 +34,34 @@ const mockU32SetObject = [2, 24, 30, 80];
|
||||
const mockU32SetHexString = '0x1002000000180000001e00000050000000';
|
||||
const mockU32SetUint8Array = Uint8Array.from([16, 2, 0, 0, 0, 24, 0, 0, 0, 30, 0, 0, 0, 80, 0, 0, 0]);
|
||||
|
||||
const mockI32SetObj = [1000, 0, 255, -255, -1000];
|
||||
const mockTextSetObj = [
|
||||
new Text(registry, 'baz'),
|
||||
new Text(registry, 'b'),
|
||||
new Text(registry, 'bb'),
|
||||
new Text(registry, 'ba'),
|
||||
new Text(registry, 'c')
|
||||
];
|
||||
const mockTupleSetObj = [
|
||||
new U32TextTuple(registry, [2, 'ba']),
|
||||
new U32TextTuple(registry, [2, 'bb']),
|
||||
new U32TextTuple(registry, [2, 'b']),
|
||||
new U32TextTuple(registry, [1, 'baz'])
|
||||
];
|
||||
const mockStructSetObj = [
|
||||
new MockStruct(registry, { int: 1, text: 'b' }),
|
||||
new MockStruct(registry, { int: -1, text: 'b' }),
|
||||
new MockStruct(registry, { int: -1, text: 'ba' }),
|
||||
new MockStruct(registry, { int: -2, text: 'baz' })
|
||||
];
|
||||
const mockEnumSetObj = [
|
||||
new MockEnum(registry, { Key3: new U32TextTuple(registry, [2, 'ba']) }),
|
||||
new MockEnum(registry, { Key3: new U32TextTuple(registry, [2, 'b']) }),
|
||||
new MockEnum(registry, { Key2: new MockStruct(registry, { int: -1, text: 'b' }) }),
|
||||
new MockEnum(registry, { Key1: new MockStruct(registry, { int: 1, text: 'b' }) }),
|
||||
new MockEnum(registry, { Key1: new MockStruct(registry, { int: -1, text: 'b' }) })
|
||||
];
|
||||
|
||||
describe('BTreeSet', (): void => {
|
||||
describe('decoding', (): void => {
|
||||
const testDecode = (type: string, input: any, output: string): void =>
|
||||
@@ -94,6 +135,47 @@ describe('BTreeSet', (): void => {
|
||||
).toEqual(17);
|
||||
});
|
||||
|
||||
it('correctly sorts numeric values', (): void => {
|
||||
expect(
|
||||
Array.from(new (BTreeSet.with(I32))(registry, mockI32SetObj)).map((k) => k.toNumber())
|
||||
).toEqual([-1000, -255, 0, 255, 1000]);
|
||||
});
|
||||
|
||||
it('correctly sorts text values', (): void => {
|
||||
expect(
|
||||
Array.from(new (BTreeSet.with(Text))(registry, mockTextSetObj)).map((k) => k.toString())
|
||||
).toEqual(['b', 'ba', 'baz', 'bb', 'c']);
|
||||
});
|
||||
|
||||
it('correctly sorts complex tuple values', (): void => {
|
||||
expect(
|
||||
Array.from(new (BTreeSet.with(U32TextTuple))(registry, mockTupleSetObj)).map((k) => k.toJSON())
|
||||
).toEqual([[1, 'baz'], [2, 'b'], [2, 'ba'], [2, 'bb']]);
|
||||
});
|
||||
|
||||
it('correctly sorts complex struct values', (): void => {
|
||||
expect(
|
||||
Array.from(new (BTreeSet.with(MockStruct))(registry, mockStructSetObj)).map((k) => k.toJSON())
|
||||
).toEqual([
|
||||
{ int: -1, text: 'b' },
|
||||
{ int: 1, text: 'b' },
|
||||
{ int: -1, text: 'ba' },
|
||||
{ int: -2, text: 'baz' }
|
||||
]);
|
||||
});
|
||||
|
||||
it('correctly sorts complex enum values', (): void => {
|
||||
expect(
|
||||
Array.from(new (BTreeSet.with(MockEnum))(registry, mockEnumSetObj)).map((k) => k.toJSON())
|
||||
).toEqual([
|
||||
{ key1: { int: -1, text: 'b' } },
|
||||
{ key1: { int: 1, text: 'b' } },
|
||||
{ key2: { int: -1, text: 'b' } },
|
||||
{ key3: [2, 'b'] },
|
||||
{ key3: [2, 'ba'] }
|
||||
]);
|
||||
});
|
||||
|
||||
it('generates sane toRawTypes', (): void => {
|
||||
expect(new (BTreeSet.with(U32))(registry).toRawType()).toBe('BTreeSet<u32>');
|
||||
expect(new (BTreeSet.with(Text))(registry).toRawType()).toBe('BTreeSet<Text>');
|
||||
|
||||
@@ -6,7 +6,7 @@ import type { AnyJson, Codec, Constructor, InterfaceTypes, Registry } from '../t
|
||||
|
||||
import { compactFromU8a, compactToU8a, isHex, isU8a, logger, stringify, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { compareSet, decodeU8a, typeToConstructor } from './utils';
|
||||
import { compareSet, decodeU8a, sortSet, typeToConstructor } from './utils';
|
||||
|
||||
const l = logger('BTreeSet');
|
||||
|
||||
@@ -84,7 +84,7 @@ export class BTreeSet<V extends Codec = Codec> extends Set<V> implements Codec {
|
||||
readonly #ValClass: Constructor<V>;
|
||||
|
||||
constructor (registry: Registry, valType: Constructor<V> | keyof InterfaceTypes, rawValue?: Uint8Array | string | string[] | Set<any>) {
|
||||
super(decodeSet(registry, valType, rawValue));
|
||||
super(sortSet(decodeSet(registry, valType, rawValue)));
|
||||
|
||||
this.registry = registry;
|
||||
this.#ValClass = typeToConstructor(registry, valType);
|
||||
|
||||
@@ -6,7 +6,10 @@ import type { AnyJson, Codec, Constructor, InterfaceTypes, Registry } from '../t
|
||||
|
||||
import { compactFromU8a, compactToU8a, isHex, isObject, isU8a, logger, stringify, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { compareMap, decodeU8a, typeToConstructor } from './utils';
|
||||
import { AbstractArray } from './AbstractArray';
|
||||
import { Enum } from './Enum';
|
||||
import { Struct } from './Struct';
|
||||
import { compareMap, decodeU8a, sortMap, typeToConstructor } from './utils';
|
||||
|
||||
const l = logger('Map');
|
||||
|
||||
@@ -34,11 +37,15 @@ function decodeMapFromMap<K extends Codec = Codec, V extends Codec = Codec> (reg
|
||||
const output = new Map<K, V>();
|
||||
|
||||
value.forEach((val: any, key: any) => {
|
||||
const isComplex = KeyClass.prototype instanceof AbstractArray ||
|
||||
KeyClass.prototype instanceof Struct ||
|
||||
KeyClass.prototype instanceof Enum;
|
||||
|
||||
try {
|
||||
output.set(
|
||||
key instanceof KeyClass
|
||||
? key
|
||||
: new KeyClass(registry, key),
|
||||
: new KeyClass(registry, isComplex ? JSON.parse(key) : key),
|
||||
val instanceof ValClass
|
||||
? val
|
||||
: new ValClass(registry, val)
|
||||
@@ -97,7 +104,9 @@ export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends
|
||||
readonly #type: string;
|
||||
|
||||
constructor (registry: Registry, keyType: Constructor<K> | keyof InterfaceTypes, valType: Constructor<V> | keyof InterfaceTypes, rawValue: Uint8Array | string | Map<any, any> | undefined, type: 'BTreeMap' | 'HashMap' = 'HashMap') {
|
||||
super(decodeMap(registry, keyType, valType, rawValue));
|
||||
const decoded = decodeMap(registry, keyType, valType, rawValue);
|
||||
|
||||
super(type === 'BTreeMap' ? sortMap(decoded) : decoded);
|
||||
|
||||
this.registry = registry;
|
||||
this.#KeyClass = typeToConstructor(registry, keyType);
|
||||
|
||||
@@ -7,3 +7,4 @@ export { compareSet } from './compareSet';
|
||||
export { decodeU8a } from './decodeU8a';
|
||||
export { mapToTypeMap } from './mapToTypeMap';
|
||||
export { typeToConstructor } from './typeToConstructor';
|
||||
export { sortAsc, sortSet, sortMap } from './sortValues';
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Codec } from '../../types';
|
||||
|
||||
import { AbstractArray } from '../AbstractArray';
|
||||
import { AbstractInt } from '../AbstractInt';
|
||||
import { Enum, Struct } from '..';
|
||||
|
||||
type SortArg = Codec | Codec[] | number[] | number | Uint8Array
|
||||
|
||||
/** @internal **/
|
||||
function isArrayLike (arg: SortArg): arg is AbstractArray<Codec> | Uint8Array | Codec[] | number[] {
|
||||
return arg instanceof AbstractArray || arg instanceof Uint8Array || Array.isArray(arg);
|
||||
}
|
||||
|
||||
/** @internal **/
|
||||
function isCodec (arg: SortArg): arg is Codec {
|
||||
return !!(arg && typeof (arg as Codec).toU8a === 'function');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort keys/values of BTreeSet/BTreeMap in acending order for encoding compatibility with Rust's BTreeSet/BTreeMap
|
||||
* (https://doc.rust-lang.org/stable/std/collections/struct.BTreeSet.html)
|
||||
* (https://doc.rust-lang.org/stable/std/collections/struct.BTreeMap.html)
|
||||
*/
|
||||
export function sortAsc<V extends SortArg = Codec> (a: V, b: V): number {
|
||||
if (typeof a === 'number' && typeof b === 'number') {
|
||||
return a - b;
|
||||
} else if (a instanceof Struct && b instanceof Struct) {
|
||||
return sortAsc(Array.from(a.values()), Array.from(b.values()));
|
||||
} else if (a instanceof Enum && b instanceof Enum) {
|
||||
return sortAsc(a.index, b.index) || sortAsc(a.value, b.value);
|
||||
} else if (isArrayLike(a) && isArrayLike(b)) {
|
||||
// Vec, Tuple, Bytes etc.
|
||||
let sortRes = 0; const lenA = a.length; const lenB = b.length;
|
||||
const minLen = Math.min(lenA, lenB);
|
||||
|
||||
for (let i = 0; i < minLen; ++i) {
|
||||
sortRes = sortAsc(a[i], b[i]);
|
||||
|
||||
if (sortRes !== 0) {
|
||||
return sortRes;
|
||||
}
|
||||
}
|
||||
|
||||
return lenA - lenB;
|
||||
} else if (a instanceof AbstractInt && b instanceof AbstractInt) {
|
||||
return a.cmp(b);
|
||||
} else if (isCodec(a) && isCodec(b)) {
|
||||
// Text, Bool etc.
|
||||
return sortAsc(a.toU8a(true), b.toU8a(true));
|
||||
} else {
|
||||
throw new Error(`Attempting to sort unrecognized value: ${JSON.stringify(a)}`);
|
||||
}
|
||||
}
|
||||
|
||||
export function sortSet<V extends Codec = Codec> (set: Set<V>): Set<V> {
|
||||
return new Set(Array.from(set).sort(sortAsc));
|
||||
}
|
||||
|
||||
export function sortMap<K extends Codec = Codec, V extends Codec = Codec> (map: Map<K, V>): Map<K, V> {
|
||||
return new Map(Array.from(map.entries()).sort(([keyA], [keyB]) => sortAsc(keyA, keyB)));
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import type { FromReg, TypeDef } from './types';
|
||||
import { assert, isNumber, isUndefined, stringify } from '@polkadot/util';
|
||||
|
||||
import { BTreeMap, BTreeSet, CodecSet, Compact, DoNotConstruct, Enum, HashMap, Int, Option, Result, Struct, Tuple, U8aFixed, UInt, Vec, VecFixed } from '../codec';
|
||||
import { Bytes, Null } from '../primitive';
|
||||
import { getTypeDef } from './getTypeDef';
|
||||
import { TypeDefInfo } from './types';
|
||||
|
||||
@@ -130,7 +131,7 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
[TypeDefInfo.Null]: (registry: Registry, _: TypeDef): Constructor =>
|
||||
createClass(registry, 'Null'),
|
||||
Null,
|
||||
|
||||
[TypeDefInfo.Option]: (registry: Registry, value: TypeDef): Constructor =>
|
||||
Option.with(getSubType(value)),
|
||||
@@ -159,7 +160,7 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
|
||||
},
|
||||
|
||||
[TypeDefInfo.Si]: (registry: Registry, value: TypeDef): Constructor =>
|
||||
getTypeClass(registry, registry.lookup.getTypeDef(value.index as number)),
|
||||
getTypeClass(registry, registry.lookup.getTypeDef(value.type)),
|
||||
|
||||
[TypeDefInfo.Struct]: (registry: Registry, value: TypeDef): Constructor =>
|
||||
Struct.with(getTypeClassMap(value), value.alias),
|
||||
@@ -175,7 +176,7 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
|
||||
|
||||
return (
|
||||
subType === 'u8'
|
||||
? createClass(registry, 'Bytes')
|
||||
? Bytes
|
||||
: Vec.with(subType)
|
||||
);
|
||||
},
|
||||
@@ -183,34 +184,38 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
|
||||
[TypeDefInfo.VecFixed]: (registry: Registry, { displayName, length, sub }: TypeDef): Constructor => {
|
||||
assert(isNumber(length) && !isUndefined(sub), 'Expected length & type information for fixed vector');
|
||||
|
||||
const subType = (sub as TypeDef).type as keyof InterfaceTypes;
|
||||
|
||||
return (
|
||||
(sub as TypeDef).type === 'u8'
|
||||
subType === 'u8'
|
||||
? U8aFixed.with((length * 8) as U8aBitLength, displayName)
|
||||
: VecFixed.with((sub as TypeDef).type as keyof InterfaceTypes, length)
|
||||
: VecFixed.with(subType, length)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// Returns the type Class for construction
|
||||
export function getTypeClass<T extends Codec = Codec> (registry: Registry, value: TypeDef): Constructor<T> {
|
||||
let Type = registry.get<T>(value.type);
|
||||
export function getTypeClass<T extends Codec = Codec> (registry: Registry, typeDef: TypeDef): Constructor<T> {
|
||||
let Type = registry.get<T>(typeDef.type);
|
||||
|
||||
if (Type) {
|
||||
return Type;
|
||||
}
|
||||
|
||||
const getFn = infoMapping[value.info];
|
||||
try {
|
||||
Type = infoMapping[typeDef.info](registry, typeDef) as Constructor<T>;
|
||||
|
||||
assert(getFn, () => `Unable to construct class from ${stringify(value)}`);
|
||||
assert(Type, 'No class created');
|
||||
|
||||
Type = getFn(registry, value) as Constructor<T>;
|
||||
// don't clobber any existing
|
||||
if (!Type.__fallbackType && typeDef.fallbackType) {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore ...this is the only place we we actually assign this...
|
||||
Type.__fallbackType = typeDef.fallbackType;
|
||||
}
|
||||
|
||||
// don't clobber any existing
|
||||
if (!Type.__fallbackType && value.fallbackType) {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore ...this is the only place we we actually assign this...
|
||||
Type.__fallbackType = value.fallbackType;
|
||||
return Type;
|
||||
} catch (error) {
|
||||
throw new Error(`Unable to construct class from ${stringify(typeDef)}: ${(error as Error).message}`);
|
||||
}
|
||||
|
||||
return Type;
|
||||
}
|
||||
|
||||
@@ -3,20 +3,16 @@
|
||||
|
||||
import type { Bytes } from '../primitive/Bytes';
|
||||
import type { Codec, Constructor, InterfaceTypes, Registry } from '../types';
|
||||
import type { FromReg } from './types';
|
||||
import type { CreateOptions, FromReg } from './types';
|
||||
|
||||
import { assert, isHex, isU8a, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { Option } from '../codec/Option';
|
||||
import { createClass } from './createClass';
|
||||
|
||||
interface CreateOptions {
|
||||
blockHash?: Uint8Array | string | null;
|
||||
isPedantic?: boolean;
|
||||
}
|
||||
|
||||
// With isPedantic, actually check that the encoding matches that supplied. This
|
||||
// is much slower, but verifies that we have the correct types defined
|
||||
function checkInstance<T extends Codec = Codec, K extends string = string> (value: Uint8Array, created: FromReg<T, K>): void {
|
||||
function checkInstance (created: FromReg<Codec, string>, value: Uint8Array): void {
|
||||
const u8a = created.toU8a();
|
||||
const rawType = created.toRawType();
|
||||
|
||||
@@ -30,25 +26,29 @@ function checkInstance<T extends Codec = Codec, K extends string = string> (valu
|
||||
);
|
||||
}
|
||||
|
||||
// Initializes a type with a value. This also checks for fallbacks and in the cases
|
||||
// where isPedantic is specified (storage decoding), also check the format/structure
|
||||
function initType<T extends Codec = Codec, K extends string = string> (registry: Registry, Type: Constructor<FromReg<T, K>>, params: unknown[] = [], { blockHash, isPedantic }: CreateOptions = {}): FromReg<T, K> {
|
||||
const created = new Type(registry, ...params);
|
||||
const value = params[0];
|
||||
|
||||
function checkPedantic (created: FromReg<Codec, string>, [value]: unknown[], isPedantic = false): void {
|
||||
if (isPedantic) {
|
||||
if (isU8a(value)) {
|
||||
checkInstance(value, created);
|
||||
checkInstance(created, value);
|
||||
} else if (isHex(value)) {
|
||||
checkInstance(u8aToU8a(value), created);
|
||||
checkInstance(created, u8aToU8a(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Initializes a type with a value. This also checks for fallbacks and in the cases
|
||||
// where isPedantic is specified (storage decoding), also check the format/structure
|
||||
function initType<T extends Codec = Codec, K extends string = string> (registry: Registry, Type: Constructor<FromReg<T, K>>, params: unknown[] = [], { blockHash, isOptional, isPedantic }: CreateOptions = {}): FromReg<T, K> {
|
||||
const created = new (isOptional ? Option.with(Type) : Type)(registry, ...params);
|
||||
|
||||
checkPedantic(created, params, isPedantic);
|
||||
|
||||
if (blockHash) {
|
||||
created.createdAtHash = createType(registry, 'Hash', blockHash);
|
||||
}
|
||||
|
||||
return created;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return created as any;
|
||||
}
|
||||
|
||||
// An unsafe version of the `createType` below. It's unsafe because the `type`
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { encodeTypeDef } from './encodeTypes';
|
||||
import { TypeRegistry } from './registry';
|
||||
import { TypeDefInfo } from './types';
|
||||
|
||||
describe('encodeTypeDef', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
it('correctly encodes a complex struct', (): void => {
|
||||
expect(
|
||||
JSON.parse(encodeTypeDef({
|
||||
JSON.parse(encodeTypeDef(registry, {
|
||||
info: TypeDefInfo.Struct,
|
||||
sub: [
|
||||
{
|
||||
@@ -47,7 +50,7 @@ describe('encodeTypeDef', (): void => {
|
||||
|
||||
it('correctly encodes a complex struct (named)', (): void => {
|
||||
expect(
|
||||
JSON.parse(encodeTypeDef({
|
||||
JSON.parse(encodeTypeDef(registry, {
|
||||
info: TypeDefInfo.Struct,
|
||||
sub: [
|
||||
{
|
||||
@@ -88,7 +91,7 @@ describe('encodeTypeDef', (): void => {
|
||||
|
||||
it('correctly encodes a complex enum', (): void => {
|
||||
expect(
|
||||
JSON.parse(encodeTypeDef({
|
||||
JSON.parse(encodeTypeDef(registry, {
|
||||
info: TypeDefInfo.Enum,
|
||||
sub: [
|
||||
{
|
||||
@@ -148,7 +151,7 @@ describe('encodeTypeDef', (): void => {
|
||||
|
||||
it('correctly encodes a complex enum (named)', (): void => {
|
||||
expect(
|
||||
JSON.parse(encodeTypeDef({
|
||||
JSON.parse(encodeTypeDef(registry, {
|
||||
info: TypeDefInfo.Enum,
|
||||
sub: [
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Registry } from '../types/registry';
|
||||
import type { TypeDef } from './types';
|
||||
|
||||
import { assert, isNumber, isUndefined, stringify } from '@polkadot/util';
|
||||
@@ -19,7 +20,7 @@ export function paramsNotation <T> (outer: string, inner?: T | T[], transform: (
|
||||
}`;
|
||||
}
|
||||
|
||||
function encodeWithParams (typeDef: TypeDef, outer: string): string {
|
||||
function encodeWithParams (registry: Registry, typeDef: TypeDef, outer: string): string {
|
||||
const { info, sub } = typeDef;
|
||||
|
||||
switch (info) {
|
||||
@@ -31,25 +32,26 @@ function encodeWithParams (typeDef: TypeDef, outer: string): string {
|
||||
case TypeDefInfo.Option:
|
||||
case TypeDefInfo.Result:
|
||||
case TypeDefInfo.Vec:
|
||||
return paramsNotation(outer, sub, (param) => encodeTypeDef(param));
|
||||
return paramsNotation(outer, sub, (param) => encodeTypeDef(registry, param));
|
||||
}
|
||||
|
||||
throw new Error(`Unable to encode ${stringify(typeDef)} with params`);
|
||||
}
|
||||
|
||||
function encodeDoNotConstruct ({ displayName }: TypeDef): string {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function encodeDoNotConstruct (registry: Registry, { displayName }: TypeDef): string {
|
||||
return `DoNotConstruct<${displayName || 'Unknown'}>`;
|
||||
}
|
||||
|
||||
function encodeSubTypes (sub: TypeDef[], asEnum?: boolean): string {
|
||||
function encodeSubTypes (registry: Registry, sub: TypeDef[], asEnum?: boolean, extra?: Record<string, unknown>): string {
|
||||
const names = sub.map(({ name }) => name);
|
||||
|
||||
assert(names.every((n) => !!n), () => `Subtypes does not have consistent names, ${names.join(', ')}`);
|
||||
|
||||
const inner = sub.reduce< Record<string, string>>((result, type) => ({
|
||||
...result,
|
||||
[type.name as string]: encodeTypeDef(type)
|
||||
}), {});
|
||||
[type.name as string]: encodeTypeDef(registry, type)
|
||||
}), { ...(extra as Record<string, string>) });
|
||||
|
||||
return stringify(
|
||||
asEnum
|
||||
@@ -58,7 +60,7 @@ function encodeSubTypes (sub: TypeDef[], asEnum?: boolean): string {
|
||||
);
|
||||
}
|
||||
|
||||
function encodeEnum (typeDef: TypeDef): string {
|
||||
function encodeEnum (registry: Registry, typeDef: TypeDef): string {
|
||||
assert(typeDef.sub && Array.isArray(typeDef.sub), 'Unable to encode Enum type');
|
||||
|
||||
const sub = typeDef.sub;
|
||||
@@ -67,28 +69,38 @@ function encodeEnum (typeDef: TypeDef): string {
|
||||
// TODO We need to take the disciminant into account and auto-add empty entries
|
||||
return sub.every(({ type }) => type === 'Null')
|
||||
? stringify({ _enum: sub.map(({ name }, index) => `${name || `Empty${index}`}`) })
|
||||
: encodeSubTypes(sub, true);
|
||||
: encodeSubTypes(registry, sub, true);
|
||||
}
|
||||
|
||||
function encodeStruct (typeDef: TypeDef): string {
|
||||
function encodeStruct (registry: Registry, typeDef: TypeDef): string {
|
||||
assert(typeDef.sub && Array.isArray(typeDef.sub), 'Unable to encode Struct type');
|
||||
|
||||
return encodeSubTypes(typeDef.sub);
|
||||
return encodeSubTypes(registry, typeDef.sub, false, {
|
||||
...(
|
||||
typeDef.alias
|
||||
? { alias: [...typeDef.alias.entries()].reduce<Record<string, string>>((all, [k, v]) => ({
|
||||
...all,
|
||||
[k]: v
|
||||
}), {}) }
|
||||
: {}
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
function encodeTuple (typeDef: TypeDef): string {
|
||||
function encodeTuple (registry: Registry, typeDef: TypeDef): string {
|
||||
assert(typeDef.sub && Array.isArray(typeDef.sub), 'Unable to encode Tuple type');
|
||||
|
||||
return `(${typeDef.sub.map((type) => encodeTypeDef(type)).join(', ')})`;
|
||||
return `(${typeDef.sub.map((type) => encodeTypeDef(registry, type)).join(',')})`;
|
||||
}
|
||||
|
||||
function encodeUInt ({ length }: TypeDef, type: 'Int' | 'UInt'): string {
|
||||
function encodeUInt (registry: Registry, { length }: TypeDef, type: 'Int' | 'UInt'): string {
|
||||
assert(isNumber(length), 'Unable to encode VecFixed type');
|
||||
|
||||
return `${type}<${length}>`;
|
||||
}
|
||||
|
||||
function encodeVecFixed ({ length, sub }: TypeDef): string {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function encodeVecFixed (registry: Registry, { length, sub }: TypeDef): string {
|
||||
assert(isNumber(length) && !isUndefined(sub) && !Array.isArray(sub), 'Unable to encode VecFixed type');
|
||||
|
||||
return `[${sub.type};${length}]`;
|
||||
@@ -96,38 +108,60 @@ function encodeVecFixed ({ length, sub }: TypeDef): string {
|
||||
|
||||
// We setup a record here to ensure we have comprehensive coverage (any item not covered will result
|
||||
// in a compile-time error with the missing index)
|
||||
const encoders: Record<TypeDefInfo, (typeDef: TypeDef) => string> = {
|
||||
[TypeDefInfo.BTreeMap]: (typeDef: TypeDef): string => encodeWithParams(typeDef, 'BTreeMap'),
|
||||
[TypeDefInfo.BTreeSet]: (typeDef: TypeDef): string => encodeWithParams(typeDef, 'BTreeSet'),
|
||||
[TypeDefInfo.Compact]: (typeDef: TypeDef): string => encodeWithParams(typeDef, 'Compact'),
|
||||
[TypeDefInfo.DoNotConstruct]: (typeDef: TypeDef): string => encodeDoNotConstruct(typeDef),
|
||||
[TypeDefInfo.Enum]: (typeDef: TypeDef): string => encodeEnum(typeDef),
|
||||
[TypeDefInfo.HashMap]: (typeDef: TypeDef): string => encodeWithParams(typeDef, 'HashMap'),
|
||||
[TypeDefInfo.Int]: (typeDef: TypeDef): string => encodeUInt(typeDef, 'Int'),
|
||||
[TypeDefInfo.Linkage]: (typeDef: TypeDef): string => encodeWithParams(typeDef, 'Linkage'),
|
||||
const encoders: Record<TypeDefInfo, (registry: Registry, typeDef: TypeDef) => string> = {
|
||||
[TypeDefInfo.BTreeMap]: (registry: Registry, typeDef: TypeDef) =>
|
||||
encodeWithParams(registry, typeDef, 'BTreeMap'),
|
||||
[TypeDefInfo.BTreeSet]: (registry: Registry, typeDef: TypeDef) =>
|
||||
encodeWithParams(registry, typeDef, 'BTreeSet'),
|
||||
[TypeDefInfo.Compact]: (registry: Registry, typeDef: TypeDef) =>
|
||||
encodeWithParams(registry, typeDef, 'Compact'),
|
||||
[TypeDefInfo.DoNotConstruct]: (registry: Registry, typeDef: TypeDef) =>
|
||||
encodeDoNotConstruct(registry, typeDef),
|
||||
[TypeDefInfo.Enum]: (registry: Registry, typeDef: TypeDef) =>
|
||||
encodeEnum(registry, typeDef),
|
||||
[TypeDefInfo.HashMap]: (registry: Registry, typeDef: TypeDef) =>
|
||||
encodeWithParams(registry, typeDef, 'HashMap'),
|
||||
[TypeDefInfo.Int]: (registry: Registry, typeDef: TypeDef) =>
|
||||
encodeUInt(registry, typeDef, 'Int'),
|
||||
[TypeDefInfo.Linkage]: (registry: Registry, typeDef: TypeDef) =>
|
||||
encodeWithParams(registry, typeDef, 'Linkage'),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
[TypeDefInfo.Null]: (typeDef: TypeDef): string => 'Null',
|
||||
[TypeDefInfo.Option]: (typeDef: TypeDef): string => encodeWithParams(typeDef, 'Option'),
|
||||
[TypeDefInfo.Plain]: (typeDef: TypeDef): string => typeDef.displayName || typeDef.type,
|
||||
[TypeDefInfo.Result]: (typeDef: TypeDef): string => encodeWithParams(typeDef, 'Result'),
|
||||
[TypeDefInfo.Set]: (typeDef: TypeDef): string => typeDef.type,
|
||||
[TypeDefInfo.Si]: (typeDef: TypeDef): string => typeDef.type,
|
||||
[TypeDefInfo.Struct]: (typeDef: TypeDef): string => encodeStruct(typeDef),
|
||||
[TypeDefInfo.Tuple]: (typeDef: TypeDef): string => encodeTuple(typeDef),
|
||||
[TypeDefInfo.UInt]: (typeDef: TypeDef): string => encodeUInt(typeDef, 'UInt'),
|
||||
[TypeDefInfo.Vec]: (typeDef: TypeDef): string => encodeWithParams(typeDef, 'Vec'),
|
||||
[TypeDefInfo.VecFixed]: (typeDef: TypeDef): string => encodeVecFixed(typeDef)
|
||||
[TypeDefInfo.Null]: (registry: Registry, typeDef: TypeDef) =>
|
||||
'Null',
|
||||
[TypeDefInfo.Option]: (registry: Registry, typeDef: TypeDef) =>
|
||||
encodeWithParams(registry, typeDef, 'Option'),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
[TypeDefInfo.Plain]: (registry: Registry, typeDef: TypeDef) =>
|
||||
typeDef.displayName || typeDef.type,
|
||||
[TypeDefInfo.Result]: (registry: Registry, typeDef: TypeDef) =>
|
||||
encodeWithParams(registry, typeDef, 'Result'),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
[TypeDefInfo.Set]: (registry: Registry, typeDef: TypeDef) =>
|
||||
typeDef.type,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
[TypeDefInfo.Si]: (registry: Registry, typeDef: TypeDef) =>
|
||||
typeDef.lookupName || typeDef.type,
|
||||
[TypeDefInfo.Struct]: (registry: Registry, typeDef: TypeDef) =>
|
||||
encodeStruct(registry, typeDef),
|
||||
[TypeDefInfo.Tuple]: (registry: Registry, typeDef: TypeDef) =>
|
||||
encodeTuple(registry, typeDef),
|
||||
[TypeDefInfo.UInt]: (registry: Registry, typeDef: TypeDef) =>
|
||||
encodeUInt(registry, typeDef, 'UInt'),
|
||||
[TypeDefInfo.Vec]: (registry: Registry, typeDef: TypeDef) =>
|
||||
encodeWithParams(registry, typeDef, 'Vec'),
|
||||
[TypeDefInfo.VecFixed]: (registry: Registry, typeDef: TypeDef) =>
|
||||
encodeVecFixed(registry, typeDef)
|
||||
};
|
||||
|
||||
function encodeType (typeDef: TypeDef): string {
|
||||
function encodeType (registry: Registry, typeDef: TypeDef): string {
|
||||
const encoder = encoders[typeDef.info];
|
||||
|
||||
assert(encoder, () => `Cannot encode type: info=${typeDef.info}, typeDef=${stringify(typeDef)}`);
|
||||
assert(encoder, () => `Cannot encode type ${stringify(typeDef)}`);
|
||||
|
||||
return encoder(typeDef);
|
||||
return typeDef.lookupName || encoder(registry, typeDef);
|
||||
}
|
||||
|
||||
export function encodeTypeDef (typeDef: TypeDef): string {
|
||||
export function encodeTypeDef (registry: Registry, typeDef: TypeDef): string {
|
||||
assert(!isUndefined(typeDef.info), () => `Invalid type definition with no instance info, typeDef=${stringify(typeDef)}`);
|
||||
|
||||
// In the case of contracts we do have the unfortunate situation where the displayName would
|
||||
@@ -137,12 +171,17 @@ export function encodeTypeDef (typeDef: TypeDef): string {
|
||||
return typeDef.displayName;
|
||||
}
|
||||
|
||||
return encodeType(typeDef);
|
||||
return encodeType(registry, typeDef);
|
||||
}
|
||||
|
||||
export function withTypeString (typeDef: Omit<TypeDef, 'type'>): TypeDef {
|
||||
export function withTypeString (registry: Registry, typeDef: Omit<TypeDef, 'type'>): TypeDef {
|
||||
const partial = { ...typeDef } as TypeDef;
|
||||
|
||||
// for the outer-most type, we ignore the lookupName
|
||||
delete partial.lookupName;
|
||||
|
||||
return {
|
||||
...typeDef,
|
||||
type: encodeType(typeDef as TypeDef)
|
||||
type: encodeType(registry, partial)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,6 +6,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, InterfaceTypes, RegisteredTypes, Registry, RegistryError, RegistryTypes } from '../types';
|
||||
import type { CreateOptions } from './types';
|
||||
|
||||
import { assert, assertReturn, BN_ZERO, formatBalance, isFunction, isString, isU8a, logger, stringCamelCase, stringify, u8aToHex } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
@@ -20,7 +21,7 @@ import * as definitions from '../interfaces/definitions';
|
||||
import { decorateConstants, decorateExtrinsics } from '../metadata/decorate';
|
||||
import { Metadata } from '../metadata/Metadata';
|
||||
import { createClass, getTypeClass } from './createClass';
|
||||
import { createType } from './createType';
|
||||
import { createTypeUnsafe } from './createType';
|
||||
import { getTypeDef } from './getTypeDef';
|
||||
|
||||
const l = logger('registry');
|
||||
@@ -247,7 +248,14 @@ export class TypeRegistry implements Registry {
|
||||
* @description Creates an instance of a type as registered
|
||||
*/
|
||||
public createType <K extends keyof InterfaceTypes> (type: K, ...params: unknown[]): InterfaceTypes[K] {
|
||||
return createType(this, type, ...params);
|
||||
return createTypeUnsafe(this, type, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Creates an instance of a type as registered
|
||||
*/
|
||||
public createTypeUnsafe <T extends Codec = Codec, K extends string = string> (type: K, params: unknown[], options?: CreateOptions): T {
|
||||
return createTypeUnsafe(this, type, params, options);
|
||||
}
|
||||
|
||||
// find a specific call
|
||||
|
||||
@@ -34,12 +34,22 @@ export enum TypeDefInfo {
|
||||
export interface TypeDef {
|
||||
alias?: Map<string, string>;
|
||||
displayName?: string;
|
||||
docs?: string[];
|
||||
fallbackType?: string;
|
||||
info: TypeDefInfo;
|
||||
index?: number;
|
||||
isFromSi?: boolean;
|
||||
length?: number;
|
||||
lookupIndex?: number;
|
||||
lookupName?: string;
|
||||
name?: string;
|
||||
namespace?: string;
|
||||
sub?: TypeDef | TypeDef[];
|
||||
type: string;
|
||||
}
|
||||
|
||||
export interface CreateOptions {
|
||||
blockHash?: Uint8Array | string | null;
|
||||
isOptional?: boolean;
|
||||
isPedantic?: boolean;
|
||||
}
|
||||
|
||||
@@ -4,28 +4,89 @@
|
||||
import type { Vec } from '../codec/Vec';
|
||||
import type { PortableType } from '../interfaces/metadata';
|
||||
import type { SiField, SiLookupTypeId, SiType, SiTypeDefArray, SiTypeDefCompact, SiTypeDefComposite, SiTypeDefSequence, SiTypeDefTuple, SiTypeDefVariant, SiVariant } from '../interfaces/scaleInfo';
|
||||
import type { Type } from '../primitive/Type';
|
||||
import type { Registry, TypeDef } from '../types';
|
||||
|
||||
import { assert, isNumber, isString, stringCamelCase, stringify } from '@polkadot/util';
|
||||
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';
|
||||
|
||||
// Alias the primitive enum with out known values
|
||||
const PRIMITIVE_ALIAS: Record<string, string> = {
|
||||
Char: 'u32', // Rust char is 4-bytes
|
||||
Str: 'Text'
|
||||
};
|
||||
|
||||
const INK_PRIMITIVE_ALWAYS = ['AccountId', 'AccountIndex', 'Address', 'Balance'];
|
||||
// ink! specific overrides
|
||||
const PRIMITIVE_INK = ['AccountId', 'AccountIndex', 'Address', 'Balance'];
|
||||
|
||||
// These are types where we have a specific decoding/encoding override + helpers
|
||||
const PRIMITIVE_SP = [
|
||||
'sp_core::crypto::AccountId32',
|
||||
'sp_runtime::generic::era::Era',
|
||||
'sp_runtime::multiaddress::MultiAddress',
|
||||
'pallet_democracy::vote::Vote',
|
||||
'pallet_identity::types::Data',
|
||||
'primitive_types::H160',
|
||||
'primitive_types::H256',
|
||||
'primitive_types::H512'
|
||||
];
|
||||
|
||||
// These we never use these as top-level names, they are wrappers
|
||||
const WRAPPERS = ['Box', 'BTreeMap', 'Cow', 'Result', 'Option'];
|
||||
|
||||
// These are reserved and conflicts with built-in Codec definitions
|
||||
const RESERVED = ['entries', 'hash', 'keys', 'size'];
|
||||
|
||||
function removeDuplicateNames (names: (string | null)[]): (string | null)[] {
|
||||
return names.map((name, index): string | null =>
|
||||
!name || names.some((o, i) => index !== i && name === o)
|
||||
? null
|
||||
: name
|
||||
);
|
||||
}
|
||||
|
||||
function extractNames (types: PortableType[]): Record<number, string> {
|
||||
return removeDuplicateNames(
|
||||
types.map(({ type: { path } }): string | null => {
|
||||
if (!path.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const parts = path.map((p) => stringUpperFirst(stringCamelCase(p)));
|
||||
|
||||
if (parts.length >= 2 && parts[parts.length - 1] === parts[parts.length - 2]) {
|
||||
parts.pop();
|
||||
}
|
||||
|
||||
const typeName = parts.join('');
|
||||
|
||||
return WRAPPERS.includes(typeName) || ['frame_support'].includes(path[0].toString())
|
||||
? null
|
||||
: typeName;
|
||||
})
|
||||
).reduce<Record<number, string>>((all, name, index) => {
|
||||
if (name) {
|
||||
all[index] = name;
|
||||
}
|
||||
|
||||
return all;
|
||||
}, {});
|
||||
}
|
||||
|
||||
export class GenericPortableRegistry extends Struct {
|
||||
#names: Record<number, string>;
|
||||
#typeDefs: Record<number, TypeDef> = {};
|
||||
|
||||
constructor (registry: Registry, value?: Uint8Array) {
|
||||
super(registry, {
|
||||
types: 'Vec<PortableType>'
|
||||
}, value);
|
||||
|
||||
this.#names = extractNames(this.types);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,20 +111,42 @@ export class GenericPortableRegistry extends Struct {
|
||||
* @description Lookup the type definition for the index
|
||||
*/
|
||||
public getTypeDef (lookupId: SiLookupTypeId | string | number): TypeDef {
|
||||
const index = this.#getLookupId(lookupId);
|
||||
const lookupIndex = this.#getLookupId(lookupId);
|
||||
|
||||
if (!this.#typeDefs[index]) {
|
||||
this.#typeDefs[index] = this.#extract(this.getSiType(lookupId), index);
|
||||
if (!this.#typeDefs[lookupIndex]) {
|
||||
// we set first since we will get into circular lookups along the way
|
||||
this.#typeDefs[lookupIndex] = {
|
||||
info: TypeDefInfo.DoNotConstruct,
|
||||
lookupIndex,
|
||||
lookupName: this.#names[lookupIndex],
|
||||
type: this.registry.createLookupType(lookupIndex)
|
||||
};
|
||||
|
||||
const extracted = this.#extract(this.getSiType(lookupId), lookupIndex);
|
||||
|
||||
Object.keys(extracted).forEach((key): void => {
|
||||
// these are safe since we are looking through the keys as set
|
||||
this.#typeDefs[lookupIndex][key as 'info'] = extracted[key as 'info'];
|
||||
});
|
||||
}
|
||||
|
||||
return this.#typeDefs[index];
|
||||
return this.#typeDefs[lookupIndex];
|
||||
}
|
||||
|
||||
#createSiDef (type: SiLookupTypeId): TypeDef {
|
||||
return {
|
||||
info: TypeDefInfo.Si,
|
||||
type: this.registry.createLookupType(type)
|
||||
};
|
||||
#createSiDef (lookupId: SiLookupTypeId): TypeDef {
|
||||
const typeDef = this.getTypeDef(lookupId);
|
||||
const lookupIndex = lookupId.toNumber();
|
||||
|
||||
// Setup for a lookup on complex types
|
||||
return [TypeDefInfo.Enum, TypeDefInfo.Struct].includes(typeDef.info)
|
||||
? {
|
||||
docs: typeDef.docs,
|
||||
info: TypeDefInfo.Si,
|
||||
lookupIndex,
|
||||
lookupName: this.#names[lookupIndex],
|
||||
type: this.registry.createLookupType(lookupId)
|
||||
}
|
||||
: typeDef;
|
||||
}
|
||||
|
||||
#getLookupId (lookupId: SiLookupTypeId | string | number): number {
|
||||
@@ -88,7 +171,8 @@ export class GenericPortableRegistry extends Struct {
|
||||
path[0].eq('ink_env') &&
|
||||
path[1].eq('types')
|
||||
) ||
|
||||
INK_PRIMITIVE_ALWAYS.includes(path[path.length - 1].toString())
|
||||
PRIMITIVE_INK.includes(path[path.length - 1].toString()) ||
|
||||
PRIMITIVE_SP.includes(path.join('::'))
|
||||
);
|
||||
let typeDef: TypeDef;
|
||||
|
||||
@@ -100,9 +184,9 @@ export class GenericPortableRegistry extends Struct {
|
||||
} else if (type.def.isCompact) {
|
||||
typeDef = this.#extractCompact(lookupIndex, type.def.asCompact);
|
||||
} else if (type.def.isComposite) {
|
||||
typeDef = this.#extractComposite(lookupIndex, type.def.asComposite);
|
||||
typeDef = this.#extractComposite(lookupIndex, type, type.def.asComposite);
|
||||
} else if (type.def.isHistoricMetaCompat) {
|
||||
typeDef = getTypeDef(type.def.asHistoricMetaCompat);
|
||||
typeDef = this.#extractHistoric(lookupIndex, type.def.asHistoricMetaCompat);
|
||||
} else if (type.def.isPrimitive) {
|
||||
typeDef = this.#extractPrimitive(lookupIndex, type);
|
||||
} else if (type.def.isSequence) {
|
||||
@@ -118,41 +202,38 @@ export class GenericPortableRegistry extends Struct {
|
||||
throw new Error(`PortableRegistry: Error extracting ${stringify(type)}: ${(error as Error).message}`);
|
||||
}
|
||||
|
||||
const displayName = path.pop()?.toString();
|
||||
|
||||
return {
|
||||
...(displayName
|
||||
? { displayName }
|
||||
: {}
|
||||
),
|
||||
...(path.length > 1
|
||||
? { namespace: path.map((s) => s.toString()).join('::') }
|
||||
: {}
|
||||
),
|
||||
docs: type.docs.map((d) => d.toString()),
|
||||
namespace: path.join('::'),
|
||||
...typeDef
|
||||
};
|
||||
}
|
||||
|
||||
#extractArray (lookupIndex: number, { len: length, type }: SiTypeDefArray): TypeDef {
|
||||
#extractArray (_: number, { len: length, type }: SiTypeDefArray): TypeDef {
|
||||
assert(!length || length.toNumber() <= 256, 'PortableRegistry: Only support for [Type; <length>], where length <= 256');
|
||||
|
||||
return {
|
||||
return withTypeString(this.registry, {
|
||||
info: TypeDefInfo.VecFixed,
|
||||
length: length.toNumber(),
|
||||
sub: this.#createSiDef(type),
|
||||
type: this.registry.createLookupType(lookupIndex)
|
||||
};
|
||||
sub: this.#createSiDef(type)
|
||||
});
|
||||
}
|
||||
|
||||
#extractCompact (lookupIndex: number, { type }: SiTypeDefCompact): TypeDef {
|
||||
return {
|
||||
#extractCompact (_: number, { type }: SiTypeDefCompact): TypeDef {
|
||||
return withTypeString(this.registry, {
|
||||
info: TypeDefInfo.Compact,
|
||||
sub: this.#createSiDef(type),
|
||||
type: this.registry.createLookupType(lookupIndex)
|
||||
};
|
||||
sub: this.#createSiDef(type)
|
||||
});
|
||||
}
|
||||
|
||||
#extractComposite (lookupIndex: number, { fields }: SiTypeDefComposite): TypeDef {
|
||||
#extractComposite (lookupIndex: number, { params, path }: SiType, { fields }: SiTypeDefComposite): TypeDef {
|
||||
if (path.length === 1 && path[0].eq('BTreeMap')) {
|
||||
return withTypeString(this.registry, {
|
||||
info: TypeDefInfo.BTreeMap,
|
||||
sub: params.map(({ type }) => this.#createSiDef(type.unwrap()))
|
||||
});
|
||||
}
|
||||
|
||||
return this.#extractFields(lookupIndex, fields);
|
||||
}
|
||||
|
||||
@@ -165,41 +246,81 @@ export class GenericPortableRegistry extends Struct {
|
||||
|
||||
assert(isTuple || isStruct, 'PortableRegistry: Invalid fields type detected, expected either Tuple or Struct');
|
||||
|
||||
if (isTuple) {
|
||||
if (fields.length === 0) {
|
||||
return {
|
||||
info: TypeDefInfo.Null,
|
||||
type: 'Null'
|
||||
};
|
||||
} else if (fields.length === 1) {
|
||||
return {
|
||||
...this.#createSiDef(fields[0].type),
|
||||
...(fields[0].name.isSome
|
||||
? { name: stringCamelCase(fields[0].name.unwrap()) }
|
||||
: {}
|
||||
)
|
||||
};
|
||||
}
|
||||
if (fields.length === 0) {
|
||||
return {
|
||||
info: TypeDefInfo.Null,
|
||||
type: 'Null'
|
||||
};
|
||||
} else if (isTuple && fields.length === 1) {
|
||||
return this.#createSiDef(fields[0].type);
|
||||
}
|
||||
|
||||
const sub = fields.map(({ name, type }) => ({
|
||||
...this.#createSiDef(type),
|
||||
...(name.isSome
|
||||
? { name: stringCamelCase(name.unwrap()) }
|
||||
: {}
|
||||
)
|
||||
}));
|
||||
const [sub, alias] = this.#extractFieldsAlias(fields);
|
||||
|
||||
return {
|
||||
return withTypeString(this.registry, {
|
||||
info: isTuple // Tuple check first
|
||||
? TypeDefInfo.Tuple
|
||||
: TypeDefInfo.Struct,
|
||||
sub,
|
||||
type: `(${sub.map(({ type }) => type).join(',')})`
|
||||
...(
|
||||
lookupIndex === -1
|
||||
? {}
|
||||
: {
|
||||
lookupIndex,
|
||||
lookupName: this.#names[lookupIndex]
|
||||
}
|
||||
),
|
||||
...(
|
||||
alias.size
|
||||
? { alias }
|
||||
: {}
|
||||
),
|
||||
sub
|
||||
});
|
||||
}
|
||||
|
||||
#extractFieldsAlias (fields: SiField[]): [TypeDef[], Map<string, string>] {
|
||||
const alias = new Map<string, string>();
|
||||
const sub = fields.map(({ docs, name, type }) => {
|
||||
const typeDef = this.#createSiDef(type);
|
||||
|
||||
if (name.isNone) {
|
||||
return typeDef;
|
||||
}
|
||||
|
||||
let nameField = stringCamelCase(name.unwrap());
|
||||
let nameOrig: string | null = null;
|
||||
|
||||
if (nameField.includes('#')) {
|
||||
nameOrig = nameField;
|
||||
nameField = nameOrig.replace(/#/g, '_');
|
||||
} else if (RESERVED.includes(nameField)) {
|
||||
nameOrig = nameField;
|
||||
nameField = `${nameField}_`;
|
||||
}
|
||||
|
||||
if (nameOrig) {
|
||||
alias.set(nameField, nameOrig);
|
||||
}
|
||||
|
||||
return {
|
||||
...typeDef,
|
||||
docs: docs.map((d) => d.toString()),
|
||||
name: nameField
|
||||
};
|
||||
});
|
||||
|
||||
return [sub, alias];
|
||||
}
|
||||
|
||||
#extractHistoric (_: number, type: Type): TypeDef {
|
||||
return {
|
||||
...getTypeDef(type),
|
||||
displayName: type.toString(),
|
||||
isFromSi: true
|
||||
};
|
||||
}
|
||||
|
||||
#extractPrimitive (lookupIndex: number, type: SiType): TypeDef {
|
||||
#extractPrimitive (_: number, type: SiType): TypeDef {
|
||||
const typeStr = type.def.asPrimitive.type.toString();
|
||||
|
||||
return {
|
||||
@@ -208,68 +329,103 @@ export class GenericPortableRegistry extends Struct {
|
||||
};
|
||||
}
|
||||
|
||||
#extractPrimitivePath (lookupIndex: number, type: SiType): TypeDef {
|
||||
#extractPrimitivePath (_: number, type: SiType): TypeDef {
|
||||
const displayName = type.path[type.path.length - 1].toString();
|
||||
|
||||
return {
|
||||
displayName,
|
||||
info: TypeDefInfo.Plain,
|
||||
type: type.path[type.path.length - 1].toString()
|
||||
type: displayName
|
||||
};
|
||||
}
|
||||
|
||||
#extractSequence (lookupIndex: number, { type }: SiTypeDefSequence): TypeDef {
|
||||
return {
|
||||
const sub = this.#createSiDef(type);
|
||||
|
||||
return withTypeString(this.registry, {
|
||||
info: TypeDefInfo.Vec,
|
||||
sub: this.#createSiDef(type),
|
||||
type: this.registry.createLookupType(lookupIndex)
|
||||
};
|
||||
lookupIndex,
|
||||
lookupName: this.#names[lookupIndex],
|
||||
sub
|
||||
});
|
||||
}
|
||||
|
||||
#extractTuple (lookupIndex: number, ids: SiTypeDefTuple): TypeDef {
|
||||
return ids.length === 1
|
||||
? this.getTypeDef(ids[0])
|
||||
: {
|
||||
info: TypeDefInfo.Tuple,
|
||||
sub: ids.map((type) => this.#createSiDef(type)),
|
||||
type: this.registry.createLookupType(lookupIndex)
|
||||
if (ids.length === 0) {
|
||||
return {
|
||||
info: TypeDefInfo.Null,
|
||||
type: 'Null'
|
||||
};
|
||||
} else if (ids.length === 1) {
|
||||
return this.getTypeDef(ids[0]);
|
||||
}
|
||||
|
||||
const sub = ids.map((type) => this.#createSiDef(type));
|
||||
|
||||
return withTypeString(this.registry, {
|
||||
info: TypeDefInfo.Tuple,
|
||||
lookupIndex,
|
||||
lookupName: this.#names[lookupIndex],
|
||||
sub
|
||||
});
|
||||
}
|
||||
|
||||
#extractVariant (lookupIndex: number, { params, path }: SiType, { variants }: SiTypeDefVariant): TypeDef {
|
||||
const specialVariant = path[0].toString();
|
||||
|
||||
return specialVariant === 'Option'
|
||||
? {
|
||||
if (specialVariant === 'Option') {
|
||||
return withTypeString(this.registry, {
|
||||
info: TypeDefInfo.Option,
|
||||
sub: this.#createSiDef(params[0].type.unwrap()),
|
||||
type: this.registry.createLookupType(lookupIndex)
|
||||
}
|
||||
: specialVariant === 'Result'
|
||||
? {
|
||||
info: TypeDefInfo.Result,
|
||||
sub: params.map((p, index) => ({
|
||||
name: ['Ok', 'Error'][index],
|
||||
...this.#createSiDef(p.type.unwrap())
|
||||
})),
|
||||
type: this.registry.createLookupType(lookupIndex)
|
||||
}
|
||||
: {
|
||||
info: TypeDefInfo.Enum,
|
||||
sub: this.#extractVariantSub(lookupIndex, variants),
|
||||
type: this.registry.createLookupType(lookupIndex)
|
||||
};
|
||||
sub: this.#createSiDef(params[0].type.unwrap())
|
||||
});
|
||||
} else if (specialVariant === 'Result') {
|
||||
return withTypeString(this.registry, {
|
||||
info: TypeDefInfo.Result,
|
||||
sub: params.map(({ type }) => this.#createSiDef(type.unwrap())).map((def, index) => ({
|
||||
name: ['Ok', 'Error'][index],
|
||||
...def
|
||||
}))
|
||||
});
|
||||
} else if (variants.length === 0) {
|
||||
return {
|
||||
info: TypeDefInfo.Null,
|
||||
type: 'Null'
|
||||
};
|
||||
}
|
||||
|
||||
return this.#extractVariantEnum(lookupIndex, variants);
|
||||
}
|
||||
|
||||
#extractVariantSub (lookupIndex: number, variants: SiVariant[]): TypeDef[] {
|
||||
return variants.every(({ fields }) => fields.length === 0)
|
||||
? variants.map(({ index, name }) => ({
|
||||
index: index.toNumber(),
|
||||
info: TypeDefInfo.Plain,
|
||||
name: name.toString(),
|
||||
type: 'Null'
|
||||
}))
|
||||
: variants.map(({ fields, index, name }) => ({
|
||||
...this.#extractFields(lookupIndex, fields),
|
||||
index: index.toNumber(),
|
||||
name: name.toString()
|
||||
}));
|
||||
#extractVariantEnum (lookupIndex: number, variants: SiVariant[]): TypeDef {
|
||||
const sub: (TypeDef & { name: string })[] = [];
|
||||
|
||||
// we may get entries out of order, arrange them first before creating with gaps filled
|
||||
variants
|
||||
.sort((a, b) => a.index.cmp(b.index))
|
||||
.forEach(({ fields, index, name }) => {
|
||||
const desired = index.toNumber();
|
||||
|
||||
while (sub.length !== desired) {
|
||||
sub.push({
|
||||
index: sub.length,
|
||||
info: TypeDefInfo.Null,
|
||||
name: `Unused${sub.length}`,
|
||||
type: 'Null'
|
||||
});
|
||||
}
|
||||
|
||||
sub.push({
|
||||
...this.#extractFields(-1, fields),
|
||||
index: index.toNumber(),
|
||||
name: name.toString()
|
||||
});
|
||||
});
|
||||
|
||||
return withTypeString(this.registry, {
|
||||
info: TypeDefInfo.Enum,
|
||||
lookupIndex,
|
||||
lookupName: this.#names[lookupIndex],
|
||||
sub
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ export function defaultValues (registry: Registry, rpcData: string, withThrow =
|
||||
|
||||
metadata.asLatest.modules.filter(({ storage }): boolean => storage.isSome).forEach((mod): void => {
|
||||
mod.storage.unwrap().items.forEach(({ fallback, modifier, name, type }): void => {
|
||||
const inner = unwrapStorageType(type, modifier.isOptional);
|
||||
const inner = unwrapStorageType(registry, type, modifier.isOptional);
|
||||
const location = `${mod.name.toString()}.${name.toString()}: ${inner}`;
|
||||
|
||||
it(`creates default types for ${location}`, (): void => {
|
||||
|
||||
@@ -4,29 +4,11 @@
|
||||
import type { EventMetadataLatest, EventMetadataV13, FunctionMetadataLatest, FunctionMetadataV13, MetadataLatest, MetadataV13, ModuleConstantMetadataLatest, ModuleConstantMetadataV13, ModuleMetadataLatest, ModuleMetadataV13, StorageEntryMetadataLatest, StorageMetadataLatest, StorageMetadataV13 } from '../../interfaces/metadata';
|
||||
import type { OverrideModuleType, Registry } from '../../types';
|
||||
|
||||
import { getModuleTypes } from '@polkadot/types-known';
|
||||
import { getModuleTypes, knownOrigins } from '@polkadot/types-known';
|
||||
import { stringCamelCase } from '@polkadot/util';
|
||||
|
||||
import { Type } from '../../primitive';
|
||||
|
||||
// FIXME: Need some sort of solution for specifying these
|
||||
// Since we don't have insight into the origin specification, we can only define what we know about
|
||||
// in a pure Substrate/Polkadot implementation, any other custom origins won't be handled at all
|
||||
const KNOWN_ORIGINS: Record<string, string> = {
|
||||
/* eslint-disable sort-keys */
|
||||
// Substrate
|
||||
Council: 'CollectiveOrigin',
|
||||
System: 'SystemOrigin',
|
||||
TechnicalCommittee: 'CollectiveOrigin',
|
||||
// Polkadot
|
||||
Xcm: 'XcmOrigin',
|
||||
XcmPallet: 'XcmOrigin',
|
||||
// Acala
|
||||
Authority: 'AuthorityOrigin',
|
||||
GeneralCouncil: 'CollectiveOrigin'
|
||||
/* eslint-enable sort-keys */
|
||||
};
|
||||
|
||||
const BOXES = [['<', '>'], ['<', ','], [',', '>'], ['(', ')'], ['(', ','], [',', ','], [',', ')']];
|
||||
|
||||
/**
|
||||
@@ -131,7 +113,7 @@ function registerOriginCaller (registry: Registry, modules: ModuleMetadataV13[],
|
||||
result[`Empty${i}`] = 'Null';
|
||||
}
|
||||
|
||||
result[name] = KNOWN_ORIGINS[name] || 'Null';
|
||||
result[name] = knownOrigins[name] || 'Null';
|
||||
|
||||
return result;
|
||||
}, {})
|
||||
|
||||
@@ -0,0 +1,325 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ErrorMetadataV13, EventMetadataV13, ExtrinsicMetadataV13, ExtrinsicMetadataV14, FunctionMetadataV13, MetadataV13, MetadataV14, ModuleConstantMetadataV13, ModuleMetadataV13, PalletCallMetadataV14, PalletConstantMetadataV14, PalletErrorMetadataV14, PalletEventMetadataV14, PalletMetadataV14, PalletStorageMetadataV14, StorageEntryMetadataV14, StorageEntryTypeV14, StorageMetadataV13 } from '../../interfaces/metadata';
|
||||
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 { getModuleTypes, knownOrigins } from '@polkadot/types-known';
|
||||
import { stringCamelCase } from '@polkadot/util';
|
||||
|
||||
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 {
|
||||
const type = _type.toString();
|
||||
const index = types.findIndex(({ def }) =>
|
||||
def.HistoricMetaCompat === type
|
||||
);
|
||||
|
||||
if (index !== -1) {
|
||||
return index;
|
||||
}
|
||||
|
||||
return types.push({
|
||||
def: { HistoricMetaCompat: type }
|
||||
}) - 1;
|
||||
}
|
||||
|
||||
function variantType (modName: Text, variantType: string, types: TypeSpec[], variants: SiVariant[]): number {
|
||||
return types.push({
|
||||
def: {
|
||||
Variant: { variants }
|
||||
},
|
||||
path: [`pallet_${modName.toString()}`, 'pallet', variantType]
|
||||
}) - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* generate & register the OriginCaller type
|
||||
**/
|
||||
function registerOriginCaller (registry: Registry, modules: ModuleMetadataV13[], metaVersion: number): void {
|
||||
registry.register({
|
||||
OriginCaller: {
|
||||
_enum: modules
|
||||
.map((mod, index): [string, number] => [
|
||||
mod.name.toString(),
|
||||
metaVersion >= 12
|
||||
? mod.index.toNumber()
|
||||
: index
|
||||
])
|
||||
.sort((a, b) => a[1] - b[1])
|
||||
.reduce((result: Record<string, string>, [name, index]): Record<string, string> => {
|
||||
for (let i = Object.keys(result).length; i < index; i++) {
|
||||
result[`Empty${i}`] = 'Null';
|
||||
}
|
||||
|
||||
result[name] = knownOrigins[name] || 'Null';
|
||||
|
||||
return result;
|
||||
}, {})
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Find and apply the correct type override
|
||||
* @internal
|
||||
**/
|
||||
function setTypeOverride (sectionTypes: OverrideModuleType, types: Type[]): void {
|
||||
types.forEach((type): void => {
|
||||
const override = Object.keys(sectionTypes).find((aliased) => type.eq(aliased));
|
||||
|
||||
if (override) {
|
||||
type.setOverride(sectionTypes[override]);
|
||||
} else {
|
||||
// FIXME: NOT happy with this approach, but gets over the initial hump cased by (Vec<Announcement>,BalanceOf)
|
||||
const orig = type.toString();
|
||||
const alias = Object
|
||||
.entries(sectionTypes)
|
||||
.reduce((result: string, [from, to]) =>
|
||||
BOXES.reduce((result, [one, two]) =>
|
||||
result.replace(`${one}${from}${two}`, `${one}${to}${two}`), result), orig);
|
||||
|
||||
if (orig !== alias) {
|
||||
type.setOverride(alias);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
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) })
|
||||
),
|
||||
index,
|
||||
name
|
||||
});
|
||||
});
|
||||
|
||||
return registry.createType('PalletCallMetadataV14', {
|
||||
type: variantType(modName, 'Call', types, variants)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply module-specific type overrides (always be done as part of toV14)
|
||||
* @internal
|
||||
*/
|
||||
function convertConstants (registry: Registry, types: TypeSpec[], 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),
|
||||
value
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply module-specific type overrides (always be done as part of toV14)
|
||||
* @internal
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function convertErrors (registry: Registry, types: TypeSpec[], modName: Text, errors: ErrorMetadataV13[], _sectionTypes: OverrideModuleType): PalletErrorMetadataV14 {
|
||||
const variants = errors.map(({ docs, name }, index): SiVariant =>
|
||||
registry.createType('SiVariant', {
|
||||
docs,
|
||||
fields: [],
|
||||
index,
|
||||
name
|
||||
})
|
||||
);
|
||||
|
||||
return registry.createType('PalletErrorMetadataV14', {
|
||||
type: variantType(modName, 'Error', types, variants)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
const variants = events.map(({ args, docs, name }, index): SiVariant => {
|
||||
setTypeOverride(sectionTypes, args);
|
||||
|
||||
return registry.createType('SiVariant', {
|
||||
docs,
|
||||
fields: args.map((type) =>
|
||||
registry.createType('SiField', { type: compatType(types, type) })
|
||||
),
|
||||
index,
|
||||
name
|
||||
});
|
||||
});
|
||||
|
||||
return registry.createType('PalletEventMetadataV14', {
|
||||
type: variantType(modName, 'Event', types, variants)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply module-specific storage type overrides (always part of toV14)
|
||||
* @internal
|
||||
**/
|
||||
function convertStorage (registry: Registry, types: TypeSpec[], { items, prefix }: StorageMetadataV13, sectionTypes: OverrideModuleType): PalletStorageMetadataV14 {
|
||||
return registry.createType('PalletStorageMetadataV14', {
|
||||
items: items.map(({ docs, fallback, modifier, name, type }): StorageEntryMetadataV14 => {
|
||||
let entryType: StorageEntryTypeV14;
|
||||
|
||||
if (type.isPlain) {
|
||||
const plain = type.asPlain;
|
||||
|
||||
setTypeOverride(sectionTypes, [plain]);
|
||||
|
||||
entryType = registry.createType('StorageEntryTypeV14', {
|
||||
Plain: compatType(types, plain)
|
||||
});
|
||||
} else if (type.isMap) {
|
||||
const map = type.asMap;
|
||||
|
||||
setTypeOverride(sectionTypes, [map.value, map.key]);
|
||||
|
||||
entryType = registry.createType('StorageEntryTypeV14', {
|
||||
Map: {
|
||||
hasher: map.hasher,
|
||||
key: compatType(types, map.key),
|
||||
value: compatType(types, map.value)
|
||||
}
|
||||
});
|
||||
} else if (type.isDoubleMap) {
|
||||
const dm = type.asDoubleMap;
|
||||
|
||||
setTypeOverride(sectionTypes, [dm.value, dm.key1, dm.key2]);
|
||||
|
||||
entryType = registry.createType('StorageEntryTypeV14', {
|
||||
DoubleMap: {
|
||||
hasher: dm.hasher,
|
||||
key1: compatType(types, dm.key1),
|
||||
key2: compatType(types, dm.key2),
|
||||
key2Hasher: dm.key2Hasher,
|
||||
value: compatType(types, dm.value)
|
||||
}
|
||||
});
|
||||
} else {
|
||||
const nm = type.asNMap;
|
||||
|
||||
setTypeOverride(sectionTypes, [nm.value, ...nm.keyVec]);
|
||||
|
||||
const key = types.push({
|
||||
def: {
|
||||
Tuple: nm.keyVec.map((type) =>
|
||||
compatType(types, type)
|
||||
)
|
||||
}
|
||||
}) - 1;
|
||||
|
||||
entryType = registry.createType('StorageEntryTypeV14', {
|
||||
NMap: {
|
||||
hashers: nm.hashers,
|
||||
key,
|
||||
value: compatType(types, nm.value)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return registry.createType('StorageEntryMetadataV14', {
|
||||
docs,
|
||||
fallback,
|
||||
modifier,
|
||||
name,
|
||||
type: entryType
|
||||
});
|
||||
}),
|
||||
prefix
|
||||
});
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function convertExtrinsic (registry: Registry, _types: TypeSpec[], { signedExtensions, version }: ExtrinsicMetadataV13): ExtrinsicMetadataV14 {
|
||||
return registry.createType('ExtrinsicMetadataV14', {
|
||||
signedExtensions: signedExtensions.map((identifier) => ({
|
||||
identifier,
|
||||
type: 0 // we don't map the fields at all
|
||||
})),
|
||||
type: 0, // Map to extrinsic like in v14?
|
||||
version: version
|
||||
});
|
||||
}
|
||||
|
||||
/** @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 {
|
||||
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),
|
||||
index: mod.index,
|
||||
name: mod.name,
|
||||
storage: storage && convertStorage(registry, types, storage, sectionTypes)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the Metadata to v14
|
||||
* @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
|
||||
registerOriginCaller(registry, v13.modules, metaVersion);
|
||||
|
||||
const extrinsic = convertExtrinsic(registry, types, v13.extrinsic);
|
||||
const pallets = v13.modules.map((mod) =>
|
||||
createPallet(registry, types, mod, {
|
||||
calls: mod.calls.unwrapOr(null),
|
||||
constants: mod.constants,
|
||||
errors: mod.errors.length ? mod.errors : null,
|
||||
events: mod.events.unwrapOr(null),
|
||||
storage: mod.storage.unwrapOr(null)
|
||||
})
|
||||
);
|
||||
|
||||
return registry.createType('MetadataV14', {
|
||||
extrinsic,
|
||||
lookup: {
|
||||
types: types.map((type, id) =>
|
||||
registry.createType('PortableType', { id, type })
|
||||
)
|
||||
},
|
||||
pallets
|
||||
});
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -3,4 +3,4 @@
|
||||
|
||||
// Auto-generated by @polkadot/dev, do not edit
|
||||
|
||||
export const packageInfo = { name: '@polkadot/types', version: '5.1.1' };
|
||||
export const packageInfo = { name: '@polkadot/types', version: '5.2.1' };
|
||||
|
||||
@@ -33,7 +33,7 @@ const HASHER_MAP: Record<keyof typeof AllHashers, [number, boolean]> = {
|
||||
};
|
||||
|
||||
/** @internal */
|
||||
export function unwrapStorageType (type: StorageEntryTypeLatest, isOptional?: boolean): keyof InterfaceTypes {
|
||||
export function unwrapStorageType (_: Registry, type: StorageEntryTypeLatest, isOptional?: boolean): keyof InterfaceTypes {
|
||||
const outputType = type.isPlain
|
||||
? type.asPlain.toString()
|
||||
: type.isMap
|
||||
@@ -142,16 +142,16 @@ function getMeta (value: StorageKey | StorageEntry | [StorageEntry, unknown]): S
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function getType (value: StorageKey | StorageEntry | [StorageEntry, unknown]): string {
|
||||
function getType (registry: Registry, value: StorageKey | StorageEntry | [StorageEntry, unknown]): string {
|
||||
if (value instanceof StorageKey) {
|
||||
return value.outputType;
|
||||
} else if (isFunction(value)) {
|
||||
return unwrapStorageType(value.meta.type);
|
||||
return unwrapStorageType(registry, value.meta.type);
|
||||
} else if (Array.isArray(value)) {
|
||||
const [fn] = value;
|
||||
|
||||
if (fn.meta) {
|
||||
return unwrapStorageType(fn.meta.type);
|
||||
return unwrapStorageType(registry, fn.meta.type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ export class StorageKey<A extends AnyTuple = AnyTuple> extends Bytes implements
|
||||
|
||||
super(registry, key);
|
||||
|
||||
this._outputType = getType(value as StorageKey);
|
||||
this._outputType = getType(registry, value as StorageKey);
|
||||
|
||||
// decode the args (as applicable based on the key and the hashers, after all init)
|
||||
this.setMeta(getMeta(value as StorageKey), override.section || section, override.method || method);
|
||||
@@ -237,7 +237,7 @@ export class StorageKey<A extends AnyTuple = AnyTuple> extends Bytes implements
|
||||
this._section = section || this._section;
|
||||
|
||||
if (meta) {
|
||||
this._outputType = unwrapStorageType(meta.type);
|
||||
this._outputType = unwrapStorageType(this.registry, meta.type);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { BN } from '@polkadot/util';
|
||||
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';
|
||||
@@ -120,6 +121,7 @@ export interface Registry {
|
||||
|
||||
createClass <K extends keyof InterfaceTypes> (type: K): Constructor<InterfaceTypes[K]>;
|
||||
createType <K extends keyof InterfaceTypes> (type: K, ...params: unknown[]): InterfaceTypes[K];
|
||||
createTypeUnsafe <T extends Codec = Codec, K extends string = string> (type: K, params: unknown[], options?: CreateOptions): T;
|
||||
get <T extends Codec = Codec> (name: string, withUnknown?: boolean): Constructor<T> | undefined;
|
||||
getChainProperties (): ChainProperties | undefined;
|
||||
getClassName (clazz: Constructor): string | undefined;
|
||||
|
||||
@@ -57,37 +57,37 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/core@npm:7.14.6, @babel/core@npm:^7.1.0, @babel/core@npm:^7.14.6, @babel/core@npm:^7.7.2, @babel/core@npm:^7.7.5":
|
||||
version: 7.14.6
|
||||
resolution: "@babel/core@npm:7.14.6"
|
||||
"@babel/core@npm:7.14.8, @babel/core@npm:^7.1.0, @babel/core@npm:^7.14.6, @babel/core@npm:^7.14.8, @babel/core@npm:^7.7.2, @babel/core@npm:^7.7.5":
|
||||
version: 7.14.8
|
||||
resolution: "@babel/core@npm:7.14.8"
|
||||
dependencies:
|
||||
"@babel/code-frame": ^7.14.5
|
||||
"@babel/generator": ^7.14.5
|
||||
"@babel/generator": ^7.14.8
|
||||
"@babel/helper-compilation-targets": ^7.14.5
|
||||
"@babel/helper-module-transforms": ^7.14.5
|
||||
"@babel/helpers": ^7.14.6
|
||||
"@babel/parser": ^7.14.6
|
||||
"@babel/helper-module-transforms": ^7.14.8
|
||||
"@babel/helpers": ^7.14.8
|
||||
"@babel/parser": ^7.14.8
|
||||
"@babel/template": ^7.14.5
|
||||
"@babel/traverse": ^7.14.5
|
||||
"@babel/types": ^7.14.5
|
||||
"@babel/traverse": ^7.14.8
|
||||
"@babel/types": ^7.14.8
|
||||
convert-source-map: ^1.7.0
|
||||
debug: ^4.1.0
|
||||
gensync: ^1.0.0-beta.2
|
||||
json5: ^2.1.2
|
||||
semver: ^6.3.0
|
||||
source-map: ^0.5.0
|
||||
checksum: 6ede604d8de7a103c087b96a58548a3d27efb9e53de6ecc84f4b4ca947cd91f02b0289fc04557b04eb6e31243dbeabdcdb8fd520a1780f284333f56eb1b58913
|
||||
checksum: 4c9a5b21020791659095a514f11c81159a96477037682183f23a1084732e0e3dbb58986e14ebf3a03a31230a75d8b2e1d23644ca84204eddf70018cba983035f
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/generator@npm:^7.14.5, @babel/generator@npm:^7.7.2":
|
||||
version: 7.14.5
|
||||
resolution: "@babel/generator@npm:7.14.5"
|
||||
"@babel/generator@npm:^7.14.8, @babel/generator@npm:^7.7.2":
|
||||
version: 7.14.8
|
||||
resolution: "@babel/generator@npm:7.14.8"
|
||||
dependencies:
|
||||
"@babel/types": ^7.14.5
|
||||
"@babel/types": ^7.14.8
|
||||
jsesc: ^2.5.1
|
||||
source-map: ^0.5.0
|
||||
checksum: 7fcfeaf17e8e76ea91c66dc86c776d2112f52ce0315d3f4ca6a74b6eada0be1592d1ea6286d7241d3f634b63717ceef5d180d041a0b3dca9d071ba2e5fa7c77b
|
||||
checksum: 0fdec7e1991fc3973d241e4c5e7d69f8c4ab063359695e6a019e4a5a0139a768ddce91d0705d7bd8a28f3befb5abde68355e19745fcdb45c40a26cf53d879191
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -226,19 +226,19 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/helper-module-transforms@npm:^7.14.5":
|
||||
version: 7.14.5
|
||||
resolution: "@babel/helper-module-transforms@npm:7.14.5"
|
||||
"@babel/helper-module-transforms@npm:^7.14.5, @babel/helper-module-transforms@npm:^7.14.8":
|
||||
version: 7.14.8
|
||||
resolution: "@babel/helper-module-transforms@npm:7.14.8"
|
||||
dependencies:
|
||||
"@babel/helper-module-imports": ^7.14.5
|
||||
"@babel/helper-replace-supers": ^7.14.5
|
||||
"@babel/helper-simple-access": ^7.14.5
|
||||
"@babel/helper-simple-access": ^7.14.8
|
||||
"@babel/helper-split-export-declaration": ^7.14.5
|
||||
"@babel/helper-validator-identifier": ^7.14.5
|
||||
"@babel/helper-validator-identifier": ^7.14.8
|
||||
"@babel/template": ^7.14.5
|
||||
"@babel/traverse": ^7.14.5
|
||||
"@babel/types": ^7.14.5
|
||||
checksum: f5d64c0242ec8949ee09069a634d28ae750ab22f9533ea90eab9eaf3405032a33b0b329a63fac0a7901482efb8a388a06279f7544225a0bc3c1b92b306ab2b6e
|
||||
"@babel/traverse": ^7.14.8
|
||||
"@babel/types": ^7.14.8
|
||||
checksum: 527b3383c40788b04c815da1ded4ac8cdc21e3356517fc81bcd03b319c1b58901638bb641a6f0cd00f493c7a31a8ae7123213d59c1d4f57cec32185b5d9f79a2
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -281,12 +281,12 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/helper-simple-access@npm:^7.14.5":
|
||||
version: 7.14.5
|
||||
resolution: "@babel/helper-simple-access@npm:7.14.5"
|
||||
"@babel/helper-simple-access@npm:^7.14.5, @babel/helper-simple-access@npm:^7.14.8":
|
||||
version: 7.14.8
|
||||
resolution: "@babel/helper-simple-access@npm:7.14.8"
|
||||
dependencies:
|
||||
"@babel/types": ^7.14.5
|
||||
checksum: cd795416bd10dd2f1bdebb36f1af08bf263024fdbf789cfda5dd1fbf4fea1fd0375e21d0bcb910a7d49b09b7480340797dcdfc888fbc895aeae45c145358ad75
|
||||
"@babel/types": ^7.14.8
|
||||
checksum: c1dae88c956154c854bb1679d19b9158ff1c8241329a4a70026ec16c594b9637e73647e5a1a0f9b7c47b2309201f633c259fb41d06a800496283debce6a67fab
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -308,10 +308,10 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/helper-validator-identifier@npm:^7.14.5":
|
||||
version: 7.14.5
|
||||
resolution: "@babel/helper-validator-identifier@npm:7.14.5"
|
||||
checksum: 6366bceab4498785defc083a1bd96344f788d90a1aa7a6f18d6813c1d3d134640bfc05690453c0b79bbfc820472cf5b29110dfddaca1f8e2763dfe1bd5df0b88
|
||||
"@babel/helper-validator-identifier@npm:^7.14.5, @babel/helper-validator-identifier@npm:^7.14.8":
|
||||
version: 7.14.8
|
||||
resolution: "@babel/helper-validator-identifier@npm:7.14.8"
|
||||
checksum: f21ad9a9f0a66a02e0e5f62d505cbeb9e01a7ac5bd34be0af9f916f0b6d8d40718efaf51b656b41759e3454703090b4d386105f1f97f6598ee5a3f8eb98adc6a
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -334,14 +334,14 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/helpers@npm:^7.14.6":
|
||||
version: 7.14.6
|
||||
resolution: "@babel/helpers@npm:7.14.6"
|
||||
"@babel/helpers@npm:^7.14.8":
|
||||
version: 7.14.8
|
||||
resolution: "@babel/helpers@npm:7.14.8"
|
||||
dependencies:
|
||||
"@babel/template": ^7.14.5
|
||||
"@babel/traverse": ^7.14.5
|
||||
"@babel/types": ^7.14.5
|
||||
checksum: fe4e73975b062a8b8b95f499f4ac1064c9a53d4ee83cc273c2420250f6a46b59f1f5e35050d41ebe04efd7885a28ceea6f4f16d8eb091e24622f2a4a5eb20f23
|
||||
"@babel/traverse": ^7.14.8
|
||||
"@babel/types": ^7.14.8
|
||||
checksum: 2f1358c19fc1ee744c183f81b499b73977da7d3d3f7a881d457b235754394a503e4717353f29364bd5feb7fa406b1edd1aab92b5ab0765dba945fb559eeb1c65
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -356,12 +356,12 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/parser@npm:^7.0.0, @babel/parser@npm:^7.1.0, @babel/parser@npm:^7.14.5, @babel/parser@npm:^7.14.6, @babel/parser@npm:^7.7.2":
|
||||
version: 7.14.7
|
||||
resolution: "@babel/parser@npm:7.14.7"
|
||||
"@babel/parser@npm:^7.0.0, @babel/parser@npm:^7.1.0, @babel/parser@npm:^7.14.5, @babel/parser@npm:^7.14.8, @babel/parser@npm:^7.7.2":
|
||||
version: 7.14.8
|
||||
resolution: "@babel/parser@npm:7.14.8"
|
||||
bin:
|
||||
parser: ./bin/babel-parser.js
|
||||
checksum: 0d7acc8cf9c19ccd0e80ab0608953f32f4375f3867c080211270e7bb4bb94c551fd1fc3f49b3cc92a4eec356cf507801f5c93c4c72996968bdc4c28815fe0550
|
||||
checksum: 9e532b2bbe690fff8cdaf8c25cfecb684ebe9e9d50d30cd775852dd711649ddb964368b26fda55786404fadf500f944043fb0f731b765104ad857d677dd29ce5
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -1360,12 +1360,12 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/runtime@npm:^7.14.6, @babel/runtime@npm:^7.8.4":
|
||||
version: 7.14.6
|
||||
resolution: "@babel/runtime@npm:7.14.6"
|
||||
"@babel/runtime@npm:^7.14.6, @babel/runtime@npm:^7.14.8, @babel/runtime@npm:^7.8.4":
|
||||
version: 7.14.8
|
||||
resolution: "@babel/runtime@npm:7.14.8"
|
||||
dependencies:
|
||||
regenerator-runtime: ^0.13.4
|
||||
checksum: 927ffed7871f2ed29f967a8dad7a72aa10662f93b6735a89d664a161fa4dc2074b8947ca159a8a0a49cec9a71c8de473d7c2b22d3de0ee4d7dd06d24a7f98018
|
||||
checksum: d2dd0ce51ddab78ac93928b04042425145d0dc8cc2b70150d47934f8703f55702eb0b2894f9bd47f66794ad04d8bb03a6a847d0138fbb7aa0b970b5ccd5cc8b7
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -1380,30 +1380,30 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/traverse@npm:^7.1.0, @babel/traverse@npm:^7.13.0, @babel/traverse@npm:^7.14.5, @babel/traverse@npm:^7.7.2":
|
||||
version: 7.14.5
|
||||
resolution: "@babel/traverse@npm:7.14.5"
|
||||
"@babel/traverse@npm:^7.1.0, @babel/traverse@npm:^7.13.0, @babel/traverse@npm:^7.14.5, @babel/traverse@npm:^7.14.8, @babel/traverse@npm:^7.7.2":
|
||||
version: 7.14.8
|
||||
resolution: "@babel/traverse@npm:7.14.8"
|
||||
dependencies:
|
||||
"@babel/code-frame": ^7.14.5
|
||||
"@babel/generator": ^7.14.5
|
||||
"@babel/generator": ^7.14.8
|
||||
"@babel/helper-function-name": ^7.14.5
|
||||
"@babel/helper-hoist-variables": ^7.14.5
|
||||
"@babel/helper-split-export-declaration": ^7.14.5
|
||||
"@babel/parser": ^7.14.5
|
||||
"@babel/types": ^7.14.5
|
||||
"@babel/parser": ^7.14.8
|
||||
"@babel/types": ^7.14.8
|
||||
debug: ^4.1.0
|
||||
globals: ^11.1.0
|
||||
checksum: 3f4cf5ed685db7fef76d4242cbb14d111db0ea0a7cca163edd29e09ace13312ce085595e7d90fedae2e14e40448a116c222b1060e1c799b87266b8ed92492a3d
|
||||
checksum: f635f99b1b09dfe60105bb162103346f78e058351231e33e9c11a17fabf6d56b4f87837ad14a0f82242c6dd0b97fecd90064735f1e11d47b7429a1c3e99a5ece
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@babel/types@npm:^7.0.0, @babel/types@npm:^7.14.5, @babel/types@npm:^7.3.0, @babel/types@npm:^7.3.3, @babel/types@npm:^7.4.4, @babel/types@npm:^7.8.3":
|
||||
version: 7.14.5
|
||||
resolution: "@babel/types@npm:7.14.5"
|
||||
"@babel/types@npm:^7.0.0, @babel/types@npm:^7.14.5, @babel/types@npm:^7.14.8, @babel/types@npm:^7.3.0, @babel/types@npm:^7.3.3, @babel/types@npm:^7.4.4, @babel/types@npm:^7.8.3":
|
||||
version: 7.14.8
|
||||
resolution: "@babel/types@npm:7.14.8"
|
||||
dependencies:
|
||||
"@babel/helper-validator-identifier": ^7.14.5
|
||||
"@babel/helper-validator-identifier": ^7.14.8
|
||||
to-fast-properties: ^2.0.0
|
||||
checksum: 7c1ab6e8bdf438d44236034cab10f7d0f1971179bc405dca26733a9b89dd87dd692dc49a238a7495075bc41a9a17fb6f08b4d1da45ea6ddcce1e5c8593574aea
|
||||
checksum: d4ebd2e0e52f05cbcb3ded434d9fb49db73c239d98c4f7bd27beaf32fcd7c81aa30618237e87d53505d5e65fd20d688cb4237b6fa927a04831129a6044f2e4b5
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -1866,43 +1866,43 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/api-contract@workspace:packages/api-contract"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/api": 5.1.1
|
||||
"@polkadot/types": 5.1.1
|
||||
"@polkadot/util": ^7.0.2
|
||||
"@babel/runtime": ^7.14.8
|
||||
"@polkadot/api": 5.2.1
|
||||
"@polkadot/types": 5.2.1
|
||||
"@polkadot/util": ^7.0.3
|
||||
rxjs: ^7.2.0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/api-derive@5.1.1, @polkadot/api-derive@workspace:packages/api-derive":
|
||||
"@polkadot/api-derive@5.2.1, @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.14.6
|
||||
"@polkadot/api": 5.1.1
|
||||
"@polkadot/keyring": ^7.0.2
|
||||
"@polkadot/rpc-core": 5.1.1
|
||||
"@polkadot/rpc-provider": 5.1.1
|
||||
"@polkadot/types": 5.1.1
|
||||
"@polkadot/util": ^7.0.2
|
||||
"@polkadot/util-crypto": ^7.0.2
|
||||
"@babel/runtime": ^7.14.8
|
||||
"@polkadot/api": 5.2.1
|
||||
"@polkadot/keyring": ^7.0.3
|
||||
"@polkadot/rpc-core": 5.2.1
|
||||
"@polkadot/rpc-provider": 5.2.1
|
||||
"@polkadot/types": 5.2.1
|
||||
"@polkadot/util": ^7.0.3
|
||||
"@polkadot/util-crypto": ^7.0.3
|
||||
rxjs: ^7.2.0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/api@5.1.1, @polkadot/api@workspace:packages/api":
|
||||
"@polkadot/api@5.2.1, @polkadot/api@workspace:packages/api":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/api@workspace:packages/api"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/api-derive": 5.1.1
|
||||
"@polkadot/keyring": ^7.0.2
|
||||
"@polkadot/rpc-core": 5.1.1
|
||||
"@polkadot/rpc-provider": 5.1.1
|
||||
"@polkadot/types": 5.1.1
|
||||
"@polkadot/types-known": 5.1.1
|
||||
"@polkadot/util": ^7.0.2
|
||||
"@polkadot/util-crypto": ^7.0.2
|
||||
"@babel/runtime": ^7.14.8
|
||||
"@polkadot/api-derive": 5.2.1
|
||||
"@polkadot/keyring": ^7.0.3
|
||||
"@polkadot/rpc-core": 5.2.1
|
||||
"@polkadot/rpc-provider": 5.2.1
|
||||
"@polkadot/types": 5.2.1
|
||||
"@polkadot/types-known": 5.2.1
|
||||
"@polkadot/util": ^7.0.3
|
||||
"@polkadot/util-crypto": ^7.0.3
|
||||
eventemitter3: ^4.0.7
|
||||
rxjs: ^7.2.0
|
||||
languageName: unknown
|
||||
@@ -2001,54 +2001,54 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/keyring@npm:^7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/keyring@npm:7.0.2"
|
||||
"@polkadot/keyring@npm:^7.0.3":
|
||||
version: 7.0.3
|
||||
resolution: "@polkadot/keyring@npm:7.0.3"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/util": 7.0.2
|
||||
"@polkadot/util-crypto": 7.0.2
|
||||
"@babel/runtime": ^7.14.8
|
||||
"@polkadot/util": 7.0.3
|
||||
"@polkadot/util-crypto": 7.0.3
|
||||
peerDependencies:
|
||||
"@polkadot/util": 7.0.2
|
||||
"@polkadot/util-crypto": 7.0.2
|
||||
checksum: f963ca2f474f95f9abacf255b22f95bd188f30e4b288d0703b484e6abc54d76b3244f9a9170af763be04a04fc8198ad1481c22a00e14a1dea449847a8360bd43
|
||||
"@polkadot/util": 7.0.3
|
||||
"@polkadot/util-crypto": 7.0.3
|
||||
checksum: 6fd48479318c86059a6647d546443f694b5aa34da35dacdc470656773d2c36a3c486f517480f26aa64fa881be8d2c9ba67ee54dfca13b0e94cffd00ee9d6674f
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/networks@npm:7.0.2, @polkadot/networks@npm:^7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/networks@npm:7.0.2"
|
||||
"@polkadot/networks@npm:7.0.3, @polkadot/networks@npm:^7.0.3":
|
||||
version: 7.0.3
|
||||
resolution: "@polkadot/networks@npm:7.0.3"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
checksum: c12b99d537523ac57fdfedaf1ecd759d74cd74b4bde121efb6917079b8ad33138799f8f083af602b523ef6473170667c40a80fc035499d9704e9ea8b495d9935
|
||||
"@babel/runtime": ^7.14.8
|
||||
checksum: 774cf76beaef69321abc648b0b254ce4bf94001445ce4139b4ff5cf649060187e27425e737602ad4b8385492ad1dffc9ff53a200d8f2f75382659e461fc00620
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/rpc-core@5.1.1, @polkadot/rpc-core@workspace:packages/rpc-core":
|
||||
"@polkadot/rpc-core@5.2.1, @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.14.6
|
||||
"@polkadot/keyring": ^7.0.2
|
||||
"@polkadot/rpc-provider": 5.1.1
|
||||
"@polkadot/types": 5.1.1
|
||||
"@polkadot/util": ^7.0.2
|
||||
"@babel/runtime": ^7.14.8
|
||||
"@polkadot/keyring": ^7.0.3
|
||||
"@polkadot/rpc-provider": 5.2.1
|
||||
"@polkadot/types": 5.2.1
|
||||
"@polkadot/util": ^7.0.3
|
||||
rxjs: ^7.2.0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/rpc-provider@5.1.1, @polkadot/rpc-provider@workspace:packages/rpc-provider":
|
||||
"@polkadot/rpc-provider@5.2.1, @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.14.6
|
||||
"@polkadot/keyring": ^7.0.2
|
||||
"@polkadot/types": 5.1.1
|
||||
"@polkadot/util": ^7.0.2
|
||||
"@polkadot/util-crypto": ^7.0.2
|
||||
"@polkadot/x-fetch": ^7.0.2
|
||||
"@polkadot/x-global": ^7.0.2
|
||||
"@polkadot/x-ws": ^7.0.2
|
||||
"@babel/runtime": ^7.14.8
|
||||
"@polkadot/keyring": ^7.0.3
|
||||
"@polkadot/types": 5.2.1
|
||||
"@polkadot/util": ^7.0.3
|
||||
"@polkadot/util-crypto": ^7.0.3
|
||||
"@polkadot/x-fetch": ^7.0.3
|
||||
"@polkadot/x-global": ^7.0.3
|
||||
"@polkadot/x-ws": ^7.0.3
|
||||
eventemitter3: ^4.0.7
|
||||
mock-socket: ^9.0.3
|
||||
nock: ^13.1.1
|
||||
@@ -2068,13 +2068,13 @@ __metadata:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/typegen@workspace:packages/typegen"
|
||||
dependencies:
|
||||
"@babel/core": ^7.14.6
|
||||
"@babel/core": ^7.14.8
|
||||
"@babel/register": ^7.14.5
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/api": 5.1.1
|
||||
"@polkadot/rpc-provider": 5.1.1
|
||||
"@polkadot/types": 5.1.1
|
||||
"@polkadot/util": ^7.0.2
|
||||
"@babel/runtime": ^7.14.8
|
||||
"@polkadot/api": 5.2.1
|
||||
"@polkadot/rpc-provider": 5.2.1
|
||||
"@polkadot/types": 5.2.1
|
||||
"@polkadot/util": ^7.0.3
|
||||
"@types/websocket": ^1.0.3
|
||||
"@types/yargs": ^17.0.2
|
||||
handlebars: ^4.7.7
|
||||
@@ -2089,40 +2089,40 @@ __metadata:
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/types-known@5.1.1, @polkadot/types-known@workspace:packages/types-known":
|
||||
"@polkadot/types-known@5.2.1, @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.14.6
|
||||
"@polkadot/networks": ^7.0.2
|
||||
"@polkadot/types": 5.1.1
|
||||
"@polkadot/util": ^7.0.2
|
||||
"@babel/runtime": ^7.14.8
|
||||
"@polkadot/networks": ^7.0.3
|
||||
"@polkadot/types": 5.2.1
|
||||
"@polkadot/util": ^7.0.3
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/types@5.1.1, @polkadot/types@workspace:packages/types":
|
||||
"@polkadot/types@5.2.1, @polkadot/types@workspace:packages/types":
|
||||
version: 0.0.0-use.local
|
||||
resolution: "@polkadot/types@workspace:packages/types"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/keyring": ^7.0.2
|
||||
"@polkadot/util": ^7.0.2
|
||||
"@polkadot/util-crypto": ^7.0.2
|
||||
"@babel/runtime": ^7.14.8
|
||||
"@polkadot/keyring": ^7.0.3
|
||||
"@polkadot/util": ^7.0.3
|
||||
"@polkadot/util-crypto": ^7.0.3
|
||||
"@types/bn.js": ^4.11.6
|
||||
bn.js: ^4.11.9
|
||||
rxjs: ^7.2.0
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
"@polkadot/util-crypto@npm:7.0.2, @polkadot/util-crypto@npm:^7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/util-crypto@npm:7.0.2"
|
||||
"@polkadot/util-crypto@npm:7.0.3, @polkadot/util-crypto@npm:^7.0.3":
|
||||
version: 7.0.3
|
||||
resolution: "@polkadot/util-crypto@npm:7.0.3"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/networks": 7.0.2
|
||||
"@polkadot/util": 7.0.2
|
||||
"@babel/runtime": ^7.14.8
|
||||
"@polkadot/networks": 7.0.3
|
||||
"@polkadot/util": 7.0.3
|
||||
"@polkadot/wasm-crypto": ^4.1.2
|
||||
"@polkadot/x-randomvalues": 7.0.2
|
||||
"@polkadot/x-randomvalues": 7.0.3
|
||||
base-x: ^3.0.8
|
||||
base64-js: ^1.5.1
|
||||
blakejs: ^1.1.1
|
||||
@@ -2135,23 +2135,23 @@ __metadata:
|
||||
tweetnacl: ^1.0.3
|
||||
xxhashjs: ^0.2.2
|
||||
peerDependencies:
|
||||
"@polkadot/util": 7.0.2
|
||||
checksum: a5f500f510f9fd5fe5a6b2566453b44ea94f63bb2fd608c7495a54112fea71abf342730b4c6758947f65835d6a3e6731b5975d775108855a48d3a5637129400b
|
||||
"@polkadot/util": 7.0.3
|
||||
checksum: f1d34c36f337486cc45e501c12268de6a037bd89100e929c3775b2d7162ec3b2ad984991fc8817455bc418d53adb0273c24a898e97d9efaa6a6e3de2828b8890
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/util@npm:7.0.2, @polkadot/util@npm:^7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/util@npm:7.0.2"
|
||||
"@polkadot/util@npm:7.0.3, @polkadot/util@npm:^7.0.3":
|
||||
version: 7.0.3
|
||||
resolution: "@polkadot/util@npm:7.0.3"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/x-textdecoder": 7.0.2
|
||||
"@polkadot/x-textencoder": 7.0.2
|
||||
"@babel/runtime": ^7.14.8
|
||||
"@polkadot/x-textdecoder": 7.0.3
|
||||
"@polkadot/x-textencoder": 7.0.3
|
||||
"@types/bn.js": ^4.11.6
|
||||
bn.js: ^4.11.9
|
||||
camelcase: ^5.3.1
|
||||
ip-regex: ^4.3.0
|
||||
checksum: 5fea37104aa5712a288cdb10b65f8d1dd4e743c7d9b4b09ce1e17aeea5a4400817f187cf8c9fd7c9b2161ede8c99d5b4dc22418b7f7426527cb12592dad91432
|
||||
checksum: e72d3d292e458d1c025922760b91b46dfd2c61f326747ff68435887e275bac9e1d3f1fd66fadf1d02c8664f7479de73e6a8c7ddb9394c039181d43c94bd65287
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -2187,66 +2187,66 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/x-fetch@npm:^7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/x-fetch@npm:7.0.2"
|
||||
"@polkadot/x-fetch@npm:^7.0.3":
|
||||
version: 7.0.3
|
||||
resolution: "@polkadot/x-fetch@npm:7.0.3"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/x-global": 7.0.2
|
||||
"@types/node-fetch": ^2.5.11
|
||||
"@babel/runtime": ^7.14.8
|
||||
"@polkadot/x-global": 7.0.3
|
||||
"@types/node-fetch": ^2.5.12
|
||||
node-fetch: ^2.6.1
|
||||
checksum: aaef78745959210ffdeae25d0845781c3c7afe12e3bc094a50334051817446ff4397d34b2daac3cefa7f75b60216d8588491fc7418daa9ab9b5e6cd1a99b447d
|
||||
checksum: 00ecb052395fb519b81cd4f7b7e69b89bf6e9b4592f8b7a1bb57c773d53b5d3203607869ab02ddc123ffa2f3186e2fd8d5c7ec86dc0f13c9f2977b795ec3ee10
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/x-global@npm:7.0.2, @polkadot/x-global@npm:^7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/x-global@npm:7.0.2"
|
||||
"@polkadot/x-global@npm:7.0.3, @polkadot/x-global@npm:^7.0.3":
|
||||
version: 7.0.3
|
||||
resolution: "@polkadot/x-global@npm:7.0.3"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
checksum: 35705f8d33e746ab872288ae61fd31ead5b2fbefd0ef942f0cf8be76ac3e54a304b3ff9ced960232cb3bca0d71c5515a0abe8e534cc5f2fbcdf543c8df01f1f6
|
||||
"@babel/runtime": ^7.14.8
|
||||
checksum: 1a3cd2ca683c7afc8bc29eb036eb2b0cd96df366041d2f5dff4135507172f72a53289c4cef23b7023a9ee48b2b031a5bbb52fcee29871905bf14d67a75a186c2
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/x-randomvalues@npm:7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/x-randomvalues@npm:7.0.2"
|
||||
"@polkadot/x-randomvalues@npm:7.0.3":
|
||||
version: 7.0.3
|
||||
resolution: "@polkadot/x-randomvalues@npm:7.0.3"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/x-global": 7.0.2
|
||||
checksum: e6f2fd9f7386ceb6124366580ef639f664b9b3624644e4749ac19e2a17456f84078febb953e293fe5cc8cbed287f1ab84e8d1acfe7d075c5a3fb779253ede082
|
||||
"@babel/runtime": ^7.14.8
|
||||
"@polkadot/x-global": 7.0.3
|
||||
checksum: 3cc53437db3de937f1d0c15245d2737276920a9f4e88408ef56c92ebc4f5642c4e179f176b4e38c8b2d5dd2ce40f473d0d629e4224dc615484078c7a0eac61ef
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/x-textdecoder@npm:7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/x-textdecoder@npm:7.0.2"
|
||||
"@polkadot/x-textdecoder@npm:7.0.3":
|
||||
version: 7.0.3
|
||||
resolution: "@polkadot/x-textdecoder@npm:7.0.3"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/x-global": 7.0.2
|
||||
checksum: ad31a9ed430d1886168f42d6b8fc5528c22b783b7c4d086a2c77ac66017af4800c64a80a8466f85e93ea73e5892cebbd1f4612bdd4c7a5ed87227ee9a3f98f5e
|
||||
"@babel/runtime": ^7.14.8
|
||||
"@polkadot/x-global": 7.0.3
|
||||
checksum: ba517cadb6438e5eb2080daa2cb158d79bbe8a3c2eb37f2d82cf55b2e965426fb5a51e82487a35976df8fdb70b42ec9d53101cbf33ac9a6ca811a1a87e2296f8
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/x-textencoder@npm:7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/x-textencoder@npm:7.0.2"
|
||||
"@polkadot/x-textencoder@npm:7.0.3":
|
||||
version: 7.0.3
|
||||
resolution: "@polkadot/x-textencoder@npm:7.0.3"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/x-global": 7.0.2
|
||||
checksum: 990ed08a001112a33d7ecbe1c6b442afacb3e09a04b10c62574876e2a2d26d0ee0da31f41a3731ffa91b19799c3828a8f09e0ee883768f608fd499b724774d6e
|
||||
"@babel/runtime": ^7.14.8
|
||||
"@polkadot/x-global": 7.0.3
|
||||
checksum: 090a3894fc9c8921f73f0bfc86da0f298af503bf986694e7fde2524dab3562b627136685a33498b02f5a6e8c0ae5d8f8ec3b551db49b3e218ce0ef72cad35996
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@polkadot/x-ws@npm:^7.0.2":
|
||||
version: 7.0.2
|
||||
resolution: "@polkadot/x-ws@npm:7.0.2"
|
||||
"@polkadot/x-ws@npm:^7.0.3":
|
||||
version: 7.0.3
|
||||
resolution: "@polkadot/x-ws@npm:7.0.3"
|
||||
dependencies:
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@polkadot/x-global": 7.0.2
|
||||
"@babel/runtime": ^7.14.8
|
||||
"@polkadot/x-global": 7.0.3
|
||||
"@types/websocket": ^1.0.3
|
||||
websocket: ^1.0.34
|
||||
checksum: 7b62fbd7254596aa60d541eb40d973e0ba7d962906596864742698b7bf9c8ad57153db61e213d647b9fad40f59ed01ceb0dbee7bef41970989b16990f0541ea2
|
||||
checksum: cf40adce17f014f91c49d1b25760dbe2ba7ac1a99fb7c62ed1416d5ccf85fd74b96043859a5c425b67982f9ab01abaf43b3116efaa157a7eb6fb66e4c1beef4f
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -2510,13 +2510,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/jest@npm:^26.0.23":
|
||||
version: 26.0.23
|
||||
resolution: "@types/jest@npm:26.0.23"
|
||||
"@types/jest@npm:^26.0.24":
|
||||
version: 26.0.24
|
||||
resolution: "@types/jest@npm:26.0.24"
|
||||
dependencies:
|
||||
jest-diff: ^26.0.0
|
||||
pretty-format: ^26.0.0
|
||||
checksum: 69db26061e6be34de2a440c8a470b651c53ba6ee0057614a278c4f756ff00281f46cc075b24e5bd761f399f175f49d0a5758b50dd921342a8592461548dea29a
|
||||
checksum: ae39675412f08d884926254e9b12bfd2b5a4e4d204c94d3148cb942174a474930d0c60540133c968f22241d4712b7940c96cbc883096eb326a4d5b206fb78bd0
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -2543,13 +2543,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@types/node-fetch@npm:^2.5.11":
|
||||
version: 2.5.11
|
||||
resolution: "@types/node-fetch@npm:2.5.11"
|
||||
"@types/node-fetch@npm:^2.5.12":
|
||||
version: 2.5.12
|
||||
resolution: "@types/node-fetch@npm:2.5.12"
|
||||
dependencies:
|
||||
"@types/node": "*"
|
||||
form-data: ^3.0.0
|
||||
checksum: a52ee9a205ce3130404a1c8eb0a163aa013fb94c5c93150735dda55bd4d21a556713834b11f6f031721ad7c82d9d7f77d45436010cefc11e851f518dfeeaca3e
|
||||
checksum: ad63c85ba6a9477b8e057ec8682257738130d98e8ece4e31141789bd99df9d9147985cc8bc0cb5c8983ed5aa6bb95d46df23d1e055f4ad5cf8b82fc69cf626c7
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@@ -9602,13 +9602,13 @@ resolve@^2.0.0-next.3:
|
||||
version: 0.0.0-use.local
|
||||
resolution: "root-workspace-0b6124@workspace:."
|
||||
dependencies:
|
||||
"@babel/core": ^7.14.6
|
||||
"@babel/core": ^7.14.8
|
||||
"@babel/register": ^7.14.5
|
||||
"@babel/runtime": ^7.14.6
|
||||
"@babel/runtime": ^7.14.8
|
||||
"@polkadot/dev": ^0.62.57
|
||||
"@polkadot/ts": ^0.4.4
|
||||
"@polkadot/typegen": "workspace:packages/typegen"
|
||||
"@types/jest": ^26.0.23
|
||||
"@types/jest": ^26.0.24
|
||||
copyfiles: ^2.4.1
|
||||
languageName: unknown
|
||||
linkType: soft
|
||||
|
||||
Reference in New Issue
Block a user