@polkadot/types-create 9.14.2 → 10.0.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/bundle.js +4 -7
- package/cjs/bundle.js +9 -46
- package/cjs/create/class.js +129 -172
- package/cjs/create/index.js +4 -26
- package/cjs/create/type.js +60 -75
- package/cjs/detectOther.js +3 -10
- package/cjs/detectPackage.js +6 -11
- package/cjs/index.js +3 -15
- package/cjs/packageInfo.js +2 -16
- package/cjs/types/augmentRegistry.js +1 -1
- package/cjs/types/index.js +4 -26
- package/cjs/types/lookup.js +2 -1
- package/cjs/types/types.js +26 -32
- package/cjs/util/encodeTypes.js +116 -199
- package/cjs/util/getTypeDef.js +166 -190
- package/cjs/util/index.js +6 -48
- package/cjs/util/typeSplit.js +57 -72
- package/cjs/util/xcm.js +7 -16
- package/create/class.js +121 -153
- package/create/index.js +2 -5
- package/create/type.js +52 -61
- package/detectOther.js +0 -3
- package/detectPackage.js +2 -7
- package/index.js +2 -5
- package/package.json +8 -5
- package/packageInfo.js +1 -11
- package/types/augmentRegistry.js +0 -5
- package/types/index.js +3 -6
- package/types/types.js +24 -27
- package/util/encodeTypes.js +108 -152
- package/util/getTypeDef.js +159 -165
- package/util/index.js +4 -7
- package/util/typeSplit.js +53 -66
- package/util/xcm.js +1 -6
package/cjs/util/getTypeDef.js
CHANGED
|
@@ -1,220 +1,196 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _util = require("@polkadot/util");
|
|
9
|
-
var _types = require("../types");
|
|
10
|
-
var _typeSplit = require("./typeSplit");
|
|
11
|
-
// Copyright 2017-2023 @polkadot/types-create authors & contributors
|
|
12
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
13
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTypeDef = void 0;
|
|
4
|
+
const types_codec_1 = require("@polkadot/types-codec");
|
|
5
|
+
const util_1 = require("@polkadot/util");
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
const typeSplit_1 = require("./typeSplit");
|
|
14
8
|
const KNOWN_INTERNALS = ['_alias', '_fallback'];
|
|
15
9
|
function getTypeString(typeOrObj) {
|
|
16
|
-
|
|
10
|
+
return (0, util_1.isString)(typeOrObj)
|
|
11
|
+
? typeOrObj.toString()
|
|
12
|
+
: JSON.stringify(typeOrObj);
|
|
17
13
|
}
|
|
18
14
|
function isRustEnum(details) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
const values = Object.values(details);
|
|
16
|
+
if (values.some((v) => (0, util_1.isNumber)(v))) {
|
|
17
|
+
if (!values.every((v) => (0, util_1.isNumber)(v) && v >= 0 && v <= 255)) {
|
|
18
|
+
throw new Error('Invalid number-indexed enum definition');
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
23
21
|
}
|
|
24
|
-
return
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
22
|
+
return true;
|
|
27
23
|
}
|
|
28
|
-
|
|
29
|
-
// decode an enum of either of the following forms
|
|
30
|
-
// { _enum: ['A', 'B', 'C'] }
|
|
31
|
-
// { _enum: { A: AccountId, B: Balance, C: u32 } }
|
|
32
|
-
// { _enum: { A: 1, B: 2 } }
|
|
33
24
|
function _decodeEnum(value, details, count, fallbackType) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
name
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
25
|
+
value.info = types_1.TypeDefInfo.Enum;
|
|
26
|
+
value.fallbackType = fallbackType;
|
|
27
|
+
// not as pretty, but remain compatible with oo7 for both struct and Array types
|
|
28
|
+
if (Array.isArray(details)) {
|
|
29
|
+
value.sub = details.map((name, index) => ({
|
|
30
|
+
index,
|
|
31
|
+
info: types_1.TypeDefInfo.Plain,
|
|
32
|
+
name,
|
|
33
|
+
type: 'Null'
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
else if (isRustEnum(details)) {
|
|
37
|
+
value.sub = Object.entries(details).map(([name, typeOrObj], index) => (0, util_1.objectSpread)({}, getTypeDef(getTypeString(typeOrObj || 'Null'), { name }, count), { index }));
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
value.sub = Object.entries(details).map(([name, index]) => ({
|
|
41
|
+
index,
|
|
42
|
+
info: types_1.TypeDefInfo.Plain,
|
|
43
|
+
name,
|
|
44
|
+
type: 'Null'
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
function _decodeSet(value, details, fallbackType) {
|
|
50
|
+
value.info = types_1.TypeDefInfo.Set;
|
|
51
|
+
value.fallbackType = fallbackType;
|
|
52
|
+
value.length = details._bitLength;
|
|
53
|
+
value.sub = Object
|
|
54
|
+
.entries(details)
|
|
55
|
+
.filter(([name]) => !name.startsWith('_'))
|
|
56
|
+
.map(([name, index]) => ({
|
|
58
57
|
index,
|
|
59
|
-
info:
|
|
58
|
+
info: types_1.TypeDefInfo.Plain,
|
|
60
59
|
name,
|
|
61
60
|
type: 'Null'
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
return value;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// decode a set of the form
|
|
69
|
-
// { _set: { A: 0b0001, B: 0b0010, C: 0b0100 } }
|
|
70
|
-
function _decodeSet(value, details, fallbackType) {
|
|
71
|
-
value.info = _types.TypeDefInfo.Set;
|
|
72
|
-
value.fallbackType = fallbackType;
|
|
73
|
-
value.length = details._bitLength;
|
|
74
|
-
value.sub = Object.entries(details).filter(_ref3 => {
|
|
75
|
-
let [name] = _ref3;
|
|
76
|
-
return !name.startsWith('_');
|
|
77
|
-
}).map(_ref4 => {
|
|
78
|
-
let [name, index] = _ref4;
|
|
79
|
-
return {
|
|
80
|
-
index,
|
|
81
|
-
info: _types.TypeDefInfo.Plain,
|
|
82
|
-
name,
|
|
83
|
-
type: 'Null'
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
return value;
|
|
61
|
+
}));
|
|
62
|
+
return value;
|
|
87
63
|
}
|
|
88
|
-
|
|
89
|
-
// decode a struct, set or enum
|
|
90
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
91
64
|
function _decodeStruct(value, type, _, count) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
65
|
+
const parsed = JSON.parse(type);
|
|
66
|
+
const keys = Object.keys(parsed);
|
|
67
|
+
if (keys.includes('_enum')) {
|
|
68
|
+
return _decodeEnum(value, parsed._enum, count, parsed._fallback);
|
|
69
|
+
}
|
|
70
|
+
else if (keys.includes('_set')) {
|
|
71
|
+
return _decodeSet(value, parsed._set, parsed._fallback);
|
|
72
|
+
}
|
|
73
|
+
value.alias = parsed._alias
|
|
74
|
+
? new Map(Object.entries(parsed._alias))
|
|
75
|
+
: undefined;
|
|
76
|
+
value.fallbackType = parsed._fallback;
|
|
77
|
+
value.sub = keys
|
|
78
|
+
.filter((name) => !KNOWN_INTERNALS.includes(name))
|
|
79
|
+
.map((name) => getTypeDef(getTypeString(parsed[name]), { name }, count));
|
|
80
|
+
return value;
|
|
105
81
|
}
|
|
106
|
-
|
|
107
|
-
// decode a fixed vector, e.g. [u8;32]
|
|
108
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
109
82
|
function _decodeFixedVec(value, type, _, count) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
83
|
+
const max = type.length - 1;
|
|
84
|
+
let index = -1;
|
|
85
|
+
let inner = 0;
|
|
86
|
+
for (let i = 1; (i < max) && (index === -1); i++) {
|
|
87
|
+
switch (type[i]) {
|
|
88
|
+
case ';': {
|
|
89
|
+
if (inner === 0) {
|
|
90
|
+
index = i;
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case '[':
|
|
95
|
+
case '(':
|
|
96
|
+
case '<':
|
|
97
|
+
inner++;
|
|
98
|
+
break;
|
|
99
|
+
case ']':
|
|
100
|
+
case ')':
|
|
101
|
+
case '>':
|
|
102
|
+
inner--;
|
|
103
|
+
break;
|
|
121
104
|
}
|
|
122
|
-
case '[':
|
|
123
|
-
case '(':
|
|
124
|
-
case '<':
|
|
125
|
-
inner++;
|
|
126
|
-
break;
|
|
127
|
-
case ']':
|
|
128
|
-
case ')':
|
|
129
|
-
case '>':
|
|
130
|
-
inner--;
|
|
131
|
-
break;
|
|
132
105
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return value;
|
|
106
|
+
if (index === -1) {
|
|
107
|
+
throw new Error(`${type}: Unable to extract location of ';'`);
|
|
108
|
+
}
|
|
109
|
+
const vecType = type.substring(1, index);
|
|
110
|
+
const [strLength, displayName] = type.substring(index + 1, max).split(';');
|
|
111
|
+
const length = parseInt(strLength.trim(), 10);
|
|
112
|
+
if (length > 2048) {
|
|
113
|
+
throw new Error(`${type}: Only support for [Type; <length>], where length <= 2048`);
|
|
114
|
+
}
|
|
115
|
+
value.displayName = displayName;
|
|
116
|
+
value.length = length;
|
|
117
|
+
value.sub = getTypeDef(vecType, {}, count);
|
|
118
|
+
return value;
|
|
147
119
|
}
|
|
148
|
-
|
|
149
|
-
// decode a tuple
|
|
150
120
|
function _decodeTuple(value, _, subType, count) {
|
|
151
|
-
|
|
152
|
-
|
|
121
|
+
value.sub = subType.length === 0
|
|
122
|
+
? []
|
|
123
|
+
: (0, typeSplit_1.typeSplit)(subType).map((inner) => getTypeDef(inner, {}, count));
|
|
124
|
+
return value;
|
|
153
125
|
}
|
|
154
|
-
|
|
155
|
-
// decode a Int/UInt<bitLength[, name]>
|
|
156
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
157
126
|
function _decodeAnyInt(value, type, _, clazz) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
127
|
+
const [strLength, displayName] = type.substring(clazz.length + 1, type.length - 1).split(',');
|
|
128
|
+
const length = parseInt(strLength.trim(), 10);
|
|
129
|
+
if ((length > 8192) || (length % 8)) {
|
|
130
|
+
throw new Error(`${type}: Only support for ${clazz}<bitLength>, where length <= 8192 and a power of 8, found ${length}`);
|
|
131
|
+
}
|
|
132
|
+
value.displayName = displayName;
|
|
133
|
+
value.length = length;
|
|
134
|
+
return value;
|
|
166
135
|
}
|
|
167
136
|
function _decodeInt(value, type, subType) {
|
|
168
|
-
|
|
137
|
+
return _decodeAnyInt(value, type, subType, 'Int');
|
|
169
138
|
}
|
|
170
139
|
function _decodeUInt(value, type, subType) {
|
|
171
|
-
|
|
140
|
+
return _decodeAnyInt(value, type, subType, 'UInt');
|
|
172
141
|
}
|
|
173
|
-
|
|
174
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
175
142
|
function _decodeDoNotConstruct(value, type, _) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
143
|
+
const NAME_LENGTH = 'DoNotConstruct'.length;
|
|
144
|
+
value.displayName = type.substring(NAME_LENGTH + 1, type.length - 1);
|
|
145
|
+
return value;
|
|
179
146
|
}
|
|
180
|
-
function hasWrapper(type,
|
|
181
|
-
|
|
182
|
-
return type.substring(0, start.length) === start && type.slice(-1 * end.length) === end;
|
|
147
|
+
function hasWrapper(type, [start, end]) {
|
|
148
|
+
return (type.substring(0, start.length) === start) && (type.slice(-1 * end.length) === end);
|
|
183
149
|
}
|
|
184
|
-
const nestedExtraction = [
|
|
185
|
-
|
|
186
|
-
['
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
150
|
+
const nestedExtraction = [
|
|
151
|
+
['[', ']', types_1.TypeDefInfo.VecFixed, _decodeFixedVec],
|
|
152
|
+
['{', '}', types_1.TypeDefInfo.Struct, _decodeStruct],
|
|
153
|
+
['(', ')', types_1.TypeDefInfo.Tuple, _decodeTuple],
|
|
154
|
+
// the inner for these are the same as tuple, multiple values
|
|
155
|
+
['BTreeMap<', '>', types_1.TypeDefInfo.BTreeMap, _decodeTuple],
|
|
156
|
+
['HashMap<', '>', types_1.TypeDefInfo.HashMap, _decodeTuple],
|
|
157
|
+
['Int<', '>', types_1.TypeDefInfo.Int, _decodeInt],
|
|
158
|
+
['Result<', '>', types_1.TypeDefInfo.Result, _decodeTuple],
|
|
159
|
+
['UInt<', '>', types_1.TypeDefInfo.UInt, _decodeUInt],
|
|
160
|
+
['DoNotConstruct<', '>', types_1.TypeDefInfo.DoNotConstruct, _decodeDoNotConstruct]
|
|
161
|
+
];
|
|
162
|
+
const wrappedExtraction = [
|
|
163
|
+
['BTreeSet<', '>', types_1.TypeDefInfo.BTreeSet],
|
|
164
|
+
['Compact<', '>', types_1.TypeDefInfo.Compact],
|
|
165
|
+
['Linkage<', '>', types_1.TypeDefInfo.Linkage],
|
|
166
|
+
['Opaque<', '>', types_1.TypeDefInfo.WrapperOpaque],
|
|
167
|
+
['Option<', '>', types_1.TypeDefInfo.Option],
|
|
168
|
+
['Range<', '>', types_1.TypeDefInfo.Range],
|
|
169
|
+
['RangeInclusive<', '>', types_1.TypeDefInfo.RangeInclusive],
|
|
170
|
+
['Vec<', '>', types_1.TypeDefInfo.Vec],
|
|
171
|
+
['WrapperKeepOpaque<', '>', types_1.TypeDefInfo.WrapperKeepOpaque],
|
|
172
|
+
['WrapperOpaque<', '>', types_1.TypeDefInfo.WrapperOpaque]
|
|
173
|
+
];
|
|
174
|
+
function extractSubType(type, [start, end]) {
|
|
175
|
+
return type.substring(start.length, type.length - end.length);
|
|
176
|
+
}
|
|
177
|
+
function getTypeDef(_type, { displayName, name } = {}, count = 0) {
|
|
178
|
+
// create the type via Type, allowing types to be sanitized
|
|
179
|
+
const type = (0, types_codec_1.sanitize)(_type);
|
|
180
|
+
const value = { displayName, info: types_1.TypeDefInfo.Plain, name, type };
|
|
181
|
+
if (++count > 64) {
|
|
182
|
+
throw new Error('getTypeDef: Maximum nested limit reached');
|
|
183
|
+
}
|
|
184
|
+
const nested = nestedExtraction.find((nested) => hasWrapper(type, nested));
|
|
185
|
+
if (nested) {
|
|
186
|
+
value.info = nested[2];
|
|
187
|
+
return nested[3](value, type, extractSubType(type, nested), count);
|
|
188
|
+
}
|
|
189
|
+
const wrapped = wrappedExtraction.find((wrapped) => hasWrapper(type, wrapped));
|
|
190
|
+
if (wrapped) {
|
|
191
|
+
value.info = wrapped[2];
|
|
192
|
+
value.sub = getTypeDef(extractSubType(type, wrapped), {}, count);
|
|
193
|
+
}
|
|
194
|
+
return value;
|
|
191
195
|
}
|
|
192
|
-
|
|
193
|
-
let {
|
|
194
|
-
displayName,
|
|
195
|
-
name
|
|
196
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
197
|
-
let count = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
198
|
-
// create the type via Type, allowing types to be sanitized
|
|
199
|
-
const type = (0, _typesCodec.sanitize)(_type);
|
|
200
|
-
const value = {
|
|
201
|
-
displayName,
|
|
202
|
-
info: _types.TypeDefInfo.Plain,
|
|
203
|
-
name,
|
|
204
|
-
type
|
|
205
|
-
};
|
|
206
|
-
if (++count > 64) {
|
|
207
|
-
throw new Error('getTypeDef: Maximum nested limit reached');
|
|
208
|
-
}
|
|
209
|
-
const nested = nestedExtraction.find(nested => hasWrapper(type, nested));
|
|
210
|
-
if (nested) {
|
|
211
|
-
value.info = nested[2];
|
|
212
|
-
return nested[3](value, type, extractSubType(type, nested), count);
|
|
213
|
-
}
|
|
214
|
-
const wrapped = wrappedExtraction.find(wrapped => hasWrapper(type, wrapped));
|
|
215
|
-
if (wrapped) {
|
|
216
|
-
value.info = wrapped[2];
|
|
217
|
-
value.sub = getTypeDef(extractSubType(type, wrapped), {}, count);
|
|
218
|
-
}
|
|
219
|
-
return value;
|
|
220
|
-
}
|
|
196
|
+
exports.getTypeDef = getTypeDef;
|
package/cjs/util/index.js
CHANGED
|
@@ -1,49 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _encodeTypes[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _encodeTypes[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _getTypeDef = require("./getTypeDef");
|
|
18
|
-
Object.keys(_getTypeDef).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _getTypeDef[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _getTypeDef[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _typeSplit = require("./typeSplit");
|
|
29
|
-
Object.keys(_typeSplit).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _typeSplit[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _typeSplit[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
var _xcm = require("./xcm");
|
|
40
|
-
Object.keys(_xcm).forEach(function (key) {
|
|
41
|
-
if (key === "default" || key === "__esModule") return;
|
|
42
|
-
if (key in exports && exports[key] === _xcm[key]) return;
|
|
43
|
-
Object.defineProperty(exports, key, {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function () {
|
|
46
|
-
return _xcm[key];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./encodeTypes"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./getTypeDef"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./typeSplit"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./xcm"), exports);
|
package/cjs/util/typeSplit.js
CHANGED
|
@@ -1,76 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.typeSplit = typeSplit;
|
|
7
|
-
// Copyright 2017-2023 @polkadot/types-create authors & contributors
|
|
8
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
-
|
|
10
|
-
// safely split a string on ', ' while taking care of any nested occurences
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.typeSplit = void 0;
|
|
11
4
|
function typeSplit(type) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
5
|
+
const result = [];
|
|
6
|
+
// these are the depths of the various tokens: <, [, {, (
|
|
7
|
+
let c = 0;
|
|
8
|
+
let f = 0;
|
|
9
|
+
let s = 0;
|
|
10
|
+
let t = 0;
|
|
11
|
+
// current start position
|
|
12
|
+
let start = 0;
|
|
13
|
+
for (let i = 0; i < type.length; i++) {
|
|
14
|
+
switch (type[i]) {
|
|
15
|
+
// if we are not nested, add the type
|
|
16
|
+
case ',': {
|
|
17
|
+
if (!(c || f || s || t)) {
|
|
18
|
+
result.push(type.substring(start, i).trim());
|
|
19
|
+
start = i + 1;
|
|
20
|
+
}
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
// adjust compact/vec (and friends) depth
|
|
24
|
+
case '<':
|
|
25
|
+
c++;
|
|
26
|
+
break;
|
|
27
|
+
case '>':
|
|
28
|
+
c--;
|
|
29
|
+
break;
|
|
30
|
+
// adjust fixed vec depths
|
|
31
|
+
case '[':
|
|
32
|
+
f++;
|
|
33
|
+
break;
|
|
34
|
+
case ']':
|
|
35
|
+
f--;
|
|
36
|
+
break;
|
|
37
|
+
// adjust struct depth
|
|
38
|
+
case '{':
|
|
39
|
+
s++;
|
|
40
|
+
break;
|
|
41
|
+
case '}':
|
|
42
|
+
s--;
|
|
43
|
+
break;
|
|
44
|
+
// adjust tuple depth
|
|
45
|
+
case '(':
|
|
46
|
+
t++;
|
|
47
|
+
break;
|
|
48
|
+
case ')':
|
|
49
|
+
t--;
|
|
50
|
+
break;
|
|
32
51
|
}
|
|
33
|
-
|
|
34
|
-
// adjust compact/vec (and friends) depth
|
|
35
|
-
case '<':
|
|
36
|
-
c++;
|
|
37
|
-
break;
|
|
38
|
-
case '>':
|
|
39
|
-
c--;
|
|
40
|
-
break;
|
|
41
|
-
|
|
42
|
-
// adjust fixed vec depths
|
|
43
|
-
case '[':
|
|
44
|
-
f++;
|
|
45
|
-
break;
|
|
46
|
-
case ']':
|
|
47
|
-
f--;
|
|
48
|
-
break;
|
|
49
|
-
|
|
50
|
-
// adjust struct depth
|
|
51
|
-
case '{':
|
|
52
|
-
s++;
|
|
53
|
-
break;
|
|
54
|
-
case '}':
|
|
55
|
-
s--;
|
|
56
|
-
break;
|
|
57
|
-
|
|
58
|
-
// adjust tuple depth
|
|
59
|
-
case '(':
|
|
60
|
-
t++;
|
|
61
|
-
break;
|
|
62
|
-
case ')':
|
|
63
|
-
t--;
|
|
64
|
-
break;
|
|
65
52
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return result;
|
|
76
|
-
}
|
|
53
|
+
// ensure we have all the terminators taken care of
|
|
54
|
+
if (c || f || s || t) {
|
|
55
|
+
throw new Error(`Invalid definition (missing terminators) found in ${type}`);
|
|
56
|
+
}
|
|
57
|
+
// the final leg of the journey
|
|
58
|
+
result.push(type.substring(start, type.length).trim());
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
exports.typeSplit = typeSplit;
|
package/cjs/util/xcm.js
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.XCM_MAPPINGS = void 0;
|
|
7
|
-
exports.mapXcmTypes = mapXcmTypes;
|
|
8
|
-
var _util = require("@polkadot/util");
|
|
9
|
-
// Copyright 2017-2023 @polkadot/types-create authors & contributors
|
|
10
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
-
|
|
12
|
-
const XCM_MAPPINGS = ['AssetInstance', 'Fungibility', 'Junction', 'Junctions', 'MultiAsset', 'MultiAssetFilter', 'MultiLocation', 'Response', 'WildFungibility', 'WildMultiAsset', 'Xcm', 'XcmError', 'XcmOrder'];
|
|
13
|
-
exports.XCM_MAPPINGS = XCM_MAPPINGS;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapXcmTypes = exports.XCM_MAPPINGS = void 0;
|
|
4
|
+
const util_1 = require("@polkadot/util");
|
|
5
|
+
exports.XCM_MAPPINGS = ['AssetInstance', 'Fungibility', 'Junction', 'Junctions', 'MultiAsset', 'MultiAssetFilter', 'MultiLocation', 'Response', 'WildFungibility', 'WildMultiAsset', 'Xcm', 'XcmError', 'XcmOrder'];
|
|
14
6
|
function mapXcmTypes(version) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
7
|
+
return exports.XCM_MAPPINGS.reduce((all, key) => (0, util_1.objectSpread)(all, { [key]: `${key}${version}` }), {});
|
|
8
|
+
}
|
|
9
|
+
exports.mapXcmTypes = mapXcmTypes;
|