@polkadot/types-codec 7.4.2-9 → 7.5.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/AbstractArray.js +0 -4
- package/abstract/AbstractInt.js +10 -24
- package/base/Base.js +15 -29
- package/base/Compact.js +20 -34
- package/base/DoNotConstruct.js +14 -23
- package/base/Enum.js +36 -70
- package/base/Null.js +2 -3
- package/base/Option.js +19 -37
- package/base/Tuple.js +5 -11
- package/base/Vec.js +6 -12
- package/base/VecFixed.js +4 -10
- package/extended/BTreeSet.js +4 -13
- package/extended/BitVec.js +5 -11
- package/extended/Map.js +8 -27
- package/extended/Range.js +4 -10
- package/extended/WrapperKeepOpaque.js +10 -21
- package/native/Bool.js +0 -2
- package/native/Date.js +0 -2
- package/native/Json.js +0 -2
- package/native/Raw.js +0 -3
- package/native/Set.js +18 -32
- package/native/Struct.js +12 -30
- package/native/Text.js +7 -20
- package/package.json +2 -2
- package/packageInfo.cjs +1 -1
- package/packageInfo.js +1 -1
- package/primitive/I128.js +2 -5
- package/primitive/I16.js +2 -5
- package/primitive/I256.js +2 -5
- package/primitive/I32.js +2 -5
- package/primitive/I64.js +2 -5
- package/primitive/I8.js +2 -5
- package/primitive/U128.js +2 -5
- package/primitive/U16.js +2 -5
- package/primitive/U256.js +2 -5
- package/primitive/U32.js +2 -5
- package/primitive/U64.js +2 -5
- package/primitive/U8.js +2 -5
package/base/Enum.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
-
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
4
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
3
|
import { assert, isHex, isNumber, isObject, isString, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, stringPascalCase, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
|
|
@@ -126,47 +124,15 @@ function decodeEnum(registry, def, value, index) {
|
|
|
126
124
|
*/
|
|
127
125
|
|
|
128
126
|
|
|
129
|
-
var _def2 = /*#__PURE__*/_classPrivateFieldLooseKey("def");
|
|
130
|
-
|
|
131
|
-
var _entryIndex = /*#__PURE__*/_classPrivateFieldLooseKey("entryIndex");
|
|
132
|
-
|
|
133
|
-
var _indexes = /*#__PURE__*/_classPrivateFieldLooseKey("indexes");
|
|
134
|
-
|
|
135
|
-
var _isBasic = /*#__PURE__*/_classPrivateFieldLooseKey("isBasic");
|
|
136
|
-
|
|
137
|
-
var _isIndexed = /*#__PURE__*/_classPrivateFieldLooseKey("isIndexed");
|
|
138
|
-
|
|
139
|
-
var _raw = /*#__PURE__*/_classPrivateFieldLooseKey("raw");
|
|
140
|
-
|
|
141
127
|
export class Enum {
|
|
128
|
+
#def;
|
|
129
|
+
#entryIndex;
|
|
130
|
+
#indexes;
|
|
131
|
+
#isBasic;
|
|
132
|
+
#isIndexed;
|
|
133
|
+
#raw;
|
|
134
|
+
|
|
142
135
|
constructor(registry, Types, value, index) {
|
|
143
|
-
this.registry = void 0;
|
|
144
|
-
this.createdAtHash = void 0;
|
|
145
|
-
Object.defineProperty(this, _def2, {
|
|
146
|
-
writable: true,
|
|
147
|
-
value: void 0
|
|
148
|
-
});
|
|
149
|
-
Object.defineProperty(this, _entryIndex, {
|
|
150
|
-
writable: true,
|
|
151
|
-
value: void 0
|
|
152
|
-
});
|
|
153
|
-
this.initialU8aLength = void 0;
|
|
154
|
-
Object.defineProperty(this, _indexes, {
|
|
155
|
-
writable: true,
|
|
156
|
-
value: void 0
|
|
157
|
-
});
|
|
158
|
-
Object.defineProperty(this, _isBasic, {
|
|
159
|
-
writable: true,
|
|
160
|
-
value: void 0
|
|
161
|
-
});
|
|
162
|
-
Object.defineProperty(this, _isIndexed, {
|
|
163
|
-
writable: true,
|
|
164
|
-
value: void 0
|
|
165
|
-
});
|
|
166
|
-
Object.defineProperty(this, _raw, {
|
|
167
|
-
writable: true,
|
|
168
|
-
value: void 0
|
|
169
|
-
});
|
|
170
136
|
const {
|
|
171
137
|
def,
|
|
172
138
|
isBasic,
|
|
@@ -175,17 +141,17 @@ export class Enum {
|
|
|
175
141
|
|
|
176
142
|
const decoded = isU8a(value) && value.length && !isNumber(index) ? createFromValue(registry, def, value[0], value.subarray(1)) : decodeEnum(registry, def, value, index);
|
|
177
143
|
this.registry = registry;
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
144
|
+
this.#def = def;
|
|
145
|
+
this.#isBasic = isBasic;
|
|
146
|
+
this.#isIndexed = isIndexed;
|
|
147
|
+
this.#indexes = Object.values(def).map(({
|
|
182
148
|
index
|
|
183
149
|
}) => index);
|
|
184
|
-
|
|
185
|
-
|
|
150
|
+
this.#entryIndex = this.#indexes.indexOf(decoded.index) || 0;
|
|
151
|
+
this.#raw = decoded.value;
|
|
186
152
|
|
|
187
|
-
if (
|
|
188
|
-
this.initialU8aLength = 1 +
|
|
153
|
+
if (this.#raw.initialU8aLength) {
|
|
154
|
+
this.initialU8aLength = 1 + this.#raw.initialU8aLength;
|
|
189
155
|
}
|
|
190
156
|
}
|
|
191
157
|
|
|
@@ -218,7 +184,7 @@ export class Enum {
|
|
|
218
184
|
|
|
219
185
|
|
|
220
186
|
get encodedLength() {
|
|
221
|
-
return 1 +
|
|
187
|
+
return 1 + this.#raw.encodedLength;
|
|
222
188
|
}
|
|
223
189
|
/**
|
|
224
190
|
* @description returns a hash of the contents
|
|
@@ -234,7 +200,7 @@ export class Enum {
|
|
|
234
200
|
|
|
235
201
|
|
|
236
202
|
get index() {
|
|
237
|
-
return
|
|
203
|
+
return this.#indexes[this.#entryIndex];
|
|
238
204
|
}
|
|
239
205
|
/**
|
|
240
206
|
* @description The value of the enum
|
|
@@ -242,7 +208,7 @@ export class Enum {
|
|
|
242
208
|
|
|
243
209
|
|
|
244
210
|
get inner() {
|
|
245
|
-
return
|
|
211
|
+
return this.#raw;
|
|
246
212
|
}
|
|
247
213
|
/**
|
|
248
214
|
* @description true if this is a basic enum (no values)
|
|
@@ -250,7 +216,7 @@ export class Enum {
|
|
|
250
216
|
|
|
251
217
|
|
|
252
218
|
get isBasic() {
|
|
253
|
-
return
|
|
219
|
+
return this.#isBasic;
|
|
254
220
|
}
|
|
255
221
|
/**
|
|
256
222
|
* @description Checks if the value is an empty value
|
|
@@ -258,7 +224,7 @@ export class Enum {
|
|
|
258
224
|
|
|
259
225
|
|
|
260
226
|
get isEmpty() {
|
|
261
|
-
return
|
|
227
|
+
return this.#raw.isEmpty;
|
|
262
228
|
}
|
|
263
229
|
/**
|
|
264
230
|
* @description Checks if the Enum points to a [[Null]] type
|
|
@@ -266,7 +232,7 @@ export class Enum {
|
|
|
266
232
|
|
|
267
233
|
|
|
268
234
|
get isNone() {
|
|
269
|
-
return
|
|
235
|
+
return this.#raw instanceof Null;
|
|
270
236
|
}
|
|
271
237
|
/**
|
|
272
238
|
* @description Checks if the Enum points to a [[Null]] type
|
|
@@ -275,7 +241,7 @@ export class Enum {
|
|
|
275
241
|
|
|
276
242
|
|
|
277
243
|
get isNull() {
|
|
278
|
-
return
|
|
244
|
+
return this.#raw instanceof Null;
|
|
279
245
|
}
|
|
280
246
|
/**
|
|
281
247
|
* @description The available keys for this enum
|
|
@@ -283,7 +249,7 @@ export class Enum {
|
|
|
283
249
|
|
|
284
250
|
|
|
285
251
|
get defIndexes() {
|
|
286
|
-
return
|
|
252
|
+
return this.#indexes;
|
|
287
253
|
}
|
|
288
254
|
/**
|
|
289
255
|
* @description The available keys for this enum
|
|
@@ -291,7 +257,7 @@ export class Enum {
|
|
|
291
257
|
|
|
292
258
|
|
|
293
259
|
get defKeys() {
|
|
294
|
-
return Object.keys(
|
|
260
|
+
return Object.keys(this.#def);
|
|
295
261
|
}
|
|
296
262
|
/**
|
|
297
263
|
* @description The name of the type this enum value represents
|
|
@@ -299,7 +265,7 @@ export class Enum {
|
|
|
299
265
|
|
|
300
266
|
|
|
301
267
|
get type() {
|
|
302
|
-
return this.defKeys[
|
|
268
|
+
return this.defKeys[this.#entryIndex];
|
|
303
269
|
}
|
|
304
270
|
/**
|
|
305
271
|
* @description The value of the enum
|
|
@@ -307,7 +273,7 @@ export class Enum {
|
|
|
307
273
|
|
|
308
274
|
|
|
309
275
|
get value() {
|
|
310
|
-
return
|
|
276
|
+
return this.#raw;
|
|
311
277
|
}
|
|
312
278
|
/**
|
|
313
279
|
* @description Compares the value of the input to see if there is a match
|
|
@@ -320,7 +286,7 @@ export class Enum {
|
|
|
320
286
|
return !this.toU8a().some((entry, index) => entry !== other[index]);
|
|
321
287
|
} else if (isNumber(other)) {
|
|
322
288
|
return this.toNumber() === other;
|
|
323
|
-
} else if (
|
|
289
|
+
} else if (this.#isBasic && isString(other)) {
|
|
324
290
|
return this.type === other;
|
|
325
291
|
} else if (isHex(other)) {
|
|
326
292
|
return this.toHex() === other;
|
|
@@ -347,8 +313,8 @@ export class Enum {
|
|
|
347
313
|
|
|
348
314
|
|
|
349
315
|
toHuman(isExtended) {
|
|
350
|
-
return
|
|
351
|
-
[this.type]:
|
|
316
|
+
return this.#isBasic || this.isNone ? this.type : {
|
|
317
|
+
[this.type]: this.#raw.toHuman(isExtended)
|
|
352
318
|
};
|
|
353
319
|
}
|
|
354
320
|
/**
|
|
@@ -357,8 +323,8 @@ export class Enum {
|
|
|
357
323
|
|
|
358
324
|
|
|
359
325
|
toJSON() {
|
|
360
|
-
return
|
|
361
|
-
[stringCamelCase(this.type)]:
|
|
326
|
+
return this.#isBasic ? this.type : {
|
|
327
|
+
[stringCamelCase(this.type)]: this.#raw.toJSON()
|
|
362
328
|
};
|
|
363
329
|
}
|
|
364
330
|
/**
|
|
@@ -375,14 +341,14 @@ export class Enum {
|
|
|
375
341
|
|
|
376
342
|
|
|
377
343
|
_toRawStruct() {
|
|
378
|
-
if (
|
|
379
|
-
return
|
|
380
|
-
out[key] =
|
|
344
|
+
if (this.#isBasic) {
|
|
345
|
+
return this.#isIndexed ? this.defKeys.reduce((out, key, index) => {
|
|
346
|
+
out[key] = this.#indexes[index];
|
|
381
347
|
return out;
|
|
382
348
|
}, {}) : this.defKeys;
|
|
383
349
|
}
|
|
384
350
|
|
|
385
|
-
const typeMap = Object.entries(
|
|
351
|
+
const typeMap = Object.entries(this.#def).reduce((out, [key, {
|
|
386
352
|
Type
|
|
387
353
|
}]) => {
|
|
388
354
|
out[key] = Type;
|
|
@@ -415,7 +381,7 @@ export class Enum {
|
|
|
415
381
|
|
|
416
382
|
|
|
417
383
|
toU8a(isBare) {
|
|
418
|
-
return u8aConcat(new Uint8Array(isBare ? [] : [this.index]),
|
|
384
|
+
return u8aConcat(new Uint8Array(isBare ? [] : [this.index]), this.#raw.toU8a(isBare));
|
|
419
385
|
}
|
|
420
386
|
|
|
421
387
|
}
|
package/base/Null.js
CHANGED
|
@@ -9,10 +9,9 @@ import { isNull } from '@polkadot/util';
|
|
|
9
9
|
|
|
10
10
|
export class Null {
|
|
11
11
|
// Added for compatibility reasons, e.g. see Option
|
|
12
|
+
initialU8aLength = 0;
|
|
13
|
+
|
|
12
14
|
constructor(registry) {
|
|
13
|
-
this.registry = void 0;
|
|
14
|
-
this.createdAtHash = void 0;
|
|
15
|
-
this.initialU8aLength = 0;
|
|
16
15
|
this.registry = registry;
|
|
17
16
|
}
|
|
18
17
|
/**
|
package/base/Option.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
-
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
4
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
3
|
import { assert, isCodec, isNull, isU8a, isUndefined, u8aToHex } from '@polkadot/util';
|
|
@@ -36,36 +34,20 @@ function decodeOption(registry, Type, value) {
|
|
|
36
34
|
*/
|
|
37
35
|
|
|
38
36
|
|
|
39
|
-
var _Type = /*#__PURE__*/_classPrivateFieldLooseKey("Type");
|
|
40
|
-
|
|
41
|
-
var _initialU8aLength = /*#__PURE__*/_classPrivateFieldLooseKey("initialU8aLength");
|
|
42
|
-
|
|
43
|
-
var _raw = /*#__PURE__*/_classPrivateFieldLooseKey("raw");
|
|
44
|
-
|
|
45
37
|
export class Option {
|
|
38
|
+
#Type;
|
|
39
|
+
#initialU8aLength;
|
|
40
|
+
#raw;
|
|
41
|
+
|
|
46
42
|
constructor(registry, typeName, value) {
|
|
47
|
-
this.registry = void 0;
|
|
48
|
-
this.createdAtHash = void 0;
|
|
49
|
-
Object.defineProperty(this, _Type, {
|
|
50
|
-
writable: true,
|
|
51
|
-
value: void 0
|
|
52
|
-
});
|
|
53
|
-
Object.defineProperty(this, _initialU8aLength, {
|
|
54
|
-
writable: true,
|
|
55
|
-
value: void 0
|
|
56
|
-
});
|
|
57
|
-
Object.defineProperty(this, _raw, {
|
|
58
|
-
writable: true,
|
|
59
|
-
value: void 0
|
|
60
|
-
});
|
|
61
43
|
const Type = typeToConstructor(registry, typeName);
|
|
62
44
|
const decoded = isU8a(value) && value.length && !isCodec(value) ? value[0] === 0 ? new Null(registry) : new Type(registry, value.subarray(1)) : decodeOption(registry, Type, value);
|
|
63
45
|
this.registry = registry;
|
|
64
|
-
|
|
65
|
-
|
|
46
|
+
this.#Type = Type;
|
|
47
|
+
this.#raw = decoded;
|
|
66
48
|
|
|
67
49
|
if (decoded.initialU8aLength) {
|
|
68
|
-
|
|
50
|
+
this.#initialU8aLength = 1 + decoded.initialU8aLength;
|
|
69
51
|
}
|
|
70
52
|
}
|
|
71
53
|
|
|
@@ -84,7 +66,7 @@ export class Option {
|
|
|
84
66
|
|
|
85
67
|
get encodedLength() {
|
|
86
68
|
// boolean byte (has value, doesn't have) along with wrapped length
|
|
87
|
-
return 1 +
|
|
69
|
+
return 1 + this.#raw.encodedLength;
|
|
88
70
|
}
|
|
89
71
|
/**
|
|
90
72
|
* @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
|
|
@@ -92,7 +74,7 @@ export class Option {
|
|
|
92
74
|
|
|
93
75
|
|
|
94
76
|
get initialU8aLength() {
|
|
95
|
-
return
|
|
77
|
+
return this.#initialU8aLength;
|
|
96
78
|
}
|
|
97
79
|
/**
|
|
98
80
|
* @description returns a hash of the contents
|
|
@@ -116,7 +98,7 @@ export class Option {
|
|
|
116
98
|
|
|
117
99
|
|
|
118
100
|
get isNone() {
|
|
119
|
-
return
|
|
101
|
+
return this.#raw instanceof Null;
|
|
120
102
|
}
|
|
121
103
|
/**
|
|
122
104
|
* @description Checks if the Option has a value
|
|
@@ -132,7 +114,7 @@ export class Option {
|
|
|
132
114
|
|
|
133
115
|
|
|
134
116
|
get value() {
|
|
135
|
-
return
|
|
117
|
+
return this.#raw;
|
|
136
118
|
}
|
|
137
119
|
/**
|
|
138
120
|
* @description Compares the value of the input to see if there is a match
|
|
@@ -162,7 +144,7 @@ export class Option {
|
|
|
162
144
|
|
|
163
145
|
|
|
164
146
|
toHuman(isExtended) {
|
|
165
|
-
return
|
|
147
|
+
return this.#raw.toHuman(isExtended);
|
|
166
148
|
}
|
|
167
149
|
/**
|
|
168
150
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
@@ -170,7 +152,7 @@ export class Option {
|
|
|
170
152
|
|
|
171
153
|
|
|
172
154
|
toJSON() {
|
|
173
|
-
return this.isNone ? null :
|
|
155
|
+
return this.isNone ? null : this.#raw.toJSON();
|
|
174
156
|
}
|
|
175
157
|
/**
|
|
176
158
|
* @description Returns the base runtime type name for this instance
|
|
@@ -178,7 +160,7 @@ export class Option {
|
|
|
178
160
|
|
|
179
161
|
|
|
180
162
|
toRawType(isBare) {
|
|
181
|
-
const wrapped = this.registry.getClassName(
|
|
163
|
+
const wrapped = this.registry.getClassName(this.#Type) || new this.#Type(this.registry).toRawType();
|
|
182
164
|
return isBare ? wrapped : `Option<${wrapped}>`;
|
|
183
165
|
}
|
|
184
166
|
/**
|
|
@@ -187,7 +169,7 @@ export class Option {
|
|
|
187
169
|
|
|
188
170
|
|
|
189
171
|
toString() {
|
|
190
|
-
return
|
|
172
|
+
return this.#raw.toString();
|
|
191
173
|
}
|
|
192
174
|
/**
|
|
193
175
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
@@ -197,14 +179,14 @@ export class Option {
|
|
|
197
179
|
|
|
198
180
|
toU8a(isBare) {
|
|
199
181
|
if (isBare) {
|
|
200
|
-
return
|
|
182
|
+
return this.#raw.toU8a(true);
|
|
201
183
|
}
|
|
202
184
|
|
|
203
185
|
const u8a = new Uint8Array(this.encodedLength);
|
|
204
186
|
|
|
205
187
|
if (this.isSome) {
|
|
206
188
|
u8a.set([1]);
|
|
207
|
-
u8a.set(
|
|
189
|
+
u8a.set(this.#raw.toU8a(), 1);
|
|
208
190
|
}
|
|
209
191
|
|
|
210
192
|
return u8a;
|
|
@@ -216,7 +198,7 @@ export class Option {
|
|
|
216
198
|
|
|
217
199
|
unwrap() {
|
|
218
200
|
assert(this.isSome, 'Option: unwrapping a None value');
|
|
219
|
-
return
|
|
201
|
+
return this.#raw;
|
|
220
202
|
}
|
|
221
203
|
/**
|
|
222
204
|
* @description Returns the value that the Option represents (if available) or defaultValue if none
|
|
@@ -234,7 +216,7 @@ export class Option {
|
|
|
234
216
|
|
|
235
217
|
|
|
236
218
|
unwrapOrDefault() {
|
|
237
|
-
return this.isSome ? this.unwrap() : new
|
|
219
|
+
return this.isSome ? this.unwrap() : new this.#Type(this.registry);
|
|
238
220
|
}
|
|
239
221
|
|
|
240
222
|
}
|
package/base/Tuple.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
-
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
4
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
3
|
import { isFunction, isHex, isString, isU8a, stringify, u8aConcat, u8aToU8a } from '@polkadot/util';
|
|
@@ -35,18 +33,14 @@ function decodeTuple(registry, Classes, value) {
|
|
|
35
33
|
*/
|
|
36
34
|
|
|
37
35
|
|
|
38
|
-
var _Types = /*#__PURE__*/_classPrivateFieldLooseKey("Types");
|
|
39
|
-
|
|
40
36
|
export class Tuple extends AbstractArray {
|
|
37
|
+
#Types;
|
|
38
|
+
|
|
41
39
|
constructor(registry, Types, value) {
|
|
42
40
|
const Classes = Array.isArray(Types) ? Types.map(t => typeToConstructor(registry, t)) : isFunction(Types) || isString(Types) ? [typeToConstructor(registry, Types)] : mapToTypeMap(registry, Types);
|
|
43
41
|
const [values, decodedLength] = isU8a(value) ? decodeU8a(registry, value, Classes) : decodeTuple(registry, Classes, value);
|
|
44
42
|
super(registry, values, decodedLength);
|
|
45
|
-
|
|
46
|
-
writable: true,
|
|
47
|
-
value: void 0
|
|
48
|
-
});
|
|
49
|
-
_classPrivateFieldLooseBase(this, _Types)[_Types] = Classes;
|
|
43
|
+
this.#Types = Classes;
|
|
50
44
|
}
|
|
51
45
|
|
|
52
46
|
static with(Types) {
|
|
@@ -77,7 +71,7 @@ export class Tuple extends AbstractArray {
|
|
|
77
71
|
|
|
78
72
|
|
|
79
73
|
get Types() {
|
|
80
|
-
return Array.isArray(
|
|
74
|
+
return Array.isArray(this.#Types) ? this.#Types.map(T => new T(this.registry).toRawType()) : Object.keys(this.#Types);
|
|
81
75
|
}
|
|
82
76
|
/**
|
|
83
77
|
* @description Returns the base runtime type name for this instance
|
|
@@ -85,7 +79,7 @@ export class Tuple extends AbstractArray {
|
|
|
85
79
|
|
|
86
80
|
|
|
87
81
|
toRawType() {
|
|
88
|
-
const types = (Array.isArray(
|
|
82
|
+
const types = (Array.isArray(this.#Types) ? this.#Types : Object.values(this.#Types)).map(T => this.registry.getClassName(T) || new T(this.registry).toRawType());
|
|
89
83
|
return `(${types.join(',')})`;
|
|
90
84
|
}
|
|
91
85
|
/**
|
package/base/Vec.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
-
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
4
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
3
|
import { assert, compactFromU8a, logger, u8aToU8a } from '@polkadot/util';
|
|
@@ -45,18 +43,14 @@ export function decodeVec(registry, Type, value, length = -1) {
|
|
|
45
43
|
* specific encoding/decoding on top of the base type.
|
|
46
44
|
*/
|
|
47
45
|
|
|
48
|
-
var _Type = /*#__PURE__*/_classPrivateFieldLooseKey("Type");
|
|
49
|
-
|
|
50
46
|
export class Vec extends AbstractArray {
|
|
47
|
+
#Type;
|
|
48
|
+
|
|
51
49
|
constructor(registry, Type, value = []) {
|
|
52
50
|
const Clazz = typeToConstructor(registry, Type);
|
|
53
51
|
const [values, decodedLength] = decodeVec(registry, Clazz, value);
|
|
54
52
|
super(registry, values, decodedLength);
|
|
55
|
-
|
|
56
|
-
writable: true,
|
|
57
|
-
value: void 0
|
|
58
|
-
});
|
|
59
|
-
_classPrivateFieldLooseBase(this, _Type)[_Type] = Clazz;
|
|
53
|
+
this.#Type = Clazz;
|
|
60
54
|
}
|
|
61
55
|
|
|
62
56
|
static with(Type) {
|
|
@@ -73,7 +67,7 @@ export class Vec extends AbstractArray {
|
|
|
73
67
|
|
|
74
68
|
|
|
75
69
|
get Type() {
|
|
76
|
-
return
|
|
70
|
+
return this.#Type.name;
|
|
77
71
|
}
|
|
78
72
|
/**
|
|
79
73
|
* @description Finds the index of the value in the array
|
|
@@ -82,7 +76,7 @@ export class Vec extends AbstractArray {
|
|
|
82
76
|
|
|
83
77
|
indexOf(_other) {
|
|
84
78
|
// convert type first, this removes overhead from the eq
|
|
85
|
-
const other = _other instanceof
|
|
79
|
+
const other = _other instanceof this.#Type ? _other : new this.#Type(this.registry, _other);
|
|
86
80
|
|
|
87
81
|
for (let i = 0; i < this.length; i++) {
|
|
88
82
|
if (other.eq(this[i])) {
|
|
@@ -98,7 +92,7 @@ export class Vec extends AbstractArray {
|
|
|
98
92
|
|
|
99
93
|
|
|
100
94
|
toRawType() {
|
|
101
|
-
return `Vec<${this.registry.getClassName(
|
|
95
|
+
return `Vec<${this.registry.getClassName(this.#Type) || new this.#Type(this.registry).toRawType()}>`;
|
|
102
96
|
}
|
|
103
97
|
|
|
104
98
|
}
|
package/base/VecFixed.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
-
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
4
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
3
|
import { assert, isU8a, u8aConcat } from '@polkadot/util';
|
|
@@ -25,18 +23,14 @@ function decodeVecFixed(registry, value, Type, length) {
|
|
|
25
23
|
*/
|
|
26
24
|
|
|
27
25
|
|
|
28
|
-
var _Type = /*#__PURE__*/_classPrivateFieldLooseKey("Type");
|
|
29
|
-
|
|
30
26
|
export class VecFixed extends AbstractArray {
|
|
27
|
+
#Type;
|
|
28
|
+
|
|
31
29
|
constructor(registry, Type, length, value = []) {
|
|
32
30
|
const Clazz = typeToConstructor(registry, Type);
|
|
33
31
|
const [values,, decodedLengthNoOffset] = isU8a(value) ? decodeU8aVec(registry, value, 0, Clazz, length) : decodeVecFixed(registry, value, Clazz, length);
|
|
34
32
|
super(registry, values, decodedLengthNoOffset);
|
|
35
|
-
|
|
36
|
-
writable: true,
|
|
37
|
-
value: void 0
|
|
38
|
-
});
|
|
39
|
-
_classPrivateFieldLooseBase(this, _Type)[_Type] = Clazz;
|
|
33
|
+
this.#Type = Clazz;
|
|
40
34
|
}
|
|
41
35
|
|
|
42
36
|
static with(Type, length) {
|
|
@@ -53,7 +47,7 @@ export class VecFixed extends AbstractArray {
|
|
|
53
47
|
|
|
54
48
|
|
|
55
49
|
get Type() {
|
|
56
|
-
return new
|
|
50
|
+
return new this.#Type(this.registry).toRawType();
|
|
57
51
|
}
|
|
58
52
|
/**
|
|
59
53
|
* @description The length of the value when encoded as a Uint8Array
|
package/extended/BTreeSet.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
-
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
4
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
3
|
import { compactFromU8a, compactToU8a, isHex, isU8a, logger, stringify, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
|
|
@@ -65,22 +63,15 @@ function decodeSet(registry, valType, value) {
|
|
|
65
63
|
throw new Error('BTreeSet: cannot decode type');
|
|
66
64
|
}
|
|
67
65
|
|
|
68
|
-
var _ValClass = /*#__PURE__*/_classPrivateFieldLooseKey("ValClass");
|
|
69
|
-
|
|
70
66
|
export class BTreeSet extends Set {
|
|
67
|
+
#ValClass;
|
|
68
|
+
|
|
71
69
|
constructor(registry, valType, rawValue) {
|
|
72
70
|
const [values, decodedLength] = decodeSet(registry, valType, rawValue);
|
|
73
71
|
super(sortSet(values));
|
|
74
|
-
this.registry = void 0;
|
|
75
|
-
this.createdAtHash = void 0;
|
|
76
|
-
this.initialU8aLength = void 0;
|
|
77
|
-
Object.defineProperty(this, _ValClass, {
|
|
78
|
-
writable: true,
|
|
79
|
-
value: void 0
|
|
80
|
-
});
|
|
81
72
|
this.registry = registry;
|
|
82
73
|
this.initialU8aLength = decodedLength;
|
|
83
|
-
|
|
74
|
+
this.#ValClass = typeToConstructor(registry, valType);
|
|
84
75
|
}
|
|
85
76
|
|
|
86
77
|
static with(valType) {
|
|
@@ -179,7 +170,7 @@ export class BTreeSet extends Set {
|
|
|
179
170
|
|
|
180
171
|
|
|
181
172
|
toRawType() {
|
|
182
|
-
return `BTreeSet<${this.registry.getClassName(
|
|
173
|
+
return `BTreeSet<${this.registry.getClassName(this.#ValClass) || new this.#ValClass(this.registry).toRawType()}>`;
|
|
183
174
|
}
|
|
184
175
|
/**
|
|
185
176
|
* @description Returns the string representation of the value
|
package/extended/BitVec.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
-
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
4
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
3
|
import { assert, compactFromU8a, compactToU8a, isString, u8aConcat, u8aToU8a } from '@polkadot/util';
|
|
@@ -36,17 +34,13 @@ function decodeBitVec(value) {
|
|
|
36
34
|
*/
|
|
37
35
|
|
|
38
36
|
|
|
39
|
-
var _decodedLength = /*#__PURE__*/_classPrivateFieldLooseKey("decodedLength");
|
|
40
|
-
|
|
41
37
|
export class BitVec extends Raw {
|
|
38
|
+
#decodedLength;
|
|
39
|
+
|
|
42
40
|
constructor(registry, value) {
|
|
43
41
|
const [decodedLength, u8a] = decodeBitVec(value);
|
|
44
42
|
super(registry, u8a);
|
|
45
|
-
|
|
46
|
-
writable: true,
|
|
47
|
-
value: void 0
|
|
48
|
-
});
|
|
49
|
-
_classPrivateFieldLooseBase(this, _decodedLength)[_decodedLength] = decodedLength;
|
|
43
|
+
this.#decodedLength = decodedLength;
|
|
50
44
|
}
|
|
51
45
|
/**
|
|
52
46
|
* @description The length of the value when encoded as a Uint8Array
|
|
@@ -54,7 +48,7 @@ export class BitVec extends Raw {
|
|
|
54
48
|
|
|
55
49
|
|
|
56
50
|
get encodedLength() {
|
|
57
|
-
return this.length + compactToU8a(
|
|
51
|
+
return this.length + compactToU8a(this.#decodedLength).length;
|
|
58
52
|
}
|
|
59
53
|
|
|
60
54
|
toHuman() {
|
|
@@ -76,7 +70,7 @@ export class BitVec extends Raw {
|
|
|
76
70
|
|
|
77
71
|
toU8a(isBare) {
|
|
78
72
|
const bitVec = super.toU8a();
|
|
79
|
-
return isBare ? bitVec : u8aConcat(compactToU8a(
|
|
73
|
+
return isBare ? bitVec : u8aConcat(compactToU8a(this.#decodedLength), bitVec);
|
|
80
74
|
}
|
|
81
75
|
|
|
82
76
|
}
|