Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbb427be5c | ||
|
|
9a18016701 | ||
|
|
bcda5caa39 | ||
|
|
b88cad4b87 | ||
|
|
c86807c0b8 | ||
|
|
771f3bc6fd | ||
|
|
58a18e1da5 | ||
|
|
b42669f864 | ||
|
|
0d2e938674 | ||
|
|
98b3b10bd9 | ||
|
|
34a1e0cbe2 | ||
|
|
44512c1d5f | ||
|
|
0440ce606a | ||
|
|
c05cb79005 | ||
|
|
ce39264b77 | ||
|
|
7c5f82404f | ||
|
|
7da9c5c20b | ||
|
|
ccd3b62632 | ||
|
|
fdf6ec9530 | ||
|
|
51b583d9ea | ||
|
|
6149b6ca76 | ||
|
|
083e0478c3 | ||
|
|
ee584f62a7 | ||
|
|
530909d773 | ||
|
|
d0c55a31b8 | ||
|
|
eafd4923fe | ||
|
|
264bcaf4ac | ||
|
|
a25c057ae7 | ||
|
|
29927129a1 | ||
|
|
4385320554 | ||
|
|
58eadc4e0f | ||
|
|
89e4cba131 |
+20
-1
@@ -1,10 +1,29 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 8.9.1 Jun 19, 2022
|
||||
|
||||
Contributed:
|
||||
|
||||
- Update `@substrate/connect` to latest (Thanks to https://github.com/tomaka)
|
||||
|
||||
Changes:
|
||||
|
||||
- Deupe all internal type property getters
|
||||
- Adjust `@polkadot/types-codec` asserts
|
||||
- Rename `Base` type to `AbstractBase` (reflecting usage)
|
||||
- Alias `blockHash` on `rpc.engine.createBlock` return
|
||||
- Instantiate `Compact/UInt/Int` with `number` when passed
|
||||
- Adjust name extraction in `PortableRegistry` (maintainability)
|
||||
- Adjust string type path extraction (maintainability)
|
||||
- Add Kusama 9230 upgrade block
|
||||
- Update to latest Substrate metadata
|
||||
|
||||
|
||||
## 8.8.2 Jun 14, 2022
|
||||
|
||||
Changes:
|
||||
|
||||
- Aling historic `DispatchErrorModule` with `U8` variant
|
||||
- Align historic `DispatchErrorModule` with `U8` variant
|
||||
- Extend lookup type name generation when conflicts arrise
|
||||
- Update to latest Substrate metadata
|
||||
|
||||
|
||||
+2
-1
@@ -1,4 +1,4 @@
|
||||
3023 Jaco 8.8.2 (#4937)
|
||||
3038 Jaco 8.9.1 (#4957)
|
||||
83 Amaury Martiny StatementKind: Regular and Saft (#2303)
|
||||
37 Keith Ingram Update contract types and rpc (#4541)
|
||||
35 Stefanie Doll Updated child storage parameters (#1709)
|
||||
@@ -86,6 +86,7 @@
|
||||
1 Oleksandr Mykhailenko Add more complex namespaced contracts & test cases for them (#4472)
|
||||
1 Paul M Fox Basic BTreeMaps codec support (#1474)
|
||||
1 philipstanislaus Update types for centrifuge chain v1.2.0 (#2424)
|
||||
1 Pierre Krieger Update substrate/connect to 0.7.6 (#4940)
|
||||
1 qiuhao update DeriveCustom type (#2581)
|
||||
1 r0t0r-r0t0r Fix memory leak on raw rpc call (#4505)
|
||||
1 Raphael Flechtner fix: typegen disconnect ws on success (#4901)
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "commonjs",
|
||||
"version": "8.8.2",
|
||||
"version": "8.9.1",
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
@@ -34,7 +34,7 @@
|
||||
"@babel/core": "^7.18.5",
|
||||
"@babel/register": "^7.17.7",
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@polkadot/dev": "^0.67.3",
|
||||
"@polkadot/dev": "^0.67.4",
|
||||
"@polkadot/typegen": "workspace:packages/typegen",
|
||||
"@types/jest": "^28.1.1",
|
||||
"copyfiles": "^2.4.1"
|
||||
|
||||
@@ -20,18 +20,18 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.8.2",
|
||||
"version": "8.9.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@polkadot/api-base": "8.8.2",
|
||||
"@polkadot/rpc-augment": "8.8.2",
|
||||
"@polkadot/types": "8.8.2",
|
||||
"@polkadot/types-augment": "8.8.2",
|
||||
"@polkadot/types-codec": "8.8.2",
|
||||
"@polkadot/util": "^9.4.1"
|
||||
"@polkadot/api-base": "8.9.1",
|
||||
"@polkadot/rpc-augment": "8.9.1",
|
||||
"@polkadot/types": "8.9.1",
|
||||
"@polkadot/types-augment": "8.9.1",
|
||||
"@polkadot/types-codec": "8.9.1",
|
||||
"@polkadot/util": "^9.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/types-support": "8.8.2"
|
||||
"@polkadot/types-support": "8.9.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/api-augment', path: 'auto', type: 'auto', version: '8.8.2' };
|
||||
export const packageInfo = { name: '@polkadot/api-augment', path: 'auto', type: 'auto', version: '8.9.1' };
|
||||
|
||||
@@ -1333,6 +1333,17 @@ declare module '@polkadot/api-base/types/events' {
|
||||
**/
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
};
|
||||
transactionPayment: {
|
||||
/**
|
||||
* A transaction fee `actual_fee`, of which `tip` was added to the minimum inclusion fee,
|
||||
* has been paid by `who`.
|
||||
**/
|
||||
TransactionFeePaid: AugmentedEvent<ApiType, [who: AccountId32, actualFee: u128, tip: u128], { who: AccountId32, actualFee: u128, tip: u128 }>;
|
||||
/**
|
||||
* Generic event
|
||||
**/
|
||||
[key: string]: AugmentedEvent<ApiType>;
|
||||
};
|
||||
transactionStorage: {
|
||||
/**
|
||||
* Storage proof was successfully checked.
|
||||
|
||||
@@ -1701,14 +1701,6 @@ declare module '@polkadot/api-base/types/storage' {
|
||||
* Storage fee per transaction.
|
||||
**/
|
||||
entryFee: AugmentedQuery<ApiType, () => Observable<Option<u128>>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* Maximum number of indexed transactions in the block.
|
||||
**/
|
||||
maxBlockTransactions: AugmentedQuery<ApiType, () => Observable<u32>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* Maximum data set in a single transaction in bytes.
|
||||
**/
|
||||
maxTransactionSize: AugmentedQuery<ApiType, () => Observable<u32>, []> & QueryableStorageEntry<ApiType, []>;
|
||||
/**
|
||||
* Was the proof checked in this block?
|
||||
**/
|
||||
|
||||
@@ -20,13 +20,13 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.8.2",
|
||||
"version": "8.9.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@polkadot/rpc-core": "8.8.2",
|
||||
"@polkadot/types": "8.8.2",
|
||||
"@polkadot/util": "^9.4.1",
|
||||
"@polkadot/rpc-core": "8.9.1",
|
||||
"@polkadot/types": "8.9.1",
|
||||
"@polkadot/util": "^9.5.1",
|
||||
"rxjs": "^7.5.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/api-base', path: 'auto', type: 'auto', version: '8.8.2' };
|
||||
export const packageInfo = { name: '@polkadot/api-base', path: 'auto', type: 'auto', version: '8.9.1' };
|
||||
|
||||
@@ -20,20 +20,20 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.8.2",
|
||||
"version": "8.9.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@polkadot/api": "8.8.2",
|
||||
"@polkadot/types": "8.8.2",
|
||||
"@polkadot/types-codec": "8.8.2",
|
||||
"@polkadot/types-create": "8.8.2",
|
||||
"@polkadot/util": "^9.4.1",
|
||||
"@polkadot/util-crypto": "^9.4.1",
|
||||
"@polkadot/api": "8.9.1",
|
||||
"@polkadot/types": "8.9.1",
|
||||
"@polkadot/types-codec": "8.9.1",
|
||||
"@polkadot/types-create": "8.9.1",
|
||||
"@polkadot/util": "^9.5.1",
|
||||
"@polkadot/util-crypto": "^9.5.1",
|
||||
"rxjs": "^7.5.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/api-augment": "8.8.2",
|
||||
"@polkadot/keyring": "^9.4.1"
|
||||
"@polkadot/api-augment": "8.9.1",
|
||||
"@polkadot/keyring": "^9.5.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/api-contract', path: 'auto', type: 'auto', version: '8.8.2' };
|
||||
export const packageInfo = { name: '@polkadot/api-contract', path: 'auto', type: 'auto', version: '8.9.1' };
|
||||
|
||||
@@ -160,6 +160,7 @@
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 10,
|
||||
"lookupName": "InkStorageCollectionsStashEntry",
|
||||
"type": "{\"_enum\":{\"Vacant\":\"InkStorageCollectionsStashVacantEntry\",\"Occupied\":\"(AccountId,AccountId)\"}}",
|
||||
"docs": [],
|
||||
"namespace": "ink_storage::collections::stash::Entry",
|
||||
|
||||
@@ -180,6 +180,7 @@
|
||||
{
|
||||
"info": "Struct",
|
||||
"lookupIndex": 10,
|
||||
"lookupName": "InkStorageCollectionsHashmapValueEntryEntry",
|
||||
"type": "{\"value\":\"u32\",\"keyIndex\":\"u32\"}",
|
||||
"docs": [],
|
||||
"namespace": "ink_storage::collections::hashmap::ValueEntry",
|
||||
@@ -205,6 +206,7 @@
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 11,
|
||||
"lookupName": "InkStorageCollectionsStashEntry",
|
||||
"type": "{\"_enum\":{\"Vacant\":\"InkStorageCollectionsStashVacantEntry\",\"Occupied\":\"(AccountId,AccountId)\"}}",
|
||||
"docs": [],
|
||||
"namespace": "ink_storage::collections::stash::Entry",
|
||||
@@ -275,6 +277,7 @@
|
||||
{
|
||||
"info": "Struct",
|
||||
"lookupIndex": 13,
|
||||
"lookupName": "InkStorageCollectionsHashmapValueEntryOption",
|
||||
"type": "{\"value\":\"bool\",\"keyIndex\":\"u32\"}",
|
||||
"docs": [],
|
||||
"namespace": "ink_storage::collections::hashmap::ValueEntry",
|
||||
|
||||
@@ -226,6 +226,7 @@
|
||||
{
|
||||
"info": "Struct",
|
||||
"lookupIndex": 12,
|
||||
"lookupName": "InkStorageCollectionsHashmapValueEntry",
|
||||
"type": "{\"value\":\"u32\",\"keyIndex\":\"u32\"}",
|
||||
"docs": [],
|
||||
"namespace": "ink_storage::collections::hashmap::ValueEntry",
|
||||
@@ -251,7 +252,7 @@
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 13,
|
||||
"type": "{\"_enum\":{\"Vacant\":\"InkStorageCollectionsStashVacantEntry\",\"Occupied\":\"MultisigPlainMultisigPlainTransaction\"}}",
|
||||
"type": "{\"_enum\":{\"Vacant\":\"InkStorageCollectionsStashVacantEntry\",\"Occupied\":\"MultisigPlainTransaction\"}}",
|
||||
"docs": [],
|
||||
"namespace": "ink_storage::collections::stash::Entry",
|
||||
"sub": [
|
||||
@@ -268,7 +269,7 @@
|
||||
"docs": [],
|
||||
"info": "Si",
|
||||
"lookupIndex": 14,
|
||||
"lookupName": "MultisigPlainMultisigPlainTransaction",
|
||||
"lookupName": "MultisigPlainTransaction",
|
||||
"type": "Lookup14",
|
||||
"index": 1,
|
||||
"name": "Occupied"
|
||||
@@ -278,7 +279,7 @@
|
||||
{
|
||||
"info": "Struct",
|
||||
"lookupIndex": 14,
|
||||
"lookupName": "MultisigPlainMultisigPlainTransaction",
|
||||
"lookupName": "MultisigPlainTransaction",
|
||||
"type": "{\"callee\":\"AccountId\",\"selector\":\"[u8;4]\",\"input\":\"Bytes\",\"transferredValue\":\"u128\",\"gasLimit\":\"u64\"}",
|
||||
"docs": [],
|
||||
"namespace": "multisig_plain::multisig_plain::Transaction",
|
||||
@@ -373,6 +374,7 @@
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 19,
|
||||
"lookupName": "InkStorageCollectionsStashEntry",
|
||||
"type": "{\"_enum\":{\"Vacant\":\"InkStorageCollectionsStashVacantEntry\",\"Occupied\":\"AccountId\"}}",
|
||||
"docs": [],
|
||||
"namespace": "ink_storage::collections::stash::Entry",
|
||||
@@ -416,7 +418,7 @@
|
||||
{
|
||||
"info": "Tuple",
|
||||
"lookupIndex": 21,
|
||||
"type": "(u32,MultisigPlainMultisigPlainConfirmationStatus)",
|
||||
"type": "(u32,MultisigPlainConfirmationStatus)",
|
||||
"docs": [],
|
||||
"namespace": "",
|
||||
"sub": [
|
||||
@@ -431,7 +433,7 @@
|
||||
"docs": [],
|
||||
"info": "Si",
|
||||
"lookupIndex": 22,
|
||||
"lookupName": "MultisigPlainMultisigPlainConfirmationStatus",
|
||||
"lookupName": "MultisigPlainConfirmationStatus",
|
||||
"type": "Lookup22"
|
||||
}
|
||||
]
|
||||
@@ -439,7 +441,7 @@
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 22,
|
||||
"lookupName": "MultisigPlainMultisigPlainConfirmationStatus",
|
||||
"lookupName": "MultisigPlainConfirmationStatus",
|
||||
"type": "{\"_enum\":{\"Confirmed\":\"Null\",\"ConfirmationsNeeded\":\"u32\"}}",
|
||||
"docs": [],
|
||||
"namespace": "multisig_plain::multisig_plain::ConfirmationStatus",
|
||||
|
||||
@@ -310,6 +310,7 @@
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 15,
|
||||
"lookupName": "InkStorageCollectionsStashEntry",
|
||||
"type": "{\"_enum\":{\"Vacant\":\"InkStorageCollectionsStashVacantEntry\",\"Occupied\":\"(u32,AccountId)\"}}",
|
||||
"docs": [],
|
||||
"namespace": "ink_storage::collections::stash::Entry",
|
||||
@@ -380,6 +381,7 @@
|
||||
{
|
||||
"info": "Struct",
|
||||
"lookupIndex": 17,
|
||||
"lookupName": "InkStorageCollectionsHashmapValueEntry",
|
||||
"type": "{\"value\":\"Null\",\"keyIndex\":\"u32\"}",
|
||||
"docs": [],
|
||||
"namespace": "ink_storage::collections::hashmap::ValueEntry",
|
||||
|
||||
@@ -83,6 +83,7 @@
|
||||
{
|
||||
"info": "Struct",
|
||||
"lookupIndex": 6,
|
||||
"lookupName": "InkStorageLazyMapping",
|
||||
"type": "{\"offsetKey\":\"InkPrimitivesKey\"}",
|
||||
"docs": [],
|
||||
"namespace": "ink_storage::lazy::mapping::Mapping",
|
||||
|
||||
@@ -83,6 +83,7 @@
|
||||
{
|
||||
"info": "Struct",
|
||||
"lookupIndex": 6,
|
||||
"lookupName": "InkStorageLazyMapping",
|
||||
"type": "{\"offsetKey\":\"InkPrimitivesKey\"}",
|
||||
"docs": [],
|
||||
"namespace": "ink_storage::lazy::mapping::Mapping",
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 4,
|
||||
"lookupName": "EnumExampleEnumExampleVariant",
|
||||
"type": "{\"_enum\":{\"None\":\"Null\",\"Weekday\":\"EnumExampleEnumExampleWeekday\",\"TupleMaybeSigned\":\"EnumExampleEnumExampleTupleMaybeSigned\",\"NamedMaybeSigned\":\"EnumExampleEnumExampleNamedMaybeSigned\",\"Color\":\"EnumExampleEnumExampleColor\"}}",
|
||||
"lookupName": "EnumExampleVariant",
|
||||
"type": "{\"_enum\":{\"None\":\"Null\",\"Weekday\":\"EnumExampleWeekday\",\"TupleMaybeSigned\":\"EnumExampleTupleMaybeSigned\",\"NamedMaybeSigned\":\"EnumExampleNamedMaybeSigned\",\"Color\":\"EnumExampleColor\"}}",
|
||||
"docs": [],
|
||||
"namespace": "enum_example::enum_example::Variant",
|
||||
"sub": [
|
||||
@@ -38,7 +38,7 @@
|
||||
"docs": [],
|
||||
"info": "Si",
|
||||
"lookupIndex": 5,
|
||||
"lookupName": "EnumExampleEnumExampleWeekday",
|
||||
"lookupName": "EnumExampleWeekday",
|
||||
"type": "Lookup5",
|
||||
"index": 1,
|
||||
"name": "Weekday"
|
||||
@@ -47,7 +47,7 @@
|
||||
"docs": [],
|
||||
"info": "Si",
|
||||
"lookupIndex": 6,
|
||||
"lookupName": "EnumExampleEnumExampleTupleMaybeSigned",
|
||||
"lookupName": "EnumExampleTupleMaybeSigned",
|
||||
"type": "Lookup6",
|
||||
"index": 2,
|
||||
"name": "TupleMaybeSigned"
|
||||
@@ -56,7 +56,7 @@
|
||||
"docs": [],
|
||||
"info": "Si",
|
||||
"lookupIndex": 7,
|
||||
"lookupName": "EnumExampleEnumExampleNamedMaybeSigned",
|
||||
"lookupName": "EnumExampleNamedMaybeSigned",
|
||||
"type": "Lookup7",
|
||||
"index": 3,
|
||||
"name": "NamedMaybeSigned"
|
||||
@@ -65,7 +65,7 @@
|
||||
"docs": [],
|
||||
"info": "Si",
|
||||
"lookupIndex": 8,
|
||||
"lookupName": "EnumExampleEnumExampleColor",
|
||||
"lookupName": "EnumExampleColor",
|
||||
"type": "Lookup8",
|
||||
"index": 4,
|
||||
"name": "Color"
|
||||
@@ -75,7 +75,7 @@
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 5,
|
||||
"lookupName": "EnumExampleEnumExampleWeekday",
|
||||
"lookupName": "EnumExampleWeekday",
|
||||
"type": "{\"_enum\":[\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\",\"Sunday\"]}",
|
||||
"docs": [],
|
||||
"namespace": "enum_example::enum_example::Weekday",
|
||||
@@ -127,7 +127,7 @@
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 6,
|
||||
"lookupName": "EnumExampleEnumExampleTupleMaybeSigned",
|
||||
"lookupName": "EnumExampleTupleMaybeSigned",
|
||||
"type": "{\"_enum\":{\"Signed\":\"i32\",\"Unsigned\":\"u32\"}}",
|
||||
"docs": [],
|
||||
"namespace": "enum_example::enum_example::TupleMaybeSigned",
|
||||
@@ -155,7 +155,7 @@
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 7,
|
||||
"lookupName": "EnumExampleEnumExampleNamedMaybeSigned",
|
||||
"lookupName": "EnumExampleNamedMaybeSigned",
|
||||
"type": "{\"_enum\":{\"Signed\":\"{\\\"value\\\":\\\"i32\\\"}\",\"Unsigned\":\"{\\\"value\\\":\\\"u32\\\"}\"}}",
|
||||
"docs": [],
|
||||
"namespace": "enum_example::enum_example::NamedMaybeSigned",
|
||||
@@ -197,7 +197,7 @@
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 8,
|
||||
"lookupName": "EnumExampleEnumExampleColor",
|
||||
"lookupName": "EnumExampleColor",
|
||||
"type": "{\"_enum\":{\"Red\":\"Null\",\"Blue\":\"Null\",\"Green\":\"Null\",\"Yellow\":\"Null\",\"Rgb\":\"{\\\"r\\\":\\\"u8\\\",\\\"g\\\":\\\"u8\\\",\\\"b\\\":\\\"u8\\\"}\",\"Rgba\":\"{\\\"r\\\":\\\"u8\\\",\\\"g\\\":\\\"u8\\\",\\\"b\\\":\\\"u8\\\",\\\"a\\\":\\\"u8\\\"}\"}}",
|
||||
"docs": [],
|
||||
"namespace": "enum_example::enum_example::Color",
|
||||
|
||||
@@ -160,6 +160,7 @@
|
||||
{
|
||||
"info": "Enum",
|
||||
"lookupIndex": 10,
|
||||
"lookupName": "InkStorageCollectionsStashEntry",
|
||||
"type": "{\"_enum\":{\"Vacant\":\"InkStorageCollectionsStashVacantEntry\",\"Occupied\":\"(AccountId,AccountId)\"}}",
|
||||
"docs": [],
|
||||
"namespace": "ink_storage::collections::stash::Entry",
|
||||
|
||||
@@ -20,25 +20,25 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.8.2",
|
||||
"version": "8.9.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@polkadot/api": "8.8.2",
|
||||
"@polkadot/api-augment": "8.8.2",
|
||||
"@polkadot/api-base": "8.8.2",
|
||||
"@polkadot/rpc-core": "8.8.2",
|
||||
"@polkadot/types": "8.8.2",
|
||||
"@polkadot/types-codec": "8.8.2",
|
||||
"@polkadot/util": "^9.4.1",
|
||||
"@polkadot/util-crypto": "^9.4.1",
|
||||
"@polkadot/api": "8.9.1",
|
||||
"@polkadot/api-augment": "8.9.1",
|
||||
"@polkadot/api-base": "8.9.1",
|
||||
"@polkadot/rpc-core": "8.9.1",
|
||||
"@polkadot/types": "8.9.1",
|
||||
"@polkadot/types-codec": "8.9.1",
|
||||
"@polkadot/util": "^9.5.1",
|
||||
"@polkadot/util-crypto": "^9.5.1",
|
||||
"rxjs": "^7.5.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/api": "8.8.2",
|
||||
"@polkadot/api-augment": "8.8.2",
|
||||
"@polkadot/rpc-augment": "8.8.2",
|
||||
"@polkadot/rpc-provider": "8.8.2",
|
||||
"@polkadot/types-support": "8.8.2"
|
||||
"@polkadot/api": "8.9.1",
|
||||
"@polkadot/api-augment": "8.9.1",
|
||||
"@polkadot/rpc-augment": "8.9.1",
|
||||
"@polkadot/rpc-provider": "8.9.1",
|
||||
"@polkadot/types-support": "8.9.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import type { DeriveApi, DeriveDispatch, DeriveProposalImage } from '../types';
|
||||
|
||||
import { catchError, combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
import { Enum } from '@polkadot/types';
|
||||
import { isFunction, stringToHex } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util';
|
||||
@@ -24,7 +25,7 @@ interface SchedulerInfo {
|
||||
|
||||
function isMaybeHashed (call: FrameSupportScheduleMaybeHashed | Call): call is FrameSupportScheduleMaybeHashed {
|
||||
// check for enum
|
||||
return (call as FrameSupportScheduleMaybeHashed).isBasic === false;
|
||||
return call instanceof Enum;
|
||||
}
|
||||
|
||||
function queryQueue (api: DeriveApi): Observable<DeriveDispatch[]> {
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/api-derive', path: 'auto', type: 'auto', version: '8.8.2' };
|
||||
export const packageInfo = { name: '@polkadot/api-derive', path: 'auto', type: 'auto', version: '8.9.1' };
|
||||
|
||||
+17
-17
@@ -20,29 +20,29 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.8.2",
|
||||
"version": "8.9.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@polkadot/api-augment": "8.8.2",
|
||||
"@polkadot/api-base": "8.8.2",
|
||||
"@polkadot/api-derive": "8.8.2",
|
||||
"@polkadot/keyring": "^9.4.1",
|
||||
"@polkadot/rpc-augment": "8.8.2",
|
||||
"@polkadot/rpc-core": "8.8.2",
|
||||
"@polkadot/rpc-provider": "8.8.2",
|
||||
"@polkadot/types": "8.8.2",
|
||||
"@polkadot/types-augment": "8.8.2",
|
||||
"@polkadot/types-codec": "8.8.2",
|
||||
"@polkadot/types-create": "8.8.2",
|
||||
"@polkadot/types-known": "8.8.2",
|
||||
"@polkadot/util": "^9.4.1",
|
||||
"@polkadot/util-crypto": "^9.4.1",
|
||||
"@polkadot/api-augment": "8.9.1",
|
||||
"@polkadot/api-base": "8.9.1",
|
||||
"@polkadot/api-derive": "8.9.1",
|
||||
"@polkadot/keyring": "^9.5.1",
|
||||
"@polkadot/rpc-augment": "8.9.1",
|
||||
"@polkadot/rpc-core": "8.9.1",
|
||||
"@polkadot/rpc-provider": "8.9.1",
|
||||
"@polkadot/types": "8.9.1",
|
||||
"@polkadot/types-augment": "8.9.1",
|
||||
"@polkadot/types-codec": "8.9.1",
|
||||
"@polkadot/types-create": "8.9.1",
|
||||
"@polkadot/types-known": "8.9.1",
|
||||
"@polkadot/util": "^9.5.1",
|
||||
"@polkadot/util-crypto": "^9.5.1",
|
||||
"eventemitter3": "^4.0.7",
|
||||
"rxjs": "^7.5.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/api-augment": "8.8.2",
|
||||
"@polkadot/types-support": "8.8.2"
|
||||
"@polkadot/api-augment": "8.9.1",
|
||||
"@polkadot/types-support": "8.9.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/api', path: 'auto', type: 'auto', version: '8.8.2' };
|
||||
export const packageInfo = { name: '@polkadot/api', path: 'auto', type: 'auto', version: '8.9.1' };
|
||||
|
||||
@@ -20,13 +20,13 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.8.2",
|
||||
"version": "8.9.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@polkadot/rpc-core": "8.8.2",
|
||||
"@polkadot/types": "8.8.2",
|
||||
"@polkadot/types-codec": "8.8.2",
|
||||
"@polkadot/util": "^9.4.1"
|
||||
"@polkadot/rpc-core": "8.9.1",
|
||||
"@polkadot/types": "8.9.1",
|
||||
"@polkadot/types-codec": "8.9.1",
|
||||
"@polkadot/util": "^9.5.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/rpc-augment', path: 'auto', type: 'auto', version: '8.8.2' };
|
||||
export const packageInfo = { name: '@polkadot/rpc-augment', path: 'auto', type: 'auto', version: '8.9.1' };
|
||||
|
||||
@@ -20,18 +20,18 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.8.2",
|
||||
"version": "8.9.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@polkadot/rpc-augment": "8.8.2",
|
||||
"@polkadot/rpc-provider": "8.8.2",
|
||||
"@polkadot/types": "8.8.2",
|
||||
"@polkadot/util": "^9.4.1",
|
||||
"@polkadot/rpc-augment": "8.9.1",
|
||||
"@polkadot/rpc-provider": "8.9.1",
|
||||
"@polkadot/types": "8.9.1",
|
||||
"@polkadot/util": "^9.5.1",
|
||||
"rxjs": "^7.5.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^9.4.1",
|
||||
"@polkadot/rpc-augment": "8.8.2"
|
||||
"@polkadot/keyring": "^9.5.1",
|
||||
"@polkadot/rpc-augment": "8.9.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/rpc-core', path: 'auto', type: 'auto', version: '8.8.2' };
|
||||
export const packageInfo = { name: '@polkadot/rpc-core', path: 'auto', type: 'auto', version: '8.9.1' };
|
||||
|
||||
@@ -20,19 +20,19 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.8.2",
|
||||
"version": "8.9.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@polkadot/keyring": "^9.4.1",
|
||||
"@polkadot/types": "8.8.2",
|
||||
"@polkadot/types-support": "8.8.2",
|
||||
"@polkadot/util": "^9.4.1",
|
||||
"@polkadot/util-crypto": "^9.4.1",
|
||||
"@polkadot/x-fetch": "^9.4.1",
|
||||
"@polkadot/x-global": "^9.4.1",
|
||||
"@polkadot/x-ws": "^9.4.1",
|
||||
"@substrate/connect": "0.7.5",
|
||||
"@polkadot/keyring": "^9.5.1",
|
||||
"@polkadot/types": "8.9.1",
|
||||
"@polkadot/types-support": "8.9.1",
|
||||
"@polkadot/util": "^9.5.1",
|
||||
"@polkadot/util-crypto": "^9.5.1",
|
||||
"@polkadot/x-fetch": "^9.5.1",
|
||||
"@polkadot/x-global": "^9.5.1",
|
||||
"@polkadot/x-ws": "^9.5.1",
|
||||
"@substrate/connect": "0.7.6",
|
||||
"eventemitter3": "^4.0.7",
|
||||
"mock-socket": "^9.1.5",
|
||||
"nock": "^13.2.6"
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/rpc-provider', path: 'auto', type: 'auto', version: '8.8.2' };
|
||||
export const packageInfo = { name: '@polkadot/rpc-provider', path: 'auto', type: 'auto', version: '8.9.1' };
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.8.2",
|
||||
"version": "8.9.1",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
"polkadot-types-chain-info": "./scripts/polkadot-types-chain-info.cjs",
|
||||
@@ -33,17 +33,17 @@
|
||||
"@babel/core": "^7.18.5",
|
||||
"@babel/register": "^7.17.7",
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@polkadot/api": "8.8.2",
|
||||
"@polkadot/api-augment": "8.8.2",
|
||||
"@polkadot/rpc-augment": "8.8.2",
|
||||
"@polkadot/rpc-provider": "8.8.2",
|
||||
"@polkadot/types": "8.8.2",
|
||||
"@polkadot/types-augment": "8.8.2",
|
||||
"@polkadot/types-codec": "8.8.2",
|
||||
"@polkadot/types-create": "8.8.2",
|
||||
"@polkadot/types-support": "8.8.2",
|
||||
"@polkadot/util": "^9.4.1",
|
||||
"@polkadot/x-ws": "^9.4.1",
|
||||
"@polkadot/api": "8.9.1",
|
||||
"@polkadot/api-augment": "8.9.1",
|
||||
"@polkadot/rpc-augment": "8.9.1",
|
||||
"@polkadot/rpc-provider": "8.9.1",
|
||||
"@polkadot/types": "8.9.1",
|
||||
"@polkadot/types-augment": "8.9.1",
|
||||
"@polkadot/types-codec": "8.9.1",
|
||||
"@polkadot/types-create": "8.9.1",
|
||||
"@polkadot/types-support": "8.9.1",
|
||||
"@polkadot/util": "^9.5.1",
|
||||
"@polkadot/x-ws": "^9.5.1",
|
||||
"handlebars": "^4.7.7",
|
||||
"websocket": "^1.0.34",
|
||||
"yargs": "^17.5.1"
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/typegen', path: 'auto', type: 'auto', version: '8.8.2' };
|
||||
export const packageInfo = { name: '@polkadot/typegen', path: 'auto', type: 'auto', version: '8.9.1' };
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
import type { AnyString, Registry } from '@polkadot/types/types';
|
||||
import type { TypeDef } from '@polkadot/types-create/types';
|
||||
|
||||
import Handlebars from 'handlebars';
|
||||
@@ -270,7 +270,7 @@ const formatters: Record<TypeDefInfo, (registry: Registry, typeDef: TypeDef, def
|
||||
*/
|
||||
/** @internal */
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
export function formatType (registry: Registry, definitions: Record<string, ModuleTypes>, type: string | String | TypeDef, imports: TypeImports, withShortcut = false): string {
|
||||
export function formatType (registry: Registry, definitions: Record<string, ModuleTypes>, type: AnyString | TypeDef, imports: TypeImports, withShortcut = false): string {
|
||||
let typeDef: TypeDef;
|
||||
|
||||
if (isString(type)) {
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.8.2",
|
||||
"version": "8.9.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@polkadot/types": "8.8.2",
|
||||
"@polkadot/types-codec": "8.8.2",
|
||||
"@polkadot/util": "^9.4.1"
|
||||
"@polkadot/types": "8.9.1",
|
||||
"@polkadot/types-codec": "8.9.1",
|
||||
"@polkadot/util": "^9.5.1"
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/types-augment', path: 'auto', type: 'auto', version: '8.8.2' };
|
||||
export const packageInfo = { name: '@polkadot/types-augment', path: 'auto', type: 'auto', version: '8.9.1' };
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -20,16 +20,16 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.8.2",
|
||||
"version": "8.9.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@polkadot/util": "^9.4.1"
|
||||
"@polkadot/util": "^9.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/types": "8.8.2",
|
||||
"@polkadot/types-augment": "8.8.2",
|
||||
"@polkadot/types-support": "8.8.2",
|
||||
"@polkadot/util-crypto": "^9.4.1"
|
||||
"@polkadot/types": "8.9.1",
|
||||
"@polkadot/types-augment": "8.9.1",
|
||||
"@polkadot/types-support": "8.9.1",
|
||||
"@polkadot/util-crypto": "^9.5.1"
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -73,14 +73,14 @@ export abstract class AbstractArray<T extends Codec> extends Array<T> implements
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
inspect (): Inspect {
|
||||
public inspect (): Inspect {
|
||||
return {
|
||||
inner: this.inspectInner(),
|
||||
outer: [compactToU8a(this.length)]
|
||||
};
|
||||
}
|
||||
|
||||
inspectInner (): Inspect[] {
|
||||
public inspectInner (): Inspect[] {
|
||||
const inner = new Array<Inspect>(this.length);
|
||||
|
||||
for (let i = 0; i < this.length; i++) {
|
||||
@@ -8,19 +8,19 @@ import type { AnyJson, BareOpts, Codec, Inspect, IU8a, Registry } from '../types
|
||||
* @name Base
|
||||
* @description A type extends the Base class, when it holds a value
|
||||
*/
|
||||
export abstract class Base<T extends Codec> implements Codec {
|
||||
readonly #registry: Registry;
|
||||
|
||||
export abstract class AbstractBase<T extends Codec> implements Codec {
|
||||
public createdAtHash?: IU8a;
|
||||
|
||||
readonly initialU8aLength?: number;
|
||||
public readonly initialU8aLength?: number;
|
||||
|
||||
public readonly registry: Registry;
|
||||
|
||||
readonly #raw: T;
|
||||
|
||||
protected constructor (registry: Registry, value: T, initialU8aLength?: number) {
|
||||
this.#registry = registry;
|
||||
this.#raw = value;
|
||||
this.initialU8aLength = initialU8aLength;
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,10 +48,6 @@ export abstract class Base<T extends Codec> implements Codec {
|
||||
return this.#raw.isEmpty;
|
||||
}
|
||||
|
||||
public get registry (): Registry {
|
||||
return this.#registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
@@ -62,7 +58,7 @@ export abstract class Base<T extends Codec> implements Codec {
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
inspect (): Inspect {
|
||||
public inspect (): Inspect {
|
||||
return this.#raw.inspect();
|
||||
}
|
||||
|
||||
+36
-28
@@ -4,7 +4,7 @@
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { AnyNumber, Inspect, INumber, IU8a, Registry, UIntBitLength } from '../types';
|
||||
|
||||
import { assert, BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_QUINTILL, BN_ZERO, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isBn, isHex, isNumber, isString, isU8a, u8aToBn } from '@polkadot/util';
|
||||
import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_QUINTILL, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isBn, isHex, isNumber, isString, isU8a, u8aToBn, u8aToNumber } from '@polkadot/util';
|
||||
|
||||
export const DEFAULT_UINT_BITS = 64;
|
||||
|
||||
@@ -25,15 +25,25 @@ function toPercentage (value: BN, divisor: BN): string {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function decodeAbstractInt (value: Exclude<AnyNumber, Uint8Array>, isNegative: boolean): string {
|
||||
if (isBn(value)) {
|
||||
return value.toString();
|
||||
} else if (isHex(value, -1, true)) {
|
||||
return hexToBn(value, { isLe: false, isNegative }).toString();
|
||||
} else if (isNumber(value)) {
|
||||
assert(value <= Number.MAX_SAFE_INTEGER && value >= Number.MIN_SAFE_INTEGER && Number.isInteger(value), 'Number needs to be an integer <= Number.MAX_SAFE_INTEGER, i.e. 2 ^ 53 - 1');
|
||||
function decodeAbstractInt (value: Exclude<AnyNumber, Uint8Array>, isNegative: boolean): string | number {
|
||||
if (isNumber(value)) {
|
||||
if (!Number.isInteger(value) || value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER) {
|
||||
throw new Error('Number needs to be an integer <= Number.MAX_SAFE_INTEGER, i.e. 2 ^ 53 - 1');
|
||||
}
|
||||
|
||||
return value;
|
||||
} else if (isString(value)) {
|
||||
assert(!(value.includes('.') || value.includes(',') || value.includes('e')), 'String should not contain decimal points or scientific notation');
|
||||
if (isHex(value, -1, true)) {
|
||||
return hexToBn(value, { isLe: false, isNegative }).toString();
|
||||
}
|
||||
|
||||
if (value.includes('.') || value.includes(',') || value.includes('e')) {
|
||||
throw new Error('String should not contain decimal points or scientific notation');
|
||||
}
|
||||
|
||||
return value;
|
||||
} else if (isBn(value)) {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
return bnToBn(value).toString();
|
||||
@@ -49,33 +59,38 @@ export abstract class AbstractInt extends BN implements INumber {
|
||||
|
||||
public createdAtHash?: IU8a;
|
||||
|
||||
readonly encodedLength: number;
|
||||
public readonly encodedLength: number;
|
||||
|
||||
public readonly isUnsigned: boolean;
|
||||
|
||||
readonly #bitLength: UIntBitLength;
|
||||
|
||||
readonly #isSigned: boolean;
|
||||
|
||||
constructor (registry: Registry, value: AnyNumber = 0, bitLength: UIntBitLength = DEFAULT_UINT_BITS, isSigned = false) {
|
||||
// Construct via a string, which will be passed in the BN constructor.
|
||||
// Construct via a string/number, which will be passed in the BN constructor.
|
||||
// It would be ideal to actually return a BN, but there is an issue:
|
||||
// https://github.com/indutny/bn.js/issues/206
|
||||
super(
|
||||
// shortcut isU8a as used in SCALE decoding
|
||||
isU8a(value)
|
||||
? u8aToBn(value.subarray(0, bitLength / 8), { isLe: true, isNegative: isSigned }).toString()
|
||||
? bitLength <= 48
|
||||
? u8aToNumber(value.subarray(0, bitLength / 8), { isNegative: isSigned })
|
||||
: u8aToBn(value.subarray(0, bitLength / 8), { isLe: true, isNegative: isSigned }).toString()
|
||||
: decodeAbstractInt(value, isSigned)
|
||||
);
|
||||
|
||||
this.registry = registry;
|
||||
this.#bitLength = bitLength;
|
||||
this.encodedLength = this.#bitLength / 8;
|
||||
this.#isSigned = isSigned;
|
||||
this.isUnsigned = !isSigned;
|
||||
|
||||
const isPositive = this.gte(BN_ZERO);
|
||||
const maxBits = bitLength - (isSigned && isPositive ? 1 : 0);
|
||||
const isNegative = this.isNeg();
|
||||
const maxBits = bitLength - (isSigned && !isNegative ? 1 : 0);
|
||||
|
||||
assert(isSigned || isPositive, () => `${this.toRawType()}: Negative number passed to unsigned type`);
|
||||
assert(super.bitLength() <= maxBits, () => `${this.toRawType()}: Input too large. Found input with ${super.bitLength()} bits, expected ${maxBits}`);
|
||||
if (isNegative && !isSigned) {
|
||||
throw new Error(`${this.toRawType()}: Negative number passed to unsigned type`);
|
||||
} else if (super.bitLength() > maxBits) {
|
||||
throw new Error(`${this.toRawType()}: Input too large. Found input with ${super.bitLength()} bits, expected ${maxBits}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,13 +107,6 @@ export abstract class AbstractInt extends BN implements INumber {
|
||||
return this.isZero();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Checks if the value is an unsigned type
|
||||
*/
|
||||
public get isUnsigned (): boolean {
|
||||
return !this.#isSigned;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the number of bits in the value
|
||||
*/
|
||||
@@ -115,7 +123,7 @@ export abstract class AbstractInt extends BN implements INumber {
|
||||
// number and BN inputs (no `.eqn` needed) - numbers will be converted
|
||||
return super.eq(
|
||||
isHex(other)
|
||||
? hexToBn(other.toString(), { isLe: false, isNegative: this.#isSigned })
|
||||
? hexToBn(other.toString(), { isLe: false, isNegative: !this.isUnsigned })
|
||||
: bnToBn(other as string)
|
||||
);
|
||||
}
|
||||
@@ -123,7 +131,7 @@ export abstract class AbstractInt extends BN implements INumber {
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
inspect (): Inspect {
|
||||
public inspect (): Inspect {
|
||||
return {
|
||||
outer: [this.toU8a()]
|
||||
};
|
||||
@@ -1,5 +1,6 @@
|
||||
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { AbstractArray } from './AbstractArray';
|
||||
export { AbstractInt } from './AbstractInt';
|
||||
export { AbstractArray } from './Array';
|
||||
export { AbstractBase } from './Base';
|
||||
export { AbstractInt } from './Int';
|
||||
|
||||
@@ -5,6 +5,10 @@ import { TypeRegistry } from '@polkadot/types';
|
||||
import { CodecDate, Compact, U32 } from '@polkadot/types-codec';
|
||||
import { BN } from '@polkadot/util';
|
||||
|
||||
import { performance } from '../test/performance';
|
||||
|
||||
const CompactU32 = Compact.with(U32);
|
||||
|
||||
describe('Compact', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
@@ -88,4 +92,6 @@ describe('Compact', (): void => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
performance('Compact', 75_000, [[new Uint8Array([63 << 2])]], (v: Uint8Array) => new CompactU32(registry, v));
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { BN } from '@polkadot/util';
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { AnyJson, AnyNumber, CodecClass, ICompact, Inspect, INumber, IU8a, Registry } from '../types';
|
||||
|
||||
import { compactFromU8a, compactToU8a, isU8a } from '@polkadot/util';
|
||||
import { compactFromU8a, compactFromU8aLim, compactToU8a, isU8a } from '@polkadot/util';
|
||||
|
||||
import { typeToConstructor } from '../utils';
|
||||
|
||||
@@ -18,6 +18,26 @@ function noopSetDefinition <T> (d: CodecClass<T>): CodecClass<T> {
|
||||
return d;
|
||||
}
|
||||
|
||||
function decodeCompact<T extends INumber> (registry: Registry, Type: CodecClass<T>, value: Compact<T> | AnyNumber): [T, number] {
|
||||
if (isU8a(value)) {
|
||||
const [decodedLength, bn] = (value[0] & 0b11) < 0b11
|
||||
? compactFromU8aLim(value)
|
||||
: compactFromU8a(value);
|
||||
|
||||
return [new Type(registry, bn), decodedLength];
|
||||
} else if (value instanceof Compact) {
|
||||
const raw = value.unwrap();
|
||||
|
||||
return raw instanceof Type
|
||||
? [raw, 0]
|
||||
: [new Type(registry, raw), 0];
|
||||
} else if (value instanceof Type) {
|
||||
return [value, 0];
|
||||
}
|
||||
|
||||
return [new Type(registry, value), 0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Compact
|
||||
* @description
|
||||
@@ -41,7 +61,7 @@ export class Compact<T extends INumber> implements ICompact<T> {
|
||||
this.registry = registry;
|
||||
this.#Type = definition || setDefinition(typeToConstructor(registry, Type));
|
||||
|
||||
const [raw, decodedLength] = Compact.decodeCompact<T>(registry, this.#Type, value);
|
||||
const [raw, decodedLength] = decodeCompact<T>(registry, this.#Type, value);
|
||||
|
||||
this.initialU8aLength = decodedLength;
|
||||
this.#raw = raw;
|
||||
@@ -61,21 +81,6 @@ export class Compact<T extends INumber> implements ICompact<T> {
|
||||
};
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
public static decodeCompact<T extends INumber> (registry: Registry, Type: CodecClass<T>, value: Compact<T> | AnyNumber): [T, number] {
|
||||
if (isU8a(value)) {
|
||||
const [decodedLength, bn] = compactFromU8a(value);
|
||||
|
||||
return [new Type(registry, bn), decodedLength];
|
||||
} else if (value instanceof Compact) {
|
||||
return [new Type(registry, value.#raw), 0];
|
||||
} else if (value instanceof Type) {
|
||||
return [value, 0];
|
||||
}
|
||||
|
||||
return [new Type(registry, value), 0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The length of the value when encoded as a Uint8Array
|
||||
*/
|
||||
@@ -118,7 +123,7 @@ export class Compact<T extends INumber> implements ICompact<T> {
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
inspect (): Inspect {
|
||||
public inspect (): Inspect {
|
||||
return {
|
||||
outer: [this.toU8a()]
|
||||
};
|
||||
|
||||
@@ -56,7 +56,7 @@ export class DoNotConstruct implements Codec {
|
||||
throw this.#neverError;
|
||||
}
|
||||
|
||||
inspect (): Inspect {
|
||||
public inspect (): Inspect {
|
||||
throw this.#neverError;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,10 @@ import { TypeRegistry } from '@polkadot/types';
|
||||
import { Enum, Null, Text, U32 } from '@polkadot/types-codec';
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { performance } from '../test/performance';
|
||||
|
||||
const PEnum = Enum.with({ a: U32, b: U32 });
|
||||
|
||||
describe('Enum', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
@@ -449,4 +453,6 @@ describe('Enum', (): void => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
performance('Enum', 20_000, [[new Uint8Array([0, 31, 32, 33, 34])]], (v: Uint8Array) => new PEnum(registry, v));
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { AnyJson, Codec, CodecClass, IEnum, Inspect, IU8a, Registry } from '../types';
|
||||
|
||||
import { assert, isCodec, isHex, isNumber, isObject, isString, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, stringPascalCase, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { isHex, isNumber, isObject, isString, isU8a, objectProperties, stringCamelCase, stringify, stringPascalCase, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { mapToTypeMap, typesToMap } from '../utils';
|
||||
import { Null } from './Null';
|
||||
@@ -45,7 +45,9 @@ function isRustEnum (def: Record<string, string | CodecClass> | Record<string, n
|
||||
const defValues = Object.values(def);
|
||||
|
||||
if (defValues.some((v) => isNumber(v))) {
|
||||
assert(defValues.every((v) => isNumber(v) && v >= 0 && v <= 255), 'Invalid number-indexed enum definition');
|
||||
if (!defValues.every((v) => isNumber(v) && v >= 0 && v <= 255)) {
|
||||
throw new Error('Invalid number-indexed enum definition');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -94,16 +96,37 @@ function extractDef (registry: Registry, _def: Record<string, string | CodecClas
|
||||
};
|
||||
}
|
||||
|
||||
function createFromValue (registry: Registry, def: TypesDef, index = 0, value?: unknown): Decoded {
|
||||
const entry = Object.values(def).find((e) => e.index === index);
|
||||
function getEntryType (def: TypesDef, checkIdx: number): CodecClass {
|
||||
const values = Object.values(def);
|
||||
|
||||
assert(!isUndefined(entry), () => `Unable to create Enum via index ${index}, in ${Object.keys(def).join(', ')}`);
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
const { Type, index } = values[i];
|
||||
|
||||
if (index === checkIdx) {
|
||||
return Type;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(`Unable to create Enum via index ${checkIdx}, in ${Object.keys(def).join(', ')}`);
|
||||
}
|
||||
|
||||
function createFromU8a (registry: Registry, def: TypesDef, index: number, value: Uint8Array): Decoded {
|
||||
const Type = getEntryType(def, index);
|
||||
|
||||
return {
|
||||
index,
|
||||
value: isCodec(value) && value instanceof entry.Type
|
||||
value: new Type(registry, value)
|
||||
};
|
||||
}
|
||||
|
||||
function createFromValue (registry: Registry, def: TypesDef, index = 0, value?: unknown): Decoded {
|
||||
const Type = getEntryType(def, index);
|
||||
|
||||
return {
|
||||
index,
|
||||
value: value instanceof Type
|
||||
? value
|
||||
: new entry.Type(registry, value)
|
||||
: new Type(registry, value)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -114,7 +137,9 @@ function decodeFromJSON (registry: Registry, def: TypesDef, key: string, value?:
|
||||
const keyLower = key.toLowerCase();
|
||||
const index = keys.indexOf(keyLower);
|
||||
|
||||
assert(index !== -1, () => `Cannot map Enum JSON, unable to find '${key}' in ${keys.join(', ')}`);
|
||||
if (index === -1) {
|
||||
throw new Error(`Cannot map Enum JSON, unable to find '${key}' in ${keys.join(', ')}`);
|
||||
}
|
||||
|
||||
try {
|
||||
return createFromValue(registry, def, Object.values(def)[index].index, value);
|
||||
@@ -133,7 +158,7 @@ function decodeEnum (registry: Registry, def: TypesDef, value?: unknown, index?:
|
||||
|
||||
// nested, we don't want to match isObject below
|
||||
if (u8a.length) {
|
||||
return createFromValue(registry, def, u8a[0], u8a.subarray(1));
|
||||
return createFromU8a(registry, def, u8a[0], u8a.subarray(1));
|
||||
}
|
||||
} else if (value instanceof Enum) {
|
||||
return createFromValue(registry, def, value.index, value.value);
|
||||
@@ -181,7 +206,7 @@ export class Enum implements IEnum {
|
||||
|
||||
// shortcut isU8a as used in SCALE decoding
|
||||
const decoded = isU8a(value) && value.length && !isNumber(index)
|
||||
? createFromValue(registry, def, value[0], value.subarray(1))
|
||||
? createFromU8a(registry, def, value[0], value.subarray(1))
|
||||
: decodeEnum(registry, def, value, index);
|
||||
|
||||
this.registry = registry;
|
||||
@@ -189,7 +214,7 @@ export class Enum implements IEnum {
|
||||
this.#isBasic = isBasic;
|
||||
this.#isIndexed = isIndexed;
|
||||
this.#indexes = Object.values(def).map(({ index }) => index);
|
||||
this.#entryIndex = this.#indexes.indexOf(decoded.index) || 0;
|
||||
this.#entryIndex = this.#indexes.indexOf(decoded.index);
|
||||
this.#raw = decoded.value;
|
||||
|
||||
if (this.#raw.initialU8aLength) {
|
||||
@@ -205,7 +230,7 @@ export class Enum implements IEnum {
|
||||
const isKeys = new Array<string>(keys.length);
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const name = stringPascalCase(keys[i].replace(' ', '_'));
|
||||
const name = stringPascalCase(keys[i]);
|
||||
|
||||
asKeys[i] = `as${name}`;
|
||||
isKeys[i] = `is${name}`;
|
||||
@@ -223,7 +248,9 @@ export class Enum implements IEnum {
|
||||
|
||||
objectProperties(this, isKeys, (_, i) => this.type === keys[i]);
|
||||
objectProperties(this, asKeys, (k, i): Codec => {
|
||||
assert(this[isKeys[i] as keyof this], () => `Cannot convert '${this.type}' via ${k}`);
|
||||
if (!this[isKeys[i] as keyof this]) {
|
||||
throw new Error(`Cannot convert '${this.type}' via ${k}`);
|
||||
}
|
||||
|
||||
return this.value;
|
||||
});
|
||||
@@ -329,7 +356,7 @@ export class Enum implements IEnum {
|
||||
return this.type === other;
|
||||
} else if (isHex(other)) {
|
||||
return this.toHex() === other;
|
||||
} else if (isCodec(other) && other instanceof Enum) {
|
||||
} else if (other instanceof Enum) {
|
||||
return this.index === other.index && this.value.eq(other.value);
|
||||
} else if (isObject(other)) {
|
||||
return this.value.eq(other[this.type]);
|
||||
@@ -342,8 +369,8 @@ export class Enum implements IEnum {
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
inspect (): Inspect {
|
||||
if (this.isBasic) {
|
||||
public inspect (): Inspect {
|
||||
if (this.#isBasic) {
|
||||
return { outer: [new Uint8Array([this.index])] };
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { AnyNumber, CodecClass, Registry, UIntBitLength } from '../types';
|
||||
|
||||
import { AbstractInt } from '../abstract/AbstractInt';
|
||||
import { AbstractInt } from '../abstract/Int';
|
||||
|
||||
/**
|
||||
* @name Int
|
||||
|
||||
@@ -12,6 +12,10 @@ import { isNull } from '@polkadot/util';
|
||||
* Implements a type that does not contain anything (apart from `null`)
|
||||
*/
|
||||
export class Null implements Codec {
|
||||
public readonly encodedLength = 0;
|
||||
|
||||
public readonly isEmpty = true;
|
||||
|
||||
public readonly registry: Registry;
|
||||
|
||||
public createdAtHash?: IU8a;
|
||||
@@ -23,13 +27,6 @@ export class Null implements Codec {
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The length of the value when encoded as a Uint8Array
|
||||
*/
|
||||
public get encodedLength (): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
@@ -37,13 +34,6 @@ export class Null implements Codec {
|
||||
throw new Error('.hash is not implemented on Null');
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Checks if the value is an empty value (always true)
|
||||
*/
|
||||
public get isEmpty (): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
@@ -54,7 +44,7 @@ export class Null implements Codec {
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
inspect (): Inspect {
|
||||
public inspect (): Inspect {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { AnyJson, Codec, CodecClass, Inspect, IOption, IU8a, Registry } from '../types';
|
||||
|
||||
import { assert, isCodec, isNull, isU8a, isUndefined, u8aToHex } from '@polkadot/util';
|
||||
import { isCodec, isNull, isU8a, isUndefined, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { typeToConstructor } from '../utils';
|
||||
import { Null } from './Null';
|
||||
@@ -70,9 +70,9 @@ export class Option<T extends Codec> implements IOption<T> {
|
||||
|
||||
public createdAtHash?: IU8a;
|
||||
|
||||
readonly #Type: CodecClass<T>;
|
||||
public initialU8aLength?: number;
|
||||
|
||||
readonly #initialU8aLength?: number;
|
||||
readonly #Type: CodecClass<T>;
|
||||
|
||||
readonly #raw: T;
|
||||
|
||||
@@ -89,7 +89,7 @@ export class Option<T extends Codec> implements IOption<T> {
|
||||
this.#raw = decoded as T;
|
||||
|
||||
if (decoded && decoded.initialU8aLength) {
|
||||
this.#initialU8aLength = 1 + decoded.initialU8aLength;
|
||||
this.initialU8aLength = 1 + decoded.initialU8aLength;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,13 +117,6 @@ export class Option<T extends Codec> implements IOption<T> {
|
||||
return 1 + this.#raw.encodedLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
|
||||
*/
|
||||
public get initialU8aLength (): number | undefined {
|
||||
return this.#initialU8aLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
@@ -173,7 +166,7 @@ export class Option<T extends Codec> implements IOption<T> {
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
inspect (): Inspect {
|
||||
public inspect (): Inspect {
|
||||
if (this.isNone) {
|
||||
return { outer: [new Uint8Array([0])] };
|
||||
}
|
||||
@@ -254,7 +247,9 @@ export class Option<T extends Codec> implements IOption<T> {
|
||||
* @description Returns the value that the Option represents (if available), throws if null
|
||||
*/
|
||||
public unwrap (): T {
|
||||
assert(this.isSome, 'Option: unwrapping a None value');
|
||||
if (this.isNone) {
|
||||
throw new Error('Option: unwrapping a None value');
|
||||
}
|
||||
|
||||
return this.#raw;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
import type { Codec, CodecClass, IResult, Registry } from '../types';
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
import { Enum } from './Enum';
|
||||
|
||||
/**
|
||||
@@ -31,7 +29,9 @@ export class Result<O extends Codec, E extends Codec> extends Enum implements IR
|
||||
* @description Returns the wrapper Err value (if isErr)
|
||||
*/
|
||||
public get asErr (): E {
|
||||
assert(this.isErr, 'Cannot extract Err value from Ok result, check isErr first');
|
||||
if (!this.isErr) {
|
||||
throw new Error('Cannot extract Err value from Ok result, check isErr first');
|
||||
}
|
||||
|
||||
return this.value as E;
|
||||
}
|
||||
@@ -47,7 +47,9 @@ export class Result<O extends Codec, E extends Codec> extends Enum implements IR
|
||||
* @description Returns the wrapper Ok value (if isOk)
|
||||
*/
|
||||
public get asOk (): O {
|
||||
assert(this.isOk, 'Cannot extract Ok value from Err result, check isOk first');
|
||||
if (!this.isOk) {
|
||||
throw new Error('Cannot extract Ok value from Err result, check isOk first');
|
||||
}
|
||||
|
||||
return this.value as O;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { AnyTupleValue, Codec, CodecClass, Inspect, ITuple, Registry } from
|
||||
|
||||
import { isFunction, isHex, isString, isU8a, stringify, u8aConcatStrict, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { AbstractArray } from '../abstract/AbstractArray';
|
||||
import { AbstractArray } from '../abstract/Array';
|
||||
import { decodeU8a, mapToTypeMap, typeToConstructor } from '../utils';
|
||||
|
||||
type TupleType = (CodecClass | string);
|
||||
@@ -26,7 +26,7 @@ function noopSetDefinition (d: Definition): Definition {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function decodeTuple (registry: Registry, result: Codec[], Classes: Definition, value?: Exclude<AnyTupleValue, Uint8Array>): [Codec[], number] {
|
||||
function decodeTuple (registry: Registry, result: Codec[], value: Exclude<AnyTupleValue, Uint8Array> | undefined, Classes: Definition): [Codec[], number] {
|
||||
if (isU8a(value) || isHex(value)) {
|
||||
return decodeU8a(registry, result, u8aToU8a(value), Classes);
|
||||
}
|
||||
@@ -70,11 +70,11 @@ export class Tuple extends AbstractArray<Codec> implements ITuple<Codec[]> {
|
||||
|
||||
super(registry, Classes[0].length);
|
||||
|
||||
const [, decodedLength] = isU8a(value)
|
||||
? decodeU8a(registry, this, value, Classes, false)
|
||||
: decodeTuple(registry, this, Classes, value);
|
||||
|
||||
this.initialU8aLength = decodedLength;
|
||||
this.initialU8aLength = (
|
||||
isU8a(value)
|
||||
? decodeU8a(registry, this, value, Classes)
|
||||
: decodeTuple(registry, this, value, Classes)
|
||||
)[1];
|
||||
this.#Types = Classes;
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ export class Tuple extends AbstractArray<Codec> implements ITuple<Codec[]> {
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
override inspect (): Inspect {
|
||||
public override inspect (): Inspect {
|
||||
return {
|
||||
inner: this.inspectInner()
|
||||
};
|
||||
|
||||
@@ -5,6 +5,8 @@ import { TypeRegistry } from '@polkadot/types';
|
||||
import { UInt } from '@polkadot/types-codec';
|
||||
import { BN, BN_TWO, isBn } from '@polkadot/util';
|
||||
|
||||
import { performance } from '../test/performance';
|
||||
|
||||
describe('UInt', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
@@ -180,4 +182,6 @@ describe('UInt', (): void => {
|
||||
expect(registry.createType('Balance', '123456789012345').toHuman()).toEqual('123.4567 Unit');
|
||||
});
|
||||
});
|
||||
|
||||
performance('UInt', 75_000, [[new Uint8Array([31, 32, 33, 34])]], (v: Uint8Array) => new UInt(registry, v));
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { AnyNumber, CodecClass, Registry, UIntBitLength } from '../types';
|
||||
|
||||
import { AbstractInt } from '../abstract/AbstractInt';
|
||||
import { AbstractInt } from '../abstract/Int';
|
||||
|
||||
/**
|
||||
* @name UInt
|
||||
|
||||
@@ -5,12 +5,15 @@ import type { PropIndex } from '@polkadot/types/interfaces/democracy';
|
||||
import type { Codec, CodecTo, ITuple } from '@polkadot/types-codec/types';
|
||||
|
||||
import { createTypeUnsafe, GenericAccountId as AccountId, Metadata, TypeRegistry } from '@polkadot/types';
|
||||
import { Text, Vec } from '@polkadot/types-codec';
|
||||
import { Text, u32, Vec } from '@polkadot/types-codec';
|
||||
import rpcMetadata from '@polkadot/types-support/metadata/static-substrate';
|
||||
import { decodeAddress, randomAsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import { performance } from '../test/performance';
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
const metadata = new Metadata(registry, rpcMetadata);
|
||||
const VecU32 = Vec.with(u32);
|
||||
|
||||
registry.setMetadata(metadata);
|
||||
|
||||
@@ -190,4 +193,6 @@ describe('Vec', (): void => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
performance('Vec<U32>', 40_000, [[new Uint8Array([3 << 2, 11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34])]], (v: Uint8Array) => new VecU32(registry, v));
|
||||
});
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { Codec, CodecClass, Registry } from '../types';
|
||||
|
||||
import { assert, compactFromU8aLim, isU8a, logger, u8aToU8a } from '@polkadot/util';
|
||||
import { compactFromU8aLim, isU8a, logger, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { AbstractArray } from '../abstract/AbstractArray';
|
||||
import { AbstractArray } from '../abstract/Array';
|
||||
import { decodeU8aVec, typeToConstructor } from '../utils';
|
||||
|
||||
const MAX_LENGTH = 64 * 1024;
|
||||
@@ -30,7 +30,9 @@ function decodeVecLength (value: Uint8Array | HexString | unknown[]): [Uint8Arra
|
||||
const u8a = u8aToU8a(value);
|
||||
const [startAt, length] = compactFromU8aLim(u8a);
|
||||
|
||||
assert(length <= MAX_LENGTH, () => `Vec length ${length.toString()} exceeds ${MAX_LENGTH}`);
|
||||
if (length > MAX_LENGTH) {
|
||||
throw new Error(`Vec length ${length.toString()} exceeds ${MAX_LENGTH}`);
|
||||
}
|
||||
|
||||
return [u8a, length, startAt];
|
||||
}
|
||||
@@ -78,11 +80,11 @@ export class Vec<T extends Codec> extends AbstractArray<T> {
|
||||
|
||||
this.#Type = definition || setDefinition(typeToConstructor<T>(registry, Type));
|
||||
|
||||
const [decodedLength] = isU8a(decodeFrom)
|
||||
? decodeU8aVec(registry, this, decodeFrom, startAt, this.#Type)
|
||||
: decodeVec(registry, this, decodeFrom, startAt, this.#Type);
|
||||
|
||||
this.initialU8aLength = decodedLength;
|
||||
this.initialU8aLength = (
|
||||
isU8a(decodeFrom)
|
||||
? decodeU8aVec(registry, this, decodeFrom, startAt, this.#Type)
|
||||
: decodeVec(registry, this, decodeFrom, startAt, this.#Type)
|
||||
)[0];
|
||||
}
|
||||
|
||||
public static with<O extends Codec> (Type: CodecClass<O> | string): CodecClass<Vec<O>> {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { Codec } from '../types';
|
||||
|
||||
import { AbstractArray } from '../abstract/AbstractArray';
|
||||
import { AbstractArray } from '../abstract/Array';
|
||||
|
||||
/**
|
||||
* @name VecAny
|
||||
|
||||
@@ -6,7 +6,7 @@ import type { Codec, CodecClass, Inspect, Registry } from '../types';
|
||||
|
||||
import { isU8a, u8aConcatStrict } from '@polkadot/util';
|
||||
|
||||
import { AbstractArray } from '../abstract/AbstractArray';
|
||||
import { AbstractArray } from '../abstract/Array';
|
||||
import { decodeU8aVec, typeToConstructor } from '../utils';
|
||||
import { decodeVec } from './Vec';
|
||||
|
||||
@@ -34,11 +34,11 @@ export class VecFixed<T extends Codec> extends AbstractArray<T> {
|
||||
|
||||
this.#Type = definition || setDefinition(typeToConstructor<T>(registry, Type));
|
||||
|
||||
const [, decodedLengthNoOffset] = isU8a(value)
|
||||
? decodeU8aVec(registry, this, value, 0, this.#Type)
|
||||
: decodeVec(registry, this, value, 0, this.#Type);
|
||||
|
||||
this.initialU8aLength = decodedLengthNoOffset;
|
||||
this.initialU8aLength = (
|
||||
isU8a(value)
|
||||
? decodeU8aVec(registry, this, value, 0, this.#Type)
|
||||
: decodeVec(registry, this, value, 0, this.#Type)
|
||||
)[1];
|
||||
}
|
||||
|
||||
public static with<O extends Codec> (Type: CodecClass<O> | string, length: number): CodecClass<VecFixed<O>> {
|
||||
@@ -78,7 +78,7 @@ export class VecFixed<T extends Codec> extends AbstractArray<T> {
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
override inspect (): Inspect {
|
||||
public override inspect (): Inspect {
|
||||
return {
|
||||
inner: this.inspectInner()
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { Base } from './Base';
|
||||
export { Compact } from './Compact';
|
||||
export { DoNotConstruct } from './DoNotConstruct';
|
||||
export { Enum } from './Enum';
|
||||
|
||||
@@ -140,7 +140,7 @@ export class BTreeSet<V extends Codec = Codec> extends Set<V> implements ISet<V>
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
inspect (): Inspect {
|
||||
public inspect (): Inspect {
|
||||
const inner = new Array<Inspect>();
|
||||
|
||||
for (const v of this.values()) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { AnyU8a, Inspect, Registry } from '../types';
|
||||
|
||||
import { assert, compactFromU8aLim, compactToU8a, isString, u8aConcatStrict, u8aToU8a } from '@polkadot/util';
|
||||
import { compactFromU8aLim, compactToU8a, isString, u8aConcatStrict, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { Raw } from '../native/Raw';
|
||||
|
||||
@@ -17,7 +17,9 @@ function decodeBitVecU8a (value?: Uint8Array): [number, Uint8Array] {
|
||||
const [offset, length] = compactFromU8aLim(value);
|
||||
const total = offset + Math.ceil(length / 8);
|
||||
|
||||
assert(total <= value.length, () => `BitVec: required length less than remainder, expected at least ${total}, found ${value.length}`);
|
||||
if (total > value.length) {
|
||||
throw new Error(`BitVec: required length less than remainder, expected at least ${total}, found ${value.length}`);
|
||||
}
|
||||
|
||||
return [length, value.subarray(offset, total)];
|
||||
}
|
||||
@@ -65,7 +67,7 @@ export class BitVec extends Raw {
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
override inspect (): Inspect {
|
||||
public override inspect (): Inspect {
|
||||
return {
|
||||
outer: [compactToU8a(this.#decodedLength), super.toU8a()]
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { AnyU8a, Inspect, Registry } from '../types';
|
||||
|
||||
import { assert, compactAddLength, compactFromU8aLim, compactToU8a, isCodec, isString, isU8a, u8aToU8a } from '@polkadot/util';
|
||||
import { compactAddLength, compactFromU8aLim, compactToU8a, isString, isU8a, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { Raw } from '../native/Raw';
|
||||
|
||||
@@ -20,8 +20,11 @@ function decodeBytesU8a (value: Uint8Array): [Uint8Array, number] {
|
||||
const [offset, length] = compactFromU8aLim(value);
|
||||
const total = offset + length;
|
||||
|
||||
assert(length <= MAX_LENGTH, () => `Bytes length ${length.toString()} exceeds ${MAX_LENGTH}`);
|
||||
assert(total <= value.length, () => `Bytes: required length less than remainder, expected at least ${total}, found ${value.length}`);
|
||||
if (length > MAX_LENGTH) {
|
||||
throw new Error(`Bytes length ${length.toString()} exceeds ${MAX_LENGTH}`);
|
||||
} else if (total > value.length) {
|
||||
throw new Error(`Bytes: required length less than remainder, expected at least ${total}, found ${value.length}`);
|
||||
}
|
||||
|
||||
return [value.subarray(offset, total), total];
|
||||
}
|
||||
@@ -35,7 +38,7 @@ function decodeBytesU8a (value: Uint8Array): [Uint8Array, number] {
|
||||
*/
|
||||
export class Bytes extends Raw {
|
||||
constructor (registry: Registry, value?: AnyU8a) {
|
||||
const [u8a, decodedLength] = isU8a(value) && !(isCodec(value) && value instanceof Raw)
|
||||
const [u8a, decodedLength] = isU8a(value) && !(value instanceof Raw)
|
||||
? decodeBytesU8a(value)
|
||||
: Array.isArray(value) || isString(value)
|
||||
? [u8aToU8a(value), 0]
|
||||
@@ -54,7 +57,7 @@ export class Bytes extends Raw {
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
override inspect (isBare?: boolean): Inspect {
|
||||
public override inspect (isBare?: boolean): Inspect {
|
||||
const clength = compactToU8a(this.length);
|
||||
|
||||
return {
|
||||
|
||||
@@ -6,7 +6,7 @@ import type { AnyJson, Codec, CodecClass, IMap, Inspect, IU8a, Registry } from '
|
||||
|
||||
import { compactFromU8aLim, compactToU8a, isHex, isObject, isU8a, logger, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { AbstractArray } from '../abstract/AbstractArray';
|
||||
import { AbstractArray } from '../abstract/Array';
|
||||
import { Enum } from '../base/Enum';
|
||||
import { Struct } from '../native/Struct';
|
||||
import { compareMap, decodeU8a, sortMap, typeToConstructor } from '../utils';
|
||||
@@ -154,7 +154,7 @@ export class CodecMap<K extends Codec = Codec, V extends Codec = Codec> extends
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
inspect (): Inspect {
|
||||
public inspect (): Inspect {
|
||||
const inner = new Array<Inspect>();
|
||||
|
||||
for (const [k, v] of this.entries()) {
|
||||
|
||||
@@ -32,6 +32,8 @@ export class OptionBool extends Option<Bool> {
|
||||
? decodeU8a(registry, u8aToU8a(value))
|
||||
: value
|
||||
);
|
||||
|
||||
this.initialU8aLength = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,13 +43,6 @@ export class OptionBool extends Option<Bool> {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
|
||||
*/
|
||||
public override get initialU8aLength (): number {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Checks if the value is an empty value (always false)
|
||||
*/
|
||||
@@ -69,7 +64,7 @@ export class OptionBool extends Option<Bool> {
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
override inspect (): Inspect {
|
||||
public override inspect (): Inspect {
|
||||
return { outer: [this.toU8a()] };
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { AnyU8a, CodecClass, Registry, U8aBitLength } from '../types';
|
||||
|
||||
import { assert, isU8a, u8aToU8a } from '@polkadot/util';
|
||||
import { isU8a, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { Raw } from '../native/Raw';
|
||||
|
||||
@@ -16,7 +16,9 @@ function decodeU8aFixed (value: AnyU8a, bitLength: U8aBitLength): [AnyU8a, numbe
|
||||
return [new Uint8Array(byteLength), 0];
|
||||
}
|
||||
|
||||
assert(isU8a(value) ? u8a.length >= byteLength : u8a.length === byteLength, () => `Expected input with ${byteLength} bytes (${bitLength} bits), found ${u8a.length} bytes`);
|
||||
if (isU8a(value) ? u8a.length < byteLength : u8a.length !== byteLength) {
|
||||
throw new Error(`Expected input with ${byteLength} bytes (${bitLength} bits), found ${u8a.length} bytes`);
|
||||
}
|
||||
|
||||
return [u8a.subarray(0, byteLength), byteLength];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { AnyJson, AnyU8a, Codec, CodecClass, Inspect, Registry } from '../types';
|
||||
|
||||
import { assertReturn, compactAddLength, compactStripLength, compactToU8a, isHex, isU8a } from '@polkadot/util';
|
||||
import { compactAddLength, compactStripLength, compactToU8a, isHex, isU8a } from '@polkadot/util';
|
||||
|
||||
import { Raw } from '../native/Raw';
|
||||
import { typeToConstructor } from '../utils';
|
||||
@@ -70,7 +70,7 @@ export class WrapperKeepOpaque<T extends Codec> extends Bytes {
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
override inspect (): Inspect {
|
||||
public override inspect (): Inspect {
|
||||
return this.#decoded
|
||||
? {
|
||||
inner: [this.#decoded.inspect()],
|
||||
@@ -110,6 +110,10 @@ export class WrapperKeepOpaque<T extends Codec> extends Bytes {
|
||||
* @description Returns the decoded that the WrapperKeepOpaque represents (if available), throws if non-decodable
|
||||
*/
|
||||
public unwrap (): T {
|
||||
return assertReturn(this.#decoded, () => `${this.#opaqueName}: unwrapping an undecodable value`);
|
||||
if (!this.#decoded) {
|
||||
throw new Error(`${this.#opaqueName}: unwrapping an undecodable value`);
|
||||
}
|
||||
|
||||
return this.#decoded;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ export class bool extends Boolean implements Codec {
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
inspect (): Inspect {
|
||||
public inspect (): Inspect {
|
||||
return {
|
||||
outer: [this.toU8a()]
|
||||
};
|
||||
|
||||
@@ -81,7 +81,7 @@ export class CodecDate extends Date implements INumber {
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
inspect (): Inspect {
|
||||
public inspect (): Inspect {
|
||||
return {
|
||||
outer: [this.toU8a()]
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { AnyJson, AnyU8a, Inspect, IU8a, Registry } from '../types';
|
||||
|
||||
import { assert, isAscii, isUndefined, isUtf8, u8aToHex, u8aToString, u8aToU8a } from '@polkadot/util';
|
||||
import { isAscii, isUndefined, isUtf8, u8aToHex, u8aToString, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
/**
|
||||
* @name Raw
|
||||
@@ -16,11 +16,11 @@ import { assert, isAscii, isUndefined, isUtf8, u8aToHex, u8aToString, u8aToU8a }
|
||||
* @noInheritDoc
|
||||
*/
|
||||
export class Raw extends Uint8Array implements IU8a {
|
||||
readonly registry: Registry;
|
||||
|
||||
public createdAtHash?: IU8a;
|
||||
|
||||
readonly initialU8aLength?: number;
|
||||
public readonly initialU8aLength?: number;
|
||||
|
||||
public readonly registry: Registry;
|
||||
|
||||
constructor (registry: Registry, value?: AnyU8a, initialU8aLength?: number) {
|
||||
super(u8aToU8a(value));
|
||||
@@ -94,7 +94,7 @@ export class Raw extends Uint8Array implements IU8a {
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
inspect (): Inspect {
|
||||
public inspect (): Inspect {
|
||||
return {
|
||||
outer: [this.toU8a()]
|
||||
};
|
||||
@@ -177,7 +177,9 @@ export class Raw extends Uint8Array implements IU8a {
|
||||
* @description Returns the wrapped data as a UTF-8 string
|
||||
*/
|
||||
public toUtf8 (): string {
|
||||
assert(this.isUtf8, 'The character sequence is not a valid Utf8 string');
|
||||
if (!this.isUtf8) {
|
||||
throw new Error('The character sequence is not a valid Utf8 string');
|
||||
}
|
||||
|
||||
return u8aToString(this);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { CodecClass, Inspect, ISet, IU8a, Registry } from '../types';
|
||||
|
||||
import { assert, BN, bnToBn, bnToU8a, isBn, isNumber, isString, isU8a, isUndefined, objectProperties, stringify, stringPascalCase, u8aToBn, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { BN, bnToBn, bnToU8a, isBn, isNumber, isString, isU8a, isUndefined, objectProperties, stringify, stringPascalCase, u8aToBn, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { compareArray } from '../utils';
|
||||
|
||||
@@ -27,7 +27,9 @@ function decodeSetArray (setValues: SetValues, values: string[]): string[] {
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
const key = values[i];
|
||||
|
||||
assert(!isUndefined(setValues[key]), () => `Set: Invalid key '${key}' passed to Set, allowed ${Object.keys(setValues).join(', ')}`);
|
||||
if (isUndefined(setValues[key])) {
|
||||
throw new Error(`Set: Invalid key '${key}' passed to Set, allowed ${Object.keys(setValues).join(', ')}`);
|
||||
}
|
||||
|
||||
result[i] = key;
|
||||
}
|
||||
@@ -51,14 +53,18 @@ function decodeSetNumber (setValues: SetValues, _value: BN | number): string[] {
|
||||
|
||||
const computed = encodeSet(setValues, result);
|
||||
|
||||
assert(bn.eq(computed), () => `Set: Mismatch decoding '${bn.toString()}', computed as '${computed.toString()}' with ${result.join(', ')}`);
|
||||
if (!bn.eq(computed)) {
|
||||
throw new Error(`Set: Mismatch decoding '${bn.toString()}', computed as '${computed.toString()}' with ${result.join(', ')}`);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function decodeSet (setValues: SetValues, value: string[] | Set<string> | Uint8Array | BN | number | string = 0, bitLength: number): string[] {
|
||||
assert(bitLength % 8 === 0, () => `Expected valid bitLength, power of 8, found ${bitLength}`);
|
||||
if (bitLength % 8 !== 0) {
|
||||
throw new Error(`Expected valid bitLength, power of 8, found ${bitLength}`);
|
||||
}
|
||||
|
||||
const byteLength = bitLength / 8;
|
||||
|
||||
@@ -161,7 +167,9 @@ export class CodecSet extends Set<string> implements ISet<string> {
|
||||
// ^^^ add = () property done to assign this instance's this, otherwise Set.add creates "some" chaos
|
||||
// we have the isUndefined(this._setValues) in here as well, add is used internally
|
||||
// in the Set constructor (so it is undefined at this point, and should allow)
|
||||
assert(isUndefined(this.#allowed) || !isUndefined(this.#allowed[key]), () => `Set: Invalid key '${key}' on add`);
|
||||
if (this.#allowed && isUndefined(this.#allowed[key])) {
|
||||
throw new Error(`Set: Invalid key '${key}' on add`);
|
||||
}
|
||||
|
||||
super.add(key);
|
||||
|
||||
@@ -187,7 +195,7 @@ export class CodecSet extends Set<string> implements ISet<string> {
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
inspect (): Inspect {
|
||||
public inspect (): Inspect {
|
||||
return {
|
||||
outer: [this.toU8a()]
|
||||
};
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { AnyJson, BareOpts, Codec, CodecClass, Inspect, IStruct, IU8a, Registry } from '../types';
|
||||
|
||||
import { assert, isBoolean, isFunction, isHex, isObject, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { isBoolean, isFunction, isHex, isObject, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { compareMap, decodeU8a, mapToTypeMap, typesToMap } from '../utils';
|
||||
import { compareMap, decodeU8aStruct, mapToTypeMap, typesToMap } from '../utils';
|
||||
|
||||
type TypesDef<T = Codec> = Record<string, string | CodecClass<T>>;
|
||||
|
||||
@@ -27,8 +27,11 @@ function decodeStructFromObject (registry: Registry, [Types, keys]: Definition,
|
||||
const typeofArray = Array.isArray(value);
|
||||
const typeofMap = value instanceof Map;
|
||||
|
||||
assert(typeofArray || typeofMap || isObject(value), () => `Struct: Cannot decode value ${stringify(value)} (typeof ${typeof value}), expected an input object, map or array`);
|
||||
assert(!typeofArray || value.length === keys.length, () => `Struct: Unable to map ${stringify(value)} array to object with known keys ${keys.join(', ')}`);
|
||||
if (!typeofArray && !typeofMap && !isObject(value)) {
|
||||
throw new Error(`Struct: Cannot decode value ${stringify(value)} (typeof ${typeof value}), expected an input object, map or array`);
|
||||
} else if (typeofArray && value.length !== keys.length) {
|
||||
throw new Error(`Struct: Unable to map ${stringify(value)} array to object with known keys ${keys.join(', ')}`);
|
||||
}
|
||||
|
||||
const raw = new Array<[string, Codec]>(keys.length);
|
||||
|
||||
@@ -100,11 +103,11 @@ export class Struct<
|
||||
V extends { [K in keyof S]: any } = { [K in keyof S]: any },
|
||||
// type names, mapped by key, name of Class in S
|
||||
E extends { [K in keyof S]: string } = { [K in keyof S]: string }> extends Map<keyof S, Codec> implements IStruct<keyof S> {
|
||||
#registry: Registry;
|
||||
|
||||
public createdAtHash?: IU8a;
|
||||
|
||||
readonly initialU8aLength?: number;
|
||||
public readonly initialU8aLength?: number;
|
||||
|
||||
public readonly registry: Registry;
|
||||
|
||||
readonly #jsonMap: Map<keyof S, string>;
|
||||
|
||||
@@ -113,15 +116,15 @@ export class Struct<
|
||||
constructor (registry: Registry, Types: S, value?: V | Map<unknown, unknown> | unknown[] | HexString | null, jsonMap = new Map<string, string>(), { definition, setDefinition = noopSetDefinition }: Options = {}) {
|
||||
const typeMap = definition || setDefinition(mapToTypeMap(registry, Types));
|
||||
const [decoded, decodedLength] = isU8a(value) || isHex(value)
|
||||
? decodeU8a<Codec, [string, Codec]>(registry, new Array(typeMap[0].length), u8aToU8a(value), typeMap, true)
|
||||
? decodeU8aStruct(registry, new Array<[string, Codec]>(typeMap[0].length), u8aToU8a(value), typeMap)
|
||||
: value instanceof Struct
|
||||
? [value as Iterable<[string, Codec]>, 0]
|
||||
: decodeStructFromObject(registry, typeMap, value || {}, jsonMap);
|
||||
|
||||
super(decoded);
|
||||
|
||||
this.#registry = registry;
|
||||
this.initialU8aLength = decodedLength;
|
||||
this.registry = registry;
|
||||
this.#jsonMap = jsonMap;
|
||||
this.#Types = typeMap;
|
||||
}
|
||||
@@ -202,10 +205,6 @@ export class Struct<
|
||||
return this.registry.hash(this.toU8a());
|
||||
}
|
||||
|
||||
public get registry (): Registry {
|
||||
return this.#registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
@@ -231,7 +230,7 @@ export class Struct<
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
inspect (isBare?: BareOpts): Inspect {
|
||||
public inspect (isBare?: BareOpts): Inspect {
|
||||
const inner = new Array<Inspect>();
|
||||
|
||||
for (const [k, v] of this.entries()) {
|
||||
|
||||
@@ -7,6 +7,8 @@ import { TypeRegistry } from '@polkadot/types';
|
||||
import { Bytes, Raw, Text } from '@polkadot/types-codec';
|
||||
import { stringToU8a } from '@polkadot/util';
|
||||
|
||||
import { performance } from '../test/performance';
|
||||
|
||||
describe('Text', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
@@ -68,7 +70,7 @@ describe('Text', (): void => {
|
||||
expect(test).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('has a snae inspect', (): void => {
|
||||
it('has a sane inspect', (): void => {
|
||||
expect(
|
||||
new Text(registry, 'abcde').inspect()
|
||||
).toEqual({
|
||||
@@ -76,4 +78,6 @@ describe('Text', (): void => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
performance('Text', 100_000, [[new Uint8Array([6 << 2, 102, 111, 111, 102, 111, 111])]], (v: Uint8Array) => new Text(registry, v));
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { AnyString, AnyU8a, Inspect, IText, IU8a, Registry } from '../types';
|
||||
|
||||
import { assert, compactAddLength, compactFromU8aLim, compactToU8a, hexToU8a, isHex, isString, isU8a, stringToU8a, u8aToHex, u8aToString } from '@polkadot/util';
|
||||
import { compactAddLength, compactFromU8aLim, compactToU8a, hexToU8a, isHex, isString, isU8a, stringToU8a, u8aToHex, u8aToString } from '@polkadot/util';
|
||||
|
||||
import { Raw } from './Raw';
|
||||
|
||||
@@ -26,8 +26,11 @@ function decodeText (value?: null | AnyString | AnyU8a | { toString: () => strin
|
||||
const [offset, length] = compactFromU8aLim(value);
|
||||
const total = offset + length;
|
||||
|
||||
assert(length <= MAX_LENGTH, () => `Text: length ${length.toString()} exceeds ${MAX_LENGTH}`);
|
||||
assert(total <= value.length, () => `Text: required length less than remainder, expected at least ${total}, found ${value.length}`);
|
||||
if (length > MAX_LENGTH) {
|
||||
throw new Error(`Text: length ${length.toString()} exceeds ${MAX_LENGTH}`);
|
||||
} else if (total > value.length) {
|
||||
throw new Error(`Text: required length less than remainder, expected at least ${total}, found ${value.length}`);
|
||||
}
|
||||
|
||||
return [u8aToString(value.subarray(offset, total)), total];
|
||||
} else if (isHex(value)) {
|
||||
@@ -46,11 +49,11 @@ function decodeText (value?: null | AnyString | AnyU8a | { toString: () => strin
|
||||
* @noInheritDoc
|
||||
*/
|
||||
export class Text extends String implements IText {
|
||||
public readonly registry: Registry;
|
||||
|
||||
public createdAtHash?: IU8a;
|
||||
|
||||
readonly #initialU8aLength?: number;
|
||||
public readonly initialU8aLength?: number;
|
||||
|
||||
public readonly registry: Registry;
|
||||
|
||||
#override: string | null = null;
|
||||
|
||||
@@ -60,7 +63,7 @@ export class Text extends String implements IText {
|
||||
super(str);
|
||||
|
||||
this.registry = registry;
|
||||
this.#initialU8aLength = decodedLength;
|
||||
this.initialU8aLength = decodedLength;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,13 +73,6 @@ export class Text extends String implements IText {
|
||||
return this.toU8a().length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
|
||||
*/
|
||||
public get initialU8aLength (): number | undefined {
|
||||
return this.#initialU8aLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
@@ -111,7 +107,7 @@ export class Text extends String implements IText {
|
||||
/**
|
||||
* @description Returns a breakdown of the hex encoding for this Codec
|
||||
*/
|
||||
inspect (): Inspect {
|
||||
public inspect (): Inspect {
|
||||
const value = stringToU8a(super.toString());
|
||||
|
||||
return {
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/types-codec', path: 'auto', type: 'auto', version: '8.8.2' };
|
||||
export const packageInfo = { name: '@polkadot/types-codec', path: 'auto', type: 'auto', version: '8.9.1' };
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Shamelessly copied from @polkadot/util/test
|
||||
|
||||
import { formatDecimal, formatNumber } from '@polkadot/util';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
type ExecFn = (...params: any[]) => unknown;
|
||||
|
||||
const NUM_PAD = 16;
|
||||
const PRE_PAD = 32;
|
||||
|
||||
function loop (count: number, inputs: unknown[][], exec: ExecFn): [number, unknown[]] {
|
||||
const start = Date.now();
|
||||
const results = new Array<unknown>(inputs.length);
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const result = exec(...inputs[i % inputs.length]);
|
||||
|
||||
if (i < inputs.length) {
|
||||
results[i] = result;
|
||||
}
|
||||
}
|
||||
|
||||
return [Date.now() - start, results];
|
||||
}
|
||||
|
||||
export function formatFixed (value: number): string {
|
||||
const [a, b] = value.toFixed(2).split('.');
|
||||
|
||||
return [formatDecimal(a), b].join('.');
|
||||
}
|
||||
|
||||
export function formatOps (count: number, time: number): string {
|
||||
const micro = (time * 1000) / count;
|
||||
const ops = 1_000_000 / micro;
|
||||
|
||||
return `
|
||||
${formatFixed(ops).padStart(NUM_PAD + PRE_PAD + 1)} ops/s
|
||||
${formatFixed(micro).padStart(NUM_PAD + PRE_PAD + 1)} μs/op`;
|
||||
}
|
||||
|
||||
export function performance (name: string, count: number, inputs: unknown[][], exec: ExecFn): void {
|
||||
it(`performance: ${name}`, (): void => {
|
||||
const [time] = loop(count, inputs, exec);
|
||||
|
||||
console.log(`
|
||||
performance run for ${name} completed with ${formatNumber(count)} iterations.
|
||||
|
||||
${`${name}:`.padStart(PRE_PAD)} ${time.toString().padStart(NUM_PAD)} ms${formatOps(count, time)}
|
||||
`);
|
||||
});
|
||||
}
|
||||
|
||||
export function performanceCmp (name: string, [first, second]: [string, string], count: number, inputs: unknown[][], exec: ExecFn): void {
|
||||
it(`performance: ${name}`, (): void => {
|
||||
const pa = inputs.map((values) => [...values, false]);
|
||||
const pb = inputs.map((values) => [...values, true]);
|
||||
const [ta, ra] = loop(count, pa, exec);
|
||||
const [tb, rb] = loop(count, pb, exec);
|
||||
|
||||
console.log(`
|
||||
performance run for ${name} completed with ${formatNumber(count)} iterations.
|
||||
|
||||
${`${first}:`.padStart(PRE_PAD)} ${ta.toString().padStart(NUM_PAD)} ms ${ta < tb ? '(fastest)' : `(slowest, ${(ta / tb).toFixed(2)}x)`}${formatOps(count, ta)}
|
||||
|
||||
${`${second}:`.padStart(PRE_PAD)} ${tb.toString().padStart(NUM_PAD)} ms ${ta > tb ? '(fastest)' : `(slowest, ${(tb / ta).toFixed(2)}x)`}${formatOps(count, tb)}
|
||||
`);
|
||||
|
||||
const unmatched = ra.filter((r, i) =>
|
||||
JSON.stringify(r) !== JSON.stringify(rb[i])
|
||||
);
|
||||
|
||||
expect(unmatched.length).toEqual(0);
|
||||
});
|
||||
}
|
||||
@@ -17,7 +17,7 @@ export interface IEnum extends Codec {
|
||||
readonly defIndexes: number[];
|
||||
readonly defKeys: string[];
|
||||
readonly index: number;
|
||||
readonly isBasic: boolean
|
||||
readonly isBasic: boolean;
|
||||
readonly type: string;
|
||||
readonly value: Codec;
|
||||
|
||||
|
||||
@@ -5,19 +5,22 @@ import type { Codec, CodecClass, Registry } from '../types';
|
||||
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
function formatFailure (error: Error, type: string | null, u8a: Uint8Array, key?: string): string {
|
||||
return `decodeU8a: failed at ${u8aToHex(u8a)}…${key ? ` on ${key}` : ''}${type ? `: ${type}` : ''}:: ${error.message}`;
|
||||
}
|
||||
/** @internal */
|
||||
function formatFailure (registry: Registry, { message }: Error, u8a: Uint8Array, i: number, count: number, Type: CodecClass, key?: string): string {
|
||||
let type = '';
|
||||
|
||||
function getRawType (registry: Registry, Type: CodecClass): string | null {
|
||||
try {
|
||||
return new Type(registry).toRawType();
|
||||
type = `: ${new Type(registry).toRawType()}`;
|
||||
} catch {
|
||||
return null;
|
||||
// ignore
|
||||
}
|
||||
|
||||
return `decodeU8a: failed at ${u8aToHex(u8a.subarray(0, 16))}…${key ? ` on ${key}` : ''} (index ${i}/${count})${type}:: ${message}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* Given an u8a, and an array of Type constructors, decode the u8a against the
|
||||
* types, and return an array of decoded values.
|
||||
*
|
||||
@@ -25,50 +28,73 @@ function getRawType (registry: Registry, Type: CodecClass): string | null {
|
||||
* @param result - The result array (will be returned with values pushed)
|
||||
* @param types - The array of CodecClass to decode the U8a against.
|
||||
*/
|
||||
export function decodeU8a <T extends Codec = Codec, E = T> (registry: Registry, result: unknown[], u8a: Uint8Array, [Types, keys]: [CodecClass[], string[]], withZip?: boolean): [E[], number] {
|
||||
export function decodeU8a <T extends Codec = Codec> (registry: Registry, result: T[], u8a: Uint8Array, [Types, keys]: [CodecClass<T>[], string[]]): [T[], number] {
|
||||
const count = result.length;
|
||||
let offset = 0;
|
||||
let i = 0;
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
try {
|
||||
try {
|
||||
while (i < count) {
|
||||
const value = new Types[i](registry, u8a.subarray(offset));
|
||||
|
||||
offset += value.initialU8aLength || value.encodedLength;
|
||||
result[i] = withZip
|
||||
? [keys[i], value]
|
||||
: value;
|
||||
} catch (error) {
|
||||
throw new Error(formatFailure(
|
||||
error as Error,
|
||||
getRawType(registry, Types[i]),
|
||||
u8a.subarray(offset, offset + 16),
|
||||
keys[i]
|
||||
));
|
||||
result[i] = value;
|
||||
i++;
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(formatFailure(registry, error as Error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
||||
}
|
||||
|
||||
return [result as E[], offset];
|
||||
return [result, offset];
|
||||
}
|
||||
|
||||
// Split from decodeU8a since this is specialized to 1 instance ... yes duplication, but
|
||||
// since we have to do less checks (and these are intensive anyway), much faster
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* Split from decodeU8a since this is specialized to zip returns ... while we duplicate, this
|
||||
* is all on the hot-path, so it is not great, however there is (some) method behind the madness
|
||||
*/
|
||||
export function decodeU8aStruct (registry: Registry, result: [string, Codec][], u8a: Uint8Array, [Types, keys]: [CodecClass[], string[]]): [[string, Codec][], number] {
|
||||
const count = result.length;
|
||||
let offset = 0;
|
||||
let i = 0;
|
||||
|
||||
try {
|
||||
while (i < count) {
|
||||
const value = new Types[i](registry, u8a.subarray(offset));
|
||||
|
||||
offset += value.initialU8aLength || value.encodedLength;
|
||||
result[i] = [keys[i], value];
|
||||
i++;
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(formatFailure(registry, error as Error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
||||
}
|
||||
|
||||
return [result, offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* Split from decodeU8a since this is specialized to 1 instance ... while we duplicate, this
|
||||
* is all on the hot-path, so it is not great, however there is (some) method behind the madness
|
||||
*/
|
||||
export function decodeU8aVec <T extends Codec = Codec> (registry: Registry, result: unknown[], u8a: Uint8Array, startAt: number, Type: CodecClass<T>): [number, number] {
|
||||
const count = result.length;
|
||||
let offset = startAt;
|
||||
let i = 0;
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
try {
|
||||
try {
|
||||
while (i < count) {
|
||||
const value = new Type(registry, u8a.subarray(offset));
|
||||
|
||||
offset += value.initialU8aLength || value.encodedLength;
|
||||
result[i] = value;
|
||||
} catch (error) {
|
||||
throw new Error(formatFailure(
|
||||
error as Error,
|
||||
getRawType(registry, Type),
|
||||
u8a.subarray(offset, offset + 16)
|
||||
));
|
||||
i++;
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(formatFailure(registry, error as Error, u8a.subarray(offset), i, count, Type));
|
||||
}
|
||||
|
||||
return [offset, offset - startAt];
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
export { compareArray } from './compareArray';
|
||||
export { compareMap } from './compareMap';
|
||||
export { compareSet } from './compareSet';
|
||||
export { decodeU8a, decodeU8aVec } from './decodeU8a';
|
||||
export { decodeU8a, decodeU8aStruct, decodeU8aVec } from './decodeU8a';
|
||||
export { mapToTypeMap } from './mapToTypeMap';
|
||||
export { typeToConstructor } from './typeToConstructor';
|
||||
export { sanitize } from './sanitize';
|
||||
|
||||
@@ -13,7 +13,7 @@ export function mapToTypeMap (registry: Registry, input: Record<string, string |
|
||||
const count = entries.length;
|
||||
const output: [CodecClass[], string[]] = [new Array<CodecClass>(count), new Array<string>(count)];
|
||||
|
||||
for (let i = 0; i < entries.length; i++) {
|
||||
for (let i = 0; i < count; i++) {
|
||||
output[1][i] = entries[i][0];
|
||||
output[0][i] = typeToConstructor(registry, entries[i][1]);
|
||||
}
|
||||
|
||||
@@ -53,10 +53,6 @@ describe('sanitize', (): void => {
|
||||
it('removes on embedded values (all)', (): void => {
|
||||
expect(fn('(T::AccountId, slashing::SpanIndex)')).toEqual('(AccountId, SpanIndex)');
|
||||
});
|
||||
|
||||
it('keeps with allowNamespaces', (): void => {
|
||||
expect(fn('::slashing::SpanIndex', { allowNamespaces: true })).toEqual('slashing::SpanIndex');
|
||||
});
|
||||
});
|
||||
|
||||
describe('bounded', (): void => {
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
interface SanitizeOptions {
|
||||
allowNamespaces?: boolean;
|
||||
}
|
||||
import { AnyString } from '../types';
|
||||
|
||||
type Mapper = (value: string, options?: SanitizeOptions) => string;
|
||||
type Mapper = (value: string) => string;
|
||||
|
||||
const BOUNDED = ['BTreeMap', 'BTreeSet', 'HashMap', 'Vec'];
|
||||
const ALLOWED_BOXES = BOUNDED.concat(['Compact', 'DoNotConstruct', 'Int', 'Linkage', 'Range', 'RangeInclusive', 'Result', 'Option', 'UInt', 'WrapperKeepOpaque', 'WrapperOpaque']);
|
||||
@@ -165,7 +163,7 @@ export function removeExtensions (type: string, isSized: boolean): Mapper {
|
||||
}
|
||||
|
||||
export function removeColons (): Mapper {
|
||||
return (value: string, { allowNamespaces }: SanitizeOptions = {}): string => {
|
||||
return (value: string): string => {
|
||||
let index = 0;
|
||||
|
||||
while (index !== -1) {
|
||||
@@ -174,10 +172,6 @@ export function removeColons (): Mapper {
|
||||
if (index === 0) {
|
||||
value = value.substring(2);
|
||||
} else if (index !== -1) {
|
||||
if (allowNamespaces) {
|
||||
return value;
|
||||
}
|
||||
|
||||
let start = index;
|
||||
|
||||
while (start !== -1 && !BOX_PRECEDING.includes(value[start])) {
|
||||
@@ -203,7 +197,7 @@ export function removeGenerics (): Mapper {
|
||||
return (
|
||||
(
|
||||
start >= 0 &&
|
||||
value.substring(start, start + box.length) === box
|
||||
value.substring(start, index) === box
|
||||
) && (
|
||||
// make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
|
||||
start === 0 ||
|
||||
@@ -225,15 +219,12 @@ export function removeGenerics (): Mapper {
|
||||
};
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function pairOfReplacer (v: string): string {
|
||||
return `(${v},${v})`;
|
||||
}
|
||||
|
||||
// remove the PairOf wrappers
|
||||
export function removePairOf (): Mapper {
|
||||
const replacer = (v: string) => `(${v},${v})`;
|
||||
|
||||
return (value: string) =>
|
||||
replaceTagWith(value, 'PairOf<', pairOfReplacer);
|
||||
replaceTagWith(value, 'PairOf<', replacer);
|
||||
}
|
||||
|
||||
// remove the type traits
|
||||
@@ -269,39 +260,31 @@ export function removeTraits (): Mapper {
|
||||
};
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function wrapReplacer (v: string): string {
|
||||
return v;
|
||||
}
|
||||
|
||||
// remove wrapping values, i.e. Box<Proposal> -> Proposal
|
||||
export function removeWrap (check: string): Mapper {
|
||||
const replacer = (v: string) => v;
|
||||
|
||||
return (value: string) =>
|
||||
replaceTagWith(value, check, wrapReplacer);
|
||||
replaceTagWith(value, check, replacer);
|
||||
}
|
||||
|
||||
const sanitizeMap = new Map<string, string>();
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
export function sanitize (value: String | string, options?: SanitizeOptions): string {
|
||||
export function sanitize (value: AnyString): string {
|
||||
const startValue = value.toString();
|
||||
const memoized = sanitizeMap.get(startValue);
|
||||
|
||||
if (memoized) {
|
||||
return memoized;
|
||||
}
|
||||
|
||||
let result = startValue;
|
||||
|
||||
if (!options) {
|
||||
const memoized = sanitizeMap.get(startValue);
|
||||
|
||||
if (memoized) {
|
||||
return memoized;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < mappings.length; i++) {
|
||||
result = mappings[i](result, options);
|
||||
result = mappings[i](result);
|
||||
}
|
||||
|
||||
if (!options) {
|
||||
sanitizeMap.set(startValue, result);
|
||||
}
|
||||
sanitizeMap.set(startValue, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
"exclude": [
|
||||
"**/*.data.ts",
|
||||
"**/checkTypes.manual.ts",
|
||||
"**/*.spec.ts"
|
||||
"**/*.spec.ts",
|
||||
"**/test/*"
|
||||
],
|
||||
"references": []
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
"include": [
|
||||
"**/*.data.ts",
|
||||
"**/checkTypes.manual.ts",
|
||||
"**/*.spec.ts"
|
||||
"**/*.spec.ts",
|
||||
"**/test/*"
|
||||
],
|
||||
"references": [
|
||||
{ "path": "../types/tsconfig.build.json" },
|
||||
|
||||
@@ -20,14 +20,14 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.8.2",
|
||||
"version": "8.9.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@polkadot/types-codec": "8.8.2",
|
||||
"@polkadot/util": "^9.4.1"
|
||||
"@polkadot/types-codec": "8.9.1",
|
||||
"@polkadot/util": "^9.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/types": "8.8.2"
|
||||
"@polkadot/types": "8.9.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { Codec, CodecClass, Registry, U8aBitLength, UIntBitLength } from '@
|
||||
import type { TypeDef } from '../types';
|
||||
|
||||
import { BTreeMap, BTreeSet, Bytes, CodecSet, Compact, DoNotConstruct, Enum, HashMap, Int, Null, Option, Range, RangeInclusive, Result, Struct, Tuple, U8aFixed, UInt, Vec, VecFixed, WrapperKeepOpaque, WrapperOpaque } from '@polkadot/types-codec';
|
||||
import { assert, isNumber, stringify } from '@polkadot/util';
|
||||
import { isNumber, stringify } from '@polkadot/util';
|
||||
|
||||
import { TypeDefInfo } from '../types';
|
||||
import { getTypeDef } from '../util/getTypeDef';
|
||||
@@ -15,13 +15,17 @@ function getTypeDefType ({ lookupName, type }: TypeDef): string {
|
||||
}
|
||||
|
||||
function getSubDefArray (value: TypeDef): TypeDef[] {
|
||||
assert(value.sub && Array.isArray(value.sub), () => `Expected subtype as TypeDef[] in ${stringify(value)}`);
|
||||
if (!Array.isArray(value.sub)) {
|
||||
throw new Error(`Expected subtype as TypeDef[] in ${stringify(value)}`);
|
||||
}
|
||||
|
||||
return value.sub;
|
||||
}
|
||||
|
||||
function getSubDef (value: TypeDef): TypeDef {
|
||||
assert(value.sub && !Array.isArray(value.sub), () => `Expected subtype as TypeDef in ${stringify(value)}`);
|
||||
if (!value.sub || Array.isArray(value.sub)) {
|
||||
throw new Error(`Expected subtype as TypeDef in ${stringify(value)}`);
|
||||
}
|
||||
|
||||
return value.sub;
|
||||
}
|
||||
@@ -48,7 +52,9 @@ function getTypeClassArray (value: TypeDef): string[] {
|
||||
}
|
||||
|
||||
function createInt (Clazz: typeof Int | typeof UInt, { displayName, length }: TypeDef): CodecClass<Codec> {
|
||||
assert(isNumber(length), () => `Expected bitLength information for ${displayName || Clazz.constructor.name}<bitLength>`);
|
||||
if (!isNumber(length)) {
|
||||
throw new Error(`Expected bitLength information for ${displayName || Clazz.constructor.name}<bitLength>`);
|
||||
}
|
||||
|
||||
return Clazz.with(length as UIntBitLength, displayName);
|
||||
}
|
||||
@@ -116,7 +122,9 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
|
||||
Null,
|
||||
|
||||
[TypeDefInfo.Option]: (registry: Registry, value: TypeDef): CodecClass<Codec> => {
|
||||
assert(value.sub && !Array.isArray(value.sub), 'Expected type information for Option');
|
||||
if (!value.sub || Array.isArray(value.sub)) {
|
||||
throw new Error('Expected type information for Option');
|
||||
}
|
||||
|
||||
// NOTE This is opt-in (unhandled), not by default
|
||||
// if (value.sub.type === 'bool') {
|
||||
@@ -165,7 +173,9 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
|
||||
createInt(UInt, value),
|
||||
|
||||
[TypeDefInfo.Vec]: (registry: Registry, { sub }: TypeDef): CodecClass<Codec> => {
|
||||
assert(sub && !Array.isArray(sub), 'Expected type information for vector');
|
||||
if (!sub || Array.isArray(sub)) {
|
||||
throw new Error('Expected type information for vector');
|
||||
}
|
||||
|
||||
return (
|
||||
sub.type === 'u8'
|
||||
@@ -175,7 +185,9 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
|
||||
},
|
||||
|
||||
[TypeDefInfo.VecFixed]: (registry: Registry, { displayName, length, sub }: TypeDef): CodecClass<Codec> => {
|
||||
assert(sub && isNumber(length) && !Array.isArray(sub), 'Expected length & type information for fixed vector');
|
||||
if (!isNumber(length) || !sub || Array.isArray(sub)) {
|
||||
throw new Error('Expected length & type information for fixed vector');
|
||||
}
|
||||
|
||||
return (
|
||||
sub.type === 'u8'
|
||||
@@ -195,7 +207,9 @@ export function constructTypeClass<T extends Codec = Codec> (registry: Registry,
|
||||
try {
|
||||
const Type = infoMapping[typeDef.info](registry, typeDef);
|
||||
|
||||
assert(Type, 'No class created');
|
||||
if (!Type) {
|
||||
throw new Error('No class created');
|
||||
}
|
||||
|
||||
// don't clobber any existing
|
||||
if (!Type.__fallbackType && typeDef.fallbackType) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { Codec, CodecClass, IU8a, Registry } from '@polkadot/types-codec/ty
|
||||
import type { CreateOptions } from '../types';
|
||||
|
||||
import { Bytes, Option } from '@polkadot/types-codec';
|
||||
import { assert, isHex, isU8a, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { isHex, isU8a, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { createClassUnsafe } from './class';
|
||||
|
||||
@@ -29,7 +29,9 @@ function checkInstance (created: Codec, matcher: Uint8Array): void {
|
||||
)
|
||||
);
|
||||
|
||||
assert(isOk, () => `${rawType}:: Decoded input doesn't match input, received ${u8aToHex(matcher, 512)} (${matcher.length} bytes), created ${u8aToHex(u8a, 512)} (${u8a.length} bytes)`);
|
||||
if (!isOk) {
|
||||
throw new Error(`${rawType}:: Decoded input doesn't match input, received ${u8aToHex(matcher, 512)} (${matcher.length} bytes), created ${u8aToHex(u8a, 512)} (${u8a.length} bytes)`);
|
||||
}
|
||||
}
|
||||
|
||||
function checkPedantic (created: Codec, [value]: unknown[]): void {
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/types-create', path: 'auto', type: 'auto', version: '8.8.2' };
|
||||
export const packageInfo = { name: '@polkadot/types-create', path: 'auto', type: 'auto', version: '8.9.1' };
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import type { Registry } from '@polkadot/types-codec/types';
|
||||
import type { TypeDef } from '@polkadot/types-create/types';
|
||||
|
||||
import { assert, isNumber, isUndefined, objectSpread, stringify } from '@polkadot/util';
|
||||
import { isNumber, isUndefined, objectSpread, stringify } from '@polkadot/util';
|
||||
|
||||
import { TypeDefInfo } from '../types';
|
||||
|
||||
@@ -45,7 +45,9 @@ function encodeWithParams (registry: Registry, typeDef: TypeDef, outer: 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(', ')}`);
|
||||
if (!names.every((n) => !!n)) {
|
||||
throw new Error(`Subtypes does not have consistent names, ${names.join(', ')}`);
|
||||
}
|
||||
|
||||
const inner: Record<string, string> = objectSpread({}, extra);
|
||||
|
||||
@@ -78,7 +80,9 @@ const encoders: Record<TypeDefInfo, (registry: Registry, typeDef: TypeDef) => st
|
||||
`DoNotConstruct<${lookupName || displayName || (isUndefined(lookupIndex) ? 'Unknown' : registry.createLookupType(lookupIndex))}>`,
|
||||
|
||||
[TypeDefInfo.Enum]: (registry: Registry, { sub }: TypeDef): string => {
|
||||
assert(sub && Array.isArray(sub), 'Unable to encode Enum type');
|
||||
if (!Array.isArray(sub)) {
|
||||
throw new Error('Unable to encode Enum type');
|
||||
}
|
||||
|
||||
// c-like enums have all Null entries
|
||||
// TODO We need to take the disciminant into account and auto-add empty entries
|
||||
@@ -118,7 +122,9 @@ const encoders: Record<TypeDefInfo, (registry: Registry, typeDef: TypeDef) => st
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
[TypeDefInfo.Set]: (registry: Registry, { length = 8, sub }: TypeDef): string => {
|
||||
assert(sub && Array.isArray(sub), 'Unable to encode Set type');
|
||||
if (!Array.isArray(sub)) {
|
||||
throw new Error('Unable to encode Set type');
|
||||
}
|
||||
|
||||
return stringify({
|
||||
_set: sub.reduce((all, { index, name }, count) =>
|
||||
@@ -132,7 +138,9 @@ const encoders: Record<TypeDefInfo, (registry: Registry, typeDef: TypeDef) => st
|
||||
lookupName || type,
|
||||
|
||||
[TypeDefInfo.Struct]: (registry: Registry, { alias, sub }: TypeDef): string => {
|
||||
assert(sub && Array.isArray(sub), 'Unable to encode Struct type');
|
||||
if (!Array.isArray(sub)) {
|
||||
throw new Error('Unable to encode Struct type');
|
||||
}
|
||||
|
||||
return encodeSubTypes(registry, sub, false,
|
||||
alias
|
||||
@@ -146,7 +154,9 @@ const encoders: Record<TypeDefInfo, (registry: Registry, typeDef: TypeDef) => st
|
||||
},
|
||||
|
||||
[TypeDefInfo.Tuple]: (registry: Registry, { sub }: TypeDef): string => {
|
||||
assert(sub && Array.isArray(sub), 'Unable to encode Tuple type');
|
||||
if (!Array.isArray(sub)) {
|
||||
throw new Error('Unable to encode Tuple type');
|
||||
}
|
||||
|
||||
return `(${sub.map((type) => encodeTypeDef(registry, type)).join(',')})`;
|
||||
},
|
||||
@@ -158,7 +168,9 @@ const encoders: Record<TypeDefInfo, (registry: Registry, typeDef: TypeDef) => st
|
||||
encodeWithParams(registry, typeDef, 'Vec'),
|
||||
|
||||
[TypeDefInfo.VecFixed]: (registry: Registry, { length, sub }: TypeDef): string => {
|
||||
assert(isNumber(length) && !isUndefined(sub) && !Array.isArray(sub), 'Unable to encode VecFixed type');
|
||||
if (!isNumber(length) || !sub || Array.isArray(sub)) {
|
||||
throw new Error('Unable to encode VecFixed type');
|
||||
}
|
||||
|
||||
return `[${sub.type};${length}]`;
|
||||
},
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// Copyright 2017-2022 @polkadot/types-create authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AnyString } from '@polkadot/types-codec/types';
|
||||
import type { TypeDef } from '@polkadot/types-create/types';
|
||||
|
||||
import { sanitize } from '@polkadot/types-codec';
|
||||
import { assert, isNumber, isString, objectSpread } from '@polkadot/util';
|
||||
import { isNumber, isString, objectSpread } from '@polkadot/util';
|
||||
|
||||
import { TypeDefInfo } from '../types';
|
||||
import { typeSplit } from './typeSplit';
|
||||
@@ -14,7 +15,6 @@ interface TypeDefOptions {
|
||||
displayName?: string;
|
||||
}
|
||||
|
||||
const MAX_NESTED = 64;
|
||||
const KNOWN_INTERNALS = ['_alias', '_fallback'];
|
||||
|
||||
function getTypeString (typeOrObj: any): string {
|
||||
@@ -27,7 +27,9 @@ function isRustEnum (details: Record<string, string> | Record<string, number>):
|
||||
const values = Object.values(details);
|
||||
|
||||
if (values.some((v) => isNumber(v))) {
|
||||
assert(values.every((v) => isNumber(v) && v >= 0 && v <= 255), 'Invalid number-indexed enum definition');
|
||||
if (!values.every((v) => isNumber(v) && v >= 0 && v <= 255)) {
|
||||
throw new Error('Invalid number-indexed enum definition');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -102,9 +104,11 @@ function _decodeStruct (value: TypeDef, type: string, _: string, count: number):
|
||||
? new Map(Object.entries(parsed._alias))
|
||||
: undefined;
|
||||
value.fallbackType = parsed._fallback;
|
||||
value.sub = keys.filter((name) => !KNOWN_INTERNALS.includes(name)).map((name): TypeDef =>
|
||||
getTypeDef(getTypeString(parsed[name]), { name }, count)
|
||||
);
|
||||
value.sub = keys
|
||||
.filter((name) => !KNOWN_INTERNALS.includes(name))
|
||||
.map((name) =>
|
||||
getTypeDef(getTypeString(parsed[name]), { name }, count)
|
||||
);
|
||||
|
||||
return value;
|
||||
}
|
||||
@@ -117,23 +121,40 @@ function _decodeFixedVec (value: TypeDef, type: string, _: string, count: number
|
||||
let inner = 0;
|
||||
|
||||
for (let i = 1; (i < max) && (index === -1); i++) {
|
||||
if (type[i] === ';' && inner === 0) {
|
||||
index = i;
|
||||
} else if (['[', '(', '<'].includes(type[i])) {
|
||||
inner++;
|
||||
} else if ([']', ')', '>'].includes(type[i])) {
|
||||
inner--;
|
||||
switch (type[i]) {
|
||||
case ';': {
|
||||
if (inner === 0) {
|
||||
index = i;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case '[':
|
||||
case '(':
|
||||
case '<':
|
||||
inner++;
|
||||
break;
|
||||
|
||||
case ']':
|
||||
case ')':
|
||||
case '>':
|
||||
inner--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(index !== -1, () => `${type}: Unable to extract location of ';'`);
|
||||
if (index === -1) {
|
||||
throw new Error(`${type}: Unable to extract location of ';'`);
|
||||
}
|
||||
|
||||
const vecType = type.substring(1, index);
|
||||
const [strLength, displayName] = type.substring(index + 1, max).split(';');
|
||||
const length = parseInt(strLength.trim(), 10);
|
||||
|
||||
// as a first round, only u8 via u8aFixed, we can add more support
|
||||
assert(length <= 256, () => `${type}: Only support for [Type; <length>], where length <= 256`);
|
||||
if (length > 2048) {
|
||||
throw new Error(`${type}: Only support for [Type; <length>], where length <= 2048`);
|
||||
}
|
||||
|
||||
value.displayName = displayName;
|
||||
value.length = length;
|
||||
@@ -157,8 +178,9 @@ function _decodeAnyInt (value: TypeDef, type: string, _: string, clazz: 'Int' |
|
||||
const [strLength, displayName] = type.substring(clazz.length + 1, type.length - 1).split(',');
|
||||
const length = parseInt(strLength.trim(), 10);
|
||||
|
||||
// as a first round, only u8 via u8aFixed, we can add more support
|
||||
assert(length <= 8192 && (length % 8) === 0, () => `${type}: Only support for ${clazz}<bitLength>, where length <= 8192 and a power of 8, found ${length}`);
|
||||
if ((length > 8192) || (length % 8)) {
|
||||
throw new Error(`${type}: Only support for ${clazz}<bitLength>, where length <= 8192 and a power of 8, found ${length}`);
|
||||
}
|
||||
|
||||
value.displayName = displayName;
|
||||
value.length = length;
|
||||
@@ -216,13 +238,14 @@ function extractSubType (type: string, [start, end]: [string, string, TypeDefInf
|
||||
return type.substring(start.length, type.length - end.length);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
export function getTypeDef (_type: String | string, { displayName, name }: TypeDefOptions = {}, count = 0): TypeDef {
|
||||
export function getTypeDef (_type: AnyString, { displayName, name }: TypeDefOptions = {}, count = 0): TypeDef {
|
||||
// create the type via Type, allowing types to be sanitized
|
||||
const type = sanitize(_type);
|
||||
const value: TypeDef = { displayName, info: TypeDefInfo.Plain, name, type };
|
||||
|
||||
assert(++count !== MAX_NESTED, 'getTypeDef: Maximum nested limit reached');
|
||||
if (++count > 64) {
|
||||
throw new Error('getTypeDef: Maximum nested limit reached');
|
||||
}
|
||||
|
||||
const nested = nestedExtraction.find((nested) => hasWrapper(type, nested));
|
||||
|
||||
|
||||
@@ -36,13 +36,13 @@ describe('typeSplit', (): void => {
|
||||
|
||||
it('checks for unclosed vec', (): void => {
|
||||
expect(
|
||||
(): string[] => typeSplit('Text, Vec<u64')
|
||||
() => typeSplit('Text, Vec<u64')
|
||||
).toThrow(/Invalid definition/);
|
||||
});
|
||||
|
||||
it('checks for unclosed tuple', (): void => {
|
||||
expect(
|
||||
(): string[] => typeSplit('Text, (u64, u32')
|
||||
() => typeSplit('Text, (u64, u32')
|
||||
).toThrow(/Invalid definition/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,48 +1,53 @@
|
||||
// Copyright 2017-2022 @polkadot/types-create authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { assert } from '@polkadot/util';
|
||||
|
||||
function isNotNested (...counters: number[]): boolean {
|
||||
return !counters.some((counter): boolean => counter !== 0);
|
||||
}
|
||||
|
||||
// safely split a string on ', ' while taking care of any nested occurences
|
||||
export function typeSplit (type: string): string[] {
|
||||
let [cDepth, fDepth, sDepth, tDepth, start] = [0, 0, 0, 0, 0];
|
||||
const result = [];
|
||||
const result: string[] = [];
|
||||
|
||||
const extract = (index: number): void => {
|
||||
if (isNotNested(cDepth, fDepth, sDepth, tDepth)) {
|
||||
result.push(type.substring(start, index).trim());
|
||||
start = index + 1;
|
||||
}
|
||||
};
|
||||
// these are the depths of the various tokens: <, [, {, (
|
||||
let c = 0;
|
||||
let f = 0;
|
||||
let s = 0;
|
||||
let t = 0;
|
||||
|
||||
for (let index = 0; index < type.length; index++) {
|
||||
switch (type[index]) {
|
||||
// current start position
|
||||
let start = 0;
|
||||
|
||||
for (let i = 0; i < type.length; i++) {
|
||||
switch (type[i]) {
|
||||
// if we are not nested, add the type
|
||||
case ',': extract(index); break;
|
||||
case ',': {
|
||||
if (!(c || f || s || t)) {
|
||||
result.push(type.substring(start, i).trim());
|
||||
start = i + 1;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// adjust compact/vec (and friends) depth
|
||||
case '<': cDepth++; break;
|
||||
case '>': cDepth--; break;
|
||||
case '<': c++; break;
|
||||
case '>': c--; break;
|
||||
|
||||
// adjust fixed vec depths
|
||||
case '[': fDepth++; break;
|
||||
case ']': fDepth--; break;
|
||||
case '[': f++; break;
|
||||
case ']': f--; break;
|
||||
|
||||
// adjust struct depth
|
||||
case '{': sDepth++; break;
|
||||
case '}': sDepth--; break;
|
||||
case '{': s++; break;
|
||||
case '}': s--; break;
|
||||
|
||||
// adjust tuple depth
|
||||
case '(': tDepth++; break;
|
||||
case ')': tDepth--; break;
|
||||
case '(': t++; break;
|
||||
case ')': t--; break;
|
||||
}
|
||||
}
|
||||
|
||||
assert(isNotNested(cDepth, fDepth, sDepth, tDepth), () => `Invalid definition (missing terminators) found in ${type}`);
|
||||
// ensure we have all the terminators taken care of
|
||||
if (c || f || s || t) {
|
||||
throw new Error(`Invalid definition (missing terminators) found in ${type}`);
|
||||
}
|
||||
|
||||
// the final leg of the journey
|
||||
result.push(type.substring(start, type.length).trim());
|
||||
|
||||
@@ -20,14 +20,14 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.8.2",
|
||||
"version": "8.9.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@polkadot/networks": "^9.4.1",
|
||||
"@polkadot/types": "8.8.2",
|
||||
"@polkadot/types-codec": "8.8.2",
|
||||
"@polkadot/types-create": "8.8.2",
|
||||
"@polkadot/util": "^9.4.1"
|
||||
"@polkadot/networks": "^9.5.1",
|
||||
"@polkadot/types": "8.9.1",
|
||||
"@polkadot/types-codec": "8.9.1",
|
||||
"@polkadot/types-create": "8.9.1",
|
||||
"@polkadot/util": "^9.5.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/types-known', path: 'auto', type: 'auto', version: '8.8.2' };
|
||||
export const packageInfo = { name: '@polkadot/types-known', path: 'auto', type: 'auto', version: '8.9.1' };
|
||||
|
||||
@@ -16,7 +16,7 @@ const upgrades: ChainUpgradesRaw = [
|
||||
[7812476, 9040], [8010981, 9050], [8073833, 9070], [8555825, 9080], [8945245, 9090],
|
||||
[9611377, 9100], [9625129, 9111], [9866422, 9122], [10403784, 9130], [10960765, 9150],
|
||||
[11006614, 9151], [11404482, 9160], [11601803, 9170], [12008022, 9180], [12405451, 9190],
|
||||
[12665416, 9200], [12909508, 9220]
|
||||
[12665416, 9200], [12909508, 9220], [13109752, 9230]
|
||||
];
|
||||
|
||||
export default upgrades;
|
||||
|
||||
@@ -20,10 +20,10 @@
|
||||
"./detectPackage.cjs"
|
||||
],
|
||||
"type": "module",
|
||||
"version": "8.8.2",
|
||||
"version": "8.9.1",
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.18.3",
|
||||
"@polkadot/util": "^9.4.1"
|
||||
"@polkadot/util": "^9.5.1"
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -3,4 +3,4 @@
|
||||
|
||||
// Do not edit, auto-generated by @polkadot/dev
|
||||
|
||||
export const packageInfo = { name: '@polkadot/types-support', path: 'auto', type: 'auto', version: '8.8.2' };
|
||||
export const packageInfo = { name: '@polkadot/types-support', path: 'auto', type: 'auto', version: '8.9.1' };
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user