@polkadot-api/view-builder 0.2.2 → 0.3.0
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/dist/esm/index.mjs +2 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/shaped-decoders.mjs +116 -0
- package/dist/esm/shaped-decoders.mjs.map +1 -0
- package/dist/{index.mjs → esm/view-builder.mjs} +22 -161
- package/dist/esm/view-builder.mjs.map +1 -0
- package/dist/esm/with-cache.mjs +19 -0
- package/dist/esm/with-cache.mjs.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +73 -94
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
- package/dist/index.d.mts +0 -171
- package/dist/index.mjs.map +0 -1
- package/dist/min/index.d.ts +0 -171
- package/dist/min/index.js +0 -2
- package/dist/min/index.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,70 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
29
2
|
|
|
30
|
-
|
|
31
|
-
var
|
|
32
|
-
__export(src_exports, {
|
|
33
|
-
getViewBuilder: () => getViewBuilder
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(src_exports);
|
|
3
|
+
var scale = require('@polkadot-api/substrate-bindings');
|
|
4
|
+
var utils = require('@polkadot-api/utils');
|
|
36
5
|
|
|
37
|
-
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
6
|
+
function _interopNamespaceDefault(e) {
|
|
7
|
+
var n = Object.create(null);
|
|
8
|
+
if (e) {
|
|
9
|
+
Object.keys(e).forEach(function (k) {
|
|
10
|
+
if (k !== 'default') {
|
|
11
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return e[k]; }
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
n.default = e;
|
|
20
|
+
return Object.freeze(n);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var scale__namespace = /*#__PURE__*/_interopNamespaceDefault(scale);
|
|
41
24
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var scale = __toESM(require("@polkadot-api/substrate-bindings"));
|
|
45
|
-
var toHex = import_utils.toHex;
|
|
46
|
-
var createInputValueDecoder = (dec, rest) => scale.createDecoder((_bytes) => {
|
|
25
|
+
const toHex = utils.toHex;
|
|
26
|
+
const createInputValueDecoder = (dec, rest) => scale__namespace.createDecoder((_bytes) => {
|
|
47
27
|
const bytes = _bytes;
|
|
48
28
|
const start = bytes.i;
|
|
49
29
|
const value = dec(bytes);
|
|
50
30
|
const input = toHex(new Uint8Array(bytes.buffer.slice(start, bytes.i)));
|
|
51
31
|
return { ...rest, value, input };
|
|
52
32
|
});
|
|
53
|
-
|
|
33
|
+
const primitiveShapedDecoder = (codec, input, rest) => {
|
|
54
34
|
const decoder = createInputValueDecoder(input, { codec, ...rest });
|
|
55
35
|
return Object.assign(decoder, {
|
|
56
36
|
shape: { codec }
|
|
57
37
|
});
|
|
58
38
|
};
|
|
59
|
-
|
|
39
|
+
const complexShapedDecoder = (shape, input, rest) => {
|
|
60
40
|
const decoder = createInputValueDecoder(input, { codec: shape.codec, ...rest });
|
|
61
41
|
return Object.assign(decoder, {
|
|
62
42
|
shape
|
|
63
43
|
});
|
|
64
44
|
};
|
|
65
|
-
|
|
66
|
-
const enhanced =
|
|
67
|
-
|
|
45
|
+
const AccountIdShaped = (ss58Prefix = 42) => {
|
|
46
|
+
const enhanced = scale__namespace.enhanceDecoder(
|
|
47
|
+
scale__namespace.AccountId(ss58Prefix).dec,
|
|
68
48
|
(address) => ({
|
|
69
49
|
address,
|
|
70
50
|
ss58Prefix
|
|
@@ -72,8 +52,8 @@ var AccountIdShaped = (ss58Prefix = 42) => {
|
|
|
72
52
|
);
|
|
73
53
|
return primitiveShapedDecoder("AccountId", enhanced, {});
|
|
74
54
|
};
|
|
75
|
-
|
|
76
|
-
|
|
55
|
+
const BytesArray = (len) => primitiveShapedDecoder("BytesArray", scale__namespace.Hex.dec(len), { len });
|
|
56
|
+
const _primitives = [
|
|
77
57
|
"_void",
|
|
78
58
|
"bool",
|
|
79
59
|
"char",
|
|
@@ -95,44 +75,44 @@ var _primitives = [
|
|
|
95
75
|
"bitSequence",
|
|
96
76
|
"ethAccount"
|
|
97
77
|
];
|
|
98
|
-
|
|
99
|
-
_primitives.map((x) => [x, primitiveShapedDecoder(x,
|
|
78
|
+
const corePrimitives = Object.fromEntries(
|
|
79
|
+
_primitives.map((x) => [x, primitiveShapedDecoder(x, scale__namespace[x].dec)])
|
|
100
80
|
);
|
|
101
|
-
|
|
81
|
+
const primitives = {
|
|
102
82
|
...corePrimitives,
|
|
103
|
-
Bytes: primitiveShapedDecoder("Bytes",
|
|
83
|
+
Bytes: primitiveShapedDecoder("Bytes", scale__namespace.Hex.dec()),
|
|
104
84
|
BytesArray,
|
|
105
85
|
AccountId: AccountIdShaped()
|
|
106
86
|
};
|
|
107
|
-
|
|
87
|
+
const Sequence = (input) => complexShapedDecoder(
|
|
108
88
|
{ codec: "Sequence", shape: input.shape },
|
|
109
|
-
|
|
89
|
+
scale__namespace.Vector.dec(input)
|
|
110
90
|
);
|
|
111
|
-
|
|
91
|
+
const ArrayDec = (input, len) => complexShapedDecoder(
|
|
112
92
|
{ codec: "Array", shape: input.shape, len },
|
|
113
|
-
|
|
93
|
+
scale__namespace.Vector.dec(input, len)
|
|
114
94
|
);
|
|
115
|
-
|
|
95
|
+
const TupleDec = (...input) => complexShapedDecoder(
|
|
116
96
|
{ codec: "Tuple", shape: input.map((x) => x.shape) },
|
|
117
|
-
|
|
97
|
+
scale__namespace.Tuple.dec(...input)
|
|
118
98
|
);
|
|
119
|
-
|
|
120
|
-
{ codec: "Struct", shape:
|
|
121
|
-
|
|
99
|
+
const StructDec = (input) => complexShapedDecoder(
|
|
100
|
+
{ codec: "Struct", shape: utils.mapStringRecord(input, (x) => x.shape) },
|
|
101
|
+
scale__namespace.Struct.dec(input)
|
|
122
102
|
);
|
|
123
|
-
|
|
124
|
-
{ codec: "Enum", shape:
|
|
125
|
-
|
|
103
|
+
const EnumDec = (input, args) => complexShapedDecoder(
|
|
104
|
+
{ codec: "Enum", shape: utils.mapStringRecord(input, (x) => x.shape) },
|
|
105
|
+
scale__namespace.Variant.dec(input, args)
|
|
126
106
|
);
|
|
127
|
-
|
|
107
|
+
const OptionDec = (input) => complexShapedDecoder(
|
|
128
108
|
{ codec: "Option", shape: input.shape },
|
|
129
|
-
|
|
109
|
+
scale__namespace.Option.dec(input)
|
|
130
110
|
);
|
|
131
|
-
|
|
111
|
+
const ResultDec = (ok, ko) => complexShapedDecoder(
|
|
132
112
|
{ codec: "Result", shape: { ok: ok.shape, ko: ko.shape } },
|
|
133
|
-
|
|
113
|
+
scale__namespace.Result.dec(ok, ko)
|
|
134
114
|
);
|
|
135
|
-
|
|
115
|
+
const selfDecoder = (value) => {
|
|
136
116
|
let cache = (x) => {
|
|
137
117
|
const decoder = value();
|
|
138
118
|
const result2 = decoder;
|
|
@@ -143,7 +123,7 @@ var selfDecoder = (value) => {
|
|
|
143
123
|
result.shape = { codec: "_void" };
|
|
144
124
|
return result;
|
|
145
125
|
};
|
|
146
|
-
|
|
126
|
+
const complex = {
|
|
147
127
|
Sequence,
|
|
148
128
|
Array: ArrayDec,
|
|
149
129
|
Tuple: TupleDec,
|
|
@@ -153,8 +133,7 @@ var complex = {
|
|
|
153
133
|
Result: ResultDec
|
|
154
134
|
};
|
|
155
135
|
|
|
156
|
-
|
|
157
|
-
var withCache = (fn, onEnterCircular, onExitCircular) => (input, cache, stack, ...rest) => {
|
|
136
|
+
const withCache = (fn, onEnterCircular, onExitCircular) => (input, cache, stack, ...rest) => {
|
|
158
137
|
const { id } = input;
|
|
159
138
|
if (cache.has(id)) return cache.get(id);
|
|
160
139
|
if (stack.has(id)) {
|
|
@@ -171,29 +150,28 @@ var withCache = (fn, onEnterCircular, onExitCircular) => (input, cache, stack, .
|
|
|
171
150
|
return result;
|
|
172
151
|
};
|
|
173
152
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
var toUnshapedDecoder = (fn) => (...args) => {
|
|
153
|
+
const emptyTuple = complex.Tuple();
|
|
154
|
+
const toUnshapedDecoder = (fn) => (...args) => {
|
|
177
155
|
const value = fn(...args);
|
|
178
156
|
return {
|
|
179
157
|
shape: value.shape,
|
|
180
158
|
decoder: value
|
|
181
159
|
};
|
|
182
160
|
};
|
|
183
|
-
|
|
184
|
-
const decoder =
|
|
161
|
+
const withProp = (input, propName, propValue) => {
|
|
162
|
+
const decoder = scale.enhanceDecoder(input, (x) => ({
|
|
185
163
|
...x,
|
|
186
164
|
[propName]: propValue
|
|
187
165
|
}));
|
|
188
166
|
decoder.shape = input.shape;
|
|
189
167
|
return decoder;
|
|
190
168
|
};
|
|
191
|
-
|
|
169
|
+
const addPath = (fn) => (input, cache, stack, lookupData, ...rest) => {
|
|
192
170
|
const { path } = lookupData[input.id];
|
|
193
171
|
const base = fn(input, cache, stack, lookupData, ...rest);
|
|
194
172
|
return path.length ? withProp(base, "path", path) : base;
|
|
195
173
|
};
|
|
196
|
-
|
|
174
|
+
const _buildShapedDecoder = (input, cache, stack, lookupData, _accountId) => {
|
|
197
175
|
if (input.type === "primitive") return primitives[input.value];
|
|
198
176
|
if (input.type === "void") return primitives._void;
|
|
199
177
|
if (input.type === "AccountId20") return primitives.ethAccount;
|
|
@@ -211,7 +189,7 @@ var _buildShapedDecoder = (input, cache, stack, lookupData, _accountId) => {
|
|
|
211
189
|
};
|
|
212
190
|
const buildTuple = (value, innerDocs) => withProp(complex.Tuple(...value.map(buildNext)), "innerDocs", innerDocs);
|
|
213
191
|
const buildStruct = (value, innerDocs) => withProp(
|
|
214
|
-
complex.Struct(
|
|
192
|
+
complex.Struct(utils.mapStringRecord(value, buildNext)),
|
|
215
193
|
"innerDocs",
|
|
216
194
|
innerDocs
|
|
217
195
|
);
|
|
@@ -240,7 +218,7 @@ var _buildShapedDecoder = (input, cache, stack, lookupData, _accountId) => {
|
|
|
240
218
|
const indexes = Object.values(input.value).map((x) => x.idx);
|
|
241
219
|
const areIndexesSorted = indexes.every((idx, i) => idx === i);
|
|
242
220
|
const withoutDocs = areIndexesSorted ? complex.Enum(inner) : complex.Enum(inner, indexes);
|
|
243
|
-
const withDocs =
|
|
221
|
+
const withDocs = scale.enhanceDecoder(withoutDocs, (val) => {
|
|
244
222
|
const docs = input.innerDocs[val.value.type];
|
|
245
223
|
return {
|
|
246
224
|
...val,
|
|
@@ -250,23 +228,22 @@ var _buildShapedDecoder = (input, cache, stack, lookupData, _accountId) => {
|
|
|
250
228
|
withDocs.shape = withoutDocs.shape;
|
|
251
229
|
return withDocs;
|
|
252
230
|
};
|
|
253
|
-
|
|
254
|
-
|
|
231
|
+
const withPath = addPath(_buildShapedDecoder);
|
|
232
|
+
const buildShapedDecoder = withCache(withPath, selfDecoder, (outter, inner) => {
|
|
255
233
|
inner.shape = outter.shape;
|
|
256
234
|
return outter;
|
|
257
235
|
});
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
const
|
|
236
|
+
const hexStrFromByte = (input) => `0x${input.toString(16).padEnd(2, "0")}`;
|
|
237
|
+
const getViewBuilder = (getLookupEntryDef) => {
|
|
238
|
+
const { metadata } = getLookupEntryDef;
|
|
261
239
|
const cache = /* @__PURE__ */ new Map();
|
|
262
240
|
const getDecoder = (id) => buildShapedDecoder(
|
|
263
241
|
getLookupEntryDef(id),
|
|
264
242
|
cache,
|
|
265
243
|
/* @__PURE__ */ new Set(),
|
|
266
|
-
|
|
244
|
+
metadata.lookup,
|
|
267
245
|
_accountId
|
|
268
246
|
);
|
|
269
|
-
const getLookupEntryDef = (0, import_metadata_builders.getLookupFn)(lookupData);
|
|
270
247
|
let _accountId = primitives.AccountId;
|
|
271
248
|
const prefix = metadata.pallets.find((x) => x.name === "System")?.constants.find((x) => x.name === "SS58Prefix");
|
|
272
249
|
if (prefix) {
|
|
@@ -277,8 +254,8 @@ var getViewBuilder = (metadata) => {
|
|
|
277
254
|
}
|
|
278
255
|
}
|
|
279
256
|
const buildDefinition = toUnshapedDecoder(getDecoder);
|
|
280
|
-
const callDecoder =
|
|
281
|
-
const palletIdx =
|
|
257
|
+
const callDecoder = scale.createDecoder((bytes) => {
|
|
258
|
+
const palletIdx = scale.u8.dec(bytes);
|
|
282
259
|
const palletEntry = metadata.pallets.find((x) => x.index === palletIdx);
|
|
283
260
|
if (!palletEntry) throw new Error("Invalid Pallet");
|
|
284
261
|
const pallet = {
|
|
@@ -313,7 +290,7 @@ var getViewBuilder = (metadata) => {
|
|
|
313
290
|
return entry.type === "tuple" ? complex.Tuple(
|
|
314
291
|
...Object.values(entry.value).map((l) => getDecoder(l.id))
|
|
315
292
|
) : entry.type === "array" ? complex.Array(getDecoder(entry.value.id), entry.len) : complex.Struct(
|
|
316
|
-
|
|
293
|
+
utils.mapObject(
|
|
317
294
|
entry.value,
|
|
318
295
|
(x) => getDecoder(x.id)
|
|
319
296
|
)
|
|
@@ -343,4 +320,6 @@ var getViewBuilder = (metadata) => {
|
|
|
343
320
|
buildConstant
|
|
344
321
|
};
|
|
345
322
|
};
|
|
346
|
-
|
|
323
|
+
|
|
324
|
+
exports.getViewBuilder = getViewBuilder;
|
|
325
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/view-builder.ts","../src/shaped-decoders.ts","../src/with-cache.ts"],"sourcesContent":["export * from \"./types\"\nexport { getViewBuilder } from \"./view-builder\"\n","import { mapObject, mapStringRecord } from \"@polkadot-api/utils\"\nimport {\n Decoder,\n type StringRecord,\n type V15,\n type V14,\n type V14Lookup,\n createDecoder,\n u8,\n HexString,\n enhanceDecoder,\n} from \"@polkadot-api/substrate-bindings\"\nimport type { EnumVar, LookupEntry } from \"@polkadot-api/metadata-builders\"\nimport { getLookupFn } from \"@polkadot-api/metadata-builders\"\nimport {\n primitives,\n complex,\n WithShapeWithoutExtra,\n ShapedDecoder,\n selfDecoder,\n AccountIdShaped,\n WithoutExtra,\n} from \"./shaped-decoders\"\nimport {\n AccountIdDecoded,\n Decoded,\n DecodedCall,\n GetViewBuilder,\n PrimitiveDecoded,\n UnshapedDecoder,\n} from \"./types\"\nimport { withCache } from \"./with-cache\"\n\nconst emptyTuple = complex.Tuple()\n\nconst toUnshapedDecoder =\n <A extends Array<any>>(\n fn: (...args: A) => ShapedDecoder,\n ): ((...args: A) => UnshapedDecoder) =>\n (...args) => {\n const value = fn(...args)\n return {\n shape: value.shape,\n decoder: value as Decoder<Decoded>,\n }\n }\n\ntype WithProp<\n T extends Decoder<any> & { shape: any },\n PropName extends string,\n PropValue,\n> = T extends Decoder<infer D> & { shape: infer S }\n ? Decoder<\n D extends WithoutExtra<PrimitiveDecoded>\n ? PrimitiveDecoded\n : D & { [P in PropName]: PropValue }\n > & { shape: S }\n : T\n\nconst withProp = <PropName extends string, PropValue>(\n input: ShapedDecoder,\n propName: PropName,\n propValue: PropValue,\n): WithProp<ShapedDecoder, PropName, PropValue> => {\n const decoder = enhanceDecoder(input as Decoder<{}>, (x) => ({\n ...x,\n [propName]: propValue,\n })) as WithProp<ShapedDecoder, PropName, PropValue>\n decoder.shape = input.shape\n return decoder\n}\n\nconst addPath =\n <Other extends Array<any>>(\n fn: (\n input: LookupEntry,\n cache: Map<number, ShapedDecoder>,\n stack: Set<number>,\n lookupData: V14Lookup,\n ...rest: Other\n ) => ShapedDecoder,\n ): ((\n input: LookupEntry,\n cache: Map<number, ShapedDecoder>,\n stack: Set<number>,\n lookupData: V14Lookup,\n ...rest: Other\n ) => ShapedDecoder | WithProp<ShapedDecoder, \"path\", string[]>) =>\n (input, cache, stack, lookupData, ...rest) => {\n const { path } = lookupData[input.id]\n const base = fn(input, cache, stack, lookupData, ...rest)\n return path.length ? withProp(base, \"path\", path) : base\n }\n\nconst _buildShapedDecoder = (\n input: LookupEntry,\n cache: Map<number, ShapedDecoder>,\n stack: Set<number>,\n lookupData: V14Lookup,\n _accountId: WithShapeWithoutExtra<AccountIdDecoded>,\n): ShapedDecoder => {\n if (input.type === \"primitive\") return primitives[input.value]\n if (input.type === \"void\") return primitives._void\n if (input.type === \"AccountId20\") return primitives.ethAccount\n if (input.type === \"AccountId32\") return _accountId\n if (input.type === \"compact\")\n return input.isBig || input.isBig === null\n ? primitives.compactBn\n : primitives.compactNumber\n if (input.type === \"bitSequence\") return primitives.bitSequence\n\n if (\n input.type === \"sequence\" &&\n input.value.type === \"primitive\" &&\n input.value.value === \"u8\"\n ) {\n return primitives.Bytes\n }\n\n const buildNext = (nextInput: LookupEntry): ShapedDecoder =>\n buildShapedDecoder(nextInput, cache, stack, lookupData, _accountId)\n\n const buildVector = (inner: LookupEntry, len?: number) => {\n const _inner = buildNext(inner)\n return len ? complex.Array(_inner, len) : complex.Sequence(_inner)\n }\n\n const buildTuple = (value: LookupEntry[], innerDocs: string[][]) =>\n withProp(complex.Tuple(...value.map(buildNext)), \"innerDocs\", innerDocs)\n\n const buildStruct = (\n value: StringRecord<LookupEntry>,\n innerDocs: StringRecord<string[]>,\n ) =>\n withProp(\n complex.Struct(mapStringRecord(value, buildNext)),\n \"innerDocs\",\n innerDocs,\n )\n\n if (input.type === \"array\") {\n // Bytes case\n if (input.value.type === \"primitive\" && input.value.value === \"u8\") {\n return primitives.BytesArray(input.len)\n }\n\n return buildVector(input.value, input.len)\n }\n\n if (input.type === \"sequence\") return buildVector(input.value)\n if (input.type === \"tuple\") return buildTuple(input.value, input.innerDocs)\n if (input.type === \"struct\") return buildStruct(input.value, input.innerDocs)\n if (input.type === \"option\") return complex.Option(buildNext(input.value))\n\n if (input.type === \"result\")\n return complex.Result(buildNext(input.value.ok), buildNext(input.value.ko))\n\n // it has to be an enum by now\n const dependencies = Object.values(input.value).map((v) => {\n if (v.type === \"void\") return primitives._void\n if (v.type === \"lookupEntry\") {\n return buildNext(v.value)\n }\n return v.type === \"tuple\"\n ? buildTuple(v.value, v.innerDocs)\n : v.type === \"array\"\n ? buildVector(v.value, v.len)\n : buildStruct(v.value, v.innerDocs)\n })\n\n const inner = Object.fromEntries(\n Object.keys(input.value).map((key, idx) => [key, dependencies[idx]]),\n ) as StringRecord<ShapedDecoder>\n\n const indexes = Object.values(input.value).map((x) => x.idx)\n const areIndexesSorted = indexes.every((idx, i) => idx === i)\n\n const withoutDocs = areIndexesSorted\n ? complex.Enum(inner)\n : complex.Enum(inner, indexes as any)\n\n const withDocs = enhanceDecoder(withoutDocs, (val) => {\n const docs = input.innerDocs[val.value.type]\n return {\n ...val,\n docs,\n }\n }) as unknown as typeof withoutDocs\n withDocs.shape = withoutDocs.shape\n return withDocs\n}\n\nconst withPath = addPath(_buildShapedDecoder)\nconst buildShapedDecoder = withCache(withPath, selfDecoder, (outter, inner) => {\n inner.shape = outter.shape\n return outter\n})\n\nconst hexStrFromByte = (input: number) =>\n `0x${input.toString(16).padEnd(2, \"0\")}` as HexString\n\nexport const getViewBuilder: GetViewBuilder = (metadata: V15 | V14) => {\n const lookupData = metadata.lookup\n const cache = new Map<number, ShapedDecoder>()\n\n const getDecoder = (id: number) =>\n buildShapedDecoder(\n getLookupEntryDef(id),\n cache,\n new Set(),\n lookupData,\n _accountId,\n )\n\n const getLookupEntryDef = getLookupFn(lookupData)\n\n let _accountId: WithShapeWithoutExtra<AccountIdDecoded> = primitives.AccountId\n\n const prefix = metadata.pallets\n .find((x) => x.name === \"System\")\n ?.constants.find((x) => x.name === \"SS58Prefix\")\n if (prefix) {\n try {\n const prefixVal = getDecoder(prefix.type)(prefix.value).value\n\n if (typeof prefixVal === \"number\") _accountId = AccountIdShaped(prefixVal)\n } catch (_) {}\n }\n\n const buildDefinition = toUnshapedDecoder(getDecoder)\n\n const callDecoder: Decoder<DecodedCall> = createDecoder((bytes) => {\n const palletIdx = u8.dec(bytes)\n\n const palletEntry = metadata.pallets.find((x) => x.index === palletIdx)\n if (!palletEntry) throw new Error(\"Invalid Pallet\")\n\n const pallet = {\n value: {\n name: palletEntry.name,\n idx: palletIdx,\n },\n input: hexStrFromByte(bytes[0]),\n }\n\n const callsDecoder = getDecoder(palletEntry.calls!)\n\n const decoded = callsDecoder(bytes)\n\n if (decoded.codec !== \"Enum\") throw null\n\n const call = {\n value: {\n name: decoded.value.type,\n idx: bytes[1],\n },\n input: hexStrFromByte(bytes[1]),\n docs: (decoded as any).docs as string[],\n }\n\n return {\n pallet,\n call,\n args: { value: decoded.value.value as any, shape: callsDecoder.shape },\n }\n })\n\n const buildEnumEntry = toUnshapedDecoder(\n (\n entry: EnumVar[\"value\"][keyof EnumVar[\"value\"]],\n forceTuple = false,\n ): ShapedDecoder => {\n if (entry.type === \"void\")\n return forceTuple ? emptyTuple : primitives._void\n\n if (entry.type === \"lookupEntry\") return getDecoder(entry.value.id)\n\n return entry.type === \"tuple\"\n ? complex.Tuple(\n ...Object.values(entry.value).map((l) => getDecoder(l.id)),\n )\n : entry.type === \"array\"\n ? complex.Array(getDecoder(entry.value.id), entry.len)\n : complex.Struct(\n mapObject(entry.value, (x) =>\n getDecoder(x.id),\n ) as StringRecord<ShapedDecoder>,\n )\n },\n )\n\n const buildVariant =\n (type: \"errors\" | \"events\" | \"calls\") =>\n (\n pallet: string,\n name: string,\n ): {\n view: UnshapedDecoder\n location: [number, number]\n } => {\n const palletEntry = metadata.pallets.find((x) => x.name === pallet)!\n\n const lookup = getLookupEntryDef(palletEntry[type]!)\n if (lookup.type !== \"enum\") throw null\n\n const event = lookup.value[name]\n\n return {\n location: [palletEntry.index, event.idx],\n view: buildEnumEntry(event, type === \"calls\"),\n }\n }\n\n const buildConstant = (pallet: string, constantName: string) => {\n const storageEntry = metadata.pallets\n .find((x) => x.name === pallet)!\n .constants!.find((s) => s.name === constantName)!\n\n return buildDefinition(storageEntry.type as number)\n }\n\n return {\n buildDefinition,\n callDecoder,\n\n buildEvent: buildVariant(\"events\"),\n buildError: buildVariant(\"errors\"),\n buildCall: buildVariant(\"calls\"),\n buildConstant,\n }\n}\n","import { toHex as _toHex, mapStringRecord } from \"@polkadot-api/utils\"\nimport * as scale from \"@polkadot-api/substrate-bindings\"\nimport type {\n Decoder,\n HexString,\n StringRecord,\n} from \"@polkadot-api/substrate-bindings\"\nimport {\n ArrayDecoded,\n ArrayShape,\n BytesArrayDecoded,\n ComplexDecoded,\n ComplexShape,\n Decoded,\n EnumDecoded,\n EnumShape,\n OptionDecoded,\n OptionShape,\n PrimitiveDecoded,\n ResultDecoded,\n ResultShape,\n SequenceDecoded,\n SequenceShape,\n StructDecoded,\n StructShape,\n TupleDecoded,\n TupleShape,\n} from \"./types\"\n\nconst toHex = _toHex as (input: Uint8Array) => HexString\n\ntype Extras = \"docs\" | \"path\" | \"innerDocs\"\nexport type WithoutExtra<T extends {}> = Omit<T, Extras>\ntype PrimitiveCodec = PrimitiveDecoded[\"codec\"]\ntype ComplexCodec = ComplexDecoded[\"codec\"]\n\nexport type WithShapeWithoutExtra<T extends PrimitiveDecoded> = Decoder<\n WithoutExtra<T>\n> & {\n shape: { codec: T[\"codec\"] }\n}\ntype PrimitiveShapeDecoder = WithShapeWithoutExtra<PrimitiveDecoded>\n\ntype SequenceShapedDecoder = Decoder<WithoutExtra<SequenceDecoded>> & {\n shape: SequenceShape\n}\ntype ArrayShapedDecoder = Decoder<WithoutExtra<ArrayDecoded>> & {\n shape: ArrayShape\n}\ntype TupleShapedDecoder = Decoder<WithoutExtra<TupleDecoded>> & {\n shape: TupleShape\n}\ntype StructShapedDecoder = Decoder<WithoutExtra<StructDecoded>> & {\n shape: StructShape\n}\n\ntype OptionShapedDecoder = Decoder<WithoutExtra<OptionDecoded>> & {\n shape: OptionShape\n}\n\ntype ResultShapedDecoder = Decoder<WithoutExtra<ResultDecoded>> & {\n shape: ResultShape\n}\n\ntype EnumShapedDecoder = Decoder<WithoutExtra<EnumDecoded>> & {\n shape: EnumShape\n}\ntype ComplexShapedDecoder =\n | SequenceShapedDecoder\n | ArrayShapedDecoder\n | TupleShapedDecoder\n | StructShapedDecoder\n | OptionShapedDecoder\n | ResultShapedDecoder\n | EnumShapedDecoder\n\nexport type ShapedDecoder = PrimitiveShapeDecoder | ComplexShapedDecoder\n\ntype PrimitiveDecodedValue<C extends PrimitiveCodec> = (PrimitiveDecoded & {\n codec: C\n})[\"value\"]\ntype PrimitiveDecodedRest<C extends PrimitiveCodec> = Omit<\n PrimitiveDecoded & { codec: C },\n \"value\" | \"input\" | \"codec\" | Extras\n>\n\ntype ComplexDecodedValue<C extends ComplexCodec> = (ComplexDecoded & {\n codec: C\n})[\"value\"]\ntype ComplexDecodedRest<C extends ComplexCodec> = Omit<\n ComplexDecoded & { codec: C },\n \"value\" | \"input\" | \"codec\" | Extras\n>\n\nconst createInputValueDecoder = <T, Rest extends { codec: Decoded[\"codec\"] }>(\n dec: Decoder<T>,\n rest: Rest,\n): Decoder<\n Rest & {\n input: HexString\n value: T\n }\n> =>\n scale.createDecoder((_bytes) => {\n const bytes = _bytes as Uint8Array & { i: number; v: DataView }\n const start = bytes.i\n const value = dec(bytes)\n const input = toHex(new Uint8Array(bytes.buffer.slice(start, bytes.i)))\n return { ...rest, value, input }\n })\n\nconst primitiveShapedDecoder = <C extends PrimitiveCodec>(\n codec: C,\n input: Decoder<PrimitiveDecodedValue<C>>,\n rest?: PrimitiveDecodedRest<C>,\n): WithShapeWithoutExtra<\n PrimitiveDecoded & {\n codec: C\n }\n> => {\n const decoder: Decoder<WithoutExtra<PrimitiveDecoded>> =\n createInputValueDecoder(input, { codec, ...rest })\n\n return Object.assign(decoder, {\n shape: { codec },\n }) as any\n}\n\nconst complexShapedDecoder = <Shape extends ComplexShape>(\n shape: Shape,\n input: Decoder<ComplexDecodedValue<Shape[\"codec\"]>>,\n rest?: ComplexDecodedRest<Shape[\"codec\"]>,\n): Decoder<\n WithoutExtra<\n ComplexDecoded & {\n codec: Shape[\"codec\"]\n }\n >\n> & {\n shape: Shape\n} => {\n const decoder: Decoder<WithoutExtra<ComplexDecoded>> =\n createInputValueDecoder(input, { codec: shape.codec, ...rest })\n\n return Object.assign(decoder, {\n shape,\n })\n}\n\nexport const AccountIdShaped = (ss58Prefix = 42) => {\n const enhanced = scale.enhanceDecoder(\n scale.AccountId(ss58Prefix).dec,\n (address) => ({\n address,\n ss58Prefix,\n }),\n )\n\n return primitiveShapedDecoder(\"AccountId\", enhanced, {})\n}\n\nconst BytesArray = (len: number): WithShapeWithoutExtra<BytesArrayDecoded> =>\n primitiveShapedDecoder(\"BytesArray\", scale.Hex.dec(len), { len })\n\nconst _primitives = [\n \"_void\",\n \"bool\",\n \"char\",\n \"str\",\n \"u8\",\n \"u16\",\n \"u32\",\n \"i8\",\n \"i16\",\n \"i32\",\n \"u64\",\n \"u128\",\n \"u256\",\n \"i64\",\n \"i128\",\n \"i256\",\n \"compactNumber\",\n \"compactBn\",\n \"bitSequence\",\n \"ethAccount\",\n] as const\n\ntype PrimitivesList = typeof _primitives\ntype PrimitivesKeys = PrimitivesList[number]\n\nconst corePrimitives: {\n [P in PrimitivesKeys]: WithShapeWithoutExtra<\n PrimitiveDecoded & {\n codec: P\n }\n >\n} = Object.fromEntries(\n _primitives.map((x) => [x, primitiveShapedDecoder(x, scale[x].dec)]),\n) as any\n\nexport const primitives = {\n ...corePrimitives,\n Bytes: primitiveShapedDecoder(\"Bytes\", scale.Hex.dec()),\n BytesArray,\n AccountId: AccountIdShaped(),\n}\n\nconst Sequence = (input: ShapedDecoder): SequenceShapedDecoder =>\n complexShapedDecoder(\n { codec: \"Sequence\", shape: input.shape },\n scale.Vector.dec(input as any),\n )\n\nconst ArrayDec = (input: ShapedDecoder, len: number): ArrayShapedDecoder =>\n complexShapedDecoder(\n { codec: \"Array\", shape: input.shape, len },\n scale.Vector.dec(input as any, len),\n )\n\nconst TupleDec = (...input: Array<ShapedDecoder>): TupleShapedDecoder =>\n complexShapedDecoder(\n { codec: \"Tuple\", shape: input.map((x) => x.shape) },\n scale.Tuple.dec(...(input as Array<Decoder<any>>)),\n )\n\nconst StructDec = (input: StringRecord<ShapedDecoder>): StructShapedDecoder =>\n complexShapedDecoder(\n { codec: \"Struct\", shape: mapStringRecord(input, (x) => x.shape) },\n scale.Struct.dec(input as {}),\n )\n\nconst EnumDec = (\n input: StringRecord<ShapedDecoder>,\n args?: number[],\n): EnumShapedDecoder =>\n complexShapedDecoder(\n { codec: \"Enum\", shape: mapStringRecord(input, (x) => x.shape) },\n scale.Variant.dec(input as {}, args as any),\n )\n\nexport const OptionDec = (input: ShapedDecoder): OptionShapedDecoder =>\n complexShapedDecoder(\n { codec: \"Option\", shape: input.shape },\n scale.Option.dec(input as any) as any,\n )\n\nexport const ResultDec = (\n ok: ShapedDecoder,\n ko: ShapedDecoder,\n): ResultShapedDecoder =>\n complexShapedDecoder(\n { codec: \"Result\", shape: { ok: ok.shape, ko: ko.shape } },\n scale.Result.dec(ok as Decoder<any>, ko as Decoder<any>) as any,\n )\n\nexport const selfDecoder = (value: () => ShapedDecoder): ShapedDecoder => {\n let cache: Decoder<any> = (x) => {\n const decoder = value()\n const result = decoder\n cache = decoder\n return result(x)\n }\n\n const result = ((x) => cache(x)) as ShapedDecoder\n result.shape = { codec: \"_void\" }\n return result\n}\n\nexport const complex = {\n Sequence,\n Array: ArrayDec,\n Tuple: TupleDec,\n Struct: StructDec,\n Enum: EnumDec,\n Option: OptionDec,\n Result: ResultDec,\n}\n","import { LookupEntry } from \"@polkadot-api/metadata-builders\"\n\ntype FnWithStack<Other extends Array<any>, T> = (\n input: LookupEntry,\n cache: Map<number, T>,\n stack: Set<number>,\n ...rest: Other\n) => T\n\nexport const withCache =\n <Other extends Array<any>, T>(\n fn: FnWithStack<Other, T>,\n onEnterCircular: (\n cacheGetter: () => T,\n circular: LookupEntry,\n ...rest: Other\n ) => T,\n onExitCircular: (\n outter: T,\n inner: T,\n circular: LookupEntry,\n ...rest: Other\n ) => T,\n ): FnWithStack<Other, T> =>\n (input, cache, stack, ...rest) => {\n const { id } = input\n if (cache.has(id)) return cache.get(id)!\n\n if (stack.has(id)) {\n const res = onEnterCircular(() => cache.get(id)!, input, ...rest)\n cache.set(id, res)\n return res\n }\n\n stack.add(id)\n let result = fn(input, cache, stack, ...rest)\n stack.delete(id)\n\n if (cache.has(id))\n result = onExitCircular(result, cache.get(id)!, input, ...rest)\n\n cache.set(id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AM;AAAA,UAAO,CAAC,MACtB,WAAW,EAAE,EAAE;AAAA,QACjB;AAAA,MACF;AAAA,IACR;AAAA,EACF;AAEA,QAAM,eACJ,CAAC,SACD,CACE,QACA,SAIG;AACH,UAAM,cAAc,SAAS,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,MAAM;AAElE,UAAM,SAAS,kBAAkB,YAAY,IAAI,CAAE;AACnD,QAAI,OAAO,SAAS,OAAQ,OAAM;AAElC,UAAM,QAAQ,OAAO,MAAM,IAAI;AAE/B,WAAO;AAAA,MACL,UAAU,CAAC,YAAY,OAAO,MAAM,GAAG;AAAA,MACvC,MAAM,eAAe,OAAO,SAAS,OAAO;AAAA,IAC9C;AAAA,EACF;AAEF,QAAM,gBAAgB,CAAC,QAAgB,iBAAyB;AAC9D,UAAM,eAAe,SAAS,QAC3B,KAAK,CAAC,MAAM,EAAE,SAAS,MAAM,EAC7B,UAAW,KAAK,CAAC,MAAM,EAAE,SAAS,YAAY;AAEjD,WAAO,gBAAgB,aAAa,IAAc;AAAA,EACpD;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IAEA,YAAY,aAAa,QAAQ;AAAA,IACjC,YAAY,aAAa,QAAQ;AAAA,IACjC,WAAW,aAAa,OAAO;AAAA,IAC/B;AAAA,EACF;AACF;","names":["import_utils","_toHex","result","inner"]}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/shaped-decoders.ts","../src/with-cache.ts","../src/view-builder.ts"],"sourcesContent":["import { toHex as _toHex, mapStringRecord } from \"@polkadot-api/utils\"\nimport * as scale from \"@polkadot-api/substrate-bindings\"\nimport type {\n Decoder,\n HexString,\n StringRecord,\n} from \"@polkadot-api/substrate-bindings\"\nimport {\n ArrayDecoded,\n ArrayShape,\n BytesArrayDecoded,\n ComplexDecoded,\n ComplexShape,\n Decoded,\n EnumDecoded,\n EnumShape,\n OptionDecoded,\n OptionShape,\n PrimitiveDecoded,\n ResultDecoded,\n ResultShape,\n SequenceDecoded,\n SequenceShape,\n StructDecoded,\n StructShape,\n TupleDecoded,\n TupleShape,\n} from \"./types\"\n\nconst toHex = _toHex as (input: Uint8Array) => HexString\n\ntype Extras = \"docs\" | \"path\" | \"innerDocs\"\nexport type WithoutExtra<T extends {}> = Omit<T, Extras>\ntype PrimitiveCodec = PrimitiveDecoded[\"codec\"]\ntype ComplexCodec = ComplexDecoded[\"codec\"]\n\nexport type WithShapeWithoutExtra<T extends PrimitiveDecoded> = Decoder<\n WithoutExtra<T>\n> & {\n shape: { codec: T[\"codec\"] }\n}\ntype PrimitiveShapeDecoder = WithShapeWithoutExtra<PrimitiveDecoded>\n\ntype SequenceShapedDecoder = Decoder<WithoutExtra<SequenceDecoded>> & {\n shape: SequenceShape\n}\ntype ArrayShapedDecoder = Decoder<WithoutExtra<ArrayDecoded>> & {\n shape: ArrayShape\n}\ntype TupleShapedDecoder = Decoder<WithoutExtra<TupleDecoded>> & {\n shape: TupleShape\n}\ntype StructShapedDecoder = Decoder<WithoutExtra<StructDecoded>> & {\n shape: StructShape\n}\n\ntype OptionShapedDecoder = Decoder<WithoutExtra<OptionDecoded>> & {\n shape: OptionShape\n}\n\ntype ResultShapedDecoder = Decoder<WithoutExtra<ResultDecoded>> & {\n shape: ResultShape\n}\n\ntype EnumShapedDecoder = Decoder<WithoutExtra<EnumDecoded>> & {\n shape: EnumShape\n}\ntype ComplexShapedDecoder =\n | SequenceShapedDecoder\n | ArrayShapedDecoder\n | TupleShapedDecoder\n | StructShapedDecoder\n | OptionShapedDecoder\n | ResultShapedDecoder\n | EnumShapedDecoder\n\nexport type ShapedDecoder = PrimitiveShapeDecoder | ComplexShapedDecoder\n\ntype PrimitiveDecodedValue<C extends PrimitiveCodec> = (PrimitiveDecoded & {\n codec: C\n})[\"value\"]\ntype PrimitiveDecodedRest<C extends PrimitiveCodec> = Omit<\n PrimitiveDecoded & { codec: C },\n \"value\" | \"input\" | \"codec\" | Extras\n>\n\ntype ComplexDecodedValue<C extends ComplexCodec> = (ComplexDecoded & {\n codec: C\n})[\"value\"]\ntype ComplexDecodedRest<C extends ComplexCodec> = Omit<\n ComplexDecoded & { codec: C },\n \"value\" | \"input\" | \"codec\" | Extras\n>\n\nconst createInputValueDecoder = <T, Rest extends { codec: Decoded[\"codec\"] }>(\n dec: Decoder<T>,\n rest: Rest,\n): Decoder<\n Rest & {\n input: HexString\n value: T\n }\n> =>\n scale.createDecoder((_bytes) => {\n const bytes = _bytes as Uint8Array & { i: number; v: DataView }\n const start = bytes.i\n const value = dec(bytes)\n const input = toHex(new Uint8Array(bytes.buffer.slice(start, bytes.i)))\n return { ...rest, value, input }\n })\n\nconst primitiveShapedDecoder = <C extends PrimitiveCodec>(\n codec: C,\n input: Decoder<PrimitiveDecodedValue<C>>,\n rest?: PrimitiveDecodedRest<C>,\n): WithShapeWithoutExtra<\n PrimitiveDecoded & {\n codec: C\n }\n> => {\n const decoder: Decoder<WithoutExtra<PrimitiveDecoded>> =\n createInputValueDecoder(input, { codec, ...rest })\n\n return Object.assign(decoder, {\n shape: { codec },\n }) as any\n}\n\nconst complexShapedDecoder = <Shape extends ComplexShape>(\n shape: Shape,\n input: Decoder<ComplexDecodedValue<Shape[\"codec\"]>>,\n rest?: ComplexDecodedRest<Shape[\"codec\"]>,\n): Decoder<\n WithoutExtra<\n ComplexDecoded & {\n codec: Shape[\"codec\"]\n }\n >\n> & {\n shape: Shape\n} => {\n const decoder: Decoder<WithoutExtra<ComplexDecoded>> =\n createInputValueDecoder(input, { codec: shape.codec, ...rest })\n\n return Object.assign(decoder, {\n shape,\n })\n}\n\nexport const AccountIdShaped = (ss58Prefix = 42) => {\n const enhanced = scale.enhanceDecoder(\n scale.AccountId(ss58Prefix).dec,\n (address) => ({\n address,\n ss58Prefix,\n }),\n )\n\n return primitiveShapedDecoder(\"AccountId\", enhanced, {})\n}\n\nconst BytesArray = (len: number): WithShapeWithoutExtra<BytesArrayDecoded> =>\n primitiveShapedDecoder(\"BytesArray\", scale.Hex.dec(len), { len })\n\nconst _primitives = [\n \"_void\",\n \"bool\",\n \"char\",\n \"str\",\n \"u8\",\n \"u16\",\n \"u32\",\n \"i8\",\n \"i16\",\n \"i32\",\n \"u64\",\n \"u128\",\n \"u256\",\n \"i64\",\n \"i128\",\n \"i256\",\n \"compactNumber\",\n \"compactBn\",\n \"bitSequence\",\n \"ethAccount\",\n] as const\n\ntype PrimitivesList = typeof _primitives\ntype PrimitivesKeys = PrimitivesList[number]\n\nconst corePrimitives: {\n [P in PrimitivesKeys]: WithShapeWithoutExtra<\n PrimitiveDecoded & {\n codec: P\n }\n >\n} = Object.fromEntries(\n _primitives.map((x) => [x, primitiveShapedDecoder(x, scale[x].dec)]),\n) as any\n\nexport const primitives = {\n ...corePrimitives,\n Bytes: primitiveShapedDecoder(\"Bytes\", scale.Hex.dec()),\n BytesArray,\n AccountId: AccountIdShaped(),\n}\n\nconst Sequence = (input: ShapedDecoder): SequenceShapedDecoder =>\n complexShapedDecoder(\n { codec: \"Sequence\", shape: input.shape },\n scale.Vector.dec(input as any),\n )\n\nconst ArrayDec = (input: ShapedDecoder, len: number): ArrayShapedDecoder =>\n complexShapedDecoder(\n { codec: \"Array\", shape: input.shape, len },\n scale.Vector.dec(input as any, len),\n )\n\nconst TupleDec = (...input: Array<ShapedDecoder>): TupleShapedDecoder =>\n complexShapedDecoder(\n { codec: \"Tuple\", shape: input.map((x) => x.shape) },\n scale.Tuple.dec(...(input as Array<Decoder<any>>)),\n )\n\nconst StructDec = (input: StringRecord<ShapedDecoder>): StructShapedDecoder =>\n complexShapedDecoder(\n { codec: \"Struct\", shape: mapStringRecord(input, (x) => x.shape) },\n scale.Struct.dec(input as {}),\n )\n\nconst EnumDec = (\n input: StringRecord<ShapedDecoder>,\n args?: number[],\n): EnumShapedDecoder =>\n complexShapedDecoder(\n { codec: \"Enum\", shape: mapStringRecord(input, (x) => x.shape) },\n scale.Variant.dec(input as {}, args as any),\n )\n\nexport const OptionDec = (input: ShapedDecoder): OptionShapedDecoder =>\n complexShapedDecoder(\n { codec: \"Option\", shape: input.shape },\n scale.Option.dec(input as any) as any,\n )\n\nexport const ResultDec = (\n ok: ShapedDecoder,\n ko: ShapedDecoder,\n): ResultShapedDecoder =>\n complexShapedDecoder(\n { codec: \"Result\", shape: { ok: ok.shape, ko: ko.shape } },\n scale.Result.dec(ok as Decoder<any>, ko as Decoder<any>) as any,\n )\n\nexport const selfDecoder = (value: () => ShapedDecoder): ShapedDecoder => {\n let cache: Decoder<any> = (x) => {\n const decoder = value()\n const result = decoder\n cache = decoder\n return result(x)\n }\n\n const result = ((x) => cache(x)) as ShapedDecoder\n result.shape = { codec: \"_void\" }\n return result\n}\n\nexport const complex = {\n Sequence,\n Array: ArrayDec,\n Tuple: TupleDec,\n Struct: StructDec,\n Enum: EnumDec,\n Option: OptionDec,\n Result: ResultDec,\n}\n","import { LookupEntry } from \"@polkadot-api/metadata-builders\"\n\ntype FnWithStack<Other extends Array<any>, T> = (\n input: LookupEntry,\n cache: Map<number, T>,\n stack: Set<number>,\n ...rest: Other\n) => T\n\nexport const withCache =\n <Other extends Array<any>, T>(\n fn: FnWithStack<Other, T>,\n onEnterCircular: (\n cacheGetter: () => T,\n circular: LookupEntry,\n ...rest: Other\n ) => T,\n onExitCircular: (\n outter: T,\n inner: T,\n circular: LookupEntry,\n ...rest: Other\n ) => T,\n ): FnWithStack<Other, T> =>\n (input, cache, stack, ...rest) => {\n const { id } = input\n if (cache.has(id)) return cache.get(id)!\n\n if (stack.has(id)) {\n const res = onEnterCircular(() => cache.get(id)!, input, ...rest)\n cache.set(id, res)\n return res\n }\n\n stack.add(id)\n let result = fn(input, cache, stack, ...rest)\n stack.delete(id)\n\n if (cache.has(id))\n result = onExitCircular(result, cache.get(id)!, input, ...rest)\n\n cache.set(id, result)\n return result\n }\n","import type {\n EnumVar,\n LookupEntry,\n MetadataLookup,\n} from \"@polkadot-api/metadata-builders\"\nimport {\n Decoder,\n HexString,\n type StringRecord,\n type V14Lookup,\n createDecoder,\n enhanceDecoder,\n u8,\n} from \"@polkadot-api/substrate-bindings\"\nimport { mapObject, mapStringRecord } from \"@polkadot-api/utils\"\nimport {\n AccountIdShaped,\n ShapedDecoder,\n WithShapeWithoutExtra,\n WithoutExtra,\n complex,\n primitives,\n selfDecoder,\n} from \"./shaped-decoders\"\nimport {\n AccountIdDecoded,\n Decoded,\n DecodedCall,\n GetViewBuilder,\n PrimitiveDecoded,\n UnshapedDecoder,\n} from \"./types\"\nimport { withCache } from \"./with-cache\"\n\nconst emptyTuple = complex.Tuple()\n\nconst toUnshapedDecoder =\n <A extends Array<any>>(\n fn: (...args: A) => ShapedDecoder,\n ): ((...args: A) => UnshapedDecoder) =>\n (...args) => {\n const value = fn(...args)\n return {\n shape: value.shape,\n decoder: value as Decoder<Decoded>,\n }\n }\n\ntype WithProp<\n T extends Decoder<any> & { shape: any },\n PropName extends string,\n PropValue,\n> = T extends Decoder<infer D> & { shape: infer S }\n ? Decoder<\n D extends WithoutExtra<PrimitiveDecoded>\n ? PrimitiveDecoded\n : D & { [P in PropName]: PropValue }\n > & { shape: S }\n : T\n\nconst withProp = <PropName extends string, PropValue>(\n input: ShapedDecoder,\n propName: PropName,\n propValue: PropValue,\n): WithProp<ShapedDecoder, PropName, PropValue> => {\n const decoder = enhanceDecoder(input as Decoder<{}>, (x) => ({\n ...x,\n [propName]: propValue,\n })) as WithProp<ShapedDecoder, PropName, PropValue>\n decoder.shape = input.shape\n return decoder\n}\n\nconst addPath =\n <Other extends Array<any>>(\n fn: (\n input: LookupEntry,\n cache: Map<number, ShapedDecoder>,\n stack: Set<number>,\n lookupData: V14Lookup,\n ...rest: Other\n ) => ShapedDecoder,\n ): ((\n input: LookupEntry,\n cache: Map<number, ShapedDecoder>,\n stack: Set<number>,\n lookupData: V14Lookup,\n ...rest: Other\n ) => ShapedDecoder | WithProp<ShapedDecoder, \"path\", string[]>) =>\n (input, cache, stack, lookupData, ...rest) => {\n const { path } = lookupData[input.id]\n const base = fn(input, cache, stack, lookupData, ...rest)\n return path.length ? withProp(base, \"path\", path) : base\n }\n\nconst _buildShapedDecoder = (\n input: LookupEntry,\n cache: Map<number, ShapedDecoder>,\n stack: Set<number>,\n lookupData: V14Lookup,\n _accountId: WithShapeWithoutExtra<AccountIdDecoded>,\n): ShapedDecoder => {\n if (input.type === \"primitive\") return primitives[input.value]\n if (input.type === \"void\") return primitives._void\n if (input.type === \"AccountId20\") return primitives.ethAccount\n if (input.type === \"AccountId32\") return _accountId\n if (input.type === \"compact\")\n return input.isBig || input.isBig === null\n ? primitives.compactBn\n : primitives.compactNumber\n if (input.type === \"bitSequence\") return primitives.bitSequence\n\n if (\n input.type === \"sequence\" &&\n input.value.type === \"primitive\" &&\n input.value.value === \"u8\"\n ) {\n return primitives.Bytes\n }\n\n const buildNext = (nextInput: LookupEntry): ShapedDecoder =>\n buildShapedDecoder(nextInput, cache, stack, lookupData, _accountId)\n\n const buildVector = (inner: LookupEntry, len?: number) => {\n const _inner = buildNext(inner)\n return len ? complex.Array(_inner, len) : complex.Sequence(_inner)\n }\n\n const buildTuple = (value: LookupEntry[], innerDocs: string[][]) =>\n withProp(complex.Tuple(...value.map(buildNext)), \"innerDocs\", innerDocs)\n\n const buildStruct = (\n value: StringRecord<LookupEntry>,\n innerDocs: StringRecord<string[]>,\n ) =>\n withProp(\n complex.Struct(mapStringRecord(value, buildNext)),\n \"innerDocs\",\n innerDocs,\n )\n\n if (input.type === \"array\") {\n // Bytes case\n if (input.value.type === \"primitive\" && input.value.value === \"u8\") {\n return primitives.BytesArray(input.len)\n }\n\n return buildVector(input.value, input.len)\n }\n\n if (input.type === \"sequence\") return buildVector(input.value)\n if (input.type === \"tuple\") return buildTuple(input.value, input.innerDocs)\n if (input.type === \"struct\") return buildStruct(input.value, input.innerDocs)\n if (input.type === \"option\") return complex.Option(buildNext(input.value))\n\n if (input.type === \"result\")\n return complex.Result(buildNext(input.value.ok), buildNext(input.value.ko))\n\n // it has to be an enum by now\n const dependencies = Object.values(input.value).map((v) => {\n if (v.type === \"void\") return primitives._void\n if (v.type === \"lookupEntry\") {\n return buildNext(v.value)\n }\n return v.type === \"tuple\"\n ? buildTuple(v.value, v.innerDocs)\n : v.type === \"array\"\n ? buildVector(v.value, v.len)\n : buildStruct(v.value, v.innerDocs)\n })\n\n const inner = Object.fromEntries(\n Object.keys(input.value).map((key, idx) => [key, dependencies[idx]]),\n ) as StringRecord<ShapedDecoder>\n\n const indexes = Object.values(input.value).map((x) => x.idx)\n const areIndexesSorted = indexes.every((idx, i) => idx === i)\n\n const withoutDocs = areIndexesSorted\n ? complex.Enum(inner)\n : complex.Enum(inner, indexes as any)\n\n const withDocs = enhanceDecoder(withoutDocs, (val) => {\n const docs = input.innerDocs[val.value.type]\n return {\n ...val,\n docs,\n }\n }) as unknown as typeof withoutDocs\n withDocs.shape = withoutDocs.shape\n return withDocs\n}\n\nconst withPath = addPath(_buildShapedDecoder)\nconst buildShapedDecoder = withCache(withPath, selfDecoder, (outter, inner) => {\n inner.shape = outter.shape\n return outter\n})\n\nconst hexStrFromByte = (input: number) =>\n `0x${input.toString(16).padEnd(2, \"0\")}` as HexString\n\nexport const getViewBuilder: GetViewBuilder = (\n getLookupEntryDef: MetadataLookup,\n) => {\n const { metadata } = getLookupEntryDef\n const cache = new Map<number, ShapedDecoder>()\n\n const getDecoder = (id: number) =>\n buildShapedDecoder(\n getLookupEntryDef(id),\n cache,\n new Set(),\n metadata.lookup,\n _accountId,\n )\n\n let _accountId: WithShapeWithoutExtra<AccountIdDecoded> = primitives.AccountId\n\n const prefix = metadata.pallets\n .find((x) => x.name === \"System\")\n ?.constants.find((x) => x.name === \"SS58Prefix\")\n if (prefix) {\n try {\n const prefixVal = getDecoder(prefix.type)(prefix.value).value\n\n if (typeof prefixVal === \"number\") _accountId = AccountIdShaped(prefixVal)\n } catch (_) {}\n }\n\n const buildDefinition = toUnshapedDecoder(getDecoder)\n\n const callDecoder: Decoder<DecodedCall> = createDecoder((bytes) => {\n const palletIdx = u8.dec(bytes)\n\n const palletEntry = metadata.pallets.find((x) => x.index === palletIdx)\n if (!palletEntry) throw new Error(\"Invalid Pallet\")\n\n const pallet = {\n value: {\n name: palletEntry.name,\n idx: palletIdx,\n },\n input: hexStrFromByte(bytes[0]),\n }\n\n const callsDecoder = getDecoder(palletEntry.calls!)\n\n const decoded = callsDecoder(bytes)\n\n if (decoded.codec !== \"Enum\") throw null\n\n const call = {\n value: {\n name: decoded.value.type,\n idx: bytes[1],\n },\n input: hexStrFromByte(bytes[1]),\n docs: (decoded as any).docs as string[],\n }\n\n return {\n pallet,\n call,\n args: { value: decoded.value.value as any, shape: callsDecoder.shape },\n }\n })\n\n const buildEnumEntry = toUnshapedDecoder(\n (\n entry: EnumVar[\"value\"][keyof EnumVar[\"value\"]],\n forceTuple = false,\n ): ShapedDecoder => {\n if (entry.type === \"void\")\n return forceTuple ? emptyTuple : primitives._void\n\n if (entry.type === \"lookupEntry\") return getDecoder(entry.value.id)\n\n return entry.type === \"tuple\"\n ? complex.Tuple(\n ...Object.values(entry.value).map((l) => getDecoder(l.id)),\n )\n : entry.type === \"array\"\n ? complex.Array(getDecoder(entry.value.id), entry.len)\n : complex.Struct(\n mapObject(entry.value, (x) =>\n getDecoder(x.id),\n ) as StringRecord<ShapedDecoder>,\n )\n },\n )\n\n const buildVariant =\n (type: \"errors\" | \"events\" | \"calls\") =>\n (\n pallet: string,\n name: string,\n ): {\n view: UnshapedDecoder\n location: [number, number]\n } => {\n const palletEntry = metadata.pallets.find((x) => x.name === pallet)!\n\n const lookup = getLookupEntryDef(palletEntry[type]!)\n if (lookup.type !== \"enum\") throw null\n\n const event = lookup.value[name]\n\n return {\n location: [palletEntry.index, event.idx],\n view: buildEnumEntry(event, type === \"calls\"),\n }\n }\n\n const buildConstant = (pallet: string, constantName: string) => {\n const storageEntry = metadata.pallets\n .find((x) => x.name === pallet)!\n .constants!.find((s) => s.name === constantName)!\n\n return buildDefinition(storageEntry.type as number)\n }\n\n return {\n buildDefinition,\n callDecoder,\n\n buildEvent: buildVariant(\"events\"),\n buildError: buildVariant(\"errors\"),\n buildCall: buildVariant(\"calls\"),\n buildConstant,\n }\n}\n"],"names":["_toHex","scale","mapStringRecord","result","enhanceDecoder","inner","createDecoder","u8","mapObject"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAM,KAAQ,GAAAA,WAAA,CAAA;AAiEd,MAAM,0BAA0B,CAC9B,GAAA,EACA,SAOAC,gBAAM,CAAA,aAAA,CAAc,CAAC,MAAW,KAAA;AAC9B,EAAA,MAAM,KAAQ,GAAA,MAAA,CAAA;AACd,EAAA,MAAM,QAAQ,KAAM,CAAA,CAAA,CAAA;AACpB,EAAM,MAAA,KAAA,GAAQ,IAAI,KAAK,CAAA,CAAA;AACvB,EAAM,MAAA,KAAA,GAAQ,KAAM,CAAA,IAAI,UAAW,CAAA,KAAA,CAAM,MAAO,CAAA,KAAA,CAAM,KAAO,EAAA,KAAA,CAAM,CAAC,CAAC,CAAC,CAAA,CAAA;AACtE,EAAA,OAAO,EAAE,GAAG,IAAM,EAAA,KAAA,EAAO,KAAM,EAAA,CAAA;AACjC,CAAC,CAAA,CAAA;AAEH,MAAM,sBAAyB,GAAA,CAC7B,KACA,EAAA,KAAA,EACA,IAKG,KAAA;AACH,EAAA,MAAM,UACJ,uBAAwB,CAAA,KAAA,EAAO,EAAE,KAAO,EAAA,GAAG,MAAM,CAAA,CAAA;AAEnD,EAAO,OAAA,MAAA,CAAO,OAAO,OAAS,EAAA;AAAA,IAC5B,KAAA,EAAO,EAAE,KAAM,EAAA;AAAA,GAChB,CAAA,CAAA;AACH,CAAA,CAAA;AAEA,MAAM,oBAAuB,GAAA,CAC3B,KACA,EAAA,KAAA,EACA,IASG,KAAA;AACH,EAAM,MAAA,OAAA,GACJ,wBAAwB,KAAO,EAAA,EAAE,OAAO,KAAM,CAAA,KAAA,EAAO,GAAG,IAAA,EAAM,CAAA,CAAA;AAEhE,EAAO,OAAA,MAAA,CAAO,OAAO,OAAS,EAAA;AAAA,IA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E,CAAA,CAAA;AACnD,IAAI,IAAA,MAAA,CAAO,IAAS,KAAA,MAAA,EAAc,MAAA,IAAA,CAAA;AAElC,IAAM,MAAA,KAAA,GAAQ,MAAO,CAAA,KAAA,CAAM,IAAI,CAAA,CAAA;AAE/B,IAAO,OAAA;AAAA,MACL,QAAU,EAAA,CAAC,WAAY,CAAA,KAAA,EAAO,MAAM,GAAG,CAAA;AAAA,MACvC,IAAM,EAAA,cAAA,CAAe,KAAO,EAAA,IAAA,KAAS,OAAO,CAAA;AAAA,KAC9C,CAAA;AAAA,GACF,CAAA;AAEF,EAAM,MAAA,aAAA,GAAgB,CAAC,MAAA,EAAgB,YAAyB,KAAA;AAC9D,IAAA,MAAM,eAAe,QAAS,CAAA,OAAA,CAC3B,IAAK,CAAA,CAAC,MAAM,CAAE,CAAA,IAAA,KAAS,MAAM,CAAA,CAC7B,UAAW,IAAK,CAAA,CAAC,CAAM,KAAA,CAAA,CAAE,SAAS,YAAY,CAAA,CAAA;AAEjD,IAAO,OAAA,eAAA,CAAgB,aAAa,IAAc,CAAA,CAAA;AAAA,GACpD,CAAA;AAEA,EAAO,OAAA;AAAA,IACL,eAAA;AAAA,IACA,WAAA;AAAA,IAEA,UAAA,EAAY,aAAa,QAAQ,CAAA;AAAA,IACjC,UAAA,EAAY,aAAa,QAAQ,CAAA;AAAA,IACjC,SAAA,EAAW,aAAa,OAAO,CAAA;AAAA,IAC/B,aAAA;AAAA,GACF,CAAA;AACF;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polkadot-api/view-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"author": "Josep M Sobrepere (https://github.com/josepot)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,38 +12,38 @@
|
|
|
12
12
|
".": {
|
|
13
13
|
"node": {
|
|
14
14
|
"production": {
|
|
15
|
-
"import": "./dist/index.mjs",
|
|
15
|
+
"import": "./dist/esm/index.mjs",
|
|
16
16
|
"require": "./dist/min/index.js",
|
|
17
17
|
"default": "./dist/index.js"
|
|
18
18
|
},
|
|
19
|
-
"import": "./dist/index.mjs",
|
|
19
|
+
"import": "./dist/esm/index.mjs",
|
|
20
20
|
"require": "./dist/index.js",
|
|
21
21
|
"default": "./dist/index.js"
|
|
22
22
|
},
|
|
23
|
-
"module": "./dist/index.mjs",
|
|
24
|
-
"import": "./dist/index.mjs",
|
|
23
|
+
"module": "./dist/esm/index.mjs",
|
|
24
|
+
"import": "./dist/esm/index.mjs",
|
|
25
25
|
"require": "./dist/index.js",
|
|
26
26
|
"default": "./dist/index.js"
|
|
27
27
|
},
|
|
28
28
|
"./package.json": "./package.json"
|
|
29
29
|
},
|
|
30
30
|
"main": "./dist/index.js",
|
|
31
|
-
"module": "./dist/index.mjs",
|
|
32
|
-
"browser": "./dist/index.mjs",
|
|
31
|
+
"module": "./dist/esm/index.mjs",
|
|
32
|
+
"browser": "./dist/esm/index.mjs",
|
|
33
33
|
"types": "./dist/index.d.ts",
|
|
34
34
|
"files": [
|
|
35
35
|
"dist"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@polkadot-api/metadata-builders": "0.
|
|
39
|
-
"@polkadot-api/
|
|
40
|
-
"@polkadot-api/
|
|
38
|
+
"@polkadot-api/metadata-builders": "0.4.0",
|
|
39
|
+
"@polkadot-api/utils": "0.1.1",
|
|
40
|
+
"@polkadot-api/substrate-bindings": "0.6.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@polkadot-api/metadata-fixtures": "0.0.0"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
|
-
"build": "tsc --noEmit &&
|
|
46
|
+
"build": "tsc --noEmit && rollup -c ../../rollup.config.js",
|
|
47
47
|
"test": "vitest",
|
|
48
48
|
"lint": "prettier --check \"src/**/*.{js,jsx,ts,tsx,json,md}\"",
|
|
49
49
|
"format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,json,md}\""
|