@polkadot/types-codec 9.5.1 → 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 +4 -4
- 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/utils/mapToTypeMap.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { typeToConstructor } from "./typeToConstructor.js";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* @description takes an input map of the form `{ [string]: string | CodecClass }` and returns a map of `{ [string]: CodecClass }`
|
|
6
8
|
*/
|
|
7
|
-
|
|
8
9
|
export function mapToTypeMap(registry, input) {
|
|
9
10
|
const entries = Object.entries(input);
|
|
10
11
|
const count = entries.length;
|
|
11
12
|
const output = [new Array(count), new Array(count)];
|
|
12
|
-
|
|
13
13
|
for (let i = 0; i < count; i++) {
|
|
14
14
|
output[1][i] = entries[i][0];
|
|
15
15
|
output[0][i] = typeToConstructor(registry, entries[i][1]);
|
|
16
16
|
}
|
|
17
|
-
|
|
18
17
|
return output;
|
|
19
18
|
}
|
package/utils/sanitize.js
CHANGED
|
@@ -1,56 +1,70 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
const BOUNDED = ['BTreeMap', 'BTreeSet', 'HashMap', 'Vec'];
|
|
4
5
|
const ALLOWED_BOXES = BOUNDED.concat(['Compact', 'DoNotConstruct', 'Int', 'Linkage', 'Range', 'RangeInclusive', 'Result', 'Opaque', 'Option', 'UInt', 'WrapperKeepOpaque', 'WrapperOpaque']);
|
|
5
6
|
const BOX_PRECEDING = ['<', '(', '[', '"', ',', ' ']; // start of vec, tuple, fixed array, part of struct def or in tuple
|
|
6
7
|
|
|
7
|
-
const mappings = [
|
|
8
|
-
alias
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
8
|
+
const mappings = [
|
|
9
|
+
// alias <T::InherentOfflineReport as InherentOfflineReport>::Inherent -> InherentOfflineReport
|
|
10
|
+
alias('<T::InherentOfflineReport as InherentOfflineReport>::Inherent', 'InherentOfflineReport', false), alias('VecDeque<', 'Vec<', false),
|
|
11
|
+
// <T::Balance as HasCompact>
|
|
12
|
+
cleanupCompact(),
|
|
13
|
+
// Change BoundedVec<Type, Size> to Vec<Type>
|
|
14
|
+
removeExtensions('Bounded', true),
|
|
15
|
+
// Change WeakVec<Type> to Vec<Type>
|
|
16
|
+
removeExtensions('Weak', false),
|
|
17
|
+
// Remove all the trait prefixes
|
|
18
|
+
removeTraits(),
|
|
19
|
+
// remove PairOf<T> -> (T, T)
|
|
20
|
+
removePairOf(),
|
|
21
|
+
// remove boxing, `Box<Proposal>` -> `Proposal`
|
|
22
|
+
removeWrap('Box<'),
|
|
23
|
+
// remove generics, `MisbehaviorReport<Hash, BlockNumber>` -> `MisbehaviorReport`
|
|
24
|
+
removeGenerics(),
|
|
25
|
+
// alias String -> Text (compat with jsonrpc methods)
|
|
26
|
+
alias('String', 'Text'),
|
|
27
|
+
// alias Vec<u8> -> Bytes
|
|
28
|
+
alias('Vec<u8>', 'Bytes'), alias('&\\[u8\\]', 'Bytes'), alias("&'static\\[u8\\]", 'Bytes'),
|
|
29
|
+
// alias RawAddress -> Address
|
|
30
|
+
alias('RawAddress', 'Address'),
|
|
31
|
+
// lookups, mapped to Address/AccountId as appropriate in runtime
|
|
32
|
+
alias('Lookup::Source', 'LookupSource'), alias('Lookup::Target', 'LookupTarget'),
|
|
33
|
+
// HACK duplication between contracts & primitives, however contracts prefixed with exec
|
|
34
|
+
alias('exec::StorageKey', 'ContractStorageKey'),
|
|
35
|
+
// flattens tuples with one value, `(AccountId)` -> `AccountId`
|
|
36
|
+
flattenSingleTuple(),
|
|
37
|
+
// converts ::Type to Type, <T as Trait<I>>::Proposal -> Proposal
|
|
38
|
+
removeColons(),
|
|
39
|
+
// remove all trailing spaces - this should always be the last
|
|
40
|
+
trim()];
|
|
41
|
+
|
|
42
|
+
// given a string, trim it
|
|
25
43
|
export function trim() {
|
|
26
44
|
return value => value.trim();
|
|
27
|
-
}
|
|
45
|
+
}
|
|
28
46
|
|
|
47
|
+
// given a starting index, find the closing >
|
|
29
48
|
export function findClosing(value, start) {
|
|
30
49
|
let depth = 0;
|
|
31
|
-
|
|
32
50
|
for (let index = start; index < value.length; index++) {
|
|
33
51
|
if (value[index] === '>') {
|
|
34
52
|
if (!depth) {
|
|
35
53
|
return index;
|
|
36
54
|
}
|
|
37
|
-
|
|
38
55
|
depth--;
|
|
39
56
|
} else if (value[index] === '<') {
|
|
40
57
|
depth++;
|
|
41
58
|
}
|
|
42
59
|
}
|
|
43
|
-
|
|
44
60
|
throw new Error(`Unable to find closing matching <> on '${value}' (start ${start})`);
|
|
45
61
|
}
|
|
46
62
|
export function alias(src, dest, withChecks = true) {
|
|
47
63
|
const from = new RegExp(`(^${src}|${BOX_PRECEDING.map(box => `\\${box}${src}`).join('|')})`, 'g');
|
|
48
|
-
|
|
49
64
|
const to = src => {
|
|
50
65
|
from.lastIndex = 0;
|
|
51
66
|
return withChecks && BOX_PRECEDING.includes(src[0]) ? `${src[0]}${dest}` : dest;
|
|
52
67
|
};
|
|
53
|
-
|
|
54
68
|
return value => value.replace(from, to);
|
|
55
69
|
}
|
|
56
70
|
export function cleanupCompact() {
|
|
@@ -59,14 +73,12 @@ export function cleanupCompact() {
|
|
|
59
73
|
for (let index = 0; index < value.length; index++) {
|
|
60
74
|
if (value[index] === '<') {
|
|
61
75
|
const end = findClosing(value, index + 1) - 14;
|
|
62
|
-
|
|
63
76
|
if (value.substring(end, end + 14) === ' as HasCompact') {
|
|
64
77
|
value = `Compact<${value.substring(index + 1, end)}>`;
|
|
65
78
|
}
|
|
66
79
|
}
|
|
67
80
|
}
|
|
68
81
|
}
|
|
69
|
-
|
|
70
82
|
return value;
|
|
71
83
|
};
|
|
72
84
|
}
|
|
@@ -75,67 +87,57 @@ export function flattenSingleTuple() {
|
|
|
75
87
|
const from2 = /\(([^,]+)\)/;
|
|
76
88
|
return value => {
|
|
77
89
|
from1.lastIndex = 0;
|
|
78
|
-
return value
|
|
79
|
-
|
|
90
|
+
return value
|
|
91
|
+
// tuples may have trailing commas, e.g. (u32, BlockNumber, )
|
|
92
|
+
.replace(from1, ')')
|
|
93
|
+
// change (u32) -> u32
|
|
80
94
|
.replace(from2, '$1');
|
|
81
95
|
};
|
|
82
96
|
}
|
|
83
|
-
|
|
84
97
|
function replaceTagWith(value, matcher, replacer) {
|
|
85
98
|
let index = -1;
|
|
86
|
-
|
|
87
99
|
while (true) {
|
|
88
100
|
index = value.indexOf(matcher, index + 1);
|
|
89
|
-
|
|
90
101
|
if (index === -1) {
|
|
91
102
|
return value;
|
|
92
103
|
}
|
|
93
|
-
|
|
94
104
|
const start = index + matcher.length;
|
|
95
105
|
const end = findClosing(value, start);
|
|
96
106
|
value = `${value.substring(0, index)}${replacer(value.substring(start, end))}${value.substring(end + 1)}`;
|
|
97
107
|
}
|
|
98
|
-
}
|
|
99
|
-
|
|
108
|
+
}
|
|
100
109
|
|
|
110
|
+
// remove the Bounded* or Weak* wrappers
|
|
101
111
|
export function removeExtensions(type, isSized) {
|
|
102
112
|
return value => {
|
|
103
113
|
for (let i = 0; i < BOUNDED.length; i++) {
|
|
104
114
|
const tag = BOUNDED[i];
|
|
105
115
|
value = replaceTagWith(value, `${type}${tag}<`, v => {
|
|
106
116
|
const parts = v.split(',').map(s => s.trim()).filter(s => s);
|
|
107
|
-
|
|
108
117
|
if (isSized) {
|
|
109
118
|
parts.pop();
|
|
110
119
|
}
|
|
111
|
-
|
|
112
120
|
return `${tag}<${parts.join(',')}>`;
|
|
113
121
|
});
|
|
114
122
|
}
|
|
115
|
-
|
|
116
123
|
return value;
|
|
117
124
|
};
|
|
118
125
|
}
|
|
119
126
|
export function removeColons() {
|
|
120
127
|
return value => {
|
|
121
128
|
let index = 0;
|
|
122
|
-
|
|
123
129
|
while (index !== -1) {
|
|
124
130
|
index = value.indexOf('::');
|
|
125
|
-
|
|
126
131
|
if (index === 0) {
|
|
127
132
|
value = value.substring(2);
|
|
128
133
|
} else if (index !== -1) {
|
|
129
134
|
let start = index;
|
|
130
|
-
|
|
131
135
|
while (start !== -1 && !BOX_PRECEDING.includes(value[start])) {
|
|
132
136
|
start--;
|
|
133
137
|
}
|
|
134
|
-
|
|
135
138
|
value = `${value.substring(0, start + 1)}${value.substring(index + 2)}`;
|
|
136
139
|
}
|
|
137
140
|
}
|
|
138
|
-
|
|
139
141
|
return value;
|
|
140
142
|
};
|
|
141
143
|
}
|
|
@@ -146,27 +148,29 @@ export function removeGenerics() {
|
|
|
146
148
|
// check against the allowed wrappers, be it Vec<..>, Option<...> ...
|
|
147
149
|
const box = ALLOWED_BOXES.find(box => {
|
|
148
150
|
const start = index - box.length;
|
|
149
|
-
return start >= 0 && value.substring(start, index) === box && (
|
|
151
|
+
return start >= 0 && value.substring(start, index) === box && (
|
|
152
|
+
// make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
|
|
150
153
|
start === 0 || BOX_PRECEDING.includes(value[start - 1]));
|
|
151
|
-
});
|
|
154
|
+
});
|
|
152
155
|
|
|
156
|
+
// we have not found anything, unwrap generic innards
|
|
153
157
|
if (!box) {
|
|
154
158
|
const end = findClosing(value, index + 1);
|
|
155
159
|
value = `${value.substring(0, index)}${value.substring(end + 1)}`;
|
|
156
160
|
}
|
|
157
161
|
}
|
|
158
162
|
}
|
|
159
|
-
|
|
160
163
|
return value;
|
|
161
164
|
};
|
|
162
|
-
}
|
|
165
|
+
}
|
|
163
166
|
|
|
167
|
+
// remove the PairOf wrappers
|
|
164
168
|
export function removePairOf() {
|
|
165
169
|
const replacer = v => `(${v},${v})`;
|
|
166
|
-
|
|
167
170
|
return value => replaceTagWith(value, 'PairOf<', replacer);
|
|
168
|
-
}
|
|
171
|
+
}
|
|
169
172
|
|
|
173
|
+
// remove the type traits
|
|
170
174
|
export function removeTraits() {
|
|
171
175
|
const from1 = /\s/g;
|
|
172
176
|
const from2 = /(T|Self)::/g;
|
|
@@ -181,36 +185,38 @@ export function removeTraits() {
|
|
|
181
185
|
from4.lastIndex = 0;
|
|
182
186
|
from5.lastIndex = 0;
|
|
183
187
|
from6.lastIndex = 0;
|
|
184
|
-
return value
|
|
185
|
-
|
|
186
|
-
.replace(
|
|
187
|
-
|
|
188
|
-
.replace(
|
|
189
|
-
|
|
188
|
+
return value
|
|
189
|
+
// remove all whitespaces
|
|
190
|
+
.replace(from1, '')
|
|
191
|
+
// anything `T::<type>` to end up as `<type>`
|
|
192
|
+
.replace(from2, '')
|
|
193
|
+
// replace `<T as Trait>::` (whitespaces were removed above)
|
|
194
|
+
.replace(from3, '')
|
|
195
|
+
// replace `<T as something::Trait>::` (whitespaces were removed above)
|
|
196
|
+
.replace(from4, '')
|
|
197
|
+
// replace <Lookup as StaticLookup>
|
|
198
|
+
.replace(from5, 'Lookup')
|
|
199
|
+
// replace `<...>::Type`
|
|
190
200
|
.replace(from6, '');
|
|
191
201
|
};
|
|
192
|
-
}
|
|
202
|
+
}
|
|
193
203
|
|
|
204
|
+
// remove wrapping values, i.e. Box<Proposal> -> Proposal
|
|
194
205
|
export function removeWrap(check) {
|
|
195
206
|
const replacer = v => v;
|
|
196
|
-
|
|
197
207
|
return value => replaceTagWith(value, check, replacer);
|
|
198
208
|
}
|
|
199
209
|
const sanitizeMap = new Map();
|
|
200
210
|
export function sanitize(value) {
|
|
201
211
|
const startValue = value.toString();
|
|
202
212
|
const memoized = sanitizeMap.get(startValue);
|
|
203
|
-
|
|
204
213
|
if (memoized) {
|
|
205
214
|
return memoized;
|
|
206
215
|
}
|
|
207
|
-
|
|
208
216
|
let result = startValue;
|
|
209
|
-
|
|
210
217
|
for (let i = 0; i < mappings.length; i++) {
|
|
211
218
|
result = mappings[i](result);
|
|
212
219
|
}
|
|
213
|
-
|
|
214
220
|
sanitizeMap.set(startValue, result);
|
|
215
221
|
return result;
|
|
216
222
|
}
|
package/utils/sortValues.js
CHANGED
|
@@ -1,54 +1,46 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { bnToBn, isBigInt, isBn, isFunction, isNumber, stringify } from '@polkadot/util';
|
|
4
3
|
|
|
4
|
+
import { bnToBn, isBigInt, isBn, isFunction, isNumber, stringify } from '@polkadot/util';
|
|
5
5
|
/** @internal **/
|
|
6
6
|
function isArrayLike(arg) {
|
|
7
7
|
return arg instanceof Uint8Array || Array.isArray(arg);
|
|
8
8
|
}
|
|
9
|
-
/** @internal **/
|
|
10
|
-
|
|
11
9
|
|
|
10
|
+
/** @internal **/
|
|
12
11
|
function isCodec(arg) {
|
|
13
12
|
return isFunction(arg && arg.toU8a);
|
|
14
13
|
}
|
|
15
|
-
/** @internal **/
|
|
16
|
-
|
|
17
14
|
|
|
15
|
+
/** @internal **/
|
|
18
16
|
function isEnum(arg) {
|
|
19
17
|
return isCodec(arg) && isNumber(arg.index) && isCodec(arg.value);
|
|
20
18
|
}
|
|
21
|
-
/** @internal */
|
|
22
|
-
|
|
23
19
|
|
|
20
|
+
/** @internal */
|
|
24
21
|
function isNumberLike(arg) {
|
|
25
22
|
return isNumber(arg) || isBn(arg) || isBigInt(arg);
|
|
26
23
|
}
|
|
27
|
-
/** @internal */
|
|
28
|
-
|
|
29
24
|
|
|
25
|
+
/** @internal */
|
|
30
26
|
function sortArray(a, b) {
|
|
31
27
|
// Vec, Tuple, Bytes etc.
|
|
32
28
|
let sortRes = 0;
|
|
33
29
|
const minLen = Math.min(a.length, b.length);
|
|
34
|
-
|
|
35
30
|
for (let i = 0; i < minLen; ++i) {
|
|
36
31
|
sortRes = sortAsc(a[i], b[i]);
|
|
37
|
-
|
|
38
32
|
if (sortRes !== 0) {
|
|
39
33
|
return sortRes;
|
|
40
34
|
}
|
|
41
35
|
}
|
|
42
|
-
|
|
43
36
|
return a.length - b.length;
|
|
44
37
|
}
|
|
38
|
+
|
|
45
39
|
/**
|
|
46
40
|
* Sort keys/values of BTreeSet/BTreeMap in ascending order for encoding compatibility with Rust's BTreeSet/BTreeMap
|
|
47
41
|
* (https://doc.rust-lang.org/stable/std/collections/struct.BTreeSet.html)
|
|
48
42
|
* (https://doc.rust-lang.org/stable/std/collections/struct.BTreeMap.html)
|
|
49
43
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
44
|
export function sortAsc(a, b) {
|
|
53
45
|
if (isNumberLike(a) && isNumberLike(b)) {
|
|
54
46
|
return bnToBn(a).cmp(bnToBn(b));
|
|
@@ -62,7 +54,6 @@ export function sortAsc(a, b) {
|
|
|
62
54
|
// Text, Bool etc.
|
|
63
55
|
return sortAsc(a.toU8a(true), b.toU8a(true));
|
|
64
56
|
}
|
|
65
|
-
|
|
66
57
|
throw new Error(`Attempting to sort unrecognized values: ${stringify(a)} (typeof ${typeof a}) <-> ${stringify(b)} (typeof ${typeof b})`);
|
|
67
58
|
}
|
|
68
59
|
export function sortSet(set) {
|
|
@@ -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 { isString } from '@polkadot/util';
|
|
4
5
|
export function typeToConstructor(registry, type) {
|
|
5
6
|
return isString(type) ? registry.createClassUnsafe(type) : type;
|
package/utils/typesToMap.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
export function typesToMap(registry, [Types, keys]) {
|
|
4
5
|
const result = {};
|
|
5
|
-
|
|
6
6
|
for (let i = 0; i < keys.length; i++) {
|
|
7
7
|
result[keys[i]] = registry.getClassName(Types[i]) || new Types[i](registry).toRawType();
|
|
8
8
|
}
|
|
9
|
-
|
|
10
9
|
return result;
|
|
11
10
|
}
|
package/utils/util.js
CHANGED