@tari-project/ootle-indexer 0.2.0 → 0.4.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.ts +1 -0
- package/dist/index.js +42 -36
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -46,6 +46,7 @@ export declare class IndexerProvider implements Provider {
|
|
|
46
46
|
*/
|
|
47
47
|
stopWatcher(): void;
|
|
48
48
|
network(): Network;
|
|
49
|
+
getCurrentEpoch(): Promise<number>;
|
|
49
50
|
getSubstate(substateId: string, version?: number | null): Promise<IndexerGetSubstateResponse>;
|
|
50
51
|
getStealthUtxo(resourceAddress: string, commitment: Uint8Array): Promise<IndexerGetSubstateResponse | null>;
|
|
51
52
|
fetchSubstates(requests: SubstateId[]): Promise<GetSubstatesResponse>;
|
package/dist/index.js
CHANGED
|
@@ -10,10 +10,13 @@ var l = Object.defineProperty, u = (e5, t3) => {
|
|
|
10
10
|
});
|
|
11
11
|
return t3 || l(n2, Symbol.toStringTag, { value: "Module" }), n2;
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
function
|
|
13
|
+
function d(e5) {
|
|
14
|
+
return JSON.stringify(e5, f);
|
|
15
|
+
}
|
|
16
|
+
function f(e5, t3) {
|
|
17
|
+
return typeof t3 == "bigint" ? t3.toString() : t3;
|
|
18
|
+
}
|
|
19
|
+
function p(e5, t3) {
|
|
17
20
|
let n2 = new AbortController();
|
|
18
21
|
return t3.signal && (t3.signal.aborted ? n2.abort() : t3.signal.addEventListener("abort", () => n2.abort(), { once: true })), (async () => {
|
|
19
22
|
let r2 = await fetch(e5, {
|
|
@@ -87,7 +90,7 @@ function d(e5, t3) {
|
|
|
87
90
|
n2.abort();
|
|
88
91
|
} };
|
|
89
92
|
}
|
|
90
|
-
var
|
|
93
|
+
var m = class e2 {
|
|
91
94
|
constructor(e5) {
|
|
92
95
|
__publicField(this, "url");
|
|
93
96
|
this.url = e5;
|
|
@@ -135,7 +138,7 @@ var f = class e2 {
|
|
|
135
138
|
let n3 = e6.toString();
|
|
136
139
|
n3.length > 0 && (r2 += `?${n3}`);
|
|
137
140
|
}
|
|
138
|
-
return
|
|
141
|
+
return p(r2, n2);
|
|
139
142
|
}
|
|
140
143
|
async sendRequest(e5, t3, n2) {
|
|
141
144
|
let r2 = new AbortController(), i2 = r2.signal, a2 = (n2 == null ? void 0 : n2.timeout_millis) ? setTimeout(() => {
|
|
@@ -148,7 +151,7 @@ var f = class e2 {
|
|
|
148
151
|
for (let [n3, r3] of Object.entries(t3.params)) r3 != null && e6.append(n3, r3.toString());
|
|
149
152
|
o2 = e6;
|
|
150
153
|
}
|
|
151
|
-
typeof t3.body == "object" && t3.body !== null && (t3.headers || (t3.headers = {}), t3.headers["Content-Type"] = "application/json", t3.body =
|
|
154
|
+
typeof t3.body == "object" && t3.body !== null && (t3.headers || (t3.headers = {}), t3.headers["Content-Type"] = "application/json", t3.body = d(t3.body));
|
|
152
155
|
let s2 = `${this.url}/${e5}`;
|
|
153
156
|
o2 && o2.toString().length > 0 && (s2 += `?${o2.toString()}`);
|
|
154
157
|
let c2 = await fetch(s2, {
|
|
@@ -163,7 +166,7 @@ var f = class e2 {
|
|
|
163
166
|
if (l2.error) throw Error(`${l2.error.code}: ${l2.error.message}`);
|
|
164
167
|
return l2;
|
|
165
168
|
}
|
|
166
|
-
},
|
|
169
|
+
}, h = /* @__PURE__ */ u({ FetchTransport: () => m }), g = class e3 {
|
|
167
170
|
constructor(e5) {
|
|
168
171
|
__publicField(this, "transport");
|
|
169
172
|
this.transport = e5;
|
|
@@ -172,7 +175,7 @@ var f = class e2 {
|
|
|
172
175
|
return new e3(t3);
|
|
173
176
|
}
|
|
174
177
|
static usingFetchTransport(t3) {
|
|
175
|
-
return e3.new(
|
|
178
|
+
return e3.new(m.new(t3));
|
|
176
179
|
}
|
|
177
180
|
getTransport() {
|
|
178
181
|
return this.transport;
|
|
@@ -268,7 +271,7 @@ var f = class e2 {
|
|
|
268
271
|
});
|
|
269
272
|
}
|
|
270
273
|
};
|
|
271
|
-
function
|
|
274
|
+
function _(e5) {
|
|
272
275
|
let t3 = [], n2 = e5.split(/\n\n|\r\n\r\n/), r2 = n2.pop() ?? "";
|
|
273
276
|
for (let e6 of n2) {
|
|
274
277
|
if (!e6.trim()) continue;
|
|
@@ -290,7 +293,7 @@ function h(e5) {
|
|
|
290
293
|
remainder: r2
|
|
291
294
|
};
|
|
292
295
|
}
|
|
293
|
-
async function*
|
|
296
|
+
async function* v(t3, n2) {
|
|
294
297
|
for (; !n2.aborted; ) {
|
|
295
298
|
let r2 = new AbortController(), i2 = () => r2.abort();
|
|
296
299
|
n2.addEventListener("abort", i2, { once: true });
|
|
@@ -315,7 +318,7 @@ async function* g(t3, n2) {
|
|
|
315
318
|
let { done: e5, value: t4 } = await a2.read();
|
|
316
319
|
if (e5) break;
|
|
317
320
|
s2 += o2.decode(t4, { stream: true });
|
|
318
|
-
let { events: n3, remainder: r3 } =
|
|
321
|
+
let { events: n3, remainder: r3 } = _(s2);
|
|
319
322
|
s2 = r3;
|
|
320
323
|
for (let e6 of n3) yield e6;
|
|
321
324
|
}
|
|
@@ -335,7 +338,7 @@ async function* g(t3, n2) {
|
|
|
335
338
|
}
|
|
336
339
|
}
|
|
337
340
|
}
|
|
338
|
-
var
|
|
341
|
+
var y = 500, b = 3e3, x = class {
|
|
339
342
|
constructor(e5) {
|
|
340
343
|
__publicField(this, "baseUrl");
|
|
341
344
|
__publicField(this, "pending", /* @__PURE__ */ new Map());
|
|
@@ -354,7 +357,7 @@ var _ = 500, v = 3e3, y = class {
|
|
|
354
357
|
this.pending.clear();
|
|
355
358
|
}
|
|
356
359
|
watch(e5, t3, n2 = 32e3) {
|
|
357
|
-
return this.start(), new
|
|
360
|
+
return this.start(), new S(e5, this, t3, n2);
|
|
358
361
|
}
|
|
359
362
|
register(e5) {
|
|
360
363
|
return new Promise((t3, n2) => {
|
|
@@ -369,7 +372,7 @@ var _ = 500, v = 3e3, y = class {
|
|
|
369
372
|
}
|
|
370
373
|
async run(e5) {
|
|
371
374
|
let t3 = `${this.baseUrl}/events`;
|
|
372
|
-
for await (let n2 of
|
|
375
|
+
for await (let n2 of v(t3, e5)) {
|
|
373
376
|
if (n2.type !== "TransactionFinalized") continue;
|
|
374
377
|
let e6 = n2.data, t4 = this.pending.get(e6.transaction_id);
|
|
375
378
|
if (!t4) continue;
|
|
@@ -385,7 +388,7 @@ var _ = 500, v = 3e3, y = class {
|
|
|
385
388
|
} else t4.resolve({ decision: "Indeterminate" });
|
|
386
389
|
}
|
|
387
390
|
}
|
|
388
|
-
},
|
|
391
|
+
}, S = class {
|
|
389
392
|
constructor(e5, t3, n2, r2) {
|
|
390
393
|
__publicField(this, "txId");
|
|
391
394
|
__publicField(this, "watcher");
|
|
@@ -412,7 +415,7 @@ var _ = 500, v = 3e3, y = class {
|
|
|
412
415
|
r2,
|
|
413
416
|
this.cancellation.promise
|
|
414
417
|
]);
|
|
415
|
-
if (n2 !== null && clearTimeout(n2), i3 === "sse-timeout") return await Promise.race([this.restPollUntilFinal(Date.now() +
|
|
418
|
+
if (n2 !== null && clearTimeout(n2), i3 === "sse-timeout") return await Promise.race([this.restPollUntilFinal(Date.now() + b, o2.signal, b), a2]);
|
|
416
419
|
if (i3.decision === "Indeterminate") return await Promise.race([this.restPollUntilFinal(t3, o2.signal, 0), a2]);
|
|
417
420
|
if (i3.decision === "Commit") return { outcome: "Commit" };
|
|
418
421
|
let s2 = await this.client.getTransactionResult(this.txId);
|
|
@@ -448,7 +451,7 @@ var _ = 500, v = 3e3, y = class {
|
|
|
448
451
|
if (e6) return e6.outcome === "Commit" ? { outcome: "Commit" } : this.throwFromReceipt(r3, e6.reason ?? "");
|
|
449
452
|
}
|
|
450
453
|
if (Date.now() >= e5) break;
|
|
451
|
-
await this.delay(
|
|
454
|
+
await this.delay(y, t3);
|
|
452
455
|
} while (Date.now() < e5 && !t3.aborted);
|
|
453
456
|
if (t3.aborted) throw new n(`Wait for transaction ${this.txId} was cancelled`);
|
|
454
457
|
let s2 = this.timeoutMs + r2, c2 = r2 > 0 ? ` (incl. ${r2}ms grace)` : "";
|
|
@@ -479,11 +482,11 @@ var _ = 500, v = 3e3, y = class {
|
|
|
479
482
|
return this.client.getTransactionResult(this.txId);
|
|
480
483
|
}
|
|
481
484
|
};
|
|
482
|
-
function
|
|
485
|
+
function C(e5) {
|
|
483
486
|
let t3 = e5 instanceof Error ? e5.message : String(e5);
|
|
484
487
|
return /not found/i.test(t3) || t3.includes("404");
|
|
485
488
|
}
|
|
486
|
-
var
|
|
489
|
+
var w = class t2 {
|
|
487
490
|
constructor(e5, t3, n2, r2) {
|
|
488
491
|
__publicField(this, "client");
|
|
489
492
|
__publicField(this, "_network");
|
|
@@ -493,14 +496,14 @@ var S = class t2 {
|
|
|
493
496
|
this.client = e5, this._network = t3, this._url = n2, this.defaultTransactionTimeoutMs = r2;
|
|
494
497
|
}
|
|
495
498
|
static async connect(e5) {
|
|
496
|
-
let n2 =
|
|
499
|
+
let n2 = g.usingFetchTransport(e5.url);
|
|
497
500
|
return await n2.identityGet(), new t2(n2, e5.network, e5.url, e5.defaultTransactionTimeoutMs ?? 6e4);
|
|
498
501
|
}
|
|
499
502
|
getClient() {
|
|
500
503
|
return this.client;
|
|
501
504
|
}
|
|
502
505
|
watchTransactionSSE(e5, t3) {
|
|
503
|
-
return this._watcher || (this._watcher = new
|
|
506
|
+
return this._watcher || (this._watcher = new x(this._url), this._watcher.start()), this._watcher.watch(e5, this.client, t3 ?? this.defaultTransactionTimeoutMs);
|
|
504
507
|
}
|
|
505
508
|
stopWatcher() {
|
|
506
509
|
var _a;
|
|
@@ -509,6 +512,9 @@ var S = class t2 {
|
|
|
509
512
|
network() {
|
|
510
513
|
return this._network;
|
|
511
514
|
}
|
|
515
|
+
async getCurrentEpoch() {
|
|
516
|
+
return (await this.client.epochManagerStats()).current_epoch;
|
|
517
|
+
}
|
|
512
518
|
async getSubstate(e5, t3 = null) {
|
|
513
519
|
return this.client.substatesGet(e5, {
|
|
514
520
|
version: t3,
|
|
@@ -520,7 +526,7 @@ var S = class t2 {
|
|
|
520
526
|
try {
|
|
521
527
|
return await this.getSubstate(n2);
|
|
522
528
|
} catch (e6) {
|
|
523
|
-
if (
|
|
529
|
+
if (C(e6)) return null;
|
|
524
530
|
throw e6;
|
|
525
531
|
}
|
|
526
532
|
}
|
|
@@ -553,7 +559,7 @@ var S = class t2 {
|
|
|
553
559
|
};
|
|
554
560
|
} catch (n2) {
|
|
555
561
|
let r2 = n2 instanceof Error ? n2.message : String(n2);
|
|
556
|
-
throw
|
|
562
|
+
throw C(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.`, {
|
|
557
563
|
cause: n2,
|
|
558
564
|
url: this._url
|
|
559
565
|
}) : new e(`Failed to resolve input "${t4.substate_id}": ${r2}. Check the indexer URL points at the same network as the substate.`, {
|
|
@@ -566,7 +572,7 @@ var S = class t2 {
|
|
|
566
572
|
async listRecentTransactions(e5) {
|
|
567
573
|
return await this.client.listRecentTransactions(e5);
|
|
568
574
|
}
|
|
569
|
-
},
|
|
575
|
+
}, T = class e4 {
|
|
570
576
|
constructor() {
|
|
571
577
|
__publicField(this, "_network", t.LocalNet);
|
|
572
578
|
__publicField(this, "_url", null);
|
|
@@ -590,10 +596,10 @@ var S = class t2 {
|
|
|
590
596
|
network: this._network,
|
|
591
597
|
defaultTransactionTimeoutMs: this._transactionTimeoutMs
|
|
592
598
|
};
|
|
593
|
-
return
|
|
599
|
+
return w.connect(e5);
|
|
594
600
|
}
|
|
595
601
|
};
|
|
596
|
-
async function
|
|
602
|
+
async function E(e5, t3) {
|
|
597
603
|
return Promise.all(t3.map(async (t4) => {
|
|
598
604
|
if (t4.type === "SpecificSubstate") {
|
|
599
605
|
if (t4.version != null) return {
|
|
@@ -622,13 +628,13 @@ async function w(e5, t3) {
|
|
|
622
628
|
}));
|
|
623
629
|
}
|
|
624
630
|
export {
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
631
|
+
g as IndexerClient,
|
|
632
|
+
w as IndexerProvider,
|
|
633
|
+
S as PendingTransaction,
|
|
634
|
+
T as ProviderBuilder,
|
|
635
|
+
x as TransactionWatcher,
|
|
636
|
+
v as openEventStream,
|
|
637
|
+
_ as parseSseChunk,
|
|
638
|
+
E as resolveWantInputs,
|
|
639
|
+
h as transports
|
|
634
640
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tari-project/ootle-indexer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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.6.0",
|
|
29
|
+
"@tari-project/ootle-ts-bindings": "^1.50.1",
|
|
30
|
+
"@tari-project/ootle": "0.4.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^25.5.0",
|