@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/cjs/base/Option.js
CHANGED
|
@@ -4,19 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Option = void 0;
|
|
7
|
-
|
|
8
7
|
var _util = require("@polkadot/util");
|
|
9
|
-
|
|
10
8
|
var _utils = require("../utils");
|
|
11
|
-
|
|
12
9
|
var _Null = require("./Null");
|
|
13
|
-
|
|
14
10
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
15
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
|
|
16
13
|
function noopSetDefinition(d) {
|
|
17
14
|
return d;
|
|
18
15
|
}
|
|
19
|
-
|
|
20
16
|
class None extends _Null.Null {
|
|
21
17
|
/**
|
|
22
18
|
* @description Returns the base runtime type name for this instance
|
|
@@ -24,11 +20,9 @@ class None extends _Null.Null {
|
|
|
24
20
|
toRawType() {
|
|
25
21
|
return 'None';
|
|
26
22
|
}
|
|
27
|
-
|
|
28
23
|
}
|
|
29
|
-
/** @internal */
|
|
30
|
-
|
|
31
24
|
|
|
25
|
+
/** @internal */
|
|
32
26
|
function decodeOption(registry, Type, value) {
|
|
33
27
|
if (value instanceof Type) {
|
|
34
28
|
// don't re-create, use as it (which also caters for derived types)
|
|
@@ -40,9 +34,9 @@ function decodeOption(registry, Type, value) {
|
|
|
40
34
|
} else if (value.isNone) {
|
|
41
35
|
// internal is None, we are also none
|
|
42
36
|
return new None(registry);
|
|
43
|
-
}
|
|
44
|
-
|
|
37
|
+
}
|
|
45
38
|
|
|
39
|
+
// convert the actual value into known
|
|
46
40
|
return new Type(registry, value.value);
|
|
47
41
|
} else if ((0, _util.isNull)(value) || (0, _util.isUndefined)(value) || value === '0x' || value instanceof None) {
|
|
48
42
|
// anyhting empty we pass as-is
|
|
@@ -52,9 +46,9 @@ function decodeOption(registry, Type, value) {
|
|
|
52
46
|
// may be an instance of it, so Type and Option checks go in first
|
|
53
47
|
return !value.length || value[0] === 0 ? new None(registry) : new Type(registry, value.subarray(1));
|
|
54
48
|
}
|
|
55
|
-
|
|
56
49
|
return new Type(registry, value);
|
|
57
50
|
}
|
|
51
|
+
|
|
58
52
|
/**
|
|
59
53
|
* @name Option
|
|
60
54
|
* @description
|
|
@@ -63,12 +57,9 @@ function decodeOption(registry, Type, value) {
|
|
|
63
57
|
* implements that - decodes, checks for optionality and wraps the required structure
|
|
64
58
|
* with a value if/as required/found.
|
|
65
59
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
60
|
class Option {
|
|
69
61
|
#Type;
|
|
70
62
|
#raw;
|
|
71
|
-
|
|
72
63
|
constructor(registry, typeName, value) {
|
|
73
64
|
let {
|
|
74
65
|
definition,
|
|
@@ -79,20 +70,16 @@ class Option {
|
|
|
79
70
|
this.registry = registry;
|
|
80
71
|
this.#Type = Type;
|
|
81
72
|
this.#raw = decoded;
|
|
82
|
-
|
|
83
73
|
if (decoded && decoded.initialU8aLength) {
|
|
84
74
|
this.initialU8aLength = 1 + decoded.initialU8aLength;
|
|
85
75
|
}
|
|
86
76
|
}
|
|
87
|
-
|
|
88
77
|
static with(Type) {
|
|
89
78
|
let definition;
|
|
90
|
-
|
|
91
79
|
const setDefinition = d => {
|
|
92
80
|
definition = d;
|
|
93
81
|
return d;
|
|
94
82
|
};
|
|
95
|
-
|
|
96
83
|
return class extends Option {
|
|
97
84
|
constructor(registry, value) {
|
|
98
85
|
super(registry, Type, value, {
|
|
@@ -100,82 +87,71 @@ class Option {
|
|
|
100
87
|
setDefinition
|
|
101
88
|
});
|
|
102
89
|
}
|
|
103
|
-
|
|
104
90
|
};
|
|
105
91
|
}
|
|
92
|
+
|
|
106
93
|
/**
|
|
107
94
|
* @description The length of the value when encoded as a Uint8Array
|
|
108
95
|
*/
|
|
109
|
-
|
|
110
|
-
|
|
111
96
|
get encodedLength() {
|
|
112
97
|
// boolean byte (has value, doesn't have) along with wrapped length
|
|
113
98
|
return 1 + this.#raw.encodedLength;
|
|
114
99
|
}
|
|
100
|
+
|
|
115
101
|
/**
|
|
116
102
|
* @description returns a hash of the contents
|
|
117
103
|
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
104
|
get hash() {
|
|
121
105
|
return this.registry.hash(this.toU8a());
|
|
122
106
|
}
|
|
107
|
+
|
|
123
108
|
/**
|
|
124
109
|
* @description Checks if the Option has no value
|
|
125
110
|
*/
|
|
126
|
-
|
|
127
|
-
|
|
128
111
|
get isEmpty() {
|
|
129
112
|
return this.isNone;
|
|
130
113
|
}
|
|
114
|
+
|
|
131
115
|
/**
|
|
132
116
|
* @description Checks if the Option has no value
|
|
133
117
|
*/
|
|
134
|
-
|
|
135
|
-
|
|
136
118
|
get isNone() {
|
|
137
119
|
return this.#raw instanceof None;
|
|
138
120
|
}
|
|
121
|
+
|
|
139
122
|
/**
|
|
140
123
|
* @description Checks if the Option has a value
|
|
141
124
|
*/
|
|
142
|
-
|
|
143
|
-
|
|
144
125
|
get isSome() {
|
|
145
126
|
return !this.isNone;
|
|
146
127
|
}
|
|
128
|
+
|
|
147
129
|
/**
|
|
148
130
|
* @description The actual value for the Option
|
|
149
131
|
*/
|
|
150
|
-
|
|
151
|
-
|
|
152
132
|
get value() {
|
|
153
133
|
return this.#raw;
|
|
154
134
|
}
|
|
135
|
+
|
|
155
136
|
/**
|
|
156
137
|
* @description Compares the value of the input to see if there is a match
|
|
157
138
|
*/
|
|
158
|
-
|
|
159
|
-
|
|
160
139
|
eq(other) {
|
|
161
140
|
if (other instanceof Option) {
|
|
162
141
|
return this.isSome === other.isSome && this.value.eq(other.value);
|
|
163
142
|
}
|
|
164
|
-
|
|
165
143
|
return this.value.eq(other);
|
|
166
144
|
}
|
|
145
|
+
|
|
167
146
|
/**
|
|
168
147
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
169
148
|
*/
|
|
170
|
-
|
|
171
|
-
|
|
172
149
|
inspect() {
|
|
173
150
|
if (this.isNone) {
|
|
174
151
|
return {
|
|
175
152
|
outer: [new Uint8Array([0])]
|
|
176
153
|
};
|
|
177
154
|
}
|
|
178
|
-
|
|
179
155
|
const {
|
|
180
156
|
inner,
|
|
181
157
|
outer = []
|
|
@@ -185,108 +161,92 @@ class Option {
|
|
|
185
161
|
outer: [new Uint8Array([1]), ...outer]
|
|
186
162
|
};
|
|
187
163
|
}
|
|
164
|
+
|
|
188
165
|
/**
|
|
189
166
|
* @description Returns a hex string representation of the value
|
|
190
167
|
*/
|
|
191
|
-
|
|
192
|
-
|
|
193
168
|
toHex() {
|
|
194
169
|
// This attempts to align with the JSON encoding - actually in this case
|
|
195
170
|
// the isSome value is correct, however the `isNone` may be problematic
|
|
196
171
|
return this.isNone ? '0x' : (0, _util.u8aToHex)(this.toU8a().subarray(1));
|
|
197
172
|
}
|
|
173
|
+
|
|
198
174
|
/**
|
|
199
175
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
200
176
|
*/
|
|
201
|
-
|
|
202
|
-
|
|
203
177
|
toHuman(isExtended) {
|
|
204
178
|
return this.#raw.toHuman(isExtended);
|
|
205
179
|
}
|
|
180
|
+
|
|
206
181
|
/**
|
|
207
182
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
208
183
|
*/
|
|
209
|
-
|
|
210
|
-
|
|
211
184
|
toJSON() {
|
|
212
185
|
return this.isNone ? null : this.#raw.toJSON();
|
|
213
186
|
}
|
|
187
|
+
|
|
214
188
|
/**
|
|
215
189
|
* @description Converts the value in a best-fit primitive form
|
|
216
190
|
*/
|
|
217
|
-
|
|
218
|
-
|
|
219
191
|
toPrimitive() {
|
|
220
192
|
return this.isNone ? null : this.#raw.toPrimitive();
|
|
221
193
|
}
|
|
194
|
+
|
|
222
195
|
/**
|
|
223
196
|
* @description Returns the base runtime type name for this instance
|
|
224
197
|
*/
|
|
225
|
-
|
|
226
|
-
|
|
227
198
|
toRawType(isBare) {
|
|
228
199
|
const wrapped = this.registry.getClassName(this.#Type) || new this.#Type(this.registry).toRawType();
|
|
229
200
|
return isBare ? wrapped : `Option<${wrapped}>`;
|
|
230
201
|
}
|
|
202
|
+
|
|
231
203
|
/**
|
|
232
204
|
* @description Returns the string representation of the value
|
|
233
205
|
*/
|
|
234
|
-
|
|
235
|
-
|
|
236
206
|
toString() {
|
|
237
207
|
return this.#raw.toString();
|
|
238
208
|
}
|
|
209
|
+
|
|
239
210
|
/**
|
|
240
211
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
241
212
|
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
242
213
|
*/
|
|
243
|
-
|
|
244
|
-
|
|
245
214
|
toU8a(isBare) {
|
|
246
215
|
if (isBare) {
|
|
247
216
|
return this.#raw.toU8a(true);
|
|
248
217
|
}
|
|
249
|
-
|
|
250
218
|
const u8a = new Uint8Array(this.encodedLength);
|
|
251
|
-
|
|
252
219
|
if (this.isSome) {
|
|
253
220
|
u8a.set([1]);
|
|
254
221
|
u8a.set(this.#raw.toU8a(), 1);
|
|
255
222
|
}
|
|
256
|
-
|
|
257
223
|
return u8a;
|
|
258
224
|
}
|
|
225
|
+
|
|
259
226
|
/**
|
|
260
227
|
* @description Returns the value that the Option represents (if available), throws if null
|
|
261
228
|
*/
|
|
262
|
-
|
|
263
|
-
|
|
264
229
|
unwrap() {
|
|
265
230
|
if (this.isNone) {
|
|
266
231
|
throw new Error('Option: unwrapping a None value');
|
|
267
232
|
}
|
|
268
|
-
|
|
269
233
|
return this.#raw;
|
|
270
234
|
}
|
|
235
|
+
|
|
271
236
|
/**
|
|
272
237
|
* @description Returns the value that the Option represents (if available) or defaultValue if none
|
|
273
238
|
* @param defaultValue The value to return if the option isNone
|
|
274
239
|
*/
|
|
275
|
-
|
|
276
|
-
|
|
277
240
|
unwrapOr(defaultValue) {
|
|
278
241
|
return this.isSome ? this.unwrap() : defaultValue;
|
|
279
242
|
}
|
|
243
|
+
|
|
280
244
|
/**
|
|
281
245
|
* @description Returns the value that the Option represents (if available) or defaultValue if none
|
|
282
246
|
* @param defaultValue The value to return if the option isNone
|
|
283
247
|
*/
|
|
284
|
-
|
|
285
|
-
|
|
286
248
|
unwrapOrDefault() {
|
|
287
249
|
return this.isSome ? this.unwrap() : new this.#Type(this.registry);
|
|
288
250
|
}
|
|
289
|
-
|
|
290
251
|
}
|
|
291
|
-
|
|
292
252
|
exports.Option = Option;
|
package/cjs/base/Result.js
CHANGED
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Result = void 0;
|
|
7
|
-
|
|
8
7
|
var _Enum = require("./Enum");
|
|
9
|
-
|
|
10
8
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
11
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
10
|
|
|
@@ -24,74 +22,61 @@ class Result extends _Enum.Enum {
|
|
|
24
22
|
Err
|
|
25
23
|
}, value);
|
|
26
24
|
}
|
|
27
|
-
|
|
28
25
|
static with(Types) {
|
|
29
26
|
return class extends Result {
|
|
30
27
|
constructor(registry, value) {
|
|
31
28
|
super(registry, Types.Ok, Types.Err, value);
|
|
32
29
|
}
|
|
33
|
-
|
|
34
30
|
};
|
|
35
31
|
}
|
|
32
|
+
|
|
36
33
|
/**
|
|
37
34
|
* @description Returns the wrapper Err value (if isErr)
|
|
38
35
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
36
|
get asErr() {
|
|
42
37
|
if (!this.isErr) {
|
|
43
38
|
throw new Error('Cannot extract Err value from Ok result, check isErr first');
|
|
44
39
|
}
|
|
45
|
-
|
|
46
40
|
return this.value;
|
|
47
41
|
}
|
|
42
|
+
|
|
48
43
|
/**
|
|
49
44
|
* @description Returns the wrapper Ok value (if isOk)
|
|
50
45
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
46
|
get asOk() {
|
|
54
47
|
if (!this.isOk) {
|
|
55
48
|
throw new Error('Cannot extract Ok value from Err result, check isOk first');
|
|
56
49
|
}
|
|
57
|
-
|
|
58
50
|
return this.value;
|
|
59
51
|
}
|
|
52
|
+
|
|
60
53
|
/**
|
|
61
54
|
* @description Checks if the Result has no value
|
|
62
55
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
56
|
get isEmpty() {
|
|
66
57
|
return this.isOk && this.value.isEmpty;
|
|
67
58
|
}
|
|
59
|
+
|
|
68
60
|
/**
|
|
69
61
|
* @description Checks if the Result wraps an Err value
|
|
70
62
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
63
|
get isErr() {
|
|
74
64
|
return !this.isOk;
|
|
75
65
|
}
|
|
66
|
+
|
|
76
67
|
/**
|
|
77
68
|
* @description Checks if the Result wraps an Ok value
|
|
78
69
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
70
|
get isOk() {
|
|
82
71
|
return this.index === 0;
|
|
83
72
|
}
|
|
73
|
+
|
|
84
74
|
/**
|
|
85
75
|
* @description Returns the base runtime type name for this instance
|
|
86
76
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
89
77
|
toRawType() {
|
|
90
78
|
const Types = this._toRawStruct();
|
|
91
|
-
|
|
92
79
|
return `Result<${Types.Ok},${Types.Err}>`;
|
|
93
80
|
}
|
|
94
|
-
|
|
95
81
|
}
|
|
96
|
-
|
|
97
82
|
exports.Result = Result;
|
package/cjs/base/Tuple.js
CHANGED
|
@@ -4,50 +4,41 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Tuple = void 0;
|
|
7
|
-
|
|
8
7
|
var _util = require("@polkadot/util");
|
|
9
|
-
|
|
10
8
|
var _Array = require("../abstract/Array");
|
|
11
|
-
|
|
12
9
|
var _utils = require("../utils");
|
|
13
|
-
|
|
14
10
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
15
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
|
|
16
13
|
function noopSetDefinition(d) {
|
|
17
14
|
return d;
|
|
18
15
|
}
|
|
19
|
-
/** @internal */
|
|
20
|
-
|
|
21
16
|
|
|
17
|
+
/** @internal */
|
|
22
18
|
function decodeTuple(registry, result, value, Classes) {
|
|
23
19
|
if ((0, _util.isU8a)(value) || (0, _util.isHex)(value)) {
|
|
24
20
|
return (0, _utils.decodeU8a)(registry, result, (0, _util.u8aToU8a)(value), Classes);
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
const Types = Classes[0];
|
|
28
|
-
|
|
29
23
|
for (let i = 0; i < Types.length; i++) {
|
|
30
24
|
try {
|
|
31
|
-
const entry = value
|
|
25
|
+
const entry = value == null ? void 0 : value[i];
|
|
32
26
|
result[i] = entry instanceof Types[i] ? entry : new Types[i](registry, entry);
|
|
33
27
|
} catch (error) {
|
|
34
28
|
throw new Error(`Tuple: failed on ${i}:: ${error.message}`);
|
|
35
29
|
}
|
|
36
30
|
}
|
|
37
|
-
|
|
38
31
|
return [result, 0];
|
|
39
32
|
}
|
|
33
|
+
|
|
40
34
|
/**
|
|
41
35
|
* @name Tuple
|
|
42
36
|
* @description
|
|
43
37
|
* A Tuple defines an anonymous fixed-length array, where each element has its
|
|
44
38
|
* own type. It extends the base JS `Array` object.
|
|
45
39
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
40
|
class Tuple extends _Array.AbstractArray {
|
|
49
41
|
#Types;
|
|
50
|
-
|
|
51
42
|
constructor(registry, Types, value) {
|
|
52
43
|
let {
|
|
53
44
|
definition,
|
|
@@ -58,12 +49,11 @@ class Tuple extends _Array.AbstractArray {
|
|
|
58
49
|
this.initialU8aLength = ((0, _util.isU8a)(value) ? (0, _utils.decodeU8a)(registry, this, value, Classes) : decodeTuple(registry, this, value, Classes))[1];
|
|
59
50
|
this.#Types = Classes;
|
|
60
51
|
}
|
|
61
|
-
|
|
62
52
|
static with(Types) {
|
|
63
|
-
let definition;
|
|
53
|
+
let definition;
|
|
64
54
|
|
|
55
|
+
// eslint-disable-next-line no-return-assign
|
|
65
56
|
const setDefinition = d => definition = d;
|
|
66
|
-
|
|
67
57
|
return class extends Tuple {
|
|
68
58
|
constructor(registry, value) {
|
|
69
59
|
super(registry, Types, value, {
|
|
@@ -71,69 +61,58 @@ class Tuple extends _Array.AbstractArray {
|
|
|
71
61
|
setDefinition
|
|
72
62
|
});
|
|
73
63
|
}
|
|
74
|
-
|
|
75
64
|
};
|
|
76
65
|
}
|
|
66
|
+
|
|
77
67
|
/**
|
|
78
68
|
* @description The length of the value when encoded as a Uint8Array
|
|
79
69
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
82
70
|
get encodedLength() {
|
|
83
71
|
let total = 0;
|
|
84
|
-
|
|
85
72
|
for (let i = 0; i < this.length; i++) {
|
|
86
73
|
total += this[i].encodedLength;
|
|
87
74
|
}
|
|
88
|
-
|
|
89
75
|
return total;
|
|
90
76
|
}
|
|
77
|
+
|
|
91
78
|
/**
|
|
92
79
|
* @description The types definition of the tuple
|
|
93
80
|
*/
|
|
94
|
-
|
|
95
|
-
|
|
96
81
|
get Types() {
|
|
97
82
|
return this.#Types[1].length ? this.#Types[1] : this.#Types[0].map(T => new T(this.registry).toRawType());
|
|
98
83
|
}
|
|
84
|
+
|
|
99
85
|
/**
|
|
100
86
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
101
87
|
*/
|
|
102
|
-
|
|
103
|
-
|
|
104
88
|
inspect() {
|
|
105
89
|
return {
|
|
106
90
|
inner: this.inspectInner()
|
|
107
91
|
};
|
|
108
92
|
}
|
|
93
|
+
|
|
109
94
|
/**
|
|
110
95
|
* @description Returns the base runtime type name for this instance
|
|
111
96
|
*/
|
|
112
|
-
|
|
113
|
-
|
|
114
97
|
toRawType() {
|
|
115
98
|
const types = this.#Types[0].map(T => this.registry.getClassName(T) || new T(this.registry).toRawType());
|
|
116
99
|
return `(${types.join(',')})`;
|
|
117
100
|
}
|
|
101
|
+
|
|
118
102
|
/**
|
|
119
103
|
* @description Returns the string representation of the value
|
|
120
104
|
*/
|
|
121
|
-
|
|
122
|
-
|
|
123
105
|
toString() {
|
|
124
106
|
// Overwrite the default toString representation of Array.
|
|
125
107
|
return (0, _util.stringify)(this.toJSON());
|
|
126
108
|
}
|
|
109
|
+
|
|
127
110
|
/**
|
|
128
111
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
129
112
|
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
130
113
|
*/
|
|
131
|
-
|
|
132
|
-
|
|
133
114
|
toU8a(isBare) {
|
|
134
115
|
return (0, _util.u8aConcatStrict)(this.toU8aInner(isBare));
|
|
135
116
|
}
|
|
136
|
-
|
|
137
117
|
}
|
|
138
|
-
|
|
139
118
|
exports.Tuple = Tuple;
|
package/cjs/base/UInt.js
CHANGED
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.UInt = void 0;
|
|
7
|
-
|
|
8
7
|
var _Int = require("../abstract/Int");
|
|
9
|
-
|
|
10
8
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
11
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
10
|
|
|
@@ -26,14 +24,10 @@ class UInt extends _Int.AbstractInt {
|
|
|
26
24
|
constructor(registry, value) {
|
|
27
25
|
super(registry, value, bitLength);
|
|
28
26
|
}
|
|
29
|
-
|
|
30
27
|
toRawType() {
|
|
31
28
|
return typeName || super.toRawType();
|
|
32
29
|
}
|
|
33
|
-
|
|
34
30
|
};
|
|
35
31
|
}
|
|
36
|
-
|
|
37
32
|
}
|
|
38
|
-
|
|
39
33
|
exports.UInt = UInt;
|
package/cjs/base/Vec.js
CHANGED
|
@@ -5,46 +5,35 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.Vec = void 0;
|
|
7
7
|
exports.decodeVec = decodeVec;
|
|
8
|
-
|
|
9
8
|
var _util = require("@polkadot/util");
|
|
10
|
-
|
|
11
9
|
var _Array = require("../abstract/Array");
|
|
12
|
-
|
|
13
10
|
var _utils = require("../utils");
|
|
14
|
-
|
|
15
11
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
16
12
|
// SPDX-License-Identifier: Apache-2.0
|
|
13
|
+
|
|
17
14
|
const MAX_LENGTH = 64 * 1024;
|
|
18
15
|
const l = (0, _util.logger)('Vec');
|
|
19
|
-
|
|
20
16
|
function noopSetDefinition(d) {
|
|
21
17
|
return d;
|
|
22
18
|
}
|
|
23
|
-
|
|
24
19
|
function decodeVecLength(value) {
|
|
25
20
|
if (Array.isArray(value)) {
|
|
26
21
|
return [value, value.length, 0];
|
|
27
22
|
}
|
|
28
|
-
|
|
29
23
|
const u8a = (0, _util.u8aToU8a)(value);
|
|
30
24
|
const [startAt, length] = (0, _util.compactFromU8aLim)(u8a);
|
|
31
|
-
|
|
32
25
|
if (length > MAX_LENGTH) {
|
|
33
26
|
throw new Error(`Vec length ${length.toString()} exceeds ${MAX_LENGTH}`);
|
|
34
27
|
}
|
|
35
|
-
|
|
36
28
|
return [u8a, length, startAt];
|
|
37
29
|
}
|
|
38
|
-
|
|
39
30
|
function decodeVec(registry, result, value, startAt, Type) {
|
|
40
31
|
if (Array.isArray(value)) {
|
|
41
32
|
const count = result.length;
|
|
42
|
-
|
|
43
33
|
for (let i = 0; i < count; i++) {
|
|
44
34
|
// 26/08/2022 this is actually a false positive - after recent eslint upgdates
|
|
45
35
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
46
36
|
const entry = value[i];
|
|
47
|
-
|
|
48
37
|
try {
|
|
49
38
|
result[i] = entry instanceof Type ? entry : new Type(registry, entry);
|
|
50
39
|
} catch (error) {
|
|
@@ -52,12 +41,11 @@ function decodeVec(registry, result, value, startAt, Type) {
|
|
|
52
41
|
throw error;
|
|
53
42
|
}
|
|
54
43
|
}
|
|
55
|
-
|
|
56
44
|
return [0, 0];
|
|
57
45
|
}
|
|
58
|
-
|
|
59
46
|
return (0, _utils.decodeU8aVec)(registry, result, (0, _util.u8aToU8a)(value), startAt, Type);
|
|
60
47
|
}
|
|
48
|
+
|
|
61
49
|
/**
|
|
62
50
|
* @name Vec
|
|
63
51
|
* @description
|
|
@@ -65,11 +53,8 @@ function decodeVec(registry, result, value, startAt, Type) {
|
|
|
65
53
|
* construction with the passed `Type` in the constructor. It is an extension to Array, providing
|
|
66
54
|
* specific encoding/decoding on top of the base type.
|
|
67
55
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
56
|
class Vec extends _Array.AbstractArray {
|
|
71
57
|
#Type;
|
|
72
|
-
|
|
73
58
|
constructor(registry, Type) {
|
|
74
59
|
let value = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
75
60
|
let {
|
|
@@ -81,12 +66,11 @@ class Vec extends _Array.AbstractArray {
|
|
|
81
66
|
this.#Type = definition || setDefinition((0, _utils.typeToConstructor)(registry, Type));
|
|
82
67
|
this.initialU8aLength = ((0, _util.isU8a)(decodeFrom) ? (0, _utils.decodeU8aVec)(registry, this, decodeFrom, startAt, this.#Type) : decodeVec(registry, this, decodeFrom, startAt, this.#Type))[0];
|
|
83
68
|
}
|
|
84
|
-
|
|
85
69
|
static with(Type) {
|
|
86
|
-
let definition;
|
|
70
|
+
let definition;
|
|
87
71
|
|
|
72
|
+
// eslint-disable-next-line no-return-assign
|
|
88
73
|
const setDefinition = d => definition = d;
|
|
89
|
-
|
|
90
74
|
return class extends Vec {
|
|
91
75
|
constructor(registry, value) {
|
|
92
76
|
super(registry, Type, value, {
|
|
@@ -94,43 +78,35 @@ class Vec extends _Array.AbstractArray {
|
|
|
94
78
|
setDefinition
|
|
95
79
|
});
|
|
96
80
|
}
|
|
97
|
-
|
|
98
81
|
};
|
|
99
82
|
}
|
|
83
|
+
|
|
100
84
|
/**
|
|
101
85
|
* @description The type for the items
|
|
102
86
|
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
87
|
get Type() {
|
|
106
88
|
return this.#Type.name;
|
|
107
89
|
}
|
|
90
|
+
|
|
108
91
|
/**
|
|
109
92
|
* @description Finds the index of the value in the array
|
|
110
93
|
*/
|
|
111
|
-
|
|
112
|
-
|
|
113
94
|
indexOf(_other) {
|
|
114
95
|
// convert type first, this removes overhead from the eq
|
|
115
96
|
const other = _other instanceof this.#Type ? _other : new this.#Type(this.registry, _other);
|
|
116
|
-
|
|
117
97
|
for (let i = 0; i < this.length; i++) {
|
|
118
98
|
if (other.eq(this[i])) {
|
|
119
99
|
return i;
|
|
120
100
|
}
|
|
121
101
|
}
|
|
122
|
-
|
|
123
102
|
return -1;
|
|
124
103
|
}
|
|
104
|
+
|
|
125
105
|
/**
|
|
126
106
|
* @description Returns the base runtime type name for this instance
|
|
127
107
|
*/
|
|
128
|
-
|
|
129
|
-
|
|
130
108
|
toRawType() {
|
|
131
109
|
return `Vec<${this.registry.getClassName(this.#Type) || new this.#Type(this.registry).toRawType()}>`;
|
|
132
110
|
}
|
|
133
|
-
|
|
134
111
|
}
|
|
135
|
-
|
|
136
112
|
exports.Vec = Vec;
|
package/cjs/base/VecAny.js
CHANGED
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.VecAny = void 0;
|
|
7
|
-
|
|
8
7
|
var _Array = require("../abstract/Array");
|
|
9
|
-
|
|
10
8
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
11
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
10
|
|
|
@@ -25,7 +23,5 @@ class VecAny extends _Array.AbstractArray {
|
|
|
25
23
|
// FIXME This is basically an any type, cannot instantiate via createType
|
|
26
24
|
return 'Vec<Codec>';
|
|
27
25
|
}
|
|
28
|
-
|
|
29
26
|
}
|
|
30
|
-
|
|
31
27
|
exports.VecAny = VecAny;
|