polkadot-api 0.0.0-prerelease-do-not-use
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/LICENSE +21 -0
- package/README.md +1 -0
- package/bin/cli.mjs +11 -0
- package/dist/index.d.mts +269 -0
- package/dist/index.d.ts +269 -0
- package/dist/index.js +916 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +929 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logs-provider/logs-provider.d.mts +1 -0
- package/dist/logs-provider/logs-provider.d.ts +1 -0
- package/dist/logs-provider/logs-provider.js +21 -0
- package/dist/logs-provider/logs-provider.js.map +1 -0
- package/dist/logs-provider/logs-provider.mjs +3 -0
- package/dist/logs-provider/logs-provider.mjs.map +1 -0
- package/dist/logs-provider/min/logs-provider.d.ts +1 -0
- package/dist/logs-provider/min/logs-provider.js +2 -0
- package/dist/logs-provider/min/logs-provider.js.map +1 -0
- package/dist/min/index.d.ts +269 -0
- package/dist/min/index.js +2 -0
- package/dist/min/index.js.map +1 -0
- package/dist/pjs-signer/min/pjs-signer.d.ts +1 -0
- package/dist/pjs-signer/min/pjs-signer.js +2 -0
- package/dist/pjs-signer/min/pjs-signer.js.map +1 -0
- package/dist/pjs-signer/pjs-signer.d.mts +1 -0
- package/dist/pjs-signer/pjs-signer.d.ts +1 -0
- package/dist/pjs-signer/pjs-signer.js +21 -0
- package/dist/pjs-signer/pjs-signer.js.map +1 -0
- package/dist/pjs-signer/pjs-signer.mjs +3 -0
- package/dist/pjs-signer/pjs-signer.mjs.map +1 -0
- package/dist/sc-provider/min/sc-provider.d.ts +1 -0
- package/dist/sc-provider/min/sc-provider.js +2 -0
- package/dist/sc-provider/min/sc-provider.js.map +1 -0
- package/dist/sc-provider/sc-provider.d.mts +1 -0
- package/dist/sc-provider/sc-provider.d.ts +1 -0
- package/dist/sc-provider/sc-provider.js +21 -0
- package/dist/sc-provider/sc-provider.js.map +1 -0
- package/dist/sc-provider/sc-provider.mjs +3 -0
- package/dist/sc-provider/sc-provider.mjs.map +1 -0
- package/dist/signer/min/signer.d.ts +1 -0
- package/dist/signer/min/signer.js +2 -0
- package/dist/signer/min/signer.js.map +1 -0
- package/dist/signer/signer.d.mts +1 -0
- package/dist/signer/signer.d.ts +1 -0
- package/dist/signer/signer.js +21 -0
- package/dist/signer/signer.js.map +1 -0
- package/dist/signer/signer.mjs +3 -0
- package/dist/signer/signer.mjs.map +1 -0
- package/dist/sm-provider/min/sm-provider.d.ts +1 -0
- package/dist/sm-provider/min/sm-provider.js +2 -0
- package/dist/sm-provider/min/sm-provider.js.map +1 -0
- package/dist/sm-provider/sm-provider.d.mts +1 -0
- package/dist/sm-provider/sm-provider.d.ts +1 -0
- package/dist/sm-provider/sm-provider.js +21 -0
- package/dist/sm-provider/sm-provider.js.map +1 -0
- package/dist/sm-provider/sm-provider.mjs +3 -0
- package/dist/sm-provider/sm-provider.mjs.map +1 -0
- package/dist/ws-provider-node/min/ws-provider-node.d.ts +1 -0
- package/dist/ws-provider-node/min/ws-provider-node.js +2 -0
- package/dist/ws-provider-node/min/ws-provider-node.js.map +1 -0
- package/dist/ws-provider-node/ws-provider-node.d.mts +1 -0
- package/dist/ws-provider-node/ws-provider-node.d.ts +1 -0
- package/dist/ws-provider-node/ws-provider-node.js +21 -0
- package/dist/ws-provider-node/ws-provider-node.js.map +1 -0
- package/dist/ws-provider-node/ws-provider-node.mjs +3 -0
- package/dist/ws-provider-node/ws-provider-node.mjs.map +1 -0
- package/dist/ws-provider-web/min/ws-provider-web.d.ts +1 -0
- package/dist/ws-provider-web/min/ws-provider-web.js +2 -0
- package/dist/ws-provider-web/min/ws-provider-web.js.map +1 -0
- package/dist/ws-provider-web/ws-provider-web.d.mts +1 -0
- package/dist/ws-provider-web/ws-provider-web.d.ts +1 -0
- package/dist/ws-provider-web/ws-provider-web.js +21 -0
- package/dist/ws-provider-web/ws-provider-web.js.map +1 -0
- package/dist/ws-provider-web/ws-provider-web.mjs +3 -0
- package/dist/ws-provider-web/ws-provider-web.mjs.map +1 -0
- package/logs-provider/package.json +8 -0
- package/package.json +192 -0
- package/pjs-signer/package.json +8 -0
- package/sc-provider/package.json +8 -0
- package/signer/package.json +8 -0
- package/sm-provider/package.json +8 -0
- package/ws-provider-node/package.json +8 -0
- package/ws-provider-web/package.json +8 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,916 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
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
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
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
|
+
|
|
25
|
+
// src/index.ts
|
|
26
|
+
var src_exports = {};
|
|
27
|
+
__export(src_exports, {
|
|
28
|
+
AccountId: () => import_substrate_bindings8.AccountId,
|
|
29
|
+
Binary: () => import_substrate_bindings8.Binary,
|
|
30
|
+
Enum: () => import_substrate_bindings8.Enum,
|
|
31
|
+
_Enum: () => import_substrate_bindings8._Enum,
|
|
32
|
+
createClient: () => createClient
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
|
|
36
|
+
// src/client.ts
|
|
37
|
+
var import_substrate_client = require("@polkadot-api/substrate-client");
|
|
38
|
+
var import_rxjs20 = require("rxjs");
|
|
39
|
+
|
|
40
|
+
// src/constants.ts
|
|
41
|
+
var import_rxjs2 = require("rxjs");
|
|
42
|
+
|
|
43
|
+
// src/runtime.ts
|
|
44
|
+
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
|
+
if (resolve) {
|
|
70
|
+
resolve(createRuntime(x, checksums2));
|
|
71
|
+
resolve = null;
|
|
72
|
+
} else {
|
|
73
|
+
latestRuntime = Promise.resolve(createRuntime(x, checksums2));
|
|
74
|
+
}
|
|
75
|
+
} else if (!resolve) {
|
|
76
|
+
latestRuntime = new Promise((res) => {
|
|
77
|
+
resolve = res;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
const result = runtimeWithChecksums$.pipe(
|
|
82
|
+
(0, import_rxjs.filter)(([x]) => Boolean(x)),
|
|
83
|
+
(0, import_rxjs.map)(([x, checksums2]) => createRuntime(x, checksums2))
|
|
84
|
+
);
|
|
85
|
+
result.latest = () => latestRuntime;
|
|
86
|
+
return result;
|
|
87
|
+
};
|
|
88
|
+
var compatibilityHelper = (runtimeApi, checksumIdx) => (getChecksum) => {
|
|
89
|
+
function isCompatibleSync(runtime) {
|
|
90
|
+
const ctx = getRuntimeContext(runtime);
|
|
91
|
+
const checksum = getImportedChecksum(runtime, checksumIdx);
|
|
92
|
+
return getChecksum(ctx) === checksum;
|
|
93
|
+
}
|
|
94
|
+
const isCompatible = (runtime) => {
|
|
95
|
+
if (runtime) {
|
|
96
|
+
return isCompatibleSync(runtime);
|
|
97
|
+
}
|
|
98
|
+
return runtimeApi.latest().then(isCompatibleSync);
|
|
99
|
+
};
|
|
100
|
+
const waitChecksums = async () => {
|
|
101
|
+
const runtime = await runtimeApi.latest();
|
|
102
|
+
return (ctx) => getChecksum(ctx) === getImportedChecksum(runtime, checksumIdx);
|
|
103
|
+
};
|
|
104
|
+
const compatibleRuntime$ = (chainHead, hash, error) => (0, import_rxjs.combineLatest)([chainHead.getRuntimeContext$(hash), waitChecksums()]).pipe(
|
|
105
|
+
(0, import_rxjs.map)(([ctx, isCompatible2]) => {
|
|
106
|
+
if (!isCompatible2(ctx)) {
|
|
107
|
+
throw error();
|
|
108
|
+
}
|
|
109
|
+
return ctx;
|
|
110
|
+
})
|
|
111
|
+
);
|
|
112
|
+
const withCompatibleRuntime = (chainHead, mapper, error) => (source$) => (0, import_rxjs.combineLatest)([
|
|
113
|
+
source$.pipe(chainHead.withRuntime(mapper)),
|
|
114
|
+
waitChecksums()
|
|
115
|
+
]).pipe(
|
|
116
|
+
(0, import_rxjs.map)(([[x, ctx], isCompatible2]) => {
|
|
117
|
+
if (!isCompatible2(ctx)) {
|
|
118
|
+
throw error();
|
|
119
|
+
}
|
|
120
|
+
return [x, ctx];
|
|
121
|
+
})
|
|
122
|
+
);
|
|
123
|
+
return {
|
|
124
|
+
isCompatible,
|
|
125
|
+
waitChecksums,
|
|
126
|
+
withCompatibleRuntime,
|
|
127
|
+
compatibleRuntime$
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// src/constants.ts
|
|
132
|
+
var createConstantEntry = (palletName, name, chainHead, compatibilityHelper2) => {
|
|
133
|
+
const { isCompatible, compatibleRuntime$ } = compatibilityHelper2(
|
|
134
|
+
(ctx) => ctx.checksumBuilder.buildConstant(palletName, name)
|
|
135
|
+
);
|
|
136
|
+
const checksumError = () => new Error(`Incompatible runtime entry Constant(${palletName}.${name})`);
|
|
137
|
+
const cachedResults = /* @__PURE__ */ new WeakMap();
|
|
138
|
+
const getValueWithContext = (ctx) => {
|
|
139
|
+
if (cachedResults.has(ctx)) {
|
|
140
|
+
return cachedResults.get(ctx);
|
|
141
|
+
}
|
|
142
|
+
const pallet = ctx.metadata.pallets.find((p) => p.name === palletName);
|
|
143
|
+
const constant = pallet?.constants.find((c) => c.name === name);
|
|
144
|
+
const result = ctx.dynamicBuilder.buildConstant(palletName, name).dec(constant.value);
|
|
145
|
+
cachedResults.set(ctx, result);
|
|
146
|
+
return result;
|
|
147
|
+
};
|
|
148
|
+
const fn = (runtime) => {
|
|
149
|
+
if (runtime) {
|
|
150
|
+
if (!isCompatible(runtime))
|
|
151
|
+
throw checksumError();
|
|
152
|
+
return getValueWithContext(getRuntimeContext(runtime));
|
|
153
|
+
}
|
|
154
|
+
return (0, import_rxjs2.firstValueFrom)(
|
|
155
|
+
compatibleRuntime$(chainHead, null, checksumError).pipe(
|
|
156
|
+
(0, import_rxjs2.map)(getValueWithContext)
|
|
157
|
+
)
|
|
158
|
+
);
|
|
159
|
+
};
|
|
160
|
+
return Object.assign(fn, { isCompatible });
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// src/event.ts
|
|
164
|
+
var import_rxjs7 = require("rxjs");
|
|
165
|
+
|
|
166
|
+
// src/utils/shareLatest.ts
|
|
167
|
+
var import_rxjs3 = require("rxjs");
|
|
168
|
+
var shareLatest = (0, import_rxjs3.share)({
|
|
169
|
+
connector: () => new import_rxjs3.ReplaySubject(1),
|
|
170
|
+
resetOnError: true,
|
|
171
|
+
resetOnComplete: true,
|
|
172
|
+
resetOnRefCountZero: true
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// src/utils/firstValueFromWithSignal.ts
|
|
176
|
+
var import_utils = require("@polkadot-api/utils");
|
|
177
|
+
var import_rxjs4 = require("rxjs");
|
|
178
|
+
function firstValueFromWithSignal(source, signal) {
|
|
179
|
+
return new Promise((resolve, reject) => {
|
|
180
|
+
let subscription = null;
|
|
181
|
+
let isDone = false;
|
|
182
|
+
const onAbort = signal ? () => {
|
|
183
|
+
subscription?.unsubscribe();
|
|
184
|
+
reject(new import_utils.AbortError());
|
|
185
|
+
} : import_rxjs4.noop;
|
|
186
|
+
subscription = source.subscribe({
|
|
187
|
+
next: (value) => {
|
|
188
|
+
resolve(value);
|
|
189
|
+
subscription?.unsubscribe();
|
|
190
|
+
isDone = true;
|
|
191
|
+
},
|
|
192
|
+
error: (e) => {
|
|
193
|
+
signal?.removeEventListener("abort", onAbort);
|
|
194
|
+
reject(e);
|
|
195
|
+
},
|
|
196
|
+
complete: () => {
|
|
197
|
+
signal?.removeEventListener("abort", onAbort);
|
|
198
|
+
reject(new Error("Observable completed without emitting"));
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
if (!isDone)
|
|
202
|
+
signal?.addEventListener("abort", onAbort);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// src/utils/concatMapEager.ts
|
|
207
|
+
var import_rxjs5 = require("rxjs");
|
|
208
|
+
var concatMapEager = (mapper, concurrent = Infinity) => (source$) => new import_rxjs5.Observable((observer) => {
|
|
209
|
+
let topSubscription;
|
|
210
|
+
const queues = /* @__PURE__ */ new Map();
|
|
211
|
+
const innerSubscriptions = /* @__PURE__ */ new Map();
|
|
212
|
+
const results = /* @__PURE__ */ new Map();
|
|
213
|
+
let mapperIdx = 0;
|
|
214
|
+
let subscriptionIdx = 0;
|
|
215
|
+
let observerIdx = 0;
|
|
216
|
+
const nextSubscription = () => {
|
|
217
|
+
const inner$ = queues.get(subscriptionIdx);
|
|
218
|
+
if (!inner$) {
|
|
219
|
+
if (innerSubscriptions.size === 0 && (typeof topSubscription === "undefined" || topSubscription.closed)) {
|
|
220
|
+
observer.complete();
|
|
221
|
+
}
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const idx = subscriptionIdx++;
|
|
225
|
+
queues.delete(idx);
|
|
226
|
+
if (observerIdx !== idx) {
|
|
227
|
+
results.set(idx, []);
|
|
228
|
+
}
|
|
229
|
+
innerSubscriptions.set(
|
|
230
|
+
idx,
|
|
231
|
+
inner$.subscribe({
|
|
232
|
+
next(x) {
|
|
233
|
+
if (observerIdx === idx) {
|
|
234
|
+
observer.next(x);
|
|
235
|
+
} else {
|
|
236
|
+
results.get(idx).push(x);
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
complete() {
|
|
240
|
+
innerSubscriptions.delete(idx);
|
|
241
|
+
if (idx === observerIdx) {
|
|
242
|
+
observerIdx++;
|
|
243
|
+
while (results.has(observerIdx)) {
|
|
244
|
+
results.get(observerIdx).forEach((x) => observer.next(x));
|
|
245
|
+
results.delete(observerIdx);
|
|
246
|
+
if (innerSubscriptions.has(observerIdx)) {
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
observerIdx++;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
nextSubscription();
|
|
253
|
+
},
|
|
254
|
+
error(e) {
|
|
255
|
+
observer.error(e);
|
|
256
|
+
}
|
|
257
|
+
})
|
|
258
|
+
);
|
|
259
|
+
};
|
|
260
|
+
topSubscription = source$.subscribe({
|
|
261
|
+
next(outterValue) {
|
|
262
|
+
const idx = mapperIdx++;
|
|
263
|
+
queues.set(
|
|
264
|
+
idx,
|
|
265
|
+
(0, import_rxjs5.defer)(() => mapper(outterValue, idx))
|
|
266
|
+
);
|
|
267
|
+
if (innerSubscriptions.size < concurrent) {
|
|
268
|
+
nextSubscription();
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
error(e) {
|
|
272
|
+
observer.error(e);
|
|
273
|
+
},
|
|
274
|
+
complete() {
|
|
275
|
+
if (innerSubscriptions.size === 0) {
|
|
276
|
+
observer.complete();
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
return () => {
|
|
281
|
+
innerSubscriptions.forEach((subscription) => subscription.unsubscribe());
|
|
282
|
+
topSubscription.unsubscribe();
|
|
283
|
+
queues.clear();
|
|
284
|
+
results.clear();
|
|
285
|
+
};
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
// src/utils/lossLessExhaustMap.ts
|
|
289
|
+
var import_rxjs6 = require("rxjs");
|
|
290
|
+
var EMPTY_VALUE = Symbol("EMPTY_VALUE");
|
|
291
|
+
var lossLessExhaustMap = (mapper) => (source$) => new import_rxjs6.Observable((observer) => {
|
|
292
|
+
let innerSubscription = null;
|
|
293
|
+
let queuedValue = EMPTY_VALUE;
|
|
294
|
+
let isOutterDone = false;
|
|
295
|
+
const setInnerSubscription = () => {
|
|
296
|
+
const observable = mapper(queuedValue);
|
|
297
|
+
queuedValue = EMPTY_VALUE;
|
|
298
|
+
innerSubscription = observable.subscribe({
|
|
299
|
+
next(vv) {
|
|
300
|
+
observer.next(vv);
|
|
301
|
+
},
|
|
302
|
+
error(ee) {
|
|
303
|
+
observer.error(ee);
|
|
304
|
+
},
|
|
305
|
+
complete() {
|
|
306
|
+
if (queuedValue !== EMPTY_VALUE)
|
|
307
|
+
setInnerSubscription();
|
|
308
|
+
else {
|
|
309
|
+
innerSubscription = null;
|
|
310
|
+
if (isOutterDone)
|
|
311
|
+
observer.complete();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
const subscription = source$.subscribe({
|
|
317
|
+
next(v) {
|
|
318
|
+
queuedValue = v;
|
|
319
|
+
if (!innerSubscription)
|
|
320
|
+
setInnerSubscription();
|
|
321
|
+
},
|
|
322
|
+
error(e) {
|
|
323
|
+
observer.error(e);
|
|
324
|
+
},
|
|
325
|
+
complete() {
|
|
326
|
+
if (!innerSubscription)
|
|
327
|
+
observer.complete();
|
|
328
|
+
isOutterDone = true;
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
return () => {
|
|
332
|
+
innerSubscription?.unsubscribe();
|
|
333
|
+
subscription.unsubscribe();
|
|
334
|
+
};
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
// src/event.ts
|
|
338
|
+
var createEventEntry = (pallet, name, chainHead, compatibilityHelper2) => {
|
|
339
|
+
const { isCompatible, withCompatibleRuntime } = compatibilityHelper2(
|
|
340
|
+
(ctx) => ctx.checksumBuilder.buildEvent(pallet, name)
|
|
341
|
+
);
|
|
342
|
+
const checksumError = () => new Error(`Incompatible runtime entry Event(${pallet}.${name})`);
|
|
343
|
+
const shared$ = chainHead.finalized$.pipe(
|
|
344
|
+
withCompatibleRuntime(chainHead, (x) => x.hash, checksumError),
|
|
345
|
+
concatMapEager(
|
|
346
|
+
([block]) => chainHead.eventsAt$(block.hash).pipe(
|
|
347
|
+
(0, import_rxjs7.map)((events) => {
|
|
348
|
+
const winners = events.filter(
|
|
349
|
+
(e) => e.event.type === pallet && e.event.value.type === name
|
|
350
|
+
);
|
|
351
|
+
return winners.map((x) => {
|
|
352
|
+
return {
|
|
353
|
+
meta: {
|
|
354
|
+
phase: x.phase,
|
|
355
|
+
block
|
|
356
|
+
},
|
|
357
|
+
payload: x.event.value.value
|
|
358
|
+
};
|
|
359
|
+
});
|
|
360
|
+
})
|
|
361
|
+
)
|
|
362
|
+
),
|
|
363
|
+
shareLatest
|
|
364
|
+
);
|
|
365
|
+
const watch = (f) => shared$.pipe((0, import_rxjs7.mergeMap)((x) => f ? x.filter((d) => f(d.payload)) : x));
|
|
366
|
+
const pull = () => (0, import_rxjs7.firstValueFrom)(shared$);
|
|
367
|
+
const filter2 = (events) => events.filter((e) => e.type === pallet && e.value.type === name).map((x) => x.value.value);
|
|
368
|
+
return { watch, pull, filter: filter2, isCompatible };
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
// src/client.ts
|
|
372
|
+
var import_observable_client = require("@polkadot-api/observable-client");
|
|
373
|
+
|
|
374
|
+
// src/runtime-call.ts
|
|
375
|
+
var import_utils4 = require("@polkadot-api/utils");
|
|
376
|
+
var import_rxjs8 = require("rxjs");
|
|
377
|
+
var isOptionalArg = (lastArg) => {
|
|
378
|
+
if (typeof lastArg !== "object")
|
|
379
|
+
return false;
|
|
380
|
+
return Object.keys(lastArg).every(
|
|
381
|
+
(k) => k === "at" && typeof lastArg.at === "string" || k === "signal" && lastArg.signal instanceof AbortSignal
|
|
382
|
+
);
|
|
383
|
+
};
|
|
384
|
+
var createRuntimeCallEntry = (api, method, chainHead, compatibilityHelper2) => {
|
|
385
|
+
const { isCompatible, compatibleRuntime$ } = compatibilityHelper2(
|
|
386
|
+
(ctx) => ctx.checksumBuilder.buildRuntimeCall(api, method)
|
|
387
|
+
);
|
|
388
|
+
const callName = `${api}_${method}`;
|
|
389
|
+
const checksumError = () => new Error(`Incompatible runtime entry RuntimeCall(${callName})`);
|
|
390
|
+
const fn = (...args) => {
|
|
391
|
+
const lastArg = args[args.length - 1];
|
|
392
|
+
const isLastArgOptional = isOptionalArg(lastArg);
|
|
393
|
+
const { signal, at: _at } = isLastArgOptional ? lastArg : {};
|
|
394
|
+
const at = _at ?? null;
|
|
395
|
+
const result$ = compatibleRuntime$(chainHead, at, checksumError).pipe(
|
|
396
|
+
(0, import_rxjs8.mergeMap)((ctx) => {
|
|
397
|
+
const codecs = ctx.dynamicBuilder.buildRuntimeCall(api, method);
|
|
398
|
+
return chainHead.call$(at, callName, (0, import_utils4.toHex)(codecs.args.enc(args))).pipe((0, import_rxjs8.map)(codecs.value.dec));
|
|
399
|
+
})
|
|
400
|
+
);
|
|
401
|
+
return firstValueFromWithSignal(result$, signal);
|
|
402
|
+
};
|
|
403
|
+
return Object.assign(fn, { isCompatible });
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
// src/storage.ts
|
|
407
|
+
var import_rxjs9 = require("rxjs");
|
|
408
|
+
var isOptionalArg2 = (lastArg) => {
|
|
409
|
+
if (typeof lastArg !== "object")
|
|
410
|
+
return false;
|
|
411
|
+
return Object.keys(lastArg).every(
|
|
412
|
+
(k) => k === "at" && typeof lastArg.at === "string" || k === "signal" && lastArg.signal instanceof AbortSignal
|
|
413
|
+
);
|
|
414
|
+
};
|
|
415
|
+
var createStorageEntry = (pallet, name, chainHead, compatibilityHelper2) => {
|
|
416
|
+
const { isCompatible, waitChecksums, withCompatibleRuntime } = compatibilityHelper2((ctx) => ctx.checksumBuilder.buildStorage(pallet, name));
|
|
417
|
+
const checksumError = () => new Error(`Incompatible runtime entry Storage(${pallet}.${name})`);
|
|
418
|
+
const invalidArgs = (args) => new Error(`Invalid Arguments calling ${pallet}.${name}(${args})`);
|
|
419
|
+
const watchValue = (...args) => {
|
|
420
|
+
const lastArg = args[args.length - 1];
|
|
421
|
+
const actualArgs = lastArg === "best" || lastArg === "finalized" ? args.slice(0, -1) : args;
|
|
422
|
+
return chainHead[lastArg === "best" ? "best$" : "finalized$"].pipe(
|
|
423
|
+
(0, import_rxjs9.debounceTime)(0),
|
|
424
|
+
withCompatibleRuntime(chainHead, (x) => x.hash, checksumError),
|
|
425
|
+
lossLessExhaustMap(([block, ctx]) => {
|
|
426
|
+
const codecs = ctx.dynamicBuilder.buildStorage(pallet, name);
|
|
427
|
+
return chainHead.storage$(block.hash, "value", () => codecs.enc(...actualArgs)).pipe((0, import_rxjs9.map)((val) => ({ val, codecs })));
|
|
428
|
+
}),
|
|
429
|
+
(0, import_rxjs9.distinctUntilChanged)((a, b) => a.val === b.val),
|
|
430
|
+
(0, import_rxjs9.map)(
|
|
431
|
+
({ val, codecs }) => val === null ? codecs.fallback : codecs.dec(val)
|
|
432
|
+
)
|
|
433
|
+
);
|
|
434
|
+
};
|
|
435
|
+
const getValue = async (...args) => {
|
|
436
|
+
const lastArg = args[args.length - 1];
|
|
437
|
+
const isLastArgOptional = isOptionalArg2(lastArg);
|
|
438
|
+
const { signal, at: _at } = isLastArgOptional ? lastArg : {};
|
|
439
|
+
const at = _at ?? null;
|
|
440
|
+
const isCompatible2 = await waitChecksums();
|
|
441
|
+
const result$ = chainHead.storage$(
|
|
442
|
+
at,
|
|
443
|
+
"value",
|
|
444
|
+
(ctx) => {
|
|
445
|
+
const codecs = ctx.dynamicBuilder.buildStorage(pallet, name);
|
|
446
|
+
const actualArgs = args.length === codecs.len ? args : args.slice(0, -1);
|
|
447
|
+
if (args !== actualArgs && !isLastArgOptional)
|
|
448
|
+
throw invalidArgs(args);
|
|
449
|
+
if (!isCompatible2(ctx))
|
|
450
|
+
throw checksumError();
|
|
451
|
+
return codecs.enc(...actualArgs);
|
|
452
|
+
},
|
|
453
|
+
null,
|
|
454
|
+
(data, ctx) => {
|
|
455
|
+
const codecs = ctx.dynamicBuilder.buildStorage(pallet, name);
|
|
456
|
+
return data === null ? codecs.fallback : codecs.dec(data);
|
|
457
|
+
}
|
|
458
|
+
);
|
|
459
|
+
return firstValueFromWithSignal(result$, signal);
|
|
460
|
+
};
|
|
461
|
+
const getEntries = async (...args) => {
|
|
462
|
+
const lastArg = args[args.length - 1];
|
|
463
|
+
const isLastArgOptional = isOptionalArg2(lastArg);
|
|
464
|
+
const { signal, at: _at } = isLastArgOptional ? lastArg : {};
|
|
465
|
+
const at = _at ?? null;
|
|
466
|
+
const isCompatible2 = await waitChecksums();
|
|
467
|
+
const result$ = chainHead.storage$(
|
|
468
|
+
at,
|
|
469
|
+
"descendantsValues",
|
|
470
|
+
(ctx) => {
|
|
471
|
+
const codecs = ctx.dynamicBuilder.buildStorage(pallet, name);
|
|
472
|
+
if (args.length > codecs.len)
|
|
473
|
+
throw invalidArgs(args);
|
|
474
|
+
const actualArgs = args.length > 0 && isLastArgOptional ? args.slice(0, -1) : args;
|
|
475
|
+
if (args.length === codecs.len && actualArgs === args)
|
|
476
|
+
throw invalidArgs(args);
|
|
477
|
+
if (!isCompatible2(ctx))
|
|
478
|
+
throw checksumError();
|
|
479
|
+
return codecs.enc(...actualArgs);
|
|
480
|
+
},
|
|
481
|
+
null,
|
|
482
|
+
(values, ctx) => {
|
|
483
|
+
const codecs = ctx.dynamicBuilder.buildStorage(pallet, name);
|
|
484
|
+
return values.map(({ key, value }) => ({
|
|
485
|
+
keyArgs: codecs.keyDecoder(key),
|
|
486
|
+
value: codecs.dec(value)
|
|
487
|
+
}));
|
|
488
|
+
}
|
|
489
|
+
);
|
|
490
|
+
return firstValueFromWithSignal(result$, signal);
|
|
491
|
+
};
|
|
492
|
+
const getValues = (keyArgs, options) => Promise.all(
|
|
493
|
+
keyArgs.map((args) => getValue(...options ? [...args, options] : args))
|
|
494
|
+
);
|
|
495
|
+
return { isCompatible, getValue, getValues, getEntries, watchValue };
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
// src/tx.ts
|
|
499
|
+
var import_substrate_bindings = require("@polkadot-api/substrate-bindings");
|
|
500
|
+
var import_utils6 = require("@polkadot-api/utils");
|
|
501
|
+
var import_rxjs10 = require("rxjs");
|
|
502
|
+
var getTxSuccessFromSystemEvents = (systemEvents, txIdx) => {
|
|
503
|
+
const events = systemEvents.filter((x) => x.phase.type === "ApplyExtrinsic" && x.phase.value === txIdx).map((x) => x.event);
|
|
504
|
+
const lastEvent = events[events.length - 1];
|
|
505
|
+
const ok = lastEvent.type === "System" && lastEvent.value.type === "ExtrinsicSuccess";
|
|
506
|
+
return { ok, events };
|
|
507
|
+
};
|
|
508
|
+
var getSubmitFns = (chainHead, client) => {
|
|
509
|
+
const tx$ = (tx) => (0, import_rxjs10.concat)(
|
|
510
|
+
chainHead.finalized$.pipe(
|
|
511
|
+
(0, import_rxjs10.take)(1),
|
|
512
|
+
(0, import_rxjs10.mergeMap)((finalized) => chainHead.validateTx$(tx, finalized.hash)),
|
|
513
|
+
(0, import_rxjs10.map)((isValid) => {
|
|
514
|
+
if (!isValid)
|
|
515
|
+
throw new Error("Invalid");
|
|
516
|
+
return { type: "broadcasted" };
|
|
517
|
+
})
|
|
518
|
+
),
|
|
519
|
+
new import_rxjs10.Observable((observer) => {
|
|
520
|
+
const subscription = chainHead.trackTx$(tx).subscribe(observer);
|
|
521
|
+
subscription.add(
|
|
522
|
+
client.broadcastTx$(tx).subscribe({
|
|
523
|
+
error(e) {
|
|
524
|
+
observer.error(e);
|
|
525
|
+
}
|
|
526
|
+
})
|
|
527
|
+
);
|
|
528
|
+
return subscription;
|
|
529
|
+
})
|
|
530
|
+
);
|
|
531
|
+
const submit$ = (transaction) => tx$(transaction).pipe(
|
|
532
|
+
(0, import_rxjs10.mergeMap)((result) => {
|
|
533
|
+
return result.type !== "finalized" ? (0, import_rxjs10.of)(result) : chainHead.eventsAt$(result.block.hash).pipe(
|
|
534
|
+
(0, import_rxjs10.map)((events) => ({
|
|
535
|
+
...result,
|
|
536
|
+
...getTxSuccessFromSystemEvents(
|
|
537
|
+
events,
|
|
538
|
+
Number(result.block.index)
|
|
539
|
+
)
|
|
540
|
+
}))
|
|
541
|
+
);
|
|
542
|
+
})
|
|
543
|
+
);
|
|
544
|
+
const submit = async (transaction) => (0, import_rxjs10.lastValueFrom)(submit$(transaction)).then((x) => {
|
|
545
|
+
if (x.type !== "finalized")
|
|
546
|
+
throw null;
|
|
547
|
+
const result = { ...x };
|
|
548
|
+
delete result.type;
|
|
549
|
+
return result;
|
|
550
|
+
});
|
|
551
|
+
return { submit$, submit };
|
|
552
|
+
};
|
|
553
|
+
var createTxEntry = (pallet, name, assetChecksum, chainHead, submits, signer, compatibilityHelper2) => {
|
|
554
|
+
const { isCompatible, compatibleRuntime$ } = compatibilityHelper2(
|
|
555
|
+
(ctx) => ctx.checksumBuilder.buildCall(pallet, name)
|
|
556
|
+
);
|
|
557
|
+
const checksumError = () => new Error(`Incompatible runtime entry Tx(${pallet}.${name})`);
|
|
558
|
+
const fn = (arg) => {
|
|
559
|
+
const getCallDataWithContext = ({ dynamicBuilder, asset: [assetEnc, assetCheck] }, arg2, hinted = {}) => {
|
|
560
|
+
let returnHinted = hinted;
|
|
561
|
+
if (hinted.asset) {
|
|
562
|
+
if (assetChecksum !== assetCheck)
|
|
563
|
+
throw new Error(`Incompatible runtime asset`);
|
|
564
|
+
returnHinted = { ...hinted, asset: assetEnc(hinted.asset) };
|
|
565
|
+
}
|
|
566
|
+
const { location, codec } = dynamicBuilder.buildCall(pallet, name);
|
|
567
|
+
return {
|
|
568
|
+
callData: import_substrate_bindings.Binary.fromBytes(
|
|
569
|
+
(0, import_utils6.mergeUint8)(new Uint8Array(location), codec.enc(arg2))
|
|
570
|
+
),
|
|
571
|
+
hinted: returnHinted
|
|
572
|
+
};
|
|
573
|
+
};
|
|
574
|
+
const getCallData$ = (arg2, hinted = {}) => compatibleRuntime$(chainHead, null, checksumError).pipe(
|
|
575
|
+
(0, import_rxjs10.map)((ctx) => getCallDataWithContext(ctx, arg2, hinted))
|
|
576
|
+
);
|
|
577
|
+
const getEncodedData = (runtime) => {
|
|
578
|
+
if (runtime) {
|
|
579
|
+
if (!isCompatible(runtime)) {
|
|
580
|
+
throw checksumError();
|
|
581
|
+
}
|
|
582
|
+
return getCallDataWithContext(getRuntimeContext(runtime), arg).callData;
|
|
583
|
+
}
|
|
584
|
+
return (0, import_rxjs10.firstValueFrom)(getCallData$(arg).pipe((0, import_rxjs10.map)((x) => x.callData)));
|
|
585
|
+
};
|
|
586
|
+
const sign$ = (from, _hinted) => getCallData$(arg, _hinted).pipe(
|
|
587
|
+
(0, import_rxjs10.withLatestFrom)(chainHead.finalized$),
|
|
588
|
+
(0, import_rxjs10.take)(1),
|
|
589
|
+
(0, import_rxjs10.mergeMap)(
|
|
590
|
+
([{ callData, hinted }, finalized]) => signer(from, callData.asBytes(), finalized, hinted)
|
|
591
|
+
)
|
|
592
|
+
);
|
|
593
|
+
const sign = (from, _hinted) => (0, import_rxjs10.firstValueFrom)(sign$(from, _hinted)).then(import_utils6.toHex);
|
|
594
|
+
const signAndSubmit = (from, _hinted) => sign(from, _hinted).then(submits.submit);
|
|
595
|
+
const signSubmitAndWatch = (from, _hinted) => sign$(from, _hinted).pipe(
|
|
596
|
+
(0, import_rxjs10.mergeMap)((result) => {
|
|
597
|
+
const tx = (0, import_utils6.toHex)(result);
|
|
598
|
+
return submits.submit$(tx).pipe((0, import_rxjs10.startWith)({ type: "signed", tx }));
|
|
599
|
+
})
|
|
600
|
+
);
|
|
601
|
+
return {
|
|
602
|
+
decodedCall: (0, import_substrate_bindings.Enum)(pallet, (0, import_substrate_bindings.Enum)(name, arg)),
|
|
603
|
+
getEncodedData,
|
|
604
|
+
sign,
|
|
605
|
+
signSubmitAndWatch,
|
|
606
|
+
signAndSubmit
|
|
607
|
+
};
|
|
608
|
+
};
|
|
609
|
+
return Object.assign(fn, { isCompatible });
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
// src/get-create-tx.ts
|
|
613
|
+
var import_rxjs19 = require("rxjs");
|
|
614
|
+
|
|
615
|
+
// src/signed-extensions/user/ChargeTransactionPayment.ts
|
|
616
|
+
var import_substrate_bindings3 = require("@polkadot-api/substrate-bindings");
|
|
617
|
+
var import_rxjs12 = require("rxjs");
|
|
618
|
+
|
|
619
|
+
// src/signed-extensions/utils.ts
|
|
620
|
+
var import_rxjs11 = require("rxjs");
|
|
621
|
+
var import_substrate_bindings2 = require("@polkadot-api/substrate-bindings");
|
|
622
|
+
var import_metadata_builders = require("@polkadot-api/metadata-builders");
|
|
623
|
+
var import_utils7 = require("@polkadot-api/utils");
|
|
624
|
+
var empty = new Uint8Array();
|
|
625
|
+
var genesisHashStorageKey = (0, import_substrate_bindings2.Storage)("System")("BlockHash", import_rxjs11.noop, [
|
|
626
|
+
import_substrate_bindings2.u32,
|
|
627
|
+
import_substrate_bindings2.Twox64Concat
|
|
628
|
+
]).enc(0);
|
|
629
|
+
var genesisHashFromCtx = (ctx) => ctx.chainHead.storage$(ctx.at, "value", () => genesisHashStorageKey, null).pipe((0, import_rxjs11.map)((result) => (0, import_utils7.fromHex)(result)));
|
|
630
|
+
var systemVersionProp$ = (propName, metadata) => {
|
|
631
|
+
const lookupFn = (0, import_metadata_builders.getLookupFn)(metadata.lookup);
|
|
632
|
+
const dynamicBuilder = (0, import_metadata_builders.getDynamicBuilder)(metadata);
|
|
633
|
+
const constant = metadata.pallets.find((x) => x.name === "System").constants.find((s) => s.name === "Version");
|
|
634
|
+
const systemVersion = lookupFn(constant.type);
|
|
635
|
+
const systemVersionDec = dynamicBuilder.buildDefinition(constant.type).dec;
|
|
636
|
+
if (systemVersion.type !== "struct")
|
|
637
|
+
throw new Error("not a struct");
|
|
638
|
+
const valueEnc = dynamicBuilder.buildDefinition(
|
|
639
|
+
systemVersion.value[propName].id
|
|
640
|
+
).enc;
|
|
641
|
+
return (0, import_rxjs11.of)(valueEnc(systemVersionDec(constant.value)[propName]));
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
// src/signed-extensions/user/ChargeTransactionPayment.ts
|
|
645
|
+
var ChargeTransactionPayment = (tip) => (0, import_rxjs12.of)({
|
|
646
|
+
value: import_substrate_bindings3.compactBn.enc(tip),
|
|
647
|
+
additionalSigned: empty
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
// src/signed-extensions/user/CheckMortality.ts
|
|
651
|
+
var import_rxjs13 = require("rxjs");
|
|
652
|
+
var import_substrate_bindings4 = require("@polkadot-api/substrate-bindings");
|
|
653
|
+
var import_utils9 = require("@polkadot-api/utils");
|
|
654
|
+
function trailingZeroes(n) {
|
|
655
|
+
let i = 0;
|
|
656
|
+
while (!(n & 1)) {
|
|
657
|
+
i++;
|
|
658
|
+
n >>= 1;
|
|
659
|
+
}
|
|
660
|
+
return i;
|
|
661
|
+
}
|
|
662
|
+
var mortal = (0, import_substrate_bindings4.enhanceEncoder)(
|
|
663
|
+
(0, import_substrate_bindings4.Bytes)(2).enc,
|
|
664
|
+
(value) => {
|
|
665
|
+
const factor = Math.max(value.period >> 12, 1);
|
|
666
|
+
const left = Math.min(Math.max(trailingZeroes(value.period) - 1, 1), 15);
|
|
667
|
+
const right = value.phase / factor << 4;
|
|
668
|
+
return import_substrate_bindings4.u16.enc(left | right);
|
|
669
|
+
}
|
|
670
|
+
);
|
|
671
|
+
var zero = new Uint8Array([0]);
|
|
672
|
+
var CheckMortality = (input, ctx) => {
|
|
673
|
+
if (!input)
|
|
674
|
+
return genesisHashFromCtx(ctx).pipe(
|
|
675
|
+
(0, import_rxjs13.map)((additionalSigned) => ({
|
|
676
|
+
additionalSigned,
|
|
677
|
+
value: zero
|
|
678
|
+
}))
|
|
679
|
+
);
|
|
680
|
+
const { period, blockNumber } = input;
|
|
681
|
+
return (0, import_rxjs13.of)({
|
|
682
|
+
additionalSigned: (0, import_utils9.fromHex)(ctx.at),
|
|
683
|
+
value: mortal({
|
|
684
|
+
period,
|
|
685
|
+
phase: blockNumber % period
|
|
686
|
+
})
|
|
687
|
+
});
|
|
688
|
+
};
|
|
689
|
+
|
|
690
|
+
// src/signed-extensions/user/ChargeAssetTxPayment.ts
|
|
691
|
+
var import_rxjs14 = require("rxjs");
|
|
692
|
+
var import_substrate_bindings5 = require("@polkadot-api/substrate-bindings");
|
|
693
|
+
var encoder = (0, import_substrate_bindings5.Struct)({
|
|
694
|
+
tip: import_substrate_bindings5.compact,
|
|
695
|
+
asset: (0, import_substrate_bindings5.Option)((0, import_substrate_bindings5.Bytes)(Infinity))
|
|
696
|
+
}).enc;
|
|
697
|
+
var ChargeAssetTxPayment = (tip, asset) => (0, import_rxjs14.of)({
|
|
698
|
+
value: encoder({
|
|
699
|
+
tip,
|
|
700
|
+
asset
|
|
701
|
+
}),
|
|
702
|
+
additionalSigned: empty
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
// src/signed-extensions/chain/index.ts
|
|
706
|
+
var chain_exports = {};
|
|
707
|
+
__export(chain_exports, {
|
|
708
|
+
CheckGenesis: () => CheckGenesis,
|
|
709
|
+
CheckNonce: () => CheckNonce,
|
|
710
|
+
CheckSpecVersion: () => CheckSpecVersion,
|
|
711
|
+
CheckTxVersion: () => CheckTxVersion
|
|
712
|
+
});
|
|
713
|
+
|
|
714
|
+
// src/signed-extensions/chain/CheckGenesis.ts
|
|
715
|
+
var import_rxjs15 = require("rxjs");
|
|
716
|
+
var CheckGenesis = (ctx) => genesisHashFromCtx(ctx).pipe(
|
|
717
|
+
(0, import_rxjs15.map)((additionalSigned) => ({ value: empty, additionalSigned }))
|
|
718
|
+
);
|
|
719
|
+
|
|
720
|
+
// src/signed-extensions/chain/CheckNonce.ts
|
|
721
|
+
var import_rxjs16 = require("rxjs");
|
|
722
|
+
var import_substrate_bindings6 = require("@polkadot-api/substrate-bindings");
|
|
723
|
+
var import_utils14 = require("@polkadot-api/utils");
|
|
724
|
+
var lenToDecoder = {
|
|
725
|
+
1: import_substrate_bindings6.u8.dec,
|
|
726
|
+
2: import_substrate_bindings6.u16.dec,
|
|
727
|
+
4: import_substrate_bindings6.u32.dec,
|
|
728
|
+
8: import_substrate_bindings6.u64.dec
|
|
729
|
+
};
|
|
730
|
+
var CheckNonce = (ctx) => ctx.chainHead.call$(ctx.at, "AccountNonceApi_account_nonce", (0, import_utils14.toHex)(ctx.from)).pipe(
|
|
731
|
+
(0, import_rxjs16.map)((result) => {
|
|
732
|
+
const bytes = (0, import_utils14.fromHex)(result);
|
|
733
|
+
const decoder = lenToDecoder[bytes.length];
|
|
734
|
+
if (!decoder)
|
|
735
|
+
throw new Error("AccountNonceApi_account_nonce retrieved wrong data");
|
|
736
|
+
return import_substrate_bindings6.compact.enc(decoder(bytes));
|
|
737
|
+
}),
|
|
738
|
+
(0, import_rxjs16.map)((value) => ({ value, additionalSigned: empty }))
|
|
739
|
+
);
|
|
740
|
+
|
|
741
|
+
// src/signed-extensions/chain/CheckSpecVersion.ts
|
|
742
|
+
var import_rxjs17 = require("rxjs");
|
|
743
|
+
var CheckSpecVersion = ({ metadata }) => systemVersionProp$("spec_version", metadata).pipe(
|
|
744
|
+
(0, import_rxjs17.map)((additionalSigned) => ({ additionalSigned, value: empty }))
|
|
745
|
+
);
|
|
746
|
+
|
|
747
|
+
// src/signed-extensions/chain/CheckTxVersion.ts
|
|
748
|
+
var import_rxjs18 = require("rxjs");
|
|
749
|
+
var CheckTxVersion = ({ metadata }) => systemVersionProp$("transaction_version", metadata).pipe(
|
|
750
|
+
(0, import_rxjs18.map)((additionalSigned) => ({ additionalSigned, value: empty }))
|
|
751
|
+
);
|
|
752
|
+
|
|
753
|
+
// src/get-create-tx.ts
|
|
754
|
+
var import_substrate_bindings7 = require("@polkadot-api/substrate-bindings");
|
|
755
|
+
var getCreateTx = (chainHead) => {
|
|
756
|
+
return (signer, callData, atBlock, hinted) => {
|
|
757
|
+
return chainHead.getRuntimeContext$(atBlock.hash).pipe(
|
|
758
|
+
(0, import_rxjs19.take)(1),
|
|
759
|
+
(0, import_rxjs19.mergeMap)((ctx) => {
|
|
760
|
+
const signedExtensionsCtx = {
|
|
761
|
+
metadata: ctx.metadata,
|
|
762
|
+
chainHead,
|
|
763
|
+
callData,
|
|
764
|
+
at: atBlock.hash,
|
|
765
|
+
from: signer.publicKey
|
|
766
|
+
};
|
|
767
|
+
const mortality = hinted?.mortality?.mortal ? { period: hinted.mortality.period, blockNumber: atBlock.number } : void 0;
|
|
768
|
+
return (0, import_rxjs19.combineLatest)(
|
|
769
|
+
ctx.metadata.extrinsic.signedExtensions.map(
|
|
770
|
+
({ identifier, type, additionalSigned }) => {
|
|
771
|
+
if (identifier === "CheckMortality")
|
|
772
|
+
return CheckMortality(mortality, signedExtensionsCtx);
|
|
773
|
+
if (identifier === "ChargeTransactionPayment")
|
|
774
|
+
return ChargeTransactionPayment(hinted?.tip ?? 0n);
|
|
775
|
+
if (identifier === "ChargeAssetTxPayment")
|
|
776
|
+
return ChargeAssetTxPayment(hinted?.tip ?? 0n, hinted?.asset);
|
|
777
|
+
const fn = chain_exports[identifier];
|
|
778
|
+
if (!fn) {
|
|
779
|
+
if (ctx.dynamicBuilder.buildDefinition(type) === import_substrate_bindings7._void && ctx.dynamicBuilder.buildDefinition(additionalSigned) === import_substrate_bindings7._void)
|
|
780
|
+
return (0, import_rxjs19.of)({
|
|
781
|
+
value: empty,
|
|
782
|
+
additionalSigned: empty
|
|
783
|
+
});
|
|
784
|
+
throw new Error(`Unsupported signed-extension: ${identifier}`);
|
|
785
|
+
}
|
|
786
|
+
return fn(signedExtensionsCtx);
|
|
787
|
+
}
|
|
788
|
+
)
|
|
789
|
+
).pipe(
|
|
790
|
+
(0, import_rxjs19.mergeMap)(
|
|
791
|
+
(signedExtensions) => signer.sign(
|
|
792
|
+
callData,
|
|
793
|
+
Object.fromEntries(
|
|
794
|
+
ctx.metadata.extrinsic.signedExtensions.map(
|
|
795
|
+
({ identifier }, idx) => [
|
|
796
|
+
identifier,
|
|
797
|
+
{ identifier, ...signedExtensions[idx] }
|
|
798
|
+
]
|
|
799
|
+
)
|
|
800
|
+
),
|
|
801
|
+
ctx.metadataRaw,
|
|
802
|
+
atBlock.number
|
|
803
|
+
)
|
|
804
|
+
)
|
|
805
|
+
);
|
|
806
|
+
})
|
|
807
|
+
);
|
|
808
|
+
};
|
|
809
|
+
};
|
|
810
|
+
|
|
811
|
+
// src/client.ts
|
|
812
|
+
var createTypedApi = (descriptors, createTxFromSigner, chainHead, submitFns) => {
|
|
813
|
+
const runtimeApi = getRuntimeApi(descriptors.checksums, chainHead);
|
|
814
|
+
const { pallets, apis: runtimeApis } = descriptors;
|
|
815
|
+
const query = {};
|
|
816
|
+
for (const pallet in pallets) {
|
|
817
|
+
query[pallet] || (query[pallet] = {});
|
|
818
|
+
const [stgEntries] = pallets[pallet];
|
|
819
|
+
for (const name in stgEntries) {
|
|
820
|
+
query[pallet][name] = createStorageEntry(
|
|
821
|
+
pallet,
|
|
822
|
+
name,
|
|
823
|
+
chainHead,
|
|
824
|
+
compatibilityHelper(runtimeApi, stgEntries[name])
|
|
825
|
+
);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
const tx = {};
|
|
829
|
+
for (const pallet in pallets) {
|
|
830
|
+
tx[pallet] || (tx[pallet] = {});
|
|
831
|
+
const [, txEntries] = pallets[pallet];
|
|
832
|
+
for (const name in txEntries) {
|
|
833
|
+
tx[pallet][name] = createTxEntry(
|
|
834
|
+
pallet,
|
|
835
|
+
name,
|
|
836
|
+
descriptors.asset,
|
|
837
|
+
chainHead,
|
|
838
|
+
submitFns,
|
|
839
|
+
createTxFromSigner,
|
|
840
|
+
compatibilityHelper(runtimeApi, txEntries[name])
|
|
841
|
+
);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
const events = {};
|
|
845
|
+
for (const pallet in pallets) {
|
|
846
|
+
events[pallet] || (events[pallet] = {});
|
|
847
|
+
const [, , evEntries] = pallets[pallet];
|
|
848
|
+
for (const name in evEntries) {
|
|
849
|
+
events[pallet][name] = createEventEntry(
|
|
850
|
+
pallet,
|
|
851
|
+
name,
|
|
852
|
+
chainHead,
|
|
853
|
+
compatibilityHelper(runtimeApi, evEntries[name])
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
const constants = {};
|
|
858
|
+
for (const pallet in pallets) {
|
|
859
|
+
constants[pallet] || (constants[pallet] = {});
|
|
860
|
+
const [, , , , ctEntries] = pallets[pallet];
|
|
861
|
+
for (const name in ctEntries) {
|
|
862
|
+
constants[pallet][name] = createConstantEntry(
|
|
863
|
+
pallet,
|
|
864
|
+
name,
|
|
865
|
+
chainHead,
|
|
866
|
+
compatibilityHelper(runtimeApi, ctEntries[name])
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
const apis = {};
|
|
871
|
+
for (const api in runtimeApis) {
|
|
872
|
+
apis[api] || (apis[api] = {});
|
|
873
|
+
const methods = runtimeApis[api];
|
|
874
|
+
for (const method in methods) {
|
|
875
|
+
apis[api][method] = createRuntimeCallEntry(
|
|
876
|
+
api,
|
|
877
|
+
method,
|
|
878
|
+
chainHead,
|
|
879
|
+
compatibilityHelper(runtimeApi, methods[method])
|
|
880
|
+
);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
return {
|
|
884
|
+
query,
|
|
885
|
+
tx,
|
|
886
|
+
event: events,
|
|
887
|
+
apis,
|
|
888
|
+
constants,
|
|
889
|
+
runtime: runtimeApi
|
|
890
|
+
};
|
|
891
|
+
};
|
|
892
|
+
function createClient(provider) {
|
|
893
|
+
const rawClient = (0, import_substrate_client.createClient)(provider);
|
|
894
|
+
const client = (0, import_observable_client.getObservableClient)(rawClient);
|
|
895
|
+
const chainHead = client.chainHead$();
|
|
896
|
+
const createTxFromSigner = getCreateTx(chainHead);
|
|
897
|
+
const submitFns = getSubmitFns(chainHead, client);
|
|
898
|
+
const { submit, submit$: submitAndWatch } = submitFns;
|
|
899
|
+
return {
|
|
900
|
+
finalized$: chainHead.finalized$,
|
|
901
|
+
bestBlocks$: chainHead.bestBlocks$,
|
|
902
|
+
getBlockHeader: (hash) => (0, import_rxjs20.firstValueFrom)(chainHead.header$(hash ?? null)),
|
|
903
|
+
getBlockBody: chainHead.body$,
|
|
904
|
+
destroy: () => {
|
|
905
|
+
chainHead.unfollow();
|
|
906
|
+
client.destroy();
|
|
907
|
+
},
|
|
908
|
+
submit,
|
|
909
|
+
submitAndWatch,
|
|
910
|
+
getTypedApi: (descriptors) => createTypedApi(descriptors, createTxFromSigner, chainHead, submitFns)
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
// src/re-exports.ts
|
|
915
|
+
var import_substrate_bindings8 = require("@polkadot-api/substrate-bindings");
|
|
916
|
+
//# sourceMappingURL=index.js.map
|