@ocap/indexdb 1.31.4 → 1.31.6

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/esm/backfill.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { deriveTxGasPayer, deriveTxSender } from "./util.mjs";
2
2
  import crypto from "node:crypto";
3
+ import { stripDefaultDepositV2BridgeFields } from "@ocap/util/lib/deposit-v2-bridge-fields";
3
4
  import uniq from "lodash/uniq.js";
4
5
 
5
6
  //#region src/backfill.ts
@@ -106,7 +107,7 @@ function buildTxIndexBackfillPlan(params) {
106
107
  const typeName = type ? `${type.split("_").filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("")}Tx` : "";
107
108
  const from = String(entry.from || parsedTx.from || "");
108
109
  const delegator = String(parsedTx.delegator || "");
109
- const itxJson = parseJsonObject(parsedTx.itxJson || parsedTx.itx);
110
+ const itxJson = stripDefaultDepositV2BridgeFields(typeName || txType, parseJsonObject(parsedTx.itxJson || parsedTx.itx));
110
111
  if (txType && !itxJson.type_url) itxJson.type_url = txType;
111
112
  if (typeName && !itxJson._type) itxJson._type = typeName;
112
113
  const sender = deriveTxSender({ tx: {
package/esm/main.d.mts CHANGED
@@ -2,6 +2,6 @@ import { ILedgerEntrySnapshot, ISqliteDatabaseLike, ISqliteStatementLike, ITxInd
2
2
  import BaseIndexDB from "./db.mjs";
3
3
  import BaseIndex from "./index.mjs";
4
4
  import { SearchResultFormatOptions, formatSearchResult } from "./search-result.mjs";
5
- import { BridgeReleaseEvidenceInput, DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, getBridgeReleaseEvidenceKey, isDefaultTokenChanged, parseDateTime } from "./util.mjs";
5
+ import { BridgeReleaseEvidenceInput, DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, getBridgeReleaseEvidenceKey, getTxBridgeReleaseEvidenceKey, isDefaultTokenChanged, parseDateTime } from "./util.mjs";
6
6
  import { clearIndexDB, rebuildIndexFromState, scanStateTable } from "./rebuild.mjs";
7
- export { BaseIndex, BaseIndexDB, BridgeReleaseEvidenceInput, DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, ILedgerEntrySnapshot, ISqliteDatabaseLike, ISqliteStatementLike, ITxIndexBackfillInsert, ITxIndexBackfillPlan, ITxIndexBackfillUpdate, ITxIndexRowSnapshot, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, type SearchResultFormatOptions, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, applyTxIndexBackfill, buildTxIndexBackfillPlan, clearIndexDB, computeBackfillPlanDigest, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatSearchResult, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, getBridgeReleaseEvidenceKey, isDefaultTokenChanged, parseDateTime, planTxIndexBackfill, rebuildIndexFromState, scanStateTable };
7
+ export { BaseIndex, BaseIndexDB, BridgeReleaseEvidenceInput, DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, ILedgerEntrySnapshot, ISqliteDatabaseLike, ISqliteStatementLike, ITxIndexBackfillInsert, ITxIndexBackfillPlan, ITxIndexBackfillUpdate, ITxIndexRowSnapshot, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, type SearchResultFormatOptions, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, applyTxIndexBackfill, buildTxIndexBackfillPlan, clearIndexDB, computeBackfillPlanDigest, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatSearchResult, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, getBridgeReleaseEvidenceKey, getTxBridgeReleaseEvidenceKey, isDefaultTokenChanged, parseDateTime, planTxIndexBackfill, rebuildIndexFromState, scanStateTable };
package/esm/main.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, getBridgeReleaseEvidenceKey, isDefaultTokenChanged, parseDateTime } from "./util.mjs";
1
+ import { createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, getBridgeReleaseEvidenceKey, getTxBridgeReleaseEvidenceKey, isDefaultTokenChanged, parseDateTime } from "./util.mjs";
2
2
  import { applyTxIndexBackfill, buildTxIndexBackfillPlan, computeBackfillPlanDigest, planTxIndexBackfill } from "./backfill.mjs";
3
3
  import { clearIndexDB, rebuildIndexFromState, scanStateTable } from "./rebuild.mjs";
4
4
  import db_default from "./db.mjs";
5
5
  import src_default from "./index.mjs";
6
6
  import { formatSearchResult } from "./search-result.mjs";
7
7
 
8
- export { src_default as BaseIndex, db_default as BaseIndexDB, applyTxIndexBackfill, buildTxIndexBackfillPlan, clearIndexDB, computeBackfillPlanDigest, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatSearchResult, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, getBridgeReleaseEvidenceKey, isDefaultTokenChanged, parseDateTime, planTxIndexBackfill, rebuildIndexFromState, scanStateTable };
8
+ export { src_default as BaseIndex, db_default as BaseIndexDB, applyTxIndexBackfill, buildTxIndexBackfillPlan, clearIndexDB, computeBackfillPlanDigest, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatSearchResult, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, getBridgeReleaseEvidenceKey, getTxBridgeReleaseEvidenceKey, isDefaultTokenChanged, parseDateTime, planTxIndexBackfill, rebuildIndexFromState, scanStateTable };
package/esm/util.d.mts CHANGED
@@ -236,7 +236,7 @@ declare const createIndexedFactory: (factory: IAssetFactoryState & {
236
236
  }, context: FactoryContext) => Record<string, unknown> & {
237
237
  tokens: TokenWithBalance[];
238
238
  };
239
- /** Fields of a release_bridge_token itx that identify the deposit or withdraw being settled */
239
+ /** Fields of a bridge release that identify the deposit or withdraw being settled */
240
240
  interface BridgeReleaseEvidenceInput {
241
241
  /** OCAP bridge (RollupState address) the release belongs to (bridge/docs/ocap-protocols.md §v2.4) */
242
242
  bridge?: string;
@@ -245,7 +245,7 @@ interface BridgeReleaseEvidenceInput {
245
245
  ordinal?: number | string;
246
246
  }
247
247
  /**
248
- * Evidence lookup key of a release_bridge_token tx: `<bridge>:<kind>:<evidence lowercased>:<ordinal>`
248
+ * Evidence lookup key of a bridge release: `<bridge>:<kind>:<evidence lowercased>:<ordinal>`
249
249
  * (kind and ordinal as decimal strings, bridge as given, trimmed: OCAP addresses are case-sensitive).
250
250
  * Returns null unless bridge is a non-empty string without ':' or whitespace, kind is 1, 2 or 3, ordinal is a
251
251
  * non-negative integer and evidence is a 0x-prefixed 32-byte hex string (after trim + lowercase).
@@ -254,6 +254,12 @@ interface BridgeReleaseEvidenceInput {
254
254
  * Pass the same key in `txFilter.evidences` of listTransactions to find the release tx.
255
255
  */
256
256
  declare const getBridgeReleaseEvidenceKey: (itx?: BridgeReleaseEvidenceInput | null) => string | null;
257
+ /**
258
+ * Evidence lookup key of a release (#1693, bridge/docs/deposit-withdraw-v2-unification.md §2.7): a `deposit_token_v2`
259
+ * with kind 1/2/3 (the bridge branch), `{ rollup, kind, evidence: { hash }, ordinal }`, mapped onto the
260
+ * `<bridge>:<kind>:<evidence>:<ordinal>` key, so one `txFilter.evidences` query finds the release. A v1 deposit (kind 0 or missing) and every other type have no key.
261
+ */
262
+ declare const getTxBridgeReleaseEvidenceKey: (type: string | undefined, itx?: Record<string, unknown> | null) => string | null;
257
263
  /**
258
264
  * Derive the signer-based sender. Only for rows that never got a getTxSender value (rejected-but-ledgered
259
265
  * txs); normal rows keep getTxSender semantics ("whose asset has net loss", may be empty).
@@ -404,4 +410,4 @@ declare const isDefaultTokenChanged: (tx: TxData, token: {
404
410
  address: string;
405
411
  }) => boolean;
406
412
  //#endregion
407
- export { BridgeReleaseEvidenceInput, DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, getBridgeReleaseEvidenceKey, isDefaultTokenChanged, parseDateTime };
413
+ export { BridgeReleaseEvidenceInput, DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, getBridgeReleaseEvidenceKey, getTxBridgeReleaseEvidenceKey, isDefaultTokenChanged, parseDateTime };
package/esm/util.mjs CHANGED
@@ -180,7 +180,7 @@ const isRejectedIndexRow = (tx) => {
180
180
  return valid === false || valid === 0;
181
181
  };
182
182
  /**
183
- * Evidence lookup key of a release_bridge_token tx: `<bridge>:<kind>:<evidence lowercased>:<ordinal>`
183
+ * Evidence lookup key of a bridge release: `<bridge>:<kind>:<evidence lowercased>:<ordinal>`
184
184
  * (kind and ordinal as decimal strings, bridge as given, trimmed: OCAP addresses are case-sensitive).
185
185
  * Returns null unless bridge is a non-empty string without ':' or whitespace, kind is 1, 2 or 3, ordinal is a
186
186
  * non-negative integer and evidence is a 0x-prefixed 32-byte hex string (after trim + lowercase).
@@ -202,6 +202,40 @@ const getBridgeReleaseEvidenceKey = (itx) => {
202
202
  ].includes(kind) || !Number.isInteger(ordinal) || ordinal < 0) return null;
203
203
  return `${bridge}:${kind}:${evidence}:${ordinal}`;
204
204
  };
205
+ /** Release kinds of the bridge branch of `deposit_token_v2` (DepositTokenV2Tx fields 8-13): DEPOSIT, REFUND, DEPOSIT_B */
206
+ const isBridgeReleaseKind = (kind) => kind === 1 || kind === 2 || kind === 3;
207
+ /**
208
+ * Evidence lookup key of a release (#1693, bridge/docs/deposit-withdraw-v2-unification.md §2.7): a `deposit_token_v2`
209
+ * with kind 1/2/3 (the bridge branch), `{ rollup, kind, evidence: { hash }, ordinal }`, mapped onto the
210
+ * `<bridge>:<kind>:<evidence>:<ordinal>` key, so one `txFilter.evidences` query finds the release. A v1 deposit (kind 0 or missing) and every other type have no key.
211
+ */
212
+ const getTxBridgeReleaseEvidenceKey = (type, itx) => {
213
+ if (!itx) return null;
214
+ if (type === "deposit_token_v2" && isBridgeReleaseKind(itx.kind)) {
215
+ const evidence = itx.evidence;
216
+ return getBridgeReleaseEvidenceKey({
217
+ bridge: itx.rollup,
218
+ kind: itx.kind,
219
+ evidence: typeof evidence?.hash === "string" ? evidence.hash : void 0,
220
+ ordinal: itx.ordinal ?? 0
221
+ });
222
+ }
223
+ return null;
224
+ };
225
+ /**
226
+ * The bridge (v2 RollupState address) a `deposit_token_v2` / `withdraw_token_v2` of the bridge branch ran against, as
227
+ * resolved by the protocol: `ctx.release.bridge` (deposit, the bridge `itx.rollup` names) or `ctx.bridge` (withdraw).
228
+ * The bridge branch sets no `rollupState`, so without this its rows would not be listed by `rollupFilter`. Empty for
229
+ * the v1 branch (`isBridgeV2` unset) and for every other type, so v1 rows index exactly as before.
230
+ */
231
+ const getBridgeBranchRollup = (ctx) => {
232
+ const c = ctx;
233
+ if (!c || c.isBridgeV2 !== true) return "";
234
+ let address;
235
+ if (c.txType === "fg:t:deposit_token_v2") address = c.release?.bridge?.address;
236
+ else if (c.txType === "fg:t:withdraw_token_v2") address = c.bridge?.address;
237
+ return typeof address === "string" ? address : "";
238
+ };
205
239
  /**
206
240
  * Derive the signer-based sender. Only for rows that never got a getTxSender value (rejected-but-ledgered
207
241
  * txs); normal rows keep getTxSender semantics ("whose asset has net loss", may be empty).
@@ -289,6 +323,8 @@ const createIndexedTransaction = async (tx, ctx, indexdb) => {
289
323
  }
290
324
  if (Array.isArray(ctx.stakeStates)) tx.stakes.push(...ctx.stakeStates.map((x) => x.address));
291
325
  if (ctx.rollupState) tx.rollups.push(ctx.rollupState.address);
326
+ const bridgeBranchRollup = getBridgeBranchRollup(ctx);
327
+ if (bridgeBranchRollup) tx.rollups.push(bridgeBranchRollup);
292
328
  if (ctx.tokenFactoryState) tx.tokenFactories.push(ctx.tokenFactoryState.address);
293
329
  const pickedFields = [
294
330
  "address",
@@ -493,9 +529,8 @@ const formatTxBeforeInsert = (row) => {
493
529
  tx.accounts = tx.accounts || [];
494
530
  tx.stakes = tx.stakes || [];
495
531
  tx.evidences = tx.evidences || [];
496
- const isValidRow = tx.valid === true || tx.valid === 1;
497
- if (tx.type === "release_bridge_token" && isValidRow && !isRejectedIndexRow(tx)) {
498
- const evidenceKey = getBridgeReleaseEvidenceKey(itx);
532
+ if ((tx.valid === true || tx.valid === 1) && !isRejectedIndexRow(tx)) {
533
+ const evidenceKey = getTxBridgeReleaseEvidenceKey(tx.type, itx);
499
534
  if (evidenceKey) tx.evidences.push(evidenceKey);
500
535
  }
501
536
  tx.evidences = uniq(tx.evidences).filter(Boolean);
@@ -645,4 +680,4 @@ const isDefaultTokenChanged = (tx, token) => {
645
680
  };
646
681
 
647
682
  //#endregion
648
- export { createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, getBridgeReleaseEvidenceKey, isDefaultTokenChanged, parseDateTime };
683
+ export { createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, getBridgeReleaseEvidenceKey, getTxBridgeReleaseEvidenceKey, isDefaultTokenChanged, parseDateTime };
package/lib/backfill.cjs CHANGED
@@ -2,6 +2,7 @@ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
2
  const require_util = require('./util.cjs');
3
3
  let node_crypto = require("node:crypto");
4
4
  node_crypto = require_rolldown_runtime.__toESM(node_crypto);
5
+ let _ocap_util_lib_deposit_v2_bridge_fields = require("@ocap/util/lib/deposit-v2-bridge-fields");
5
6
  let lodash_uniq = require("lodash/uniq");
6
7
  lodash_uniq = require_rolldown_runtime.__toESM(lodash_uniq);
7
8
 
@@ -109,7 +110,7 @@ function buildTxIndexBackfillPlan(params) {
109
110
  const typeName = type ? `${type.split("_").filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("")}Tx` : "";
110
111
  const from = String(entry.from || parsedTx.from || "");
111
112
  const delegator = String(parsedTx.delegator || "");
112
- const itxJson = parseJsonObject(parsedTx.itxJson || parsedTx.itx);
113
+ const itxJson = (0, _ocap_util_lib_deposit_v2_bridge_fields.stripDefaultDepositV2BridgeFields)(typeName || txType, parseJsonObject(parsedTx.itxJson || parsedTx.itx));
113
114
  if (txType && !itxJson.type_url) itxJson.type_url = txType;
114
115
  if (typeName && !itxJson._type) itxJson._type = typeName;
115
116
  const sender = require_util.deriveTxSender({ tx: {
package/lib/main.cjs CHANGED
@@ -32,6 +32,7 @@ exports.formatTokenMeta = require_util.formatTokenMeta;
32
32
  exports.formatTxAfterRead = require_util.formatTxAfterRead;
33
33
  exports.formatTxBeforeInsert = require_util.formatTxBeforeInsert;
34
34
  exports.getBridgeReleaseEvidenceKey = require_util.getBridgeReleaseEvidenceKey;
35
+ exports.getTxBridgeReleaseEvidenceKey = require_util.getTxBridgeReleaseEvidenceKey;
35
36
  exports.isDefaultTokenChanged = require_util.isDefaultTokenChanged;
36
37
  exports.parseDateTime = require_util.parseDateTime;
37
38
  exports.planTxIndexBackfill = require_backfill.planTxIndexBackfill;
package/lib/main.d.cts CHANGED
@@ -2,6 +2,6 @@ import { ILedgerEntrySnapshot, ISqliteDatabaseLike, ISqliteStatementLike, ITxInd
2
2
  import BaseIndexDB from "./db.cjs";
3
3
  import BaseIndex from "./index.cjs";
4
4
  import { SearchResultFormatOptions, formatSearchResult } from "./search-result.cjs";
5
- import { BridgeReleaseEvidenceInput, DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, getBridgeReleaseEvidenceKey, isDefaultTokenChanged, parseDateTime } from "./util.cjs";
5
+ import { BridgeReleaseEvidenceInput, DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, getBridgeReleaseEvidenceKey, getTxBridgeReleaseEvidenceKey, isDefaultTokenChanged, parseDateTime } from "./util.cjs";
6
6
  import { clearIndexDB, rebuildIndexFromState, scanStateTable } from "./rebuild.cjs";
7
- export { BaseIndex, BaseIndexDB, BridgeReleaseEvidenceInput, DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, ILedgerEntrySnapshot, ISqliteDatabaseLike, ISqliteStatementLike, ITxIndexBackfillInsert, ITxIndexBackfillPlan, ITxIndexBackfillUpdate, ITxIndexRowSnapshot, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, type SearchResultFormatOptions, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, applyTxIndexBackfill, buildTxIndexBackfillPlan, clearIndexDB, computeBackfillPlanDigest, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatSearchResult, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, getBridgeReleaseEvidenceKey, isDefaultTokenChanged, parseDateTime, planTxIndexBackfill, rebuildIndexFromState, scanStateTable };
7
+ export { BaseIndex, BaseIndexDB, BridgeReleaseEvidenceInput, DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, ILedgerEntrySnapshot, ISqliteDatabaseLike, ISqliteStatementLike, ITxIndexBackfillInsert, ITxIndexBackfillPlan, ITxIndexBackfillUpdate, ITxIndexRowSnapshot, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, type SearchResultFormatOptions, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, applyTxIndexBackfill, buildTxIndexBackfillPlan, clearIndexDB, computeBackfillPlanDigest, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatSearchResult, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, getBridgeReleaseEvidenceKey, getTxBridgeReleaseEvidenceKey, isDefaultTokenChanged, parseDateTime, planTxIndexBackfill, rebuildIndexFromState, scanStateTable };
package/lib/util.cjs CHANGED
@@ -185,7 +185,7 @@ const isRejectedIndexRow = (tx) => {
185
185
  return valid === false || valid === 0;
186
186
  };
187
187
  /**
188
- * Evidence lookup key of a release_bridge_token tx: `<bridge>:<kind>:<evidence lowercased>:<ordinal>`
188
+ * Evidence lookup key of a bridge release: `<bridge>:<kind>:<evidence lowercased>:<ordinal>`
189
189
  * (kind and ordinal as decimal strings, bridge as given, trimmed: OCAP addresses are case-sensitive).
190
190
  * Returns null unless bridge is a non-empty string without ':' or whitespace, kind is 1, 2 or 3, ordinal is a
191
191
  * non-negative integer and evidence is a 0x-prefixed 32-byte hex string (after trim + lowercase).
@@ -207,6 +207,40 @@ const getBridgeReleaseEvidenceKey = (itx) => {
207
207
  ].includes(kind) || !Number.isInteger(ordinal) || ordinal < 0) return null;
208
208
  return `${bridge}:${kind}:${evidence}:${ordinal}`;
209
209
  };
210
+ /** Release kinds of the bridge branch of `deposit_token_v2` (DepositTokenV2Tx fields 8-13): DEPOSIT, REFUND, DEPOSIT_B */
211
+ const isBridgeReleaseKind = (kind) => kind === 1 || kind === 2 || kind === 3;
212
+ /**
213
+ * Evidence lookup key of a release (#1693, bridge/docs/deposit-withdraw-v2-unification.md §2.7): a `deposit_token_v2`
214
+ * with kind 1/2/3 (the bridge branch), `{ rollup, kind, evidence: { hash }, ordinal }`, mapped onto the
215
+ * `<bridge>:<kind>:<evidence>:<ordinal>` key, so one `txFilter.evidences` query finds the release. A v1 deposit (kind 0 or missing) and every other type have no key.
216
+ */
217
+ const getTxBridgeReleaseEvidenceKey = (type, itx) => {
218
+ if (!itx) return null;
219
+ if (type === "deposit_token_v2" && isBridgeReleaseKind(itx.kind)) {
220
+ const evidence = itx.evidence;
221
+ return getBridgeReleaseEvidenceKey({
222
+ bridge: itx.rollup,
223
+ kind: itx.kind,
224
+ evidence: typeof evidence?.hash === "string" ? evidence.hash : void 0,
225
+ ordinal: itx.ordinal ?? 0
226
+ });
227
+ }
228
+ return null;
229
+ };
230
+ /**
231
+ * The bridge (v2 RollupState address) a `deposit_token_v2` / `withdraw_token_v2` of the bridge branch ran against, as
232
+ * resolved by the protocol: `ctx.release.bridge` (deposit, the bridge `itx.rollup` names) or `ctx.bridge` (withdraw).
233
+ * The bridge branch sets no `rollupState`, so without this its rows would not be listed by `rollupFilter`. Empty for
234
+ * the v1 branch (`isBridgeV2` unset) and for every other type, so v1 rows index exactly as before.
235
+ */
236
+ const getBridgeBranchRollup = (ctx) => {
237
+ const c = ctx;
238
+ if (!c || c.isBridgeV2 !== true) return "";
239
+ let address;
240
+ if (c.txType === "fg:t:deposit_token_v2") address = c.release?.bridge?.address;
241
+ else if (c.txType === "fg:t:withdraw_token_v2") address = c.bridge?.address;
242
+ return typeof address === "string" ? address : "";
243
+ };
210
244
  /**
211
245
  * Derive the signer-based sender. Only for rows that never got a getTxSender value (rejected-but-ledgered
212
246
  * txs); normal rows keep getTxSender semantics ("whose asset has net loss", may be empty).
@@ -294,6 +328,8 @@ const createIndexedTransaction = async (tx, ctx, indexdb) => {
294
328
  }
295
329
  if (Array.isArray(ctx.stakeStates)) tx.stakes.push(...ctx.stakeStates.map((x) => x.address));
296
330
  if (ctx.rollupState) tx.rollups.push(ctx.rollupState.address);
331
+ const bridgeBranchRollup = getBridgeBranchRollup(ctx);
332
+ if (bridgeBranchRollup) tx.rollups.push(bridgeBranchRollup);
297
333
  if (ctx.tokenFactoryState) tx.tokenFactories.push(ctx.tokenFactoryState.address);
298
334
  const pickedFields = [
299
335
  "address",
@@ -498,9 +534,8 @@ const formatTxBeforeInsert = (row) => {
498
534
  tx.accounts = tx.accounts || [];
499
535
  tx.stakes = tx.stakes || [];
500
536
  tx.evidences = tx.evidences || [];
501
- const isValidRow = tx.valid === true || tx.valid === 1;
502
- if (tx.type === "release_bridge_token" && isValidRow && !isRejectedIndexRow(tx)) {
503
- const evidenceKey = getBridgeReleaseEvidenceKey(itx);
537
+ if ((tx.valid === true || tx.valid === 1) && !isRejectedIndexRow(tx)) {
538
+ const evidenceKey = getTxBridgeReleaseEvidenceKey(tx.type, itx);
504
539
  if (evidenceKey) tx.evidences.push(evidenceKey);
505
540
  }
506
541
  tx.evidences = (0, lodash_uniq.default)(tx.evidences).filter(Boolean);
@@ -670,5 +705,6 @@ exports.formatTokenMeta = formatTokenMeta;
670
705
  exports.formatTxAfterRead = formatTxAfterRead;
671
706
  exports.formatTxBeforeInsert = formatTxBeforeInsert;
672
707
  exports.getBridgeReleaseEvidenceKey = getBridgeReleaseEvidenceKey;
708
+ exports.getTxBridgeReleaseEvidenceKey = getTxBridgeReleaseEvidenceKey;
673
709
  exports.isDefaultTokenChanged = isDefaultTokenChanged;
674
710
  exports.parseDateTime = parseDateTime;
package/lib/util.d.cts CHANGED
@@ -236,7 +236,7 @@ declare const createIndexedFactory: (factory: IAssetFactoryState & {
236
236
  }, context: FactoryContext) => Record<string, unknown> & {
237
237
  tokens: TokenWithBalance[];
238
238
  };
239
- /** Fields of a release_bridge_token itx that identify the deposit or withdraw being settled */
239
+ /** Fields of a bridge release that identify the deposit or withdraw being settled */
240
240
  interface BridgeReleaseEvidenceInput {
241
241
  /** OCAP bridge (RollupState address) the release belongs to (bridge/docs/ocap-protocols.md §v2.4) */
242
242
  bridge?: string;
@@ -245,7 +245,7 @@ interface BridgeReleaseEvidenceInput {
245
245
  ordinal?: number | string;
246
246
  }
247
247
  /**
248
- * Evidence lookup key of a release_bridge_token tx: `<bridge>:<kind>:<evidence lowercased>:<ordinal>`
248
+ * Evidence lookup key of a bridge release: `<bridge>:<kind>:<evidence lowercased>:<ordinal>`
249
249
  * (kind and ordinal as decimal strings, bridge as given, trimmed: OCAP addresses are case-sensitive).
250
250
  * Returns null unless bridge is a non-empty string without ':' or whitespace, kind is 1, 2 or 3, ordinal is a
251
251
  * non-negative integer and evidence is a 0x-prefixed 32-byte hex string (after trim + lowercase).
@@ -254,6 +254,12 @@ interface BridgeReleaseEvidenceInput {
254
254
  * Pass the same key in `txFilter.evidences` of listTransactions to find the release tx.
255
255
  */
256
256
  declare const getBridgeReleaseEvidenceKey: (itx?: BridgeReleaseEvidenceInput | null) => string | null;
257
+ /**
258
+ * Evidence lookup key of a release (#1693, bridge/docs/deposit-withdraw-v2-unification.md §2.7): a `deposit_token_v2`
259
+ * with kind 1/2/3 (the bridge branch), `{ rollup, kind, evidence: { hash }, ordinal }`, mapped onto the
260
+ * `<bridge>:<kind>:<evidence>:<ordinal>` key, so one `txFilter.evidences` query finds the release. A v1 deposit (kind 0 or missing) and every other type have no key.
261
+ */
262
+ declare const getTxBridgeReleaseEvidenceKey: (type: string | undefined, itx?: Record<string, unknown> | null) => string | null;
257
263
  /**
258
264
  * Derive the signer-based sender. Only for rows that never got a getTxSender value (rejected-but-ledgered
259
265
  * txs); normal rows keep getTxSender semantics ("whose asset has net loss", may be empty).
@@ -404,4 +410,4 @@ declare const isDefaultTokenChanged: (tx: TxData, token: {
404
410
  address: string;
405
411
  }) => boolean;
406
412
  //#endregion
407
- export { BridgeReleaseEvidenceInput, DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, getBridgeReleaseEvidenceKey, isDefaultTokenChanged, parseDateTime };
413
+ export { BridgeReleaseEvidenceInput, DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, getBridgeReleaseEvidenceKey, getTxBridgeReleaseEvidenceKey, isDefaultTokenChanged, parseDateTime };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.31.4",
6
+ "version": "1.31.6",
7
7
  "type": "module",
8
8
  "description": "Defines the basic interface for OCAP IndexDB",
9
9
  "main": "./lib/main.cjs",
@@ -52,9 +52,9 @@
52
52
  "tsdown": "^0.18.4"
53
53
  },
54
54
  "dependencies": {
55
- "@ocap/state": "1.31.4",
56
- "@ocap/types": "1.31.4",
57
- "@ocap/util": "1.31.4",
55
+ "@ocap/state": "1.31.6",
56
+ "@ocap/types": "1.31.6",
57
+ "@ocap/util": "1.31.6",
58
58
  "kareem": "^2.4.1",
59
59
  "lodash": "^4.17.23"
60
60
  }