@secondlayer/subgraphs 8.0.4 → 8.1.1
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 +7 -6
- package/dist/index.js.map +4 -4
- package/dist/runtime/emitter.js +37 -10
- package/dist/runtime/emitter.js.map +3 -3
- package/dist/runtime/replay.js +29 -13
- package/dist/runtime/replay.js.map +6 -6
- package/dist/schema/index.js +5 -4
- package/dist/schema/index.js.map +3 -3
- package/dist/testing/index.js +3 -3
- package/dist/testing/index.js.map +1 -1
- package/dist/verification.js +3 -3
- package/dist/verification.js.map +1 -1
- package/dist/verify/index.js +3 -3
- package/dist/verify/index.js.map +1 -1
- package/package.json +2 -2
package/dist/runtime/replay.js
CHANGED
|
@@ -12,6 +12,7 @@ import { logger as logger2 } from "@secondlayer/shared/logger";
|
|
|
12
12
|
|
|
13
13
|
// src/runtime/block-source.ts
|
|
14
14
|
import { getSourceDb } from "@secondlayer/shared/db";
|
|
15
|
+
import { resolveChainTip } from "@secondlayer/shared/db/queries/integrity";
|
|
15
16
|
import {
|
|
16
17
|
BillingPausedError,
|
|
17
18
|
createInternalIndexHttpClient
|
|
@@ -23,7 +24,7 @@ import { createHash } from "node:crypto";
|
|
|
23
24
|
// package.json
|
|
24
25
|
var package_default = {
|
|
25
26
|
name: "@secondlayer/subgraphs",
|
|
26
|
-
version: "8.
|
|
27
|
+
version: "8.1.1",
|
|
27
28
|
description: "Describe the Stacks data you want as one TypeScript file; it fills itself and survives reorgs.",
|
|
28
29
|
license: "MIT",
|
|
29
30
|
repository: {
|
|
@@ -79,7 +80,7 @@ var package_default = {
|
|
|
79
80
|
prepublishOnly: "bun run build"
|
|
80
81
|
},
|
|
81
82
|
dependencies: {
|
|
82
|
-
"@secondlayer/shared": "^15.
|
|
83
|
+
"@secondlayer/shared": "^15.3.1",
|
|
83
84
|
"@secondlayer/stacks": "^6.5.4",
|
|
84
85
|
"@secondlayer/verify": "^0.6.3",
|
|
85
86
|
esbuild: "^0.28.2",
|
|
@@ -928,8 +929,7 @@ class PostgresBlockSource {
|
|
|
928
929
|
this.feed = feed;
|
|
929
930
|
}
|
|
930
931
|
async getTip() {
|
|
931
|
-
|
|
932
|
-
return progress ? Number(progress.highest_seen_block) : 0;
|
|
932
|
+
return await resolveChainTip(getSourceDb(), "seen") ?? 0;
|
|
933
933
|
}
|
|
934
934
|
loadBlockRange(fromHeight, toHeight) {
|
|
935
935
|
return loadBlockRange(getSourceDb(), fromHeight, toHeight, {
|
|
@@ -1153,8 +1153,9 @@ function databaseChainDataReader(db) {
|
|
|
1153
1153
|
traitContractIds(trait, asOfBlock) {
|
|
1154
1154
|
return resolveTraitContractIds(db, trait, asOfBlock);
|
|
1155
1155
|
},
|
|
1156
|
-
|
|
1157
|
-
|
|
1156
|
+
async settlementsSince(scan) {
|
|
1157
|
+
const rows = await db.selectFrom("sbtc_settlements as s").innerJoin("sbtc_events as e", (join) => join.onRef("e.sweep_txid", "=", "s.sweep_txid").on("e.topic", "=", "withdrawal-accept").on("e.canonical", "=", true)).innerJoin("blocks as b", (join) => join.onRef("b.height", "=", "e.block_height").on("b.canonical", "=", true)).where("s.settlement_confirmed", "=", true).where((eb) => ("afterSeq" in scan) ? eb("s.seq", ">", scan.afterSeq) : eb("s.confirmed_at", ">", scan.confirmedAfter)).select([
|
|
1158
|
+
"s.seq",
|
|
1158
1159
|
"s.sweep_txid",
|
|
1159
1160
|
"s.request_id",
|
|
1160
1161
|
"s.btc_confirmations",
|
|
@@ -1166,7 +1167,8 @@ function databaseChainDataReader(db) {
|
|
|
1166
1167
|
"e.sender",
|
|
1167
1168
|
"b.hash as block_hash",
|
|
1168
1169
|
"b.timestamp as block_timestamp"
|
|
1169
|
-
]).execute();
|
|
1170
|
+
]).orderBy("s.seq").execute();
|
|
1171
|
+
return rows.map((row) => ({ ...row, seq: Number(row.seq) }));
|
|
1170
1172
|
}
|
|
1171
1173
|
};
|
|
1172
1174
|
}
|
|
@@ -1248,8 +1250,8 @@ function hostedChainDataReader(client, opts = {}) {
|
|
|
1248
1250
|
}
|
|
1249
1251
|
return ids;
|
|
1250
1252
|
},
|
|
1251
|
-
async
|
|
1252
|
-
const withdrawals = oneWithdrawalPerSweep(await client.fetchSettledWithdrawals(
|
|
1253
|
+
async settlementsSince(scan) {
|
|
1254
|
+
const withdrawals = oneWithdrawalPerSweep(await client.fetchSettledWithdrawals(scan)).sort((a, b) => Number(a.settlement_seq) - Number(b.settlement_seq));
|
|
1253
1255
|
const out = [];
|
|
1254
1256
|
for (const w of withdrawals) {
|
|
1255
1257
|
const accepts = await client.fetchSbtcEvents(0, THROUGH_TIP, ["withdrawal-accept"], { requestId: w.request_id });
|
|
@@ -1260,6 +1262,7 @@ function hostedChainDataReader(client, opts = {}) {
|
|
|
1260
1262
|
if (!block)
|
|
1261
1263
|
continue;
|
|
1262
1264
|
out.push({
|
|
1265
|
+
seq: Number(w.settlement_seq),
|
|
1263
1266
|
sweep_txid: w.sweep_txid,
|
|
1264
1267
|
request_id: w.request_id,
|
|
1265
1268
|
btc_confirmations: w.btc_confirmations ?? 0,
|
|
@@ -1292,7 +1295,7 @@ function chainDataReader(opts) {
|
|
|
1292
1295
|
return {
|
|
1293
1296
|
sbtcEvents: async (...args) => (await reader()).sbtcEvents(...args),
|
|
1294
1297
|
traitContractIds: async (...args) => (await reader()).traitContractIds(...args),
|
|
1295
|
-
|
|
1298
|
+
settlementsSince: async (...args) => (await reader()).settlementsSince(...args)
|
|
1296
1299
|
};
|
|
1297
1300
|
}
|
|
1298
1301
|
var processHttpClient;
|
|
@@ -1818,6 +1821,7 @@ function applyRow(meta, blockHeight, blockHash, txId, eventIndex, event, replayI
|
|
|
1818
1821
|
webhook_id: meta.webhookId,
|
|
1819
1822
|
kind: "chain",
|
|
1820
1823
|
block_height: blockHeight,
|
|
1824
|
+
block_hash: blockHash,
|
|
1821
1825
|
tx_id: txId,
|
|
1822
1826
|
row_pk: clock === "vm" ? { tx_id: txId, event_index: eventIndex, clock } : { tx_id: txId, event_index: eventIndex },
|
|
1823
1827
|
event_type: `chain.${meta.triggerType}.apply`,
|
|
@@ -2044,13 +2048,25 @@ async function replayWebhook(input, opts) {
|
|
|
2044
2048
|
});
|
|
2045
2049
|
try {
|
|
2046
2050
|
const result = await replayChainWebhook(db, sub, input, opts);
|
|
2047
|
-
await finishScan(db, replayId, {
|
|
2051
|
+
const finished = await finishScan(db, replayId, {
|
|
2048
2052
|
scanned: result.scannedCount,
|
|
2049
2053
|
enqueued: result.enqueuedCount
|
|
2050
2054
|
});
|
|
2055
|
+
if (!finished) {
|
|
2056
|
+
logger2.warn("Replay scan finished but the replay was no longer scanning", {
|
|
2057
|
+
replayId,
|
|
2058
|
+
webhookId: sub.id
|
|
2059
|
+
});
|
|
2060
|
+
}
|
|
2051
2061
|
return result;
|
|
2052
2062
|
} catch (err) {
|
|
2053
|
-
await failScan(db, replayId, getErrorMessage(err));
|
|
2063
|
+
const failed = await failScan(db, replayId, getErrorMessage(err));
|
|
2064
|
+
if (!failed) {
|
|
2065
|
+
logger2.warn("Replay scan failed but the replay was no longer scanning", {
|
|
2066
|
+
replayId,
|
|
2067
|
+
webhookId: sub.id
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2054
2070
|
throw err;
|
|
2055
2071
|
}
|
|
2056
2072
|
}
|
|
@@ -2103,5 +2119,5 @@ export {
|
|
|
2103
2119
|
replayWebhook
|
|
2104
2120
|
};
|
|
2105
2121
|
|
|
2106
|
-
//# debugId=
|
|
2122
|
+
//# debugId=79ADCE67697CFB1864756E2164756E21
|
|
2107
2123
|
//# sourceMappingURL=replay.js.map
|