polkadot-api 0.5.5 → 0.7.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/index.d.mts +292 -68
- package/dist/index.d.ts +292 -68
- package/dist/index.js +620 -462
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +630 -457
- package/dist/index.mjs.map +1 -1
- package/dist/min/index.d.ts +292 -68
- package/dist/min/index.js +1 -1
- package/dist/min/index.js.map +1 -1
- package/package.json +12 -17
package/dist/index.js
CHANGED
|
@@ -3,7 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
6
|
var __export = (target, all) => {
|
|
8
7
|
for (var name in all)
|
|
9
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -17,119 +16,26 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
16
|
return to;
|
|
18
17
|
};
|
|
19
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var __publicField = (obj, key, value) => {
|
|
21
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
-
return value;
|
|
23
|
-
};
|
|
24
19
|
|
|
25
20
|
// src/index.ts
|
|
26
21
|
var src_exports = {};
|
|
27
22
|
__export(src_exports, {
|
|
28
|
-
AccountId: () =>
|
|
29
|
-
Binary: () =>
|
|
30
|
-
Enum: () =>
|
|
31
|
-
|
|
23
|
+
AccountId: () => import_substrate_bindings9.AccountId,
|
|
24
|
+
Binary: () => import_substrate_bindings9.Binary,
|
|
25
|
+
Enum: () => import_substrate_bindings9.Enum,
|
|
26
|
+
FixedSizeBinary: () => import_substrate_bindings9.FixedSizeBinary,
|
|
27
|
+
_Enum: () => import_substrate_bindings9._Enum,
|
|
32
28
|
createClient: () => createClient
|
|
33
29
|
});
|
|
34
30
|
module.exports = __toCommonJS(src_exports);
|
|
35
31
|
|
|
36
32
|
// src/client.ts
|
|
33
|
+
var import_observable_client2 = require("@polkadot-api/observable-client");
|
|
37
34
|
var import_substrate_client = require("@polkadot-api/substrate-client");
|
|
38
|
-
var
|
|
35
|
+
var import_rxjs22 = require("rxjs");
|
|
39
36
|
|
|
40
37
|
// src/constants.ts
|
|
41
|
-
var import_rxjs2 = require("rxjs");
|
|
42
|
-
|
|
43
|
-
// src/runtime.ts
|
|
44
38
|
var import_rxjs = require("rxjs");
|
|
45
|
-
var Runtime = class {
|
|
46
|
-
constructor(ctx, checksums) {
|
|
47
|
-
__publicField(this, "_ctx");
|
|
48
|
-
__publicField(this, "_checksums");
|
|
49
|
-
this._ctx = ctx;
|
|
50
|
-
this._checksums = checksums;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
function getRuntimeContext(runtime) {
|
|
54
|
-
return runtime._ctx;
|
|
55
|
-
}
|
|
56
|
-
function getImportedChecksum(runtime, idx) {
|
|
57
|
-
return runtime._checksums[idx];
|
|
58
|
-
}
|
|
59
|
-
var createRuntime = (ctx, checksums) => new Runtime(ctx, checksums);
|
|
60
|
-
var getRuntimeApi = (checksums, chainHead) => {
|
|
61
|
-
let latestRuntime;
|
|
62
|
-
let resolve = null;
|
|
63
|
-
latestRuntime = new Promise((res) => {
|
|
64
|
-
resolve = res;
|
|
65
|
-
});
|
|
66
|
-
const runtimeWithChecksums$ = (0, import_rxjs.combineLatest)([chainHead.runtime$, checksums]);
|
|
67
|
-
runtimeWithChecksums$.subscribe(([x, checksums2]) => {
|
|
68
|
-
if (x) {
|
|
69
|
-
const runtime = createRuntime(x, checksums2);
|
|
70
|
-
if (resolve) {
|
|
71
|
-
resolve(runtime);
|
|
72
|
-
resolve = null;
|
|
73
|
-
} else {
|
|
74
|
-
latestRuntime = Promise.resolve(runtime);
|
|
75
|
-
}
|
|
76
|
-
} else if (!resolve) {
|
|
77
|
-
latestRuntime = new Promise((res) => {
|
|
78
|
-
resolve = res;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
const result = runtimeWithChecksums$.pipe(
|
|
83
|
-
(0, import_rxjs.filter)(([x]) => Boolean(x)),
|
|
84
|
-
(0, import_rxjs.map)(([x, checksums2]) => createRuntime(x, checksums2))
|
|
85
|
-
);
|
|
86
|
-
result.latest = () => latestRuntime;
|
|
87
|
-
return result;
|
|
88
|
-
};
|
|
89
|
-
var compatibilityHelper = (runtimeApi, checksumIdx) => (getChecksum) => {
|
|
90
|
-
function isCompatibleSync(runtime) {
|
|
91
|
-
const ctx = getRuntimeContext(runtime);
|
|
92
|
-
const checksum = getImportedChecksum(runtime, checksumIdx);
|
|
93
|
-
return getChecksum(ctx) === checksum;
|
|
94
|
-
}
|
|
95
|
-
const isCompatible = (runtime) => {
|
|
96
|
-
if (runtime) {
|
|
97
|
-
return isCompatibleSync(runtime);
|
|
98
|
-
}
|
|
99
|
-
return runtimeApi.latest().then(isCompatibleSync);
|
|
100
|
-
};
|
|
101
|
-
const waitChecksums = async () => {
|
|
102
|
-
const runtime = await runtimeApi.latest();
|
|
103
|
-
return (ctx) => getChecksum(ctx) === getImportedChecksum(runtime, checksumIdx);
|
|
104
|
-
};
|
|
105
|
-
const compatibleRuntime$ = (chainHead, hash, error) => (0, import_rxjs.combineLatest)([chainHead.getRuntimeContext$(hash), waitChecksums()]).pipe(
|
|
106
|
-
(0, import_rxjs.map)(([ctx, isCompatible2]) => {
|
|
107
|
-
if (!isCompatible2(ctx)) {
|
|
108
|
-
throw error();
|
|
109
|
-
}
|
|
110
|
-
return ctx;
|
|
111
|
-
})
|
|
112
|
-
);
|
|
113
|
-
const withCompatibleRuntime = (chainHead, mapper, error) => (source$) => (0, import_rxjs.combineLatest)([
|
|
114
|
-
source$.pipe(chainHead.withRuntime(mapper)),
|
|
115
|
-
waitChecksums()
|
|
116
|
-
]).pipe(
|
|
117
|
-
(0, import_rxjs.map)(([[x, ctx], isCompatible2]) => {
|
|
118
|
-
if (!isCompatible2(ctx)) {
|
|
119
|
-
throw error();
|
|
120
|
-
}
|
|
121
|
-
return [x, ctx];
|
|
122
|
-
})
|
|
123
|
-
);
|
|
124
|
-
return {
|
|
125
|
-
isCompatible,
|
|
126
|
-
waitChecksums,
|
|
127
|
-
withCompatibleRuntime,
|
|
128
|
-
compatibleRuntime$
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
// src/constants.ts
|
|
133
39
|
var createConstantEntry = (palletName, name, chainHead, compatibilityHelper2) => {
|
|
134
40
|
const { isCompatible, compatibleRuntime$ } = compatibilityHelper2(
|
|
135
41
|
(ctx) => ctx.checksumBuilder.buildConstant(palletName, name)
|
|
@@ -150,11 +56,11 @@ var createConstantEntry = (palletName, name, chainHead, compatibilityHelper2) =>
|
|
|
150
56
|
if (runtime) {
|
|
151
57
|
if (!isCompatible(runtime))
|
|
152
58
|
throw checksumError();
|
|
153
|
-
return getValueWithContext(
|
|
59
|
+
return getValueWithContext(runtime._getCtx());
|
|
154
60
|
}
|
|
155
|
-
return (0,
|
|
61
|
+
return (0, import_rxjs.firstValueFrom)(
|
|
156
62
|
compatibleRuntime$(chainHead, null, checksumError).pipe(
|
|
157
|
-
(0,
|
|
63
|
+
(0, import_rxjs.map)(getValueWithContext)
|
|
158
64
|
)
|
|
159
65
|
);
|
|
160
66
|
};
|
|
@@ -165,9 +71,9 @@ var createConstantEntry = (palletName, name, chainHead, compatibilityHelper2) =>
|
|
|
165
71
|
var import_rxjs7 = require("rxjs");
|
|
166
72
|
|
|
167
73
|
// src/utils/shareLatest.ts
|
|
168
|
-
var
|
|
169
|
-
var shareLatest = (0,
|
|
170
|
-
connector: () => new
|
|
74
|
+
var import_rxjs2 = require("rxjs");
|
|
75
|
+
var shareLatest = (0, import_rxjs2.share)({
|
|
76
|
+
connector: () => new import_rxjs2.ReplaySubject(1),
|
|
171
77
|
resetOnError: true,
|
|
172
78
|
resetOnComplete: true,
|
|
173
79
|
resetOnRefCountZero: true
|
|
@@ -175,7 +81,7 @@ var shareLatest = (0, import_rxjs3.share)({
|
|
|
175
81
|
|
|
176
82
|
// src/utils/firstValueFromWithSignal.ts
|
|
177
83
|
var import_utils = require("@polkadot-api/utils");
|
|
178
|
-
var
|
|
84
|
+
var import_rxjs3 = require("rxjs");
|
|
179
85
|
function firstValueFromWithSignal(source, signal) {
|
|
180
86
|
return new Promise((resolve, reject) => {
|
|
181
87
|
let subscription = null;
|
|
@@ -183,7 +89,7 @@ function firstValueFromWithSignal(source, signal) {
|
|
|
183
89
|
const onAbort = signal ? () => {
|
|
184
90
|
subscription?.unsubscribe();
|
|
185
91
|
reject(new import_utils.AbortError());
|
|
186
|
-
} :
|
|
92
|
+
} : import_rxjs3.noop;
|
|
187
93
|
subscription = source.subscribe({
|
|
188
94
|
next: (value) => {
|
|
189
95
|
resolve(value);
|
|
@@ -205,8 +111,8 @@ function firstValueFromWithSignal(source, signal) {
|
|
|
205
111
|
}
|
|
206
112
|
|
|
207
113
|
// src/utils/concatMapEager.ts
|
|
208
|
-
var
|
|
209
|
-
var concatMapEager = (mapper, concurrent = Infinity) => (source$) => new
|
|
114
|
+
var import_rxjs4 = require("rxjs");
|
|
115
|
+
var concatMapEager = (mapper, concurrent = Infinity) => (source$) => new import_rxjs4.Observable((observer) => {
|
|
210
116
|
let topSubscription;
|
|
211
117
|
const queues = /* @__PURE__ */ new Map();
|
|
212
118
|
const innerSubscriptions = /* @__PURE__ */ new Map();
|
|
@@ -263,7 +169,7 @@ var concatMapEager = (mapper, concurrent = Infinity) => (source$) => new import_
|
|
|
263
169
|
const idx = mapperIdx++;
|
|
264
170
|
queues.set(
|
|
265
171
|
idx,
|
|
266
|
-
(0,
|
|
172
|
+
(0, import_rxjs4.defer)(() => mapper(outterValue, idx))
|
|
267
173
|
);
|
|
268
174
|
if (innerSubscriptions.size < concurrent) {
|
|
269
175
|
nextSubscription();
|
|
@@ -287,12 +193,12 @@ var concatMapEager = (mapper, concurrent = Infinity) => (source$) => new import_
|
|
|
287
193
|
});
|
|
288
194
|
|
|
289
195
|
// src/utils/raceMap.ts
|
|
290
|
-
var
|
|
291
|
-
var raceMap = (mapper, concurrent) => (source$) => new
|
|
196
|
+
var import_rxjs5 = require("rxjs");
|
|
197
|
+
var raceMap = (mapper, concurrent) => (source$) => new import_rxjs5.Observable((observer) => {
|
|
292
198
|
let innerSubscriptions = new Array();
|
|
293
199
|
let isOuterDone = false;
|
|
294
200
|
const createSubscription = (value) => {
|
|
295
|
-
const sub = new
|
|
201
|
+
const sub = new import_rxjs5.Subscription();
|
|
296
202
|
innerSubscriptions.push(sub);
|
|
297
203
|
if (innerSubscriptions.length > concurrent) {
|
|
298
204
|
innerSubscriptions[0].unsubscribe();
|
|
@@ -336,6 +242,30 @@ var raceMap = (mapper, concurrent) => (source$) => new import_rxjs6.Observable((
|
|
|
336
242
|
};
|
|
337
243
|
});
|
|
338
244
|
|
|
245
|
+
// src/utils/continue-with.ts
|
|
246
|
+
var import_rxjs6 = require("rxjs");
|
|
247
|
+
var NOTIN = {};
|
|
248
|
+
var continueWith = (mapper) => (source) => new import_rxjs6.Observable((observer) => {
|
|
249
|
+
let latestValue = NOTIN;
|
|
250
|
+
let subscription = source.subscribe({
|
|
251
|
+
next(v) {
|
|
252
|
+
observer.next(latestValue = v);
|
|
253
|
+
},
|
|
254
|
+
error(e) {
|
|
255
|
+
observer.error(e);
|
|
256
|
+
},
|
|
257
|
+
complete() {
|
|
258
|
+
if (latestValue === NOTIN)
|
|
259
|
+
observer.complete();
|
|
260
|
+
else
|
|
261
|
+
subscription = mapper(latestValue).subscribe(observer);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
return () => {
|
|
265
|
+
subscription.unsubscribe();
|
|
266
|
+
};
|
|
267
|
+
});
|
|
268
|
+
|
|
339
269
|
// src/event.ts
|
|
340
270
|
var createEventEntry = (pallet, name, chainHead, compatibilityHelper2) => {
|
|
341
271
|
const { isCompatible, withCompatibleRuntime } = compatibilityHelper2(
|
|
@@ -366,16 +296,105 @@ var createEventEntry = (pallet, name, chainHead, compatibilityHelper2) => {
|
|
|
366
296
|
);
|
|
367
297
|
const watch = (f) => shared$.pipe((0, import_rxjs7.mergeMap)((x) => f ? x.filter((d) => f(d.payload)) : x));
|
|
368
298
|
const pull = () => (0, import_rxjs7.firstValueFrom)(shared$);
|
|
369
|
-
const
|
|
370
|
-
return { watch, pull, filter:
|
|
299
|
+
const filter3 = (events) => events.filter((e) => e.type === pallet && e.value.type === name).map((x) => x.value.value);
|
|
300
|
+
return { watch, pull, filter: filter3, isCompatible };
|
|
371
301
|
};
|
|
372
302
|
|
|
373
|
-
// src/
|
|
374
|
-
var
|
|
303
|
+
// src/runtime.ts
|
|
304
|
+
var import_rxjs8 = require("rxjs");
|
|
305
|
+
var Runtime = class _Runtime {
|
|
306
|
+
constructor(_ctx, _checksums, _descriptors) {
|
|
307
|
+
this._ctx = _ctx;
|
|
308
|
+
this._checksums = _checksums;
|
|
309
|
+
this._descriptors = _descriptors;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* @access package - Internal implementation detail. Do not use.
|
|
313
|
+
*/
|
|
314
|
+
static _create(ctx, checksums, descriptors) {
|
|
315
|
+
return new _Runtime(ctx, checksums, descriptors);
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* @access package - Internal implementation detail. Do not use.
|
|
319
|
+
*/
|
|
320
|
+
_getCtx() {
|
|
321
|
+
return this._ctx;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* @access package - Internal implementation detail. Do not use.
|
|
325
|
+
*/
|
|
326
|
+
_getPalletChecksum(opType, pallet, name) {
|
|
327
|
+
return this._checksums[this._descriptors.pallets[pallet][opType][name]];
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* @access package - Internal implementation detail. Do not use.
|
|
331
|
+
*/
|
|
332
|
+
_getApiChecksum(name, method) {
|
|
333
|
+
return this._checksums[this._descriptors.apis[name][method]];
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
var getRuntimeApi = (checksums, descriptors, chainHead) => {
|
|
337
|
+
const runtimeWithChecksums$ = (0, import_rxjs8.connectable)(
|
|
338
|
+
(0, import_rxjs8.combineLatest)([chainHead.runtime$, checksums, descriptors]).pipe(
|
|
339
|
+
(0, import_rxjs8.map)(
|
|
340
|
+
([x, checksums2, descriptors2]) => x ? Runtime._create(x, checksums2, descriptors2) : null
|
|
341
|
+
)
|
|
342
|
+
),
|
|
343
|
+
{
|
|
344
|
+
connector: () => new import_rxjs8.ReplaySubject(1)
|
|
345
|
+
}
|
|
346
|
+
);
|
|
347
|
+
runtimeWithChecksums$.connect();
|
|
348
|
+
const result = runtimeWithChecksums$.pipe(
|
|
349
|
+
(0, import_rxjs8.filter)((v) => Boolean(v))
|
|
350
|
+
);
|
|
351
|
+
result.latest = () => (0, import_rxjs8.firstValueFrom)(result);
|
|
352
|
+
return result;
|
|
353
|
+
};
|
|
354
|
+
var compatibilityHelper = (runtimeApi, getDescriptorChecksum) => (getChecksum) => {
|
|
355
|
+
function isCompatibleSync(runtime) {
|
|
356
|
+
return getChecksum(runtime._getCtx()) === getDescriptorChecksum(runtime);
|
|
357
|
+
}
|
|
358
|
+
const isCompatible = (runtime) => {
|
|
359
|
+
if (runtime) {
|
|
360
|
+
return isCompatibleSync(runtime);
|
|
361
|
+
}
|
|
362
|
+
return runtimeApi.latest().then(isCompatibleSync);
|
|
363
|
+
};
|
|
364
|
+
const waitChecksums = async () => {
|
|
365
|
+
const runtime = await runtimeApi.latest();
|
|
366
|
+
return (ctx) => getChecksum(ctx) === getDescriptorChecksum(runtime);
|
|
367
|
+
};
|
|
368
|
+
const compatibleRuntime$ = (chainHead, hash, error) => (0, import_rxjs8.combineLatest)([chainHead.getRuntimeContext$(hash), waitChecksums()]).pipe(
|
|
369
|
+
(0, import_rxjs8.map)(([ctx, isCompatible2]) => {
|
|
370
|
+
if (!isCompatible2(ctx)) {
|
|
371
|
+
throw error();
|
|
372
|
+
}
|
|
373
|
+
return ctx;
|
|
374
|
+
})
|
|
375
|
+
);
|
|
376
|
+
const withCompatibleRuntime = (chainHead, mapper, error) => (source$) => (0, import_rxjs8.combineLatest)([
|
|
377
|
+
source$.pipe(chainHead.withRuntime(mapper)),
|
|
378
|
+
waitChecksums()
|
|
379
|
+
]).pipe(
|
|
380
|
+
(0, import_rxjs8.map)(([[x, ctx], isCompatible2]) => {
|
|
381
|
+
if (!isCompatible2(ctx)) {
|
|
382
|
+
throw error();
|
|
383
|
+
}
|
|
384
|
+
return [x, ctx];
|
|
385
|
+
})
|
|
386
|
+
);
|
|
387
|
+
return {
|
|
388
|
+
isCompatible,
|
|
389
|
+
waitChecksums,
|
|
390
|
+
withCompatibleRuntime,
|
|
391
|
+
compatibleRuntime$
|
|
392
|
+
};
|
|
393
|
+
};
|
|
375
394
|
|
|
376
395
|
// src/runtime-call.ts
|
|
377
396
|
var import_utils4 = require("@polkadot-api/utils");
|
|
378
|
-
var
|
|
397
|
+
var import_rxjs9 = require("rxjs");
|
|
379
398
|
var isOptionalArg = (lastArg) => {
|
|
380
399
|
if (typeof lastArg !== "object")
|
|
381
400
|
return false;
|
|
@@ -395,9 +414,9 @@ var createRuntimeCallEntry = (api, method, chainHead, compatibilityHelper2) => {
|
|
|
395
414
|
const { signal, at: _at } = isLastArgOptional ? lastArg : {};
|
|
396
415
|
const at = _at ?? null;
|
|
397
416
|
const result$ = compatibleRuntime$(chainHead, at, checksumError).pipe(
|
|
398
|
-
(0,
|
|
417
|
+
(0, import_rxjs9.mergeMap)((ctx) => {
|
|
399
418
|
const codecs = ctx.dynamicBuilder.buildRuntimeCall(api, method);
|
|
400
|
-
return chainHead.call$(at, callName, (0, import_utils4.toHex)(codecs.args.enc(args))).pipe((0,
|
|
419
|
+
return chainHead.call$(at, callName, (0, import_utils4.toHex)(codecs.args.enc(args))).pipe((0, import_rxjs9.map)(codecs.value.dec));
|
|
401
420
|
})
|
|
402
421
|
);
|
|
403
422
|
return firstValueFromWithSignal(result$, signal);
|
|
@@ -406,7 +425,8 @@ var createRuntimeCallEntry = (api, method, chainHead, compatibilityHelper2) => {
|
|
|
406
425
|
};
|
|
407
426
|
|
|
408
427
|
// src/storage.ts
|
|
409
|
-
var
|
|
428
|
+
var import_rxjs10 = require("rxjs");
|
|
429
|
+
var import_observable_client = require("@polkadot-api/observable-client");
|
|
410
430
|
var isOptionalArg2 = (lastArg) => {
|
|
411
431
|
if (typeof lastArg !== "object")
|
|
412
432
|
return false;
|
|
@@ -415,21 +435,27 @@ var isOptionalArg2 = (lastArg) => {
|
|
|
415
435
|
);
|
|
416
436
|
};
|
|
417
437
|
var createStorageEntry = (pallet, name, chainHead, compatibilityHelper2) => {
|
|
438
|
+
const isSystemNumber = pallet === "System" && name === "Number";
|
|
418
439
|
const { isCompatible, waitChecksums, withCompatibleRuntime } = compatibilityHelper2((ctx) => ctx.checksumBuilder.buildStorage(pallet, name));
|
|
419
440
|
const checksumError = () => new Error(`Incompatible runtime entry Storage(${pallet}.${name})`);
|
|
420
441
|
const invalidArgs = (args) => new Error(`Invalid Arguments calling ${pallet}.${name}(${args})`);
|
|
421
442
|
const watchValue = (...args) => {
|
|
422
|
-
const
|
|
423
|
-
const actualArgs =
|
|
424
|
-
|
|
425
|
-
|
|
443
|
+
const target = args[args.length - 1];
|
|
444
|
+
const actualArgs = target === "best" || target === "finalized" ? args.slice(0, -1) : args;
|
|
445
|
+
if (isSystemNumber)
|
|
446
|
+
return chainHead.bestBlocks$.pipe(
|
|
447
|
+
(0, import_rxjs10.map)((blocks) => blocks.at(target === "best" ? 0 : -1).number),
|
|
448
|
+
(0, import_rxjs10.distinctUntilChanged)()
|
|
449
|
+
);
|
|
450
|
+
return chainHead[target === "best" ? "best$" : "finalized$"].pipe(
|
|
451
|
+
(0, import_rxjs10.debounceTime)(0),
|
|
426
452
|
withCompatibleRuntime(chainHead, (x) => x.hash, checksumError),
|
|
427
453
|
raceMap(([block, ctx]) => {
|
|
428
454
|
const codecs = ctx.dynamicBuilder.buildStorage(pallet, name);
|
|
429
|
-
return chainHead.storage$(block.hash, "value", () => codecs.enc(...actualArgs)).pipe((0,
|
|
455
|
+
return chainHead.storage$(block.hash, "value", () => codecs.enc(...actualArgs)).pipe((0, import_rxjs10.map)((val) => ({ val, codecs })));
|
|
430
456
|
}, 4),
|
|
431
|
-
(0,
|
|
432
|
-
(0,
|
|
457
|
+
(0, import_rxjs10.distinctUntilChanged)((a, b) => a.val === b.val),
|
|
458
|
+
(0, import_rxjs10.map)(
|
|
433
459
|
({ val, codecs }) => val === null ? codecs.fallback : codecs.dec(val)
|
|
434
460
|
)
|
|
435
461
|
);
|
|
@@ -439,25 +465,44 @@ var createStorageEntry = (pallet, name, chainHead, compatibilityHelper2) => {
|
|
|
439
465
|
const isLastArgOptional = isOptionalArg2(lastArg);
|
|
440
466
|
const { signal, at: _at } = isLastArgOptional ? lastArg : {};
|
|
441
467
|
const at = _at ?? null;
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
468
|
+
let result$;
|
|
469
|
+
if (isSystemNumber) {
|
|
470
|
+
result$ = chainHead.bestBlocks$.pipe(
|
|
471
|
+
(0, import_rxjs10.map)((blocks) => {
|
|
472
|
+
if (at === "finalized" || !at)
|
|
473
|
+
return blocks.at(-1);
|
|
474
|
+
if (at === "best")
|
|
475
|
+
return blocks.at(0);
|
|
476
|
+
return blocks.find((block) => block.hash === at);
|
|
477
|
+
}),
|
|
478
|
+
(0, import_rxjs10.map)((block) => {
|
|
479
|
+
if (!block)
|
|
480
|
+
throw new import_observable_client.NotBestBlockError();
|
|
481
|
+
return block.number;
|
|
482
|
+
}),
|
|
483
|
+
(0, import_rxjs10.distinctUntilChanged)()
|
|
484
|
+
);
|
|
485
|
+
} else {
|
|
486
|
+
const isCompatible2 = await waitChecksums();
|
|
487
|
+
result$ = chainHead.storage$(
|
|
488
|
+
at,
|
|
489
|
+
"value",
|
|
490
|
+
(ctx) => {
|
|
491
|
+
if (!isCompatible2(ctx))
|
|
492
|
+
throw checksumError();
|
|
493
|
+
const codecs = ctx.dynamicBuilder.buildStorage(pallet, name);
|
|
494
|
+
const actualArgs = args.length === codecs.len ? args : args.slice(0, -1);
|
|
495
|
+
if (args !== actualArgs && !isLastArgOptional)
|
|
496
|
+
throw invalidArgs(args);
|
|
497
|
+
return codecs.enc(...actualArgs);
|
|
498
|
+
},
|
|
499
|
+
null,
|
|
500
|
+
(data, ctx) => {
|
|
501
|
+
const codecs = ctx.dynamicBuilder.buildStorage(pallet, name);
|
|
502
|
+
return data === null ? codecs.fallback : codecs.dec(data);
|
|
503
|
+
}
|
|
504
|
+
);
|
|
505
|
+
}
|
|
461
506
|
return firstValueFromWithSignal(result$, signal);
|
|
462
507
|
};
|
|
463
508
|
const getEntries = async (...args) => {
|
|
@@ -497,159 +542,30 @@ var createStorageEntry = (pallet, name, chainHead, compatibilityHelper2) => {
|
|
|
497
542
|
return { isCompatible, getValue, getValues, getEntries, watchValue };
|
|
498
543
|
};
|
|
499
544
|
|
|
500
|
-
// src/tx.ts
|
|
501
|
-
var
|
|
502
|
-
var
|
|
503
|
-
var
|
|
504
|
-
var
|
|
505
|
-
const events = systemEvents.filter((x) => x.phase.type === "ApplyExtrinsic" && x.phase.value === txIdx).map((x) => x.event);
|
|
506
|
-
const lastEvent = events[events.length - 1];
|
|
507
|
-
const ok = lastEvent.type === "System" && lastEvent.value.type === "ExtrinsicSuccess";
|
|
508
|
-
return { ok, events };
|
|
509
|
-
};
|
|
510
|
-
var getSubmitFns = (chainHead, client) => {
|
|
511
|
-
const tx$ = (tx) => (0, import_rxjs10.concat)(
|
|
512
|
-
chainHead.finalized$.pipe(
|
|
513
|
-
(0, import_rxjs10.take)(1),
|
|
514
|
-
(0, import_rxjs10.mergeMap)((finalized) => chainHead.validateTx$(tx, finalized.hash)),
|
|
515
|
-
(0, import_rxjs10.map)((isValid) => {
|
|
516
|
-
if (!isValid)
|
|
517
|
-
throw new Error("Invalid");
|
|
518
|
-
return { type: "broadcasted" };
|
|
519
|
-
})
|
|
520
|
-
),
|
|
521
|
-
new import_rxjs10.Observable((observer) => {
|
|
522
|
-
const subscription = chainHead.trackTx$(tx).subscribe(observer);
|
|
523
|
-
subscription.add(
|
|
524
|
-
client.broadcastTx$(tx).subscribe({
|
|
525
|
-
error(e) {
|
|
526
|
-
observer.error(e);
|
|
527
|
-
}
|
|
528
|
-
})
|
|
529
|
-
);
|
|
530
|
-
return subscription;
|
|
531
|
-
})
|
|
532
|
-
);
|
|
533
|
-
const submit$ = (transaction) => tx$(transaction).pipe(
|
|
534
|
-
(0, import_rxjs10.mergeMap)((result) => {
|
|
535
|
-
return result.type !== "finalized" ? (0, import_rxjs10.of)(result) : chainHead.eventsAt$(result.block.hash).pipe(
|
|
536
|
-
(0, import_rxjs10.map)((events) => ({
|
|
537
|
-
...result,
|
|
538
|
-
...getTxSuccessFromSystemEvents(
|
|
539
|
-
events,
|
|
540
|
-
Number(result.block.index)
|
|
541
|
-
)
|
|
542
|
-
}))
|
|
543
|
-
);
|
|
544
|
-
})
|
|
545
|
-
);
|
|
546
|
-
const submit = async (transaction) => (0, import_rxjs10.lastValueFrom)(submit$(transaction)).then((x) => {
|
|
547
|
-
if (x.type !== "finalized")
|
|
548
|
-
throw null;
|
|
549
|
-
const result = { ...x };
|
|
550
|
-
delete result.type;
|
|
551
|
-
return result;
|
|
552
|
-
});
|
|
553
|
-
return { submit$, submit };
|
|
554
|
-
};
|
|
555
|
-
var feeDetailsDec = (0, import_substrate_bindings.Option)((0, import_substrate_bindings.Tuple)(import_substrate_bindings.u128, import_substrate_bindings.u128, import_substrate_bindings.u128)).dec;
|
|
556
|
-
var createTxEntry = (pallet, name, assetChecksum, chainHead, submits, signer, compatibilityHelper2) => {
|
|
557
|
-
const { isCompatible, compatibleRuntime$ } = compatibilityHelper2(
|
|
558
|
-
(ctx) => ctx.checksumBuilder.buildCall(pallet, name)
|
|
559
|
-
);
|
|
560
|
-
const checksumError = () => new Error(`Incompatible runtime entry Tx(${pallet}.${name})`);
|
|
561
|
-
const fn = (arg) => {
|
|
562
|
-
const getCallDataWithContext = ({ dynamicBuilder, asset: [assetEnc, assetCheck] }, arg2, hinted = {}) => {
|
|
563
|
-
let returnHinted = hinted;
|
|
564
|
-
if (hinted.asset) {
|
|
565
|
-
if (assetChecksum !== assetCheck)
|
|
566
|
-
throw new Error(`Incompatible runtime asset`);
|
|
567
|
-
returnHinted = { ...hinted, asset: assetEnc(hinted.asset) };
|
|
568
|
-
}
|
|
569
|
-
const { location, codec } = dynamicBuilder.buildCall(pallet, name);
|
|
570
|
-
return {
|
|
571
|
-
callData: import_substrate_bindings.Binary.fromBytes(
|
|
572
|
-
(0, import_utils6.mergeUint8)(new Uint8Array(location), codec.enc(arg2))
|
|
573
|
-
),
|
|
574
|
-
hinted: returnHinted
|
|
575
|
-
};
|
|
576
|
-
};
|
|
577
|
-
const getCallData$ = (arg2, hinted = {}) => compatibleRuntime$(chainHead, null, checksumError).pipe(
|
|
578
|
-
(0, import_rxjs10.map)((ctx) => getCallDataWithContext(ctx, arg2, hinted))
|
|
579
|
-
);
|
|
580
|
-
const getEncodedData = (runtime) => {
|
|
581
|
-
if (runtime) {
|
|
582
|
-
if (!isCompatible(runtime)) {
|
|
583
|
-
throw checksumError();
|
|
584
|
-
}
|
|
585
|
-
return getCallDataWithContext(getRuntimeContext(runtime), arg).callData;
|
|
586
|
-
}
|
|
587
|
-
return (0, import_rxjs10.firstValueFrom)(getCallData$(arg).pipe((0, import_rxjs10.map)((x) => x.callData)));
|
|
588
|
-
};
|
|
589
|
-
const sign$ = (from, _hinted) => getCallData$(arg, _hinted).pipe(
|
|
590
|
-
(0, import_rxjs10.withLatestFrom)(chainHead.finalized$),
|
|
591
|
-
(0, import_rxjs10.take)(1),
|
|
592
|
-
(0, import_rxjs10.mergeMap)(
|
|
593
|
-
([{ callData, hinted }, finalized]) => signer(from, callData.asBytes(), finalized, hinted)
|
|
594
|
-
)
|
|
595
|
-
);
|
|
596
|
-
const sign = (from, _hinted) => (0, import_rxjs10.firstValueFrom)(sign$(from, _hinted)).then(import_utils6.toHex);
|
|
597
|
-
const signAndSubmit = (from, _hinted) => sign(from, _hinted).then(submits.submit);
|
|
598
|
-
const signSubmitAndWatch = (from, _hinted) => sign$(from, _hinted).pipe(
|
|
599
|
-
(0, import_rxjs10.mergeMap)((result) => {
|
|
600
|
-
const tx = (0, import_utils6.toHex)(result);
|
|
601
|
-
return submits.submit$(tx).pipe((0, import_rxjs10.startWith)({ type: "signed", tx }));
|
|
602
|
-
})
|
|
603
|
-
);
|
|
604
|
-
const getEstimatedFees = async () => {
|
|
605
|
-
const encoded = (await getEncodedData()).asBytes();
|
|
606
|
-
const preLen = encoded.length + 103;
|
|
607
|
-
const len = preLen + import_substrate_bindings.compact.enc(preLen).length;
|
|
608
|
-
const args = (0, import_utils6.toHex)((0, import_utils6.mergeUint8)(encoded, import_substrate_bindings.u32.enc(len)));
|
|
609
|
-
return (0, import_rxjs10.firstValueFrom)(
|
|
610
|
-
chainHead.call$(null, "TransactionPaymentCallApi_query_call_fee_details", args).pipe(
|
|
611
|
-
(0, import_rxjs10.map)((x) => {
|
|
612
|
-
const result = feeDetailsDec(x);
|
|
613
|
-
if (!result)
|
|
614
|
-
throw new Error("Unable to calculate tx fees");
|
|
615
|
-
return result.reduce((a, b) => a + b);
|
|
616
|
-
})
|
|
617
|
-
)
|
|
618
|
-
);
|
|
619
|
-
};
|
|
620
|
-
return {
|
|
621
|
-
getEstimatedFees,
|
|
622
|
-
decodedCall: {
|
|
623
|
-
type: pallet,
|
|
624
|
-
value: (0, import_substrate_bindings.Enum)(name, arg)
|
|
625
|
-
},
|
|
626
|
-
getEncodedData,
|
|
627
|
-
sign,
|
|
628
|
-
signSubmitAndWatch,
|
|
629
|
-
signAndSubmit
|
|
630
|
-
};
|
|
631
|
-
};
|
|
632
|
-
return Object.assign(fn, { isCompatible });
|
|
633
|
-
};
|
|
545
|
+
// src/tx/tx.ts
|
|
546
|
+
var import_substrate_bindings8 = require("@polkadot-api/substrate-bindings");
|
|
547
|
+
var import_utils19 = require("@polkadot-api/utils");
|
|
548
|
+
var import_rxjs21 = require("rxjs");
|
|
549
|
+
var import_signer = require("@polkadot-api/signer");
|
|
634
550
|
|
|
635
|
-
// src/
|
|
551
|
+
// src/tx/create-tx.ts
|
|
636
552
|
var import_rxjs19 = require("rxjs");
|
|
637
553
|
|
|
638
|
-
// src/signed-extensions/user/ChargeTransactionPayment.ts
|
|
639
|
-
var
|
|
554
|
+
// src/tx/signed-extensions/user/ChargeTransactionPayment.ts
|
|
555
|
+
var import_substrate_bindings2 = require("@polkadot-api/substrate-bindings");
|
|
640
556
|
var import_rxjs12 = require("rxjs");
|
|
641
557
|
|
|
642
|
-
// src/signed-extensions/utils.ts
|
|
558
|
+
// src/tx/signed-extensions/utils.ts
|
|
643
559
|
var import_rxjs11 = require("rxjs");
|
|
644
|
-
var
|
|
560
|
+
var import_substrate_bindings = require("@polkadot-api/substrate-bindings");
|
|
645
561
|
var import_metadata_builders = require("@polkadot-api/metadata-builders");
|
|
646
|
-
var
|
|
562
|
+
var import_utils6 = require("@polkadot-api/utils");
|
|
647
563
|
var empty = new Uint8Array();
|
|
648
|
-
var genesisHashStorageKey = (0,
|
|
649
|
-
|
|
650
|
-
|
|
564
|
+
var genesisHashStorageKey = (0, import_substrate_bindings.Storage)("System")("BlockHash", import_rxjs11.noop, [
|
|
565
|
+
import_substrate_bindings.u32,
|
|
566
|
+
import_substrate_bindings.Twox64Concat
|
|
651
567
|
]).enc(0);
|
|
652
|
-
var genesisHashFromCtx = (ctx) => ctx.chainHead.storage$(ctx.at, "value", () => genesisHashStorageKey, null).pipe((0, import_rxjs11.map)((result) => (0,
|
|
568
|
+
var genesisHashFromCtx = (ctx) => ctx.chainHead.storage$(ctx.at, "value", () => genesisHashStorageKey, null).pipe((0, import_rxjs11.map)((result) => (0, import_utils6.fromHex)(result)));
|
|
653
569
|
var systemVersionProp$ = (propName, metadata) => {
|
|
654
570
|
const lookupFn = (0, import_metadata_builders.getLookupFn)(metadata.lookup);
|
|
655
571
|
const dynamicBuilder = (0, import_metadata_builders.getDynamicBuilder)(metadata);
|
|
@@ -664,16 +580,16 @@ var systemVersionProp$ = (propName, metadata) => {
|
|
|
664
580
|
return (0, import_rxjs11.of)(valueEnc(systemVersionDec(constant.value)[propName]));
|
|
665
581
|
};
|
|
666
582
|
|
|
667
|
-
// src/signed-extensions/user/ChargeTransactionPayment.ts
|
|
583
|
+
// src/tx/signed-extensions/user/ChargeTransactionPayment.ts
|
|
668
584
|
var ChargeTransactionPayment = (tip) => (0, import_rxjs12.of)({
|
|
669
|
-
value:
|
|
585
|
+
value: import_substrate_bindings2.compactBn.enc(tip),
|
|
670
586
|
additionalSigned: empty
|
|
671
587
|
});
|
|
672
588
|
|
|
673
|
-
// src/signed-extensions/user/CheckMortality.ts
|
|
589
|
+
// src/tx/signed-extensions/user/CheckMortality.ts
|
|
674
590
|
var import_rxjs13 = require("rxjs");
|
|
675
|
-
var
|
|
676
|
-
var
|
|
591
|
+
var import_substrate_bindings3 = require("@polkadot-api/substrate-bindings");
|
|
592
|
+
var import_utils8 = require("@polkadot-api/utils");
|
|
677
593
|
function trailingZeroes(n) {
|
|
678
594
|
let i = 0;
|
|
679
595
|
while (!(n & 1)) {
|
|
@@ -682,13 +598,13 @@ function trailingZeroes(n) {
|
|
|
682
598
|
}
|
|
683
599
|
return i;
|
|
684
600
|
}
|
|
685
|
-
var mortal = (0,
|
|
686
|
-
(0,
|
|
601
|
+
var mortal = (0, import_substrate_bindings3.enhanceEncoder)(
|
|
602
|
+
(0, import_substrate_bindings3.Bytes)(2).enc,
|
|
687
603
|
(value) => {
|
|
688
604
|
const factor = Math.max(value.period >> 12, 1);
|
|
689
605
|
const left = Math.min(Math.max(trailingZeroes(value.period) - 1, 1), 15);
|
|
690
606
|
const right = value.phase / factor << 4;
|
|
691
|
-
return
|
|
607
|
+
return import_substrate_bindings3.u16.enc(left | right);
|
|
692
608
|
}
|
|
693
609
|
);
|
|
694
610
|
var zero = new Uint8Array([0]);
|
|
@@ -702,7 +618,7 @@ var CheckMortality = (input, ctx) => {
|
|
|
702
618
|
);
|
|
703
619
|
const { period, blockNumber } = input;
|
|
704
620
|
return (0, import_rxjs13.of)({
|
|
705
|
-
additionalSigned: (0,
|
|
621
|
+
additionalSigned: (0, import_utils8.fromHex)(ctx.at),
|
|
706
622
|
value: mortal({
|
|
707
623
|
period,
|
|
708
624
|
phase: blockNumber % period
|
|
@@ -710,12 +626,12 @@ var CheckMortality = (input, ctx) => {
|
|
|
710
626
|
});
|
|
711
627
|
};
|
|
712
628
|
|
|
713
|
-
// src/signed-extensions/user/ChargeAssetTxPayment.ts
|
|
629
|
+
// src/tx/signed-extensions/user/ChargeAssetTxPayment.ts
|
|
714
630
|
var import_rxjs14 = require("rxjs");
|
|
715
|
-
var
|
|
716
|
-
var encoder = (0,
|
|
717
|
-
tip:
|
|
718
|
-
asset: (0,
|
|
631
|
+
var import_substrate_bindings4 = require("@polkadot-api/substrate-bindings");
|
|
632
|
+
var encoder = (0, import_substrate_bindings4.Struct)({
|
|
633
|
+
tip: import_substrate_bindings4.compact,
|
|
634
|
+
asset: (0, import_substrate_bindings4.Option)((0, import_substrate_bindings4.Bytes)(Infinity))
|
|
719
635
|
}).enc;
|
|
720
636
|
var ChargeAssetTxPayment = (tip, asset) => (0, import_rxjs14.of)({
|
|
721
637
|
value: encoder({
|
|
@@ -725,220 +641,462 @@ var ChargeAssetTxPayment = (tip, asset) => (0, import_rxjs14.of)({
|
|
|
725
641
|
additionalSigned: empty
|
|
726
642
|
});
|
|
727
643
|
|
|
728
|
-
// src/signed-extensions/chain/index.ts
|
|
644
|
+
// src/tx/signed-extensions/chain/index.ts
|
|
729
645
|
var chain_exports = {};
|
|
730
646
|
__export(chain_exports, {
|
|
731
647
|
CheckGenesis: () => CheckGenesis,
|
|
732
648
|
CheckNonce: () => CheckNonce,
|
|
733
649
|
CheckSpecVersion: () => CheckSpecVersion,
|
|
734
|
-
CheckTxVersion: () => CheckTxVersion
|
|
650
|
+
CheckTxVersion: () => CheckTxVersion,
|
|
651
|
+
getNonce: () => getNonce
|
|
735
652
|
});
|
|
736
653
|
|
|
737
|
-
// src/signed-extensions/chain/CheckGenesis.ts
|
|
654
|
+
// src/tx/signed-extensions/chain/CheckGenesis.ts
|
|
738
655
|
var import_rxjs15 = require("rxjs");
|
|
739
656
|
var CheckGenesis = (ctx) => genesisHashFromCtx(ctx).pipe(
|
|
740
657
|
(0, import_rxjs15.map)((additionalSigned) => ({ value: empty, additionalSigned }))
|
|
741
658
|
);
|
|
742
659
|
|
|
743
|
-
// src/signed-extensions/chain/CheckNonce.ts
|
|
660
|
+
// src/tx/signed-extensions/chain/CheckNonce.ts
|
|
744
661
|
var import_rxjs16 = require("rxjs");
|
|
745
|
-
var
|
|
746
|
-
var
|
|
662
|
+
var import_substrate_bindings5 = require("@polkadot-api/substrate-bindings");
|
|
663
|
+
var import_utils13 = require("@polkadot-api/utils");
|
|
664
|
+
var NONCE_RUNTIME_CALL = "AccountNonceApi_account_nonce";
|
|
747
665
|
var lenToDecoder = {
|
|
748
|
-
1:
|
|
749
|
-
2:
|
|
750
|
-
4:
|
|
751
|
-
8:
|
|
666
|
+
1: import_substrate_bindings5.u8.dec,
|
|
667
|
+
2: import_substrate_bindings5.u16.dec,
|
|
668
|
+
4: import_substrate_bindings5.u32.dec,
|
|
669
|
+
8: import_substrate_bindings5.u64.dec
|
|
752
670
|
};
|
|
753
|
-
var
|
|
754
|
-
|
|
755
|
-
|
|
671
|
+
var getNonce = (input) => (0, import_rxjs16.of)({ value: import_substrate_bindings5.compact.enc(input), additionalSigned: empty });
|
|
672
|
+
var CheckNonce = (ctx) => ctx.chainHead.call$(ctx.at, NONCE_RUNTIME_CALL, (0, import_utils13.toHex)(ctx.from)).pipe(
|
|
673
|
+
(0, import_rxjs16.mergeMap)((result) => {
|
|
674
|
+
const bytes = (0, import_utils13.fromHex)(result);
|
|
756
675
|
const decoder = lenToDecoder[bytes.length];
|
|
757
676
|
if (!decoder)
|
|
758
|
-
throw new Error(
|
|
759
|
-
return
|
|
760
|
-
})
|
|
761
|
-
(0, import_rxjs16.map)((value) => ({ value, additionalSigned: empty }))
|
|
677
|
+
throw new Error(`${NONCE_RUNTIME_CALL} retrieved wrong data`);
|
|
678
|
+
return getNonce(decoder(bytes));
|
|
679
|
+
})
|
|
762
680
|
);
|
|
763
681
|
|
|
764
|
-
// src/signed-extensions/chain/CheckSpecVersion.ts
|
|
682
|
+
// src/tx/signed-extensions/chain/CheckSpecVersion.ts
|
|
765
683
|
var import_rxjs17 = require("rxjs");
|
|
766
684
|
var CheckSpecVersion = ({ metadata }) => systemVersionProp$("spec_version", metadata).pipe(
|
|
767
685
|
(0, import_rxjs17.map)((additionalSigned) => ({ additionalSigned, value: empty }))
|
|
768
686
|
);
|
|
769
687
|
|
|
770
|
-
// src/signed-extensions/chain/CheckTxVersion.ts
|
|
688
|
+
// src/tx/signed-extensions/chain/CheckTxVersion.ts
|
|
771
689
|
var import_rxjs18 = require("rxjs");
|
|
772
690
|
var CheckTxVersion = ({ metadata }) => systemVersionProp$("transaction_version", metadata).pipe(
|
|
773
691
|
(0, import_rxjs18.map)((additionalSigned) => ({ additionalSigned, value: empty }))
|
|
774
692
|
);
|
|
775
693
|
|
|
776
|
-
// src/
|
|
777
|
-
var
|
|
778
|
-
var
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
694
|
+
// src/tx/create-tx.ts
|
|
695
|
+
var import_substrate_bindings6 = require("@polkadot-api/substrate-bindings");
|
|
696
|
+
var createTx = (chainHead, signer, callData, atBlock, hinted = {}) => chainHead.getRuntimeContext$(atBlock.hash).pipe(
|
|
697
|
+
(0, import_rxjs19.take)(1),
|
|
698
|
+
(0, import_rxjs19.mergeMap)((ctx) => {
|
|
699
|
+
const signedExtensionsCtx = {
|
|
700
|
+
metadata: ctx.metadata,
|
|
701
|
+
chainHead,
|
|
702
|
+
callData,
|
|
703
|
+
at: atBlock.hash,
|
|
704
|
+
from: signer.publicKey
|
|
705
|
+
};
|
|
706
|
+
const mortality = !hinted.mortality ? { period: 64, blockNumber: atBlock.number } : hinted.mortality.mortal ? { period: hinted.mortality.period, blockNumber: atBlock.number } : void 0;
|
|
707
|
+
return (0, import_rxjs19.combineLatest)(
|
|
708
|
+
ctx.metadata.extrinsic.signedExtensions.map(
|
|
709
|
+
({ identifier, type, additionalSigned }) => {
|
|
710
|
+
if (identifier === "CheckMortality")
|
|
711
|
+
return CheckMortality(mortality, signedExtensionsCtx);
|
|
712
|
+
if (identifier === "ChargeTransactionPayment")
|
|
713
|
+
return ChargeTransactionPayment(hinted.tip ?? 0n);
|
|
714
|
+
if (identifier === "ChargeAssetTxPayment")
|
|
715
|
+
return ChargeAssetTxPayment(hinted.tip ?? 0n, hinted.asset);
|
|
716
|
+
if (identifier === "CheckNonce" && "nonce" in hinted)
|
|
717
|
+
return getNonce(hinted.nonce);
|
|
718
|
+
const fn = chain_exports[identifier];
|
|
719
|
+
if (!fn) {
|
|
720
|
+
if (ctx.dynamicBuilder.buildDefinition(type) === import_substrate_bindings6._void && ctx.dynamicBuilder.buildDefinition(additionalSigned) === import_substrate_bindings6._void)
|
|
721
|
+
return (0, import_rxjs19.of)({
|
|
722
|
+
value: empty,
|
|
723
|
+
additionalSigned: empty
|
|
724
|
+
});
|
|
725
|
+
throw new Error(`Unsupported signed-extension: ${identifier}`);
|
|
726
|
+
}
|
|
727
|
+
return fn(signedExtensionsCtx);
|
|
728
|
+
}
|
|
729
|
+
)
|
|
730
|
+
).pipe(
|
|
731
|
+
(0, import_rxjs19.mergeMap)(
|
|
732
|
+
(signedExtensions) => signer.sign(
|
|
786
733
|
callData,
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
({ identifier, type, additionalSigned }) => {
|
|
794
|
-
if (identifier === "CheckMortality")
|
|
795
|
-
return CheckMortality(mortality, signedExtensionsCtx);
|
|
796
|
-
if (identifier === "ChargeTransactionPayment")
|
|
797
|
-
return ChargeTransactionPayment(hinted?.tip ?? 0n);
|
|
798
|
-
if (identifier === "ChargeAssetTxPayment")
|
|
799
|
-
return ChargeAssetTxPayment(hinted?.tip ?? 0n, hinted?.asset);
|
|
800
|
-
const fn = chain_exports[identifier];
|
|
801
|
-
if (!fn) {
|
|
802
|
-
if (ctx.dynamicBuilder.buildDefinition(type) === import_substrate_bindings7._void && ctx.dynamicBuilder.buildDefinition(additionalSigned) === import_substrate_bindings7._void)
|
|
803
|
-
return (0, import_rxjs19.of)({
|
|
804
|
-
value: empty,
|
|
805
|
-
additionalSigned: empty
|
|
806
|
-
});
|
|
807
|
-
throw new Error(`Unsupported signed-extension: ${identifier}`);
|
|
808
|
-
}
|
|
809
|
-
return fn(signedExtensionsCtx);
|
|
810
|
-
}
|
|
811
|
-
)
|
|
812
|
-
).pipe(
|
|
813
|
-
(0, import_rxjs19.mergeMap)(
|
|
814
|
-
(signedExtensions) => signer.sign(
|
|
815
|
-
callData,
|
|
816
|
-
Object.fromEntries(
|
|
817
|
-
ctx.metadata.extrinsic.signedExtensions.map(
|
|
818
|
-
({ identifier }, idx) => [
|
|
819
|
-
identifier,
|
|
820
|
-
{ identifier, ...signedExtensions[idx] }
|
|
821
|
-
]
|
|
822
|
-
)
|
|
823
|
-
),
|
|
824
|
-
ctx.metadataRaw,
|
|
825
|
-
atBlock.number
|
|
734
|
+
Object.fromEntries(
|
|
735
|
+
ctx.metadata.extrinsic.signedExtensions.map(
|
|
736
|
+
({ identifier }, idx) => [
|
|
737
|
+
identifier,
|
|
738
|
+
{ identifier, ...signedExtensions[idx] }
|
|
739
|
+
]
|
|
826
740
|
)
|
|
827
|
-
)
|
|
828
|
-
|
|
829
|
-
|
|
741
|
+
),
|
|
742
|
+
ctx.metadataRaw,
|
|
743
|
+
atBlock.number
|
|
744
|
+
)
|
|
745
|
+
)
|
|
830
746
|
);
|
|
831
|
-
}
|
|
832
|
-
|
|
747
|
+
})
|
|
748
|
+
);
|
|
833
749
|
|
|
834
|
-
// src/
|
|
835
|
-
var
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
)
|
|
750
|
+
// src/tx/submit-fns.ts
|
|
751
|
+
var import_substrate_bindings7 = require("@polkadot-api/substrate-bindings");
|
|
752
|
+
var import_rxjs20 = require("rxjs");
|
|
753
|
+
var import_utils18 = require("@polkadot-api/utils");
|
|
754
|
+
var hashFromTx = (tx) => (0, import_utils18.toHex)((0, import_substrate_bindings7.Blake2256)((0, import_utils18.fromHex)(tx)));
|
|
755
|
+
var computeState = (analized$, blocks$) => new import_rxjs20.Observable((observer) => {
|
|
756
|
+
const analyzedBlocks = /* @__PURE__ */ new Map();
|
|
757
|
+
let pinnedBlocks;
|
|
758
|
+
let latestState;
|
|
759
|
+
const computeNextState = () => {
|
|
760
|
+
let current = pinnedBlocks.best;
|
|
761
|
+
let analyzed = analyzedBlocks.get(current);
|
|
762
|
+
while (!analyzed) {
|
|
763
|
+
const block = pinnedBlocks.blocks.get(current);
|
|
764
|
+
if (!block)
|
|
765
|
+
break;
|
|
766
|
+
analyzed = analyzedBlocks.get(current = block.parent);
|
|
849
767
|
}
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
name,
|
|
859
|
-
descriptors.asset,
|
|
860
|
-
chainHead,
|
|
861
|
-
submitFns,
|
|
862
|
-
createTxFromSigner,
|
|
863
|
-
compatibilityHelper(runtimeApi, txEntries[name])
|
|
864
|
-
);
|
|
768
|
+
if (!analyzed)
|
|
769
|
+
return;
|
|
770
|
+
const isFinalized = pinnedBlocks.blocks.get(analyzed.hash).number <= pinnedBlocks.blocks.get(pinnedBlocks.finalized).number;
|
|
771
|
+
const found = analyzed.found.type;
|
|
772
|
+
if (found && typeof latestState === "object" && latestState.hash === analyzed.hash) {
|
|
773
|
+
if (isFinalized)
|
|
774
|
+
observer.complete();
|
|
775
|
+
return;
|
|
865
776
|
}
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
);
|
|
777
|
+
observer.next(
|
|
778
|
+
latestState = found ? {
|
|
779
|
+
hash: analyzed.hash,
|
|
780
|
+
...analyzed.found
|
|
781
|
+
} : analyzed.found.isValid
|
|
782
|
+
);
|
|
783
|
+
if (isFinalized) {
|
|
784
|
+
if (found)
|
|
785
|
+
observer.complete();
|
|
786
|
+
else if (!analyzed.found.isValid)
|
|
787
|
+
observer.error(new Error("Invalid"));
|
|
878
788
|
}
|
|
879
|
-
}
|
|
880
|
-
const
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
789
|
+
};
|
|
790
|
+
const subscription = blocks$.pipe(
|
|
791
|
+
(0, import_rxjs20.distinctUntilChanged)(
|
|
792
|
+
(a, b) => a.finalized === b.finalized && a.best === b.best
|
|
793
|
+
)
|
|
794
|
+
).subscribe({
|
|
795
|
+
next: (pinned) => {
|
|
796
|
+
pinnedBlocks = pinned;
|
|
797
|
+
if (analyzedBlocks.size === 0)
|
|
798
|
+
return;
|
|
799
|
+
computeNextState();
|
|
800
|
+
},
|
|
801
|
+
error(e) {
|
|
802
|
+
observer.error(e);
|
|
891
803
|
}
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
804
|
+
});
|
|
805
|
+
subscription.add(
|
|
806
|
+
analized$.subscribe({
|
|
807
|
+
next: (block) => {
|
|
808
|
+
analyzedBlocks.set(block.hash, block);
|
|
809
|
+
computeNextState();
|
|
810
|
+
},
|
|
811
|
+
error(e) {
|
|
812
|
+
observer.error(e);
|
|
813
|
+
}
|
|
814
|
+
})
|
|
815
|
+
);
|
|
816
|
+
return subscription;
|
|
817
|
+
}).pipe((0, import_rxjs20.distinctUntilChanged)((a, b) => a === b));
|
|
818
|
+
var getTxSuccessFromSystemEvents = (systemEvents, txIdx) => {
|
|
819
|
+
const events = systemEvents.filter((x) => x.phase.type === "ApplyExtrinsic" && x.phase.value === txIdx).map((x) => x.event);
|
|
820
|
+
const lastEvent = events[events.length - 1];
|
|
821
|
+
const ok = lastEvent.type === "System" && lastEvent.value.type === "ExtrinsicSuccess";
|
|
822
|
+
return { ok, events };
|
|
823
|
+
};
|
|
824
|
+
var submit$ = (chainHead, broadcastTx$, tx, at, emitSign = false) => {
|
|
825
|
+
const txHash = hashFromTx(tx);
|
|
826
|
+
const getTxEvent = (type, rest) => ({
|
|
827
|
+
type,
|
|
828
|
+
txHash,
|
|
829
|
+
...rest
|
|
830
|
+
});
|
|
831
|
+
const at$ = chainHead.pinnedBlocks$.pipe(
|
|
832
|
+
(0, import_rxjs20.take)(1),
|
|
833
|
+
(0, import_rxjs20.map)((blocks) => blocks.blocks.get(at)?.hash ?? blocks.finalized)
|
|
834
|
+
);
|
|
835
|
+
const validate$ = at$.pipe(
|
|
836
|
+
(0, import_rxjs20.mergeMap)(
|
|
837
|
+
(at2) => chainHead.validateTx$(at2, tx).pipe(
|
|
838
|
+
(0, import_rxjs20.filter)((x) => !x),
|
|
839
|
+
(0, import_rxjs20.map)(() => {
|
|
840
|
+
throw new Error("Invalid");
|
|
841
|
+
})
|
|
842
|
+
)
|
|
843
|
+
)
|
|
844
|
+
);
|
|
845
|
+
const track$ = new import_rxjs20.Observable((observer) => {
|
|
846
|
+
const subscription = chainHead.trackTx$(tx).subscribe(observer);
|
|
847
|
+
subscription.add(
|
|
848
|
+
broadcastTx$(tx).subscribe({
|
|
849
|
+
error(e) {
|
|
850
|
+
observer.error(e);
|
|
851
|
+
}
|
|
852
|
+
})
|
|
853
|
+
);
|
|
854
|
+
return subscription;
|
|
855
|
+
});
|
|
856
|
+
const bestBlockState$ = computeState(track$, chainHead.pinnedBlocks$).pipe(
|
|
857
|
+
(0, import_rxjs20.map)((x) => {
|
|
858
|
+
if (x === true || x === false)
|
|
859
|
+
return getTxEvent("txBestBlocksState", {
|
|
860
|
+
found: false,
|
|
861
|
+
isValid: x
|
|
862
|
+
});
|
|
863
|
+
return getTxEvent("txBestBlocksState", {
|
|
864
|
+
found: true,
|
|
865
|
+
block: {
|
|
866
|
+
index: x.index,
|
|
867
|
+
hash: x.hash
|
|
868
|
+
},
|
|
869
|
+
...getTxSuccessFromSystemEvents(x.events, x.index)
|
|
870
|
+
});
|
|
871
|
+
})
|
|
872
|
+
);
|
|
873
|
+
return (0, import_rxjs20.concat)(
|
|
874
|
+
emitSign ? (0, import_rxjs20.of)(getTxEvent("signed", {})) : import_rxjs20.EMPTY,
|
|
875
|
+
validate$,
|
|
876
|
+
(0, import_rxjs20.of)(getTxEvent("broadcasted", {})),
|
|
877
|
+
bestBlockState$.pipe(
|
|
878
|
+
continueWith(
|
|
879
|
+
({ found, type, ...rest }) => found ? (0, import_rxjs20.of)(getTxEvent("finalized", rest)) : import_rxjs20.EMPTY
|
|
880
|
+
)
|
|
881
|
+
)
|
|
882
|
+
);
|
|
883
|
+
};
|
|
884
|
+
var submit = async (chainHead, broadcastTx$, transaction, at) => (0, import_rxjs20.lastValueFrom)(submit$(chainHead, broadcastTx$, transaction, at)).then((x) => {
|
|
885
|
+
if (x.type !== "finalized")
|
|
886
|
+
throw null;
|
|
887
|
+
const result = { ...x };
|
|
888
|
+
delete result.type;
|
|
889
|
+
return result;
|
|
890
|
+
});
|
|
891
|
+
|
|
892
|
+
// src/tx/tx.ts
|
|
893
|
+
var accountIdEnc = (0, import_substrate_bindings8.AccountId)().enc;
|
|
894
|
+
var queryInfoRawDec = (0, import_substrate_bindings8.Tuple)(import_substrate_bindings8.compact, import_substrate_bindings8.compact, import_substrate_bindings8.u8, import_substrate_bindings8.u128).dec;
|
|
895
|
+
var queryInfoDec = (input) => queryInfoRawDec(input)[3];
|
|
896
|
+
var fakeSignature = new Uint8Array(64);
|
|
897
|
+
var getFakeSignature = () => fakeSignature;
|
|
898
|
+
var createTxEntry = (pallet, name, assetChecksum, chainHead, broadcast, compatibilityHelper2) => {
|
|
899
|
+
const { isCompatible, compatibleRuntime$ } = compatibilityHelper2(
|
|
900
|
+
(ctx) => ctx.checksumBuilder.buildCall(pallet, name)
|
|
901
|
+
);
|
|
902
|
+
const checksumError = () => new Error(`Incompatible runtime entry Tx(${pallet}.${name})`);
|
|
903
|
+
const fn = (arg) => {
|
|
904
|
+
const getCallDataWithContext = ({ dynamicBuilder, asset: [assetEnc, assetCheck] }, arg2, txOptions = {}) => {
|
|
905
|
+
let returnOptions = txOptions;
|
|
906
|
+
if (txOptions.asset) {
|
|
907
|
+
if (assetChecksum !== assetCheck)
|
|
908
|
+
throw new Error(`Incompatible runtime asset`);
|
|
909
|
+
returnOptions = { ...txOptions, asset: assetEnc(txOptions.asset) };
|
|
910
|
+
}
|
|
911
|
+
const { location, codec } = dynamicBuilder.buildCall(pallet, name);
|
|
912
|
+
return {
|
|
913
|
+
callData: import_substrate_bindings8.Binary.fromBytes(
|
|
914
|
+
(0, import_utils19.mergeUint8)(new Uint8Array(location), codec.enc(arg2))
|
|
915
|
+
),
|
|
916
|
+
options: returnOptions
|
|
917
|
+
};
|
|
918
|
+
};
|
|
919
|
+
const getCallData$ = (arg2, options = {}) => compatibleRuntime$(chainHead, null, checksumError).pipe(
|
|
920
|
+
(0, import_rxjs21.map)((ctx) => getCallDataWithContext(ctx, arg2, options))
|
|
921
|
+
);
|
|
922
|
+
const getEncodedData = (runtime) => {
|
|
923
|
+
if (!runtime)
|
|
924
|
+
return (0, import_rxjs21.firstValueFrom)(getCallData$(arg).pipe((0, import_rxjs21.map)((x) => x.callData)));
|
|
925
|
+
if (!isCompatible(runtime))
|
|
926
|
+
throw checksumError();
|
|
927
|
+
return getCallDataWithContext(runtime._getCtx(), arg).callData;
|
|
928
|
+
};
|
|
929
|
+
const sign$ = (from, { ..._options }, atBlock) => getCallData$(arg, _options).pipe(
|
|
930
|
+
(0, import_rxjs21.mergeMap)(
|
|
931
|
+
({ callData, options }) => createTx(chainHead, from, callData.asBytes(), atBlock, options)
|
|
932
|
+
)
|
|
933
|
+
);
|
|
934
|
+
const _sign = (from, { at, ..._options } = {}) => {
|
|
935
|
+
return (!at || at === "finalized" ? chainHead.finalized$ : at === "best" ? chainHead.best$ : chainHead.bestBlocks$.pipe(
|
|
936
|
+
(0, import_rxjs21.map)((x) => x.find((b) => b.hash === at))
|
|
937
|
+
)).pipe(
|
|
938
|
+
(0, import_rxjs21.take)(1),
|
|
939
|
+
(0, import_rxjs21.mergeMap)(
|
|
940
|
+
(atBlock) => atBlock ? sign$(from, _options, atBlock).pipe(
|
|
941
|
+
(0, import_rxjs21.map)((signed) => ({
|
|
942
|
+
tx: (0, import_utils19.toHex)(signed),
|
|
943
|
+
block: atBlock
|
|
944
|
+
}))
|
|
945
|
+
) : (0, import_rxjs21.throwError)(() => new Error(`Uknown block ${at}`))
|
|
946
|
+
)
|
|
903
947
|
);
|
|
948
|
+
};
|
|
949
|
+
const sign = (from, options) => (0, import_rxjs21.firstValueFrom)(_sign(from, options)).then((x) => x.tx);
|
|
950
|
+
const signAndSubmit = (from, _options) => (0, import_rxjs21.firstValueFrom)(_sign(from, _options)).then(
|
|
951
|
+
({ tx, block }) => submit(chainHead, broadcast, tx, block.hash)
|
|
952
|
+
);
|
|
953
|
+
const signSubmitAndWatch = (from, _options) => _sign(from, _options).pipe(
|
|
954
|
+
(0, import_rxjs21.mergeMap)(
|
|
955
|
+
({ tx, block }) => submit$(chainHead, broadcast, tx, block.hash, true)
|
|
956
|
+
)
|
|
957
|
+
);
|
|
958
|
+
const getEstimatedFees = async (from, _options) => {
|
|
959
|
+
const fakeSigner = (0, import_signer.getPolkadotSigner)(
|
|
960
|
+
from instanceof Uint8Array ? from : accountIdEnc(from),
|
|
961
|
+
"Sr25519",
|
|
962
|
+
getFakeSignature
|
|
963
|
+
);
|
|
964
|
+
const encoded = (0, import_utils19.fromHex)(await sign(fakeSigner, _options));
|
|
965
|
+
const args = (0, import_utils19.toHex)((0, import_utils19.mergeUint8)(encoded, import_substrate_bindings8.u32.enc(encoded.length)));
|
|
966
|
+
return (0, import_rxjs21.firstValueFrom)(
|
|
967
|
+
chainHead.call$(null, "TransactionPaymentApi_query_info", args).pipe((0, import_rxjs21.map)(queryInfoDec))
|
|
968
|
+
);
|
|
969
|
+
};
|
|
970
|
+
return {
|
|
971
|
+
getEstimatedFees,
|
|
972
|
+
decodedCall: {
|
|
973
|
+
type: pallet,
|
|
974
|
+
value: (0, import_substrate_bindings8.Enum)(name, arg)
|
|
975
|
+
},
|
|
976
|
+
getEncodedData,
|
|
977
|
+
sign,
|
|
978
|
+
signSubmitAndWatch,
|
|
979
|
+
signAndSubmit
|
|
980
|
+
};
|
|
981
|
+
};
|
|
982
|
+
return Object.assign(fn, { isCompatible });
|
|
983
|
+
};
|
|
984
|
+
|
|
985
|
+
// src/client.ts
|
|
986
|
+
var createTypedApi = (chainDefinition, chainHead, broadcast$) => {
|
|
987
|
+
const runtime = getRuntimeApi(
|
|
988
|
+
chainDefinition.checksums,
|
|
989
|
+
chainDefinition.descriptors,
|
|
990
|
+
chainHead
|
|
991
|
+
);
|
|
992
|
+
const target = {};
|
|
993
|
+
const createProxy = (propCall) => new Proxy(target, {
|
|
994
|
+
get(_, prop) {
|
|
995
|
+
return propCall(prop);
|
|
904
996
|
}
|
|
905
|
-
}
|
|
997
|
+
});
|
|
998
|
+
const createProxyPath = (pathCall) => {
|
|
999
|
+
const cache = {};
|
|
1000
|
+
return createProxy((a) => {
|
|
1001
|
+
if (!cache[a])
|
|
1002
|
+
cache[a] = {};
|
|
1003
|
+
return createProxy((b) => {
|
|
1004
|
+
if (!cache[a][b])
|
|
1005
|
+
cache[a][b] = pathCall(a, b);
|
|
1006
|
+
return cache[a][b];
|
|
1007
|
+
});
|
|
1008
|
+
});
|
|
1009
|
+
};
|
|
1010
|
+
const query = createProxyPath(
|
|
1011
|
+
(pallet, name) => createStorageEntry(
|
|
1012
|
+
pallet,
|
|
1013
|
+
name,
|
|
1014
|
+
chainHead,
|
|
1015
|
+
compatibilityHelper(
|
|
1016
|
+
runtime,
|
|
1017
|
+
(r) => r._getPalletChecksum(0 /* Storage */, pallet, name)
|
|
1018
|
+
)
|
|
1019
|
+
)
|
|
1020
|
+
);
|
|
1021
|
+
const tx = createProxyPath(
|
|
1022
|
+
(pallet, name) => createTxEntry(
|
|
1023
|
+
pallet,
|
|
1024
|
+
name,
|
|
1025
|
+
chainDefinition.asset,
|
|
1026
|
+
chainHead,
|
|
1027
|
+
broadcast$,
|
|
1028
|
+
compatibilityHelper(
|
|
1029
|
+
runtime,
|
|
1030
|
+
(r) => r._getPalletChecksum(1 /* Tx */, pallet, name)
|
|
1031
|
+
)
|
|
1032
|
+
)
|
|
1033
|
+
);
|
|
1034
|
+
const event = createProxyPath(
|
|
1035
|
+
(pallet, name) => createEventEntry(
|
|
1036
|
+
pallet,
|
|
1037
|
+
name,
|
|
1038
|
+
chainHead,
|
|
1039
|
+
compatibilityHelper(
|
|
1040
|
+
runtime,
|
|
1041
|
+
(r) => r._getPalletChecksum(2 /* Event */, pallet, name)
|
|
1042
|
+
)
|
|
1043
|
+
)
|
|
1044
|
+
);
|
|
1045
|
+
const constants = createProxyPath(
|
|
1046
|
+
(pallet, name) => createConstantEntry(
|
|
1047
|
+
pallet,
|
|
1048
|
+
name,
|
|
1049
|
+
chainHead,
|
|
1050
|
+
compatibilityHelper(
|
|
1051
|
+
runtime,
|
|
1052
|
+
(r) => r._getPalletChecksum(4 /* Const */, pallet, name)
|
|
1053
|
+
)
|
|
1054
|
+
)
|
|
1055
|
+
);
|
|
1056
|
+
const apis = createProxyPath(
|
|
1057
|
+
(api, method) => createRuntimeCallEntry(
|
|
1058
|
+
api,
|
|
1059
|
+
method,
|
|
1060
|
+
chainHead,
|
|
1061
|
+
compatibilityHelper(runtime, (r) => r._getApiChecksum(api, method))
|
|
1062
|
+
)
|
|
1063
|
+
);
|
|
906
1064
|
return {
|
|
907
1065
|
query,
|
|
908
1066
|
tx,
|
|
909
|
-
event
|
|
1067
|
+
event,
|
|
910
1068
|
apis,
|
|
911
1069
|
constants,
|
|
912
|
-
runtime
|
|
1070
|
+
runtime
|
|
913
1071
|
};
|
|
914
1072
|
};
|
|
915
1073
|
function createClient(provider) {
|
|
916
1074
|
const rawClient = (0, import_substrate_client.createClient)(provider);
|
|
917
|
-
const client = (0,
|
|
1075
|
+
const client = (0, import_observable_client2.getObservableClient)(rawClient);
|
|
918
1076
|
const chainHead = client.chainHead$();
|
|
919
|
-
const createTxFromSigner = getCreateTx(chainHead);
|
|
920
|
-
const submitFns = getSubmitFns(chainHead, client);
|
|
921
|
-
const { submit, submit$: submitAndWatch } = submitFns;
|
|
922
1077
|
const { getChainSpecData } = rawClient;
|
|
1078
|
+
const _request = rawClient.request;
|
|
1079
|
+
const { broadcastTx$ } = client;
|
|
923
1080
|
return {
|
|
924
1081
|
getChainSpecData,
|
|
925
1082
|
finalizedBlock$: chainHead.finalized$,
|
|
926
|
-
getFinalizedBlock: () => (0,
|
|
1083
|
+
getFinalizedBlock: () => (0, import_rxjs22.firstValueFrom)(chainHead.finalized$),
|
|
927
1084
|
bestBlocks$: chainHead.bestBlocks$,
|
|
928
|
-
getBestBlocks: () => (0,
|
|
929
|
-
|
|
930
|
-
getBlockBody: (hash) => (0,
|
|
931
|
-
getBlockHeader: (hash) => (0,
|
|
932
|
-
submit,
|
|
933
|
-
submitAndWatch,
|
|
934
|
-
getTypedApi: (
|
|
1085
|
+
getBestBlocks: () => (0, import_rxjs22.firstValueFrom)(chainHead.bestBlocks$),
|
|
1086
|
+
watchBlockBody: chainHead.body$,
|
|
1087
|
+
getBlockBody: (hash) => (0, import_rxjs22.firstValueFrom)(chainHead.body$(hash)),
|
|
1088
|
+
getBlockHeader: (hash) => (0, import_rxjs22.firstValueFrom)(chainHead.header$(hash ?? null)),
|
|
1089
|
+
submit: (...args) => submit(chainHead, broadcastTx$, ...args),
|
|
1090
|
+
submitAndWatch: (...args) => submit$(chainHead, broadcastTx$, ...args),
|
|
1091
|
+
getTypedApi: (chainDefinition) => createTypedApi(chainDefinition, chainHead, broadcastTx$),
|
|
935
1092
|
destroy: () => {
|
|
936
1093
|
chainHead.unfollow();
|
|
937
1094
|
client.destroy();
|
|
938
|
-
}
|
|
1095
|
+
},
|
|
1096
|
+
_request
|
|
939
1097
|
};
|
|
940
1098
|
}
|
|
941
1099
|
|
|
942
1100
|
// src/re-exports.ts
|
|
943
|
-
var
|
|
1101
|
+
var import_substrate_bindings9 = require("@polkadot-api/substrate-bindings");
|
|
944
1102
|
//# sourceMappingURL=index.js.map
|