@polkadot/types-codec 8.3.3-2 → 8.3.3-5
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/base/Compact.js +6 -6
- package/cjs/base/Compact.js +5 -5
- package/cjs/packageInfo.js +1 -1
- package/package.json +1 -1
- package/packageInfo.js +1 -1
package/base/Compact.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { compactFromU8a, compactToU8a,
|
|
3
|
+
import { compactFromU8a, compactToU8a, isU8a } from '@polkadot/util';
|
|
4
4
|
import { typeToConstructor } from "../utils/index.js";
|
|
5
5
|
/**
|
|
6
6
|
* @name Compact
|
|
@@ -35,16 +35,16 @@ export class Compact {
|
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
static decodeCompact(registry, Type, value) {
|
|
38
|
-
if (value
|
|
38
|
+
if (isU8a(value)) {
|
|
39
|
+
const [decodedLength, bn] = compactFromU8a(value);
|
|
40
|
+
return [new Type(registry, bn), decodedLength];
|
|
41
|
+
} else if (value instanceof Compact) {
|
|
39
42
|
return [new Type(registry, value.#raw), 0];
|
|
40
43
|
} else if (value instanceof Type) {
|
|
41
44
|
return [value, 0];
|
|
42
|
-
} else if (isString(value) || isNumber(value) || isBn(value) || isBigInt(value)) {
|
|
43
|
-
return [new Type(registry, value), 0];
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
return [new Type(registry, bn), decodedLength];
|
|
47
|
+
return [new Type(registry, value), 0];
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* @description The length of the value when encoded as a Uint8Array
|
package/cjs/base/Compact.js
CHANGED
|
@@ -45,16 +45,16 @@ class Compact {
|
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
static decodeCompact(registry, Type, value) {
|
|
48
|
-
if (
|
|
48
|
+
if ((0, _util.isU8a)(value)) {
|
|
49
|
+
const [decodedLength, bn] = (0, _util.compactFromU8a)(value);
|
|
50
|
+
return [new Type(registry, bn), decodedLength];
|
|
51
|
+
} else if (value instanceof Compact) {
|
|
49
52
|
return [new Type(registry, value.#raw), 0];
|
|
50
53
|
} else if (value instanceof Type) {
|
|
51
54
|
return [value, 0];
|
|
52
|
-
} else if ((0, _util.isString)(value) || (0, _util.isNumber)(value) || (0, _util.isBn)(value) || (0, _util.isBigInt)(value)) {
|
|
53
|
-
return [new Type(registry, value), 0];
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
return [new Type(registry, bn), decodedLength];
|
|
57
|
+
return [new Type(registry, value), 0];
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
60
|
* @description The length of the value when encoded as a Uint8Array
|
package/cjs/packageInfo.js
CHANGED
package/package.json
CHANGED
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.3.3-
|
|
8
|
+
version: '8.3.3-5'
|
|
9
9
|
};
|