@polkadot/types-codec 6.12.2-2
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.cjs +208 -0
- package/abstract/AbstractArray.d.ts +84 -0
- package/abstract/AbstractArray.js +197 -0
- package/abstract/AbstractInt.cjs +254 -0
- package/abstract/AbstractInt.d.ts +75 -0
- package/abstract/AbstractInt.js +231 -0
- package/abstract/index.cjs +21 -0
- package/abstract/index.d.ts +2 -0
- package/abstract/index.js +4 -0
- package/base/Base.cjs +109 -0
- package/base/Base.d.ts +54 -0
- package/base/Base.js +100 -0
- package/base/Compact.cjs +201 -0
- package/base/Compact.d.ts +83 -0
- package/base/Compact.js +186 -0
- package/base/DoNotConstruct.cjs +101 -0
- package/base/DoNotConstruct.d.ts +33 -0
- package/base/DoNotConstruct.js +88 -0
- package/base/Enum.cjs +437 -0
- package/base/Enum.d.ts +101 -0
- package/base/Enum.js +413 -0
- package/base/Int.cjs +45 -0
- package/base/Int.d.ts +16 -0
- package/base/Int.js +33 -0
- package/base/Null.cjs +111 -0
- package/base/Null.d.ts +54 -0
- package/base/Null.js +101 -0
- package/base/Option.cjs +256 -0
- package/base/Option.d.ts +88 -0
- package/base/Option.js +240 -0
- package/base/Result.cjs +109 -0
- package/base/Result.d.ts +46 -0
- package/base/Result.js +98 -0
- package/base/Tuple.cjs +132 -0
- package/base/Tuple.d.ts +39 -0
- package/base/Tuple.js +116 -0
- package/base/UInt.cjs +39 -0
- package/base/UInt.d.ts +15 -0
- package/base/UInt.js +29 -0
- package/base/Vec.cjs +126 -0
- package/base/Vec.d.ts +28 -0
- package/base/Vec.js +104 -0
- package/base/VecAny.cjs +31 -0
- package/base/VecAny.d.ts +15 -0
- package/base/VecAny.js +21 -0
- package/base/VecFixed.cjs +111 -0
- package/base/VecFixed.d.ts +26 -0
- package/base/VecFixed.js +93 -0
- package/base/index.cjs +109 -0
- package/base/index.d.ts +13 -0
- package/base/index.js +15 -0
- package/bundle.cjs +100 -0
- package/bundle.d.ts +7 -0
- package/bundle.js +9 -0
- package/detectPackage.cjs +9 -0
- package/detectPackage.d.ts +1 -0
- package/detectPackage.js +5 -0
- package/extended/BTreeMap.cjs +24 -0
- package/extended/BTreeMap.d.ts +5 -0
- package/extended/BTreeMap.js +14 -0
- package/extended/BTreeSet.cjs +227 -0
- package/extended/BTreeSet.d.ts +55 -0
- package/extended/BTreeSet.js +212 -0
- package/extended/BitVec.cjs +97 -0
- package/extended/BitVec.d.ts +26 -0
- package/extended/BitVec.js +82 -0
- package/extended/Bytes.cjs +86 -0
- package/extended/Bytes.d.ts +25 -0
- package/extended/Bytes.js +75 -0
- package/extended/HashMap.cjs +24 -0
- package/extended/HashMap.d.ts +5 -0
- package/extended/HashMap.js +14 -0
- package/extended/Linkage.cjs +89 -0
- package/extended/Linkage.d.ts +31 -0
- package/extended/Linkage.js +71 -0
- package/extended/Map.cjs +244 -0
- package/extended/Map.d.ts +50 -0
- package/extended/Map.js +225 -0
- package/extended/Range.cjs +92 -0
- package/extended/Range.d.ts +30 -0
- package/extended/Range.js +75 -0
- package/extended/Type.cjs +39 -0
- package/extended/Type.d.ts +16 -0
- package/extended/Type.js +27 -0
- package/extended/U8aFixed.cjs +66 -0
- package/extended/U8aFixed.d.ts +16 -0
- package/extended/U8aFixed.js +53 -0
- package/extended/WrapperOpaque.cjs +68 -0
- package/extended/WrapperOpaque.d.ts +18 -0
- package/extended/WrapperOpaque.js +57 -0
- package/extended/index.cjs +105 -0
- package/extended/index.d.ts +11 -0
- package/extended/index.js +13 -0
- package/index.cjs +20 -0
- package/index.d.ts +2 -0
- package/index.js +4 -0
- package/native/Bool.cjs +141 -0
- package/native/Bool.d.ts +62 -0
- package/native/Bool.js +130 -0
- package/native/Date.cjs +170 -0
- package/native/Date.d.ts +76 -0
- package/native/Date.js +158 -0
- package/native/Json.cjs +133 -0
- package/native/Json.d.ts +55 -0
- package/native/Json.js +117 -0
- package/native/Raw.cjs +192 -0
- package/native/Raw.d.ts +90 -0
- package/native/Raw.js +182 -0
- package/native/Set.cjs +268 -0
- package/native/Set.d.ts +76 -0
- package/native/Set.js +251 -0
- package/native/Struct.cjs +289 -0
- package/native/Struct.d.ts +92 -0
- package/native/Struct.js +273 -0
- package/native/Text.cjs +193 -0
- package/native/Text.d.ts +71 -0
- package/native/Text.js +178 -0
- package/native/index.cjs +79 -0
- package/native/index.d.ts +7 -0
- package/native/index.js +9 -0
- package/package.json +387 -0
- package/packageInfo.cjs +14 -0
- package/packageInfo.d.ts +4 -0
- package/packageInfo.js +7 -0
- package/primitive/I128.cjs +26 -0
- package/primitive/I128.d.ts +11 -0
- package/primitive/I128.js +16 -0
- package/primitive/I16.cjs +26 -0
- package/primitive/I16.d.ts +11 -0
- package/primitive/I16.js +16 -0
- package/primitive/I256.cjs +26 -0
- package/primitive/I256.d.ts +11 -0
- package/primitive/I256.js +16 -0
- package/primitive/I32.cjs +26 -0
- package/primitive/I32.d.ts +11 -0
- package/primitive/I32.js +16 -0
- package/primitive/I64.cjs +26 -0
- package/primitive/I64.d.ts +11 -0
- package/primitive/I64.js +16 -0
- package/primitive/I8.cjs +26 -0
- package/primitive/I8.d.ts +11 -0
- package/primitive/I8.js +16 -0
- package/primitive/U128.cjs +26 -0
- package/primitive/U128.d.ts +11 -0
- package/primitive/U128.js +16 -0
- package/primitive/U16.cjs +26 -0
- package/primitive/U16.d.ts +11 -0
- package/primitive/U16.js +16 -0
- package/primitive/U256.cjs +26 -0
- package/primitive/U256.d.ts +11 -0
- package/primitive/U256.js +16 -0
- package/primitive/U32.cjs +26 -0
- package/primitive/U32.d.ts +11 -0
- package/primitive/U32.js +16 -0
- package/primitive/U64.cjs +26 -0
- package/primitive/U64.d.ts +11 -0
- package/primitive/U64.js +16 -0
- package/primitive/U8.cjs +26 -0
- package/primitive/U8.d.ts +11 -0
- package/primitive/U8.js +16 -0
- package/primitive/USize.cjs +28 -0
- package/primitive/USize.d.ts +12 -0
- package/primitive/USize.js +18 -0
- package/primitive/index.cjs +187 -0
- package/primitive/index.d.ts +13 -0
- package/primitive/index.js +15 -0
- package/types/codec.cjs +1 -0
- package/types/codec.d.ts +77 -0
- package/types/codec.js +1 -0
- package/types/helpers.cjs +1 -0
- package/types/helpers.d.ts +14 -0
- package/types/helpers.js +1 -0
- package/types/index.cjs +57 -0
- package/types/index.d.ts +4 -0
- package/types/index.js +6 -0
- package/types/interfaces.cjs +1 -0
- package/types/interfaces.d.ts +68 -0
- package/types/interfaces.js +1 -0
- package/types/registry.cjs +1 -0
- package/types/registry.d.ts +44 -0
- package/types/registry.js +1 -0
- package/utils/compareArray.cjs +22 -0
- package/utils/compareArray.d.ts +1 -0
- package/utils/compareArray.js +13 -0
- package/utils/compareMap.cjs +39 -0
- package/utils/compareMap.d.ts +1 -0
- package/utils/compareMap.js +31 -0
- package/utils/compareSet.cjs +29 -0
- package/utils/compareSet.d.ts +1 -0
- package/utils/compareSet.js +22 -0
- package/utils/decodeU8a.cjs +69 -0
- package/utils/decodeU8a.d.ts +13 -0
- package/utils/decodeU8a.js +60 -0
- package/utils/index.cjs +95 -0
- package/utils/index.d.ts +9 -0
- package/utils/index.js +11 -0
- package/utils/mapToTypeMap.cjs +25 -0
- package/utils/mapToTypeMap.d.ts +5 -0
- package/utils/mapToTypeMap.js +17 -0
- package/utils/sanitize.cjs +242 -0
- package/utils/sanitize.d.ts +16 -0
- package/utils/sanitize.js +215 -0
- package/utils/sortValues.cjs +89 -0
- package/utils/sortValues.d.ts +13 -0
- package/utils/sortValues.js +73 -0
- package/utils/typeToConstructor.cjs +14 -0
- package/utils/typeToConstructor.d.ts +2 -0
- package/utils/typeToConstructor.js +6 -0
- package/utils/typesToMap.cjs +20 -0
- package/utils/typesToMap.d.ts +2 -0
- package/utils/typesToMap.js +13 -0
- package/utils/util.cjs +15 -0
- package/utils/util.d.ts +3 -0
- package/utils/util.js +7 -0
package/extended/Map.js
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
+
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
import { compactFromU8a, compactToU8a, isHex, isObject, isU8a, logger, stringify, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
|
|
6
|
+
import { AbstractArray } from "../abstract/AbstractArray.js";
|
|
7
|
+
import { Enum } from "../base/Enum.js";
|
|
8
|
+
import { Struct } from "../native/Struct.js";
|
|
9
|
+
import { compareMap, decodeU8a, sortMap, typeToConstructor } from "../utils/index.js";
|
|
10
|
+
const l = logger('Map');
|
|
11
|
+
/** @internal */
|
|
12
|
+
|
|
13
|
+
function decodeMapFromU8a(registry, KeyClass, ValClass, u8a) {
|
|
14
|
+
const output = new Map();
|
|
15
|
+
const [offset, length] = compactFromU8a(u8a);
|
|
16
|
+
const count = length.toNumber();
|
|
17
|
+
const types = [];
|
|
18
|
+
|
|
19
|
+
for (let i = 0; i < count; i++) {
|
|
20
|
+
types.push(KeyClass, ValClass);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const [values, decodedLength] = decodeU8a(registry, u8a.subarray(offset), types);
|
|
24
|
+
|
|
25
|
+
for (let i = 0; i < values.length; i += 2) {
|
|
26
|
+
output.set(values[i], values[i + 1]);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return [output, offset + decodedLength];
|
|
30
|
+
}
|
|
31
|
+
/** @internal */
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
function decodeMapFromMap(registry, KeyClass, ValClass, value) {
|
|
35
|
+
const output = new Map();
|
|
36
|
+
|
|
37
|
+
for (const [key, val] of value.entries()) {
|
|
38
|
+
const isComplex = KeyClass.prototype instanceof AbstractArray || KeyClass.prototype instanceof Struct || KeyClass.prototype instanceof Enum;
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
output.set(key instanceof KeyClass ? key : new KeyClass(registry, isComplex ? JSON.parse(key) : key), val instanceof ValClass ? val : new ValClass(registry, val));
|
|
42
|
+
} catch (error) {
|
|
43
|
+
l.error('Failed to decode key or value:', error.message);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return [output, 0];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Decode input to pass into constructor.
|
|
52
|
+
*
|
|
53
|
+
* @param KeyClass - Type of the map key
|
|
54
|
+
* @param ValClass - Type of the map value
|
|
55
|
+
* @param value - Value to decode, one of:
|
|
56
|
+
* - null
|
|
57
|
+
* - undefined
|
|
58
|
+
* - hex
|
|
59
|
+
* - Uint8Array
|
|
60
|
+
* - Map<any, any>, where both key and value types are either
|
|
61
|
+
* constructors or decodeable values for their types.
|
|
62
|
+
* @param jsonMap
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
function decodeMap(registry, keyType, valType, value) {
|
|
68
|
+
const KeyClass = typeToConstructor(registry, keyType);
|
|
69
|
+
const ValClass = typeToConstructor(registry, valType);
|
|
70
|
+
|
|
71
|
+
if (!value) {
|
|
72
|
+
return [new Map(), 0];
|
|
73
|
+
} else if (isU8a(value) || isHex(value)) {
|
|
74
|
+
return decodeMapFromU8a(registry, KeyClass, ValClass, u8aToU8a(value));
|
|
75
|
+
} else if (value instanceof Map) {
|
|
76
|
+
return decodeMapFromMap(registry, KeyClass, ValClass, value);
|
|
77
|
+
} else if (isObject(value)) {
|
|
78
|
+
return decodeMapFromMap(registry, KeyClass, ValClass, new Map(Object.entries(value)));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
throw new Error('Map: cannot decode type');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
var _KeyClass = /*#__PURE__*/_classPrivateFieldLooseKey("KeyClass");
|
|
85
|
+
|
|
86
|
+
var _ValClass = /*#__PURE__*/_classPrivateFieldLooseKey("ValClass");
|
|
87
|
+
|
|
88
|
+
var _type = /*#__PURE__*/_classPrivateFieldLooseKey("type");
|
|
89
|
+
|
|
90
|
+
export class CodecMap extends Map {
|
|
91
|
+
constructor(registry, keyType, valType, rawValue, type = 'HashMap') {
|
|
92
|
+
const [decoded, decodedLength] = decodeMap(registry, keyType, valType, rawValue);
|
|
93
|
+
super(type === 'BTreeMap' ? sortMap(decoded) : decoded);
|
|
94
|
+
this.registry = void 0;
|
|
95
|
+
this.createdAtHash = void 0;
|
|
96
|
+
Object.defineProperty(this, _KeyClass, {
|
|
97
|
+
writable: true,
|
|
98
|
+
value: void 0
|
|
99
|
+
});
|
|
100
|
+
Object.defineProperty(this, _ValClass, {
|
|
101
|
+
writable: true,
|
|
102
|
+
value: void 0
|
|
103
|
+
});
|
|
104
|
+
this.initialU8aLength = void 0;
|
|
105
|
+
Object.defineProperty(this, _type, {
|
|
106
|
+
writable: true,
|
|
107
|
+
value: void 0
|
|
108
|
+
});
|
|
109
|
+
this.registry = registry;
|
|
110
|
+
this.initialU8aLength = decodedLength;
|
|
111
|
+
_classPrivateFieldLooseBase(this, _KeyClass)[_KeyClass] = typeToConstructor(registry, keyType);
|
|
112
|
+
_classPrivateFieldLooseBase(this, _ValClass)[_ValClass] = typeToConstructor(registry, valType);
|
|
113
|
+
_classPrivateFieldLooseBase(this, _type)[_type] = type;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
get encodedLength() {
|
|
121
|
+
let len = compactToU8a(this.size).length;
|
|
122
|
+
|
|
123
|
+
for (const [k, v] of this.entries()) {
|
|
124
|
+
len += v.encodedLength + k.encodedLength;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return len;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* @description Returns a hash of the value
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
get hash() {
|
|
135
|
+
return this.registry.hash(this.toU8a());
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* @description Checks if the value is an empty value
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
get isEmpty() {
|
|
143
|
+
return this.size === 0;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* @description Compares the value of the input to see if there is a match
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
eq(other) {
|
|
151
|
+
return compareMap(this, other);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
toHex() {
|
|
159
|
+
return u8aToHex(this.toU8a());
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
toHuman(isExtended) {
|
|
167
|
+
const json = {};
|
|
168
|
+
|
|
169
|
+
for (const [k, v] of this.entries()) {
|
|
170
|
+
json[k.toString()] = v.toHuman(isExtended);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return json;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
177
|
+
*/
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
toJSON() {
|
|
181
|
+
const json = {};
|
|
182
|
+
|
|
183
|
+
for (const [k, v] of this.entries()) {
|
|
184
|
+
json[k.toString()] = v.toJSON();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return json;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* @description Returns the base runtime type name for this instance
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
toRawType() {
|
|
195
|
+
return `${_classPrivateFieldLooseBase(this, _type)[_type]}<${this.registry.getClassName(_classPrivateFieldLooseBase(this, _KeyClass)[_KeyClass]) || new (_classPrivateFieldLooseBase(this, _KeyClass)[_KeyClass])(this.registry).toRawType()},${this.registry.getClassName(_classPrivateFieldLooseBase(this, _ValClass)[_ValClass]) || new (_classPrivateFieldLooseBase(this, _ValClass)[_ValClass])(this.registry).toRawType()}>`;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* @description Returns the string representation of the value
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
toString() {
|
|
203
|
+
return stringify(this.toJSON());
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
207
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
208
|
+
*/
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
toU8a(isBare) {
|
|
212
|
+
const encoded = new Array();
|
|
213
|
+
|
|
214
|
+
if (!isBare) {
|
|
215
|
+
encoded.push(compactToU8a(this.size));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
for (const [k, v] of this.entries()) {
|
|
219
|
+
encoded.push(k.toU8a(isBare), v.toU8a(isBare));
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return u8aConcat(...encoded);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.RangeInclusive = exports.Range = void 0;
|
|
9
|
+
|
|
10
|
+
var _classPrivateFieldLooseBase2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldLooseBase"));
|
|
11
|
+
|
|
12
|
+
var _classPrivateFieldLooseKey2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldLooseKey"));
|
|
13
|
+
|
|
14
|
+
var _Tuple = require("../base/Tuple.cjs");
|
|
15
|
+
|
|
16
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
17
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
18
|
+
var _rangeName = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("rangeName");
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @name Range
|
|
22
|
+
* @description
|
|
23
|
+
* Rust `Range<T>` representation
|
|
24
|
+
*/
|
|
25
|
+
class Range extends _Tuple.Tuple {
|
|
26
|
+
constructor(registry, Type, value) {
|
|
27
|
+
let rangeName = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'Range';
|
|
28
|
+
super(registry, {
|
|
29
|
+
end: Type,
|
|
30
|
+
start: Type
|
|
31
|
+
}, value);
|
|
32
|
+
Object.defineProperty(this, _rangeName, {
|
|
33
|
+
writable: true,
|
|
34
|
+
value: void 0
|
|
35
|
+
});
|
|
36
|
+
(0, _classPrivateFieldLooseBase2.default)(this, _rangeName)[_rangeName] = rangeName;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static with(Types) {
|
|
40
|
+
return class extends Range {
|
|
41
|
+
constructor(registry, value) {
|
|
42
|
+
super(registry, Types, value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @description Returns the starting range value
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
get start() {
|
|
53
|
+
return this[0];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* @description Returns the ending range value
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
get end() {
|
|
61
|
+
return this[1];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @description Returns the base runtime type name for this instance
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
toRawType() {
|
|
69
|
+
return `${(0, _classPrivateFieldLooseBase2.default)(this, _rangeName)[_rangeName]}<${this.start.toRawType()}>`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
exports.Range = Range;
|
|
75
|
+
|
|
76
|
+
class RangeInclusive extends Range {
|
|
77
|
+
constructor(registry, type, value) {
|
|
78
|
+
super(registry, type, value, 'RangeInclusive');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static with(Types) {
|
|
82
|
+
return class extends RangeInclusive {
|
|
83
|
+
constructor(registry, value) {
|
|
84
|
+
super(registry, Types, value);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
exports.RangeInclusive = RangeInclusive;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AnyTuple, CodecClass, CodecRegistry, INumber } from '../types';
|
|
2
|
+
import { Tuple } from '../base/Tuple';
|
|
3
|
+
declare type RangeType = 'Range' | 'RangeInclusive';
|
|
4
|
+
/**
|
|
5
|
+
* @name Range
|
|
6
|
+
* @description
|
|
7
|
+
* Rust `Range<T>` representation
|
|
8
|
+
*/
|
|
9
|
+
export declare class Range<T extends INumber> extends Tuple {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(registry: CodecRegistry, Type: CodecClass<T> | string, value?: AnyTuple, rangeName?: RangeType);
|
|
12
|
+
static with<T extends INumber>(Types: CodecClass<T> | string): CodecClass<Range<T>>;
|
|
13
|
+
/**
|
|
14
|
+
* @description Returns the starting range value
|
|
15
|
+
*/
|
|
16
|
+
get start(): T;
|
|
17
|
+
/**
|
|
18
|
+
* @description Returns the ending range value
|
|
19
|
+
*/
|
|
20
|
+
get end(): T;
|
|
21
|
+
/**
|
|
22
|
+
* @description Returns the base runtime type name for this instance
|
|
23
|
+
*/
|
|
24
|
+
toRawType(): string;
|
|
25
|
+
}
|
|
26
|
+
export declare class RangeInclusive<T extends INumber = INumber> extends Range<T> {
|
|
27
|
+
constructor(registry: CodecRegistry, type: CodecClass<T> | string, value?: AnyTuple);
|
|
28
|
+
static with<T extends INumber>(Types: CodecClass<T> | string): CodecClass<RangeInclusive<T>>;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
+
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
import { Tuple } from "../base/Tuple.js";
|
|
6
|
+
|
|
7
|
+
var _rangeName = /*#__PURE__*/_classPrivateFieldLooseKey("rangeName");
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @name Range
|
|
11
|
+
* @description
|
|
12
|
+
* Rust `Range<T>` representation
|
|
13
|
+
*/
|
|
14
|
+
export class Range extends Tuple {
|
|
15
|
+
constructor(registry, Type, value, rangeName = 'Range') {
|
|
16
|
+
super(registry, {
|
|
17
|
+
end: Type,
|
|
18
|
+
start: Type
|
|
19
|
+
}, value);
|
|
20
|
+
Object.defineProperty(this, _rangeName, {
|
|
21
|
+
writable: true,
|
|
22
|
+
value: void 0
|
|
23
|
+
});
|
|
24
|
+
_classPrivateFieldLooseBase(this, _rangeName)[_rangeName] = rangeName;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static with(Types) {
|
|
28
|
+
return class extends Range {
|
|
29
|
+
constructor(registry, value) {
|
|
30
|
+
super(registry, Types, value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @description Returns the starting range value
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
get start() {
|
|
41
|
+
return this[0];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @description Returns the ending range value
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
get end() {
|
|
49
|
+
return this[1];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @description Returns the base runtime type name for this instance
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
toRawType() {
|
|
57
|
+
return `${_classPrivateFieldLooseBase(this, _rangeName)[_rangeName]}<${this.start.toRawType()}>`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
export class RangeInclusive extends Range {
|
|
62
|
+
constructor(registry, type, value) {
|
|
63
|
+
super(registry, type, value, 'RangeInclusive');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static with(Types) {
|
|
67
|
+
return class extends RangeInclusive {
|
|
68
|
+
constructor(registry, value) {
|
|
69
|
+
super(registry, Types, value);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Type = void 0;
|
|
7
|
+
|
|
8
|
+
var _Text = require("../native/Text.cjs");
|
|
9
|
+
|
|
10
|
+
var _index = require("../utils/index.cjs");
|
|
11
|
+
|
|
12
|
+
// Copyright 2017-2021 @polkadot/types authors & contributors
|
|
13
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @name Type
|
|
17
|
+
* @description
|
|
18
|
+
* This is a extended version of Text, specifically to handle types. Here we rely fully
|
|
19
|
+
* on what Text provides us, however we also adjust the types received from the runtime,
|
|
20
|
+
* i.e. we remove the `T::` prefixes found in some types for consistency across implementation.
|
|
21
|
+
*/
|
|
22
|
+
class Type extends _Text.Text {
|
|
23
|
+
constructor(registry) {
|
|
24
|
+
let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
25
|
+
super(registry, value);
|
|
26
|
+
this.setOverride((0, _index.sanitize)(this.toString()));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @description Returns the base runtime type name for this instance
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
toRawType() {
|
|
34
|
+
return 'Type';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.Type = Type;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CodecRegistry } from '../types';
|
|
2
|
+
import { Text } from '../native/Text';
|
|
3
|
+
/**
|
|
4
|
+
* @name Type
|
|
5
|
+
* @description
|
|
6
|
+
* This is a extended version of Text, specifically to handle types. Here we rely fully
|
|
7
|
+
* on what Text provides us, however we also adjust the types received from the runtime,
|
|
8
|
+
* i.e. we remove the `T::` prefixes found in some types for consistency across implementation.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Type extends Text {
|
|
11
|
+
constructor(registry: CodecRegistry, value?: Text | Uint8Array | string);
|
|
12
|
+
/**
|
|
13
|
+
* @description Returns the base runtime type name for this instance
|
|
14
|
+
*/
|
|
15
|
+
toRawType(): string;
|
|
16
|
+
}
|
package/extended/Type.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Copyright 2017-2021 @polkadot/types authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { Text } from "../native/Text.js";
|
|
4
|
+
import { sanitize } from "../utils/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* @name Type
|
|
7
|
+
* @description
|
|
8
|
+
* This is a extended version of Text, specifically to handle types. Here we rely fully
|
|
9
|
+
* on what Text provides us, however we also adjust the types received from the runtime,
|
|
10
|
+
* i.e. we remove the `T::` prefixes found in some types for consistency across implementation.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export class Type extends Text {
|
|
14
|
+
constructor(registry, value = '') {
|
|
15
|
+
super(registry, value);
|
|
16
|
+
this.setOverride(sanitize(this.toString()));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @description Returns the base runtime type name for this instance
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
toRawType() {
|
|
24
|
+
return 'Type';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.U8aFixed = void 0;
|
|
7
|
+
|
|
8
|
+
var _util = require("@polkadot/util");
|
|
9
|
+
|
|
10
|
+
var _Raw = require("../native/Raw.cjs");
|
|
11
|
+
|
|
12
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
13
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
14
|
+
|
|
15
|
+
/** @internal */
|
|
16
|
+
function decodeU8aFixed(value, bitLength) {
|
|
17
|
+
const u8a = (0, _util.u8aToU8a)(value);
|
|
18
|
+
const byteLength = bitLength / 8;
|
|
19
|
+
|
|
20
|
+
if (!u8a.length) {
|
|
21
|
+
return [new Uint8Array(byteLength), 0];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
(0, _util.assert)(u8a.length >= byteLength, () => `Expected at least ${byteLength} bytes (${bitLength} bits), found ${u8a.length} bytes`);
|
|
25
|
+
return [u8a.subarray(0, byteLength), byteLength];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @name U8aFixed
|
|
29
|
+
* @description
|
|
30
|
+
* A U8a that manages a a sequence of bytes up to the specified bitLength. Not meant
|
|
31
|
+
* to be used directly, rather is should be subclassed with the specific lengths.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class U8aFixed extends _Raw.Raw {
|
|
36
|
+
constructor(registry) {
|
|
37
|
+
let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Uint8Array();
|
|
38
|
+
let bitLength = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 256;
|
|
39
|
+
const [u8a, decodedLength] = decodeU8aFixed(value, bitLength);
|
|
40
|
+
super(registry, u8a, decodedLength);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static with(bitLength, typeName) {
|
|
44
|
+
return class extends U8aFixed {
|
|
45
|
+
constructor(registry, value) {
|
|
46
|
+
super(registry, value, bitLength);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
toRawType() {
|
|
50
|
+
return typeName || super.toRawType();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* @description Returns the base runtime type name for this instance
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
toRawType() {
|
|
61
|
+
return `[u8;${this.length}]`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
exports.U8aFixed = U8aFixed;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AnyU8a, CodecClass, CodecRegistry, U8aBitLength } from '../types';
|
|
2
|
+
import { Raw } from '../native/Raw';
|
|
3
|
+
/**
|
|
4
|
+
* @name U8aFixed
|
|
5
|
+
* @description
|
|
6
|
+
* A U8a that manages a a sequence of bytes up to the specified bitLength. Not meant
|
|
7
|
+
* to be used directly, rather is should be subclassed with the specific lengths.
|
|
8
|
+
*/
|
|
9
|
+
export declare class U8aFixed extends Raw {
|
|
10
|
+
constructor(registry: CodecRegistry, value?: AnyU8a, bitLength?: U8aBitLength);
|
|
11
|
+
static with(bitLength: U8aBitLength, typeName?: string): CodecClass<U8aFixed>;
|
|
12
|
+
/**
|
|
13
|
+
* @description Returns the base runtime type name for this instance
|
|
14
|
+
*/
|
|
15
|
+
toRawType(): string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { assert, u8aToU8a } from '@polkadot/util';
|
|
4
|
+
import { Raw } from "../native/Raw.js";
|
|
5
|
+
/** @internal */
|
|
6
|
+
|
|
7
|
+
function decodeU8aFixed(value, bitLength) {
|
|
8
|
+
const u8a = u8aToU8a(value);
|
|
9
|
+
const byteLength = bitLength / 8;
|
|
10
|
+
|
|
11
|
+
if (!u8a.length) {
|
|
12
|
+
return [new Uint8Array(byteLength), 0];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
assert(u8a.length >= byteLength, () => `Expected at least ${byteLength} bytes (${bitLength} bits), found ${u8a.length} bytes`);
|
|
16
|
+
return [u8a.subarray(0, byteLength), byteLength];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @name U8aFixed
|
|
20
|
+
* @description
|
|
21
|
+
* A U8a that manages a a sequence of bytes up to the specified bitLength. Not meant
|
|
22
|
+
* to be used directly, rather is should be subclassed with the specific lengths.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
export class U8aFixed extends Raw {
|
|
27
|
+
constructor(registry, value = new Uint8Array(), bitLength = 256) {
|
|
28
|
+
const [u8a, decodedLength] = decodeU8aFixed(value, bitLength);
|
|
29
|
+
super(registry, u8a, decodedLength);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static with(bitLength, typeName) {
|
|
33
|
+
return class extends U8aFixed {
|
|
34
|
+
constructor(registry, value) {
|
|
35
|
+
super(registry, value, bitLength);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
toRawType() {
|
|
39
|
+
return typeName || super.toRawType();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @description Returns the base runtime type name for this instance
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
toRawType() {
|
|
50
|
+
return `[u8;${this.length}]`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
}
|