@polkadot/types-codec 8.8.2 → 8.8.3-10
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/{AbstractArray.d.ts → Array.d.ts} +0 -0
- package/abstract/{AbstractArray.js → Array.js} +0 -0
- package/{base → abstract}/Base.d.ts +2 -2
- package/{base → abstract}/Base.js +2 -7
- package/abstract/{AbstractInt.d.ts → Int.d.ts} +1 -4
- package/abstract/{AbstractInt.js → Int.js} +19 -22
- package/abstract/index.d.ts +3 -2
- package/abstract/index.js +3 -2
- package/base/Compact.d.ts +0 -2
- package/base/Compact.js +16 -17
- package/base/Enum.js +6 -6
- package/base/Int.d.ts +1 -1
- package/base/Int.js +1 -1
- package/base/Null.d.ts +2 -8
- package/base/Null.js +2 -16
- package/base/Option.d.ts +1 -4
- package/base/Option.js +1 -10
- package/base/Tuple.d.ts +1 -1
- package/base/Tuple.js +3 -4
- package/base/UInt.d.ts +1 -1
- package/base/UInt.js +1 -1
- package/base/Vec.d.ts +1 -1
- package/base/Vec.js +2 -3
- package/base/VecAny.d.ts +1 -1
- package/base/VecAny.js +1 -1
- package/base/VecFixed.d.ts +1 -1
- package/base/VecFixed.js +2 -3
- package/base/index.d.ts +0 -1
- package/base/index.js +0 -1
- package/cjs/abstract/{AbstractArray.js → Array.js} +0 -0
- package/cjs/{base → abstract}/Base.js +4 -9
- package/cjs/abstract/{AbstractInt.js → Int.js} +18 -21
- package/cjs/abstract/index.js +12 -4
- package/cjs/base/Compact.js +15 -16
- package/cjs/base/Enum.js +5 -5
- package/cjs/base/Int.js +2 -2
- package/cjs/base/Null.js +2 -16
- package/cjs/base/Option.js +1 -10
- package/cjs/base/Tuple.js +4 -5
- package/cjs/base/UInt.js +2 -2
- package/cjs/base/Vec.js +3 -4
- package/cjs/base/VecAny.js +2 -2
- package/cjs/base/VecFixed.js +3 -4
- package/cjs/base/index.js +0 -8
- package/cjs/extended/Bytes.js +1 -1
- package/cjs/extended/Map.js +2 -2
- package/cjs/extended/OptionBool.js +1 -8
- package/cjs/native/Struct.js +2 -7
- package/cjs/native/Text.js +1 -10
- package/cjs/packageInfo.js +1 -1
- package/cjs/utils/decodeU8a.js +63 -20
- package/cjs/utils/index.js +6 -0
- package/cjs/utils/mapToTypeMap.js +1 -1
- package/cjs/utils/sanitize.js +17 -37
- package/extended/Bytes.js +2 -2
- package/extended/Map.js +1 -1
- package/extended/OptionBool.d.ts +0 -4
- package/extended/OptionBool.js +1 -8
- package/native/Raw.d.ts +1 -1
- package/native/Struct.d.ts +1 -1
- package/native/Struct.js +3 -8
- package/native/Text.d.ts +2 -5
- package/native/Text.js +1 -10
- package/package.json +15 -15
- package/packageInfo.js +1 -1
- package/utils/decodeU8a.d.ts +16 -1
- package/utils/decodeU8a.js +57 -19
- package/utils/index.d.ts +1 -1
- package/utils/index.js +1 -1
- package/utils/mapToTypeMap.js +1 -1
- package/utils/sanitize.d.ts +3 -5
- package/utils/sanitize.js +17 -37
|
@@ -24,17 +24,21 @@ function toPercentage(value, divisor) {
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
function decodeAbstractInt(value, isNegative) {
|
|
27
|
-
if ((0, _util.
|
|
28
|
-
return value.toString();
|
|
29
|
-
} else if ((0, _util.isHex)(value, -1, true)) {
|
|
30
|
-
return (0, _util.hexToBn)(value, {
|
|
31
|
-
isLe: false,
|
|
32
|
-
isNegative
|
|
33
|
-
}).toString();
|
|
34
|
-
} else if ((0, _util.isNumber)(value)) {
|
|
27
|
+
if ((0, _util.isNumber)(value)) {
|
|
35
28
|
(0, _util.assert)(value <= Number.MAX_SAFE_INTEGER && value >= Number.MIN_SAFE_INTEGER && Number.isInteger(value), 'Number needs to be an integer <= Number.MAX_SAFE_INTEGER, i.e. 2 ^ 53 - 1');
|
|
29
|
+
return value;
|
|
36
30
|
} else if ((0, _util.isString)(value)) {
|
|
31
|
+
if ((0, _util.isHex)(value, -1, true)) {
|
|
32
|
+
return (0, _util.hexToBn)(value, {
|
|
33
|
+
isLe: false,
|
|
34
|
+
isNegative
|
|
35
|
+
}).toString();
|
|
36
|
+
}
|
|
37
|
+
|
|
37
38
|
(0, _util.assert)(!(value.includes('.') || value.includes(',') || value.includes('e')), 'String should not contain decimal points or scientific notation');
|
|
39
|
+
return value;
|
|
40
|
+
} else if ((0, _util.isBn)(value)) {
|
|
41
|
+
return value.toString();
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
return (0, _util.bnToBn)(value).toString();
|
|
@@ -48,24 +52,25 @@ function decodeAbstractInt(value, isNegative) {
|
|
|
48
52
|
|
|
49
53
|
class AbstractInt extends _util.BN {
|
|
50
54
|
#bitLength;
|
|
51
|
-
#isSigned;
|
|
52
55
|
|
|
53
56
|
constructor(registry) {
|
|
54
57
|
let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
55
58
|
let bitLength = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_UINT_BITS;
|
|
56
59
|
let isSigned = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
57
|
-
// Construct via a string, which will be passed in the BN constructor.
|
|
60
|
+
// Construct via a string/number, which will be passed in the BN constructor.
|
|
58
61
|
// It would be ideal to actually return a BN, but there is an issue:
|
|
59
62
|
// https://github.com/indutny/bn.js/issues/206
|
|
60
63
|
super( // shortcut isU8a as used in SCALE decoding
|
|
61
|
-
(0, _util.isU8a)(value) ? (0, _util.
|
|
64
|
+
(0, _util.isU8a)(value) ? bitLength <= 48 ? (0, _util.u8aToNumber)(value.subarray(0, bitLength / 8), {
|
|
65
|
+
isNegative: isSigned
|
|
66
|
+
}) : (0, _util.u8aToBn)(value.subarray(0, bitLength / 8), {
|
|
62
67
|
isLe: true,
|
|
63
68
|
isNegative: isSigned
|
|
64
69
|
}).toString() : decodeAbstractInt(value, isSigned));
|
|
65
70
|
this.registry = registry;
|
|
66
71
|
this.#bitLength = bitLength;
|
|
67
72
|
this.encodedLength = this.#bitLength / 8;
|
|
68
|
-
this
|
|
73
|
+
this.isUnsigned = !isSigned;
|
|
69
74
|
const isPositive = this.gte(_util.BN_ZERO);
|
|
70
75
|
const maxBits = bitLength - (isSigned && isPositive ? 1 : 0);
|
|
71
76
|
(0, _util.assert)(isSigned || isPositive, () => `${this.toRawType()}: Negative number passed to unsigned type`);
|
|
@@ -87,14 +92,6 @@ class AbstractInt extends _util.BN {
|
|
|
87
92
|
get isEmpty() {
|
|
88
93
|
return this.isZero();
|
|
89
94
|
}
|
|
90
|
-
/**
|
|
91
|
-
* @description Checks if the value is an unsigned type
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
get isUnsigned() {
|
|
96
|
-
return !this.#isSigned;
|
|
97
|
-
}
|
|
98
95
|
/**
|
|
99
96
|
* @description Returns the number of bits in the value
|
|
100
97
|
*/
|
|
@@ -114,7 +111,7 @@ class AbstractInt extends _util.BN {
|
|
|
114
111
|
// number and BN inputs (no `.eqn` needed) - numbers will be converted
|
|
115
112
|
return super.eq((0, _util.isHex)(other) ? (0, _util.hexToBn)(other.toString(), {
|
|
116
113
|
isLe: false,
|
|
117
|
-
isNegative: this
|
|
114
|
+
isNegative: !this.isUnsigned
|
|
118
115
|
}) : (0, _util.bnToBn)(other));
|
|
119
116
|
}
|
|
120
117
|
/**
|
package/cjs/abstract/index.js
CHANGED
|
@@ -6,16 +6,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
Object.defineProperty(exports, "AbstractArray", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return
|
|
9
|
+
return _Array.AbstractArray;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "AbstractBase", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _Base.AbstractBase;
|
|
10
16
|
}
|
|
11
17
|
});
|
|
12
18
|
Object.defineProperty(exports, "AbstractInt", {
|
|
13
19
|
enumerable: true,
|
|
14
20
|
get: function () {
|
|
15
|
-
return
|
|
21
|
+
return _Int.AbstractInt;
|
|
16
22
|
}
|
|
17
23
|
});
|
|
18
24
|
|
|
19
|
-
var
|
|
25
|
+
var _Array = require("./Array");
|
|
26
|
+
|
|
27
|
+
var _Base = require("./Base");
|
|
20
28
|
|
|
21
|
-
var
|
|
29
|
+
var _Int = require("./Int");
|
package/cjs/base/Compact.js
CHANGED
|
@@ -14,6 +14,20 @@ var _utils = require("../utils");
|
|
|
14
14
|
function noopSetDefinition(d) {
|
|
15
15
|
return d;
|
|
16
16
|
}
|
|
17
|
+
|
|
18
|
+
function decodeCompact(registry, Type, value) {
|
|
19
|
+
if ((0, _util.isU8a)(value)) {
|
|
20
|
+
const [decodedLength, bn] = (value[0] & 0b11) < 0b11 ? (0, _util.compactFromU8aLim)(value) : (0, _util.compactFromU8a)(value);
|
|
21
|
+
return [new Type(registry, bn), decodedLength];
|
|
22
|
+
} else if (value instanceof Compact) {
|
|
23
|
+
const raw = value.unwrap();
|
|
24
|
+
return raw instanceof Type ? [raw, 0] : [new Type(registry, raw), 0];
|
|
25
|
+
} else if (value instanceof Type) {
|
|
26
|
+
return [value, 0];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return [new Type(registry, value), 0];
|
|
30
|
+
}
|
|
17
31
|
/**
|
|
18
32
|
* @name Compact
|
|
19
33
|
* @description
|
|
@@ -36,7 +50,7 @@ class Compact {
|
|
|
36
50
|
} = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
37
51
|
this.registry = registry;
|
|
38
52
|
this.#Type = definition || setDefinition((0, _utils.typeToConstructor)(registry, Type));
|
|
39
|
-
const [raw, decodedLength] =
|
|
53
|
+
const [raw, decodedLength] = decodeCompact(registry, this.#Type, value);
|
|
40
54
|
this.initialU8aLength = decodedLength;
|
|
41
55
|
this.#raw = raw;
|
|
42
56
|
}
|
|
@@ -56,21 +70,6 @@ class Compact {
|
|
|
56
70
|
|
|
57
71
|
};
|
|
58
72
|
}
|
|
59
|
-
/** @internal */
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
static decodeCompact(registry, Type, value) {
|
|
63
|
-
if ((0, _util.isU8a)(value)) {
|
|
64
|
-
const [decodedLength, bn] = (0, _util.compactFromU8a)(value);
|
|
65
|
-
return [new Type(registry, bn), decodedLength];
|
|
66
|
-
} else if (value instanceof Compact) {
|
|
67
|
-
return [new Type(registry, value.#raw), 0];
|
|
68
|
-
} else if (value instanceof Type) {
|
|
69
|
-
return [value, 0];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return [new Type(registry, value), 0];
|
|
73
|
-
}
|
|
74
73
|
/**
|
|
75
74
|
* @description The length of the value when encoded as a Uint8Array
|
|
76
75
|
*/
|
package/cjs/base/Enum.js
CHANGED
|
@@ -89,7 +89,7 @@ function createFromValue(registry, def) {
|
|
|
89
89
|
(0, _util.assert)(!(0, _util.isUndefined)(entry), () => `Unable to create Enum via index ${index}, in ${Object.keys(def).join(', ')}`);
|
|
90
90
|
return {
|
|
91
91
|
index,
|
|
92
|
-
value:
|
|
92
|
+
value: value instanceof entry.Type ? value : new entry.Type(registry, value)
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
95
|
|
|
@@ -171,7 +171,7 @@ class Enum {
|
|
|
171
171
|
} = _ref2;
|
|
172
172
|
return index;
|
|
173
173
|
});
|
|
174
|
-
this.#entryIndex = this.#indexes.indexOf(decoded.index)
|
|
174
|
+
this.#entryIndex = this.#indexes.indexOf(decoded.index);
|
|
175
175
|
this.#raw = decoded.value;
|
|
176
176
|
|
|
177
177
|
if (this.#raw.initialU8aLength) {
|
|
@@ -185,7 +185,7 @@ class Enum {
|
|
|
185
185
|
const isKeys = new Array(keys.length);
|
|
186
186
|
|
|
187
187
|
for (let i = 0; i < keys.length; i++) {
|
|
188
|
-
const name = (0, _util.stringPascalCase)(keys[i]
|
|
188
|
+
const name = (0, _util.stringPascalCase)(keys[i]);
|
|
189
189
|
asKeys[i] = `as${name}`;
|
|
190
190
|
isKeys[i] = `is${name}`;
|
|
191
191
|
}
|
|
@@ -321,7 +321,7 @@ class Enum {
|
|
|
321
321
|
return this.type === other;
|
|
322
322
|
} else if ((0, _util.isHex)(other)) {
|
|
323
323
|
return this.toHex() === other;
|
|
324
|
-
} else if (
|
|
324
|
+
} else if (other instanceof Enum) {
|
|
325
325
|
return this.index === other.index && this.value.eq(other.value);
|
|
326
326
|
} else if ((0, _util.isObject)(other)) {
|
|
327
327
|
return this.value.eq(other[this.type]);
|
|
@@ -336,7 +336,7 @@ class Enum {
|
|
|
336
336
|
|
|
337
337
|
|
|
338
338
|
inspect() {
|
|
339
|
-
if (this
|
|
339
|
+
if (this.#isBasic) {
|
|
340
340
|
return {
|
|
341
341
|
outer: [new Uint8Array([this.index])]
|
|
342
342
|
};
|
package/cjs/base/Int.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.Int = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _Int = require("../abstract/Int");
|
|
9
9
|
|
|
10
10
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
11
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -20,7 +20,7 @@ var _AbstractInt = require("../abstract/AbstractInt");
|
|
|
20
20
|
* is available here.
|
|
21
21
|
* @noInheritDoc
|
|
22
22
|
*/
|
|
23
|
-
class Int extends
|
|
23
|
+
class Int extends _Int.AbstractInt {
|
|
24
24
|
constructor(registry) {
|
|
25
25
|
let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
26
26
|
let bitLength = arguments.length > 2 ? arguments[2] : undefined;
|
package/cjs/base/Null.js
CHANGED
|
@@ -16,20 +16,14 @@ var _util = require("@polkadot/util");
|
|
|
16
16
|
* Implements a type that does not contain anything (apart from `null`)
|
|
17
17
|
*/
|
|
18
18
|
class Null {
|
|
19
|
+
encodedLength = 0;
|
|
20
|
+
isEmpty = true;
|
|
19
21
|
// Added for compatibility reasons, e.g. see Option
|
|
20
22
|
initialU8aLength = 0;
|
|
21
23
|
|
|
22
24
|
constructor(registry) {
|
|
23
25
|
this.registry = registry;
|
|
24
26
|
}
|
|
25
|
-
/**
|
|
26
|
-
* @description The length of the value when encoded as a Uint8Array
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
get encodedLength() {
|
|
31
|
-
return 0;
|
|
32
|
-
}
|
|
33
27
|
/**
|
|
34
28
|
* @description returns a hash of the contents
|
|
35
29
|
*/
|
|
@@ -38,14 +32,6 @@ class Null {
|
|
|
38
32
|
get hash() {
|
|
39
33
|
throw new Error('.hash is not implemented on Null');
|
|
40
34
|
}
|
|
41
|
-
/**
|
|
42
|
-
* @description Checks if the value is an empty value (always true)
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
get isEmpty() {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
35
|
/**
|
|
50
36
|
* @description Compares the value of the input to see if there is a match
|
|
51
37
|
*/
|
package/cjs/base/Option.js
CHANGED
|
@@ -67,7 +67,6 @@ function decodeOption(registry, Type, value) {
|
|
|
67
67
|
|
|
68
68
|
class Option {
|
|
69
69
|
#Type;
|
|
70
|
-
#initialU8aLength;
|
|
71
70
|
#raw;
|
|
72
71
|
|
|
73
72
|
constructor(registry, typeName, value) {
|
|
@@ -82,7 +81,7 @@ class Option {
|
|
|
82
81
|
this.#raw = decoded;
|
|
83
82
|
|
|
84
83
|
if (decoded && decoded.initialU8aLength) {
|
|
85
|
-
this
|
|
84
|
+
this.initialU8aLength = 1 + decoded.initialU8aLength;
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
87
|
|
|
@@ -113,14 +112,6 @@ class Option {
|
|
|
113
112
|
// boolean byte (has value, doesn't have) along with wrapped length
|
|
114
113
|
return 1 + this.#raw.encodedLength;
|
|
115
114
|
}
|
|
116
|
-
/**
|
|
117
|
-
* @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
|
|
118
|
-
*/
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
get initialU8aLength() {
|
|
122
|
-
return this.#initialU8aLength;
|
|
123
|
-
}
|
|
124
115
|
/**
|
|
125
116
|
* @description returns a hash of the contents
|
|
126
117
|
*/
|
package/cjs/base/Tuple.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.Tuple = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _util = require("@polkadot/util");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _Array = require("../abstract/Array");
|
|
11
11
|
|
|
12
12
|
var _utils = require("../utils");
|
|
13
13
|
|
|
@@ -19,7 +19,7 @@ function noopSetDefinition(d) {
|
|
|
19
19
|
/** @internal */
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
function decodeTuple(registry, result,
|
|
22
|
+
function decodeTuple(registry, result, value, Classes) {
|
|
23
23
|
if ((0, _util.isU8a)(value) || (0, _util.isHex)(value)) {
|
|
24
24
|
return (0, _utils.decodeU8a)(registry, result, (0, _util.u8aToU8a)(value), Classes);
|
|
25
25
|
}
|
|
@@ -45,7 +45,7 @@ function decodeTuple(registry, result, Classes, value) {
|
|
|
45
45
|
*/
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
class Tuple extends
|
|
48
|
+
class Tuple extends _Array.AbstractArray {
|
|
49
49
|
#Types;
|
|
50
50
|
|
|
51
51
|
constructor(registry, Types, value) {
|
|
@@ -55,8 +55,7 @@ class Tuple extends _AbstractArray.AbstractArray {
|
|
|
55
55
|
} = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
56
56
|
const Classes = definition || setDefinition(Array.isArray(Types) ? [Types.map(t => (0, _utils.typeToConstructor)(registry, t)), []] : (0, _util.isFunction)(Types) || (0, _util.isString)(Types) ? [[(0, _utils.typeToConstructor)(registry, Types)], []] : (0, _utils.mapToTypeMap)(registry, Types));
|
|
57
57
|
super(registry, Classes[0].length);
|
|
58
|
-
|
|
59
|
-
this.initialU8aLength = decodedLength;
|
|
58
|
+
this.initialU8aLength = ((0, _util.isU8a)(value) ? (0, _utils.decodeU8a)(registry, this, value, Classes) : decodeTuple(registry, this, value, Classes))[1];
|
|
60
59
|
this.#Types = Classes;
|
|
61
60
|
}
|
|
62
61
|
|
package/cjs/base/UInt.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.UInt = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _Int = require("../abstract/Int");
|
|
9
9
|
|
|
10
10
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
11
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -20,7 +20,7 @@ var _AbstractInt = require("../abstract/AbstractInt");
|
|
|
20
20
|
* is available here.
|
|
21
21
|
* @noInheritDoc
|
|
22
22
|
*/
|
|
23
|
-
class UInt extends
|
|
23
|
+
class UInt extends _Int.AbstractInt {
|
|
24
24
|
static with(bitLength, typeName) {
|
|
25
25
|
return class extends UInt {
|
|
26
26
|
constructor(registry, value) {
|
package/cjs/base/Vec.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.decodeVec = decodeVec;
|
|
|
8
8
|
|
|
9
9
|
var _util = require("@polkadot/util");
|
|
10
10
|
|
|
11
|
-
var
|
|
11
|
+
var _Array = require("../abstract/Array");
|
|
12
12
|
|
|
13
13
|
var _utils = require("../utils");
|
|
14
14
|
|
|
@@ -61,7 +61,7 @@ function decodeVec(registry, result, value, startAt, Type) {
|
|
|
61
61
|
*/
|
|
62
62
|
|
|
63
63
|
|
|
64
|
-
class Vec extends
|
|
64
|
+
class Vec extends _Array.AbstractArray {
|
|
65
65
|
#Type;
|
|
66
66
|
|
|
67
67
|
constructor(registry, Type) {
|
|
@@ -73,8 +73,7 @@ class Vec extends _AbstractArray.AbstractArray {
|
|
|
73
73
|
const [decodeFrom, length, startAt] = decodeVecLength(value);
|
|
74
74
|
super(registry, length);
|
|
75
75
|
this.#Type = definition || setDefinition((0, _utils.typeToConstructor)(registry, Type));
|
|
76
|
-
|
|
77
|
-
this.initialU8aLength = decodedLength;
|
|
76
|
+
this.initialU8aLength = ((0, _util.isU8a)(decodeFrom) ? (0, _utils.decodeU8aVec)(registry, this, decodeFrom, startAt, this.#Type) : decodeVec(registry, this, decodeFrom, startAt, this.#Type))[0];
|
|
78
77
|
}
|
|
79
78
|
|
|
80
79
|
static with(Type) {
|
package/cjs/base/VecAny.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.VecAny = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _Array = require("../abstract/Array");
|
|
9
9
|
|
|
10
10
|
// Copyright 2017-2022 @polkadot/types-codec authors & contributors
|
|
11
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -17,7 +17,7 @@ var _AbstractArray = require("../abstract/AbstractArray");
|
|
|
17
17
|
* a vector, this can be used to manage array-like structures with variable arguments of
|
|
18
18
|
* any types
|
|
19
19
|
*/
|
|
20
|
-
class VecAny extends
|
|
20
|
+
class VecAny extends _Array.AbstractArray {
|
|
21
21
|
/**
|
|
22
22
|
* @description Returns the base runtime type name for this instance
|
|
23
23
|
*/
|
package/cjs/base/VecFixed.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.VecFixed = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _util = require("@polkadot/util");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _Array = require("../abstract/Array");
|
|
11
11
|
|
|
12
12
|
var _utils = require("../utils");
|
|
13
13
|
|
|
@@ -25,7 +25,7 @@ function noopSetDefinition(d) {
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
class VecFixed extends
|
|
28
|
+
class VecFixed extends _Array.AbstractArray {
|
|
29
29
|
#Type;
|
|
30
30
|
|
|
31
31
|
constructor(registry, Type, length) {
|
|
@@ -36,8 +36,7 @@ class VecFixed extends _AbstractArray.AbstractArray {
|
|
|
36
36
|
} = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
37
37
|
super(registry, length);
|
|
38
38
|
this.#Type = definition || setDefinition((0, _utils.typeToConstructor)(registry, Type));
|
|
39
|
-
|
|
40
|
-
this.initialU8aLength = decodedLengthNoOffset;
|
|
39
|
+
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];
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
static with(Type, length) {
|
package/cjs/base/index.js
CHANGED
|
@@ -3,12 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "Base", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _Base.Base;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
6
|
Object.defineProperty(exports, "Compact", {
|
|
13
7
|
enumerable: true,
|
|
14
8
|
get: function () {
|
|
@@ -82,8 +76,6 @@ Object.defineProperty(exports, "VecFixed", {
|
|
|
82
76
|
}
|
|
83
77
|
});
|
|
84
78
|
|
|
85
|
-
var _Base = require("./Base");
|
|
86
|
-
|
|
87
79
|
var _Compact = require("./Compact");
|
|
88
80
|
|
|
89
81
|
var _DoNotConstruct = require("./DoNotConstruct");
|
package/cjs/extended/Bytes.js
CHANGED
|
@@ -38,7 +38,7 @@ function decodeBytesU8a(value) {
|
|
|
38
38
|
|
|
39
39
|
class Bytes extends _Raw.Raw {
|
|
40
40
|
constructor(registry, value) {
|
|
41
|
-
const [u8a, decodedLength] = (0, _util.isU8a)(value) && !(
|
|
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];
|
|
42
42
|
super(registry, u8a, decodedLength);
|
|
43
43
|
}
|
|
44
44
|
/**
|
package/cjs/extended/Map.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.CodecMap = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _util = require("@polkadot/util");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _Array = require("../abstract/Array");
|
|
11
11
|
|
|
12
12
|
var _Enum = require("../base/Enum");
|
|
13
13
|
|
|
@@ -44,7 +44,7 @@ function decodeMapFromMap(registry, KeyClass, ValClass, value) {
|
|
|
44
44
|
const output = new Map();
|
|
45
45
|
|
|
46
46
|
for (const [key, val] of value.entries()) {
|
|
47
|
-
const isComplex = KeyClass.prototype instanceof
|
|
47
|
+
const isComplex = KeyClass.prototype instanceof _Array.AbstractArray || KeyClass.prototype instanceof _Struct.Struct || KeyClass.prototype instanceof _Enum.Enum;
|
|
48
48
|
|
|
49
49
|
try {
|
|
50
50
|
output.set(key instanceof KeyClass ? key : new KeyClass(registry, isComplex ? JSON.parse(key) : key), val instanceof ValClass ? val : new ValClass(registry, val));
|
|
@@ -29,6 +29,7 @@ function decodeU8a(registry, value) {
|
|
|
29
29
|
class OptionBool extends _Option.Option {
|
|
30
30
|
constructor(registry, value) {
|
|
31
31
|
super(registry, _Bool.bool, (0, _util.isU8a)(value) || (0, _util.isHex)(value) ? decodeU8a(registry, (0, _util.u8aToU8a)(value)) : value);
|
|
32
|
+
this.initialU8aLength = 1;
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
35
|
* @description The length of the value when encoded as a Uint8Array
|
|
@@ -38,14 +39,6 @@ class OptionBool extends _Option.Option {
|
|
|
38
39
|
get encodedLength() {
|
|
39
40
|
return 1;
|
|
40
41
|
}
|
|
41
|
-
/**
|
|
42
|
-
* @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
get initialU8aLength() {
|
|
47
|
-
return 1;
|
|
48
|
-
}
|
|
49
42
|
/**
|
|
50
43
|
* @description Checks if the value is an empty value (always false)
|
|
51
44
|
*/
|
package/cjs/native/Struct.js
CHANGED
|
@@ -82,7 +82,6 @@ function decodeStructFromObject(registry, _ref, value, jsonMap) {
|
|
|
82
82
|
|
|
83
83
|
|
|
84
84
|
class Struct extends Map {
|
|
85
|
-
#registry;
|
|
86
85
|
#jsonMap;
|
|
87
86
|
#Types;
|
|
88
87
|
|
|
@@ -93,10 +92,10 @@ class Struct extends Map {
|
|
|
93
92
|
setDefinition = noopSetDefinition
|
|
94
93
|
} = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
95
94
|
const typeMap = definition || setDefinition((0, _utils.mapToTypeMap)(registry, Types));
|
|
96
|
-
const [decoded, decodedLength] = (0, _util.isU8a)(value) || (0, _util.isHex)(value) ? (0, _utils.
|
|
95
|
+
const [decoded, decodedLength] = (0, _util.isU8a)(value) || (0, _util.isHex)(value) ? (0, _utils.decodeU8aStruct)(registry, new Array(typeMap[0].length), (0, _util.u8aToU8a)(value), typeMap) : value instanceof Struct ? [value, 0] : decodeStructFromObject(registry, typeMap, value || {}, jsonMap);
|
|
97
96
|
super(decoded);
|
|
98
|
-
this.#registry = registry;
|
|
99
97
|
this.initialU8aLength = decodedLength;
|
|
98
|
+
this.registry = registry;
|
|
100
99
|
this.#jsonMap = jsonMap;
|
|
101
100
|
this.#Types = typeMap;
|
|
102
101
|
}
|
|
@@ -181,10 +180,6 @@ class Struct extends Map {
|
|
|
181
180
|
get hash() {
|
|
182
181
|
return this.registry.hash(this.toU8a());
|
|
183
182
|
}
|
|
184
|
-
|
|
185
|
-
get registry() {
|
|
186
|
-
return this.#registry;
|
|
187
|
-
}
|
|
188
183
|
/**
|
|
189
184
|
* @description Compares the value of the input to see if there is a match
|
|
190
185
|
*/
|
package/cjs/native/Text.js
CHANGED
|
@@ -48,14 +48,13 @@ function decodeText(value) {
|
|
|
48
48
|
|
|
49
49
|
|
|
50
50
|
class Text extends String {
|
|
51
|
-
#initialU8aLength;
|
|
52
51
|
#override = null;
|
|
53
52
|
|
|
54
53
|
constructor(registry, value) {
|
|
55
54
|
const [str, decodedLength] = decodeText(value);
|
|
56
55
|
super(str);
|
|
57
56
|
this.registry = registry;
|
|
58
|
-
this
|
|
57
|
+
this.initialU8aLength = decodedLength;
|
|
59
58
|
}
|
|
60
59
|
/**
|
|
61
60
|
* @description The length of the value when encoded as a Uint8Array
|
|
@@ -65,14 +64,6 @@ class Text extends String {
|
|
|
65
64
|
get encodedLength() {
|
|
66
65
|
return this.toU8a().length;
|
|
67
66
|
}
|
|
68
|
-
/**
|
|
69
|
-
* @description The length of the initial encoded value (Only available when constructed from a Uint8Array)
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
get initialU8aLength() {
|
|
74
|
-
return this.#initialU8aLength;
|
|
75
|
-
}
|
|
76
67
|
/**
|
|
77
68
|
* @description returns a hash of the contents
|
|
78
69
|
*/
|