@polkadot/types-codec 9.5.1 → 9.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/abstract/Array.js +15 -44
- package/abstract/Base.js +12 -28
- package/abstract/BigInt.js +3 -2
- package/abstract/Int.js +25 -52
- package/abstract/index.js +1 -0
- package/base/Compact.js +21 -45
- package/base/DoNotConstruct.js +3 -19
- package/base/Enum.js +37 -88
- package/base/Int.js +2 -5
- package/base/Null.js +12 -23
- package/base/Option.js +23 -59
- package/base/Result.js +8 -19
- package/base/Tuple.js +12 -29
- package/base/UInt.js +2 -4
- package/base/Vec.js +7 -25
- package/base/VecAny.js +2 -2
- package/base/VecFixed.js +8 -20
- package/base/index.js +1 -0
- package/bundle.js +1 -0
- package/cjs/abstract/Array.js +13 -47
- package/cjs/abstract/Base.js +12 -30
- package/cjs/abstract/BigInt.js +1 -4
- package/cjs/abstract/Int.js +25 -55
- package/cjs/abstract/index.js +0 -3
- package/cjs/base/Compact.js +21 -48
- package/cjs/base/DoNotConstruct.js +3 -21
- package/cjs/base/Enum.js +34 -92
- package/cjs/base/Int.js +0 -7
- package/cjs/base/Null.js +10 -25
- package/cjs/base/Option.js +23 -63
- package/cjs/base/Result.js +6 -21
- package/cjs/base/Tuple.js +12 -33
- package/cjs/base/UInt.js +0 -6
- package/cjs/base/Vec.js +7 -31
- package/cjs/base/VecAny.js +0 -4
- package/cjs/base/VecFixed.js +8 -25
- package/cjs/base/index.js +0 -12
- package/cjs/bundle.js +0 -13
- package/cjs/detectPackage.js +2 -4
- package/cjs/extended/BTreeMap.js +1 -5
- package/cjs/extended/BTreeSet.js +17 -57
- package/cjs/extended/BitVec.js +11 -25
- package/cjs/extended/Bytes.js +9 -20
- package/cjs/extended/HashMap.js +1 -5
- package/cjs/extended/Linkage.js +5 -20
- package/cjs/extended/Map.js +16 -62
- package/cjs/extended/OptionBool.js +8 -21
- package/cjs/extended/Range.js +3 -13
- package/cjs/extended/RangeInclusive.js +1 -6
- package/cjs/extended/Type.js +1 -7
- package/cjs/extended/U8aFixed.js +2 -15
- package/cjs/extended/WrapperKeepOpaque.js +8 -28
- package/cjs/extended/WrapperOpaque.js +2 -8
- package/cjs/extended/index.js +0 -14
- package/cjs/index.js +0 -3
- package/cjs/native/Bool.js +14 -32
- package/cjs/native/Date.js +18 -40
- package/cjs/native/Float.js +11 -29
- package/cjs/native/Json.js +14 -33
- package/cjs/native/Raw.js +18 -41
- package/cjs/native/Set.js +21 -67
- package/cjs/native/Struct.data.js +1 -0
- package/cjs/native/Struct.js +33 -83
- package/cjs/native/Text.js +20 -44
- package/cjs/native/index.js +0 -8
- package/cjs/packageInfo.js +3 -1
- package/cjs/primitive/F32.js +0 -3
- package/cjs/primitive/F64.js +0 -3
- package/cjs/primitive/I128.js +0 -3
- package/cjs/primitive/I16.js +0 -3
- package/cjs/primitive/I256.js +0 -3
- package/cjs/primitive/I32.js +0 -3
- package/cjs/primitive/I64.js +0 -3
- package/cjs/primitive/I8.js +0 -3
- package/cjs/primitive/U128.js +0 -3
- package/cjs/primitive/U16.js +0 -3
- package/cjs/primitive/U256.js +0 -3
- package/cjs/primitive/U32.js +0 -3
- package/cjs/primitive/U64.js +0 -3
- package/cjs/primitive/U8.js +0 -3
- package/cjs/primitive/USize.js +0 -4
- package/cjs/primitive/index.js +0 -15
- package/cjs/types/index.js +0 -8
- package/cjs/utils/compareArray.js +1 -4
- package/cjs/utils/compareMap.js +4 -9
- package/cjs/utils/compareSet.js +4 -6
- package/cjs/utils/decodeU8a.js +7 -17
- package/cjs/utils/index.js +0 -9
- package/cjs/utils/mapToTypeMap.js +0 -4
- package/cjs/utils/sanitize.js +66 -71
- package/cjs/utils/sortValues.js +5 -18
- package/cjs/utils/typeToConstructor.js +1 -2
- package/cjs/utils/typesToMap.js +1 -3
- package/cjs/utils/util.js +1 -2
- package/detectOther.js +2 -0
- package/detectPackage.js +2 -0
- package/extended/BTreeMap.js +1 -2
- package/extended/BTreeSet.js +17 -53
- package/extended/BitVec.js +13 -22
- package/extended/Bytes.js +11 -17
- package/extended/HashMap.js +1 -2
- package/extended/Linkage.js +5 -12
- package/extended/Map.js +16 -54
- package/extended/OptionBool.js +8 -17
- package/extended/Range.js +4 -11
- package/extended/RangeInclusive.js +1 -3
- package/extended/Type.js +3 -4
- package/extended/U8aFixed.js +4 -12
- package/extended/WrapperKeepOpaque.js +8 -23
- package/extended/WrapperOpaque.js +2 -5
- package/extended/index.js +1 -0
- package/index.js +1 -0
- package/native/Bool.js +16 -30
- package/native/Date.js +18 -37
- package/native/Float.js +12 -27
- package/native/Json.js +16 -30
- package/native/Raw.js +20 -39
- package/native/Set.js +21 -63
- package/native/Struct.data.js +1 -0
- package/native/Struct.js +33 -80
- package/native/Text.js +20 -40
- package/native/index.js +1 -0
- package/package.json +4 -4
- package/packageInfo.js +3 -1
- package/primitive/F32.js +2 -1
- package/primitive/F64.js +2 -1
- package/primitive/I128.js +2 -1
- package/primitive/I16.js +2 -1
- package/primitive/I256.js +2 -1
- package/primitive/I32.js +2 -1
- package/primitive/I64.js +2 -1
- package/primitive/I8.js +2 -1
- package/primitive/U128.js +2 -1
- package/primitive/U16.js +2 -1
- package/primitive/U256.js +2 -1
- package/primitive/U32.js +2 -1
- package/primitive/U64.js +2 -1
- package/primitive/U8.js +2 -1
- package/primitive/USize.js +2 -2
- package/primitive/index.js +1 -0
- package/types/index.js +1 -0
- package/utils/compareArray.js +4 -3
- package/utils/compareMap.js +4 -7
- package/utils/compareSet.js +4 -5
- package/utils/decodeU8a.js +9 -14
- package/utils/index.js +1 -0
- package/utils/mapToTypeMap.js +2 -3
- package/utils/sanitize.js +66 -60
- package/utils/sortValues.js +6 -15
- package/utils/typeToConstructor.js +1 -0
- package/utils/typesToMap.js +1 -2
- package/utils/util.js +1 -0
package/cjs/extended/HashMap.js
CHANGED
|
@@ -4,21 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.HashMap = void 0;
|
|
7
|
-
|
|
8
7
|
var _Map = require("./Map");
|
|
9
|
-
|
|
10
8
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
11
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
10
|
+
|
|
12
11
|
class HashMap extends _Map.CodecMap {
|
|
13
12
|
static with(keyType, valType) {
|
|
14
13
|
return class extends HashMap {
|
|
15
14
|
constructor(registry, value) {
|
|
16
15
|
super(registry, keyType, valType, value);
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
};
|
|
20
18
|
}
|
|
21
|
-
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
exports.HashMap = HashMap;
|
package/cjs/extended/Linkage.js
CHANGED
|
@@ -4,23 +4,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.LinkageResult = exports.Linkage = void 0;
|
|
7
|
-
|
|
8
7
|
var _Option = require("../base/Option");
|
|
9
|
-
|
|
10
8
|
var _Tuple = require("../base/Tuple");
|
|
11
|
-
|
|
12
9
|
var _Vec = require("../base/Vec");
|
|
13
|
-
|
|
14
10
|
var _Struct = require("../native/Struct");
|
|
15
|
-
|
|
16
11
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
17
12
|
// SPDX-License-Identifier: Apache-2.0
|
|
13
|
+
|
|
18
14
|
const EMPTY = new Uint8Array();
|
|
15
|
+
|
|
19
16
|
/**
|
|
20
17
|
* @name Linkage
|
|
21
18
|
* @description The wrapper for the result from a LinkedMap
|
|
22
19
|
*/
|
|
23
|
-
|
|
24
20
|
class Linkage extends _Struct.Struct {
|
|
25
21
|
constructor(registry, Type, value) {
|
|
26
22
|
super(registry, {
|
|
@@ -29,51 +25,42 @@ class Linkage extends _Struct.Struct {
|
|
|
29
25
|
next: _Option.Option.with(Type)
|
|
30
26
|
}, value);
|
|
31
27
|
}
|
|
32
|
-
|
|
33
28
|
static withKey(Type) {
|
|
34
29
|
return class extends Linkage {
|
|
35
30
|
constructor(registry, value) {
|
|
36
31
|
super(registry, Type, value);
|
|
37
32
|
}
|
|
38
|
-
|
|
39
33
|
};
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
get previous() {
|
|
43
36
|
return this.get('previous');
|
|
44
37
|
}
|
|
45
|
-
|
|
46
38
|
get next() {
|
|
47
39
|
return this.get('next');
|
|
48
40
|
}
|
|
41
|
+
|
|
49
42
|
/**
|
|
50
43
|
* @description Returns the base runtime type name for this instance
|
|
51
44
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
45
|
toRawType() {
|
|
55
46
|
return `Linkage<${this.next.toRawType(true)}>`;
|
|
56
47
|
}
|
|
48
|
+
|
|
57
49
|
/**
|
|
58
50
|
* @description Custom toU8a which with bare mode does not return the linkage if empty
|
|
59
51
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
52
|
toU8a() {
|
|
63
53
|
// As part of a storage query (where these appear), in the case of empty, the values
|
|
64
54
|
// are NOT populated by the node - follow the same logic, leaving it empty
|
|
65
55
|
return this.isEmpty ? EMPTY : super.toU8a();
|
|
66
56
|
}
|
|
67
|
-
|
|
68
57
|
}
|
|
58
|
+
|
|
69
59
|
/**
|
|
70
60
|
* @name LinkageResult
|
|
71
61
|
* @description A Linkage keys/Values tuple
|
|
72
62
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
63
|
exports.Linkage = Linkage;
|
|
76
|
-
|
|
77
64
|
class LinkageResult extends _Tuple.Tuple {
|
|
78
65
|
constructor(registry, _ref, _ref2) {
|
|
79
66
|
let [TypeKey, keys] = _ref;
|
|
@@ -83,7 +70,5 @@ class LinkageResult extends _Tuple.Tuple {
|
|
|
83
70
|
Values: _Vec.Vec.with(TypeValue)
|
|
84
71
|
}, [keys, values]);
|
|
85
72
|
}
|
|
86
|
-
|
|
87
73
|
}
|
|
88
|
-
|
|
89
74
|
exports.LinkageResult = LinkageResult;
|
package/cjs/extended/Map.js
CHANGED
|
@@ -4,50 +4,37 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.CodecMap = void 0;
|
|
7
|
-
|
|
8
7
|
var _util = require("@polkadot/util");
|
|
9
|
-
|
|
10
8
|
var _Array = require("../abstract/Array");
|
|
11
|
-
|
|
12
9
|
var _Enum = require("../base/Enum");
|
|
13
|
-
|
|
14
10
|
var _Raw = require("../native/Raw");
|
|
15
|
-
|
|
16
11
|
var _Struct = require("../native/Struct");
|
|
17
|
-
|
|
18
12
|
var _utils = require("../utils");
|
|
19
|
-
|
|
20
13
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
21
14
|
// SPDX-License-Identifier: Apache-2.0
|
|
15
|
+
|
|
22
16
|
const l = (0, _util.logger)('Map');
|
|
23
|
-
/** @internal */
|
|
24
17
|
|
|
18
|
+
/** @internal */
|
|
25
19
|
function decodeMapFromU8a(registry, KeyClass, ValClass, u8a) {
|
|
26
20
|
const output = new Map();
|
|
27
21
|
const [offset, count] = (0, _util.compactFromU8aLim)(u8a);
|
|
28
22
|
const types = [];
|
|
29
|
-
|
|
30
23
|
for (let i = 0; i < count; i++) {
|
|
31
24
|
types.push(KeyClass, ValClass);
|
|
32
25
|
}
|
|
33
|
-
|
|
34
26
|
const [values, decodedLength] = (0, _utils.decodeU8a)(registry, new Array(types.length), u8a.subarray(offset), [types, []]);
|
|
35
|
-
|
|
36
27
|
for (let i = 0; i < values.length; i += 2) {
|
|
37
28
|
output.set(values[i], values[i + 1]);
|
|
38
29
|
}
|
|
39
|
-
|
|
40
30
|
return [KeyClass, ValClass, output, offset + decodedLength];
|
|
41
31
|
}
|
|
42
|
-
/** @internal */
|
|
43
|
-
|
|
44
32
|
|
|
33
|
+
/** @internal */
|
|
45
34
|
function decodeMapFromMap(registry, KeyClass, ValClass, value) {
|
|
46
35
|
const output = new Map();
|
|
47
|
-
|
|
48
36
|
for (const [key, val] of value.entries()) {
|
|
49
37
|
const isComplex = KeyClass.prototype instanceof _Array.AbstractArray || KeyClass.prototype instanceof _Struct.Struct || KeyClass.prototype instanceof _Enum.Enum;
|
|
50
|
-
|
|
51
38
|
try {
|
|
52
39
|
output.set(key instanceof KeyClass ? key : new KeyClass(registry, isComplex && typeof key === 'string' ? JSON.parse(key) : key), val instanceof ValClass ? val : new ValClass(registry, val));
|
|
53
40
|
} catch (error) {
|
|
@@ -55,9 +42,9 @@ function decodeMapFromMap(registry, KeyClass, ValClass, value) {
|
|
|
55
42
|
throw error;
|
|
56
43
|
}
|
|
57
44
|
}
|
|
58
|
-
|
|
59
45
|
return [KeyClass, ValClass, output, 0];
|
|
60
46
|
}
|
|
47
|
+
|
|
61
48
|
/**
|
|
62
49
|
* Decode input to pass into constructor.
|
|
63
50
|
*
|
|
@@ -73,12 +60,9 @@ function decodeMapFromMap(registry, KeyClass, ValClass, value) {
|
|
|
73
60
|
* @param jsonMap
|
|
74
61
|
* @internal
|
|
75
62
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
78
63
|
function decodeMap(registry, keyType, valType, value) {
|
|
79
64
|
const KeyClass = (0, _utils.typeToConstructor)(registry, keyType);
|
|
80
65
|
const ValClass = (0, _utils.typeToConstructor)(registry, valType);
|
|
81
|
-
|
|
82
66
|
if (!value) {
|
|
83
67
|
return [KeyClass, ValClass, new Map(), 0];
|
|
84
68
|
} else if ((0, _util.isU8a)(value) || (0, _util.isHex)(value)) {
|
|
@@ -88,15 +72,12 @@ function decodeMap(registry, keyType, valType, value) {
|
|
|
88
72
|
} else if ((0, _util.isObject)(value)) {
|
|
89
73
|
return decodeMapFromMap(registry, KeyClass, ValClass, new Map(Object.entries(value)));
|
|
90
74
|
}
|
|
91
|
-
|
|
92
75
|
throw new Error('Map: cannot decode type');
|
|
93
76
|
}
|
|
94
|
-
|
|
95
77
|
class CodecMap extends Map {
|
|
96
78
|
#KeyClass;
|
|
97
79
|
#ValClass;
|
|
98
80
|
#type;
|
|
99
|
-
|
|
100
81
|
constructor(registry, keyType, valType, rawValue) {
|
|
101
82
|
let type = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'HashMap';
|
|
102
83
|
const [KeyClass, ValClass, decoded, decodedLength] = decodeMap(registry, keyType, valType, rawValue);
|
|
@@ -107,148 +88,121 @@ class CodecMap extends Map {
|
|
|
107
88
|
this.#ValClass = ValClass;
|
|
108
89
|
this.#type = type;
|
|
109
90
|
}
|
|
91
|
+
|
|
110
92
|
/**
|
|
111
93
|
* @description The length of the value when encoded as a Uint8Array
|
|
112
94
|
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
95
|
get encodedLength() {
|
|
116
96
|
let len = (0, _util.compactToU8a)(this.size).length;
|
|
117
|
-
|
|
118
97
|
for (const [k, v] of this.entries()) {
|
|
119
98
|
len += k.encodedLength + v.encodedLength;
|
|
120
99
|
}
|
|
121
|
-
|
|
122
100
|
return len;
|
|
123
101
|
}
|
|
102
|
+
|
|
124
103
|
/**
|
|
125
104
|
* @description Returns a hash of the value
|
|
126
105
|
*/
|
|
127
|
-
|
|
128
|
-
|
|
129
106
|
get hash() {
|
|
130
107
|
return this.registry.hash(this.toU8a());
|
|
131
108
|
}
|
|
109
|
+
|
|
132
110
|
/**
|
|
133
111
|
* @description Checks if the value is an empty value
|
|
134
112
|
*/
|
|
135
|
-
|
|
136
|
-
|
|
137
113
|
get isEmpty() {
|
|
138
114
|
return this.size === 0;
|
|
139
115
|
}
|
|
116
|
+
|
|
140
117
|
/**
|
|
141
118
|
* @description Compares the value of the input to see if there is a match
|
|
142
119
|
*/
|
|
143
|
-
|
|
144
|
-
|
|
145
120
|
eq(other) {
|
|
146
121
|
return (0, _utils.compareMap)(this, other);
|
|
147
122
|
}
|
|
123
|
+
|
|
148
124
|
/**
|
|
149
125
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
150
126
|
*/
|
|
151
|
-
|
|
152
|
-
|
|
153
127
|
inspect() {
|
|
154
128
|
const inner = new Array();
|
|
155
|
-
|
|
156
129
|
for (const [k, v] of this.entries()) {
|
|
157
130
|
inner.push(k.inspect());
|
|
158
131
|
inner.push(v.inspect());
|
|
159
132
|
}
|
|
160
|
-
|
|
161
133
|
return {
|
|
162
134
|
inner,
|
|
163
135
|
outer: [(0, _util.compactToU8a)(this.size)]
|
|
164
136
|
};
|
|
165
137
|
}
|
|
138
|
+
|
|
166
139
|
/**
|
|
167
140
|
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
168
141
|
*/
|
|
169
|
-
|
|
170
|
-
|
|
171
142
|
toHex() {
|
|
172
143
|
return (0, _util.u8aToHex)(this.toU8a());
|
|
173
144
|
}
|
|
145
|
+
|
|
174
146
|
/**
|
|
175
147
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
176
148
|
*/
|
|
177
|
-
|
|
178
|
-
|
|
179
149
|
toHuman(isExtended) {
|
|
180
150
|
const json = {};
|
|
181
|
-
|
|
182
151
|
for (const [k, v] of this.entries()) {
|
|
183
152
|
json[k instanceof _Raw.Raw && k.isAscii ? k.toUtf8() : k.toString()] = v.toHuman(isExtended);
|
|
184
153
|
}
|
|
185
|
-
|
|
186
154
|
return json;
|
|
187
155
|
}
|
|
156
|
+
|
|
188
157
|
/**
|
|
189
158
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
190
159
|
*/
|
|
191
|
-
|
|
192
|
-
|
|
193
160
|
toJSON() {
|
|
194
161
|
const json = {};
|
|
195
|
-
|
|
196
162
|
for (const [k, v] of this.entries()) {
|
|
197
163
|
json[k.toString()] = v.toJSON();
|
|
198
164
|
}
|
|
199
|
-
|
|
200
165
|
return json;
|
|
201
166
|
}
|
|
167
|
+
|
|
202
168
|
/**
|
|
203
169
|
* @description Converts the value in a best-fit primitive form
|
|
204
170
|
*/
|
|
205
|
-
|
|
206
|
-
|
|
207
171
|
toPrimitive() {
|
|
208
172
|
const json = {};
|
|
209
|
-
|
|
210
173
|
for (const [k, v] of this.entries()) {
|
|
211
174
|
json[k instanceof _Raw.Raw && k.isAscii ? k.toUtf8() : k.toString()] = v.toPrimitive();
|
|
212
175
|
}
|
|
213
|
-
|
|
214
176
|
return json;
|
|
215
177
|
}
|
|
178
|
+
|
|
216
179
|
/**
|
|
217
180
|
* @description Returns the base runtime type name for this instance
|
|
218
181
|
*/
|
|
219
|
-
|
|
220
|
-
|
|
221
182
|
toRawType() {
|
|
222
183
|
return `${this.#type}<${this.registry.getClassName(this.#KeyClass) || new this.#KeyClass(this.registry).toRawType()},${this.registry.getClassName(this.#ValClass) || new this.#ValClass(this.registry).toRawType()}>`;
|
|
223
184
|
}
|
|
185
|
+
|
|
224
186
|
/**
|
|
225
187
|
* @description Returns the string representation of the value
|
|
226
188
|
*/
|
|
227
|
-
|
|
228
|
-
|
|
229
189
|
toString() {
|
|
230
190
|
return (0, _util.stringify)(this.toJSON());
|
|
231
191
|
}
|
|
192
|
+
|
|
232
193
|
/**
|
|
233
194
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
234
195
|
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
235
196
|
*/
|
|
236
|
-
|
|
237
|
-
|
|
238
197
|
toU8a(isBare) {
|
|
239
198
|
const encoded = new Array();
|
|
240
|
-
|
|
241
199
|
if (!isBare) {
|
|
242
200
|
encoded.push((0, _util.compactToU8a)(this.size));
|
|
243
201
|
}
|
|
244
|
-
|
|
245
202
|
for (const [k, v] of this.entries()) {
|
|
246
203
|
encoded.push(k.toU8a(isBare), v.toU8a(isBare));
|
|
247
204
|
}
|
|
248
|
-
|
|
249
205
|
return (0, _util.u8aConcatStrict)(encoded);
|
|
250
206
|
}
|
|
251
|
-
|
|
252
207
|
}
|
|
253
|
-
|
|
254
208
|
exports.CodecMap = CodecMap;
|
|
@@ -4,15 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.OptionBool = void 0;
|
|
7
|
-
|
|
8
7
|
var _util = require("@polkadot/util");
|
|
9
|
-
|
|
10
8
|
var _Option = require("../base/Option");
|
|
11
|
-
|
|
12
9
|
var _Bool = require("../native/Bool");
|
|
13
|
-
|
|
14
10
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
15
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
|
|
16
13
|
function decodeU8a(registry, value) {
|
|
17
14
|
// Encoded as -
|
|
18
15
|
// - 0 = None
|
|
@@ -20,73 +17,63 @@ function decodeU8a(registry, value) {
|
|
|
20
17
|
// - 2 = False
|
|
21
18
|
return value[0] === 0 ? null : new _Bool.bool(registry, value[0] === 1);
|
|
22
19
|
}
|
|
20
|
+
|
|
23
21
|
/**
|
|
24
22
|
* @name OptionBool
|
|
25
23
|
* @description A specific implementation of Option<bool> than allows for single-byte encoding
|
|
26
24
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
25
|
class OptionBool extends _Option.Option {
|
|
30
26
|
constructor(registry, value) {
|
|
31
27
|
super(registry, _Bool.bool, (0, _util.isU8a)(value) || (0, _util.isHex)(value) ? decodeU8a(registry, (0, _util.u8aToU8a)(value)) : value);
|
|
32
28
|
this.initialU8aLength = 1;
|
|
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
|
return 1;
|
|
41
36
|
}
|
|
37
|
+
|
|
42
38
|
/**
|
|
43
39
|
* @description Checks if the value is an empty value (always false)
|
|
44
40
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
41
|
get isFalse() {
|
|
48
42
|
return this.isSome ? !this.value.valueOf() : false;
|
|
49
43
|
}
|
|
44
|
+
|
|
50
45
|
/**
|
|
51
46
|
* @description Checks if the value is an empty value (always false)
|
|
52
47
|
*/
|
|
53
|
-
|
|
54
|
-
|
|
55
48
|
get isTrue() {
|
|
56
49
|
return this.isSome ? this.value.valueOf() : false;
|
|
57
50
|
}
|
|
51
|
+
|
|
58
52
|
/**
|
|
59
53
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
60
54
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
55
|
inspect() {
|
|
64
56
|
return {
|
|
65
57
|
outer: [this.toU8a()]
|
|
66
58
|
};
|
|
67
59
|
}
|
|
60
|
+
|
|
68
61
|
/**
|
|
69
62
|
* @description Returns the base runtime type name for this instance
|
|
70
63
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
64
|
toRawType(isBare) {
|
|
74
65
|
return isBare ? 'bool' : 'Option<bool>';
|
|
75
66
|
}
|
|
67
|
+
|
|
76
68
|
/**
|
|
77
69
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
78
70
|
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
79
71
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
82
72
|
toU8a(isBare) {
|
|
83
73
|
if (isBare) {
|
|
84
74
|
return super.toU8a(true);
|
|
85
75
|
}
|
|
86
|
-
|
|
87
76
|
return this.isSome ? new Uint8Array([this.isTrue ? 1 : 2]) : new Uint8Array([0]);
|
|
88
77
|
}
|
|
89
|
-
|
|
90
78
|
}
|
|
91
|
-
|
|
92
79
|
exports.OptionBool = OptionBool;
|
package/cjs/extended/Range.js
CHANGED
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Range = void 0;
|
|
7
|
-
|
|
8
7
|
var _Tuple = require("../base/Tuple");
|
|
9
|
-
|
|
10
8
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
11
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
10
|
|
|
@@ -17,7 +15,6 @@ var _Tuple = require("../base/Tuple");
|
|
|
17
15
|
*/
|
|
18
16
|
class Range extends _Tuple.Tuple {
|
|
19
17
|
#rangeName;
|
|
20
|
-
|
|
21
18
|
constructor(registry, Type, value) {
|
|
22
19
|
let {
|
|
23
20
|
rangeName = 'Range'
|
|
@@ -25,40 +22,33 @@ class Range extends _Tuple.Tuple {
|
|
|
25
22
|
super(registry, [Type, Type], value);
|
|
26
23
|
this.#rangeName = rangeName;
|
|
27
24
|
}
|
|
28
|
-
|
|
29
25
|
static with(Type) {
|
|
30
26
|
return class extends Range {
|
|
31
27
|
constructor(registry, value) {
|
|
32
28
|
super(registry, Type, value);
|
|
33
29
|
}
|
|
34
|
-
|
|
35
30
|
};
|
|
36
31
|
}
|
|
32
|
+
|
|
37
33
|
/**
|
|
38
34
|
* @description Returns the starting range value
|
|
39
35
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
36
|
get start() {
|
|
43
37
|
return this[0];
|
|
44
38
|
}
|
|
39
|
+
|
|
45
40
|
/**
|
|
46
41
|
* @description Returns the ending range value
|
|
47
42
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
43
|
get end() {
|
|
51
44
|
return this[1];
|
|
52
45
|
}
|
|
46
|
+
|
|
53
47
|
/**
|
|
54
48
|
* @description Returns the base runtime type name for this instance
|
|
55
49
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
58
50
|
toRawType() {
|
|
59
51
|
return `${this.#rangeName}<${this.start.toRawType()}>`;
|
|
60
52
|
}
|
|
61
|
-
|
|
62
53
|
}
|
|
63
|
-
|
|
64
54
|
exports.Range = Range;
|
|
@@ -4,27 +4,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.RangeInclusive = void 0;
|
|
7
|
-
|
|
8
7
|
var _Range = require("./Range");
|
|
9
|
-
|
|
10
8
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
11
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
10
|
+
|
|
12
11
|
class RangeInclusive extends _Range.Range {
|
|
13
12
|
constructor(registry, Type, value) {
|
|
14
13
|
super(registry, Type, value, {
|
|
15
14
|
rangeName: 'RangeInclusive'
|
|
16
15
|
});
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
static with(Type) {
|
|
20
18
|
return class extends RangeInclusive {
|
|
21
19
|
constructor(registry, value) {
|
|
22
20
|
super(registry, Type, value);
|
|
23
21
|
}
|
|
24
|
-
|
|
25
22
|
};
|
|
26
23
|
}
|
|
27
|
-
|
|
28
24
|
}
|
|
29
|
-
|
|
30
25
|
exports.RangeInclusive = RangeInclusive;
|
package/cjs/extended/Type.js
CHANGED
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Type = void 0;
|
|
7
|
-
|
|
8
7
|
var _Text = require("../native/Text");
|
|
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
|
|
14
11
|
|
|
@@ -25,15 +22,12 @@ class Type extends _Text.Text {
|
|
|
25
22
|
super(registry, value);
|
|
26
23
|
this.setOverride((0, _utils.sanitize)(this.toString()));
|
|
27
24
|
}
|
|
25
|
+
|
|
28
26
|
/**
|
|
29
27
|
* @description Returns the base runtime type name for this instance
|
|
30
28
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
29
|
toRawType() {
|
|
34
30
|
return 'Type';
|
|
35
31
|
}
|
|
36
|
-
|
|
37
32
|
}
|
|
38
|
-
|
|
39
33
|
exports.Type = Type;
|
package/cjs/extended/U8aFixed.js
CHANGED
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.U8aFixed = void 0;
|
|
7
|
-
|
|
8
7
|
var _util = require("@polkadot/util");
|
|
9
|
-
|
|
10
8
|
var _Raw = require("../native/Raw");
|
|
11
|
-
|
|
12
9
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
13
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
14
11
|
|
|
@@ -16,25 +13,21 @@ var _Raw = require("../native/Raw");
|
|
|
16
13
|
function decodeU8aFixed(value, bitLength) {
|
|
17
14
|
const u8a = (0, _util.u8aToU8a)(value);
|
|
18
15
|
const byteLength = bitLength / 8;
|
|
19
|
-
|
|
20
16
|
if (!u8a.length) {
|
|
21
17
|
return [new Uint8Array(byteLength), 0];
|
|
22
18
|
}
|
|
23
|
-
|
|
24
19
|
if ((0, _util.isU8a)(value) ? u8a.length < byteLength : u8a.length !== byteLength) {
|
|
25
20
|
throw new Error(`Expected input with ${byteLength} bytes (${bitLength} bits), found ${u8a.length} bytes`);
|
|
26
21
|
}
|
|
27
|
-
|
|
28
22
|
return [u8a.subarray(0, byteLength), byteLength];
|
|
29
23
|
}
|
|
24
|
+
|
|
30
25
|
/**
|
|
31
26
|
* @name U8aFixed
|
|
32
27
|
* @description
|
|
33
28
|
* A U8a that manages a a sequence of bytes up to the specified bitLength. Not meant
|
|
34
29
|
* to be used directly, rather is should be subclassed with the specific lengths.
|
|
35
30
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
31
|
class U8aFixed extends _Raw.Raw {
|
|
39
32
|
constructor(registry) {
|
|
40
33
|
let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Uint8Array();
|
|
@@ -42,28 +35,22 @@ class U8aFixed extends _Raw.Raw {
|
|
|
42
35
|
const [u8a, decodedLength] = decodeU8aFixed(value, bitLength);
|
|
43
36
|
super(registry, u8a, decodedLength);
|
|
44
37
|
}
|
|
45
|
-
|
|
46
38
|
static with(bitLength, typeName) {
|
|
47
39
|
return class extends U8aFixed {
|
|
48
40
|
constructor(registry, value) {
|
|
49
41
|
super(registry, value, bitLength);
|
|
50
42
|
}
|
|
51
|
-
|
|
52
43
|
toRawType() {
|
|
53
44
|
return typeName || super.toRawType();
|
|
54
45
|
}
|
|
55
|
-
|
|
56
46
|
};
|
|
57
47
|
}
|
|
48
|
+
|
|
58
49
|
/**
|
|
59
50
|
* @description Returns the base runtime type name for this instance
|
|
60
51
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
52
|
toRawType() {
|
|
64
53
|
return `[u8;${this.length}]`;
|
|
65
54
|
}
|
|
66
|
-
|
|
67
55
|
}
|
|
68
|
-
|
|
69
56
|
exports.U8aFixed = U8aFixed;
|