@secondlayer/subgraphs 3.15.2 → 3.17.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.
@@ -1354,7 +1354,9 @@ import { sql as sql3 } from "kysely";
1354
1354
 
1355
1355
  // src/runtime/block-source.ts
1356
1356
  import { getSourceDb } from "@secondlayer/shared/db";
1357
- import { IndexHttpClient } from "@secondlayer/shared/index-http";
1357
+ import {
1358
+ IndexHttpClient
1359
+ } from "@secondlayer/shared/index-http";
1358
1360
  import { logger as logger3 } from "@secondlayer/shared/logger";
1359
1361
 
1360
1362
  // src/runtime/batch-loader.ts
@@ -1433,6 +1435,22 @@ function reconstructTransaction(t) {
1433
1435
  created_at: new Date(0)
1434
1436
  };
1435
1437
  }
1438
+ function reconstructTxFromEventRow(e) {
1439
+ return {
1440
+ tx_id: e.tx_id,
1441
+ block_height: e.block_height,
1442
+ tx_index: e.tx_index ?? 0,
1443
+ type: e.tx_type ?? "",
1444
+ sender: e.tx_sender ?? "",
1445
+ status: e.tx_status ?? "success",
1446
+ contract_id: e.tx_contract_id ?? null,
1447
+ function_name: e.tx_function_name ?? null,
1448
+ function_args: [],
1449
+ raw_result: null,
1450
+ raw_tx: "",
1451
+ created_at: new Date(0)
1452
+ };
1453
+ }
1436
1454
  function reconstructEvent(e) {
1437
1455
  const base = {
1438
1456
  id: `${e.tx_id}#${e.event_index}`,
@@ -1558,6 +1576,17 @@ function sourceFilters(subgraph) {
1558
1576
  const sources = subgraph.sources;
1559
1577
  return Array.isArray(sources) ? sources : Object.values(sources);
1560
1578
  }
1579
+ function needsTransactionData(subgraph) {
1580
+ return sourceFilters(subgraph).some((f) => TX_SOURCE_TYPES.has(f.type));
1581
+ }
1582
+ function synthesizeTxsFromEvents(events) {
1583
+ const byId = new Map;
1584
+ for (const e of events) {
1585
+ if (!byId.has(e.tx_id))
1586
+ byId.set(e.tx_id, reconstructTxFromEventRow(e));
1587
+ }
1588
+ return [...byId.values()];
1589
+ }
1561
1590
  function indexEventTypesForFilterTypes(filterTypes) {
1562
1591
  if (filterTypes.some((t) => TX_SOURCE_TYPES.has(t))) {
1563
1592
  return ALL_INDEX_EVENT_TYPES;
@@ -1591,10 +1620,12 @@ class PublicApiBlockSource {
1591
1620
  http;
1592
1621
  eventTypes;
1593
1622
  probeTargets;
1594
- constructor(http, eventTypes, probeTargets) {
1623
+ needsTransactions;
1624
+ constructor(http, eventTypes, probeTargets, needsTransactions = true) {
1595
1625
  this.http = http;
1596
1626
  this.eventTypes = eventTypes;
1597
1627
  this.probeTargets = probeTargets;
1628
+ this.needsTransactions = needsTransactions;
1598
1629
  }
1599
1630
  async nextDataHeight(afterHeight, untilHeight) {
1600
1631
  if (!this.probeTargets?.length)
@@ -1607,10 +1638,11 @@ class PublicApiBlockSource {
1607
1638
  return this.http.getIndexTip();
1608
1639
  }
1609
1640
  async loadBlockRange(fromHeight, toHeight) {
1610
- const [blocks, txs, eventLists] = await Promise.all([
1641
+ const withTx = !this.needsTransactions;
1642
+ const [blocks, txRows, eventLists] = await Promise.all([
1611
1643
  this.http.walkBlocks(fromHeight, toHeight),
1612
- this.http.walkTransactions(fromHeight, toHeight),
1613
- Promise.all(this.eventTypes.map((t) => this.http.walkEvents(t, fromHeight, toHeight)))
1644
+ this.needsTransactions ? this.http.walkTransactions(fromHeight, toHeight) : Promise.resolve([]),
1645
+ Promise.all(this.eventTypes.map((t) => this.http.walkEvents(t, fromHeight, toHeight, withTx)))
1614
1646
  ]);
1615
1647
  const map = new Map;
1616
1648
  for (const b of blocks) {
@@ -1620,8 +1652,9 @@ class PublicApiBlockSource {
1620
1652
  events: []
1621
1653
  });
1622
1654
  }
1655
+ const txs = this.needsTransactions ? txRows.map(reconstructTransaction) : synthesizeTxsFromEvents(eventLists.flat());
1623
1656
  for (const t of txs) {
1624
- map.get(t.block_height)?.txs.push(reconstructTransaction(t));
1657
+ map.get(t.block_height)?.txs.push(t);
1625
1658
  }
1626
1659
  for (const list of eventLists) {
1627
1660
  for (const e of list) {
@@ -1686,7 +1719,7 @@ function buildHttpClient() {
1686
1719
  }
1687
1720
  function resolveBlockSource(subgraph) {
1688
1721
  if (process.env.SUBGRAPH_SOURCE === "streams-index" && subgraph && isStreamsIndexEligible(subgraph)) {
1689
- return new FallbackBlockSource(new PublicApiBlockSource(buildHttpClient(), referencedIndexEventTypes(subgraph), canSparseScan(subgraph) ? sparseProbeTargets(subgraph) : undefined), postgresBlockSource);
1722
+ return new FallbackBlockSource(new PublicApiBlockSource(buildHttpClient(), referencedIndexEventTypes(subgraph), canSparseScan(subgraph) ? sparseProbeTargets(subgraph) : undefined, needsTransactionData(subgraph)), postgresBlockSource);
1690
1723
  }
1691
1724
  if (process.env.SUBGRAPH_SOURCE === "streams-index" && subgraph) {
1692
1725
  logger3.debug("Subgraph not streams-index eligible, using DB tap", {
@@ -2320,5 +2353,5 @@ export {
2320
2353
  handleSubgraphReorg
2321
2354
  };
2322
2355
 
2323
- //# debugId=31DC2A79B3C82C3A64756E2164756E21
2356
+ //# debugId=9AC73085D64D8A9364756E2164756E21
2324
2357
  //# sourceMappingURL=reorg.js.map