@polkadot/types-codec 16.2.1 → 16.2.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/Base.js +14 -14
- package/abstract/Int.js +8 -8
- package/base/Compact.js +20 -20
- package/base/DoNotConstruct.js +15 -15
- package/base/Enum.js +39 -39
- package/base/Option.js +17 -17
- package/base/Tuple.js +6 -6
- package/base/Vec.js +8 -8
- package/base/VecFixed.js +5 -5
- package/cjs/abstract/Base.js +14 -14
- package/cjs/abstract/Int.js +8 -8
- package/cjs/base/Compact.js +20 -20
- package/cjs/base/DoNotConstruct.js +15 -15
- package/cjs/base/Enum.js +39 -39
- package/cjs/base/Option.js +17 -17
- package/cjs/base/Tuple.js +6 -6
- package/cjs/base/Vec.js +8 -8
- package/cjs/base/VecFixed.js +5 -5
- package/cjs/extended/BTreeSet.js +3 -3
- package/cjs/extended/BitVec.js +9 -9
- package/cjs/extended/Map.js +7 -7
- package/cjs/extended/Range.js +3 -3
- package/cjs/extended/WrapperKeepOpaque.js +19 -19
- package/cjs/native/Float.js +4 -4
- package/cjs/native/Set.js +9 -9
- package/cjs/native/Struct.js +8 -8
- package/cjs/native/Text.js +3 -3
- package/cjs/packageInfo.js +1 -1
- package/cjs/utils/decodeU8a.js +12 -0
- package/extended/BTreeSet.js +3 -3
- package/extended/BitVec.js +9 -9
- package/extended/Map.js +7 -7
- package/extended/Range.js +3 -3
- package/extended/WrapperKeepOpaque.js +19 -19
- package/native/Float.js +4 -4
- package/native/Set.js +9 -9
- package/native/Struct.js +8 -8
- package/native/Text.js +3 -3
- package/package.json +3 -3
- package/packageInfo.js +1 -1
- package/utils/decodeU8a.js +12 -0
package/base/Option.js
CHANGED
|
@@ -53,8 +53,8 @@ export class Option {
|
|
|
53
53
|
createdAtHash;
|
|
54
54
|
initialU8aLength;
|
|
55
55
|
isStorageFallback;
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
#Type;
|
|
57
|
+
#raw;
|
|
58
58
|
constructor(registry, typeName, value, { definition, setDefinition = identity } = {}) {
|
|
59
59
|
const Type = definition || setDefinition(typeToConstructor(registry, typeName));
|
|
60
60
|
const decoded = isU8a(value) && value.length && !isCodec(value)
|
|
@@ -63,8 +63,8 @@ export class Option {
|
|
|
63
63
|
: new Type(registry, value.subarray(1))
|
|
64
64
|
: decodeOption(registry, Type, value);
|
|
65
65
|
this.registry = registry;
|
|
66
|
-
this
|
|
67
|
-
this
|
|
66
|
+
this.#Type = Type;
|
|
67
|
+
this.#raw = decoded;
|
|
68
68
|
if (decoded?.initialU8aLength) {
|
|
69
69
|
this.initialU8aLength = 1 + decoded.initialU8aLength;
|
|
70
70
|
}
|
|
@@ -86,7 +86,7 @@ export class Option {
|
|
|
86
86
|
*/
|
|
87
87
|
get encodedLength() {
|
|
88
88
|
// boolean byte (has value, doesn't have) along with wrapped length
|
|
89
|
-
return 1 + this.
|
|
89
|
+
return 1 + this.#raw.encodedLength;
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
92
|
* @description returns a hash of the contents
|
|
@@ -104,7 +104,7 @@ export class Option {
|
|
|
104
104
|
* @description Checks if the Option has no value
|
|
105
105
|
*/
|
|
106
106
|
get isNone() {
|
|
107
|
-
return this
|
|
107
|
+
return this.#raw instanceof None;
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
110
110
|
* @description Checks if the Option has a value
|
|
@@ -116,7 +116,7 @@ export class Option {
|
|
|
116
116
|
* @description The actual value for the Option
|
|
117
117
|
*/
|
|
118
118
|
get value() {
|
|
119
|
-
return this
|
|
119
|
+
return this.#raw;
|
|
120
120
|
}
|
|
121
121
|
/**
|
|
122
122
|
* @description Compares the value of the input to see if there is a match
|
|
@@ -134,7 +134,7 @@ export class Option {
|
|
|
134
134
|
if (this.isNone) {
|
|
135
135
|
return { outer: [new Uint8Array([0])] };
|
|
136
136
|
}
|
|
137
|
-
const { inner, outer = [] } = this.
|
|
137
|
+
const { inner, outer = [] } = this.#raw.inspect();
|
|
138
138
|
return {
|
|
139
139
|
inner,
|
|
140
140
|
outer: [new Uint8Array([1]), ...outer]
|
|
@@ -154,7 +154,7 @@ export class Option {
|
|
|
154
154
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
155
155
|
*/
|
|
156
156
|
toHuman(isExtended, disableAscii) {
|
|
157
|
-
return this.
|
|
157
|
+
return this.#raw.toHuman(isExtended, disableAscii);
|
|
158
158
|
}
|
|
159
159
|
/**
|
|
160
160
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
@@ -162,7 +162,7 @@ export class Option {
|
|
|
162
162
|
toJSON() {
|
|
163
163
|
return this.isNone
|
|
164
164
|
? null
|
|
165
|
-
: this.
|
|
165
|
+
: this.#raw.toJSON();
|
|
166
166
|
}
|
|
167
167
|
/**
|
|
168
168
|
* @description Converts the value in a best-fit primitive form
|
|
@@ -170,13 +170,13 @@ export class Option {
|
|
|
170
170
|
toPrimitive(disableAscii) {
|
|
171
171
|
return this.isNone
|
|
172
172
|
? null
|
|
173
|
-
: this.
|
|
173
|
+
: this.#raw.toPrimitive(disableAscii);
|
|
174
174
|
}
|
|
175
175
|
/**
|
|
176
176
|
* @description Returns the base runtime type name for this instance
|
|
177
177
|
*/
|
|
178
178
|
toRawType(isBare) {
|
|
179
|
-
const wrapped = this.registry.getClassName(this
|
|
179
|
+
const wrapped = this.registry.getClassName(this.#Type) || new this.#Type(this.registry).toRawType();
|
|
180
180
|
return isBare
|
|
181
181
|
? wrapped
|
|
182
182
|
: `Option<${wrapped}>`;
|
|
@@ -185,7 +185,7 @@ export class Option {
|
|
|
185
185
|
* @description Returns the string representation of the value
|
|
186
186
|
*/
|
|
187
187
|
toString() {
|
|
188
|
-
return this.
|
|
188
|
+
return this.#raw.toString();
|
|
189
189
|
}
|
|
190
190
|
/**
|
|
191
191
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
@@ -193,12 +193,12 @@ export class Option {
|
|
|
193
193
|
*/
|
|
194
194
|
toU8a(isBare) {
|
|
195
195
|
if (isBare) {
|
|
196
|
-
return this.
|
|
196
|
+
return this.#raw.toU8a(true);
|
|
197
197
|
}
|
|
198
198
|
const u8a = new Uint8Array(this.encodedLength);
|
|
199
199
|
if (this.isSome) {
|
|
200
200
|
u8a.set([1]);
|
|
201
|
-
u8a.set(this.
|
|
201
|
+
u8a.set(this.#raw.toU8a(), 1);
|
|
202
202
|
}
|
|
203
203
|
return u8a;
|
|
204
204
|
}
|
|
@@ -209,7 +209,7 @@ export class Option {
|
|
|
209
209
|
if (this.isNone) {
|
|
210
210
|
throw new Error('Option: unwrapping a None value');
|
|
211
211
|
}
|
|
212
|
-
return this
|
|
212
|
+
return this.#raw;
|
|
213
213
|
}
|
|
214
214
|
/**
|
|
215
215
|
* @description Returns the value that the Option represents (if available) or defaultValue if none
|
|
@@ -227,6 +227,6 @@ export class Option {
|
|
|
227
227
|
unwrapOrDefault() {
|
|
228
228
|
return this.isSome
|
|
229
229
|
? this.unwrap()
|
|
230
|
-
: new this
|
|
230
|
+
: new this.#Type(this.registry);
|
|
231
231
|
}
|
|
232
232
|
}
|
package/base/Tuple.js
CHANGED
|
@@ -37,7 +37,7 @@ function decodeTuple(registry, result, value, Classes) {
|
|
|
37
37
|
* own type. It extends the base JS `Array` object.
|
|
38
38
|
*/
|
|
39
39
|
export class Tuple extends AbstractArray {
|
|
40
|
-
|
|
40
|
+
#Types;
|
|
41
41
|
constructor(registry, Types, value, { definition, setDefinition = identity } = {}) {
|
|
42
42
|
const Classes = definition || setDefinition(Array.isArray(Types)
|
|
43
43
|
? [typesToConstructors(registry, Types), []]
|
|
@@ -48,7 +48,7 @@ export class Tuple extends AbstractArray {
|
|
|
48
48
|
this.initialU8aLength = (isU8a(value)
|
|
49
49
|
? decodeU8a(registry, this, value, Classes)
|
|
50
50
|
: decodeTuple(registry, this, value, Classes))[1];
|
|
51
|
-
this
|
|
51
|
+
this.#Types = Classes;
|
|
52
52
|
}
|
|
53
53
|
static with(Types) {
|
|
54
54
|
let definition;
|
|
@@ -74,9 +74,9 @@ export class Tuple extends AbstractArray {
|
|
|
74
74
|
* @description The types definition of the tuple
|
|
75
75
|
*/
|
|
76
76
|
get Types() {
|
|
77
|
-
return this
|
|
78
|
-
? this
|
|
79
|
-
: this
|
|
77
|
+
return this.#Types[1].length
|
|
78
|
+
? this.#Types[1]
|
|
79
|
+
: this.#Types[0].map((T) => new T(this.registry).toRawType());
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
82
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
@@ -90,7 +90,7 @@ export class Tuple extends AbstractArray {
|
|
|
90
90
|
* @description Returns the base runtime type name for this instance
|
|
91
91
|
*/
|
|
92
92
|
toRawType() {
|
|
93
|
-
const types = this
|
|
93
|
+
const types = this.#Types[0].map((T) => this.registry.getClassName(T) || new T(this.registry).toRawType());
|
|
94
94
|
return `(${types.join(',')})`;
|
|
95
95
|
}
|
|
96
96
|
/**
|
package/base/Vec.js
CHANGED
|
@@ -53,14 +53,14 @@ export function decodeVec(registry, result, value, startAt, Type) {
|
|
|
53
53
|
* specific encoding/decoding on top of the base type.
|
|
54
54
|
*/
|
|
55
55
|
export class Vec extends AbstractArray {
|
|
56
|
-
|
|
56
|
+
#Type;
|
|
57
57
|
constructor(registry, Type, value = [], { definition, setDefinition = identity } = {}) {
|
|
58
58
|
const [decodeFrom, length, startAt] = decodeVecLength(value);
|
|
59
59
|
super(registry, length);
|
|
60
|
-
this
|
|
60
|
+
this.#Type = definition || setDefinition(typeToConstructor(registry, Type));
|
|
61
61
|
this.initialU8aLength = (isU8a(decodeFrom)
|
|
62
|
-
? decodeU8aVec(registry, this, decodeFrom, startAt, this
|
|
63
|
-
: decodeVec(registry, this, decodeFrom, startAt, this
|
|
62
|
+
? decodeU8aVec(registry, this, decodeFrom, startAt, this.#Type)
|
|
63
|
+
: decodeVec(registry, this, decodeFrom, startAt, this.#Type))[0];
|
|
64
64
|
}
|
|
65
65
|
static with(Type) {
|
|
66
66
|
let definition;
|
|
@@ -76,16 +76,16 @@ export class Vec extends AbstractArray {
|
|
|
76
76
|
* @description The type for the items
|
|
77
77
|
*/
|
|
78
78
|
get Type() {
|
|
79
|
-
return this.
|
|
79
|
+
return this.#Type.name;
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
82
|
* @description Finds the index of the value in the array
|
|
83
83
|
*/
|
|
84
84
|
indexOf(other) {
|
|
85
85
|
// convert type first, this removes overhead from the eq
|
|
86
|
-
const check = other instanceof this
|
|
86
|
+
const check = other instanceof this.#Type
|
|
87
87
|
? other
|
|
88
|
-
: new this
|
|
88
|
+
: new this.#Type(this.registry, other);
|
|
89
89
|
for (let i = 0, count = this.length; i < count; i++) {
|
|
90
90
|
if (check.eq(this[i])) {
|
|
91
91
|
return i;
|
|
@@ -97,6 +97,6 @@ export class Vec extends AbstractArray {
|
|
|
97
97
|
* @description Returns the base runtime type name for this instance
|
|
98
98
|
*/
|
|
99
99
|
toRawType() {
|
|
100
|
-
return `Vec<${this.registry.getClassName(this
|
|
100
|
+
return `Vec<${this.registry.getClassName(this.#Type) || new this.#Type(this.registry).toRawType()}>`;
|
|
101
101
|
}
|
|
102
102
|
}
|
package/base/VecFixed.js
CHANGED
|
@@ -8,13 +8,13 @@ import { decodeVec } from './Vec.js';
|
|
|
8
8
|
* This manages codec arrays of a fixed length
|
|
9
9
|
*/
|
|
10
10
|
export class VecFixed extends AbstractArray {
|
|
11
|
-
|
|
11
|
+
#Type;
|
|
12
12
|
constructor(registry, Type, length, value = [], { definition, setDefinition = identity } = {}) {
|
|
13
13
|
super(registry, length);
|
|
14
|
-
this
|
|
14
|
+
this.#Type = definition || setDefinition(typeToConstructor(registry, Type));
|
|
15
15
|
this.initialU8aLength = (isU8a(value)
|
|
16
|
-
? decodeU8aVec(registry, this, value, 0, this
|
|
17
|
-
: decodeVec(registry, this, value, 0, this
|
|
16
|
+
? decodeU8aVec(registry, this, value, 0, this.#Type)
|
|
17
|
+
: decodeVec(registry, this, value, 0, this.#Type))[1];
|
|
18
18
|
}
|
|
19
19
|
static with(Type, length) {
|
|
20
20
|
let definition;
|
|
@@ -30,7 +30,7 @@ export class VecFixed extends AbstractArray {
|
|
|
30
30
|
* @description The type for the items
|
|
31
31
|
*/
|
|
32
32
|
get Type() {
|
|
33
|
-
return new this
|
|
33
|
+
return new this.#Type(this.registry).toRawType();
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* @description The length of the value when encoded as a Uint8Array
|
package/cjs/abstract/Base.js
CHANGED
|
@@ -10,10 +10,10 @@ class AbstractBase {
|
|
|
10
10
|
createdAtHash;
|
|
11
11
|
initialU8aLength;
|
|
12
12
|
isStorageFallback;
|
|
13
|
-
|
|
13
|
+
#raw;
|
|
14
14
|
constructor(registry, value, initialU8aLength) {
|
|
15
15
|
this.initialU8aLength = initialU8aLength;
|
|
16
|
-
this
|
|
16
|
+
this.#raw = value;
|
|
17
17
|
this.registry = registry;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -32,74 +32,74 @@ class AbstractBase {
|
|
|
32
32
|
* @description returns the inner (wrapped value)
|
|
33
33
|
*/
|
|
34
34
|
get inner() {
|
|
35
|
-
return this
|
|
35
|
+
return this.#raw;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* @description Checks if the value is an empty value
|
|
39
39
|
*/
|
|
40
40
|
get isEmpty() {
|
|
41
|
-
return this.
|
|
41
|
+
return this.#raw.isEmpty;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
44
|
* @description Compares the value of the input to see if there is a match
|
|
45
45
|
*/
|
|
46
46
|
eq(other) {
|
|
47
|
-
return this.
|
|
47
|
+
return this.#raw.eq(other);
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
51
51
|
*/
|
|
52
52
|
inspect() {
|
|
53
|
-
return this.
|
|
53
|
+
return this.#raw.inspect();
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
56
|
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
57
57
|
*/
|
|
58
58
|
toHex(isLe) {
|
|
59
|
-
return this.
|
|
59
|
+
return this.#raw.toHex(isLe);
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
62
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
63
63
|
*/
|
|
64
64
|
toHuman(isExtended, disableAscii) {
|
|
65
|
-
return this.
|
|
65
|
+
return this.#raw.toHuman(isExtended, disableAscii);
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
68
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
69
69
|
*/
|
|
70
70
|
toJSON() {
|
|
71
|
-
return this.
|
|
71
|
+
return this.#raw.toJSON();
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
74
|
* @description Converts the value in a best-fit primitive form
|
|
75
75
|
*/
|
|
76
76
|
toPrimitive(disableAscii) {
|
|
77
|
-
return this.
|
|
77
|
+
return this.#raw.toPrimitive(disableAscii);
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* @description Returns the string representation of the value
|
|
81
81
|
*/
|
|
82
82
|
toString() {
|
|
83
|
-
return this.
|
|
83
|
+
return this.#raw.toString();
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
86
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
87
87
|
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
88
88
|
*/
|
|
89
89
|
toU8a(isBare) {
|
|
90
|
-
return this.
|
|
90
|
+
return this.#raw.toU8a(isBare);
|
|
91
91
|
}
|
|
92
92
|
/**
|
|
93
93
|
* @description Returns the inner wrapped value (equivalent to valueOf)
|
|
94
94
|
*/
|
|
95
95
|
unwrap() {
|
|
96
|
-
return this
|
|
96
|
+
return this.#raw;
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
99
|
* @description Returns the inner wrapped value
|
|
100
100
|
*/
|
|
101
101
|
valueOf() {
|
|
102
|
-
return this
|
|
102
|
+
return this.#raw;
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
exports.AbstractBase = AbstractBase;
|
package/cjs/abstract/Int.js
CHANGED
|
@@ -67,7 +67,7 @@ class AbstractInt extends util_1.BN {
|
|
|
67
67
|
createdAtHash;
|
|
68
68
|
initialU8aLength;
|
|
69
69
|
isStorageFallback;
|
|
70
|
-
|
|
70
|
+
#bitLength;
|
|
71
71
|
constructor(registry, value = 0, bitLength = exports.DEFAULT_UINT_BITS, isSigned = false) {
|
|
72
72
|
// Construct via a string/number, which will be passed in the BN constructor.
|
|
73
73
|
// It would be ideal to actually return a BN, but there is an issue:
|
|
@@ -80,9 +80,9 @@ class AbstractInt extends util_1.BN {
|
|
|
80
80
|
: (0, util_1.u8aToBn)(value.subarray(0, bitLength / 8), { isLe: true, isNegative: isSigned }).toString()
|
|
81
81
|
: decodeAbstractInt(value, isSigned));
|
|
82
82
|
this.registry = registry;
|
|
83
|
-
this
|
|
84
|
-
this.encodedLength = this
|
|
85
|
-
this.initialU8aLength = this
|
|
83
|
+
this.#bitLength = bitLength;
|
|
84
|
+
this.encodedLength = this.#bitLength / 8;
|
|
85
|
+
this.initialU8aLength = this.#bitLength / 8;
|
|
86
86
|
this.isUnsigned = !isSigned;
|
|
87
87
|
const isNegative = this.isNeg();
|
|
88
88
|
const maxBits = bitLength - (isSigned && !isNegative ? 1 : 0);
|
|
@@ -109,7 +109,7 @@ class AbstractInt extends util_1.BN {
|
|
|
109
109
|
* @description Returns the number of bits in the value
|
|
110
110
|
*/
|
|
111
111
|
bitLength() {
|
|
112
|
-
return this
|
|
112
|
+
return this.#bitLength;
|
|
113
113
|
}
|
|
114
114
|
/**
|
|
115
115
|
* @description Compares the value of the input to see if there is a match
|
|
@@ -135,7 +135,7 @@ class AbstractInt extends util_1.BN {
|
|
|
135
135
|
*/
|
|
136
136
|
isMax() {
|
|
137
137
|
const u8a = this.toU8a().filter((b) => b === 0xff);
|
|
138
|
-
return u8a.length === (this
|
|
138
|
+
return u8a.length === (this.#bitLength / 8);
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
141
|
* @description Returns a BigInt representation of the number
|
|
@@ -184,8 +184,8 @@ class AbstractInt extends util_1.BN {
|
|
|
184
184
|
// FIXME this return type should by string | number, however BN returns string
|
|
185
185
|
// Options here are
|
|
186
186
|
// - super.bitLength() - the actual used bits, use hex when close to MAX_SAFE_INTEGER
|
|
187
|
-
// - this
|
|
188
|
-
return onlyHex || (this
|
|
187
|
+
// - this.#bitLength - the max used bits, use hex when larger than native Rust type
|
|
188
|
+
return onlyHex || (this.#bitLength > 128) || (super.bitLength() > MAX_NUMBER_BITS)
|
|
189
189
|
? this.toHex()
|
|
190
190
|
: this.toNumber();
|
|
191
191
|
}
|
package/cjs/base/Compact.js
CHANGED
|
@@ -34,14 +34,14 @@ class Compact {
|
|
|
34
34
|
createdAtHash;
|
|
35
35
|
initialU8aLength;
|
|
36
36
|
isStorageFallback;
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
#Type;
|
|
38
|
+
#raw;
|
|
39
39
|
constructor(registry, Type, value = 0, { definition, setDefinition = util_1.identity } = {}) {
|
|
40
40
|
this.registry = registry;
|
|
41
|
-
this
|
|
42
|
-
const [raw, decodedLength] = decodeCompact(registry, this
|
|
41
|
+
this.#Type = definition || setDefinition((0, index_js_1.typeToConstructor)(registry, Type));
|
|
42
|
+
const [raw, decodedLength] = decodeCompact(registry, this.#Type, value);
|
|
43
43
|
this.initialU8aLength = decodedLength;
|
|
44
|
-
this
|
|
44
|
+
this.#raw = raw;
|
|
45
45
|
}
|
|
46
46
|
static with(Type) {
|
|
47
47
|
let definition;
|
|
@@ -69,20 +69,20 @@ class Compact {
|
|
|
69
69
|
* @description Checks if the value is an empty value
|
|
70
70
|
*/
|
|
71
71
|
get isEmpty() {
|
|
72
|
-
return this.
|
|
72
|
+
return this.#raw.isEmpty;
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* @description Returns the number of bits in the value
|
|
76
76
|
*/
|
|
77
77
|
bitLength() {
|
|
78
|
-
return this.
|
|
78
|
+
return this.#raw.bitLength();
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* @description Compares the value of the input to see if there is a match
|
|
82
82
|
*/
|
|
83
83
|
eq(other) {
|
|
84
|
-
return this.
|
|
85
|
-
? other
|
|
84
|
+
return this.#raw.eq(other instanceof Compact
|
|
85
|
+
? other.#raw
|
|
86
86
|
: other);
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
@@ -97,67 +97,67 @@ class Compact {
|
|
|
97
97
|
* @description Returns a BigInt representation of the number
|
|
98
98
|
*/
|
|
99
99
|
toBigInt() {
|
|
100
|
-
return this.
|
|
100
|
+
return this.#raw.toBigInt();
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
103
|
* @description Returns the BN representation of the number
|
|
104
104
|
*/
|
|
105
105
|
toBn() {
|
|
106
|
-
return this.
|
|
106
|
+
return this.#raw.toBn();
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
109
|
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
110
110
|
*/
|
|
111
111
|
toHex(isLe) {
|
|
112
|
-
return this.
|
|
112
|
+
return this.#raw.toHex(isLe);
|
|
113
113
|
}
|
|
114
114
|
/**
|
|
115
115
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
116
116
|
*/
|
|
117
117
|
toHuman(isExtended, disableAscii) {
|
|
118
|
-
return this.
|
|
118
|
+
return this.#raw.toHuman(isExtended, disableAscii);
|
|
119
119
|
}
|
|
120
120
|
/**
|
|
121
121
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
122
122
|
*/
|
|
123
123
|
toJSON() {
|
|
124
|
-
return this.
|
|
124
|
+
return this.#raw.toJSON();
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
127
127
|
* @description Returns the number representation for the value
|
|
128
128
|
*/
|
|
129
129
|
toNumber() {
|
|
130
|
-
return this.
|
|
130
|
+
return this.#raw.toNumber();
|
|
131
131
|
}
|
|
132
132
|
/**
|
|
133
133
|
* @description Converts the value in a best-fit primitive form
|
|
134
134
|
*/
|
|
135
135
|
toPrimitive(disableAscii) {
|
|
136
|
-
return this.
|
|
136
|
+
return this.#raw.toPrimitive(disableAscii);
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
139
|
* @description Returns the base runtime type name for this instance
|
|
140
140
|
*/
|
|
141
141
|
toRawType() {
|
|
142
|
-
return `Compact<${this.registry.getClassName(this
|
|
142
|
+
return `Compact<${this.registry.getClassName(this.#Type) || this.#raw.toRawType()}>`;
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
145
145
|
* @description Returns the string representation of the value
|
|
146
146
|
*/
|
|
147
147
|
toString() {
|
|
148
|
-
return this.
|
|
148
|
+
return this.#raw.toString();
|
|
149
149
|
}
|
|
150
150
|
/**
|
|
151
151
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
152
152
|
*/
|
|
153
153
|
toU8a(_isBare) {
|
|
154
|
-
return (0, util_1.compactToU8a)(this.
|
|
154
|
+
return (0, util_1.compactToU8a)(this.#raw.toBn());
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
157
|
* @description Returns the embedded [[UInt]] or [[Moment]] value
|
|
158
158
|
*/
|
|
159
159
|
unwrap() {
|
|
160
|
-
return this
|
|
160
|
+
return this.#raw;
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
exports.Compact = Compact;
|
|
@@ -10,11 +10,11 @@ class DoNotConstruct {
|
|
|
10
10
|
registry;
|
|
11
11
|
createdAtHash;
|
|
12
12
|
isStorageFallback;
|
|
13
|
-
|
|
13
|
+
#neverError;
|
|
14
14
|
constructor(registry, typeName = 'DoNotConstruct') {
|
|
15
15
|
this.registry = registry;
|
|
16
|
-
this
|
|
17
|
-
throw this
|
|
16
|
+
this.#neverError = new Error(`DoNotConstruct: Cannot construct unknown type ${typeName}`);
|
|
17
|
+
throw this.#neverError;
|
|
18
18
|
}
|
|
19
19
|
static with(typeName) {
|
|
20
20
|
return class extends DoNotConstruct {
|
|
@@ -27,73 +27,73 @@ class DoNotConstruct {
|
|
|
27
27
|
* @description The length of the value when encoded as a Uint8Array
|
|
28
28
|
*/
|
|
29
29
|
get encodedLength() {
|
|
30
|
-
throw this
|
|
30
|
+
throw this.#neverError;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* @description returns a hash of the contents
|
|
34
34
|
*/
|
|
35
35
|
get hash() {
|
|
36
|
-
throw this
|
|
36
|
+
throw this.#neverError;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* @description Checks if the value is an empty value (always true)
|
|
40
40
|
*/
|
|
41
41
|
get isEmpty() {
|
|
42
|
-
throw this
|
|
42
|
+
throw this.#neverError;
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
45
|
* @description Unimplemented
|
|
46
46
|
*/
|
|
47
47
|
eq() {
|
|
48
|
-
throw this
|
|
48
|
+
throw this.#neverError;
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* @description Unimplemented
|
|
52
52
|
*/
|
|
53
53
|
inspect() {
|
|
54
|
-
throw this
|
|
54
|
+
throw this.#neverError;
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* @description Unimplemented
|
|
58
58
|
*/
|
|
59
59
|
toHex() {
|
|
60
|
-
throw this
|
|
60
|
+
throw this.#neverError;
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
63
|
* @description Unimplemented
|
|
64
64
|
*/
|
|
65
65
|
toHuman() {
|
|
66
|
-
throw this
|
|
66
|
+
throw this.#neverError;
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* @description Unimplemented
|
|
70
70
|
*/
|
|
71
71
|
toJSON() {
|
|
72
|
-
throw this
|
|
72
|
+
throw this.#neverError;
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* @description Unimplemented
|
|
76
76
|
*/
|
|
77
77
|
toPrimitive() {
|
|
78
|
-
throw this
|
|
78
|
+
throw this.#neverError;
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* @description Unimplemented
|
|
82
82
|
*/
|
|
83
83
|
toRawType() {
|
|
84
|
-
throw this
|
|
84
|
+
throw this.#neverError;
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
87
87
|
* @description Unimplemented
|
|
88
88
|
*/
|
|
89
89
|
toString() {
|
|
90
|
-
throw this
|
|
90
|
+
throw this.#neverError;
|
|
91
91
|
}
|
|
92
92
|
/**
|
|
93
93
|
* @description Unimplemented
|
|
94
94
|
*/
|
|
95
95
|
toU8a() {
|
|
96
|
-
throw this
|
|
96
|
+
throw this.#neverError;
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
exports.DoNotConstruct = DoNotConstruct;
|