@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/native/Text.js
CHANGED
|
@@ -1,38 +1,36 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { compactAddLength, compactFromU8aLim, compactToU8a, hexToU8a, isHex, isString, isU8a, stringToU8a, u8aToHex, u8aToString } from '@polkadot/util';
|
|
4
5
|
import { Raw } from "./Raw.js";
|
|
5
6
|
const MAX_LENGTH = 128 * 1024;
|
|
6
|
-
/** @internal */
|
|
7
7
|
|
|
8
|
+
/** @internal */
|
|
8
9
|
function decodeText(value) {
|
|
9
10
|
if (isU8a(value)) {
|
|
10
11
|
if (!value.length) {
|
|
11
12
|
return ['', 0];
|
|
12
|
-
}
|
|
13
|
-
// (the same applies in e.g. Bytes, where length is added at encoding-time)
|
|
14
|
-
|
|
13
|
+
}
|
|
15
14
|
|
|
15
|
+
// for Raw, the internal buffer does not have an internal length
|
|
16
|
+
// (the same applies in e.g. Bytes, where length is added at encoding-time)
|
|
16
17
|
if (value instanceof Raw) {
|
|
17
18
|
return [u8aToString(value), 0];
|
|
18
19
|
}
|
|
19
|
-
|
|
20
20
|
const [offset, length] = compactFromU8aLim(value);
|
|
21
21
|
const total = offset + length;
|
|
22
|
-
|
|
23
22
|
if (length > MAX_LENGTH) {
|
|
24
23
|
throw new Error(`Text: length ${length.toString()} exceeds ${MAX_LENGTH}`);
|
|
25
24
|
} else if (total > value.length) {
|
|
26
25
|
throw new Error(`Text: required length less than remainder, expected at least ${total}, found ${value.length}`);
|
|
27
26
|
}
|
|
28
|
-
|
|
29
27
|
return [u8aToString(value.subarray(offset, total)), total];
|
|
30
28
|
} else if (isHex(value)) {
|
|
31
29
|
return [u8aToString(hexToU8a(value)), 0];
|
|
32
30
|
}
|
|
33
|
-
|
|
34
31
|
return [value ? value.toString() : '', 0];
|
|
35
32
|
}
|
|
33
|
+
|
|
36
34
|
/**
|
|
37
35
|
* @name Text
|
|
38
36
|
* @description
|
|
@@ -41,138 +39,120 @@ function decodeText(value) {
|
|
|
41
39
|
* object, inheriting all methods exposed from `String`.
|
|
42
40
|
* @noInheritDoc
|
|
43
41
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
42
|
export class Text extends String {
|
|
47
43
|
#override = null;
|
|
48
|
-
|
|
49
44
|
constructor(registry, value) {
|
|
50
45
|
const [str, decodedLength] = decodeText(value);
|
|
51
46
|
super(str);
|
|
52
47
|
this.registry = registry;
|
|
53
48
|
this.initialU8aLength = decodedLength;
|
|
54
49
|
}
|
|
50
|
+
|
|
55
51
|
/**
|
|
56
52
|
* @description The length of the value when encoded as a Uint8Array
|
|
57
53
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
54
|
get encodedLength() {
|
|
61
55
|
return this.toU8a().length;
|
|
62
56
|
}
|
|
57
|
+
|
|
63
58
|
/**
|
|
64
59
|
* @description returns a hash of the contents
|
|
65
60
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
61
|
get hash() {
|
|
69
62
|
return this.registry.hash(this.toU8a());
|
|
70
63
|
}
|
|
64
|
+
|
|
71
65
|
/**
|
|
72
66
|
* @description Checks if the value is an empty value
|
|
73
67
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
68
|
get isEmpty() {
|
|
77
69
|
return this.length === 0;
|
|
78
70
|
}
|
|
71
|
+
|
|
79
72
|
/**
|
|
80
73
|
* @description The length of the value
|
|
81
74
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
75
|
get length() {
|
|
85
76
|
// only included here since we ignore inherited docs
|
|
86
77
|
return super.length;
|
|
87
78
|
}
|
|
79
|
+
|
|
88
80
|
/**
|
|
89
81
|
* @description Compares the value of the input to see if there is a match
|
|
90
82
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
83
|
eq(other) {
|
|
94
84
|
return isString(other) ? this.toString() === other.toString() : false;
|
|
95
85
|
}
|
|
86
|
+
|
|
96
87
|
/**
|
|
97
88
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
98
89
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
90
|
inspect() {
|
|
102
91
|
const value = stringToU8a(super.toString());
|
|
103
92
|
return {
|
|
104
93
|
outer: value.length ? [compactToU8a(value.length), value] : [compactToU8a(value.length)]
|
|
105
94
|
};
|
|
106
95
|
}
|
|
96
|
+
|
|
107
97
|
/**
|
|
108
98
|
* @description Set an override value for this
|
|
109
99
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
100
|
setOverride(override) {
|
|
113
101
|
this.#override = override;
|
|
114
102
|
}
|
|
103
|
+
|
|
115
104
|
/**
|
|
116
105
|
* @description Returns a hex string representation of the value
|
|
117
106
|
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
107
|
toHex() {
|
|
121
108
|
// like with Vec<u8>, when we are encoding to hex, we don't actually add
|
|
122
109
|
// the length prefix (it is already implied by the actual string length)
|
|
123
110
|
return u8aToHex(this.toU8a(true));
|
|
124
111
|
}
|
|
112
|
+
|
|
125
113
|
/**
|
|
126
114
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
127
115
|
*/
|
|
128
|
-
|
|
129
|
-
|
|
130
116
|
toHuman() {
|
|
131
117
|
return this.toJSON();
|
|
132
118
|
}
|
|
119
|
+
|
|
133
120
|
/**
|
|
134
121
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
135
122
|
*/
|
|
136
|
-
|
|
137
|
-
|
|
138
123
|
toJSON() {
|
|
139
124
|
return this.toString();
|
|
140
125
|
}
|
|
126
|
+
|
|
141
127
|
/**
|
|
142
128
|
* @description Converts the value in a best-fit primitive form
|
|
143
129
|
*/
|
|
144
|
-
|
|
145
|
-
|
|
146
130
|
toPrimitive() {
|
|
147
131
|
return this.toJSON();
|
|
148
132
|
}
|
|
133
|
+
|
|
149
134
|
/**
|
|
150
135
|
* @description Returns the base runtime type name for this instance
|
|
151
136
|
*/
|
|
152
|
-
|
|
153
|
-
|
|
154
137
|
toRawType() {
|
|
155
138
|
return 'Text';
|
|
156
139
|
}
|
|
140
|
+
|
|
157
141
|
/**
|
|
158
142
|
* @description Returns the string representation of the value
|
|
159
143
|
*/
|
|
160
|
-
|
|
161
|
-
|
|
162
144
|
toString() {
|
|
163
145
|
return this.#override || super.toString();
|
|
164
146
|
}
|
|
147
|
+
|
|
165
148
|
/**
|
|
166
149
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
167
150
|
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
168
151
|
*/
|
|
169
|
-
|
|
170
|
-
|
|
171
152
|
toU8a(isBare) {
|
|
172
153
|
// NOTE Here we use the super toString (we are not taking overrides into account,
|
|
173
154
|
// rather encoding the original value the string was constructed with)
|
|
174
155
|
const encoded = stringToU8a(super.toString());
|
|
175
156
|
return isBare ? encoded : compactAddLength(encoded);
|
|
176
157
|
}
|
|
177
|
-
|
|
178
158
|
}
|
package/native/index.js
CHANGED
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"./cjs/detectPackage.js"
|
|
21
21
|
],
|
|
22
22
|
"type": "module",
|
|
23
|
-
"version": "9.
|
|
23
|
+
"version": "9.6.2",
|
|
24
24
|
"main": "./cjs/index.js",
|
|
25
25
|
"module": "./index.js",
|
|
26
26
|
"types": "./index.d.ts",
|
|
@@ -434,7 +434,7 @@
|
|
|
434
434
|
}
|
|
435
435
|
},
|
|
436
436
|
"dependencies": {
|
|
437
|
-
"@babel/runtime": "^7.
|
|
437
|
+
"@babel/runtime": "^7.20.0",
|
|
438
438
|
"@polkadot/util": "^10.1.11",
|
|
439
439
|
"@polkadot/x-bigint": "^10.1.11"
|
|
440
440
|
}
|
package/packageInfo.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
// Do not edit, auto-generated by @polkadot/dev
|
|
5
|
+
|
|
4
6
|
export const packageInfo = {
|
|
5
7
|
name: '@polkadot/types-codec',
|
|
6
8
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
7
9
|
type: 'esm',
|
|
8
|
-
version: '9.
|
|
10
|
+
version: '9.6.2'
|
|
9
11
|
};
|
package/primitive/F32.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { Float } from "../native/Float.js";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* @name f32
|
|
6
8
|
* @description
|
|
7
9
|
* A 32-bit float
|
|
8
10
|
*/
|
|
9
|
-
|
|
10
11
|
export class f32 extends Float.with(32) {
|
|
11
12
|
// NOTE without this, we cannot properly determine extensions
|
|
12
13
|
__FloatType = 'f32';
|
package/primitive/F64.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { Float } from "../native/Float.js";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* @name f64
|
|
6
8
|
* @description
|
|
7
9
|
* A 64-bit float
|
|
8
10
|
*/
|
|
9
|
-
|
|
10
11
|
export class f64 extends Float.with(64) {
|
|
11
12
|
// NOTE without this, we cannot properly determine extensions
|
|
12
13
|
__FloatType = 'f64';
|
package/primitive/I128.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { Int } from "../base/Int.js";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* @name i128
|
|
6
8
|
* @description
|
|
7
9
|
* A 128-bit signed integer
|
|
8
10
|
*/
|
|
9
|
-
|
|
10
11
|
export class i128 extends Int.with(128) {
|
|
11
12
|
// NOTE without this, we cannot properly determine extensions
|
|
12
13
|
__IntType = 'i128';
|
package/primitive/I16.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { Int } from "../base/Int.js";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* @name i16
|
|
6
8
|
* @description
|
|
7
9
|
* A 16-bit signed integer
|
|
8
10
|
*/
|
|
9
|
-
|
|
10
11
|
export class i16 extends Int.with(16) {
|
|
11
12
|
// NOTE without this, we cannot properly determine extensions
|
|
12
13
|
__IntType = 'i16';
|
package/primitive/I256.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { Int } from "../base/Int.js";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* @name i256
|
|
6
8
|
* @description
|
|
7
9
|
* A 256-bit signed integer
|
|
8
10
|
*/
|
|
9
|
-
|
|
10
11
|
export class i256 extends Int.with(256) {
|
|
11
12
|
// NOTE without this, we cannot properly determine extensions
|
|
12
13
|
__IntType = 'i256';
|
package/primitive/I32.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { Int } from "../base/Int.js";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* @name i32
|
|
6
8
|
* @description
|
|
7
9
|
* A 32-bit signed integer
|
|
8
10
|
*/
|
|
9
|
-
|
|
10
11
|
export class i32 extends Int.with(32) {
|
|
11
12
|
// NOTE without this, we cannot properly determine extensions
|
|
12
13
|
__IntType = 'i32';
|
package/primitive/I64.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { Int } from "../base/Int.js";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* @name i64
|
|
6
8
|
* @description
|
|
7
9
|
* A 64-bit signed integer
|
|
8
10
|
*/
|
|
9
|
-
|
|
10
11
|
export class i64 extends Int.with(64) {
|
|
11
12
|
// NOTE without this, we cannot properly determine extensions
|
|
12
13
|
__IntType = 'i64';
|
package/primitive/I8.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { Int } from "../base/Int.js";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* @name i8
|
|
6
8
|
* @description
|
|
7
9
|
* An 8-bit signed integer
|
|
8
10
|
*/
|
|
9
|
-
|
|
10
11
|
export class i8 extends Int.with(8) {
|
|
11
12
|
// NOTE without this, we cannot properly determine extensions
|
|
12
13
|
__IntType = 'i8';
|
package/primitive/U128.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { UInt } from "../base/UInt.js";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* @name u128
|
|
6
8
|
* @description
|
|
7
9
|
* A 128-bit unsigned integer
|
|
8
10
|
*/
|
|
9
|
-
|
|
10
11
|
export class u128 extends UInt.with(128) {
|
|
11
12
|
// NOTE without this, we cannot properly determine extensions
|
|
12
13
|
__UIntType = 'u128';
|
package/primitive/U16.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { UInt } from "../base/UInt.js";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* @name u16
|
|
6
8
|
* @description
|
|
7
9
|
* A 16-bit unsigned integer
|
|
8
10
|
*/
|
|
9
|
-
|
|
10
11
|
export class u16 extends UInt.with(16) {
|
|
11
12
|
// NOTE without this, we cannot properly determine extensions
|
|
12
13
|
__UIntType = 'u16';
|
package/primitive/U256.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { UInt } from "../base/UInt.js";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* @name u256
|
|
6
8
|
* @description
|
|
7
9
|
* A 256-bit unsigned integer
|
|
8
10
|
*/
|
|
9
|
-
|
|
10
11
|
export class u256 extends UInt.with(256) {
|
|
11
12
|
// NOTE without this, we cannot properly determine extensions
|
|
12
13
|
__UIntType = 'u256';
|
package/primitive/U32.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { UInt } from "../base/UInt.js";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* @name u32
|
|
6
8
|
* @description
|
|
7
9
|
* A 32-bit unsigned integer
|
|
8
10
|
*/
|
|
9
|
-
|
|
10
11
|
export class u32 extends UInt.with(32) {
|
|
11
12
|
// NOTE without this, we cannot properly determine extensions
|
|
12
13
|
__UIntType = 'u32';
|
package/primitive/U64.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { UInt } from "../base/UInt.js";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* @name u64
|
|
6
8
|
* @description
|
|
7
9
|
* A 64-bit unsigned integer
|
|
8
10
|
*/
|
|
9
|
-
|
|
10
11
|
export class u64 extends UInt.with(64) {
|
|
11
12
|
// NOTE without this, we cannot properly determine extensions
|
|
12
13
|
__UIntType = 'u64';
|
package/primitive/U8.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { UInt } from "../base/UInt.js";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* @name u8
|
|
6
8
|
* @description
|
|
7
9
|
* An 8-bit unsigned integer
|
|
8
10
|
*/
|
|
9
|
-
|
|
10
11
|
export class u8 extends UInt.with(8) {
|
|
11
12
|
// NOTE without this, we cannot properly determine extensions
|
|
12
13
|
__UIntType = 'u8';
|
package/primitive/USize.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { u32 } from "./U32.js";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* @name USize
|
|
6
8
|
* @description
|
|
@@ -8,11 +10,9 @@ import { u32 } from "./U32.js";
|
|
|
8
10
|
* data. It is a wrapper for [[U32]] as a WASM default (as generated by Rust bindings).
|
|
9
11
|
* It is not to be used, since it created consensus mismatches.
|
|
10
12
|
*/
|
|
11
|
-
|
|
12
13
|
export class usize extends u32 {
|
|
13
14
|
constructor(registry, value) {
|
|
14
15
|
super(registry, value);
|
|
15
16
|
throw new Error('The `usize` type should not be used. Since it is platform-specific, it creates incompatibilities between native (generally u64) and WASM (always u32) code. Use one of the `u32` or `u64` types explicitly.');
|
|
16
17
|
}
|
|
17
|
-
|
|
18
18
|
}
|
package/primitive/index.js
CHANGED
package/types/index.js
CHANGED
package/utils/compareArray.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { isUndefined } from '@polkadot/util';
|
|
4
|
-
import { hasEq } from "./util.js";
|
|
5
|
-
// when the second is an Codec[] that the first has to be as well
|
|
5
|
+
import { hasEq } from "./util.js";
|
|
6
6
|
|
|
7
|
+
// NOTE These are used internally and when comparing objects, expects that
|
|
8
|
+
// when the second is an Codec[] that the first has to be as well
|
|
7
9
|
export function compareArray(a, b) {
|
|
8
10
|
if (Array.isArray(b)) {
|
|
9
11
|
return a.length === b.length && isUndefined(a.find((v, index) => hasEq(v) ? !v.eq(b[index]) : v !== b[index]));
|
|
10
12
|
}
|
|
11
|
-
|
|
12
13
|
return false;
|
|
13
14
|
}
|
package/utils/compareMap.js
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { isObject, isUndefined } from '@polkadot/util';
|
|
4
5
|
import { hasEq } from "./util.js";
|
|
5
|
-
|
|
6
6
|
function hasMismatch(a, b) {
|
|
7
7
|
return isUndefined(a) || (hasEq(a) ? !a.eq(b) : a !== b);
|
|
8
8
|
}
|
|
9
|
-
|
|
10
9
|
function notEntry(value) {
|
|
11
10
|
return !Array.isArray(value) || value.length !== 2;
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
function compareMapArray(a, b) {
|
|
15
13
|
// equal number of entries and each entry in the array should match
|
|
16
14
|
return a.size === b.length && !b.some(e => notEntry(e) || hasMismatch(a.get(e[0]), e[1]));
|
|
17
|
-
}
|
|
18
|
-
// when the second is an Map<string, Codec> that the first has to be as well
|
|
19
|
-
|
|
15
|
+
}
|
|
20
16
|
|
|
17
|
+
// NOTE These are used internally and when comparing objects, expects that
|
|
18
|
+
// when the second is an Map<string, Codec> that the first has to be as well
|
|
21
19
|
export function compareMap(a, b) {
|
|
22
20
|
if (Array.isArray(b)) {
|
|
23
21
|
return compareMapArray(a, b);
|
|
@@ -26,6 +24,5 @@ export function compareMap(a, b) {
|
|
|
26
24
|
} else if (isObject(b)) {
|
|
27
25
|
return compareMapArray(a, Object.entries(b));
|
|
28
26
|
}
|
|
29
|
-
|
|
30
27
|
return false;
|
|
31
28
|
}
|
package/utils/compareSet.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { isObject } from '@polkadot/util';
|
|
4
3
|
|
|
4
|
+
import { isObject } from '@polkadot/util';
|
|
5
5
|
function compareSetArray(a, b) {
|
|
6
6
|
// equal number of entries and each entry in the array should match
|
|
7
7
|
return a.size === b.length && !b.some(e => !a.has(e));
|
|
8
|
-
}
|
|
9
|
-
// when the second is an Set<string, Codec> that the first has to be as well
|
|
10
|
-
|
|
8
|
+
}
|
|
11
9
|
|
|
10
|
+
// NOTE These are used internally and when comparing objects, expects that
|
|
11
|
+
// when the second is an Set<string, Codec> that the first has to be as well
|
|
12
12
|
export function compareSet(a, b) {
|
|
13
13
|
if (Array.isArray(b)) {
|
|
14
14
|
return compareSetArray(a, b);
|
|
@@ -17,6 +17,5 @@ export function compareSet(a, b) {
|
|
|
17
17
|
} else if (isObject(b)) {
|
|
18
18
|
return compareSetArray(a, Object.values(b));
|
|
19
19
|
}
|
|
20
|
-
|
|
21
20
|
return false;
|
|
22
21
|
}
|
package/utils/decodeU8a.js
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
3
4
|
import { u8aToHex } from '@polkadot/util';
|
|
4
|
-
/** @internal */
|
|
5
5
|
|
|
6
|
+
/** @internal */
|
|
6
7
|
function formatFailure(registry, result, {
|
|
7
8
|
message
|
|
8
9
|
}, u8a, i, count, Type, key) {
|
|
9
10
|
let type = '';
|
|
10
|
-
|
|
11
11
|
try {
|
|
12
12
|
type = `: ${new Type(registry).toRawType()}`;
|
|
13
|
-
} catch {
|
|
14
|
-
|
|
13
|
+
} catch {
|
|
14
|
+
// ignore
|
|
15
|
+
}
|
|
15
16
|
|
|
17
|
+
// This is extra debugging info (we most-probably want this in in some way, shape or form,
|
|
18
|
+
// but at this point not quite sure how to include and format it (it can be quite massive)
|
|
19
|
+
// console.error(JSON.stringify(result, null, 2));
|
|
16
20
|
|
|
17
|
-
return `decodeU8a: failed at ${u8aToHex(u8a.subarray(0, 16))}…${key ? ` on ${key}` : ''} (index ${i}/${count})${type}:: ${message}`;
|
|
21
|
+
return `decodeU8a: failed at ${u8aToHex(u8a.subarray(0, 16))}…${key ? ` on ${key}` : ''} (index ${i + 1}/${count})${type}:: ${message}`;
|
|
18
22
|
}
|
|
23
|
+
|
|
19
24
|
/**
|
|
20
25
|
* @internal
|
|
21
26
|
*
|
|
@@ -26,13 +31,10 @@ function formatFailure(registry, result, {
|
|
|
26
31
|
* @param result - The result array (will be returned with values pushed)
|
|
27
32
|
* @param types - The array of CodecClass to decode the U8a against.
|
|
28
33
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
34
|
export function decodeU8a(registry, result, u8a, [Types, keys]) {
|
|
32
35
|
const count = result.length;
|
|
33
36
|
let offset = 0;
|
|
34
37
|
let i = 0;
|
|
35
|
-
|
|
36
38
|
try {
|
|
37
39
|
while (i < count) {
|
|
38
40
|
const value = new Types[i](registry, u8a.subarray(offset));
|
|
@@ -43,21 +45,19 @@ export function decodeU8a(registry, result, u8a, [Types, keys]) {
|
|
|
43
45
|
} catch (error) {
|
|
44
46
|
throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
|
45
47
|
}
|
|
46
|
-
|
|
47
48
|
return [result, offset];
|
|
48
49
|
}
|
|
50
|
+
|
|
49
51
|
/**
|
|
50
52
|
* @internal
|
|
51
53
|
*
|
|
52
54
|
* Split from decodeU8a since this is specialized to zip returns ... while we duplicate, this
|
|
53
55
|
* is all on the hot-path, so it is not great, however there is (some) method behind the madness
|
|
54
56
|
*/
|
|
55
|
-
|
|
56
57
|
export function decodeU8aStruct(registry, result, u8a, [Types, keys]) {
|
|
57
58
|
const count = result.length;
|
|
58
59
|
let offset = 0;
|
|
59
60
|
let i = 0;
|
|
60
|
-
|
|
61
61
|
try {
|
|
62
62
|
while (i < count) {
|
|
63
63
|
const value = new Types[i](registry, u8a.subarray(offset));
|
|
@@ -68,21 +68,19 @@ export function decodeU8aStruct(registry, result, u8a, [Types, keys]) {
|
|
|
68
68
|
} catch (error) {
|
|
69
69
|
throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
|
70
70
|
}
|
|
71
|
-
|
|
72
71
|
return [result, offset];
|
|
73
72
|
}
|
|
73
|
+
|
|
74
74
|
/**
|
|
75
75
|
* @internal
|
|
76
76
|
*
|
|
77
77
|
* Split from decodeU8a since this is specialized to 1 instance ... while we duplicate, this
|
|
78
78
|
* is all on the hot-path, so it is not great, however there is (some) method behind the madness
|
|
79
79
|
*/
|
|
80
|
-
|
|
81
80
|
export function decodeU8aVec(registry, result, u8a, startAt, Type) {
|
|
82
81
|
const count = result.length;
|
|
83
82
|
let offset = startAt;
|
|
84
83
|
let i = 0;
|
|
85
|
-
|
|
86
84
|
try {
|
|
87
85
|
while (i < count) {
|
|
88
86
|
const value = new Type(registry, u8a.subarray(offset));
|
|
@@ -93,6 +91,5 @@ export function decodeU8aVec(registry, result, u8a, startAt, Type) {
|
|
|
93
91
|
} catch (error) {
|
|
94
92
|
throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Type));
|
|
95
93
|
}
|
|
96
|
-
|
|
97
94
|
return [offset, offset - startAt];
|
|
98
95
|
}
|