@polkadot/types-codec 8.11.3 → 8.13.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 +4 -2
- package/cjs/abstract/Array.js +4 -2
- package/cjs/extended/WrapperKeepOpaque.js +1 -1
- package/cjs/native/Date.js +5 -1
- package/cjs/native/Struct.js +3 -1
- package/cjs/package.json +1 -1
- package/cjs/packageInfo.js +1 -1
- package/cjs/utils/decodeU8a.js +6 -5
- package/cjs/utils/sanitize.js +1 -1
- package/extended/WrapperKeepOpaque.js +2 -2
- package/native/Date.js +5 -1
- package/native/Struct.js +3 -1
- package/package.json +4 -4
- package/packageInfo.js +1 -1
- package/utils/decodeU8a.js +6 -5
- package/utils/sanitize.js +1 -1
package/abstract/Array.js
CHANGED
|
@@ -118,7 +118,7 @@ export class AbstractArray extends Array {
|
|
|
118
118
|
const result = new Array(this.length);
|
|
119
119
|
|
|
120
120
|
for (let i = 0; i < this.length; i++) {
|
|
121
|
-
result[i] = this[i].toHuman(isExtended);
|
|
121
|
+
result[i] = this[i] && this[i].toHuman(isExtended);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
return result;
|
|
@@ -132,7 +132,9 @@ export class AbstractArray extends Array {
|
|
|
132
132
|
const result = new Array(this.length);
|
|
133
133
|
|
|
134
134
|
for (let i = 0; i < this.length; i++) {
|
|
135
|
-
|
|
135
|
+
// We actually log inside the U8a decoding and use JSON.stringify(...), which
|
|
136
|
+
// means that the Vec may be partially populated (same applies to toHuman, same check)
|
|
137
|
+
result[i] = this[i] && this[i].toJSON();
|
|
136
138
|
}
|
|
137
139
|
|
|
138
140
|
return result;
|
package/cjs/abstract/Array.js
CHANGED
|
@@ -127,7 +127,7 @@ class AbstractArray extends Array {
|
|
|
127
127
|
const result = new Array(this.length);
|
|
128
128
|
|
|
129
129
|
for (let i = 0; i < this.length; i++) {
|
|
130
|
-
result[i] = this[i].toHuman(isExtended);
|
|
130
|
+
result[i] = this[i] && this[i].toHuman(isExtended);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
return result;
|
|
@@ -141,7 +141,9 @@ class AbstractArray extends Array {
|
|
|
141
141
|
const result = new Array(this.length);
|
|
142
142
|
|
|
143
143
|
for (let i = 0; i < this.length; i++) {
|
|
144
|
-
|
|
144
|
+
// We actually log inside the U8a decoding and use JSON.stringify(...), which
|
|
145
|
+
// means that the Vec may be partially populated (same applies to toHuman, same check)
|
|
146
|
+
result[i] = this[i] && this[i].toJSON();
|
|
145
147
|
}
|
|
146
148
|
|
|
147
149
|
return result;
|
|
@@ -20,7 +20,7 @@ function decodeRaw(registry, typeName, value) {
|
|
|
20
20
|
|
|
21
21
|
if ((0, _util.isU8a)(value) || (0, _util.isHex)(value)) {
|
|
22
22
|
try {
|
|
23
|
-
const [, u8a] = (0, _util.isHex)(value)
|
|
23
|
+
const [, u8a] = (0, _util.isHex)(value) ? [0, (0, _util.u8aToU8a)(value)] : value instanceof _Raw.Raw ? [0, value.subarray()] : (0, _util.compactStripLength)(value);
|
|
24
24
|
return [Type, new Type(registry, u8a), value];
|
|
25
25
|
} catch {
|
|
26
26
|
return [Type, null, value];
|
package/cjs/native/Date.js
CHANGED
|
@@ -10,6 +10,10 @@ var _util = require("@polkadot/util");
|
|
|
10
10
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
11
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
12
12
|
const BITLENGTH = 64;
|
|
13
|
+
const U8A_OPTS = {
|
|
14
|
+
bitLength: BITLENGTH,
|
|
15
|
+
isLe: true
|
|
16
|
+
};
|
|
13
17
|
|
|
14
18
|
function decodeDate(value) {
|
|
15
19
|
if ((0, _util.isU8a)(value)) {
|
|
@@ -170,7 +174,7 @@ class CodecDate extends Date {
|
|
|
170
174
|
|
|
171
175
|
|
|
172
176
|
toU8a(isBare) {
|
|
173
|
-
return (0, _util.bnToU8a)(this.toNumber(),
|
|
177
|
+
return (0, _util.bnToU8a)(this.toNumber(), U8A_OPTS);
|
|
174
178
|
}
|
|
175
179
|
|
|
176
180
|
}
|
package/cjs/native/Struct.js
CHANGED
|
@@ -267,7 +267,9 @@ class Struct extends Map {
|
|
|
267
267
|
const json = {};
|
|
268
268
|
|
|
269
269
|
for (const [k, v] of this.entries()) {
|
|
270
|
-
const jsonKey = this.#jsonMap.get(k) || k;
|
|
270
|
+
const jsonKey = this.#jsonMap.get(k) || k; // We actually log inside the U8a decoding and use JSON.stringify(...), which
|
|
271
|
+
// means that the Vec may be partially populated (same applies to toHuman, same check)
|
|
272
|
+
|
|
271
273
|
json[jsonKey] = v && v.toJSON();
|
|
272
274
|
}
|
|
273
275
|
|
package/cjs/package.json
CHANGED
package/cjs/packageInfo.js
CHANGED
package/cjs/utils/decodeU8a.js
CHANGED
|
@@ -13,7 +13,7 @@ var _util = require("@polkadot/util");
|
|
|
13
13
|
// SPDX-License-Identifier: Apache-2.0
|
|
14
14
|
|
|
15
15
|
/** @internal */
|
|
16
|
-
function formatFailure(registry, _ref, u8a, i, count, Type, key) {
|
|
16
|
+
function formatFailure(registry, result, _ref, u8a, i, count, Type, key) {
|
|
17
17
|
let {
|
|
18
18
|
message
|
|
19
19
|
} = _ref;
|
|
@@ -22,7 +22,8 @@ function formatFailure(registry, _ref, u8a, i, count, Type, key) {
|
|
|
22
22
|
try {
|
|
23
23
|
type = `: ${new Type(registry).toRawType()}`;
|
|
24
24
|
} catch {// ignore
|
|
25
|
-
}
|
|
25
|
+
} // console.error(JSON.stringify(result, null, 2));
|
|
26
|
+
|
|
26
27
|
|
|
27
28
|
return `decodeU8a: failed at ${(0, _util.u8aToHex)(u8a.subarray(0, 16))}…${key ? ` on ${key}` : ''} (index ${i}/${count})${type}:: ${message}`;
|
|
28
29
|
}
|
|
@@ -52,7 +53,7 @@ function decodeU8a(registry, result, u8a, _ref2) {
|
|
|
52
53
|
i++;
|
|
53
54
|
}
|
|
54
55
|
} catch (error) {
|
|
55
|
-
throw new Error(formatFailure(registry, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
|
56
|
+
throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
return [result, offset];
|
|
@@ -79,7 +80,7 @@ function decodeU8aStruct(registry, result, u8a, _ref3) {
|
|
|
79
80
|
i++;
|
|
80
81
|
}
|
|
81
82
|
} catch (error) {
|
|
82
|
-
throw new Error(formatFailure(registry, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
|
83
|
+
throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
return [result, offset];
|
|
@@ -105,7 +106,7 @@ function decodeU8aVec(registry, result, u8a, startAt, Type) {
|
|
|
105
106
|
i++;
|
|
106
107
|
}
|
|
107
108
|
} catch (error) {
|
|
108
|
-
throw new Error(formatFailure(registry, error, u8a.subarray(offset), i, count, Type));
|
|
109
|
+
throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Type));
|
|
109
110
|
}
|
|
110
111
|
|
|
111
112
|
return [offset, offset - startAt];
|
package/cjs/utils/sanitize.js
CHANGED
|
@@ -18,7 +18,7 @@ exports.trim = trim;
|
|
|
18
18
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
19
19
|
// SPDX-License-Identifier: Apache-2.0
|
|
20
20
|
const BOUNDED = ['BTreeMap', 'BTreeSet', 'HashMap', 'Vec'];
|
|
21
|
-
const ALLOWED_BOXES = BOUNDED.concat(['Compact', 'DoNotConstruct', 'Int', 'Linkage', 'Range', 'RangeInclusive', 'Result', 'Option', 'UInt', 'WrapperKeepOpaque', 'WrapperOpaque']);
|
|
21
|
+
const ALLOWED_BOXES = BOUNDED.concat(['Compact', 'DoNotConstruct', 'Int', 'Linkage', 'Range', 'RangeInclusive', 'Result', 'Opaque', 'Option', 'UInt', 'WrapperKeepOpaque', 'WrapperOpaque']);
|
|
22
22
|
const BOX_PRECEDING = ['<', '(', '[', '"', ',', ' ']; // start of vec, tuple, fixed array, part of struct def or in tuple
|
|
23
23
|
|
|
24
24
|
const mappings = [// alias <T::InherentOfflineReport as InherentOfflineReport>::Inherent -> InherentOfflineReport
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { compactAddLength, compactStripLength, compactToU8a, isHex, isU8a } from '@polkadot/util';
|
|
3
|
+
import { compactAddLength, compactStripLength, compactToU8a, isHex, isU8a, u8aToU8a } from '@polkadot/util';
|
|
4
4
|
import { Raw } from "../native/Raw.js";
|
|
5
5
|
import { typeToConstructor } from "../utils/index.js";
|
|
6
6
|
import { Bytes } from "./Bytes.js";
|
|
@@ -10,7 +10,7 @@ function decodeRaw(registry, typeName, value) {
|
|
|
10
10
|
|
|
11
11
|
if (isU8a(value) || isHex(value)) {
|
|
12
12
|
try {
|
|
13
|
-
const [, u8a] = isHex(value)
|
|
13
|
+
const [, u8a] = isHex(value) ? [0, u8aToU8a(value)] : value instanceof Raw ? [0, value.subarray()] : compactStripLength(value);
|
|
14
14
|
return [Type, new Type(registry, u8a), value];
|
|
15
15
|
} catch {
|
|
16
16
|
return [Type, null, value];
|
package/native/Date.js
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { BN, bnToBn, bnToHex, bnToU8a, isString, isU8a, u8aToBn } from '@polkadot/util';
|
|
4
4
|
const BITLENGTH = 64;
|
|
5
|
+
const U8A_OPTS = {
|
|
6
|
+
bitLength: BITLENGTH,
|
|
7
|
+
isLe: true
|
|
8
|
+
};
|
|
5
9
|
|
|
6
10
|
function decodeDate(value) {
|
|
7
11
|
if (isU8a(value)) {
|
|
@@ -160,7 +164,7 @@ export class CodecDate extends Date {
|
|
|
160
164
|
|
|
161
165
|
|
|
162
166
|
toU8a(isBare) {
|
|
163
|
-
return bnToU8a(this.toNumber(),
|
|
167
|
+
return bnToU8a(this.toNumber(), U8A_OPTS);
|
|
164
168
|
}
|
|
165
169
|
|
|
166
170
|
}
|
package/native/Struct.js
CHANGED
|
@@ -256,7 +256,9 @@ export class Struct extends Map {
|
|
|
256
256
|
const json = {};
|
|
257
257
|
|
|
258
258
|
for (const [k, v] of this.entries()) {
|
|
259
|
-
const jsonKey = this.#jsonMap.get(k) || k;
|
|
259
|
+
const jsonKey = this.#jsonMap.get(k) || k; // We actually log inside the U8a decoding and use JSON.stringify(...), which
|
|
260
|
+
// means that the Vec may be partially populated (same applies to toHuman, same check)
|
|
261
|
+
|
|
260
262
|
json[jsonKey] = v && v.toJSON();
|
|
261
263
|
}
|
|
262
264
|
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"./cjs/detectPackage.js"
|
|
21
21
|
],
|
|
22
22
|
"type": "module",
|
|
23
|
-
"version": "8.
|
|
23
|
+
"version": "8.13.1",
|
|
24
24
|
"main": "./cjs/index.js",
|
|
25
25
|
"module": "./index.js",
|
|
26
26
|
"types": "./index.d.ts",
|
|
@@ -435,7 +435,7 @@
|
|
|
435
435
|
},
|
|
436
436
|
"dependencies": {
|
|
437
437
|
"@babel/runtime": "^7.18.6",
|
|
438
|
-
"@polkadot/util": "^
|
|
439
|
-
"@polkadot/x-bigint": "^
|
|
438
|
+
"@polkadot/util": "^10.0.2",
|
|
439
|
+
"@polkadot/x-bigint": "^10.0.2"
|
|
440
440
|
}
|
|
441
|
-
}
|
|
441
|
+
}
|
package/packageInfo.js
CHANGED
|
@@ -5,5 +5,5 @@ export const packageInfo = {
|
|
|
5
5
|
name: '@polkadot/types-codec',
|
|
6
6
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
7
7
|
type: 'esm',
|
|
8
|
-
version: '8.
|
|
8
|
+
version: '8.13.1'
|
|
9
9
|
};
|
package/utils/decodeU8a.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { u8aToHex } from '@polkadot/util';
|
|
4
4
|
/** @internal */
|
|
5
5
|
|
|
6
|
-
function formatFailure(registry, {
|
|
6
|
+
function formatFailure(registry, result, {
|
|
7
7
|
message
|
|
8
8
|
}, u8a, i, count, Type, key) {
|
|
9
9
|
let type = '';
|
|
@@ -11,7 +11,8 @@ function formatFailure(registry, {
|
|
|
11
11
|
try {
|
|
12
12
|
type = `: ${new Type(registry).toRawType()}`;
|
|
13
13
|
} catch {// ignore
|
|
14
|
-
}
|
|
14
|
+
} // console.error(JSON.stringify(result, null, 2));
|
|
15
|
+
|
|
15
16
|
|
|
16
17
|
return `decodeU8a: failed at ${u8aToHex(u8a.subarray(0, 16))}…${key ? ` on ${key}` : ''} (index ${i}/${count})${type}:: ${message}`;
|
|
17
18
|
}
|
|
@@ -40,7 +41,7 @@ export function decodeU8a(registry, result, u8a, [Types, keys]) {
|
|
|
40
41
|
i++;
|
|
41
42
|
}
|
|
42
43
|
} catch (error) {
|
|
43
|
-
throw new Error(formatFailure(registry, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
|
44
|
+
throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
return [result, offset];
|
|
@@ -65,7 +66,7 @@ export function decodeU8aStruct(registry, result, u8a, [Types, keys]) {
|
|
|
65
66
|
i++;
|
|
66
67
|
}
|
|
67
68
|
} catch (error) {
|
|
68
|
-
throw new Error(formatFailure(registry, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
|
69
|
+
throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Types[i], keys[i]));
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
return [result, offset];
|
|
@@ -90,7 +91,7 @@ export function decodeU8aVec(registry, result, u8a, startAt, Type) {
|
|
|
90
91
|
i++;
|
|
91
92
|
}
|
|
92
93
|
} catch (error) {
|
|
93
|
-
throw new Error(formatFailure(registry, error, u8a.subarray(offset), i, count, Type));
|
|
94
|
+
throw new Error(formatFailure(registry, result, error, u8a.subarray(offset), i, count, Type));
|
|
94
95
|
}
|
|
95
96
|
|
|
96
97
|
return [offset, offset - startAt];
|
package/utils/sanitize.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
const BOUNDED = ['BTreeMap', 'BTreeSet', 'HashMap', 'Vec'];
|
|
4
|
-
const ALLOWED_BOXES = BOUNDED.concat(['Compact', 'DoNotConstruct', 'Int', 'Linkage', 'Range', 'RangeInclusive', 'Result', 'Option', 'UInt', 'WrapperKeepOpaque', 'WrapperOpaque']);
|
|
4
|
+
const ALLOWED_BOXES = BOUNDED.concat(['Compact', 'DoNotConstruct', 'Int', 'Linkage', 'Range', 'RangeInclusive', 'Result', 'Opaque', 'Option', 'UInt', 'WrapperKeepOpaque', 'WrapperOpaque']);
|
|
5
5
|
const BOX_PRECEDING = ['<', '(', '[', '"', ',', ' ']; // start of vec, tuple, fixed array, part of struct def or in tuple
|
|
6
6
|
|
|
7
7
|
const mappings = [// alias <T::InherentOfflineReport as InherentOfflineReport>::Inherent -> InherentOfflineReport
|