@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/native/Json.js
CHANGED
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Json = 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
|
|
14
11
|
|
|
@@ -16,6 +13,7 @@ var _utils = require("../utils");
|
|
|
16
13
|
function decodeJson(value) {
|
|
17
14
|
return Object.entries(value || {});
|
|
18
15
|
}
|
|
16
|
+
|
|
19
17
|
/**
|
|
20
18
|
* @name Json
|
|
21
19
|
* @description
|
|
@@ -24,8 +22,6 @@ function decodeJson(value) {
|
|
|
24
22
|
* i.e. no hex decoding. Unlike a struct, this waps a JSON object with unknown keys
|
|
25
23
|
* @noInheritDoc
|
|
26
24
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
25
|
class Json extends Map {
|
|
30
26
|
constructor(registry, value) {
|
|
31
27
|
const decoded = decodeJson(value);
|
|
@@ -36,67 +32,59 @@ class Json extends Map {
|
|
|
36
32
|
return k;
|
|
37
33
|
}), k => this.get(k));
|
|
38
34
|
}
|
|
35
|
+
|
|
39
36
|
/**
|
|
40
37
|
* @description Always 0, never encodes as a Uint8Array
|
|
41
38
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
39
|
get encodedLength() {
|
|
45
40
|
return 0;
|
|
46
41
|
}
|
|
42
|
+
|
|
47
43
|
/**
|
|
48
44
|
* @description returns a hash of the contents
|
|
49
45
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
46
|
get hash() {
|
|
53
47
|
return this.registry.hash(this.toU8a());
|
|
54
48
|
}
|
|
49
|
+
|
|
55
50
|
/**
|
|
56
51
|
* @description Checks if the value is an empty value
|
|
57
52
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
53
|
get isEmpty() {
|
|
61
54
|
return [...this.keys()].length === 0;
|
|
62
55
|
}
|
|
56
|
+
|
|
63
57
|
/**
|
|
64
58
|
* @description Compares the value of the input to see if there is a match
|
|
65
59
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
60
|
eq(other) {
|
|
69
61
|
return (0, _utils.compareMap)(this, other);
|
|
70
62
|
}
|
|
63
|
+
|
|
71
64
|
/**
|
|
72
65
|
* @description Returns a typed value from the internal map
|
|
73
66
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
67
|
getT(key) {
|
|
77
68
|
return this.get(key);
|
|
78
69
|
}
|
|
70
|
+
|
|
79
71
|
/**
|
|
80
72
|
* @description Unimplemented, will throw
|
|
81
73
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
74
|
inspect() {
|
|
85
75
|
throw new Error('Unimplemented');
|
|
86
76
|
}
|
|
77
|
+
|
|
87
78
|
/**
|
|
88
79
|
* @description Unimplemented, will throw
|
|
89
80
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
81
|
toHex() {
|
|
93
82
|
throw new Error('Unimplemented');
|
|
94
83
|
}
|
|
84
|
+
|
|
95
85
|
/**
|
|
96
86
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
97
87
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
88
|
toHuman() {
|
|
101
89
|
return [...this.entries()].reduce((json, _ref2) => {
|
|
102
90
|
let [key, value] = _ref2;
|
|
@@ -104,11 +92,10 @@ class Json extends Map {
|
|
|
104
92
|
return json;
|
|
105
93
|
}, {});
|
|
106
94
|
}
|
|
95
|
+
|
|
107
96
|
/**
|
|
108
97
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
109
98
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
99
|
toJSON() {
|
|
113
100
|
return [...this.entries()].reduce((json, _ref3) => {
|
|
114
101
|
let [key, value] = _ref3;
|
|
@@ -116,11 +103,10 @@ class Json extends Map {
|
|
|
116
103
|
return json;
|
|
117
104
|
}, {});
|
|
118
105
|
}
|
|
106
|
+
|
|
119
107
|
/**
|
|
120
108
|
* @description Converts the value in a best-fit primitive form
|
|
121
109
|
*/
|
|
122
|
-
|
|
123
|
-
|
|
124
110
|
toPrimitive() {
|
|
125
111
|
return [...this.entries()].reduce((json, _ref4) => {
|
|
126
112
|
let [key, value] = _ref4;
|
|
@@ -128,32 +114,27 @@ class Json extends Map {
|
|
|
128
114
|
return json;
|
|
129
115
|
}, {});
|
|
130
116
|
}
|
|
117
|
+
|
|
131
118
|
/**
|
|
132
119
|
* @description Returns the base runtime type name for this instance
|
|
133
120
|
*/
|
|
134
|
-
|
|
135
|
-
|
|
136
121
|
toRawType() {
|
|
137
122
|
return 'Json';
|
|
138
123
|
}
|
|
124
|
+
|
|
139
125
|
/**
|
|
140
126
|
* @description Returns the string representation of the value
|
|
141
127
|
*/
|
|
142
|
-
|
|
143
|
-
|
|
144
128
|
toString() {
|
|
145
129
|
return (0, _util.stringify)(this.toJSON());
|
|
146
130
|
}
|
|
131
|
+
|
|
147
132
|
/**
|
|
148
133
|
* @description Unimplemented, will throw
|
|
149
134
|
*/
|
|
150
135
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
151
|
-
|
|
152
|
-
|
|
153
136
|
toU8a(isBare) {
|
|
154
137
|
throw new Error('Unimplemented');
|
|
155
138
|
}
|
|
156
|
-
|
|
157
139
|
}
|
|
158
|
-
|
|
159
140
|
exports.Json = Json;
|
package/cjs/native/Raw.js
CHANGED
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Raw = 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
10
|
|
|
@@ -27,161 +25,140 @@ class Raw extends Uint8Array {
|
|
|
27
25
|
static get [Symbol.species]() {
|
|
28
26
|
return Uint8Array;
|
|
29
27
|
}
|
|
30
|
-
|
|
31
28
|
constructor(registry, value, initialU8aLength) {
|
|
32
29
|
super((0, _util.u8aToU8a)(value));
|
|
33
30
|
this.registry = registry;
|
|
34
31
|
this.initialU8aLength = initialU8aLength;
|
|
35
32
|
}
|
|
33
|
+
|
|
36
34
|
/**
|
|
37
35
|
* @description The length of the value when encoded as a Uint8Array
|
|
38
36
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
37
|
get encodedLength() {
|
|
42
38
|
return this.length;
|
|
43
39
|
}
|
|
40
|
+
|
|
44
41
|
/**
|
|
45
42
|
* @description returns a hash of the contents
|
|
46
43
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
44
|
get hash() {
|
|
50
45
|
return this.registry.hash(this.toU8a());
|
|
51
46
|
}
|
|
47
|
+
|
|
52
48
|
/**
|
|
53
49
|
* @description Returns true if the wrapped value contains only ASCII printable characters
|
|
54
50
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
51
|
get isAscii() {
|
|
58
52
|
return (0, _util.isAscii)(this);
|
|
59
53
|
}
|
|
54
|
+
|
|
60
55
|
/**
|
|
61
56
|
* @description Returns true if the type wraps an empty/default all-0 value
|
|
62
57
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
58
|
get isEmpty() {
|
|
66
59
|
return !this.length || (0, _util.isUndefined)(this.find(b => !!b));
|
|
67
60
|
}
|
|
61
|
+
|
|
68
62
|
/**
|
|
69
63
|
* @description Returns true if the wrapped value contains only utf8 characters
|
|
70
64
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
65
|
get isUtf8() {
|
|
74
66
|
return (0, _util.isUtf8)(this);
|
|
75
67
|
}
|
|
68
|
+
|
|
76
69
|
/**
|
|
77
70
|
* @description Returns the number of bits in the value
|
|
78
71
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
72
|
bitLength() {
|
|
82
73
|
return this.length * 8;
|
|
83
74
|
}
|
|
75
|
+
|
|
84
76
|
/**
|
|
85
77
|
* @description Compares the value of the input to see if there is a match
|
|
86
78
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
89
79
|
eq(other) {
|
|
90
80
|
if (other instanceof Uint8Array) {
|
|
91
81
|
return this.length === other.length && !this.some((b, index) => b !== other[index]);
|
|
92
82
|
}
|
|
93
|
-
|
|
94
83
|
return this.eq((0, _util.u8aToU8a)(other));
|
|
95
84
|
}
|
|
85
|
+
|
|
96
86
|
/**
|
|
97
87
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
98
88
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
89
|
inspect() {
|
|
102
90
|
return {
|
|
103
91
|
outer: [this.toU8a()]
|
|
104
92
|
};
|
|
105
93
|
}
|
|
94
|
+
|
|
106
95
|
/**
|
|
107
96
|
* @description Returns a hex string representation of the value
|
|
108
97
|
*/
|
|
109
|
-
|
|
110
|
-
|
|
111
98
|
toHex() {
|
|
112
99
|
return (0, _util.u8aToHex)(this);
|
|
113
100
|
}
|
|
101
|
+
|
|
114
102
|
/**
|
|
115
103
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
116
104
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
105
|
toHuman() {
|
|
120
106
|
return this.toPrimitive();
|
|
121
107
|
}
|
|
108
|
+
|
|
122
109
|
/**
|
|
123
110
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
124
111
|
*/
|
|
125
|
-
|
|
126
|
-
|
|
127
112
|
toJSON() {
|
|
128
113
|
return this.toHex();
|
|
129
114
|
}
|
|
115
|
+
|
|
130
116
|
/**
|
|
131
117
|
* @description Converts the value in a best-fit primitive form
|
|
132
118
|
*/
|
|
133
|
-
|
|
134
|
-
|
|
135
119
|
toPrimitive() {
|
|
136
120
|
if (this.isAscii) {
|
|
137
|
-
const text = this.toUtf8();
|
|
121
|
+
const text = this.toUtf8();
|
|
138
122
|
|
|
123
|
+
// ensure we didn't end up with multibyte codepoints
|
|
139
124
|
if ((0, _util.isAscii)(text)) {
|
|
140
125
|
return text;
|
|
141
126
|
}
|
|
142
127
|
}
|
|
143
|
-
|
|
144
128
|
return this.toJSON();
|
|
145
129
|
}
|
|
130
|
+
|
|
146
131
|
/**
|
|
147
132
|
* @description Returns the base runtime type name for this instance
|
|
148
133
|
*/
|
|
149
|
-
|
|
150
|
-
|
|
151
134
|
toRawType() {
|
|
152
135
|
return 'Raw';
|
|
153
136
|
}
|
|
137
|
+
|
|
154
138
|
/**
|
|
155
139
|
* @description Returns the string representation of the value
|
|
156
140
|
*/
|
|
157
|
-
|
|
158
|
-
|
|
159
141
|
toString() {
|
|
160
142
|
return this.toHex();
|
|
161
143
|
}
|
|
144
|
+
|
|
162
145
|
/**
|
|
163
146
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
164
147
|
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
165
148
|
*/
|
|
166
149
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
167
|
-
|
|
168
|
-
|
|
169
150
|
toU8a(isBare) {
|
|
170
151
|
return Uint8Array.from(this);
|
|
171
152
|
}
|
|
153
|
+
|
|
172
154
|
/**
|
|
173
155
|
* @description Returns the wrapped data as a UTF-8 string
|
|
174
156
|
*/
|
|
175
|
-
|
|
176
|
-
|
|
177
157
|
toUtf8() {
|
|
178
158
|
if (!this.isUtf8) {
|
|
179
159
|
throw new Error('The character sequence is not a valid Utf8 string');
|
|
180
160
|
}
|
|
181
|
-
|
|
182
161
|
return (0, _util.u8aToString)(this);
|
|
183
162
|
}
|
|
184
|
-
|
|
185
163
|
}
|
|
186
|
-
|
|
187
164
|
exports.Raw = Raw;
|
package/cjs/native/Set.js
CHANGED
|
@@ -4,77 +4,58 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.CodecSet = 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 encodeSet(setValues, values) {
|
|
15
13
|
const encoded = new _util.BN(0);
|
|
16
|
-
|
|
17
14
|
for (let i = 0; i < values.length; i++) {
|
|
18
15
|
encoded.ior((0, _util.bnToBn)(setValues[values[i]] || 0));
|
|
19
16
|
}
|
|
20
|
-
|
|
21
17
|
return encoded;
|
|
22
18
|
}
|
|
23
|
-
/** @internal */
|
|
24
|
-
|
|
25
19
|
|
|
20
|
+
/** @internal */
|
|
26
21
|
function decodeSetArray(setValues, values) {
|
|
27
22
|
const result = new Array(values.length);
|
|
28
|
-
|
|
29
23
|
for (let i = 0; i < values.length; i++) {
|
|
30
24
|
const key = values[i];
|
|
31
|
-
|
|
32
25
|
if ((0, _util.isUndefined)(setValues[key])) {
|
|
33
26
|
throw new Error(`Set: Invalid key '${key}' passed to Set, allowed ${Object.keys(setValues).join(', ')}`);
|
|
34
27
|
}
|
|
35
|
-
|
|
36
28
|
result[i] = key;
|
|
37
29
|
}
|
|
38
|
-
|
|
39
30
|
return result;
|
|
40
31
|
}
|
|
41
|
-
/** @internal */
|
|
42
|
-
|
|
43
32
|
|
|
33
|
+
/** @internal */
|
|
44
34
|
function decodeSetNumber(setValues, _value) {
|
|
45
35
|
const bn = (0, _util.bnToBn)(_value);
|
|
46
36
|
const keys = Object.keys(setValues);
|
|
47
37
|
const result = [];
|
|
48
|
-
|
|
49
38
|
for (let i = 0; i < keys.length; i++) {
|
|
50
39
|
const key = keys[i];
|
|
51
|
-
|
|
52
40
|
if (bn.and((0, _util.bnToBn)(setValues[key])).eq((0, _util.bnToBn)(setValues[key]))) {
|
|
53
41
|
result.push(key);
|
|
54
42
|
}
|
|
55
43
|
}
|
|
56
|
-
|
|
57
44
|
const computed = encodeSet(setValues, result);
|
|
58
|
-
|
|
59
45
|
if (!bn.eq(computed)) {
|
|
60
46
|
throw new Error(`Set: Mismatch decoding '${bn.toString()}', computed as '${computed.toString()}' with ${result.join(', ')}`);
|
|
61
47
|
}
|
|
62
|
-
|
|
63
48
|
return result;
|
|
64
49
|
}
|
|
65
|
-
/** @internal */
|
|
66
|
-
|
|
67
50
|
|
|
51
|
+
/** @internal */
|
|
68
52
|
function decodeSet(setValues) {
|
|
69
53
|
let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
70
54
|
let bitLength = arguments.length > 2 ? arguments[2] : undefined;
|
|
71
|
-
|
|
72
55
|
if (bitLength % 8 !== 0) {
|
|
73
56
|
throw new Error(`Expected valid bitLength, power of 8, found ${bitLength}`);
|
|
74
57
|
}
|
|
75
|
-
|
|
76
58
|
const byteLength = bitLength / 8;
|
|
77
|
-
|
|
78
59
|
if ((0, _util.isU8a)(value)) {
|
|
79
60
|
return value.length === 0 ? [] : decodeSetNumber(setValues, (0, _util.u8aToBn)(value.subarray(0, byteLength), {
|
|
80
61
|
isLe: true
|
|
@@ -85,21 +66,18 @@ function decodeSet(setValues) {
|
|
|
85
66
|
const input = Array.isArray(value) ? value : [...value.values()];
|
|
86
67
|
return decodeSetArray(setValues, input);
|
|
87
68
|
}
|
|
88
|
-
|
|
89
69
|
return decodeSetNumber(setValues, value);
|
|
90
70
|
}
|
|
71
|
+
|
|
91
72
|
/**
|
|
92
73
|
* @name Set
|
|
93
74
|
* @description
|
|
94
75
|
* An Set is an array of string values, represented an an encoded type by
|
|
95
76
|
* a bitwise representation of the values.
|
|
96
77
|
*/
|
|
97
|
-
|
|
98
|
-
|
|
99
78
|
class CodecSet extends Set {
|
|
100
79
|
#allowed;
|
|
101
80
|
#byteLength;
|
|
102
|
-
|
|
103
81
|
constructor(registry, setValues, value) {
|
|
104
82
|
let bitLength = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 8;
|
|
105
83
|
super(decodeSet(setValues, value, bitLength));
|
|
@@ -107,71 +85,60 @@ class CodecSet extends Set {
|
|
|
107
85
|
this.#allowed = setValues;
|
|
108
86
|
this.#byteLength = bitLength / 8;
|
|
109
87
|
}
|
|
110
|
-
|
|
111
88
|
static with(values, bitLength) {
|
|
112
89
|
var _class;
|
|
113
|
-
|
|
114
90
|
return _class = class extends CodecSet {
|
|
115
91
|
constructor(registry, value) {
|
|
116
92
|
super(registry, values, value, bitLength);
|
|
117
93
|
}
|
|
118
|
-
|
|
119
94
|
}, (() => {
|
|
120
95
|
const keys = Object.keys(values);
|
|
121
96
|
const isKeys = new Array(keys.length);
|
|
122
|
-
|
|
123
97
|
for (let i = 0; i < keys.length; i++) {
|
|
124
98
|
isKeys[i] = `is${(0, _util.stringPascalCase)(keys[i])}`;
|
|
125
99
|
}
|
|
126
|
-
|
|
127
100
|
(0, _util.objectProperties)(_class.prototype, isKeys, (_, i, self) => self.strings.includes(keys[i]));
|
|
128
101
|
})(), _class;
|
|
129
102
|
}
|
|
103
|
+
|
|
130
104
|
/**
|
|
131
105
|
* @description The length of the value when encoded as a Uint8Array
|
|
132
106
|
*/
|
|
133
|
-
|
|
134
|
-
|
|
135
107
|
get encodedLength() {
|
|
136
108
|
return this.#byteLength;
|
|
137
109
|
}
|
|
110
|
+
|
|
138
111
|
/**
|
|
139
112
|
* @description returns a hash of the contents
|
|
140
113
|
*/
|
|
141
|
-
|
|
142
|
-
|
|
143
114
|
get hash() {
|
|
144
115
|
return this.registry.hash(this.toU8a());
|
|
145
116
|
}
|
|
117
|
+
|
|
146
118
|
/**
|
|
147
119
|
* @description true is the Set contains no values
|
|
148
120
|
*/
|
|
149
|
-
|
|
150
|
-
|
|
151
121
|
get isEmpty() {
|
|
152
122
|
return this.size === 0;
|
|
153
123
|
}
|
|
124
|
+
|
|
154
125
|
/**
|
|
155
126
|
* @description The actual set values as a string[]
|
|
156
127
|
*/
|
|
157
|
-
|
|
158
|
-
|
|
159
128
|
get strings() {
|
|
160
129
|
return [...super.values()];
|
|
161
130
|
}
|
|
131
|
+
|
|
162
132
|
/**
|
|
163
133
|
* @description The encoded value for the set members
|
|
164
134
|
*/
|
|
165
|
-
|
|
166
|
-
|
|
167
135
|
get valueEncoded() {
|
|
168
136
|
return encodeSet(this.#allowed, this.strings);
|
|
169
137
|
}
|
|
138
|
+
|
|
170
139
|
/**
|
|
171
140
|
* @description adds a value to the Set (extended to allow for validity checking)
|
|
172
141
|
*/
|
|
173
|
-
|
|
174
|
-
|
|
175
142
|
add = key => {
|
|
176
143
|
// ^^^ add = () property done to assign this instance's this, otherwise Set.add creates "some" chaos
|
|
177
144
|
// we have the isUndefined(this._setValues) in here as well, add is used internally
|
|
@@ -179,14 +146,13 @@ class CodecSet extends Set {
|
|
|
179
146
|
if (this.#allowed && (0, _util.isUndefined)(this.#allowed[key])) {
|
|
180
147
|
throw new Error(`Set: Invalid key '${key}' on add`);
|
|
181
148
|
}
|
|
182
|
-
|
|
183
149
|
super.add(key);
|
|
184
150
|
return this;
|
|
185
151
|
};
|
|
152
|
+
|
|
186
153
|
/**
|
|
187
154
|
* @description Compares the value of the input to see if there is a match
|
|
188
155
|
*/
|
|
189
|
-
|
|
190
156
|
eq(other) {
|
|
191
157
|
if (Array.isArray(other)) {
|
|
192
158
|
// we don't actually care about the order, sort the values
|
|
@@ -196,91 +162,79 @@ class CodecSet extends Set {
|
|
|
196
162
|
} else if ((0, _util.isNumber)(other) || (0, _util.isBn)(other)) {
|
|
197
163
|
return this.valueEncoded.eq((0, _util.bnToBn)(other));
|
|
198
164
|
}
|
|
199
|
-
|
|
200
165
|
return false;
|
|
201
166
|
}
|
|
167
|
+
|
|
202
168
|
/**
|
|
203
169
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
204
170
|
*/
|
|
205
|
-
|
|
206
|
-
|
|
207
171
|
inspect() {
|
|
208
172
|
return {
|
|
209
173
|
outer: [this.toU8a()]
|
|
210
174
|
};
|
|
211
175
|
}
|
|
176
|
+
|
|
212
177
|
/**
|
|
213
178
|
* @description Returns a hex string representation of the value
|
|
214
179
|
*/
|
|
215
|
-
|
|
216
|
-
|
|
217
180
|
toHex() {
|
|
218
181
|
return (0, _util.u8aToHex)(this.toU8a());
|
|
219
182
|
}
|
|
183
|
+
|
|
220
184
|
/**
|
|
221
185
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
222
186
|
*/
|
|
223
|
-
|
|
224
|
-
|
|
225
187
|
toHuman() {
|
|
226
188
|
return this.toJSON();
|
|
227
189
|
}
|
|
190
|
+
|
|
228
191
|
/**
|
|
229
192
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
230
193
|
*/
|
|
231
|
-
|
|
232
|
-
|
|
233
194
|
toJSON() {
|
|
234
195
|
return this.strings;
|
|
235
196
|
}
|
|
197
|
+
|
|
236
198
|
/**
|
|
237
199
|
* @description The encoded value for the set members
|
|
238
200
|
*/
|
|
239
|
-
|
|
240
|
-
|
|
241
201
|
toNumber() {
|
|
242
202
|
return this.valueEncoded.toNumber();
|
|
243
203
|
}
|
|
204
|
+
|
|
244
205
|
/**
|
|
245
206
|
* @description Converts the value in a best-fit primitive form
|
|
246
207
|
*/
|
|
247
|
-
|
|
248
|
-
|
|
249
208
|
toPrimitive() {
|
|
250
209
|
return this.toJSON();
|
|
251
210
|
}
|
|
211
|
+
|
|
252
212
|
/**
|
|
253
213
|
* @description Returns the base runtime type name for this instance
|
|
254
214
|
*/
|
|
255
|
-
|
|
256
|
-
|
|
257
215
|
toRawType() {
|
|
258
216
|
return (0, _util.stringify)({
|
|
259
217
|
_set: this.#allowed
|
|
260
218
|
});
|
|
261
219
|
}
|
|
220
|
+
|
|
262
221
|
/**
|
|
263
222
|
* @description Returns the string representation of the value
|
|
264
223
|
*/
|
|
265
|
-
|
|
266
|
-
|
|
267
224
|
toString() {
|
|
268
225
|
return `[${this.strings.join(', ')}]`;
|
|
269
226
|
}
|
|
227
|
+
|
|
270
228
|
/**
|
|
271
229
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
272
230
|
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
273
231
|
*/
|
|
274
232
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
275
|
-
|
|
276
|
-
|
|
277
233
|
toU8a(isBare) {
|
|
278
234
|
return (0, _util.bnToU8a)(this.valueEncoded, {
|
|
279
235
|
bitLength: this.#byteLength * 8,
|
|
280
236
|
isLe: true
|
|
281
237
|
});
|
|
282
238
|
}
|
|
283
|
-
|
|
284
239
|
}
|
|
285
|
-
|
|
286
240
|
exports.CodecSet = CodecSet;
|