@polkadot/types-codec 9.5.1 → 9.6.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 +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 +7 -17
- 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 +4 -4
- 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 +9 -14
- 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/base/VecFixed.js
CHANGED
|
@@ -4,30 +4,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.VecFixed = void 0;
|
|
7
|
-
|
|
8
7
|
var _util = require("@polkadot/util");
|
|
9
|
-
|
|
10
8
|
var _Array = require("../abstract/Array");
|
|
11
|
-
|
|
12
9
|
var _utils = require("../utils");
|
|
13
|
-
|
|
14
10
|
var _Vec = require("./Vec");
|
|
15
|
-
|
|
16
11
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
17
12
|
// SPDX-License-Identifier: Apache-2.0
|
|
13
|
+
|
|
18
14
|
function noopSetDefinition(d) {
|
|
19
15
|
return d;
|
|
20
16
|
}
|
|
17
|
+
|
|
21
18
|
/**
|
|
22
19
|
* @name VecFixed
|
|
23
20
|
* @description
|
|
24
21
|
* This manages codec arrays of a fixed length
|
|
25
22
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
23
|
class VecFixed extends _Array.AbstractArray {
|
|
29
24
|
#Type;
|
|
30
|
-
|
|
31
25
|
constructor(registry, Type, length) {
|
|
32
26
|
let value = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
33
27
|
let {
|
|
@@ -38,12 +32,11 @@ class VecFixed extends _Array.AbstractArray {
|
|
|
38
32
|
this.#Type = definition || setDefinition((0, _utils.typeToConstructor)(registry, Type));
|
|
39
33
|
this.initialU8aLength = ((0, _util.isU8a)(value) ? (0, _utils.decodeU8aVec)(registry, this, value, 0, this.#Type) : (0, _Vec.decodeVec)(registry, this, value, 0, this.#Type))[1];
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
static with(Type, length) {
|
|
43
|
-
let definition;
|
|
36
|
+
let definition;
|
|
44
37
|
|
|
38
|
+
// eslint-disable-next-line no-return-assign
|
|
45
39
|
const setDefinition = d => definition = d;
|
|
46
|
-
|
|
47
40
|
return class extends VecFixed {
|
|
48
41
|
constructor(registry, value) {
|
|
49
42
|
super(registry, Type, length, value, {
|
|
@@ -51,57 +44,47 @@ class VecFixed extends _Array.AbstractArray {
|
|
|
51
44
|
setDefinition
|
|
52
45
|
});
|
|
53
46
|
}
|
|
54
|
-
|
|
55
47
|
};
|
|
56
48
|
}
|
|
49
|
+
|
|
57
50
|
/**
|
|
58
51
|
* @description The type for the items
|
|
59
52
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
53
|
get Type() {
|
|
63
54
|
return new this.#Type(this.registry).toRawType();
|
|
64
55
|
}
|
|
56
|
+
|
|
65
57
|
/**
|
|
66
58
|
* @description The length of the value when encoded as a Uint8Array
|
|
67
59
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
60
|
get encodedLength() {
|
|
71
61
|
let total = 0;
|
|
72
|
-
|
|
73
62
|
for (let i = 0; i < this.length; i++) {
|
|
74
63
|
total += this[i].encodedLength;
|
|
75
64
|
}
|
|
76
|
-
|
|
77
65
|
return total;
|
|
78
66
|
}
|
|
67
|
+
|
|
79
68
|
/**
|
|
80
69
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
81
70
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
71
|
inspect() {
|
|
85
72
|
return {
|
|
86
73
|
inner: this.inspectInner()
|
|
87
74
|
};
|
|
88
75
|
}
|
|
89
|
-
|
|
90
76
|
toU8a() {
|
|
91
77
|
// we override, we don't add the length prefix for ourselves, and at the same time we
|
|
92
78
|
// ignore isBare on entries, since they should be properly encoded at all times
|
|
93
79
|
const encoded = this.toU8aInner();
|
|
94
80
|
return encoded.length ? (0, _util.u8aConcatStrict)(encoded) : new Uint8Array([]);
|
|
95
81
|
}
|
|
82
|
+
|
|
96
83
|
/**
|
|
97
84
|
* @description Returns the base runtime type name for this instance
|
|
98
85
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
86
|
toRawType() {
|
|
102
87
|
return `[${this.Type};${this.length}]`;
|
|
103
88
|
}
|
|
104
|
-
|
|
105
89
|
}
|
|
106
|
-
|
|
107
90
|
exports.VecFixed = VecFixed;
|
package/cjs/base/index.js
CHANGED
|
@@ -75,27 +75,15 @@ Object.defineProperty(exports, "VecFixed", {
|
|
|
75
75
|
return _VecFixed.VecFixed;
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
|
-
|
|
79
78
|
var _Compact = require("./Compact");
|
|
80
|
-
|
|
81
79
|
var _DoNotConstruct = require("./DoNotConstruct");
|
|
82
|
-
|
|
83
80
|
var _Enum = require("./Enum");
|
|
84
|
-
|
|
85
81
|
var _Int = require("./Int");
|
|
86
|
-
|
|
87
82
|
var _Null = require("./Null");
|
|
88
|
-
|
|
89
83
|
var _Option = require("./Option");
|
|
90
|
-
|
|
91
84
|
var _Result = require("./Result");
|
|
92
|
-
|
|
93
85
|
var _Tuple = require("./Tuple");
|
|
94
|
-
|
|
95
86
|
var _UInt = require("./UInt");
|
|
96
|
-
|
|
97
87
|
var _Vec = require("./Vec");
|
|
98
|
-
|
|
99
88
|
var _VecAny = require("./VecAny");
|
|
100
|
-
|
|
101
89
|
var _VecFixed = require("./VecFixed");
|
package/cjs/bundle.js
CHANGED
|
@@ -12,11 +12,8 @@ Object.defineProperty(exports, "packageInfo", {
|
|
|
12
12
|
return _packageInfo.packageInfo;
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
|
-
|
|
16
15
|
var _packageInfo = require("./packageInfo");
|
|
17
|
-
|
|
18
16
|
var _abstract = require("./abstract");
|
|
19
|
-
|
|
20
17
|
Object.keys(_abstract).forEach(function (key) {
|
|
21
18
|
if (key === "default" || key === "__esModule") return;
|
|
22
19
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -28,9 +25,7 @@ Object.keys(_abstract).forEach(function (key) {
|
|
|
28
25
|
}
|
|
29
26
|
});
|
|
30
27
|
});
|
|
31
|
-
|
|
32
28
|
var _base = require("./base");
|
|
33
|
-
|
|
34
29
|
Object.keys(_base).forEach(function (key) {
|
|
35
30
|
if (key === "default" || key === "__esModule") return;
|
|
36
31
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -42,9 +37,7 @@ Object.keys(_base).forEach(function (key) {
|
|
|
42
37
|
}
|
|
43
38
|
});
|
|
44
39
|
});
|
|
45
|
-
|
|
46
40
|
var _extended = require("./extended");
|
|
47
|
-
|
|
48
41
|
Object.keys(_extended).forEach(function (key) {
|
|
49
42
|
if (key === "default" || key === "__esModule") return;
|
|
50
43
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -56,9 +49,7 @@ Object.keys(_extended).forEach(function (key) {
|
|
|
56
49
|
}
|
|
57
50
|
});
|
|
58
51
|
});
|
|
59
|
-
|
|
60
52
|
var _native = require("./native");
|
|
61
|
-
|
|
62
53
|
Object.keys(_native).forEach(function (key) {
|
|
63
54
|
if (key === "default" || key === "__esModule") return;
|
|
64
55
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -70,9 +61,7 @@ Object.keys(_native).forEach(function (key) {
|
|
|
70
61
|
}
|
|
71
62
|
});
|
|
72
63
|
});
|
|
73
|
-
|
|
74
64
|
var _primitive = require("./primitive");
|
|
75
|
-
|
|
76
65
|
Object.keys(_primitive).forEach(function (key) {
|
|
77
66
|
if (key === "default" || key === "__esModule") return;
|
|
78
67
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -84,9 +73,7 @@ Object.keys(_primitive).forEach(function (key) {
|
|
|
84
73
|
}
|
|
85
74
|
});
|
|
86
75
|
});
|
|
87
|
-
|
|
88
76
|
var _utils = require("./utils");
|
|
89
|
-
|
|
90
77
|
Object.keys(_utils).forEach(function (key) {
|
|
91
78
|
if (key === "default" || key === "__esModule") return;
|
|
92
79
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
package/cjs/detectPackage.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _util = require("@polkadot/util");
|
|
6
|
-
|
|
7
5
|
var _detectOther = _interopRequireDefault(require("./detectOther"));
|
|
8
|
-
|
|
9
6
|
var _packageInfo = require("./packageInfo");
|
|
10
|
-
|
|
11
7
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
12
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
13
10
|
// Do not edit, auto-generated by @polkadot/dev
|
|
11
|
+
|
|
14
12
|
(0, _util.detectPackage)(_packageInfo.packageInfo, null, _detectOther.default);
|
package/cjs/extended/BTreeMap.js
CHANGED
|
@@ -4,21 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.BTreeMap = void 0;
|
|
7
|
-
|
|
8
7
|
var _Map = require("./Map");
|
|
9
|
-
|
|
10
8
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
11
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
10
|
+
|
|
12
11
|
class BTreeMap extends _Map.CodecMap {
|
|
13
12
|
static with(keyType, valType) {
|
|
14
13
|
return class extends BTreeMap {
|
|
15
14
|
constructor(registry, value) {
|
|
16
15
|
super(registry, keyType, valType, value, 'BTreeMap');
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
};
|
|
20
18
|
}
|
|
21
|
-
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
exports.BTreeMap = BTreeMap;
|
package/cjs/extended/BTreeSet.js
CHANGED
|
@@ -4,31 +4,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.BTreeSet = 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
|
const l = (0, _util.logger)('BTreeSet');
|
|
15
|
-
/** @internal */
|
|
16
13
|
|
|
14
|
+
/** @internal */
|
|
17
15
|
function decodeSetFromU8a(registry, ValClass, u8a) {
|
|
18
16
|
const output = new Set();
|
|
19
17
|
const [offset, count] = (0, _util.compactFromU8aLim)(u8a);
|
|
20
18
|
const result = new Array(count);
|
|
21
19
|
const [decodedLength] = (0, _utils.decodeU8aVec)(registry, result, u8a, offset, ValClass);
|
|
22
|
-
|
|
23
20
|
for (let i = 0; i < count; i++) {
|
|
24
21
|
output.add(result[i]);
|
|
25
22
|
}
|
|
26
|
-
|
|
27
23
|
return [ValClass, output, decodedLength];
|
|
28
24
|
}
|
|
29
|
-
/** @internal */
|
|
30
|
-
|
|
31
25
|
|
|
26
|
+
/** @internal */
|
|
32
27
|
function decodeSetFromSet(registry, ValClass, value) {
|
|
33
28
|
const output = new Set();
|
|
34
29
|
value.forEach(val => {
|
|
@@ -41,6 +36,7 @@ function decodeSetFromSet(registry, ValClass, value) {
|
|
|
41
36
|
});
|
|
42
37
|
return [ValClass, output, 0];
|
|
43
38
|
}
|
|
39
|
+
|
|
44
40
|
/**
|
|
45
41
|
* Decode input to pass into constructor.
|
|
46
42
|
*
|
|
@@ -55,11 +51,8 @@ function decodeSetFromSet(registry, ValClass, value) {
|
|
|
55
51
|
* @param jsonSet
|
|
56
52
|
* @internal
|
|
57
53
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
54
|
function decodeSet(registry, valType, value) {
|
|
61
55
|
const ValClass = (0, _utils.typeToConstructor)(registry, valType);
|
|
62
|
-
|
|
63
56
|
if (!value) {
|
|
64
57
|
return [ValClass, new Set(), 0];
|
|
65
58
|
} else if ((0, _util.isU8a)(value) || (0, _util.isHex)(value)) {
|
|
@@ -67,13 +60,10 @@ function decodeSet(registry, valType, value) {
|
|
|
67
60
|
} else if (Array.isArray(value) || value instanceof Set) {
|
|
68
61
|
return decodeSetFromSet(registry, ValClass, value);
|
|
69
62
|
}
|
|
70
|
-
|
|
71
63
|
throw new Error('BTreeSet: cannot decode type');
|
|
72
64
|
}
|
|
73
|
-
|
|
74
65
|
class BTreeSet extends Set {
|
|
75
66
|
#ValClass;
|
|
76
|
-
|
|
77
67
|
constructor(registry, valType, rawValue) {
|
|
78
68
|
const [ValClass, values, decodedLength] = decodeSet(registry, valType, rawValue);
|
|
79
69
|
super((0, _utils.sortSet)(values));
|
|
@@ -81,164 +71,134 @@ class BTreeSet extends Set {
|
|
|
81
71
|
this.initialU8aLength = decodedLength;
|
|
82
72
|
this.#ValClass = ValClass;
|
|
83
73
|
}
|
|
84
|
-
|
|
85
74
|
static with(valType) {
|
|
86
75
|
return class extends BTreeSet {
|
|
87
76
|
constructor(registry, value) {
|
|
88
77
|
super(registry, valType, value);
|
|
89
78
|
}
|
|
90
|
-
|
|
91
79
|
};
|
|
92
80
|
}
|
|
81
|
+
|
|
93
82
|
/**
|
|
94
83
|
* @description The length of the value when encoded as a Uint8Array
|
|
95
84
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
85
|
get encodedLength() {
|
|
99
86
|
let len = (0, _util.compactToU8a)(this.size).length;
|
|
100
|
-
|
|
101
87
|
for (const v of this.values()) {
|
|
102
88
|
len += v.encodedLength;
|
|
103
89
|
}
|
|
104
|
-
|
|
105
90
|
return len;
|
|
106
91
|
}
|
|
92
|
+
|
|
107
93
|
/**
|
|
108
94
|
* @description Returns a hash of the value
|
|
109
95
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
96
|
get hash() {
|
|
113
97
|
return this.registry.hash(this.toU8a());
|
|
114
98
|
}
|
|
99
|
+
|
|
115
100
|
/**
|
|
116
101
|
* @description Checks if the value is an empty value
|
|
117
102
|
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
103
|
get isEmpty() {
|
|
121
104
|
return this.size === 0;
|
|
122
105
|
}
|
|
106
|
+
|
|
123
107
|
/**
|
|
124
108
|
* @description The actual set values as a string[]
|
|
125
109
|
*/
|
|
126
|
-
|
|
127
|
-
|
|
128
110
|
get strings() {
|
|
129
111
|
return [...super.values()].map(v => v.toString());
|
|
130
112
|
}
|
|
113
|
+
|
|
131
114
|
/**
|
|
132
115
|
* @description Compares the value of the input to see if there is a match
|
|
133
116
|
*/
|
|
134
|
-
|
|
135
|
-
|
|
136
117
|
eq(other) {
|
|
137
118
|
return (0, _utils.compareSet)(this, other);
|
|
138
119
|
}
|
|
120
|
+
|
|
139
121
|
/**
|
|
140
122
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
141
123
|
*/
|
|
142
|
-
|
|
143
|
-
|
|
144
124
|
inspect() {
|
|
145
125
|
const inner = new Array();
|
|
146
|
-
|
|
147
126
|
for (const v of this.values()) {
|
|
148
127
|
inner.push(v.inspect());
|
|
149
128
|
}
|
|
150
|
-
|
|
151
129
|
return {
|
|
152
130
|
inner,
|
|
153
131
|
outer: [(0, _util.compactToU8a)(this.size)]
|
|
154
132
|
};
|
|
155
133
|
}
|
|
134
|
+
|
|
156
135
|
/**
|
|
157
136
|
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
158
137
|
*/
|
|
159
|
-
|
|
160
|
-
|
|
161
138
|
toHex() {
|
|
162
139
|
return (0, _util.u8aToHex)(this.toU8a());
|
|
163
140
|
}
|
|
141
|
+
|
|
164
142
|
/**
|
|
165
143
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
166
144
|
*/
|
|
167
|
-
|
|
168
|
-
|
|
169
145
|
toHuman(isExtended) {
|
|
170
146
|
const json = [];
|
|
171
|
-
|
|
172
147
|
for (const v of this.values()) {
|
|
173
148
|
json.push(v.toHuman(isExtended));
|
|
174
149
|
}
|
|
175
|
-
|
|
176
150
|
return json;
|
|
177
151
|
}
|
|
152
|
+
|
|
178
153
|
/**
|
|
179
154
|
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
180
155
|
*/
|
|
181
|
-
|
|
182
|
-
|
|
183
156
|
toJSON() {
|
|
184
157
|
const json = [];
|
|
185
|
-
|
|
186
158
|
for (const v of this.values()) {
|
|
187
159
|
json.push(v.toJSON());
|
|
188
160
|
}
|
|
189
|
-
|
|
190
161
|
return json;
|
|
191
162
|
}
|
|
163
|
+
|
|
192
164
|
/**
|
|
193
165
|
* @description Returns the base runtime type name for this instance
|
|
194
166
|
*/
|
|
195
|
-
|
|
196
|
-
|
|
197
167
|
toRawType() {
|
|
198
168
|
return `BTreeSet<${this.registry.getClassName(this.#ValClass) || new this.#ValClass(this.registry).toRawType()}>`;
|
|
199
169
|
}
|
|
170
|
+
|
|
200
171
|
/**
|
|
201
172
|
* @description Converts the value in a best-fit primitive form
|
|
202
173
|
*/
|
|
203
|
-
|
|
204
|
-
|
|
205
174
|
toPrimitive() {
|
|
206
175
|
const json = [];
|
|
207
|
-
|
|
208
176
|
for (const v of this.values()) {
|
|
209
177
|
json.push(v.toPrimitive());
|
|
210
178
|
}
|
|
211
|
-
|
|
212
179
|
return json;
|
|
213
180
|
}
|
|
181
|
+
|
|
214
182
|
/**
|
|
215
183
|
* @description Returns the string representation of the value
|
|
216
184
|
*/
|
|
217
|
-
|
|
218
|
-
|
|
219
185
|
toString() {
|
|
220
186
|
return (0, _util.stringify)(this.toJSON());
|
|
221
187
|
}
|
|
188
|
+
|
|
222
189
|
/**
|
|
223
190
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
224
191
|
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
225
192
|
*/
|
|
226
|
-
|
|
227
|
-
|
|
228
193
|
toU8a(isBare) {
|
|
229
194
|
const encoded = new Array();
|
|
230
|
-
|
|
231
195
|
if (!isBare) {
|
|
232
196
|
encoded.push((0, _util.compactToU8a)(this.size));
|
|
233
197
|
}
|
|
234
|
-
|
|
235
198
|
for (const v of this.values()) {
|
|
236
199
|
encoded.push(v.toU8a(isBare));
|
|
237
200
|
}
|
|
238
|
-
|
|
239
201
|
return (0, _util.u8aConcatStrict)(encoded);
|
|
240
202
|
}
|
|
241
|
-
|
|
242
203
|
}
|
|
243
|
-
|
|
244
204
|
exports.BTreeSet = BTreeSet;
|
package/cjs/extended/BitVec.js
CHANGED
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.BitVec = void 0;
|
|
7
|
-
|
|
8
7
|
var _util = require("@polkadot/util");
|
|
9
|
-
|
|
10
8
|
var _Raw = require("../native/Raw");
|
|
11
|
-
|
|
12
9
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
13
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
14
11
|
|
|
@@ -16,43 +13,39 @@ var _Raw = require("../native/Raw");
|
|
|
16
13
|
function decodeBitVecU8a(value) {
|
|
17
14
|
if (!value || !value.length) {
|
|
18
15
|
return [0, new Uint8Array()];
|
|
19
|
-
}
|
|
20
|
-
|
|
16
|
+
}
|
|
21
17
|
|
|
18
|
+
// handle all other Uint8Array inputs, these do have a length prefix which is the number of bits encoded
|
|
22
19
|
const [offset, length] = (0, _util.compactFromU8aLim)(value);
|
|
23
20
|
const total = offset + Math.ceil(length / 8);
|
|
24
|
-
|
|
25
21
|
if (total > value.length) {
|
|
26
22
|
throw new Error(`BitVec: required length less than remainder, expected at least ${total}, found ${value.length}`);
|
|
27
23
|
}
|
|
28
|
-
|
|
29
24
|
return [length, value.subarray(offset, total)];
|
|
30
25
|
}
|
|
31
|
-
/** @internal */
|
|
32
|
-
|
|
33
26
|
|
|
27
|
+
/** @internal */
|
|
34
28
|
function decodeBitVec(value) {
|
|
35
29
|
if (Array.isArray(value) || (0, _util.isString)(value)) {
|
|
36
30
|
const u8a = (0, _util.u8aToU8a)(value);
|
|
37
31
|
return [u8a.length / 8, u8a];
|
|
38
32
|
}
|
|
39
|
-
|
|
40
33
|
return decodeBitVecU8a(value);
|
|
41
34
|
}
|
|
35
|
+
|
|
42
36
|
/**
|
|
43
37
|
* @name BitVec
|
|
44
38
|
* @description
|
|
45
39
|
* A BitVec that represents an array of bits. The bits are however stored encoded. The difference between this
|
|
46
40
|
* and a normal Bytes would be that the length prefix indicates the number of bits encoded, not the bytes
|
|
47
41
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
42
|
class BitVec extends _Raw.Raw {
|
|
51
43
|
#decodedLength;
|
|
52
|
-
#isMsb;
|
|
44
|
+
#isMsb;
|
|
45
|
+
|
|
46
|
+
// In lieu of having the Msb/Lsb identifiers passed through, we default to assuming
|
|
53
47
|
// we are dealing with Lsb, which is the default (as of writing) BitVec format used
|
|
54
48
|
// in the Polkadot code (this only affects the toHuman displays)
|
|
55
|
-
|
|
56
49
|
constructor(registry, value) {
|
|
57
50
|
let isMsb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
58
51
|
const [decodedLength, u8a] = decodeBitVec(value);
|
|
@@ -60,47 +53,40 @@ class BitVec extends _Raw.Raw {
|
|
|
60
53
|
this.#decodedLength = decodedLength;
|
|
61
54
|
this.#isMsb = isMsb;
|
|
62
55
|
}
|
|
56
|
+
|
|
63
57
|
/**
|
|
64
58
|
* @description The length of the value when encoded as a Uint8Array
|
|
65
59
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
60
|
get encodedLength() {
|
|
69
61
|
return this.length + (0, _util.compactToU8a)(this.#decodedLength).length;
|
|
70
62
|
}
|
|
63
|
+
|
|
71
64
|
/**
|
|
72
65
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
73
66
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
67
|
inspect() {
|
|
77
68
|
return {
|
|
78
69
|
outer: [(0, _util.compactToU8a)(this.#decodedLength), super.toU8a()]
|
|
79
70
|
};
|
|
80
71
|
}
|
|
81
|
-
|
|
82
72
|
toHuman() {
|
|
83
73
|
return `0b${[...this.toU8a(true)].map(d => `00000000${d.toString(2)}`.slice(-8)).map(s => this.#isMsb ? s : s.split('').reverse().join('')).join('_')}`;
|
|
84
74
|
}
|
|
75
|
+
|
|
85
76
|
/**
|
|
86
77
|
* @description Returns the base runtime type name for this instance
|
|
87
78
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
90
79
|
toRawType() {
|
|
91
80
|
return 'BitVec';
|
|
92
81
|
}
|
|
82
|
+
|
|
93
83
|
/**
|
|
94
84
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
95
85
|
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
96
86
|
*/
|
|
97
|
-
|
|
98
|
-
|
|
99
87
|
toU8a(isBare) {
|
|
100
88
|
const bitVec = super.toU8a();
|
|
101
89
|
return isBare ? bitVec : (0, _util.u8aConcatStrict)([(0, _util.compactToU8a)(this.#decodedLength), bitVec]);
|
|
102
90
|
}
|
|
103
|
-
|
|
104
91
|
}
|
|
105
|
-
|
|
106
92
|
exports.BitVec = BitVec;
|
package/cjs/extended/Bytes.js
CHANGED
|
@@ -4,34 +4,31 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Bytes = void 0;
|
|
7
|
-
|
|
8
7
|
var _util = require("@polkadot/util");
|
|
9
|
-
|
|
10
8
|
var _Raw = require("../native/Raw");
|
|
11
|
-
|
|
12
9
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
13
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
|
|
14
12
|
// Bytes are used for things like on-chain code, so it has a healthy limit
|
|
15
13
|
const MAX_LENGTH = 10 * 1024 * 1024;
|
|
16
|
-
/** @internal */
|
|
17
14
|
|
|
15
|
+
/** @internal */
|
|
18
16
|
function decodeBytesU8a(value) {
|
|
19
17
|
if (!value.length) {
|
|
20
18
|
return [new Uint8Array(), 0];
|
|
21
|
-
}
|
|
22
|
-
|
|
19
|
+
}
|
|
23
20
|
|
|
21
|
+
// handle all other Uint8Array inputs, these do have a length prefix
|
|
24
22
|
const [offset, length] = (0, _util.compactFromU8aLim)(value);
|
|
25
23
|
const total = offset + length;
|
|
26
|
-
|
|
27
24
|
if (length > MAX_LENGTH) {
|
|
28
25
|
throw new Error(`Bytes length ${length.toString()} exceeds ${MAX_LENGTH}`);
|
|
29
26
|
} else if (total > value.length) {
|
|
30
27
|
throw new Error(`Bytes: required length less than remainder, expected at least ${total}, found ${value.length}`);
|
|
31
28
|
}
|
|
32
|
-
|
|
33
29
|
return [value.subarray(offset, total), total];
|
|
34
30
|
}
|
|
31
|
+
|
|
35
32
|
/**
|
|
36
33
|
* @name Bytes
|
|
37
34
|
* @description
|
|
@@ -39,50 +36,42 @@ function decodeBytesU8a(value) {
|
|
|
39
36
|
* is that this version allows for length-encoding. (i.e. it is a variable-item codec, the same
|
|
40
37
|
* as what is found in [[Text]] and [[Vec]])
|
|
41
38
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
39
|
class Bytes extends _Raw.Raw {
|
|
45
40
|
constructor(registry, value) {
|
|
46
41
|
const [u8a, decodedLength] = (0, _util.isU8a)(value) && !(value instanceof _Raw.Raw) ? decodeBytesU8a(value) : Array.isArray(value) || (0, _util.isString)(value) ? [(0, _util.u8aToU8a)(value), 0] : [value, 0];
|
|
47
42
|
super(registry, u8a, decodedLength);
|
|
48
43
|
}
|
|
44
|
+
|
|
49
45
|
/**
|
|
50
46
|
* @description The length of the value when encoded as a Uint8Array
|
|
51
47
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
48
|
get encodedLength() {
|
|
55
49
|
return this.length + (0, _util.compactToU8a)(this.length).length;
|
|
56
50
|
}
|
|
51
|
+
|
|
57
52
|
/**
|
|
58
53
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
59
54
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
55
|
inspect(isBare) {
|
|
63
56
|
const clength = (0, _util.compactToU8a)(this.length);
|
|
64
57
|
return {
|
|
65
58
|
outer: isBare ? [super.toU8a()] : this.length ? [clength, super.toU8a()] : [clength]
|
|
66
59
|
};
|
|
67
60
|
}
|
|
61
|
+
|
|
68
62
|
/**
|
|
69
63
|
* @description Returns the base runtime type name for this instance
|
|
70
64
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
65
|
toRawType() {
|
|
74
66
|
return 'Bytes';
|
|
75
67
|
}
|
|
68
|
+
|
|
76
69
|
/**
|
|
77
70
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
78
71
|
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
79
72
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
82
73
|
toU8a(isBare) {
|
|
83
74
|
return isBare ? super.toU8a(isBare) : (0, _util.compactAddLength)(this);
|
|
84
75
|
}
|
|
85
|
-
|
|
86
76
|
}
|
|
87
|
-
|
|
88
77
|
exports.Bytes = Bytes;
|