@polkadot/types-codec 9.5.2 → 9.6.2
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 +10 -18
- 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 +2 -2
- 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 +12 -15
- 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/abstract/Int.js
CHANGED
|
@@ -4,31 +4,28 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.DEFAULT_UINT_BITS = exports.AbstractInt = void 0;
|
|
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
|
|
12
|
-
const DEFAULT_UINT_BITS = 64; // Maximum allowed integer for JS is 2^53 - 1, set limit at 52
|
|
13
|
-
// In this case however, we always print any >32 as hex
|
|
14
10
|
|
|
11
|
+
const DEFAULT_UINT_BITS = 64;
|
|
12
|
+
|
|
13
|
+
// Maximum allowed integer for JS is 2^53 - 1, set limit at 52
|
|
14
|
+
// In this case however, we always print any >32 as hex
|
|
15
15
|
exports.DEFAULT_UINT_BITS = DEFAULT_UINT_BITS;
|
|
16
16
|
const MAX_NUMBER_BITS = 52;
|
|
17
17
|
const MUL_P = new _util.BN(10000);
|
|
18
18
|
const FORMATTERS = [['Perquintill', _util.BN_QUINTILL], ['Perbill', _util.BN_BILLION], ['Permill', _util.BN_MILLION], ['Percent', _util.BN_HUNDRED]];
|
|
19
|
-
|
|
20
19
|
function toPercentage(value, divisor) {
|
|
21
20
|
return `${(value.mul(MUL_P).div(divisor).toNumber() / 100).toFixed(2)}%`;
|
|
22
21
|
}
|
|
23
|
-
/** @internal */
|
|
24
|
-
|
|
25
22
|
|
|
23
|
+
/** @internal */
|
|
26
24
|
function decodeAbstractInt(value, isNegative) {
|
|
27
25
|
if ((0, _util.isNumber)(value)) {
|
|
28
26
|
if (!Number.isInteger(value) || value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER) {
|
|
29
27
|
throw new Error('Number needs to be an integer <= Number.MAX_SAFE_INTEGER, i.e. 2 ^ 53 - 1');
|
|
30
28
|
}
|
|
31
|
-
|
|
32
29
|
return value;
|
|
33
30
|
} else if ((0, _util.isString)(value)) {
|
|
34
31
|
if ((0, _util.isHex)(value, -1, true)) {
|
|
@@ -37,11 +34,9 @@ function decodeAbstractInt(value, isNegative) {
|
|
|
37
34
|
isNegative
|
|
38
35
|
}).toString();
|
|
39
36
|
}
|
|
40
|
-
|
|
41
37
|
if (value.includes('.') || value.includes(',') || value.includes('e')) {
|
|
42
38
|
throw new Error('String should not contain decimal points or scientific notation');
|
|
43
39
|
}
|
|
44
|
-
|
|
45
40
|
return value;
|
|
46
41
|
} else if ((0, _util.isBn)(value)) {
|
|
47
42
|
return value.toString();
|
|
@@ -50,32 +45,25 @@ function decodeAbstractInt(value, isNegative) {
|
|
|
50
45
|
// single key objects can be treated equivalently to numbers, assuming they meet the
|
|
51
46
|
// specific requirements. (This is useful in Weights 1.5 where Objects are compact)
|
|
52
47
|
const keys = Object.keys(value);
|
|
53
|
-
|
|
54
48
|
if (keys.length !== 1) {
|
|
55
49
|
throw new Error('Unable to construct number from multi-key object');
|
|
56
50
|
}
|
|
57
|
-
|
|
58
51
|
const inner = value[keys[0]];
|
|
59
|
-
|
|
60
52
|
if (!(0, _util.isString)(inner) && !(0, _util.isNumber)(inner)) {
|
|
61
53
|
throw new Error('Unable to construct from object with non-string/non-number value');
|
|
62
54
|
}
|
|
63
|
-
|
|
64
55
|
return decodeAbstractInt(inner, isNegative);
|
|
65
56
|
}
|
|
66
|
-
|
|
67
57
|
return (0, _util.bnToBn)(value).toString();
|
|
68
58
|
}
|
|
59
|
+
|
|
69
60
|
/**
|
|
70
61
|
* @name AbstractInt
|
|
71
62
|
* @ignore
|
|
72
63
|
* @noInheritDoc
|
|
73
64
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
65
|
class AbstractInt extends _util.BN {
|
|
77
66
|
#bitLength;
|
|
78
|
-
|
|
79
67
|
constructor(registry) {
|
|
80
68
|
let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
81
69
|
let bitLength = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_UINT_BITS;
|
|
@@ -83,7 +71,8 @@ class AbstractInt extends _util.BN {
|
|
|
83
71
|
// Construct via a string/number, which will be passed in the BN constructor.
|
|
84
72
|
// It would be ideal to actually return a BN, but there is an issue:
|
|
85
73
|
// https://github.com/indutny/bn.js/issues/206
|
|
86
|
-
super(
|
|
74
|
+
super(
|
|
75
|
+
// shortcut isU8a as used in SCALE decoding
|
|
87
76
|
(0, _util.isU8a)(value) ? bitLength <= 48 ? (0, _util.u8aToNumber)(value.subarray(0, bitLength / 8), {
|
|
88
77
|
isNegative: isSigned
|
|
89
78
|
}) : (0, _util.u8aToBn)(value.subarray(0, bitLength / 8), {
|
|
@@ -96,43 +85,38 @@ class AbstractInt extends _util.BN {
|
|
|
96
85
|
this.isUnsigned = !isSigned;
|
|
97
86
|
const isNegative = this.isNeg();
|
|
98
87
|
const maxBits = bitLength - (isSigned && !isNegative ? 1 : 0);
|
|
99
|
-
|
|
100
88
|
if (isNegative && !isSigned) {
|
|
101
89
|
throw new Error(`${this.toRawType()}: Negative number passed to unsigned type`);
|
|
102
90
|
} else if (super.bitLength() > maxBits) {
|
|
103
91
|
throw new Error(`${this.toRawType()}: Input too large. Found input with ${super.bitLength()} bits, expected ${maxBits}`);
|
|
104
92
|
}
|
|
105
93
|
}
|
|
94
|
+
|
|
106
95
|
/**
|
|
107
96
|
* @description returns a hash of the contents
|
|
108
97
|
*/
|
|
109
|
-
|
|
110
|
-
|
|
111
98
|
get hash() {
|
|
112
99
|
return this.registry.hash(this.toU8a());
|
|
113
100
|
}
|
|
101
|
+
|
|
114
102
|
/**
|
|
115
103
|
* @description Checks if the value is a zero value (align elsewhere)
|
|
116
104
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
105
|
get isEmpty() {
|
|
120
106
|
return this.isZero();
|
|
121
107
|
}
|
|
108
|
+
|
|
122
109
|
/**
|
|
123
110
|
* @description Returns the number of bits in the value
|
|
124
111
|
*/
|
|
125
|
-
|
|
126
|
-
|
|
127
112
|
bitLength() {
|
|
128
113
|
return this.#bitLength;
|
|
129
114
|
}
|
|
115
|
+
|
|
130
116
|
/**
|
|
131
117
|
* @description Compares the value of the input to see if there is a match
|
|
132
118
|
*/
|
|
133
119
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
134
|
-
|
|
135
|
-
|
|
136
120
|
eq(other) {
|
|
137
121
|
// Here we are actually overriding the built-in .eq to take care of both
|
|
138
122
|
// number and BN inputs (no `.eqn` needed) - numbers will be converted
|
|
@@ -141,46 +125,41 @@ class AbstractInt extends _util.BN {
|
|
|
141
125
|
isNegative: !this.isUnsigned
|
|
142
126
|
}) : (0, _util.bnToBn)(other));
|
|
143
127
|
}
|
|
128
|
+
|
|
144
129
|
/**
|
|
145
130
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
146
131
|
*/
|
|
147
|
-
|
|
148
|
-
|
|
149
132
|
inspect() {
|
|
150
133
|
return {
|
|
151
134
|
outer: [this.toU8a()]
|
|
152
135
|
};
|
|
153
136
|
}
|
|
137
|
+
|
|
154
138
|
/**
|
|
155
139
|
* @description True if this value is the max of the type
|
|
156
140
|
*/
|
|
157
|
-
|
|
158
|
-
|
|
159
141
|
isMax() {
|
|
160
142
|
const u8a = this.toU8a().filter(b => b === 0xff);
|
|
161
143
|
return u8a.length === this.#bitLength / 8;
|
|
162
144
|
}
|
|
145
|
+
|
|
163
146
|
/**
|
|
164
147
|
* @description Returns a BigInt representation of the number
|
|
165
148
|
*/
|
|
166
|
-
|
|
167
|
-
|
|
168
149
|
toBigInt() {
|
|
169
150
|
return BigInt(this.toString());
|
|
170
151
|
}
|
|
152
|
+
|
|
171
153
|
/**
|
|
172
154
|
* @description Returns the BN representation of the number. (Compatibility)
|
|
173
155
|
*/
|
|
174
|
-
|
|
175
|
-
|
|
176
156
|
toBn() {
|
|
177
157
|
return this;
|
|
178
158
|
}
|
|
159
|
+
|
|
179
160
|
/**
|
|
180
161
|
* @description Returns a hex string representation of the value
|
|
181
162
|
*/
|
|
182
|
-
|
|
183
|
-
|
|
184
163
|
toHex() {
|
|
185
164
|
let isLe = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
186
165
|
// For display/JSON, this is BE, for compare, use isLe
|
|
@@ -190,17 +169,16 @@ class AbstractInt extends _util.BN {
|
|
|
190
169
|
isNegative: !this.isUnsigned
|
|
191
170
|
});
|
|
192
171
|
}
|
|
172
|
+
|
|
193
173
|
/**
|
|
194
174
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
195
175
|
*/
|
|
196
176
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
197
|
-
|
|
198
|
-
|
|
199
177
|
toHuman(isExpanded) {
|
|
200
178
|
const rawType = this.toRawType();
|
|
201
|
-
|
|
202
179
|
if (rawType === 'Balance') {
|
|
203
|
-
return this.isMax() ? 'everything'
|
|
180
|
+
return this.isMax() ? 'everything'
|
|
181
|
+
// FIXME In the case of multiples we need some way of detecting which instance this belongs
|
|
204
182
|
// to. as it stands we will always format (incorrectly) against the first token defined
|
|
205
183
|
: (0, _util.formatBalance)(this, {
|
|
206
184
|
decimals: this.registry.chainDecimals[0],
|
|
@@ -208,18 +186,16 @@ class AbstractInt extends _util.BN {
|
|
|
208
186
|
withUnit: this.registry.chainTokens[0]
|
|
209
187
|
});
|
|
210
188
|
}
|
|
211
|
-
|
|
212
189
|
const [, divisor] = FORMATTERS.find(_ref => {
|
|
213
190
|
let [type] = _ref;
|
|
214
191
|
return type === rawType;
|
|
215
192
|
}) || [];
|
|
216
193
|
return divisor ? toPercentage(this, divisor) : (0, _util.formatNumber)(this);
|
|
217
194
|
}
|
|
195
|
+
|
|
218
196
|
/**
|
|
219
197
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
220
198
|
*/
|
|
221
|
-
|
|
222
|
-
|
|
223
199
|
toJSON() {
|
|
224
200
|
let onlyHex = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
225
201
|
// FIXME this return type should by string | number, however BN returns string
|
|
@@ -228,42 +204,38 @@ class AbstractInt extends _util.BN {
|
|
|
228
204
|
// - this.#bitLength - the type bits (this should be used, however contracts RPC is problematic)
|
|
229
205
|
return onlyHex || super.bitLength() > MAX_NUMBER_BITS ? this.toHex() : this.toNumber();
|
|
230
206
|
}
|
|
207
|
+
|
|
231
208
|
/**
|
|
232
209
|
* @description Returns the value in a primitive form, either number when <= 52 bits, or string otherwise
|
|
233
210
|
*/
|
|
234
|
-
|
|
235
|
-
|
|
236
211
|
toPrimitive() {
|
|
237
212
|
return super.bitLength() > MAX_NUMBER_BITS ? this.toString() : this.toNumber();
|
|
238
213
|
}
|
|
214
|
+
|
|
239
215
|
/**
|
|
240
216
|
* @description Returns the base runtime type name for this instance
|
|
241
217
|
*/
|
|
242
|
-
|
|
243
|
-
|
|
244
218
|
toRawType() {
|
|
245
219
|
// NOTE In the case of balances, which have a special meaning on the UI
|
|
246
220
|
// and can be interpreted differently, return a specific value for it so
|
|
247
221
|
// underlying it always matches (no matter which length it actually is)
|
|
248
222
|
return this instanceof this.registry.createClassUnsafe('Balance') ? 'Balance' : `${this.isUnsigned ? 'u' : 'i'}${this.bitLength()}`;
|
|
249
223
|
}
|
|
224
|
+
|
|
250
225
|
/**
|
|
251
226
|
* @description Returns the string representation of the value
|
|
252
227
|
* @param base The base to use for the conversion
|
|
253
228
|
*/
|
|
254
|
-
|
|
255
|
-
|
|
256
229
|
toString(base) {
|
|
257
230
|
// only included here since we do not inherit docs
|
|
258
231
|
return super.toString(base);
|
|
259
232
|
}
|
|
233
|
+
|
|
260
234
|
/**
|
|
261
235
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
262
236
|
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
263
237
|
*/
|
|
264
238
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
265
|
-
|
|
266
|
-
|
|
267
239
|
toU8a(isBare) {
|
|
268
240
|
return (0, _util.bnToU8a)(this, {
|
|
269
241
|
bitLength: this.bitLength(),
|
|
@@ -271,7 +243,5 @@ class AbstractInt extends _util.BN {
|
|
|
271
243
|
isNegative: !this.isUnsigned
|
|
272
244
|
});
|
|
273
245
|
}
|
|
274
|
-
|
|
275
246
|
}
|
|
276
|
-
|
|
277
247
|
exports.AbstractInt = AbstractInt;
|
package/cjs/abstract/index.js
CHANGED
package/cjs/base/Compact.js
CHANGED
|
@@ -4,17 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Compact = void 0;
|
|
7
|
-
|
|
8
7
|
var _util = require("@polkadot/util");
|
|
9
|
-
|
|
10
8
|
var _utils = require("../utils");
|
|
11
|
-
|
|
12
9
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
13
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
|
|
14
12
|
function noopSetDefinition(d) {
|
|
15
13
|
return d;
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
function decodeCompact(registry, Type, value) {
|
|
19
16
|
if ((0, _util.isU8a)(value)) {
|
|
20
17
|
const [decodedLength, bn] = (value[0] & 0b11) < 0b11 ? (0, _util.compactFromU8aLim)(value) : (0, _util.compactFromU8a)(value);
|
|
@@ -25,9 +22,9 @@ function decodeCompact(registry, Type, value) {
|
|
|
25
22
|
} else if (value instanceof Type) {
|
|
26
23
|
return [value, 0];
|
|
27
24
|
}
|
|
28
|
-
|
|
29
25
|
return [new Type(registry, value), 0];
|
|
30
26
|
}
|
|
27
|
+
|
|
31
28
|
/**
|
|
32
29
|
* @name Compact
|
|
33
30
|
* @description
|
|
@@ -36,12 +33,9 @@ function decodeCompact(registry, Type, value) {
|
|
|
36
33
|
* used by other types to add length-prefixed encoding, or in the case of wrapped types, taking
|
|
37
34
|
* a number and making the compact representation thereof
|
|
38
35
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
36
|
class Compact {
|
|
42
37
|
#Type;
|
|
43
38
|
#raw;
|
|
44
|
-
|
|
45
39
|
constructor(registry, Type) {
|
|
46
40
|
let value = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
47
41
|
let {
|
|
@@ -54,12 +48,11 @@ class Compact {
|
|
|
54
48
|
this.initialU8aLength = decodedLength;
|
|
55
49
|
this.#raw = raw;
|
|
56
50
|
}
|
|
57
|
-
|
|
58
51
|
static with(Type) {
|
|
59
|
-
let definition;
|
|
52
|
+
let definition;
|
|
60
53
|
|
|
54
|
+
// eslint-disable-next-line no-return-assign
|
|
61
55
|
const setDefinition = d => definition = d;
|
|
62
|
-
|
|
63
56
|
return class extends Compact {
|
|
64
57
|
constructor(registry, value) {
|
|
65
58
|
super(registry, Type, value, {
|
|
@@ -67,150 +60,130 @@ class Compact {
|
|
|
67
60
|
setDefinition
|
|
68
61
|
});
|
|
69
62
|
}
|
|
70
|
-
|
|
71
63
|
};
|
|
72
64
|
}
|
|
65
|
+
|
|
73
66
|
/**
|
|
74
67
|
* @description The length of the value when encoded as a Uint8Array
|
|
75
68
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
78
69
|
get encodedLength() {
|
|
79
70
|
return this.toU8a().length;
|
|
80
71
|
}
|
|
72
|
+
|
|
81
73
|
/**
|
|
82
74
|
* @description returns a hash of the contents
|
|
83
75
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
76
|
get hash() {
|
|
87
77
|
return this.registry.hash(this.toU8a());
|
|
88
78
|
}
|
|
79
|
+
|
|
89
80
|
/**
|
|
90
81
|
* @description Checks if the value is an empty value
|
|
91
82
|
*/
|
|
92
|
-
|
|
93
|
-
|
|
94
83
|
get isEmpty() {
|
|
95
84
|
return this.#raw.isEmpty;
|
|
96
85
|
}
|
|
86
|
+
|
|
97
87
|
/**
|
|
98
88
|
* @description Returns the number of bits in the value
|
|
99
89
|
*/
|
|
100
|
-
|
|
101
|
-
|
|
102
90
|
bitLength() {
|
|
103
91
|
return this.#raw.bitLength();
|
|
104
92
|
}
|
|
93
|
+
|
|
105
94
|
/**
|
|
106
95
|
* @description Compares the value of the input to see if there is a match
|
|
107
96
|
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
97
|
eq(other) {
|
|
111
98
|
return this.#raw.eq(other instanceof Compact ? other.#raw : other);
|
|
112
99
|
}
|
|
100
|
+
|
|
113
101
|
/**
|
|
114
102
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
115
103
|
*/
|
|
116
|
-
|
|
117
|
-
|
|
118
104
|
inspect() {
|
|
119
105
|
return {
|
|
120
106
|
outer: [this.toU8a()]
|
|
121
107
|
};
|
|
122
108
|
}
|
|
109
|
+
|
|
123
110
|
/**
|
|
124
111
|
* @description Returns a BigInt representation of the number
|
|
125
112
|
*/
|
|
126
|
-
|
|
127
|
-
|
|
128
113
|
toBigInt() {
|
|
129
114
|
return this.#raw.toBigInt();
|
|
130
115
|
}
|
|
116
|
+
|
|
131
117
|
/**
|
|
132
118
|
* @description Returns the BN representation of the number
|
|
133
119
|
*/
|
|
134
|
-
|
|
135
|
-
|
|
136
120
|
toBn() {
|
|
137
121
|
return this.#raw.toBn();
|
|
138
122
|
}
|
|
123
|
+
|
|
139
124
|
/**
|
|
140
125
|
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
141
126
|
*/
|
|
142
|
-
|
|
143
|
-
|
|
144
127
|
toHex(isLe) {
|
|
145
128
|
return this.#raw.toHex(isLe);
|
|
146
129
|
}
|
|
130
|
+
|
|
147
131
|
/**
|
|
148
132
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
149
133
|
*/
|
|
150
|
-
|
|
151
|
-
|
|
152
134
|
toHuman(isExtended) {
|
|
153
135
|
return this.#raw.toHuman(isExtended);
|
|
154
136
|
}
|
|
137
|
+
|
|
155
138
|
/**
|
|
156
139
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
157
140
|
*/
|
|
158
|
-
|
|
159
|
-
|
|
160
141
|
toJSON() {
|
|
161
142
|
return this.#raw.toJSON();
|
|
162
143
|
}
|
|
144
|
+
|
|
163
145
|
/**
|
|
164
146
|
* @description Returns the number representation for the value
|
|
165
147
|
*/
|
|
166
|
-
|
|
167
|
-
|
|
168
148
|
toNumber() {
|
|
169
149
|
return this.#raw.toNumber();
|
|
170
150
|
}
|
|
151
|
+
|
|
171
152
|
/**
|
|
172
153
|
* @description Converts the value in a best-fit primitive form
|
|
173
154
|
*/
|
|
174
|
-
|
|
175
|
-
|
|
176
155
|
toPrimitive() {
|
|
177
156
|
return this.#raw.toPrimitive();
|
|
178
157
|
}
|
|
158
|
+
|
|
179
159
|
/**
|
|
180
160
|
* @description Returns the base runtime type name for this instance
|
|
181
161
|
*/
|
|
182
|
-
|
|
183
|
-
|
|
184
162
|
toRawType() {
|
|
185
163
|
return `Compact<${this.registry.getClassName(this.#Type) || this.#raw.toRawType()}>`;
|
|
186
164
|
}
|
|
165
|
+
|
|
187
166
|
/**
|
|
188
167
|
* @description Returns the string representation of the value
|
|
189
168
|
*/
|
|
190
|
-
|
|
191
|
-
|
|
192
169
|
toString() {
|
|
193
170
|
return this.#raw.toString();
|
|
194
171
|
}
|
|
172
|
+
|
|
195
173
|
/**
|
|
196
174
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
197
175
|
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
198
176
|
*/
|
|
199
177
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
200
|
-
|
|
201
|
-
|
|
202
178
|
toU8a(isBare) {
|
|
203
179
|
return (0, _util.compactToU8a)(this.#raw.toBn());
|
|
204
180
|
}
|
|
181
|
+
|
|
205
182
|
/**
|
|
206
183
|
* @description Returns the embedded [[UInt]] or [[Moment]] value
|
|
207
184
|
*/
|
|
208
|
-
|
|
209
|
-
|
|
210
185
|
unwrap() {
|
|
211
186
|
return this.#raw;
|
|
212
187
|
}
|
|
213
|
-
|
|
214
188
|
}
|
|
215
|
-
|
|
216
189
|
exports.Compact = Compact;
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.DoNotConstruct = void 0;
|
|
7
|
-
|
|
8
7
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
9
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
10
9
|
|
|
@@ -15,83 +14,66 @@ exports.DoNotConstruct = void 0;
|
|
|
15
14
|
*/
|
|
16
15
|
class DoNotConstruct {
|
|
17
16
|
#neverError;
|
|
18
|
-
|
|
19
17
|
constructor(registry) {
|
|
20
18
|
let typeName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'DoNotConstruct';
|
|
21
19
|
this.registry = registry;
|
|
22
20
|
this.#neverError = new Error(`DoNotConstruct: Cannot construct unknown type ${typeName}`);
|
|
23
21
|
throw this.#neverError;
|
|
24
22
|
}
|
|
25
|
-
|
|
26
23
|
static with(typeName) {
|
|
27
24
|
return class extends DoNotConstruct {
|
|
28
25
|
constructor(registry) {
|
|
29
26
|
super(registry, typeName);
|
|
30
27
|
}
|
|
31
|
-
|
|
32
28
|
};
|
|
33
29
|
}
|
|
30
|
+
|
|
34
31
|
/**
|
|
35
32
|
* @description The length of the value when encoded as a Uint8Array
|
|
36
33
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
34
|
get encodedLength() {
|
|
40
35
|
throw this.#neverError;
|
|
41
36
|
}
|
|
37
|
+
|
|
42
38
|
/**
|
|
43
39
|
* @description returns a hash of the contents
|
|
44
40
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
41
|
get hash() {
|
|
48
42
|
throw this.#neverError;
|
|
49
43
|
}
|
|
44
|
+
|
|
50
45
|
/**
|
|
51
46
|
* @description Checks if the value is an empty value (always true)
|
|
52
47
|
*/
|
|
53
|
-
|
|
54
|
-
|
|
55
48
|
get isEmpty() {
|
|
56
49
|
throw this.#neverError;
|
|
57
50
|
}
|
|
58
|
-
|
|
59
51
|
eq() {
|
|
60
52
|
throw this.#neverError;
|
|
61
53
|
}
|
|
62
|
-
|
|
63
54
|
inspect() {
|
|
64
55
|
throw this.#neverError;
|
|
65
56
|
}
|
|
66
|
-
|
|
67
57
|
toHex() {
|
|
68
58
|
throw this.#neverError;
|
|
69
59
|
}
|
|
70
|
-
|
|
71
60
|
toHuman() {
|
|
72
61
|
throw this.#neverError;
|
|
73
62
|
}
|
|
74
|
-
|
|
75
63
|
toJSON() {
|
|
76
64
|
throw this.#neverError;
|
|
77
65
|
}
|
|
78
|
-
|
|
79
66
|
toPrimitive() {
|
|
80
67
|
throw this.#neverError;
|
|
81
68
|
}
|
|
82
|
-
|
|
83
69
|
toRawType() {
|
|
84
70
|
throw this.#neverError;
|
|
85
71
|
}
|
|
86
|
-
|
|
87
72
|
toString() {
|
|
88
73
|
throw this.#neverError;
|
|
89
74
|
}
|
|
90
|
-
|
|
91
75
|
toU8a() {
|
|
92
76
|
throw this.#neverError;
|
|
93
77
|
}
|
|
94
|
-
|
|
95
78
|
}
|
|
96
|
-
|
|
97
79
|
exports.DoNotConstruct = DoNotConstruct;
|