@ocap/indexdb 1.31.1 → 1.31.2
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/main.d.mts +2 -2
- package/esm/main.mjs +2 -2
- package/esm/util.d.mts +20 -1
- package/esm/util.mjs +32 -1
- package/lib/main.cjs +1 -0
- package/lib/main.d.cts +2 -2
- package/lib/util.cjs +32 -0
- package/lib/util.d.cts +20 -1
- package/package.json +4 -4
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 { 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, 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, isDefaultTokenChanged, parseDateTime } from "./util.mjs";
|
|
6
6
|
import { clearIndexDB, rebuildIndexFromState, scanStateTable } from "./rebuild.mjs";
|
|
7
|
-
export { BaseIndex, BaseIndexDB, 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, 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, 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, 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, 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, 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, isDefaultTokenChanged, parseDateTime, planTxIndexBackfill, rebuildIndexFromState, scanStateTable };
|
package/esm/util.d.mts
CHANGED
|
@@ -121,6 +121,7 @@ interface TxData {
|
|
|
121
121
|
rollups?: string[];
|
|
122
122
|
delegations?: string[];
|
|
123
123
|
tokenFactories?: string[];
|
|
124
|
+
evidences?: string[];
|
|
124
125
|
tokenSymbols?: Array<Partial<TTokenMeta>>;
|
|
125
126
|
[key: string]: unknown;
|
|
126
127
|
}
|
|
@@ -235,6 +236,24 @@ declare const createIndexedFactory: (factory: IAssetFactoryState & {
|
|
|
235
236
|
}, context: FactoryContext) => Record<string, unknown> & {
|
|
236
237
|
tokens: TokenWithBalance[];
|
|
237
238
|
};
|
|
239
|
+
/** Fields of a release_bridge_token itx that identify the deposit or withdraw being settled */
|
|
240
|
+
interface BridgeReleaseEvidenceInput {
|
|
241
|
+
/** OCAP bridge (RollupState address) the release belongs to (bridge/docs/ocap-protocols.md §v2.4) */
|
|
242
|
+
bridge?: string;
|
|
243
|
+
kind?: number | string;
|
|
244
|
+
evidence?: string;
|
|
245
|
+
ordinal?: number | string;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Evidence lookup key of a release_bridge_token tx: `<bridge>:<kind>:<evidence lowercased>:<ordinal>`
|
|
249
|
+
* (kind and ordinal as decimal strings, bridge as given, trimmed: OCAP addresses are case-sensitive).
|
|
250
|
+
* Returns null unless bridge is a non-empty string without ':' or whitespace, kind is 1, 2 or 3, ordinal is a
|
|
251
|
+
* non-negative integer and evidence is a 0x-prefixed 32-byte hex string (after trim + lowercase).
|
|
252
|
+
* The key was `<kind>:<evidence>:<ordinal>` in the single-reserve model (#1479). The index is new and unused in
|
|
253
|
+
* production, so rows written with the old key are simply not found under the new one (no migration).
|
|
254
|
+
* Pass the same key in `txFilter.evidences` of listTransactions to find the release tx.
|
|
255
|
+
*/
|
|
256
|
+
declare const getBridgeReleaseEvidenceKey: (itx?: BridgeReleaseEvidenceInput | null) => string | null;
|
|
238
257
|
/**
|
|
239
258
|
* Derive the signer-based sender. Only for rows that never got a getTxSender value (rejected-but-ledgered
|
|
240
259
|
* txs); normal rows keep getTxSender semantics ("whose asset has net loss", may be empty).
|
|
@@ -385,4 +404,4 @@ declare const isDefaultTokenChanged: (tx: TxData, token: {
|
|
|
385
404
|
address: string;
|
|
386
405
|
}) => boolean;
|
|
387
406
|
//#endregion
|
|
388
|
-
export { 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, isDefaultTokenChanged, parseDateTime };
|
|
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 };
|
package/esm/util.mjs
CHANGED
|
@@ -180,6 +180,29 @@ 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>`
|
|
184
|
+
* (kind and ordinal as decimal strings, bridge as given, trimmed: OCAP addresses are case-sensitive).
|
|
185
|
+
* Returns null unless bridge is a non-empty string without ':' or whitespace, kind is 1, 2 or 3, ordinal is a
|
|
186
|
+
* non-negative integer and evidence is a 0x-prefixed 32-byte hex string (after trim + lowercase).
|
|
187
|
+
* The key was `<kind>:<evidence>:<ordinal>` in the single-reserve model (#1479). The index is new and unused in
|
|
188
|
+
* production, so rows written with the old key are simply not found under the new one (no migration).
|
|
189
|
+
* Pass the same key in `txFilter.evidences` of listTransactions to find the release tx.
|
|
190
|
+
*/
|
|
191
|
+
const getBridgeReleaseEvidenceKey = (itx) => {
|
|
192
|
+
const bridge = typeof itx?.bridge === "string" ? itx.bridge.trim() : "";
|
|
193
|
+
if (!bridge || /[:\s]/.test(bridge)) return null;
|
|
194
|
+
const evidence = typeof itx?.evidence === "string" ? itx.evidence.trim().toLowerCase() : "";
|
|
195
|
+
if (!/^0x[0-9a-f]{64}$/.test(evidence)) return null;
|
|
196
|
+
const kind = Number(itx?.kind);
|
|
197
|
+
const ordinal = Number(itx?.ordinal ?? 0);
|
|
198
|
+
if (![
|
|
199
|
+
1,
|
|
200
|
+
2,
|
|
201
|
+
3
|
|
202
|
+
].includes(kind) || !Number.isInteger(ordinal) || ordinal < 0) return null;
|
|
203
|
+
return `${bridge}:${kind}:${evidence}:${ordinal}`;
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
183
206
|
* Derive the signer-based sender. Only for rows that never got a getTxSender value (rejected-but-ledgered
|
|
184
207
|
* txs); normal rows keep getTxSender semantics ("whose asset has net loss", may be empty).
|
|
185
208
|
*/
|
|
@@ -469,6 +492,13 @@ const formatTxBeforeInsert = (row) => {
|
|
|
469
492
|
else if (tx.type === "exchange_v2") tx.tokens.push(...(itx.sender?.tokens || []).map((x) => x.address), ...(itx.receiver?.tokens || []).map((x) => x.address));
|
|
470
493
|
tx.accounts = tx.accounts || [];
|
|
471
494
|
tx.stakes = tx.stakes || [];
|
|
495
|
+
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);
|
|
499
|
+
if (evidenceKey) tx.evidences.push(evidenceKey);
|
|
500
|
+
}
|
|
501
|
+
tx.evidences = uniq(tx.evidences).filter(Boolean);
|
|
472
502
|
tx.assets = uniq(tx.assets).filter(Boolean);
|
|
473
503
|
tx.factories = uniq(tx.factories).filter(Boolean);
|
|
474
504
|
tx.tokens = uniq(tx.tokens).filter(Boolean);
|
|
@@ -489,6 +519,7 @@ const formatTxAfterRead = (tx) => {
|
|
|
489
519
|
delete tx.stakes;
|
|
490
520
|
delete tx.rollups;
|
|
491
521
|
delete tx.delegations;
|
|
522
|
+
delete tx.evidences;
|
|
492
523
|
return tx;
|
|
493
524
|
};
|
|
494
525
|
/**
|
|
@@ -614,4 +645,4 @@ const isDefaultTokenChanged = (tx, token) => {
|
|
|
614
645
|
};
|
|
615
646
|
|
|
616
647
|
//#endregion
|
|
617
|
-
export { createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, isDefaultTokenChanged, parseDateTime };
|
|
648
|
+
export { createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, deriveTxGasPayer, deriveTxSender, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, getBridgeReleaseEvidenceKey, isDefaultTokenChanged, parseDateTime };
|
package/lib/main.cjs
CHANGED
|
@@ -31,6 +31,7 @@ exports.formatSearchResult = require_search_result.formatSearchResult;
|
|
|
31
31
|
exports.formatTokenMeta = require_util.formatTokenMeta;
|
|
32
32
|
exports.formatTxAfterRead = require_util.formatTxAfterRead;
|
|
33
33
|
exports.formatTxBeforeInsert = require_util.formatTxBeforeInsert;
|
|
34
|
+
exports.getBridgeReleaseEvidenceKey = require_util.getBridgeReleaseEvidenceKey;
|
|
34
35
|
exports.isDefaultTokenChanged = require_util.isDefaultTokenChanged;
|
|
35
36
|
exports.parseDateTime = require_util.parseDateTime;
|
|
36
37
|
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 { 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, 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, isDefaultTokenChanged, parseDateTime } from "./util.cjs";
|
|
6
6
|
import { clearIndexDB, rebuildIndexFromState, scanStateTable } from "./rebuild.cjs";
|
|
7
|
-
export { BaseIndex, BaseIndexDB, 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, 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, isDefaultTokenChanged, parseDateTime, planTxIndexBackfill, rebuildIndexFromState, scanStateTable };
|
package/lib/util.cjs
CHANGED
|
@@ -185,6 +185,29 @@ 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>`
|
|
189
|
+
* (kind and ordinal as decimal strings, bridge as given, trimmed: OCAP addresses are case-sensitive).
|
|
190
|
+
* Returns null unless bridge is a non-empty string without ':' or whitespace, kind is 1, 2 or 3, ordinal is a
|
|
191
|
+
* non-negative integer and evidence is a 0x-prefixed 32-byte hex string (after trim + lowercase).
|
|
192
|
+
* The key was `<kind>:<evidence>:<ordinal>` in the single-reserve model (#1479). The index is new and unused in
|
|
193
|
+
* production, so rows written with the old key are simply not found under the new one (no migration).
|
|
194
|
+
* Pass the same key in `txFilter.evidences` of listTransactions to find the release tx.
|
|
195
|
+
*/
|
|
196
|
+
const getBridgeReleaseEvidenceKey = (itx) => {
|
|
197
|
+
const bridge = typeof itx?.bridge === "string" ? itx.bridge.trim() : "";
|
|
198
|
+
if (!bridge || /[:\s]/.test(bridge)) return null;
|
|
199
|
+
const evidence = typeof itx?.evidence === "string" ? itx.evidence.trim().toLowerCase() : "";
|
|
200
|
+
if (!/^0x[0-9a-f]{64}$/.test(evidence)) return null;
|
|
201
|
+
const kind = Number(itx?.kind);
|
|
202
|
+
const ordinal = Number(itx?.ordinal ?? 0);
|
|
203
|
+
if (![
|
|
204
|
+
1,
|
|
205
|
+
2,
|
|
206
|
+
3
|
|
207
|
+
].includes(kind) || !Number.isInteger(ordinal) || ordinal < 0) return null;
|
|
208
|
+
return `${bridge}:${kind}:${evidence}:${ordinal}`;
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
188
211
|
* Derive the signer-based sender. Only for rows that never got a getTxSender value (rejected-but-ledgered
|
|
189
212
|
* txs); normal rows keep getTxSender semantics ("whose asset has net loss", may be empty).
|
|
190
213
|
*/
|
|
@@ -474,6 +497,13 @@ const formatTxBeforeInsert = (row) => {
|
|
|
474
497
|
else if (tx.type === "exchange_v2") tx.tokens.push(...(itx.sender?.tokens || []).map((x) => x.address), ...(itx.receiver?.tokens || []).map((x) => x.address));
|
|
475
498
|
tx.accounts = tx.accounts || [];
|
|
476
499
|
tx.stakes = tx.stakes || [];
|
|
500
|
+
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);
|
|
504
|
+
if (evidenceKey) tx.evidences.push(evidenceKey);
|
|
505
|
+
}
|
|
506
|
+
tx.evidences = (0, lodash_uniq.default)(tx.evidences).filter(Boolean);
|
|
477
507
|
tx.assets = (0, lodash_uniq.default)(tx.assets).filter(Boolean);
|
|
478
508
|
tx.factories = (0, lodash_uniq.default)(tx.factories).filter(Boolean);
|
|
479
509
|
tx.tokens = (0, lodash_uniq.default)(tx.tokens).filter(Boolean);
|
|
@@ -494,6 +524,7 @@ const formatTxAfterRead = (tx) => {
|
|
|
494
524
|
delete tx.stakes;
|
|
495
525
|
delete tx.rollups;
|
|
496
526
|
delete tx.delegations;
|
|
527
|
+
delete tx.evidences;
|
|
497
528
|
return tx;
|
|
498
529
|
};
|
|
499
530
|
/**
|
|
@@ -638,5 +669,6 @@ exports.formatPagination = formatPagination;
|
|
|
638
669
|
exports.formatTokenMeta = formatTokenMeta;
|
|
639
670
|
exports.formatTxAfterRead = formatTxAfterRead;
|
|
640
671
|
exports.formatTxBeforeInsert = formatTxBeforeInsert;
|
|
672
|
+
exports.getBridgeReleaseEvidenceKey = getBridgeReleaseEvidenceKey;
|
|
641
673
|
exports.isDefaultTokenChanged = isDefaultTokenChanged;
|
|
642
674
|
exports.parseDateTime = parseDateTime;
|
package/lib/util.d.cts
CHANGED
|
@@ -121,6 +121,7 @@ interface TxData {
|
|
|
121
121
|
rollups?: string[];
|
|
122
122
|
delegations?: string[];
|
|
123
123
|
tokenFactories?: string[];
|
|
124
|
+
evidences?: string[];
|
|
124
125
|
tokenSymbols?: Array<Partial<TTokenMeta>>;
|
|
125
126
|
[key: string]: unknown;
|
|
126
127
|
}
|
|
@@ -235,6 +236,24 @@ declare const createIndexedFactory: (factory: IAssetFactoryState & {
|
|
|
235
236
|
}, context: FactoryContext) => Record<string, unknown> & {
|
|
236
237
|
tokens: TokenWithBalance[];
|
|
237
238
|
};
|
|
239
|
+
/** Fields of a release_bridge_token itx that identify the deposit or withdraw being settled */
|
|
240
|
+
interface BridgeReleaseEvidenceInput {
|
|
241
|
+
/** OCAP bridge (RollupState address) the release belongs to (bridge/docs/ocap-protocols.md §v2.4) */
|
|
242
|
+
bridge?: string;
|
|
243
|
+
kind?: number | string;
|
|
244
|
+
evidence?: string;
|
|
245
|
+
ordinal?: number | string;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Evidence lookup key of a release_bridge_token tx: `<bridge>:<kind>:<evidence lowercased>:<ordinal>`
|
|
249
|
+
* (kind and ordinal as decimal strings, bridge as given, trimmed: OCAP addresses are case-sensitive).
|
|
250
|
+
* Returns null unless bridge is a non-empty string without ':' or whitespace, kind is 1, 2 or 3, ordinal is a
|
|
251
|
+
* non-negative integer and evidence is a 0x-prefixed 32-byte hex string (after trim + lowercase).
|
|
252
|
+
* The key was `<kind>:<evidence>:<ordinal>` in the single-reserve model (#1479). The index is new and unused in
|
|
253
|
+
* production, so rows written with the old key are simply not found under the new one (no migration).
|
|
254
|
+
* Pass the same key in `txFilter.evidences` of listTransactions to find the release tx.
|
|
255
|
+
*/
|
|
256
|
+
declare const getBridgeReleaseEvidenceKey: (itx?: BridgeReleaseEvidenceInput | null) => string | null;
|
|
238
257
|
/**
|
|
239
258
|
* Derive the signer-based sender. Only for rows that never got a getTxSender value (rejected-but-ledgered
|
|
240
259
|
* txs); normal rows keep getTxSender semantics ("whose asset has net loss", may be empty).
|
|
@@ -385,4 +404,4 @@ declare const isDefaultTokenChanged: (tx: TxData, token: {
|
|
|
385
404
|
address: string;
|
|
386
405
|
}) => boolean;
|
|
387
406
|
//#endregion
|
|
388
|
-
export { 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, isDefaultTokenChanged, parseDateTime };
|
|
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 };
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.31.
|
|
6
|
+
"version": "1.31.2",
|
|
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.
|
|
56
|
-
"@ocap/types": "1.31.
|
|
57
|
-
"@ocap/util": "1.31.
|
|
55
|
+
"@ocap/state": "1.31.2",
|
|
56
|
+
"@ocap/types": "1.31.2",
|
|
57
|
+
"@ocap/util": "1.31.2",
|
|
58
58
|
"kareem": "^2.4.1",
|
|
59
59
|
"lodash": "^4.17.23"
|
|
60
60
|
}
|