@polkadot/types-codec 16.2.1 → 16.3.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/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/abstract/Base.js
CHANGED
|
@@ -7,10 +7,10 @@ export class AbstractBase {
|
|
|
7
7
|
createdAtHash;
|
|
8
8
|
initialU8aLength;
|
|
9
9
|
isStorageFallback;
|
|
10
|
-
|
|
10
|
+
#raw;
|
|
11
11
|
constructor(registry, value, initialU8aLength) {
|
|
12
12
|
this.initialU8aLength = initialU8aLength;
|
|
13
|
-
this
|
|
13
|
+
this.#raw = value;
|
|
14
14
|
this.registry = registry;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
@@ -29,73 +29,73 @@ export class AbstractBase {
|
|
|
29
29
|
* @description returns the inner (wrapped value)
|
|
30
30
|
*/
|
|
31
31
|
get inner() {
|
|
32
|
-
return this
|
|
32
|
+
return this.#raw;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* @description Checks if the value is an empty value
|
|
36
36
|
*/
|
|
37
37
|
get isEmpty() {
|
|
38
|
-
return this.
|
|
38
|
+
return this.#raw.isEmpty;
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* @description Compares the value of the input to see if there is a match
|
|
42
42
|
*/
|
|
43
43
|
eq(other) {
|
|
44
|
-
return this.
|
|
44
|
+
return this.#raw.eq(other);
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
48
48
|
*/
|
|
49
49
|
inspect() {
|
|
50
|
-
return this.
|
|
50
|
+
return this.#raw.inspect();
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
54
54
|
*/
|
|
55
55
|
toHex(isLe) {
|
|
56
|
-
return this.
|
|
56
|
+
return this.#raw.toHex(isLe);
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
59
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
60
60
|
*/
|
|
61
61
|
toHuman(isExtended, disableAscii) {
|
|
62
|
-
return this.
|
|
62
|
+
return this.#raw.toHuman(isExtended, disableAscii);
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
66
66
|
*/
|
|
67
67
|
toJSON() {
|
|
68
|
-
return this.
|
|
68
|
+
return this.#raw.toJSON();
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
71
|
* @description Converts the value in a best-fit primitive form
|
|
72
72
|
*/
|
|
73
73
|
toPrimitive(disableAscii) {
|
|
74
|
-
return this.
|
|
74
|
+
return this.#raw.toPrimitive(disableAscii);
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
77
|
* @description Returns the string representation of the value
|
|
78
78
|
*/
|
|
79
79
|
toString() {
|
|
80
|
-
return this.
|
|
80
|
+
return this.#raw.toString();
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
84
84
|
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
85
85
|
*/
|
|
86
86
|
toU8a(isBare) {
|
|
87
|
-
return this.
|
|
87
|
+
return this.#raw.toU8a(isBare);
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* @description Returns the inner wrapped value (equivalent to valueOf)
|
|
91
91
|
*/
|
|
92
92
|
unwrap() {
|
|
93
|
-
return this
|
|
93
|
+
return this.#raw;
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
96
|
* @description Returns the inner wrapped value
|
|
97
97
|
*/
|
|
98
98
|
valueOf() {
|
|
99
|
-
return this
|
|
99
|
+
return this.#raw;
|
|
100
100
|
}
|
|
101
101
|
}
|
package/abstract/Int.js
CHANGED
|
@@ -64,7 +64,7 @@ export class AbstractInt extends BN {
|
|
|
64
64
|
createdAtHash;
|
|
65
65
|
initialU8aLength;
|
|
66
66
|
isStorageFallback;
|
|
67
|
-
|
|
67
|
+
#bitLength;
|
|
68
68
|
constructor(registry, value = 0, bitLength = DEFAULT_UINT_BITS, isSigned = false) {
|
|
69
69
|
// Construct via a string/number, which will be passed in the BN constructor.
|
|
70
70
|
// It would be ideal to actually return a BN, but there is an issue:
|
|
@@ -77,9 +77,9 @@ export class AbstractInt extends BN {
|
|
|
77
77
|
: u8aToBn(value.subarray(0, bitLength / 8), { isLe: true, isNegative: isSigned }).toString()
|
|
78
78
|
: decodeAbstractInt(value, isSigned));
|
|
79
79
|
this.registry = registry;
|
|
80
|
-
this
|
|
81
|
-
this.encodedLength = this
|
|
82
|
-
this.initialU8aLength = this
|
|
80
|
+
this.#bitLength = bitLength;
|
|
81
|
+
this.encodedLength = this.#bitLength / 8;
|
|
82
|
+
this.initialU8aLength = this.#bitLength / 8;
|
|
83
83
|
this.isUnsigned = !isSigned;
|
|
84
84
|
const isNegative = this.isNeg();
|
|
85
85
|
const maxBits = bitLength - (isSigned && !isNegative ? 1 : 0);
|
|
@@ -106,7 +106,7 @@ export class AbstractInt extends BN {
|
|
|
106
106
|
* @description Returns the number of bits in the value
|
|
107
107
|
*/
|
|
108
108
|
bitLength() {
|
|
109
|
-
return this
|
|
109
|
+
return this.#bitLength;
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
112
|
* @description Compares the value of the input to see if there is a match
|
|
@@ -132,7 +132,7 @@ export class AbstractInt extends BN {
|
|
|
132
132
|
*/
|
|
133
133
|
isMax() {
|
|
134
134
|
const u8a = this.toU8a().filter((b) => b === 0xff);
|
|
135
|
-
return u8a.length === (this
|
|
135
|
+
return u8a.length === (this.#bitLength / 8);
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
138
138
|
* @description Returns a BigInt representation of the number
|
|
@@ -181,8 +181,8 @@ export class AbstractInt extends BN {
|
|
|
181
181
|
// FIXME this return type should by string | number, however BN returns string
|
|
182
182
|
// Options here are
|
|
183
183
|
// - super.bitLength() - the actual used bits, use hex when close to MAX_SAFE_INTEGER
|
|
184
|
-
// - this
|
|
185
|
-
return onlyHex || (this
|
|
184
|
+
// - this.#bitLength - the max used bits, use hex when larger than native Rust type
|
|
185
|
+
return onlyHex || (this.#bitLength > 128) || (super.bitLength() > MAX_NUMBER_BITS)
|
|
186
186
|
? this.toHex()
|
|
187
187
|
: this.toNumber();
|
|
188
188
|
}
|
package/base/Compact.js
CHANGED
|
@@ -31,14 +31,14 @@ export class Compact {
|
|
|
31
31
|
createdAtHash;
|
|
32
32
|
initialU8aLength;
|
|
33
33
|
isStorageFallback;
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
#Type;
|
|
35
|
+
#raw;
|
|
36
36
|
constructor(registry, Type, value = 0, { definition, setDefinition = identity } = {}) {
|
|
37
37
|
this.registry = registry;
|
|
38
|
-
this
|
|
39
|
-
const [raw, decodedLength] = decodeCompact(registry, this
|
|
38
|
+
this.#Type = definition || setDefinition(typeToConstructor(registry, Type));
|
|
39
|
+
const [raw, decodedLength] = decodeCompact(registry, this.#Type, value);
|
|
40
40
|
this.initialU8aLength = decodedLength;
|
|
41
|
-
this
|
|
41
|
+
this.#raw = raw;
|
|
42
42
|
}
|
|
43
43
|
static with(Type) {
|
|
44
44
|
let definition;
|
|
@@ -66,20 +66,20 @@ export class Compact {
|
|
|
66
66
|
* @description Checks if the value is an empty value
|
|
67
67
|
*/
|
|
68
68
|
get isEmpty() {
|
|
69
|
-
return this.
|
|
69
|
+
return this.#raw.isEmpty;
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* @description Returns the number of bits in the value
|
|
73
73
|
*/
|
|
74
74
|
bitLength() {
|
|
75
|
-
return this.
|
|
75
|
+
return this.#raw.bitLength();
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* @description Compares the value of the input to see if there is a match
|
|
79
79
|
*/
|
|
80
80
|
eq(other) {
|
|
81
|
-
return this.
|
|
82
|
-
? other
|
|
81
|
+
return this.#raw.eq(other instanceof Compact
|
|
82
|
+
? other.#raw
|
|
83
83
|
: other);
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
@@ -94,66 +94,66 @@ export class Compact {
|
|
|
94
94
|
* @description Returns a BigInt representation of the number
|
|
95
95
|
*/
|
|
96
96
|
toBigInt() {
|
|
97
|
-
return this.
|
|
97
|
+
return this.#raw.toBigInt();
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
100
100
|
* @description Returns the BN representation of the number
|
|
101
101
|
*/
|
|
102
102
|
toBn() {
|
|
103
|
-
return this.
|
|
103
|
+
return this.#raw.toBn();
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
107
107
|
*/
|
|
108
108
|
toHex(isLe) {
|
|
109
|
-
return this.
|
|
109
|
+
return this.#raw.toHex(isLe);
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
112
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
113
113
|
*/
|
|
114
114
|
toHuman(isExtended, disableAscii) {
|
|
115
|
-
return this.
|
|
115
|
+
return this.#raw.toHuman(isExtended, disableAscii);
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
118
118
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
119
119
|
*/
|
|
120
120
|
toJSON() {
|
|
121
|
-
return this.
|
|
121
|
+
return this.#raw.toJSON();
|
|
122
122
|
}
|
|
123
123
|
/**
|
|
124
124
|
* @description Returns the number representation for the value
|
|
125
125
|
*/
|
|
126
126
|
toNumber() {
|
|
127
|
-
return this.
|
|
127
|
+
return this.#raw.toNumber();
|
|
128
128
|
}
|
|
129
129
|
/**
|
|
130
130
|
* @description Converts the value in a best-fit primitive form
|
|
131
131
|
*/
|
|
132
132
|
toPrimitive(disableAscii) {
|
|
133
|
-
return this.
|
|
133
|
+
return this.#raw.toPrimitive(disableAscii);
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
136
136
|
* @description Returns the base runtime type name for this instance
|
|
137
137
|
*/
|
|
138
138
|
toRawType() {
|
|
139
|
-
return `Compact<${this.registry.getClassName(this
|
|
139
|
+
return `Compact<${this.registry.getClassName(this.#Type) || this.#raw.toRawType()}>`;
|
|
140
140
|
}
|
|
141
141
|
/**
|
|
142
142
|
* @description Returns the string representation of the value
|
|
143
143
|
*/
|
|
144
144
|
toString() {
|
|
145
|
-
return this.
|
|
145
|
+
return this.#raw.toString();
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
148
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
149
149
|
*/
|
|
150
150
|
toU8a(_isBare) {
|
|
151
|
-
return compactToU8a(this.
|
|
151
|
+
return compactToU8a(this.#raw.toBn());
|
|
152
152
|
}
|
|
153
153
|
/**
|
|
154
154
|
* @description Returns the embedded [[UInt]] or [[Moment]] value
|
|
155
155
|
*/
|
|
156
156
|
unwrap() {
|
|
157
|
-
return this
|
|
157
|
+
return this.#raw;
|
|
158
158
|
}
|
|
159
159
|
}
|
package/base/DoNotConstruct.js
CHANGED
|
@@ -7,11 +7,11 @@ export class DoNotConstruct {
|
|
|
7
7
|
registry;
|
|
8
8
|
createdAtHash;
|
|
9
9
|
isStorageFallback;
|
|
10
|
-
|
|
10
|
+
#neverError;
|
|
11
11
|
constructor(registry, typeName = 'DoNotConstruct') {
|
|
12
12
|
this.registry = registry;
|
|
13
|
-
this
|
|
14
|
-
throw this
|
|
13
|
+
this.#neverError = new Error(`DoNotConstruct: Cannot construct unknown type ${typeName}`);
|
|
14
|
+
throw this.#neverError;
|
|
15
15
|
}
|
|
16
16
|
static with(typeName) {
|
|
17
17
|
return class extends DoNotConstruct {
|
|
@@ -24,72 +24,72 @@ export class DoNotConstruct {
|
|
|
24
24
|
* @description The length of the value when encoded as a Uint8Array
|
|
25
25
|
*/
|
|
26
26
|
get encodedLength() {
|
|
27
|
-
throw this
|
|
27
|
+
throw this.#neverError;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* @description returns a hash of the contents
|
|
31
31
|
*/
|
|
32
32
|
get hash() {
|
|
33
|
-
throw this
|
|
33
|
+
throw this.#neverError;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* @description Checks if the value is an empty value (always true)
|
|
37
37
|
*/
|
|
38
38
|
get isEmpty() {
|
|
39
|
-
throw this
|
|
39
|
+
throw this.#neverError;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* @description Unimplemented
|
|
43
43
|
*/
|
|
44
44
|
eq() {
|
|
45
|
-
throw this
|
|
45
|
+
throw this.#neverError;
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* @description Unimplemented
|
|
49
49
|
*/
|
|
50
50
|
inspect() {
|
|
51
|
-
throw this
|
|
51
|
+
throw this.#neverError;
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* @description Unimplemented
|
|
55
55
|
*/
|
|
56
56
|
toHex() {
|
|
57
|
-
throw this
|
|
57
|
+
throw this.#neverError;
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
60
|
* @description Unimplemented
|
|
61
61
|
*/
|
|
62
62
|
toHuman() {
|
|
63
|
-
throw this
|
|
63
|
+
throw this.#neverError;
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* @description Unimplemented
|
|
67
67
|
*/
|
|
68
68
|
toJSON() {
|
|
69
|
-
throw this
|
|
69
|
+
throw this.#neverError;
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* @description Unimplemented
|
|
73
73
|
*/
|
|
74
74
|
toPrimitive() {
|
|
75
|
-
throw this
|
|
75
|
+
throw this.#neverError;
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* @description Unimplemented
|
|
79
79
|
*/
|
|
80
80
|
toRawType() {
|
|
81
|
-
throw this
|
|
81
|
+
throw this.#neverError;
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
84
|
* @description Unimplemented
|
|
85
85
|
*/
|
|
86
86
|
toString() {
|
|
87
|
-
throw this
|
|
87
|
+
throw this.#neverError;
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* @description Unimplemented
|
|
91
91
|
*/
|
|
92
92
|
toU8a() {
|
|
93
|
-
throw this
|
|
93
|
+
throw this.#neverError;
|
|
94
94
|
}
|
|
95
95
|
}
|
package/base/Enum.js
CHANGED
|
@@ -127,12 +127,12 @@ export class Enum {
|
|
|
127
127
|
createdAtHash;
|
|
128
128
|
initialU8aLength;
|
|
129
129
|
isStorageFallback;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
130
|
+
#def;
|
|
131
|
+
#entryIndex;
|
|
132
|
+
#indexes;
|
|
133
|
+
#isBasic;
|
|
134
|
+
#isIndexed;
|
|
135
|
+
#raw;
|
|
136
136
|
constructor(registry, Types, value, index, { definition, setDefinition = identity } = {}) {
|
|
137
137
|
const { def, isBasic, isIndexed } = definition || setDefinition(extractDef(registry, Types));
|
|
138
138
|
// shortcut isU8a as used in SCALE decoding
|
|
@@ -140,14 +140,14 @@ export class Enum {
|
|
|
140
140
|
? createFromU8a(registry, def, value[0], value.subarray(1))
|
|
141
141
|
: decodeEnum(registry, def, value, index);
|
|
142
142
|
this.registry = registry;
|
|
143
|
-
this
|
|
144
|
-
this
|
|
145
|
-
this
|
|
146
|
-
this
|
|
147
|
-
this
|
|
148
|
-
this
|
|
149
|
-
if (this.
|
|
150
|
-
this.initialU8aLength = 1 + this.
|
|
143
|
+
this.#def = def;
|
|
144
|
+
this.#isBasic = isBasic;
|
|
145
|
+
this.#isIndexed = isIndexed;
|
|
146
|
+
this.#indexes = Object.values(def).map(({ index }) => index);
|
|
147
|
+
this.#entryIndex = this.#indexes.indexOf(decoded.index);
|
|
148
|
+
this.#raw = decoded.value;
|
|
149
|
+
if (this.#raw.initialU8aLength) {
|
|
150
|
+
this.initialU8aLength = 1 + this.#raw.initialU8aLength;
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
static with(Types) {
|
|
@@ -184,7 +184,7 @@ export class Enum {
|
|
|
184
184
|
* @description The length of the value when encoded as a Uint8Array
|
|
185
185
|
*/
|
|
186
186
|
get encodedLength() {
|
|
187
|
-
return 1 + this.
|
|
187
|
+
return 1 + this.#raw.encodedLength;
|
|
188
188
|
}
|
|
189
189
|
/**
|
|
190
190
|
* @description returns a hash of the contents
|
|
@@ -196,55 +196,55 @@ export class Enum {
|
|
|
196
196
|
* @description The index of the enum value
|
|
197
197
|
*/
|
|
198
198
|
get index() {
|
|
199
|
-
return this
|
|
199
|
+
return this.#indexes[this.#entryIndex];
|
|
200
200
|
}
|
|
201
201
|
/**
|
|
202
202
|
* @description The value of the enum
|
|
203
203
|
*/
|
|
204
204
|
get inner() {
|
|
205
|
-
return this
|
|
205
|
+
return this.#raw;
|
|
206
206
|
}
|
|
207
207
|
/**
|
|
208
208
|
* @description true if this is a basic enum (no values)
|
|
209
209
|
*/
|
|
210
210
|
get isBasic() {
|
|
211
|
-
return this
|
|
211
|
+
return this.#isBasic;
|
|
212
212
|
}
|
|
213
213
|
/**
|
|
214
214
|
* @description Checks if the value is an empty value
|
|
215
215
|
*/
|
|
216
216
|
get isEmpty() {
|
|
217
|
-
return this.
|
|
217
|
+
return this.#raw.isEmpty;
|
|
218
218
|
}
|
|
219
219
|
/**
|
|
220
220
|
* @description Checks if the Enum points to a [[Null]] type
|
|
221
221
|
*/
|
|
222
222
|
get isNone() {
|
|
223
|
-
return this
|
|
223
|
+
return this.#raw instanceof Null;
|
|
224
224
|
}
|
|
225
225
|
/**
|
|
226
226
|
* @description The available keys for this enum
|
|
227
227
|
*/
|
|
228
228
|
get defIndexes() {
|
|
229
|
-
return this
|
|
229
|
+
return this.#indexes;
|
|
230
230
|
}
|
|
231
231
|
/**
|
|
232
232
|
* @description The available keys for this enum
|
|
233
233
|
*/
|
|
234
234
|
get defKeys() {
|
|
235
|
-
return Object.keys(this
|
|
235
|
+
return Object.keys(this.#def);
|
|
236
236
|
}
|
|
237
237
|
/**
|
|
238
238
|
* @description The name of the type this enum value represents
|
|
239
239
|
*/
|
|
240
240
|
get type() {
|
|
241
|
-
return this.defKeys[this
|
|
241
|
+
return this.defKeys[this.#entryIndex];
|
|
242
242
|
}
|
|
243
243
|
/**
|
|
244
244
|
* @description The value of the enum
|
|
245
245
|
*/
|
|
246
246
|
get value() {
|
|
247
|
-
return this
|
|
247
|
+
return this.#raw;
|
|
248
248
|
}
|
|
249
249
|
/**
|
|
250
250
|
* @description Compares the value of the input to see if there is a match
|
|
@@ -257,7 +257,7 @@ export class Enum {
|
|
|
257
257
|
else if (isNumber(other)) {
|
|
258
258
|
return this.toNumber() === other;
|
|
259
259
|
}
|
|
260
|
-
else if (this
|
|
260
|
+
else if (this.#isBasic && isString(other)) {
|
|
261
261
|
return this.type === other;
|
|
262
262
|
}
|
|
263
263
|
else if (isHex(other)) {
|
|
@@ -276,10 +276,10 @@ export class Enum {
|
|
|
276
276
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
277
277
|
*/
|
|
278
278
|
inspect() {
|
|
279
|
-
if (this
|
|
279
|
+
if (this.#isBasic) {
|
|
280
280
|
return { outer: [new Uint8Array([this.index])] };
|
|
281
281
|
}
|
|
282
|
-
const { inner, outer = [] } = this.
|
|
282
|
+
const { inner, outer = [] } = this.#raw.inspect();
|
|
283
283
|
return {
|
|
284
284
|
inner,
|
|
285
285
|
outer: [new Uint8Array([this.index]), ...outer]
|
|
@@ -295,17 +295,17 @@ export class Enum {
|
|
|
295
295
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
296
296
|
*/
|
|
297
297
|
toHuman(isExtended, disableAscii) {
|
|
298
|
-
return this
|
|
298
|
+
return this.#isBasic || this.isNone
|
|
299
299
|
? this.type
|
|
300
|
-
: { [this.type]: this.
|
|
300
|
+
: { [this.type]: this.#raw.toHuman(isExtended, disableAscii) };
|
|
301
301
|
}
|
|
302
302
|
/**
|
|
303
303
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
304
304
|
*/
|
|
305
305
|
toJSON() {
|
|
306
|
-
return this
|
|
306
|
+
return this.#isBasic
|
|
307
307
|
? this.type
|
|
308
|
-
: { [stringCamelCase(this.type)]: this.
|
|
308
|
+
: { [stringCamelCase(this.type)]: this.#raw.toJSON() };
|
|
309
309
|
}
|
|
310
310
|
/**
|
|
311
311
|
* @description Returns the number representation for the value
|
|
@@ -317,23 +317,23 @@ export class Enum {
|
|
|
317
317
|
* @description Converts the value in a best-fit primitive form
|
|
318
318
|
*/
|
|
319
319
|
toPrimitive(disableAscii) {
|
|
320
|
-
return this
|
|
320
|
+
return this.#isBasic
|
|
321
321
|
? this.type
|
|
322
|
-
: { [stringCamelCase(this.type)]: this.
|
|
322
|
+
: { [stringCamelCase(this.type)]: this.#raw.toPrimitive(disableAscii) };
|
|
323
323
|
}
|
|
324
324
|
/**
|
|
325
325
|
* @description Returns a raw struct representation of the enum types
|
|
326
326
|
*/
|
|
327
327
|
_toRawStruct() {
|
|
328
|
-
if (this
|
|
329
|
-
return this
|
|
328
|
+
if (this.#isBasic) {
|
|
329
|
+
return this.#isIndexed
|
|
330
330
|
? this.defKeys.reduce((out, key, index) => {
|
|
331
|
-
out[key] = this
|
|
331
|
+
out[key] = this.#indexes[index];
|
|
332
332
|
return out;
|
|
333
333
|
}, {})
|
|
334
334
|
: this.defKeys;
|
|
335
335
|
}
|
|
336
|
-
const entries = Object.entries(this
|
|
336
|
+
const entries = Object.entries(this.#def);
|
|
337
337
|
return typesToMap(this.registry, entries.reduce((out, [key, { Type }], i) => {
|
|
338
338
|
out[0][i] = Type;
|
|
339
339
|
out[1][i] = key;
|
|
@@ -360,10 +360,10 @@ export class Enum {
|
|
|
360
360
|
*/
|
|
361
361
|
toU8a(isBare) {
|
|
362
362
|
return isBare
|
|
363
|
-
? this.
|
|
363
|
+
? this.#raw.toU8a(isBare)
|
|
364
364
|
: u8aConcatStrict([
|
|
365
365
|
new Uint8Array([this.index]),
|
|
366
|
-
this.
|
|
366
|
+
this.#raw.toU8a(isBare)
|
|
367
367
|
]);
|
|
368
368
|
}
|
|
369
369
|
}
|