@polkadot/types-codec 9.5.2 → 9.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/abstract/Array.js +15 -44
- package/abstract/Base.js +12 -28
- package/abstract/BigInt.js +3 -2
- package/abstract/Int.js +25 -52
- package/abstract/index.js +1 -0
- package/base/Compact.js +21 -45
- package/base/DoNotConstruct.js +3 -19
- package/base/Enum.js +37 -88
- package/base/Int.js +2 -5
- package/base/Null.js +12 -23
- package/base/Option.js +23 -59
- package/base/Result.js +8 -19
- package/base/Tuple.js +12 -29
- package/base/UInt.js +2 -4
- package/base/Vec.js +7 -25
- package/base/VecAny.js +2 -2
- package/base/VecFixed.js +8 -20
- package/base/index.js +1 -0
- package/bundle.js +1 -0
- package/cjs/abstract/Array.js +13 -47
- package/cjs/abstract/Base.js +12 -30
- package/cjs/abstract/BigInt.js +1 -4
- package/cjs/abstract/Int.js +25 -55
- package/cjs/abstract/index.js +0 -3
- package/cjs/base/Compact.js +21 -48
- package/cjs/base/DoNotConstruct.js +3 -21
- package/cjs/base/Enum.js +34 -92
- package/cjs/base/Int.js +0 -7
- package/cjs/base/Null.js +10 -25
- package/cjs/base/Option.js +23 -63
- package/cjs/base/Result.js +6 -21
- package/cjs/base/Tuple.js +12 -33
- package/cjs/base/UInt.js +0 -6
- package/cjs/base/Vec.js +7 -31
- package/cjs/base/VecAny.js +0 -4
- package/cjs/base/VecFixed.js +8 -25
- package/cjs/base/index.js +0 -12
- package/cjs/bundle.js +0 -13
- package/cjs/detectPackage.js +2 -4
- package/cjs/extended/BTreeMap.js +1 -5
- package/cjs/extended/BTreeSet.js +17 -57
- package/cjs/extended/BitVec.js +11 -25
- package/cjs/extended/Bytes.js +9 -20
- package/cjs/extended/HashMap.js +1 -5
- package/cjs/extended/Linkage.js +5 -20
- package/cjs/extended/Map.js +16 -62
- package/cjs/extended/OptionBool.js +8 -21
- package/cjs/extended/Range.js +3 -13
- package/cjs/extended/RangeInclusive.js +1 -6
- package/cjs/extended/Type.js +1 -7
- package/cjs/extended/U8aFixed.js +2 -15
- package/cjs/extended/WrapperKeepOpaque.js +8 -28
- package/cjs/extended/WrapperOpaque.js +2 -8
- package/cjs/extended/index.js +0 -14
- package/cjs/index.js +0 -3
- package/cjs/native/Bool.js +14 -32
- package/cjs/native/Date.js +18 -40
- package/cjs/native/Float.js +11 -29
- package/cjs/native/Json.js +14 -33
- package/cjs/native/Raw.js +18 -41
- package/cjs/native/Set.js +21 -67
- package/cjs/native/Struct.data.js +1 -0
- package/cjs/native/Struct.js +33 -83
- package/cjs/native/Text.js +20 -44
- package/cjs/native/index.js +0 -8
- package/cjs/packageInfo.js +3 -1
- package/cjs/primitive/F32.js +0 -3
- package/cjs/primitive/F64.js +0 -3
- package/cjs/primitive/I128.js +0 -3
- package/cjs/primitive/I16.js +0 -3
- package/cjs/primitive/I256.js +0 -3
- package/cjs/primitive/I32.js +0 -3
- package/cjs/primitive/I64.js +0 -3
- package/cjs/primitive/I8.js +0 -3
- package/cjs/primitive/U128.js +0 -3
- package/cjs/primitive/U16.js +0 -3
- package/cjs/primitive/U256.js +0 -3
- package/cjs/primitive/U32.js +0 -3
- package/cjs/primitive/U64.js +0 -3
- package/cjs/primitive/U8.js +0 -3
- package/cjs/primitive/USize.js +0 -4
- package/cjs/primitive/index.js +0 -15
- package/cjs/types/index.js +0 -8
- package/cjs/utils/compareArray.js +1 -4
- package/cjs/utils/compareMap.js +4 -9
- package/cjs/utils/compareSet.js +4 -6
- package/cjs/utils/decodeU8a.js +7 -17
- package/cjs/utils/index.js +0 -9
- package/cjs/utils/mapToTypeMap.js +0 -4
- package/cjs/utils/sanitize.js +66 -71
- package/cjs/utils/sortValues.js +5 -18
- package/cjs/utils/typeToConstructor.js +1 -2
- package/cjs/utils/typesToMap.js +1 -3
- package/cjs/utils/util.js +1 -2
- package/detectOther.js +2 -0
- package/detectPackage.js +2 -0
- package/extended/BTreeMap.js +1 -2
- package/extended/BTreeSet.js +17 -53
- package/extended/BitVec.js +13 -22
- package/extended/Bytes.js +11 -17
- package/extended/HashMap.js +1 -2
- package/extended/Linkage.js +5 -12
- package/extended/Map.js +16 -54
- package/extended/OptionBool.js +8 -17
- package/extended/Range.js +4 -11
- package/extended/RangeInclusive.js +1 -3
- package/extended/Type.js +3 -4
- package/extended/U8aFixed.js +4 -12
- package/extended/WrapperKeepOpaque.js +8 -23
- package/extended/WrapperOpaque.js +2 -5
- package/extended/index.js +1 -0
- package/index.js +1 -0
- package/native/Bool.js +16 -30
- package/native/Date.js +18 -37
- package/native/Float.js +12 -27
- package/native/Json.js +16 -30
- package/native/Raw.js +20 -39
- package/native/Set.js +21 -63
- package/native/Struct.data.js +1 -0
- package/native/Struct.js +33 -80
- package/native/Text.js +20 -40
- package/native/index.js +1 -0
- package/package.json +1 -1
- package/packageInfo.js +3 -1
- package/primitive/F32.js +2 -1
- package/primitive/F64.js +2 -1
- package/primitive/I128.js +2 -1
- package/primitive/I16.js +2 -1
- package/primitive/I256.js +2 -1
- package/primitive/I32.js +2 -1
- package/primitive/I64.js +2 -1
- package/primitive/I8.js +2 -1
- package/primitive/U128.js +2 -1
- package/primitive/U16.js +2 -1
- package/primitive/U256.js +2 -1
- package/primitive/U32.js +2 -1
- package/primitive/U64.js +2 -1
- package/primitive/U8.js +2 -1
- package/primitive/USize.js +2 -2
- package/primitive/index.js +1 -0
- package/types/index.js +1 -0
- package/utils/compareArray.js +4 -3
- package/utils/compareMap.js +4 -7
- package/utils/compareSet.js +4 -5
- package/utils/decodeU8a.js +9 -14
- package/utils/index.js +1 -0
- package/utils/mapToTypeMap.js +2 -3
- package/utils/sanitize.js +66 -60
- package/utils/sortValues.js +6 -15
- package/utils/typeToConstructor.js +1 -0
- package/utils/typesToMap.js +1 -2
- package/utils/util.js +1 -0
package/cjs/utils/decodeU8a.js
CHANGED
|
@@ -6,9 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.decodeU8a = decodeU8a;
|
|
7
7
|
exports.decodeU8aStruct = decodeU8aStruct;
|
|
8
8
|
exports.decodeU8aVec = decodeU8aVec;
|
|
9
|
-
|
|
10
9
|
var _util = require("@polkadot/util");
|
|
11
|
-
|
|
12
10
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
13
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
14
12
|
|
|
@@ -18,15 +16,17 @@ function formatFailure(registry, result, _ref, u8a, i, count, Type, key) {
|
|
|
18
16
|
message
|
|
19
17
|
} = _ref;
|
|
20
18
|
let type = '';
|
|
21
|
-
|
|
22
19
|
try {
|
|
23
20
|
type = `: ${new Type(registry).toRawType()}`;
|
|
24
|
-
} catch {
|
|
25
|
-
|
|
21
|
+
} catch {
|
|
22
|
+
// ignore
|
|
23
|
+
}
|
|
26
24
|
|
|
25
|
+
// console.error(JSON.stringify(result, null, 2));
|
|
27
26
|
|
|
28
27
|
return `decodeU8a: failed at ${(0, _util.u8aToHex)(u8a.subarray(0, 16))}…${key ? ` on ${key}` : ''} (index ${i}/${count})${type}:: ${message}`;
|
|
29
28
|
}
|
|
29
|
+
|
|
30
30
|
/**
|
|
31
31
|
* @internal
|
|
32
32
|
*
|
|
@@ -37,14 +37,11 @@ function formatFailure(registry, result, _ref, u8a, i, count, Type, key) {
|
|
|
37
37
|
* @param result - The result array (will be returned with values pushed)
|
|
38
38
|
* @param types - The array of CodecClass to decode the U8a against.
|
|
39
39
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
40
|
function decodeU8a(registry, result, u8a, _ref2) {
|
|
43
41
|
let [Types, keys] = _ref2;
|
|
44
42
|
const count = result.length;
|
|
45
43
|
let offset = 0;
|
|
46
44
|
let i = 0;
|
|
47
|
-
|
|
48
45
|
try {
|
|
49
46
|
while (i < count) {
|
|
50
47
|
const value = new Types[i](registry, u8a.subarray(offset));
|
|
@@ -55,23 +52,20 @@ function decodeU8a(registry, result, u8a, _ref2) {
|
|
|
55
52
|
} catch (error) {
|
|
56
53
|
throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
|
57
54
|
}
|
|
58
|
-
|
|
59
55
|
return [result, offset];
|
|
60
56
|
}
|
|
57
|
+
|
|
61
58
|
/**
|
|
62
59
|
* @internal
|
|
63
60
|
*
|
|
64
61
|
* Split from decodeU8a since this is specialized to zip returns ... while we duplicate, this
|
|
65
62
|
* is all on the hot-path, so it is not great, however there is (some) method behind the madness
|
|
66
63
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
64
|
function decodeU8aStruct(registry, result, u8a, _ref3) {
|
|
70
65
|
let [Types, keys] = _ref3;
|
|
71
66
|
const count = result.length;
|
|
72
67
|
let offset = 0;
|
|
73
68
|
let i = 0;
|
|
74
|
-
|
|
75
69
|
try {
|
|
76
70
|
while (i < count) {
|
|
77
71
|
const value = new Types[i](registry, u8a.subarray(offset));
|
|
@@ -82,22 +76,19 @@ function decodeU8aStruct(registry, result, u8a, _ref3) {
|
|
|
82
76
|
} catch (error) {
|
|
83
77
|
throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
|
84
78
|
}
|
|
85
|
-
|
|
86
79
|
return [result, offset];
|
|
87
80
|
}
|
|
81
|
+
|
|
88
82
|
/**
|
|
89
83
|
* @internal
|
|
90
84
|
*
|
|
91
85
|
* Split from decodeU8a since this is specialized to 1 instance ... while we duplicate, this
|
|
92
86
|
* is all on the hot-path, so it is not great, however there is (some) method behind the madness
|
|
93
87
|
*/
|
|
94
|
-
|
|
95
|
-
|
|
96
88
|
function decodeU8aVec(registry, result, u8a, startAt, Type) {
|
|
97
89
|
const count = result.length;
|
|
98
90
|
let offset = startAt;
|
|
99
91
|
let i = 0;
|
|
100
|
-
|
|
101
92
|
try {
|
|
102
93
|
while (i < count) {
|
|
103
94
|
const value = new Type(registry, u8a.subarray(offset));
|
|
@@ -108,6 +99,5 @@ function decodeU8aVec(registry, result, u8a, startAt, Type) {
|
|
|
108
99
|
} catch (error) {
|
|
109
100
|
throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Type));
|
|
110
101
|
}
|
|
111
|
-
|
|
112
102
|
return [offset, offset - startAt];
|
|
113
103
|
}
|
package/cjs/utils/index.js
CHANGED
|
@@ -81,21 +81,12 @@ Object.defineProperty(exports, "typesToMap", {
|
|
|
81
81
|
return _typesToMap.typesToMap;
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
|
-
|
|
85
84
|
var _compareArray = require("./compareArray");
|
|
86
|
-
|
|
87
85
|
var _compareMap = require("./compareMap");
|
|
88
|
-
|
|
89
86
|
var _compareSet = require("./compareSet");
|
|
90
|
-
|
|
91
87
|
var _decodeU8a = require("./decodeU8a");
|
|
92
|
-
|
|
93
88
|
var _mapToTypeMap = require("./mapToTypeMap");
|
|
94
|
-
|
|
95
89
|
var _typeToConstructor = require("./typeToConstructor");
|
|
96
|
-
|
|
97
90
|
var _sanitize = require("./sanitize");
|
|
98
|
-
|
|
99
91
|
var _sortValues = require("./sortValues");
|
|
100
|
-
|
|
101
92
|
var _typesToMap = require("./typesToMap");
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.mapToTypeMap = mapToTypeMap;
|
|
7
|
-
|
|
8
7
|
var _typeToConstructor = require("./typeToConstructor");
|
|
9
|
-
|
|
10
8
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
11
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
10
|
|
|
@@ -17,11 +15,9 @@ function mapToTypeMap(registry, input) {
|
|
|
17
15
|
const entries = Object.entries(input);
|
|
18
16
|
const count = entries.length;
|
|
19
17
|
const output = [new Array(count), new Array(count)];
|
|
20
|
-
|
|
21
18
|
for (let i = 0; i < count; i++) {
|
|
22
19
|
output[1][i] = entries[i][0];
|
|
23
20
|
output[0][i] = (0, _typeToConstructor.typeToConstructor)(registry, entries[i][1]);
|
|
24
21
|
}
|
|
25
|
-
|
|
26
22
|
return output;
|
|
27
23
|
}
|
package/cjs/utils/sanitize.js
CHANGED
|
@@ -17,152 +17,148 @@ exports.sanitize = sanitize;
|
|
|
17
17
|
exports.trim = trim;
|
|
18
18
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
19
19
|
// SPDX-License-Identifier: Apache-2.0
|
|
20
|
+
|
|
20
21
|
const BOUNDED = ['BTreeMap', 'BTreeSet', 'HashMap', 'Vec'];
|
|
21
22
|
const ALLOWED_BOXES = BOUNDED.concat(['Compact', 'DoNotConstruct', 'Int', 'Linkage', 'Range', 'RangeInclusive', 'Result', 'Opaque', 'Option', 'UInt', 'WrapperKeepOpaque', 'WrapperOpaque']);
|
|
22
23
|
const BOX_PRECEDING = ['<', '(', '[', '"', ',', ' ']; // start of vec, tuple, fixed array, part of struct def or in tuple
|
|
23
24
|
|
|
24
|
-
const mappings = [
|
|
25
|
-
alias
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
25
|
+
const mappings = [
|
|
26
|
+
// alias <T::InherentOfflineReport as InherentOfflineReport>::Inherent -> InherentOfflineReport
|
|
27
|
+
alias('<T::InherentOfflineReport as InherentOfflineReport>::Inherent', 'InherentOfflineReport', false), alias('VecDeque<', 'Vec<', false),
|
|
28
|
+
// <T::Balance as HasCompact>
|
|
29
|
+
cleanupCompact(),
|
|
30
|
+
// Change BoundedVec<Type, Size> to Vec<Type>
|
|
31
|
+
removeExtensions('Bounded', true),
|
|
32
|
+
// Change WeakVec<Type> to Vec<Type>
|
|
33
|
+
removeExtensions('Weak', false),
|
|
34
|
+
// Remove all the trait prefixes
|
|
35
|
+
removeTraits(),
|
|
36
|
+
// remove PairOf<T> -> (T, T)
|
|
37
|
+
removePairOf(),
|
|
38
|
+
// remove boxing, `Box<Proposal>` -> `Proposal`
|
|
39
|
+
removeWrap('Box<'),
|
|
40
|
+
// remove generics, `MisbehaviorReport<Hash, BlockNumber>` -> `MisbehaviorReport`
|
|
41
|
+
removeGenerics(),
|
|
42
|
+
// alias String -> Text (compat with jsonrpc methods)
|
|
43
|
+
alias('String', 'Text'),
|
|
44
|
+
// alias Vec<u8> -> Bytes
|
|
45
|
+
alias('Vec<u8>', 'Bytes'), alias('&\\[u8\\]', 'Bytes'), alias("&'static\\[u8\\]", 'Bytes'),
|
|
46
|
+
// alias RawAddress -> Address
|
|
47
|
+
alias('RawAddress', 'Address'),
|
|
48
|
+
// lookups, mapped to Address/AccountId as appropriate in runtime
|
|
49
|
+
alias('Lookup::Source', 'LookupSource'), alias('Lookup::Target', 'LookupTarget'),
|
|
50
|
+
// HACK duplication between contracts & primitives, however contracts prefixed with exec
|
|
51
|
+
alias('exec::StorageKey', 'ContractStorageKey'),
|
|
52
|
+
// flattens tuples with one value, `(AccountId)` -> `AccountId`
|
|
53
|
+
flattenSingleTuple(),
|
|
54
|
+
// converts ::Type to Type, <T as Trait<I>>::Proposal -> Proposal
|
|
55
|
+
removeColons(),
|
|
56
|
+
// remove all trailing spaces - this should always be the last
|
|
57
|
+
trim()];
|
|
58
|
+
|
|
59
|
+
// given a string, trim it
|
|
42
60
|
function trim() {
|
|
43
61
|
return value => value.trim();
|
|
44
|
-
}
|
|
45
|
-
|
|
62
|
+
}
|
|
46
63
|
|
|
64
|
+
// given a starting index, find the closing >
|
|
47
65
|
function findClosing(value, start) {
|
|
48
66
|
let depth = 0;
|
|
49
|
-
|
|
50
67
|
for (let index = start; index < value.length; index++) {
|
|
51
68
|
if (value[index] === '>') {
|
|
52
69
|
if (!depth) {
|
|
53
70
|
return index;
|
|
54
71
|
}
|
|
55
|
-
|
|
56
72
|
depth--;
|
|
57
73
|
} else if (value[index] === '<') {
|
|
58
74
|
depth++;
|
|
59
75
|
}
|
|
60
76
|
}
|
|
61
|
-
|
|
62
77
|
throw new Error(`Unable to find closing matching <> on '${value}' (start ${start})`);
|
|
63
78
|
}
|
|
64
|
-
|
|
65
79
|
function alias(src, dest) {
|
|
66
80
|
let withChecks = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
67
81
|
const from = new RegExp(`(^${src}|${BOX_PRECEDING.map(box => `\\${box}${src}`).join('|')})`, 'g');
|
|
68
|
-
|
|
69
82
|
const to = src => {
|
|
70
83
|
from.lastIndex = 0;
|
|
71
84
|
return withChecks && BOX_PRECEDING.includes(src[0]) ? `${src[0]}${dest}` : dest;
|
|
72
85
|
};
|
|
73
|
-
|
|
74
86
|
return value => value.replace(from, to);
|
|
75
87
|
}
|
|
76
|
-
|
|
77
88
|
function cleanupCompact() {
|
|
78
89
|
return value => {
|
|
79
90
|
if (value.includes(' as HasCompact')) {
|
|
80
91
|
for (let index = 0; index < value.length; index++) {
|
|
81
92
|
if (value[index] === '<') {
|
|
82
93
|
const end = findClosing(value, index + 1) - 14;
|
|
83
|
-
|
|
84
94
|
if (value.substring(end, end + 14) === ' as HasCompact') {
|
|
85
95
|
value = `Compact<${value.substring(index + 1, end)}>`;
|
|
86
96
|
}
|
|
87
97
|
}
|
|
88
98
|
}
|
|
89
99
|
}
|
|
90
|
-
|
|
91
100
|
return value;
|
|
92
101
|
};
|
|
93
102
|
}
|
|
94
|
-
|
|
95
103
|
function flattenSingleTuple() {
|
|
96
104
|
const from1 = /,\)/g;
|
|
97
105
|
const from2 = /\(([^,]+)\)/;
|
|
98
106
|
return value => {
|
|
99
107
|
from1.lastIndex = 0;
|
|
100
|
-
return value
|
|
101
|
-
|
|
108
|
+
return value
|
|
109
|
+
// tuples may have trailing commas, e.g. (u32, BlockNumber, )
|
|
110
|
+
.replace(from1, ')')
|
|
111
|
+
// change (u32) -> u32
|
|
102
112
|
.replace(from2, '$1');
|
|
103
113
|
};
|
|
104
114
|
}
|
|
105
|
-
|
|
106
115
|
function replaceTagWith(value, matcher, replacer) {
|
|
107
116
|
let index = -1;
|
|
108
|
-
|
|
109
117
|
while (true) {
|
|
110
118
|
index = value.indexOf(matcher, index + 1);
|
|
111
|
-
|
|
112
119
|
if (index === -1) {
|
|
113
120
|
return value;
|
|
114
121
|
}
|
|
115
|
-
|
|
116
122
|
const start = index + matcher.length;
|
|
117
123
|
const end = findClosing(value, start);
|
|
118
124
|
value = `${value.substring(0, index)}${replacer(value.substring(start, end))}${value.substring(end + 1)}`;
|
|
119
125
|
}
|
|
120
|
-
}
|
|
121
|
-
|
|
126
|
+
}
|
|
122
127
|
|
|
128
|
+
// remove the Bounded* or Weak* wrappers
|
|
123
129
|
function removeExtensions(type, isSized) {
|
|
124
130
|
return value => {
|
|
125
131
|
for (let i = 0; i < BOUNDED.length; i++) {
|
|
126
132
|
const tag = BOUNDED[i];
|
|
127
133
|
value = replaceTagWith(value, `${type}${tag}<`, v => {
|
|
128
134
|
const parts = v.split(',').map(s => s.trim()).filter(s => s);
|
|
129
|
-
|
|
130
135
|
if (isSized) {
|
|
131
136
|
parts.pop();
|
|
132
137
|
}
|
|
133
|
-
|
|
134
138
|
return `${tag}<${parts.join(',')}>`;
|
|
135
139
|
});
|
|
136
140
|
}
|
|
137
|
-
|
|
138
141
|
return value;
|
|
139
142
|
};
|
|
140
143
|
}
|
|
141
|
-
|
|
142
144
|
function removeColons() {
|
|
143
145
|
return value => {
|
|
144
146
|
let index = 0;
|
|
145
|
-
|
|
146
147
|
while (index !== -1) {
|
|
147
148
|
index = value.indexOf('::');
|
|
148
|
-
|
|
149
149
|
if (index === 0) {
|
|
150
150
|
value = value.substring(2);
|
|
151
151
|
} else if (index !== -1) {
|
|
152
152
|
let start = index;
|
|
153
|
-
|
|
154
153
|
while (start !== -1 && !BOX_PRECEDING.includes(value[start])) {
|
|
155
154
|
start--;
|
|
156
155
|
}
|
|
157
|
-
|
|
158
156
|
value = `${value.substring(0, start + 1)}${value.substring(index + 2)}`;
|
|
159
157
|
}
|
|
160
158
|
}
|
|
161
|
-
|
|
162
159
|
return value;
|
|
163
160
|
};
|
|
164
161
|
}
|
|
165
|
-
|
|
166
162
|
function removeGenerics() {
|
|
167
163
|
return value => {
|
|
168
164
|
for (let index = 0; index < value.length; index++) {
|
|
@@ -170,29 +166,29 @@ function removeGenerics() {
|
|
|
170
166
|
// check against the allowed wrappers, be it Vec<..>, Option<...> ...
|
|
171
167
|
const box = ALLOWED_BOXES.find(box => {
|
|
172
168
|
const start = index - box.length;
|
|
173
|
-
return start >= 0 && value.substring(start, index) === box && (
|
|
169
|
+
return start >= 0 && value.substring(start, index) === box && (
|
|
170
|
+
// make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
|
|
174
171
|
start === 0 || BOX_PRECEDING.includes(value[start - 1]));
|
|
175
|
-
});
|
|
172
|
+
});
|
|
176
173
|
|
|
174
|
+
// we have not found anything, unwrap generic innards
|
|
177
175
|
if (!box) {
|
|
178
176
|
const end = findClosing(value, index + 1);
|
|
179
177
|
value = `${value.substring(0, index)}${value.substring(end + 1)}`;
|
|
180
178
|
}
|
|
181
179
|
}
|
|
182
180
|
}
|
|
183
|
-
|
|
184
181
|
return value;
|
|
185
182
|
};
|
|
186
|
-
}
|
|
187
|
-
|
|
183
|
+
}
|
|
188
184
|
|
|
185
|
+
// remove the PairOf wrappers
|
|
189
186
|
function removePairOf() {
|
|
190
187
|
const replacer = v => `(${v},${v})`;
|
|
191
|
-
|
|
192
188
|
return value => replaceTagWith(value, 'PairOf<', replacer);
|
|
193
|
-
}
|
|
194
|
-
|
|
189
|
+
}
|
|
195
190
|
|
|
191
|
+
// remove the type traits
|
|
196
192
|
function removeTraits() {
|
|
197
193
|
const from1 = /\s/g;
|
|
198
194
|
const from2 = /(T|Self)::/g;
|
|
@@ -207,39 +203,38 @@ function removeTraits() {
|
|
|
207
203
|
from4.lastIndex = 0;
|
|
208
204
|
from5.lastIndex = 0;
|
|
209
205
|
from6.lastIndex = 0;
|
|
210
|
-
return value
|
|
211
|
-
|
|
212
|
-
.replace(
|
|
213
|
-
|
|
214
|
-
.replace(
|
|
215
|
-
|
|
206
|
+
return value
|
|
207
|
+
// remove all whitespaces
|
|
208
|
+
.replace(from1, '')
|
|
209
|
+
// anything `T::<type>` to end up as `<type>`
|
|
210
|
+
.replace(from2, '')
|
|
211
|
+
// replace `<T as Trait>::` (whitespaces were removed above)
|
|
212
|
+
.replace(from3, '')
|
|
213
|
+
// replace `<T as something::Trait>::` (whitespaces were removed above)
|
|
214
|
+
.replace(from4, '')
|
|
215
|
+
// replace <Lookup as StaticLookup>
|
|
216
|
+
.replace(from5, 'Lookup')
|
|
217
|
+
// replace `<...>::Type`
|
|
216
218
|
.replace(from6, '');
|
|
217
219
|
};
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
+
}
|
|
220
221
|
|
|
222
|
+
// remove wrapping values, i.e. Box<Proposal> -> Proposal
|
|
221
223
|
function removeWrap(check) {
|
|
222
224
|
const replacer = v => v;
|
|
223
|
-
|
|
224
225
|
return value => replaceTagWith(value, check, replacer);
|
|
225
226
|
}
|
|
226
|
-
|
|
227
227
|
const sanitizeMap = new Map();
|
|
228
|
-
|
|
229
228
|
function sanitize(value) {
|
|
230
229
|
const startValue = value.toString();
|
|
231
230
|
const memoized = sanitizeMap.get(startValue);
|
|
232
|
-
|
|
233
231
|
if (memoized) {
|
|
234
232
|
return memoized;
|
|
235
233
|
}
|
|
236
|
-
|
|
237
234
|
let result = startValue;
|
|
238
|
-
|
|
239
235
|
for (let i = 0; i < mappings.length; i++) {
|
|
240
236
|
result = mappings[i](result);
|
|
241
237
|
}
|
|
242
|
-
|
|
243
238
|
sanitizeMap.set(startValue, result);
|
|
244
239
|
return result;
|
|
245
240
|
}
|
package/cjs/utils/sortValues.js
CHANGED
|
@@ -6,9 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.sortAsc = sortAsc;
|
|
7
7
|
exports.sortMap = sortMap;
|
|
8
8
|
exports.sortSet = sortSet;
|
|
9
|
-
|
|
10
9
|
var _util = require("@polkadot/util");
|
|
11
|
-
|
|
12
10
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
13
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
14
12
|
|
|
@@ -16,49 +14,41 @@ var _util = require("@polkadot/util");
|
|
|
16
14
|
function isArrayLike(arg) {
|
|
17
15
|
return arg instanceof Uint8Array || Array.isArray(arg);
|
|
18
16
|
}
|
|
19
|
-
/** @internal **/
|
|
20
|
-
|
|
21
17
|
|
|
18
|
+
/** @internal **/
|
|
22
19
|
function isCodec(arg) {
|
|
23
20
|
return (0, _util.isFunction)(arg && arg.toU8a);
|
|
24
21
|
}
|
|
25
|
-
/** @internal **/
|
|
26
|
-
|
|
27
22
|
|
|
23
|
+
/** @internal **/
|
|
28
24
|
function isEnum(arg) {
|
|
29
25
|
return isCodec(arg) && (0, _util.isNumber)(arg.index) && isCodec(arg.value);
|
|
30
26
|
}
|
|
31
|
-
/** @internal */
|
|
32
|
-
|
|
33
27
|
|
|
28
|
+
/** @internal */
|
|
34
29
|
function isNumberLike(arg) {
|
|
35
30
|
return (0, _util.isNumber)(arg) || (0, _util.isBn)(arg) || (0, _util.isBigInt)(arg);
|
|
36
31
|
}
|
|
37
|
-
/** @internal */
|
|
38
|
-
|
|
39
32
|
|
|
33
|
+
/** @internal */
|
|
40
34
|
function sortArray(a, b) {
|
|
41
35
|
// Vec, Tuple, Bytes etc.
|
|
42
36
|
let sortRes = 0;
|
|
43
37
|
const minLen = Math.min(a.length, b.length);
|
|
44
|
-
|
|
45
38
|
for (let i = 0; i < minLen; ++i) {
|
|
46
39
|
sortRes = sortAsc(a[i], b[i]);
|
|
47
|
-
|
|
48
40
|
if (sortRes !== 0) {
|
|
49
41
|
return sortRes;
|
|
50
42
|
}
|
|
51
43
|
}
|
|
52
|
-
|
|
53
44
|
return a.length - b.length;
|
|
54
45
|
}
|
|
46
|
+
|
|
55
47
|
/**
|
|
56
48
|
* Sort keys/values of BTreeSet/BTreeMap in ascending order for encoding compatibility with Rust's BTreeSet/BTreeMap
|
|
57
49
|
* (https://doc.rust-lang.org/stable/std/collections/struct.BTreeSet.html)
|
|
58
50
|
* (https://doc.rust-lang.org/stable/std/collections/struct.BTreeMap.html)
|
|
59
51
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
52
|
function sortAsc(a, b) {
|
|
63
53
|
if (isNumberLike(a) && isNumberLike(b)) {
|
|
64
54
|
return (0, _util.bnToBn)(a).cmp((0, _util.bnToBn)(b));
|
|
@@ -72,14 +62,11 @@ function sortAsc(a, b) {
|
|
|
72
62
|
// Text, Bool etc.
|
|
73
63
|
return sortAsc(a.toU8a(true), b.toU8a(true));
|
|
74
64
|
}
|
|
75
|
-
|
|
76
65
|
throw new Error(`Attempting to sort unrecognized values: ${(0, _util.stringify)(a)} (typeof ${typeof a}) <-> ${(0, _util.stringify)(b)} (typeof ${typeof b})`);
|
|
77
66
|
}
|
|
78
|
-
|
|
79
67
|
function sortSet(set) {
|
|
80
68
|
return new Set(Array.from(set).sort(sortAsc));
|
|
81
69
|
}
|
|
82
|
-
|
|
83
70
|
function sortMap(map) {
|
|
84
71
|
return new Map(Array.from(map.entries()).sort((_ref, _ref2) => {
|
|
85
72
|
let [keyA] = _ref;
|
|
@@ -4,11 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.typeToConstructor = typeToConstructor;
|
|
7
|
-
|
|
8
7
|
var _util = require("@polkadot/util");
|
|
9
|
-
|
|
10
8
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
11
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
10
|
+
|
|
12
11
|
function typeToConstructor(registry, type) {
|
|
13
12
|
return (0, _util.isString)(type) ? registry.createClassUnsafe(type) : type;
|
|
14
13
|
}
|
package/cjs/utils/typesToMap.js
CHANGED
|
@@ -4,16 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.typesToMap = typesToMap;
|
|
7
|
-
|
|
8
7
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
9
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
10
10
|
function typesToMap(registry, _ref) {
|
|
11
11
|
let [Types, keys] = _ref;
|
|
12
12
|
const result = {};
|
|
13
|
-
|
|
14
13
|
for (let i = 0; i < keys.length; i++) {
|
|
15
14
|
result[keys[i]] = registry.getClassName(Types[i]) || new Types[i](registry).toRawType();
|
|
16
15
|
}
|
|
17
|
-
|
|
18
16
|
return result;
|
|
19
17
|
}
|
package/cjs/utils/util.js
CHANGED
|
@@ -4,11 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.hasEq = hasEq;
|
|
7
|
-
|
|
8
7
|
var _util = require("@polkadot/util");
|
|
9
|
-
|
|
10
8
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
11
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
10
|
+
|
|
12
11
|
function hasEq(o) {
|
|
13
12
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
14
13
|
return (0, _util.isFunction)(o.eq);
|
package/detectOther.js
CHANGED
package/detectPackage.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
// Do not edit, auto-generated by @polkadot/dev
|
|
5
|
+
|
|
4
6
|
import { detectPackage } from '@polkadot/util';
|
|
5
7
|
import others from "./detectOther.js";
|
|
6
8
|
import { packageInfo } from "./packageInfo.js";
|
package/extended/BTreeMap.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { CodecMap } from "./Map.js";
|
|
4
5
|
export class BTreeMap extends CodecMap {
|
|
5
6
|
static with(keyType, valType) {
|
|
@@ -7,8 +8,6 @@ export class BTreeMap extends CodecMap {
|
|
|
7
8
|
constructor(registry, value) {
|
|
8
9
|
super(registry, keyType, valType, value, 'BTreeMap');
|
|
9
10
|
}
|
|
10
|
-
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
|
|
14
13
|
}
|