@tari-project/ootle-indexer 0.6.0 → 0.8.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.js +59 -49
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -9,14 +9,20 @@ var l = Object.defineProperty, u = (e5, t3) => {
|
|
|
9
9
|
enumerable: true
|
|
10
10
|
});
|
|
11
11
|
return t3 || l(n2, Symbol.toStringTag, { value: "Module" }), n2;
|
|
12
|
+
}, d = class extends Error {
|
|
13
|
+
constructor(e5, t3, n2) {
|
|
14
|
+
super(`HTTP ${e5}: ${t3}${n2 ? ` - ${n2}` : ""}`);
|
|
15
|
+
__publicField(this, "status");
|
|
16
|
+
this.name = "HttpError", this.status = e5;
|
|
17
|
+
}
|
|
12
18
|
};
|
|
13
|
-
function
|
|
14
|
-
return JSON.stringify(e5,
|
|
19
|
+
function f(e5) {
|
|
20
|
+
return JSON.stringify(e5, p);
|
|
15
21
|
}
|
|
16
|
-
function
|
|
22
|
+
function p(e5, t3) {
|
|
17
23
|
return typeof t3 == "bigint" ? t3.toString() : t3;
|
|
18
24
|
}
|
|
19
|
-
function
|
|
25
|
+
function m(e5, t3) {
|
|
20
26
|
let n2 = new AbortController();
|
|
21
27
|
return t3.signal && (t3.signal.aborted ? n2.abort() : t3.signal.addEventListener("abort", () => n2.abort(), { once: true })), (async () => {
|
|
22
28
|
let r2 = await fetch(e5, {
|
|
@@ -26,10 +32,10 @@ function p(e5, t3) {
|
|
|
26
32
|
});
|
|
27
33
|
if (!r2.ok) {
|
|
28
34
|
let e6 = await r2.text();
|
|
29
|
-
throw
|
|
35
|
+
throw new d(r2.status, r2.statusText, e6);
|
|
30
36
|
}
|
|
31
37
|
if (!r2.body) throw Error("Response body is not readable");
|
|
32
|
-
let i2 = r2.body.getReader(), a2 = new TextDecoder(), o2 = "", s2 = "", c2 = [], l2, u2,
|
|
38
|
+
let i2 = r2.body.getReader(), a2 = new TextDecoder(), o2 = "", s2 = "", c2 = [], l2, u2, f2 = () => {
|
|
33
39
|
if (c2.length === 0) {
|
|
34
40
|
s2 = "", l2 = void 0, u2 = void 0;
|
|
35
41
|
return;
|
|
@@ -41,9 +47,9 @@ function p(e5, t3) {
|
|
|
41
47
|
retry: u2
|
|
42
48
|
};
|
|
43
49
|
t3.onEvent(e6), s2 = "", c2 = [], l2 = void 0, u2 = void 0;
|
|
44
|
-
},
|
|
50
|
+
}, p2 = (e6) => {
|
|
45
51
|
if (e6 === "") {
|
|
46
|
-
|
|
52
|
+
f2();
|
|
47
53
|
return;
|
|
48
54
|
}
|
|
49
55
|
if (e6.startsWith(":")) return;
|
|
@@ -73,10 +79,10 @@ function p(e5, t3) {
|
|
|
73
79
|
let n3 = /\r\n|\r|\n/, r3;
|
|
74
80
|
for (; (r3 = n3.exec(o2)) !== null; ) {
|
|
75
81
|
let e7 = o2.slice(0, r3.index);
|
|
76
|
-
o2 = o2.slice(r3.index + r3[0].length),
|
|
82
|
+
o2 = o2.slice(r3.index + r3[0].length), p2(e7);
|
|
77
83
|
}
|
|
78
84
|
}
|
|
79
|
-
o2.length > 0 && (
|
|
85
|
+
o2.length > 0 && (p2(o2), f2());
|
|
80
86
|
} finally {
|
|
81
87
|
i2.releaseLock();
|
|
82
88
|
}
|
|
@@ -90,7 +96,7 @@ function p(e5, t3) {
|
|
|
90
96
|
n2.abort();
|
|
91
97
|
} };
|
|
92
98
|
}
|
|
93
|
-
var
|
|
99
|
+
var h = class e2 {
|
|
94
100
|
constructor(e5) {
|
|
95
101
|
__publicField(this, "url");
|
|
96
102
|
this.url = e5;
|
|
@@ -138,7 +144,7 @@ var m = class e2 {
|
|
|
138
144
|
let n3 = e6.toString();
|
|
139
145
|
n3.length > 0 && (r2 += `?${n3}`);
|
|
140
146
|
}
|
|
141
|
-
return
|
|
147
|
+
return m(r2, n2);
|
|
142
148
|
}
|
|
143
149
|
async sendRequest(e5, t3, n2) {
|
|
144
150
|
let r2 = new AbortController(), i2 = r2.signal, a2 = (n2 == null ? void 0 : n2.timeout_millis) ? setTimeout(() => {
|
|
@@ -151,7 +157,7 @@ var m = class e2 {
|
|
|
151
157
|
for (let [n3, r3] of Object.entries(t3.params)) r3 != null && e6.append(n3, r3.toString());
|
|
152
158
|
o2 = e6;
|
|
153
159
|
}
|
|
154
|
-
typeof t3.body == "object" && t3.body !== null && (t3.headers || (t3.headers = {}), t3.headers["Content-Type"] = "application/json", t3.body =
|
|
160
|
+
typeof t3.body == "object" && t3.body !== null && (t3.headers || (t3.headers = {}), t3.headers["Content-Type"] = "application/json", t3.body = f(t3.body));
|
|
155
161
|
let s2 = `${this.url}/${e5}`;
|
|
156
162
|
o2 && o2.toString().length > 0 && (s2 += `?${o2.toString()}`);
|
|
157
163
|
let c2 = await fetch(s2, {
|
|
@@ -160,13 +166,13 @@ var m = class e2 {
|
|
|
160
166
|
});
|
|
161
167
|
if (a2 && clearTimeout(a2), !c2.ok) {
|
|
162
168
|
let e6 = await c2.text();
|
|
163
|
-
throw
|
|
169
|
+
throw new d(c2.status, c2.statusText, e6);
|
|
164
170
|
}
|
|
165
171
|
let l2 = await c2.json();
|
|
166
172
|
if (l2.error) throw Error(`${l2.error.code}: ${l2.error.message}`);
|
|
167
173
|
return l2;
|
|
168
174
|
}
|
|
169
|
-
},
|
|
175
|
+
}, g = /* @__PURE__ */ u({ FetchTransport: () => h }), _ = class e3 {
|
|
170
176
|
constructor(e5) {
|
|
171
177
|
__publicField(this, "transport");
|
|
172
178
|
this.transport = e5;
|
|
@@ -175,7 +181,7 @@ var m = class e2 {
|
|
|
175
181
|
return new e3(t3);
|
|
176
182
|
}
|
|
177
183
|
static usingFetchTransport(t3) {
|
|
178
|
-
return e3.new(
|
|
184
|
+
return e3.new(h.new(t3));
|
|
179
185
|
}
|
|
180
186
|
getTransport() {
|
|
181
187
|
return this.transport;
|
|
@@ -216,8 +222,8 @@ var m = class e2 {
|
|
|
216
222
|
getTransaction(e5) {
|
|
217
223
|
return this.transport.sendGet(`transactions/${encodeURIComponent(e5)}`, {});
|
|
218
224
|
}
|
|
219
|
-
getTransactionResult(e5) {
|
|
220
|
-
return this.transport.sendGet(`transactions/${encodeURIComponent(e5)}/result`, {});
|
|
225
|
+
getTransactionResult(e5, t3 = false) {
|
|
226
|
+
return this.transport.sendGet(`transactions/${encodeURIComponent(e5)}/result`, { include_proof: t3 });
|
|
221
227
|
}
|
|
222
228
|
listRecentTransactions(e5) {
|
|
223
229
|
return this.transport.sendGet("transactions/recent", e5);
|
|
@@ -268,7 +274,7 @@ var m = class e2 {
|
|
|
268
274
|
});
|
|
269
275
|
}
|
|
270
276
|
};
|
|
271
|
-
function
|
|
277
|
+
function v(e5) {
|
|
272
278
|
let t3 = [], n2 = e5.split(/\n\n|\r\n\r\n/), r2 = n2.pop() ?? "";
|
|
273
279
|
for (let e6 of n2) {
|
|
274
280
|
if (!e6.trim()) continue;
|
|
@@ -290,7 +296,7 @@ function _(e5) {
|
|
|
290
296
|
remainder: r2
|
|
291
297
|
};
|
|
292
298
|
}
|
|
293
|
-
async function*
|
|
299
|
+
async function* y(t3, n2) {
|
|
294
300
|
for (; !n2.aborted; ) {
|
|
295
301
|
let r2 = new AbortController(), i2 = () => r2.abort();
|
|
296
302
|
n2.addEventListener("abort", i2, { once: true });
|
|
@@ -315,7 +321,7 @@ async function* v(t3, n2) {
|
|
|
315
321
|
let { done: e5, value: t4 } = await a2.read();
|
|
316
322
|
if (e5) break;
|
|
317
323
|
s2 += o2.decode(t4, { stream: true });
|
|
318
|
-
let { events: n3, remainder: r3 } =
|
|
324
|
+
let { events: n3, remainder: r3 } = v(s2);
|
|
319
325
|
s2 = r3;
|
|
320
326
|
for (let e6 of n3) yield e6;
|
|
321
327
|
}
|
|
@@ -335,7 +341,7 @@ async function* v(t3, n2) {
|
|
|
335
341
|
}
|
|
336
342
|
}
|
|
337
343
|
}
|
|
338
|
-
var
|
|
344
|
+
var b = 500, x = 3e3, S = class {
|
|
339
345
|
constructor(e5) {
|
|
340
346
|
__publicField(this, "baseUrl");
|
|
341
347
|
__publicField(this, "pending", /* @__PURE__ */ new Map());
|
|
@@ -354,7 +360,7 @@ var y = 500, b = 3e3, x = class {
|
|
|
354
360
|
this.pending.clear();
|
|
355
361
|
}
|
|
356
362
|
watch(e5, t3, n2 = 32e3) {
|
|
357
|
-
return this.start(), new
|
|
363
|
+
return this.start(), new C(e5, this, t3, n2);
|
|
358
364
|
}
|
|
359
365
|
register(e5) {
|
|
360
366
|
return new Promise((t3, n2) => {
|
|
@@ -369,7 +375,7 @@ var y = 500, b = 3e3, x = class {
|
|
|
369
375
|
}
|
|
370
376
|
async run(e5) {
|
|
371
377
|
let t3 = `${this.baseUrl}/events`;
|
|
372
|
-
for await (let n2 of
|
|
378
|
+
for await (let n2 of y(t3, e5)) {
|
|
373
379
|
if (n2.type !== "TransactionFinalized") continue;
|
|
374
380
|
let e6 = n2.data, t4 = this.pending.get(e6.transaction_id);
|
|
375
381
|
if (!t4) continue;
|
|
@@ -385,7 +391,7 @@ var y = 500, b = 3e3, x = class {
|
|
|
385
391
|
} else t4.resolve({ decision: "Indeterminate" });
|
|
386
392
|
}
|
|
387
393
|
}
|
|
388
|
-
},
|
|
394
|
+
}, C = class {
|
|
389
395
|
constructor(e5, t3, n2, r2) {
|
|
390
396
|
__publicField(this, "txId");
|
|
391
397
|
__publicField(this, "watcher");
|
|
@@ -412,7 +418,7 @@ var y = 500, b = 3e3, x = class {
|
|
|
412
418
|
r2,
|
|
413
419
|
this.cancellation.promise
|
|
414
420
|
]);
|
|
415
|
-
if (n2 !== null && clearTimeout(n2), i3 === "sse-timeout") return await Promise.race([this.restPollUntilFinal(Date.now() +
|
|
421
|
+
if (n2 !== null && clearTimeout(n2), i3 === "sse-timeout") return await Promise.race([this.restPollUntilFinal(Date.now() + x, o2.signal, x), a2]);
|
|
416
422
|
if (i3.decision === "Indeterminate") return await Promise.race([this.restPollUntilFinal(t3, o2.signal, 0), a2]);
|
|
417
423
|
if (i3.decision === "Commit") return { outcome: "Commit" };
|
|
418
424
|
let s2 = await this.client.getTransactionResult(this.txId);
|
|
@@ -448,7 +454,7 @@ var y = 500, b = 3e3, x = class {
|
|
|
448
454
|
if (e6) return e6.outcome === "Commit" ? { outcome: "Commit" } : this.throwFromReceipt(r3, e6.reason ?? "");
|
|
449
455
|
}
|
|
450
456
|
if (Date.now() >= e5) break;
|
|
451
|
-
await this.delay(
|
|
457
|
+
await this.delay(b, t3);
|
|
452
458
|
} while (Date.now() < e5 && !t3.aborted);
|
|
453
459
|
if (t3.aborted) throw new n(`Wait for transaction ${this.txId} was cancelled`);
|
|
454
460
|
let s2 = this.timeoutMs + r2, c2 = r2 > 0 ? ` (incl. ${r2}ms grace)` : "";
|
|
@@ -479,11 +485,11 @@ var y = 500, b = 3e3, x = class {
|
|
|
479
485
|
return this.client.getTransactionResult(this.txId);
|
|
480
486
|
}
|
|
481
487
|
};
|
|
482
|
-
function
|
|
488
|
+
function w(e5) {
|
|
483
489
|
let t3 = e5 instanceof Error ? e5.message : String(e5);
|
|
484
490
|
return /not found/i.test(t3) || t3.includes("404");
|
|
485
491
|
}
|
|
486
|
-
var
|
|
492
|
+
var T = class t2 {
|
|
487
493
|
constructor(e5, t3, n2, r2) {
|
|
488
494
|
__publicField(this, "client");
|
|
489
495
|
__publicField(this, "_network");
|
|
@@ -493,14 +499,14 @@ var w = class t2 {
|
|
|
493
499
|
this.client = e5, this._network = t3, this._url = n2, this.defaultTransactionTimeoutMs = r2;
|
|
494
500
|
}
|
|
495
501
|
static async connect(e5) {
|
|
496
|
-
let n2 =
|
|
502
|
+
let n2 = _.usingFetchTransport(e5.url);
|
|
497
503
|
return await n2.identityGet(), new t2(n2, e5.network, e5.url, e5.defaultTransactionTimeoutMs ?? 6e4);
|
|
498
504
|
}
|
|
499
505
|
getClient() {
|
|
500
506
|
return this.client;
|
|
501
507
|
}
|
|
502
508
|
watchTransactionSSE(e5, t3) {
|
|
503
|
-
return this._watcher || (this._watcher = new
|
|
509
|
+
return this._watcher || (this._watcher = new S(this._url), this._watcher.start()), this._watcher.watch(e5, this.client, t3 ?? this.defaultTransactionTimeoutMs);
|
|
504
510
|
}
|
|
505
511
|
stopWatcher() {
|
|
506
512
|
var _a;
|
|
@@ -515,7 +521,8 @@ var w = class t2 {
|
|
|
515
521
|
async getSubstate(e5, t3 = null) {
|
|
516
522
|
return this.client.substatesGet(e5, {
|
|
517
523
|
version: t3,
|
|
518
|
-
local_search_only: false
|
|
524
|
+
local_search_only: false,
|
|
525
|
+
include_proof: false
|
|
519
526
|
});
|
|
520
527
|
}
|
|
521
528
|
async getStealthUtxo(e5, t3) {
|
|
@@ -523,14 +530,15 @@ var w = class t2 {
|
|
|
523
530
|
try {
|
|
524
531
|
return await this.getSubstate(n2);
|
|
525
532
|
} catch (e6) {
|
|
526
|
-
if (
|
|
533
|
+
if (w(e6)) return null;
|
|
527
534
|
throw e6;
|
|
528
535
|
}
|
|
529
536
|
}
|
|
530
537
|
async fetchSubstates(e5) {
|
|
531
538
|
return this.client.fetchSubstates({
|
|
532
539
|
requests: e5,
|
|
533
|
-
cached_only: false
|
|
540
|
+
cached_only: false,
|
|
541
|
+
include_proofs: false
|
|
534
542
|
});
|
|
535
543
|
}
|
|
536
544
|
async getTemplateDefinition(e5) {
|
|
@@ -548,7 +556,8 @@ var w = class t2 {
|
|
|
548
556
|
try {
|
|
549
557
|
let e5 = await this.client.substatesGet(t4.substate_id, {
|
|
550
558
|
version: null,
|
|
551
|
-
local_search_only: false
|
|
559
|
+
local_search_only: false,
|
|
560
|
+
include_proof: false
|
|
552
561
|
});
|
|
553
562
|
return {
|
|
554
563
|
...t4,
|
|
@@ -556,7 +565,7 @@ var w = class t2 {
|
|
|
556
565
|
};
|
|
557
566
|
} catch (n2) {
|
|
558
567
|
let r2 = n2 instanceof Error ? n2.message : String(n2);
|
|
559
|
-
throw
|
|
568
|
+
throw w(n2) ? new e(`Failed to find input "${t4.substate_id}": ${r2}. Verify the substate id is correct (typo? wrong network?) or wait for the producing transaction to finalize.`, {
|
|
560
569
|
cause: n2,
|
|
561
570
|
url: this._url
|
|
562
571
|
}) : new e(`Failed to resolve input "${t4.substate_id}": ${r2}. Check the indexer URL points at the same network as the substate.`, {
|
|
@@ -569,7 +578,7 @@ var w = class t2 {
|
|
|
569
578
|
async listRecentTransactions(e5) {
|
|
570
579
|
return await this.client.listRecentTransactions(e5);
|
|
571
580
|
}
|
|
572
|
-
},
|
|
581
|
+
}, E = class e4 {
|
|
573
582
|
constructor() {
|
|
574
583
|
__publicField(this, "_network", t.LocalNet);
|
|
575
584
|
__publicField(this, "_url", null);
|
|
@@ -593,10 +602,10 @@ var w = class t2 {
|
|
|
593
602
|
network: this._network,
|
|
594
603
|
defaultTransactionTimeoutMs: this._transactionTimeoutMs
|
|
595
604
|
};
|
|
596
|
-
return
|
|
605
|
+
return T.connect(e5);
|
|
597
606
|
}
|
|
598
607
|
};
|
|
599
|
-
async function
|
|
608
|
+
async function D(e5, t3) {
|
|
600
609
|
return Promise.all(t3.map(async (t4) => {
|
|
601
610
|
if (t4.type === "SpecificSubstate") {
|
|
602
611
|
if (t4.version != null) return {
|
|
@@ -605,7 +614,8 @@ async function E(e5, t3) {
|
|
|
605
614
|
};
|
|
606
615
|
let n3 = await e5.substatesGet(t4.substateId, {
|
|
607
616
|
version: null,
|
|
608
|
-
local_search_only: false
|
|
617
|
+
local_search_only: false,
|
|
618
|
+
include_proof: false
|
|
609
619
|
});
|
|
610
620
|
return {
|
|
611
621
|
substate_id: t4.substateId,
|
|
@@ -625,13 +635,13 @@ async function E(e5, t3) {
|
|
|
625
635
|
}));
|
|
626
636
|
}
|
|
627
637
|
export {
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
638
|
+
_ as IndexerClient,
|
|
639
|
+
T as IndexerProvider,
|
|
640
|
+
C as PendingTransaction,
|
|
641
|
+
E as ProviderBuilder,
|
|
642
|
+
S as TransactionWatcher,
|
|
643
|
+
y as openEventStream,
|
|
644
|
+
v as parseSseChunk,
|
|
645
|
+
D as resolveWantInputs,
|
|
646
|
+
g as transports
|
|
637
647
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tari-project/ootle-indexer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/tari-project/ootle.ts.git",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@tari-project/indexer-client": "^1.
|
|
29
|
-
"@tari-project/ootle-ts-bindings": "^1.
|
|
30
|
-
"@tari-project/ootle": "0.
|
|
28
|
+
"@tari-project/indexer-client": "^1.10.0",
|
|
29
|
+
"@tari-project/ootle-ts-bindings": "^1.57.0",
|
|
30
|
+
"@tari-project/ootle": "0.8.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^25.5.0",
|