@polkadot/types-codec 10.4.1 → 10.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 +21 -14
- package/abstract/Base.js +13 -17
- package/abstract/Int.js +8 -12
- package/base/Compact.js +20 -28
- package/base/DoNotConstruct.js +14 -18
- package/base/Enum.js +42 -53
- package/base/Option.js +17 -25
- package/base/Tuple.js +12 -19
- package/base/Vec.js +10 -17
- package/base/VecFixed.js +7 -14
- package/cjs/abstract/Array.js +21 -14
- package/cjs/abstract/Base.js +13 -17
- package/cjs/abstract/Int.js +8 -12
- package/cjs/base/Compact.js +19 -27
- package/cjs/base/DoNotConstruct.js +14 -18
- package/cjs/base/Enum.js +41 -52
- package/cjs/base/Option.js +16 -24
- package/cjs/base/Tuple.js +10 -17
- package/cjs/base/Vec.js +9 -16
- package/cjs/base/VecFixed.js +6 -13
- package/cjs/extended/BTreeSet.js +2 -6
- package/cjs/extended/BitVec.js +10 -14
- package/cjs/extended/Map.js +5 -11
- package/cjs/extended/Range.js +2 -6
- package/cjs/extended/WrapperKeepOpaque.js +16 -22
- package/cjs/native/Float.js +3 -7
- package/cjs/native/Set.js +15 -18
- package/cjs/native/Struct.js +12 -16
- package/cjs/native/Text.js +3 -6
- package/cjs/native/index.js +2 -2
- package/cjs/packageInfo.js +1 -1
- package/cjs/primitive/index.js +17 -17
- package/cjs/utils/index.js +6 -6
- package/cjs/utils/sanitize.js +16 -16
- package/cjs/utils/sortValues.js +2 -6
- package/cjs/utils/toConstructors.js +41 -0
- package/cjs/utils/typesToMap.js +1 -1
- package/extended/BTreeSet.js +2 -6
- package/extended/BitVec.js +10 -14
- package/extended/Map.js +5 -11
- package/extended/Range.js +2 -6
- package/extended/WrapperKeepOpaque.js +16 -22
- package/native/Float.js +3 -7
- package/native/Set.js +15 -18
- package/native/Struct.js +12 -16
- package/native/Text.js +3 -6
- package/native/index.d.ts +1 -1
- package/native/index.js +1 -1
- package/package.json +8 -13
- package/packageInfo.js +1 -1
- package/primitive/index.d.ts +16 -16
- package/primitive/index.js +16 -16
- package/types/registry.d.ts +1 -0
- package/utils/index.d.ts +2 -3
- package/utils/index.js +2 -3
- package/utils/sanitize.js +16 -16
- package/utils/sortValues.js +1 -5
- package/utils/toConstructors.d.ts +16 -0
- package/utils/toConstructors.js +35 -0
- package/utils/typesToMap.js +1 -1
- package/cjs/utils/mapToTypeMap.js +0 -18
- package/cjs/utils/typeToConstructor.js +0 -10
- package/utils/mapToTypeMap.d.ts +0 -5
- package/utils/mapToTypeMap.js +0 -14
- package/utils/typeToConstructor.d.ts +0 -2
- package/utils/typeToConstructor.js +0 -6
package/cjs/utils/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.typesToMap = exports.
|
|
3
|
+
exports.typesToMap = exports.typeToConstructor = exports.typesToConstructors = exports.mapToTypeMap = exports.sortSet = exports.sortMap = exports.sortAsc = exports.sanitize = exports.decodeU8aVec = exports.decodeU8aStruct = exports.decodeU8a = exports.compareSet = exports.compareMap = exports.compareArray = void 0;
|
|
4
4
|
var compareArray_js_1 = require("./compareArray.js");
|
|
5
5
|
Object.defineProperty(exports, "compareArray", { enumerable: true, get: function () { return compareArray_js_1.compareArray; } });
|
|
6
6
|
var compareMap_js_1 = require("./compareMap.js");
|
|
@@ -11,15 +11,15 @@ var decodeU8a_js_1 = require("./decodeU8a.js");
|
|
|
11
11
|
Object.defineProperty(exports, "decodeU8a", { enumerable: true, get: function () { return decodeU8a_js_1.decodeU8a; } });
|
|
12
12
|
Object.defineProperty(exports, "decodeU8aStruct", { enumerable: true, get: function () { return decodeU8a_js_1.decodeU8aStruct; } });
|
|
13
13
|
Object.defineProperty(exports, "decodeU8aVec", { enumerable: true, get: function () { return decodeU8a_js_1.decodeU8aVec; } });
|
|
14
|
-
var mapToTypeMap_js_1 = require("./mapToTypeMap.js");
|
|
15
|
-
Object.defineProperty(exports, "mapToTypeMap", { enumerable: true, get: function () { return mapToTypeMap_js_1.mapToTypeMap; } });
|
|
16
|
-
var typeToConstructor_js_1 = require("./typeToConstructor.js");
|
|
17
|
-
Object.defineProperty(exports, "typeToConstructor", { enumerable: true, get: function () { return typeToConstructor_js_1.typeToConstructor; } });
|
|
18
14
|
var sanitize_js_1 = require("./sanitize.js");
|
|
19
15
|
Object.defineProperty(exports, "sanitize", { enumerable: true, get: function () { return sanitize_js_1.sanitize; } });
|
|
20
16
|
var sortValues_js_1 = require("./sortValues.js");
|
|
21
17
|
Object.defineProperty(exports, "sortAsc", { enumerable: true, get: function () { return sortValues_js_1.sortAsc; } });
|
|
22
|
-
Object.defineProperty(exports, "sortSet", { enumerable: true, get: function () { return sortValues_js_1.sortSet; } });
|
|
23
18
|
Object.defineProperty(exports, "sortMap", { enumerable: true, get: function () { return sortValues_js_1.sortMap; } });
|
|
19
|
+
Object.defineProperty(exports, "sortSet", { enumerable: true, get: function () { return sortValues_js_1.sortSet; } });
|
|
20
|
+
var toConstructors_js_1 = require("./toConstructors.js");
|
|
21
|
+
Object.defineProperty(exports, "mapToTypeMap", { enumerable: true, get: function () { return toConstructors_js_1.mapToTypeMap; } });
|
|
22
|
+
Object.defineProperty(exports, "typesToConstructors", { enumerable: true, get: function () { return toConstructors_js_1.typesToConstructors; } });
|
|
23
|
+
Object.defineProperty(exports, "typeToConstructor", { enumerable: true, get: function () { return toConstructors_js_1.typeToConstructor; } });
|
|
24
24
|
var typesToMap_js_1 = require("./typesToMap.js");
|
|
25
25
|
Object.defineProperty(exports, "typesToMap", { enumerable: true, get: function () { return typesToMap_js_1.typesToMap; } });
|
package/cjs/utils/sanitize.js
CHANGED
|
@@ -48,14 +48,14 @@ function trim() {
|
|
|
48
48
|
exports.trim = trim;
|
|
49
49
|
function findClosing(value, start) {
|
|
50
50
|
let depth = 0;
|
|
51
|
-
for (let
|
|
52
|
-
if (value[
|
|
51
|
+
for (let i = start, count = value.length; i < count; i++) {
|
|
52
|
+
if (value[i] === '>') {
|
|
53
53
|
if (!depth) {
|
|
54
|
-
return
|
|
54
|
+
return i;
|
|
55
55
|
}
|
|
56
56
|
depth--;
|
|
57
57
|
}
|
|
58
|
-
else if (value[
|
|
58
|
+
else if (value[i] === '<') {
|
|
59
59
|
depth++;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -76,11 +76,11 @@ exports.alias = alias;
|
|
|
76
76
|
function cleanupCompact() {
|
|
77
77
|
return (value) => {
|
|
78
78
|
if (value.includes(' as HasCompact')) {
|
|
79
|
-
for (let
|
|
80
|
-
if (value[
|
|
81
|
-
const end = findClosing(value,
|
|
79
|
+
for (let i = 0, count = value.length; i < count; i++) {
|
|
80
|
+
if (value[i] === '<') {
|
|
81
|
+
const end = findClosing(value, i + 1) - 14;
|
|
82
82
|
if (value.substring(end, end + 14) === ' as HasCompact') {
|
|
83
|
-
value = `Compact<${value.substring(
|
|
83
|
+
value = `Compact<${value.substring(i + 1, end)}>`;
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -116,7 +116,7 @@ function replaceTagWith(value, matcher, replacer) {
|
|
|
116
116
|
}
|
|
117
117
|
function removeExtensions(type, isSized) {
|
|
118
118
|
return (value) => {
|
|
119
|
-
for (let i = 0
|
|
119
|
+
for (let i = 0, count = BOUNDED.length; i < count; i++) {
|
|
120
120
|
const tag = BOUNDED[i];
|
|
121
121
|
value = replaceTagWith(value, `${type}${tag}<`, (v) => {
|
|
122
122
|
const parts = v
|
|
@@ -155,21 +155,21 @@ function removeColons() {
|
|
|
155
155
|
exports.removeColons = removeColons;
|
|
156
156
|
function removeGenerics() {
|
|
157
157
|
return (value) => {
|
|
158
|
-
for (let
|
|
159
|
-
if (value[
|
|
158
|
+
for (let i = 0, count = value.length; i < count; i++) {
|
|
159
|
+
if (value[i] === '<') {
|
|
160
160
|
// check against the allowed wrappers, be it Vec<..>, Option<...> ...
|
|
161
161
|
const box = ALLOWED_BOXES.find((box) => {
|
|
162
|
-
const start =
|
|
162
|
+
const start = i - box.length;
|
|
163
163
|
return ((start >= 0 &&
|
|
164
|
-
value.substring(start,
|
|
164
|
+
value.substring(start, i) === box) && (
|
|
165
165
|
// make sure it is stand-alone, i.e. don't catch ElectionResult<...> as Result<...>
|
|
166
166
|
start === 0 ||
|
|
167
167
|
BOX_PRECEDING.includes(value[start - 1])));
|
|
168
168
|
});
|
|
169
169
|
// we have not found anything, unwrap generic innards
|
|
170
170
|
if (!box) {
|
|
171
|
-
const end = findClosing(value,
|
|
172
|
-
value = `${value.substring(0,
|
|
171
|
+
const end = findClosing(value, i + 1);
|
|
172
|
+
value = `${value.substring(0, i)}${value.substring(end + 1)}`;
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
}
|
|
@@ -225,7 +225,7 @@ function sanitize(value) {
|
|
|
225
225
|
return memoized;
|
|
226
226
|
}
|
|
227
227
|
let result = startValue;
|
|
228
|
-
for (let i = 0
|
|
228
|
+
for (let i = 0, count = mappings.length; i < count; i++) {
|
|
229
229
|
result = mappings[i](result);
|
|
230
230
|
}
|
|
231
231
|
sanitizeMap.set(startValue, result);
|
package/cjs/utils/sortValues.js
CHANGED
|
@@ -7,12 +7,8 @@ function isArrayLike(arg) {
|
|
|
7
7
|
return arg instanceof Uint8Array || Array.isArray(arg);
|
|
8
8
|
}
|
|
9
9
|
/** @internal **/
|
|
10
|
-
function isCodec(arg) {
|
|
11
|
-
return (0, util_1.isFunction)(arg && arg.toU8a);
|
|
12
|
-
}
|
|
13
|
-
/** @internal **/
|
|
14
10
|
function isEnum(arg) {
|
|
15
|
-
return isCodec(arg) && (0, util_1.isNumber)(arg.index) && isCodec(arg.value);
|
|
11
|
+
return (0, util_1.isCodec)(arg) && (0, util_1.isNumber)(arg.index) && (0, util_1.isCodec)(arg.value);
|
|
16
12
|
}
|
|
17
13
|
/** @internal */
|
|
18
14
|
function isNumberLike(arg) {
|
|
@@ -49,7 +45,7 @@ function sortAsc(a, b) {
|
|
|
49
45
|
else if (isArrayLike(a) && isArrayLike(b)) {
|
|
50
46
|
return sortArray(a, b);
|
|
51
47
|
}
|
|
52
|
-
else if (isCodec(a) && isCodec(b)) {
|
|
48
|
+
else if ((0, util_1.isCodec)(a) && (0, util_1.isCodec)(b)) {
|
|
53
49
|
// Text, Bool etc.
|
|
54
50
|
return sortAsc(a.toU8a(true), b.toU8a(true));
|
|
55
51
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapToTypeMap = exports.typesToConstructors = exports.typeToConstructor = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
* From a type string or class, return the associated type class
|
|
7
|
+
*/
|
|
8
|
+
function typeToConstructor(registry, type) {
|
|
9
|
+
return typeof type === 'function'
|
|
10
|
+
? type
|
|
11
|
+
: registry.createClassUnsafe(type);
|
|
12
|
+
}
|
|
13
|
+
exports.typeToConstructor = typeToConstructor;
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
* Takes an input array of types and returns the associated classes for it
|
|
17
|
+
*/
|
|
18
|
+
function typesToConstructors(registry, types) {
|
|
19
|
+
const count = types.length;
|
|
20
|
+
const result = new Array(count);
|
|
21
|
+
for (let i = 0; i < count; i++) {
|
|
22
|
+
result[i] = typeToConstructor(registry, types[i]);
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
exports.typesToConstructors = typesToConstructors;
|
|
27
|
+
/**
|
|
28
|
+
* @internal
|
|
29
|
+
* Takes an input map of the form `{ [string]: string | CodecClass }` and returns a map of `{ [string]: CodecClass }`
|
|
30
|
+
*/
|
|
31
|
+
function mapToTypeMap(registry, input) {
|
|
32
|
+
const entries = Object.entries(input);
|
|
33
|
+
const count = entries.length;
|
|
34
|
+
const output = [new Array(count), new Array(count)];
|
|
35
|
+
for (let i = 0; i < count; i++) {
|
|
36
|
+
output[1][i] = entries[i][0];
|
|
37
|
+
output[0][i] = typeToConstructor(registry, entries[i][1]);
|
|
38
|
+
}
|
|
39
|
+
return output;
|
|
40
|
+
}
|
|
41
|
+
exports.mapToTypeMap = mapToTypeMap;
|
package/cjs/utils/typesToMap.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.typesToMap = void 0;
|
|
4
4
|
function typesToMap(registry, [Types, keys]) {
|
|
5
5
|
const result = {};
|
|
6
|
-
for (let i = 0
|
|
6
|
+
for (let i = 0, count = keys.length; i < count; i++) {
|
|
7
7
|
result[keys[i]] = registry.getClassName(Types[i]) || new Types[i](registry).toRawType();
|
|
8
8
|
}
|
|
9
9
|
return result;
|
package/extended/BTreeSet.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var _BTreeSet_ValClass;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
1
|
import { compactFromU8aLim, compactToU8a, isHex, isU8a, logger, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
|
|
4
2
|
import { compareSet, decodeU8aVec, sortSet, typeToConstructor } from '../utils/index.js';
|
|
5
3
|
const l = logger('BTreeSet');
|
|
@@ -59,10 +57,9 @@ export class BTreeSet extends Set {
|
|
|
59
57
|
constructor(registry, valType, rawValue) {
|
|
60
58
|
const [ValClass, values, decodedLength] = decodeSet(registry, valType, rawValue);
|
|
61
59
|
super(sortSet(values));
|
|
62
|
-
_BTreeSet_ValClass.set(this, void 0);
|
|
63
60
|
this.registry = registry;
|
|
64
61
|
this.initialU8aLength = decodedLength;
|
|
65
|
-
|
|
62
|
+
this.__internal__ValClass = ValClass;
|
|
66
63
|
}
|
|
67
64
|
static with(valType) {
|
|
68
65
|
return class extends BTreeSet {
|
|
@@ -148,7 +145,7 @@ export class BTreeSet extends Set {
|
|
|
148
145
|
* @description Returns the base runtime type name for this instance
|
|
149
146
|
*/
|
|
150
147
|
toRawType() {
|
|
151
|
-
return `BTreeSet<${this.registry.getClassName(
|
|
148
|
+
return `BTreeSet<${this.registry.getClassName(this.__internal__ValClass) || new this.__internal__ValClass(this.registry).toRawType()}>`;
|
|
152
149
|
}
|
|
153
150
|
/**
|
|
154
151
|
* @description Converts the value in a best-fit primitive form
|
|
@@ -181,4 +178,3 @@ export class BTreeSet extends Set {
|
|
|
181
178
|
return u8aConcatStrict(encoded);
|
|
182
179
|
}
|
|
183
180
|
}
|
|
184
|
-
_BTreeSet_ValClass = new WeakMap();
|
package/extended/BitVec.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var _BitVec_decodedLength, _BitVec_isMsb;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
1
|
import { compactFromU8aLim, compactToU8a, isString, u8aConcatStrict, u8aToU8a } from '@polkadot/util';
|
|
4
2
|
import { Raw } from '../native/Raw.js';
|
|
5
3
|
/** @internal */
|
|
@@ -36,23 +34,21 @@ export class BitVec extends Raw {
|
|
|
36
34
|
constructor(registry, value, isMsb = false) {
|
|
37
35
|
const [decodedLength, u8a] = decodeBitVec(value);
|
|
38
36
|
super(registry, u8a);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
__classPrivateFieldSet(this, _BitVec_decodedLength, decodedLength, "f");
|
|
42
|
-
__classPrivateFieldSet(this, _BitVec_isMsb, isMsb, "f");
|
|
37
|
+
this.__internal__decodedLength = decodedLength;
|
|
38
|
+
this.__internal__isMsb = isMsb;
|
|
43
39
|
}
|
|
44
40
|
/**
|
|
45
41
|
* @description The length of the value when encoded as a Uint8Array
|
|
46
42
|
*/
|
|
47
43
|
get encodedLength() {
|
|
48
|
-
return this.length + compactToU8a(
|
|
44
|
+
return this.length + compactToU8a(this.__internal__decodedLength).length;
|
|
49
45
|
}
|
|
50
46
|
/**
|
|
51
47
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
52
48
|
*/
|
|
53
49
|
inspect() {
|
|
54
50
|
return {
|
|
55
|
-
outer: [compactToU8a(
|
|
51
|
+
outer: [compactToU8a(this.__internal__decodedLength), super.toU8a()]
|
|
56
52
|
};
|
|
57
53
|
}
|
|
58
54
|
/**
|
|
@@ -69,12 +65,13 @@ export class BitVec extends Raw {
|
|
|
69
65
|
!!(v & 2),
|
|
70
66
|
!!(v & 1)
|
|
71
67
|
]);
|
|
72
|
-
const
|
|
73
|
-
|
|
68
|
+
const count = map.length;
|
|
69
|
+
const result = new Array(8 * count);
|
|
70
|
+
for (let i = 0; i < count; i++) {
|
|
74
71
|
const off = i * 8;
|
|
75
72
|
const v = map[i];
|
|
76
73
|
for (let j = 0; j < 8; j++) {
|
|
77
|
-
result[off + j] =
|
|
74
|
+
result[off + j] = this.__internal__isMsb
|
|
78
75
|
? v[j]
|
|
79
76
|
: v[7 - j];
|
|
80
77
|
}
|
|
@@ -87,7 +84,7 @@ export class BitVec extends Raw {
|
|
|
87
84
|
toHuman() {
|
|
88
85
|
return `0b${[...this.toU8a(true)]
|
|
89
86
|
.map((d) => `00000000${d.toString(2)}`.slice(-8))
|
|
90
|
-
.map((s) =>
|
|
87
|
+
.map((s) => this.__internal__isMsb ? s : s.split('').reverse().join(''))
|
|
91
88
|
.join('_')}`;
|
|
92
89
|
}
|
|
93
90
|
/**
|
|
@@ -104,7 +101,6 @@ export class BitVec extends Raw {
|
|
|
104
101
|
const bitVec = super.toU8a(isBare);
|
|
105
102
|
return isBare
|
|
106
103
|
? bitVec
|
|
107
|
-
: u8aConcatStrict([compactToU8a(
|
|
104
|
+
: u8aConcatStrict([compactToU8a(this.__internal__decodedLength), bitVec]);
|
|
108
105
|
}
|
|
109
106
|
}
|
|
110
|
-
_BitVec_decodedLength = new WeakMap(), _BitVec_isMsb = new WeakMap();
|
package/extended/Map.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var _CodecMap_KeyClass, _CodecMap_ValClass, _CodecMap_type;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
1
|
import { compactFromU8aLim, compactToU8a, isHex, isObject, isU8a, logger, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
|
|
4
2
|
import { AbstractArray } from '../abstract/Array.js';
|
|
5
3
|
import { Enum } from '../base/Enum.js';
|
|
@@ -16,7 +14,7 @@ function decodeMapFromU8a(registry, KeyClass, ValClass, u8a) {
|
|
|
16
14
|
types.push(KeyClass, ValClass);
|
|
17
15
|
}
|
|
18
16
|
const [values, decodedLength] = decodeU8a(registry, new Array(types.length), u8a.subarray(offset), [types, []]);
|
|
19
|
-
for (let i = 0
|
|
17
|
+
for (let i = 0, count = values.length; i < count; i += 2) {
|
|
20
18
|
output.set(values[i], values[i + 1]);
|
|
21
19
|
}
|
|
22
20
|
return [KeyClass, ValClass, output, offset + decodedLength];
|
|
@@ -78,14 +76,11 @@ export class CodecMap extends Map {
|
|
|
78
76
|
constructor(registry, keyType, valType, rawValue, type = 'HashMap') {
|
|
79
77
|
const [KeyClass, ValClass, decoded, decodedLength] = decodeMap(registry, keyType, valType, rawValue);
|
|
80
78
|
super(type === 'BTreeMap' ? sortMap(decoded) : decoded);
|
|
81
|
-
_CodecMap_KeyClass.set(this, void 0);
|
|
82
|
-
_CodecMap_ValClass.set(this, void 0);
|
|
83
|
-
_CodecMap_type.set(this, void 0);
|
|
84
79
|
this.registry = registry;
|
|
85
80
|
this.initialU8aLength = decodedLength;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
81
|
+
this.__internal__KeyClass = KeyClass;
|
|
82
|
+
this.__internal__ValClass = ValClass;
|
|
83
|
+
this.__internal__type = type;
|
|
89
84
|
}
|
|
90
85
|
/**
|
|
91
86
|
* @description The length of the value when encoded as a Uint8Array
|
|
@@ -173,7 +168,7 @@ export class CodecMap extends Map {
|
|
|
173
168
|
* @description Returns the base runtime type name for this instance
|
|
174
169
|
*/
|
|
175
170
|
toRawType() {
|
|
176
|
-
return `${
|
|
171
|
+
return `${this.__internal__type}<${this.registry.getClassName(this.__internal__KeyClass) || new this.__internal__KeyClass(this.registry).toRawType()},${this.registry.getClassName(this.__internal__ValClass) || new this.__internal__ValClass(this.registry).toRawType()}>`;
|
|
177
172
|
}
|
|
178
173
|
/**
|
|
179
174
|
* @description Returns the string representation of the value
|
|
@@ -196,4 +191,3 @@ export class CodecMap extends Map {
|
|
|
196
191
|
return u8aConcatStrict(encoded);
|
|
197
192
|
}
|
|
198
193
|
}
|
|
199
|
-
_CodecMap_KeyClass = new WeakMap(), _CodecMap_ValClass = new WeakMap(), _CodecMap_type = new WeakMap();
|
package/extended/Range.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var _Range_rangeName;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
1
|
import { Tuple } from '../base/Tuple.js';
|
|
4
2
|
/**
|
|
5
3
|
* @name Range
|
|
@@ -9,8 +7,7 @@ import { Tuple } from '../base/Tuple.js';
|
|
|
9
7
|
export class Range extends Tuple {
|
|
10
8
|
constructor(registry, Type, value, { rangeName = 'Range' } = {}) {
|
|
11
9
|
super(registry, [Type, Type], value);
|
|
12
|
-
|
|
13
|
-
__classPrivateFieldSet(this, _Range_rangeName, rangeName, "f");
|
|
10
|
+
this.__internal__rangeName = rangeName;
|
|
14
11
|
}
|
|
15
12
|
static with(Type) {
|
|
16
13
|
return class extends Range {
|
|
@@ -35,7 +32,6 @@ export class Range extends Tuple {
|
|
|
35
32
|
* @description Returns the base runtime type name for this instance
|
|
36
33
|
*/
|
|
37
34
|
toRawType() {
|
|
38
|
-
return `${
|
|
35
|
+
return `${this.__internal__rangeName}<${this.start.toRawType()}>`;
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
|
-
_Range_rangeName = new WeakMap();
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var _WrapperKeepOpaque_Type, _WrapperKeepOpaque_decoded, _WrapperKeepOpaque_opaqueName;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
1
|
import { compactAddLength, compactStripLength, compactToU8a, isHex, isU8a, u8aToU8a } from '@polkadot/util';
|
|
4
2
|
import { Raw } from '../native/Raw.js';
|
|
5
3
|
import { typeToConstructor } from '../utils/index.js';
|
|
@@ -26,12 +24,9 @@ export class WrapperKeepOpaque extends Bytes {
|
|
|
26
24
|
constructor(registry, typeName, value, { opaqueName = 'WrapperKeepOpaque' } = {}) {
|
|
27
25
|
const [Type, decoded, u8a] = decodeRaw(registry, typeName, value);
|
|
28
26
|
super(registry, u8a);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
__classPrivateFieldSet(this, _WrapperKeepOpaque_Type, Type, "f");
|
|
33
|
-
__classPrivateFieldSet(this, _WrapperKeepOpaque_decoded, decoded, "f");
|
|
34
|
-
__classPrivateFieldSet(this, _WrapperKeepOpaque_opaqueName, opaqueName, "f");
|
|
27
|
+
this.__internal__Type = Type;
|
|
28
|
+
this.__internal__decoded = decoded;
|
|
29
|
+
this.__internal__opaqueName = opaqueName;
|
|
35
30
|
}
|
|
36
31
|
static with(Type) {
|
|
37
32
|
return class extends WrapperKeepOpaque {
|
|
@@ -44,15 +39,15 @@ export class WrapperKeepOpaque extends Bytes {
|
|
|
44
39
|
* @description Checks if the wrapper is decodable
|
|
45
40
|
*/
|
|
46
41
|
get isDecoded() {
|
|
47
|
-
return !!
|
|
42
|
+
return !!this.__internal__decoded;
|
|
48
43
|
}
|
|
49
44
|
/**
|
|
50
45
|
* @description Returns a breakdown of the hex encoding for this Codec
|
|
51
46
|
*/
|
|
52
47
|
inspect() {
|
|
53
|
-
return
|
|
48
|
+
return this.__internal__decoded
|
|
54
49
|
? {
|
|
55
|
-
inner: [
|
|
50
|
+
inner: [this.__internal__decoded.inspect()],
|
|
56
51
|
outer: [compactToU8a(this.length)]
|
|
57
52
|
}
|
|
58
53
|
: {
|
|
@@ -63,40 +58,39 @@ export class WrapperKeepOpaque extends Bytes {
|
|
|
63
58
|
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
64
59
|
*/
|
|
65
60
|
toHuman(isExtended) {
|
|
66
|
-
return
|
|
67
|
-
?
|
|
61
|
+
return this.__internal__decoded
|
|
62
|
+
? this.__internal__decoded.toHuman(isExtended)
|
|
68
63
|
: super.toHuman();
|
|
69
64
|
}
|
|
70
65
|
/**
|
|
71
66
|
* @description Converts the value in a best-fit primitive form
|
|
72
67
|
*/
|
|
73
68
|
toPrimitive() {
|
|
74
|
-
return
|
|
75
|
-
?
|
|
69
|
+
return this.__internal__decoded
|
|
70
|
+
? this.__internal__decoded.toPrimitive()
|
|
76
71
|
: super.toPrimitive();
|
|
77
72
|
}
|
|
78
73
|
/**
|
|
79
74
|
* @description Returns the base runtime type name for this instance
|
|
80
75
|
*/
|
|
81
76
|
toRawType() {
|
|
82
|
-
return `${
|
|
77
|
+
return `${this.__internal__opaqueName}<${this.registry.getClassName(this.__internal__Type) || (this.__internal__decoded ? this.__internal__decoded.toRawType() : new this.__internal__Type(this.registry).toRawType())}>`;
|
|
83
78
|
}
|
|
84
79
|
/**
|
|
85
80
|
* @description Converts the Object to to a string (either decoded or bytes)
|
|
86
81
|
*/
|
|
87
82
|
toString() {
|
|
88
|
-
return
|
|
89
|
-
?
|
|
83
|
+
return this.__internal__decoded
|
|
84
|
+
? this.__internal__decoded.toString()
|
|
90
85
|
: super.toString();
|
|
91
86
|
}
|
|
92
87
|
/**
|
|
93
88
|
* @description Returns the decoded that the WrapperKeepOpaque represents (if available), throws if non-decodable
|
|
94
89
|
*/
|
|
95
90
|
unwrap() {
|
|
96
|
-
if (!
|
|
97
|
-
throw new Error(`${
|
|
91
|
+
if (!this.__internal__decoded) {
|
|
92
|
+
throw new Error(`${this.__internal__opaqueName}: unwrapping an undecodable value`);
|
|
98
93
|
}
|
|
99
|
-
return
|
|
94
|
+
return this.__internal__decoded;
|
|
100
95
|
}
|
|
101
96
|
}
|
|
102
|
-
_WrapperKeepOpaque_Type = new WeakMap(), _WrapperKeepOpaque_decoded = new WeakMap(), _WrapperKeepOpaque_opaqueName = new WeakMap();
|
package/native/Float.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var _Float_bitLength;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
1
|
import { floatToU8a, isHex, isU8a, u8aToFloat, u8aToHex, u8aToU8a } from '@polkadot/util';
|
|
4
2
|
/**
|
|
5
3
|
* @name Float
|
|
@@ -16,8 +14,7 @@ export class Float extends Number {
|
|
|
16
14
|
? 0
|
|
17
15
|
: u8aToFloat(u8aToU8a(value), { bitLength })
|
|
18
16
|
: (value || 0));
|
|
19
|
-
|
|
20
|
-
__classPrivateFieldSet(this, _Float_bitLength, bitLength, "f");
|
|
17
|
+
this.__internal__bitLength = bitLength;
|
|
21
18
|
this.encodedLength = bitLength / 8;
|
|
22
19
|
this.initialU8aLength = this.encodedLength;
|
|
23
20
|
this.registry = registry;
|
|
@@ -91,15 +88,14 @@ export class Float extends Number {
|
|
|
91
88
|
* @description Returns the base runtime type name for this instance
|
|
92
89
|
*/
|
|
93
90
|
toRawType() {
|
|
94
|
-
return `f${
|
|
91
|
+
return `f${this.__internal__bitLength}`;
|
|
95
92
|
}
|
|
96
93
|
/**
|
|
97
94
|
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
98
95
|
*/
|
|
99
96
|
toU8a(_isBare) {
|
|
100
97
|
return floatToU8a(this, {
|
|
101
|
-
bitLength:
|
|
98
|
+
bitLength: this.__internal__bitLength
|
|
102
99
|
});
|
|
103
100
|
}
|
|
104
101
|
}
|
|
105
|
-
_Float_bitLength = new WeakMap();
|
package/native/Set.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
var _CodecSet_allowed, _CodecSet_byteLength;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
1
|
import { BN, bnToBn, bnToU8a, isBn, isNumber, isString, isU8a, isUndefined, objectProperties, stringify, stringPascalCase, u8aToBn, u8aToHex, u8aToU8a } from '@polkadot/util';
|
|
4
2
|
import { compareArray } from '../utils/index.js';
|
|
5
3
|
function encodeSet(setValues, values) {
|
|
6
4
|
const encoded = new BN(0);
|
|
7
|
-
for (let i = 0
|
|
5
|
+
for (let i = 0, count = values.length; i < count; i++) {
|
|
8
6
|
encoded.ior(bnToBn(setValues[values[i]] || 0));
|
|
9
7
|
}
|
|
10
8
|
return encoded;
|
|
11
9
|
}
|
|
12
10
|
/** @internal */
|
|
13
11
|
function decodeSetArray(setValues, values) {
|
|
14
|
-
const
|
|
15
|
-
|
|
12
|
+
const count = values.length;
|
|
13
|
+
const result = new Array(count);
|
|
14
|
+
for (let i = 0; i < count; i++) {
|
|
16
15
|
const key = values[i];
|
|
17
16
|
if (isUndefined(setValues[key])) {
|
|
18
17
|
throw new Error(`Set: Invalid key '${key}' passed to Set, allowed ${Object.keys(setValues).join(', ')}`);
|
|
@@ -26,7 +25,7 @@ function decodeSetNumber(setValues, _value) {
|
|
|
26
25
|
const bn = bnToBn(_value);
|
|
27
26
|
const keys = Object.keys(setValues);
|
|
28
27
|
const result = [];
|
|
29
|
-
for (let i = 0
|
|
28
|
+
for (let i = 0, count = keys.length; i < count; i++) {
|
|
30
29
|
const key = keys[i];
|
|
31
30
|
if (bn.and(bnToBn(setValues[key])).eq(bnToBn(setValues[key]))) {
|
|
32
31
|
result.push(key);
|
|
@@ -69,8 +68,6 @@ function decodeSet(setValues, value = 0, bitLength) {
|
|
|
69
68
|
export class CodecSet extends Set {
|
|
70
69
|
constructor(registry, setValues, value, bitLength = 8) {
|
|
71
70
|
super(decodeSet(setValues, value, bitLength));
|
|
72
|
-
_CodecSet_allowed.set(this, void 0);
|
|
73
|
-
_CodecSet_byteLength.set(this, void 0);
|
|
74
71
|
/**
|
|
75
72
|
* @description adds a value to the Set (extended to allow for validity checking)
|
|
76
73
|
*/
|
|
@@ -78,15 +75,15 @@ export class CodecSet extends Set {
|
|
|
78
75
|
// ^^^ add = () property done to assign this instance's this, otherwise Set.add creates "some" chaos
|
|
79
76
|
// we have the isUndefined(this._setValues) in here as well, add is used internally
|
|
80
77
|
// in the Set constructor (so it is undefined at this point, and should allow)
|
|
81
|
-
if (
|
|
78
|
+
if (this.__internal__allowed && isUndefined(this.__internal__allowed[key])) {
|
|
82
79
|
throw new Error(`Set: Invalid key '${key}' on add`);
|
|
83
80
|
}
|
|
84
81
|
super.add(key);
|
|
85
82
|
return this;
|
|
86
83
|
};
|
|
87
84
|
this.registry = registry;
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
this.__internal__allowed = setValues;
|
|
86
|
+
this.__internal__byteLength = bitLength / 8;
|
|
90
87
|
}
|
|
91
88
|
static with(values, bitLength) {
|
|
92
89
|
var _a;
|
|
@@ -97,8 +94,9 @@ export class CodecSet extends Set {
|
|
|
97
94
|
},
|
|
98
95
|
(() => {
|
|
99
96
|
const keys = Object.keys(values);
|
|
100
|
-
const
|
|
101
|
-
|
|
97
|
+
const count = keys.length;
|
|
98
|
+
const isKeys = new Array(count);
|
|
99
|
+
for (let i = 0; i < count; i++) {
|
|
102
100
|
isKeys[i] = `is${stringPascalCase(keys[i])}`;
|
|
103
101
|
}
|
|
104
102
|
objectProperties(_a.prototype, isKeys, (_, i, self) => self.strings.includes(keys[i]));
|
|
@@ -109,7 +107,7 @@ export class CodecSet extends Set {
|
|
|
109
107
|
* @description The length of the value when encoded as a Uint8Array
|
|
110
108
|
*/
|
|
111
109
|
get encodedLength() {
|
|
112
|
-
return
|
|
110
|
+
return this.__internal__byteLength;
|
|
113
111
|
}
|
|
114
112
|
/**
|
|
115
113
|
* @description returns a hash of the contents
|
|
@@ -133,7 +131,7 @@ export class CodecSet extends Set {
|
|
|
133
131
|
* @description The encoded value for the set members
|
|
134
132
|
*/
|
|
135
133
|
get valueEncoded() {
|
|
136
|
-
return encodeSet(
|
|
134
|
+
return encodeSet(this.__internal__allowed, this.strings);
|
|
137
135
|
}
|
|
138
136
|
/**
|
|
139
137
|
* @description Compares the value of the input to see if there is a match
|
|
@@ -193,7 +191,7 @@ export class CodecSet extends Set {
|
|
|
193
191
|
* @description Returns the base runtime type name for this instance
|
|
194
192
|
*/
|
|
195
193
|
toRawType() {
|
|
196
|
-
return stringify({ _set:
|
|
194
|
+
return stringify({ _set: this.__internal__allowed });
|
|
197
195
|
}
|
|
198
196
|
/**
|
|
199
197
|
* @description Returns the string representation of the value
|
|
@@ -206,9 +204,8 @@ export class CodecSet extends Set {
|
|
|
206
204
|
*/
|
|
207
205
|
toU8a(_isBare) {
|
|
208
206
|
return bnToU8a(this.valueEncoded, {
|
|
209
|
-
bitLength:
|
|
207
|
+
bitLength: this.__internal__byteLength * 8,
|
|
210
208
|
isLe: true
|
|
211
209
|
});
|
|
212
210
|
}
|
|
213
211
|
}
|
|
214
|
-
_CodecSet_allowed = new WeakMap(), _CodecSet_byteLength = new WeakMap();
|