@polkadot-api/substrate-client 0.6.1-canary.f1c6573 → 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/{esm/archive/archive.mjs → archive/archive.js} +5 -5
- package/dist/archive/archive.js.map +1 -0
- package/dist/{esm/archive/errors.mjs → archive/errors.js} +1 -1
- package/dist/archive/errors.js.map +1 -0
- package/dist/{esm/archive/storage-subscription.mjs → archive/storage-subscription.js} +2 -2
- package/dist/archive/storage-subscription.js.map +1 -0
- package/dist/{esm/archive/storage.mjs → archive/storage.js} +2 -2
- package/dist/archive/storage.js.map +1 -0
- package/dist/{esm/chainhead/body.mjs → chainhead/body.js} +3 -3
- package/dist/chainhead/body.js.map +1 -0
- package/dist/{esm/chainhead/call.mjs → chainhead/call.js} +3 -3
- package/dist/chainhead/call.js.map +1 -0
- package/dist/{esm/chainhead/chainhead.mjs → chainhead/chainhead.js} +11 -11
- package/dist/chainhead/chainhead.js.map +1 -0
- package/dist/{esm/chainhead/errors.mjs → chainhead/errors.js} +9 -9
- package/dist/chainhead/errors.js.map +1 -0
- package/dist/{esm/chainhead/header.mjs → chainhead/header.js} +2 -2
- package/dist/chainhead/header.js.map +1 -0
- package/dist/{esm/chainhead/operation-promise.mjs → chainhead/operation-promise.js} +5 -5
- package/dist/chainhead/operation-promise.js.map +1 -0
- package/dist/{esm/chainhead/storage-subscription.mjs → chainhead/storage-subscription.js} +5 -5
- package/dist/chainhead/storage-subscription.js.map +1 -0
- package/dist/{esm/chainhead/storage.mjs → chainhead/storage.js} +6 -6
- package/dist/chainhead/storage.js.map +1 -0
- package/dist/{esm/chainhead/unpin.mjs → chainhead/unpin.js} +2 -2
- package/dist/chainhead/unpin.js.map +1 -0
- package/dist/{esm/chainspec.mjs → chainspec.js} +3 -3
- package/dist/chainspec.js.map +1 -0
- package/dist/index.js +6 -648
- package/dist/index.js.map +1 -1
- package/dist/{esm/internal-utils/abortablePromiseFn.mjs → internal-utils/abortablePromiseFn.js} +1 -1
- package/dist/internal-utils/abortablePromiseFn.js.map +1 -0
- package/dist/{esm/internal-utils/deferred-promise.mjs → internal-utils/deferred-promise.js} +1 -1
- package/dist/internal-utils/deferred-promise.js.map +1 -0
- package/dist/{esm/internal-utils/noop.mjs → internal-utils/noop.js} +1 -1
- package/dist/internal-utils/noop.js.map +1 -0
- package/dist/{esm/methods.mjs → methods.js} +1 -1
- package/dist/methods.js.map +1 -0
- package/dist/{esm/substrate-client.mjs → substrate-client.js} +8 -8
- package/dist/substrate-client.js.map +1 -0
- package/dist/{esm/transaction/transaction.mjs → transaction/transaction.js} +3 -3
- package/dist/transaction/transaction.js.map +1 -0
- package/package.json +11 -21
- package/dist/esm/archive/archive.mjs.map +0 -1
- package/dist/esm/archive/errors.mjs.map +0 -1
- package/dist/esm/archive/storage-subscription.mjs.map +0 -1
- package/dist/esm/archive/storage.mjs.map +0 -1
- package/dist/esm/chainhead/body.mjs.map +0 -1
- package/dist/esm/chainhead/call.mjs.map +0 -1
- package/dist/esm/chainhead/chainhead.mjs.map +0 -1
- package/dist/esm/chainhead/errors.mjs.map +0 -1
- package/dist/esm/chainhead/header.mjs.map +0 -1
- package/dist/esm/chainhead/operation-promise.mjs.map +0 -1
- package/dist/esm/chainhead/storage-subscription.mjs.map +0 -1
- package/dist/esm/chainhead/storage.mjs.map +0 -1
- package/dist/esm/chainhead/unpin.mjs.map +0 -1
- package/dist/esm/chainspec.mjs.map +0 -1
- package/dist/esm/index.mjs +0 -7
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/internal-utils/abortablePromiseFn.mjs.map +0 -1
- package/dist/esm/internal-utils/deferred-promise.mjs.map +0 -1
- package/dist/esm/internal-utils/noop.mjs.map +0 -1
- package/dist/esm/methods.mjs.map +0 -1
- package/dist/esm/substrate-client.mjs.map +0 -1
- package/dist/esm/transaction/transaction.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,649 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, key + "" , value);
|
|
9
|
-
const _StopError = class _StopError extends Error {
|
|
10
|
-
constructor() {
|
|
11
|
-
super("ChainHead stopped");
|
|
12
|
-
this.name = _StopError.errorName;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
__publicField$1(_StopError, "errorName", "StopError");
|
|
16
|
-
let StopError = _StopError;
|
|
17
|
-
const _DisjointError = class _DisjointError extends Error {
|
|
18
|
-
constructor() {
|
|
19
|
-
super("ChainHead disjointed");
|
|
20
|
-
this.name = _DisjointError.errorName;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
__publicField$1(_DisjointError, "errorName", "DisjointError");
|
|
24
|
-
let DisjointError = _DisjointError;
|
|
25
|
-
const _OperationLimitError = class _OperationLimitError extends Error {
|
|
26
|
-
constructor() {
|
|
27
|
-
super("ChainHead operations limit reached");
|
|
28
|
-
this.name = _OperationLimitError.errorName;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
__publicField$1(_OperationLimitError, "errorName", "OperationLimitError");
|
|
32
|
-
let OperationLimitError = _OperationLimitError;
|
|
33
|
-
const _OperationError = class _OperationError extends Error {
|
|
34
|
-
constructor(error) {
|
|
35
|
-
super(error);
|
|
36
|
-
this.name = _OperationError.errorName;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
__publicField$1(_OperationError, "errorName", "OperationError");
|
|
40
|
-
let OperationError = _OperationError;
|
|
41
|
-
const _OperationInaccessibleError = class _OperationInaccessibleError extends Error {
|
|
42
|
-
constructor() {
|
|
43
|
-
super("ChainHead operation inaccessible");
|
|
44
|
-
this.name = _OperationInaccessibleError.errorName;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
__publicField$1(_OperationInaccessibleError, "errorName", "OperationInaccessibleError");
|
|
48
|
-
let OperationInaccessibleError = _OperationInaccessibleError;
|
|
49
|
-
|
|
50
|
-
const abortablePromiseFn = (fn) => (...args) => new Promise((res, rej) => {
|
|
51
|
-
let cancel = utils.noop;
|
|
52
|
-
const [actualArgs, abortSignal] = args[args.length - 1] instanceof AbortSignal ? [args.slice(0, args.length - 1), args[args.length - 1]] : [args];
|
|
53
|
-
const onAbort = () => {
|
|
54
|
-
cancel();
|
|
55
|
-
rej(new utils.AbortError());
|
|
56
|
-
};
|
|
57
|
-
abortSignal?.addEventListener("abort", onAbort, { once: true });
|
|
58
|
-
const withCleanup = (fn2) => (x) => {
|
|
59
|
-
cancel = utils.noop;
|
|
60
|
-
abortSignal?.removeEventListener("abort", onAbort);
|
|
61
|
-
fn2(x);
|
|
62
|
-
};
|
|
63
|
-
cancel = fn(...[withCleanup(res), withCleanup(rej), ...actualArgs]);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
function deferred() {
|
|
67
|
-
let res = () => {
|
|
68
|
-
};
|
|
69
|
-
let rej = () => {
|
|
70
|
-
};
|
|
71
|
-
const promise = new Promise((_res, _rej) => {
|
|
72
|
-
res = _res;
|
|
73
|
-
rej = _rej;
|
|
74
|
-
});
|
|
75
|
-
return { promise, res, rej };
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const noop = () => {
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const chainHead = {
|
|
82
|
-
body: "",
|
|
83
|
-
call: "",
|
|
84
|
-
continue: "",
|
|
85
|
-
follow: "",
|
|
86
|
-
header: "",
|
|
87
|
-
stopOperation: "",
|
|
88
|
-
storage: "",
|
|
89
|
-
unfollow: "",
|
|
90
|
-
unpin: "",
|
|
91
|
-
followEvent: ""
|
|
92
|
-
};
|
|
93
|
-
const chainSpec = {
|
|
94
|
-
chainName: "",
|
|
95
|
-
genesisHash: "",
|
|
96
|
-
properties: ""
|
|
97
|
-
};
|
|
98
|
-
const transaction = {
|
|
99
|
-
broadcast: "",
|
|
100
|
-
stop: ""
|
|
101
|
-
};
|
|
102
|
-
Object.entries({ chainHead, chainSpec, transaction }).forEach(
|
|
103
|
-
([fnGroupName, methods]) => {
|
|
104
|
-
Object.keys(methods).forEach((methodName) => {
|
|
105
|
-
methods[methodName] = `${fnGroupName}_v1_${methodName}`;
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
const createOperationPromise = (operationName, factory) => (request) => abortablePromiseFn((res, rej, ...args) => {
|
|
111
|
-
let isRunning = true;
|
|
112
|
-
let cancel = () => {
|
|
113
|
-
isRunning = false;
|
|
114
|
-
};
|
|
115
|
-
const [requestArgs, logicCb] = factory(...args);
|
|
116
|
-
request(operationName, requestArgs, {
|
|
117
|
-
onSuccess: (response, followSubscription) => {
|
|
118
|
-
if (response.result === "limitReached")
|
|
119
|
-
return rej(new OperationLimitError());
|
|
120
|
-
const { operationId } = response;
|
|
121
|
-
const stopOperation = () => {
|
|
122
|
-
request(chainHead.stopOperation, [operationId]);
|
|
123
|
-
};
|
|
124
|
-
if (!isRunning) return stopOperation();
|
|
125
|
-
let done = noop;
|
|
126
|
-
const _res = (x) => {
|
|
127
|
-
isRunning = false;
|
|
128
|
-
done();
|
|
129
|
-
res(x);
|
|
130
|
-
};
|
|
131
|
-
const _rej = (x) => {
|
|
132
|
-
isRunning = false;
|
|
133
|
-
done();
|
|
134
|
-
rej(x);
|
|
135
|
-
};
|
|
136
|
-
done = followSubscription(operationId, {
|
|
137
|
-
next: (e) => {
|
|
138
|
-
const _e = e;
|
|
139
|
-
if (_e.event === "operationError")
|
|
140
|
-
rej(new OperationError(_e.error));
|
|
141
|
-
else if (_e.event === "operationInaccessible")
|
|
142
|
-
rej(new OperationInaccessibleError());
|
|
143
|
-
else logicCb(e, _res, _rej);
|
|
144
|
-
},
|
|
145
|
-
error: _rej
|
|
146
|
-
});
|
|
147
|
-
cancel = () => {
|
|
148
|
-
if (isRunning) {
|
|
149
|
-
done();
|
|
150
|
-
stopOperation();
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
},
|
|
154
|
-
onError: rej
|
|
155
|
-
});
|
|
156
|
-
return () => {
|
|
157
|
-
cancel();
|
|
158
|
-
};
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
const createBodyFn = createOperationPromise(
|
|
162
|
-
chainHead.body,
|
|
163
|
-
(hash) => [
|
|
164
|
-
[hash],
|
|
165
|
-
(e, res) => {
|
|
166
|
-
res(e.value);
|
|
167
|
-
}
|
|
168
|
-
]
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
const createCallFn = createOperationPromise(
|
|
172
|
-
chainHead.call,
|
|
173
|
-
(hash, fnName, callParameters) => [
|
|
174
|
-
[hash, fnName, callParameters],
|
|
175
|
-
(e, res) => {
|
|
176
|
-
res(e.output);
|
|
177
|
-
}
|
|
178
|
-
]
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
const createHeaderFn = (request) => (hash) => new Promise((res, rej) => {
|
|
182
|
-
request(chainHead.header, [hash], {
|
|
183
|
-
onSuccess: res,
|
|
184
|
-
onError: rej
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
const createStorageCb$1 = (request) => (hash, inputs, childTrie, onItems, onError, onDone, onDiscardedItems) => {
|
|
189
|
-
if (inputs.length === 0) {
|
|
190
|
-
onDone();
|
|
191
|
-
return utils.noop;
|
|
192
|
-
}
|
|
193
|
-
let isRunning = true;
|
|
194
|
-
let cancel = () => {
|
|
195
|
-
isRunning = false;
|
|
196
|
-
};
|
|
197
|
-
request(chainHead.storage, [hash, inputs, childTrie], {
|
|
198
|
-
onSuccess: (response, followSubscription) => {
|
|
199
|
-
if (response.result === "limitReached" || response.discardedItems === inputs.length)
|
|
200
|
-
return onError(new OperationLimitError());
|
|
201
|
-
const { operationId } = response;
|
|
202
|
-
const stopOperation = () => {
|
|
203
|
-
request(chainHead.stopOperation, [operationId]);
|
|
204
|
-
};
|
|
205
|
-
if (!isRunning) return stopOperation();
|
|
206
|
-
const doneListening = followSubscription(response.operationId, {
|
|
207
|
-
next: (event) => {
|
|
208
|
-
switch (event.event) {
|
|
209
|
-
case "operationStorageItems": {
|
|
210
|
-
onItems(event.items);
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
case "operationStorageDone": {
|
|
214
|
-
_onDone();
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
217
|
-
case "operationError": {
|
|
218
|
-
_onError(new OperationError(event.error));
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
case "operationInaccessible": {
|
|
222
|
-
_onError(new OperationInaccessibleError());
|
|
223
|
-
break;
|
|
224
|
-
}
|
|
225
|
-
default:
|
|
226
|
-
request(chainHead.continue, [event.operationId]);
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
error: onError
|
|
230
|
-
});
|
|
231
|
-
cancel = () => {
|
|
232
|
-
doneListening();
|
|
233
|
-
request(chainHead.stopOperation, [response.operationId]);
|
|
234
|
-
};
|
|
235
|
-
const _onError = (e) => {
|
|
236
|
-
cancel = utils.noop;
|
|
237
|
-
doneListening();
|
|
238
|
-
onError(e);
|
|
239
|
-
};
|
|
240
|
-
const _onDone = () => {
|
|
241
|
-
cancel = utils.noop;
|
|
242
|
-
doneListening();
|
|
243
|
-
onDone();
|
|
244
|
-
};
|
|
245
|
-
onDiscardedItems(response.discardedItems);
|
|
246
|
-
},
|
|
247
|
-
onError
|
|
248
|
-
});
|
|
249
|
-
return () => {
|
|
250
|
-
cancel();
|
|
251
|
-
};
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
const createStorageFn$1 = (request) => {
|
|
255
|
-
const cbStore = createStorageCb$1(request);
|
|
256
|
-
return abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => {
|
|
257
|
-
const isDescendants = type.startsWith("descendants");
|
|
258
|
-
let result = isDescendants ? [] : null;
|
|
259
|
-
const onItems = isDescendants ? (items) => {
|
|
260
|
-
result.push(items);
|
|
261
|
-
} : (items) => {
|
|
262
|
-
result = items[0]?.[type];
|
|
263
|
-
};
|
|
264
|
-
const cancel = cbStore(
|
|
265
|
-
hash,
|
|
266
|
-
[{ key, type }],
|
|
267
|
-
childTrie ?? null,
|
|
268
|
-
onItems,
|
|
269
|
-
reject,
|
|
270
|
-
() => {
|
|
271
|
-
try {
|
|
272
|
-
resolve(isDescendants ? result.flat() : result);
|
|
273
|
-
} catch (e) {
|
|
274
|
-
reject(e);
|
|
275
|
-
}
|
|
276
|
-
},
|
|
277
|
-
(nDiscarded) => {
|
|
278
|
-
if (nDiscarded > 0) {
|
|
279
|
-
cancel();
|
|
280
|
-
reject(new OperationLimitError());
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
);
|
|
284
|
-
return cancel;
|
|
285
|
-
});
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
const createUnpinFn = (request) => (hashes) => hashes.length > 0 ? new Promise((res, rej) => {
|
|
289
|
-
request(chainHead.unpin, [hashes], {
|
|
290
|
-
onSuccess() {
|
|
291
|
-
res();
|
|
292
|
-
},
|
|
293
|
-
onError: rej
|
|
294
|
-
});
|
|
295
|
-
}) : Promise.resolve();
|
|
296
|
-
|
|
297
|
-
function isOperationEvent(event) {
|
|
298
|
-
return event.operationId !== void 0;
|
|
299
|
-
}
|
|
300
|
-
function getChainHead(request) {
|
|
301
|
-
return (withRuntime, onFollowEvent, onFollowError) => {
|
|
302
|
-
const subscriptions = rawClient.getSubscriptionsManager();
|
|
303
|
-
const ongoingRequests = /* @__PURE__ */ new Set();
|
|
304
|
-
const deferredFollow = deferred();
|
|
305
|
-
let followSubscription = deferredFollow.promise;
|
|
306
|
-
let stopListeningToFollowEvents = noop;
|
|
307
|
-
const unfollowRequest = (subscriptionId) => {
|
|
308
|
-
request(chainHead.unfollow, [subscriptionId]);
|
|
309
|
-
};
|
|
310
|
-
const stopEverything = (sendUnfollow) => {
|
|
311
|
-
stopListeningToFollowEvents();
|
|
312
|
-
if (followSubscription === null) return;
|
|
313
|
-
if (sendUnfollow) {
|
|
314
|
-
if (followSubscription instanceof Promise) {
|
|
315
|
-
followSubscription.then((x) => {
|
|
316
|
-
if (typeof x === "string") unfollowRequest(x);
|
|
317
|
-
});
|
|
318
|
-
} else unfollowRequest(followSubscription);
|
|
319
|
-
}
|
|
320
|
-
followSubscription = null;
|
|
321
|
-
ongoingRequests.forEach((cb) => {
|
|
322
|
-
cb();
|
|
323
|
-
});
|
|
324
|
-
ongoingRequests.clear();
|
|
325
|
-
subscriptions.errorAll(new DisjointError());
|
|
326
|
-
};
|
|
327
|
-
const onAllFollowEventsNext = (event) => {
|
|
328
|
-
if (isOperationEvent(event))
|
|
329
|
-
return subscriptions.next(event.operationId, event);
|
|
330
|
-
switch (event.event) {
|
|
331
|
-
case "stop":
|
|
332
|
-
onFollowError(new StopError());
|
|
333
|
-
return stopEverything(false);
|
|
334
|
-
case "initialized":
|
|
335
|
-
case "newBlock":
|
|
336
|
-
case "bestBlockChanged":
|
|
337
|
-
case "finalized":
|
|
338
|
-
const { event: type, ...rest } = event;
|
|
339
|
-
return onFollowEvent({ type, ...rest });
|
|
340
|
-
}
|
|
341
|
-
};
|
|
342
|
-
const onAllFollowEventsError = (error) => {
|
|
343
|
-
onFollowError(error);
|
|
344
|
-
stopEverything(!(error instanceof rawClient.DestroyedError));
|
|
345
|
-
};
|
|
346
|
-
request(chainHead.follow, [withRuntime], {
|
|
347
|
-
onSuccess: (subscriptionId, follow) => {
|
|
348
|
-
if (followSubscription instanceof Promise) {
|
|
349
|
-
followSubscription = subscriptionId;
|
|
350
|
-
stopListeningToFollowEvents = follow(subscriptionId, {
|
|
351
|
-
next: onAllFollowEventsNext,
|
|
352
|
-
error: onAllFollowEventsError
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
deferredFollow.res(subscriptionId);
|
|
356
|
-
},
|
|
357
|
-
onError: (e) => {
|
|
358
|
-
followSubscription = null;
|
|
359
|
-
deferredFollow.res(e);
|
|
360
|
-
onFollowError(e);
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
const fRequest = (method, params, cb) => {
|
|
364
|
-
const disjoint = () => {
|
|
365
|
-
cb?.onError(new DisjointError());
|
|
366
|
-
};
|
|
367
|
-
if (followSubscription === null) {
|
|
368
|
-
disjoint();
|
|
369
|
-
return noop;
|
|
370
|
-
}
|
|
371
|
-
const onSubscription = (subscription) => {
|
|
372
|
-
if (!cb) return request(method, [subscription, ...params]);
|
|
373
|
-
ongoingRequests.add(disjoint);
|
|
374
|
-
const onSubscribeOperation = (operationId, subscriber) => {
|
|
375
|
-
if (followSubscription === null) {
|
|
376
|
-
subscriber.error(new DisjointError());
|
|
377
|
-
return noop;
|
|
378
|
-
}
|
|
379
|
-
subscriptions.subscribe(operationId, subscriber);
|
|
380
|
-
return () => {
|
|
381
|
-
subscriptions.unsubscribe(operationId);
|
|
382
|
-
};
|
|
383
|
-
};
|
|
384
|
-
const cleanup = request(method, [subscription, ...params], {
|
|
385
|
-
onSuccess: (response) => {
|
|
386
|
-
ongoingRequests.delete(disjoint);
|
|
387
|
-
cb.onSuccess(response, onSubscribeOperation);
|
|
388
|
-
},
|
|
389
|
-
onError: (e) => {
|
|
390
|
-
ongoingRequests.delete(disjoint);
|
|
391
|
-
cb.onError(e);
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
return () => {
|
|
395
|
-
ongoingRequests.delete(disjoint);
|
|
396
|
-
cleanup();
|
|
397
|
-
};
|
|
398
|
-
};
|
|
399
|
-
if (typeof followSubscription === "string")
|
|
400
|
-
return onSubscription(followSubscription);
|
|
401
|
-
let onCancel = noop;
|
|
402
|
-
followSubscription.then((x) => {
|
|
403
|
-
if (x instanceof Error) return disjoint();
|
|
404
|
-
if (followSubscription) onCancel = onSubscription(x);
|
|
405
|
-
});
|
|
406
|
-
return () => {
|
|
407
|
-
onCancel();
|
|
408
|
-
};
|
|
409
|
-
};
|
|
410
|
-
return {
|
|
411
|
-
unfollow() {
|
|
412
|
-
stopEverything(true);
|
|
413
|
-
},
|
|
414
|
-
body: createBodyFn(fRequest),
|
|
415
|
-
call: createCallFn(fRequest),
|
|
416
|
-
header: createHeaderFn(fRequest),
|
|
417
|
-
storage: createStorageFn$1(fRequest),
|
|
418
|
-
storageSubscription: createStorageCb$1(fRequest),
|
|
419
|
-
unpin: createUnpinFn(fRequest),
|
|
420
|
-
_request: fRequest
|
|
421
|
-
};
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
var __defProp = Object.defineProperty;
|
|
426
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
427
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
428
|
-
const _BlockHashNotFoundError = class _BlockHashNotFoundError extends Error {
|
|
429
|
-
constructor(hash) {
|
|
430
|
-
super(`Invalid BlockHash: ${hash}`);
|
|
431
|
-
this.name = _BlockHashNotFoundError.errorName;
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
__publicField(_BlockHashNotFoundError, "errorName", "BlockHashNotFoundError");
|
|
435
|
-
let BlockHashNotFoundError = _BlockHashNotFoundError;
|
|
436
|
-
const _StorageError = class _StorageError extends Error {
|
|
437
|
-
constructor(message) {
|
|
438
|
-
super(`Storage Error: ${message}`);
|
|
439
|
-
this.name = _StorageError.errorName;
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
__publicField(_StorageError, "errorName", "StorageError");
|
|
443
|
-
let StorageError = _StorageError;
|
|
444
|
-
const _CallError = class _CallError extends Error {
|
|
445
|
-
constructor(message) {
|
|
446
|
-
super(`Call Error: ${message}`);
|
|
447
|
-
this.name = _CallError.errorName;
|
|
448
|
-
}
|
|
449
|
-
};
|
|
450
|
-
__publicField(_CallError, "errorName", "CallError");
|
|
451
|
-
let CallError = _CallError;
|
|
452
|
-
|
|
453
|
-
const createStorageCb = (archiveRequest) => (hash, inputs, childTrie, onItem, onError, onDone) => {
|
|
454
|
-
if (inputs.length === 0) {
|
|
455
|
-
onDone();
|
|
456
|
-
return utils.noop;
|
|
457
|
-
}
|
|
458
|
-
let isRunning = true;
|
|
459
|
-
let cancel = () => {
|
|
460
|
-
isRunning = false;
|
|
461
|
-
};
|
|
462
|
-
archiveRequest("storage", [hash, inputs, childTrie], {
|
|
463
|
-
onSuccess: (operationId, followSubscription) => {
|
|
464
|
-
const stopOperation = () => {
|
|
465
|
-
archiveRequest("stopStorage", [operationId]);
|
|
466
|
-
};
|
|
467
|
-
if (!isRunning) return stopOperation();
|
|
468
|
-
const doneListening = followSubscription(operationId, {
|
|
469
|
-
next: (event) => {
|
|
470
|
-
const { event: type } = event;
|
|
471
|
-
if (type === "storage") {
|
|
472
|
-
const { event: _, ...item } = event;
|
|
473
|
-
onItem(item);
|
|
474
|
-
} else if (type === "storageDone") _onDone();
|
|
475
|
-
else _onError(new StorageError(event.error));
|
|
476
|
-
},
|
|
477
|
-
error: onError
|
|
478
|
-
});
|
|
479
|
-
const tearDown = () => {
|
|
480
|
-
cancel = utils.noop;
|
|
481
|
-
doneListening();
|
|
482
|
-
};
|
|
483
|
-
cancel = () => {
|
|
484
|
-
tearDown();
|
|
485
|
-
stopOperation();
|
|
486
|
-
};
|
|
487
|
-
const _onError = (e) => {
|
|
488
|
-
tearDown();
|
|
489
|
-
onError(e);
|
|
490
|
-
};
|
|
491
|
-
const _onDone = () => {
|
|
492
|
-
tearDown();
|
|
493
|
-
onDone();
|
|
494
|
-
};
|
|
495
|
-
},
|
|
496
|
-
onError
|
|
497
|
-
});
|
|
498
|
-
return () => {
|
|
499
|
-
cancel();
|
|
500
|
-
};
|
|
501
|
-
};
|
|
502
|
-
|
|
503
|
-
const createStorageFn = (cbStore) => abortablePromiseFn((resolve, reject, hash, type, key, childTrie) => {
|
|
504
|
-
const isDescendants = type.startsWith("descendants");
|
|
505
|
-
let result = isDescendants ? [] : null;
|
|
506
|
-
const onItem = isDescendants ? result.push.bind(result) : ({ [type]: res }) => {
|
|
507
|
-
result = res;
|
|
508
|
-
};
|
|
509
|
-
return cbStore(
|
|
510
|
-
hash,
|
|
511
|
-
[{ key, type }],
|
|
512
|
-
childTrie,
|
|
513
|
-
onItem,
|
|
514
|
-
(e) => {
|
|
515
|
-
reject(e);
|
|
516
|
-
result = null;
|
|
517
|
-
},
|
|
518
|
-
() => {
|
|
519
|
-
resolve(result);
|
|
520
|
-
result = null;
|
|
521
|
-
}
|
|
522
|
-
);
|
|
523
|
-
});
|
|
524
|
-
|
|
525
|
-
const identity = () => (x) => x;
|
|
526
|
-
const handleInvalidBlockHash = () => (result, hash) => {
|
|
527
|
-
if (result === null) throw new BlockHashNotFoundError(hash);
|
|
528
|
-
return result;
|
|
529
|
-
};
|
|
530
|
-
const getArchive = (request) => {
|
|
531
|
-
const archiveRequest = (method, ...rest) => request(`archive_v1_${method}`, ...rest);
|
|
532
|
-
const fnCreator = (method) => (mapper) => abortablePromiseFn(
|
|
533
|
-
(res, rej, ...args) => archiveRequest(method, args, {
|
|
534
|
-
onSuccess: (x) => {
|
|
535
|
-
try {
|
|
536
|
-
res(mapper(x, ...args));
|
|
537
|
-
} catch (e) {
|
|
538
|
-
rej(e);
|
|
539
|
-
}
|
|
540
|
-
},
|
|
541
|
-
onError: rej
|
|
542
|
-
})
|
|
543
|
-
);
|
|
544
|
-
const header = fnCreator("header")(
|
|
545
|
-
handleInvalidBlockHash()
|
|
546
|
-
);
|
|
547
|
-
const body = fnCreator("body")(
|
|
548
|
-
handleInvalidBlockHash()
|
|
549
|
-
);
|
|
550
|
-
const storageSubscription = createStorageCb(archiveRequest);
|
|
551
|
-
const storage = createStorageFn(storageSubscription);
|
|
552
|
-
const call = fnCreator("call")((x, hash) => {
|
|
553
|
-
if (!x) throw new BlockHashNotFoundError(hash);
|
|
554
|
-
if (!x.success) throw new CallError(x.error);
|
|
555
|
-
return x.value;
|
|
556
|
-
});
|
|
557
|
-
const finalizedHeight = fnCreator("finalizedHeight")(identity());
|
|
558
|
-
const hashByHeight = fnCreator("hashByHeight")(identity());
|
|
559
|
-
return {
|
|
560
|
-
header,
|
|
561
|
-
body,
|
|
562
|
-
storageSubscription,
|
|
563
|
-
storage,
|
|
564
|
-
call,
|
|
565
|
-
finalizedHeight,
|
|
566
|
-
hashByHeight
|
|
567
|
-
};
|
|
568
|
-
};
|
|
569
|
-
|
|
570
|
-
const getTransaction = (request) => (tx, error) => {
|
|
571
|
-
let isDone = false;
|
|
572
|
-
let cancel = () => {
|
|
573
|
-
isDone = true;
|
|
574
|
-
};
|
|
575
|
-
request(transaction.broadcast, [tx], {
|
|
576
|
-
onSuccess: (subscriptionId) => {
|
|
577
|
-
if (subscriptionId !== null) {
|
|
578
|
-
cancel = () => {
|
|
579
|
-
request(transaction.stop, [subscriptionId]);
|
|
580
|
-
cancel = noop;
|
|
581
|
-
};
|
|
582
|
-
if (isDone) cancel();
|
|
583
|
-
} else if (!isDone) {
|
|
584
|
-
error(new Error("Max # of broadcasted transactions has been reached"));
|
|
585
|
-
}
|
|
586
|
-
},
|
|
587
|
-
onError: error
|
|
588
|
-
});
|
|
589
|
-
return () => {
|
|
590
|
-
cancel();
|
|
591
|
-
};
|
|
592
|
-
};
|
|
593
|
-
|
|
594
|
-
const createGetChainSpec = (clientRequest) => {
|
|
595
|
-
const request = abortablePromiseFn(
|
|
596
|
-
(onSuccess, onError, method, params) => clientRequest(method, params, { onSuccess, onError })
|
|
597
|
-
);
|
|
598
|
-
let cachedPromise = null;
|
|
599
|
-
return async () => {
|
|
600
|
-
if (cachedPromise) return cachedPromise;
|
|
601
|
-
return cachedPromise = Promise.all([
|
|
602
|
-
request(chainSpec.chainName, []),
|
|
603
|
-
request(chainSpec.genesisHash, []),
|
|
604
|
-
request(chainSpec.properties, [])
|
|
605
|
-
]).then(([name, genesisHash, properties]) => ({
|
|
606
|
-
name,
|
|
607
|
-
genesisHash,
|
|
608
|
-
properties
|
|
609
|
-
}));
|
|
610
|
-
};
|
|
611
|
-
};
|
|
612
|
-
|
|
613
|
-
const createClient = (provider) => {
|
|
614
|
-
const { request, disconnect } = rawClient.createClient(provider);
|
|
615
|
-
return {
|
|
616
|
-
archive: getArchive(request),
|
|
617
|
-
chainHead: getChainHead(request),
|
|
618
|
-
transaction: getTransaction(request),
|
|
619
|
-
getChainSpecData: createGetChainSpec(request),
|
|
620
|
-
destroy: disconnect,
|
|
621
|
-
request: abortablePromiseFn(
|
|
622
|
-
(onSuccess, onError, method, params) => request(method, params, { onSuccess, onError })
|
|
623
|
-
),
|
|
624
|
-
_request: request
|
|
625
|
-
};
|
|
626
|
-
};
|
|
627
|
-
|
|
628
|
-
Object.defineProperty(exports, "AbortError", {
|
|
629
|
-
enumerable: true,
|
|
630
|
-
get: function () { return utils.AbortError; }
|
|
631
|
-
});
|
|
632
|
-
Object.defineProperty(exports, "DestroyedError", {
|
|
633
|
-
enumerable: true,
|
|
634
|
-
get: function () { return rawClient.DestroyedError; }
|
|
635
|
-
});
|
|
636
|
-
Object.defineProperty(exports, "RpcError", {
|
|
637
|
-
enumerable: true,
|
|
638
|
-
get: function () { return rawClient.RpcError; }
|
|
639
|
-
});
|
|
640
|
-
exports.BlockHashNotFoundError = BlockHashNotFoundError;
|
|
641
|
-
exports.CallError = CallError;
|
|
642
|
-
exports.DisjointError = DisjointError;
|
|
643
|
-
exports.OperationError = OperationError;
|
|
644
|
-
exports.OperationInaccessibleError = OperationInaccessibleError;
|
|
645
|
-
exports.OperationLimitError = OperationLimitError;
|
|
646
|
-
exports.StopError = StopError;
|
|
647
|
-
exports.StorageError = StorageError;
|
|
648
|
-
exports.createClient = createClient;
|
|
1
|
+
export { AbortError } from '@polkadot-api/utils';
|
|
2
|
+
export { DestroyedError, RpcError } from '@polkadot-api/raw-client';
|
|
3
|
+
export { DisjointError, OperationError, OperationInaccessibleError, OperationLimitError, StopError } from './chainhead/errors.js';
|
|
4
|
+
import './methods.js';
|
|
5
|
+
export { BlockHashNotFoundError, CallError, StorageError } from './archive/errors.js';
|
|
6
|
+
export { createClient } from './substrate-client.js';
|
|
649
7
|
//# sourceMappingURL=index.js.map
|