@polkadot/types-codec 9.3.3 → 9.4.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/Int.js +18 -1
- package/cjs/abstract/Int.js +17 -0
- package/cjs/packageInfo.js +1 -1
- package/package.json +4 -4
- package/packageInfo.js +1 -1
package/abstract/Int.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 { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_QUINTILL, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isBn, isHex, isNumber, isString, isU8a, u8aToBn, u8aToNumber } from '@polkadot/util';
|
|
3
|
+
import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_QUINTILL, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isBn, isFunction, isHex, isNumber, isObject, isString, isU8a, u8aToBn, u8aToNumber } from '@polkadot/util';
|
|
4
4
|
export const DEFAULT_UINT_BITS = 64; // Maximum allowed integer for JS is 2^53 - 1, set limit at 52
|
|
5
5
|
// In this case however, we always print any >32 as hex
|
|
6
6
|
|
|
@@ -36,6 +36,23 @@ function decodeAbstractInt(value, isNegative) {
|
|
|
36
36
|
return value;
|
|
37
37
|
} else if (isBn(value)) {
|
|
38
38
|
return value.toString();
|
|
39
|
+
} else if (isObject(value) && !isFunction(value.toBn)) {
|
|
40
|
+
// Allow the construction from an object with a single top-level key. This means that
|
|
41
|
+
// single key objects can be treated equivalently to numbers, assuming they meet the
|
|
42
|
+
// specific requirements. (This is useful in Weights 1.5 where Objects are compact)
|
|
43
|
+
const keys = Object.keys(value);
|
|
44
|
+
|
|
45
|
+
if (keys.length !== 1) {
|
|
46
|
+
throw new Error('Unable to construct number from multi-key object');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const inner = value[keys[0]];
|
|
50
|
+
|
|
51
|
+
if (!isString(inner) && !isNumber(inner)) {
|
|
52
|
+
throw new Error('Unable to construct from object with non-string/non-number value');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return decodeAbstractInt(inner, isNegative);
|
|
39
56
|
}
|
|
40
57
|
|
|
41
58
|
return bnToBn(value).toString();
|
package/cjs/abstract/Int.js
CHANGED
|
@@ -45,6 +45,23 @@ function decodeAbstractInt(value, isNegative) {
|
|
|
45
45
|
return value;
|
|
46
46
|
} else if ((0, _util.isBn)(value)) {
|
|
47
47
|
return value.toString();
|
|
48
|
+
} else if ((0, _util.isObject)(value) && !(0, _util.isFunction)(value.toBn)) {
|
|
49
|
+
// Allow the construction from an object with a single top-level key. This means that
|
|
50
|
+
// single key objects can be treated equivalently to numbers, assuming they meet the
|
|
51
|
+
// specific requirements. (This is useful in Weights 1.5 where Objects are compact)
|
|
52
|
+
const keys = Object.keys(value);
|
|
53
|
+
|
|
54
|
+
if (keys.length !== 1) {
|
|
55
|
+
throw new Error('Unable to construct number from multi-key object');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const inner = value[keys[0]];
|
|
59
|
+
|
|
60
|
+
if (!(0, _util.isString)(inner) && !(0, _util.isNumber)(inner)) {
|
|
61
|
+
throw new Error('Unable to construct from object with non-string/non-number value');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return decodeAbstractInt(inner, isNegative);
|
|
48
65
|
}
|
|
49
66
|
|
|
50
67
|
return (0, _util.bnToBn)(value).toString();
|
package/cjs/packageInfo.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.4.1",
|
|
24
24
|
"main": "./cjs/index.js",
|
|
25
25
|
"module": "./index.js",
|
|
26
26
|
"types": "./index.d.ts",
|
|
@@ -434,8 +434,8 @@
|
|
|
434
434
|
}
|
|
435
435
|
},
|
|
436
436
|
"dependencies": {
|
|
437
|
-
"@babel/runtime": "^7.
|
|
438
|
-
"@polkadot/util": "^10.1.
|
|
439
|
-
"@polkadot/x-bigint": "^10.1.
|
|
437
|
+
"@babel/runtime": "^7.19.0",
|
|
438
|
+
"@polkadot/util": "^10.1.8",
|
|
439
|
+
"@polkadot/x-bigint": "^10.1.8"
|
|
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: '9.
|
|
8
|
+
version: '9.4.1'
|
|
9
9
|
};
|