@bsv/wallet-toolbox 2.1.25 → 3.0.0-alpha.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/docs/CREATEACTION_BLOCKERS.md +391 -0
- package/docs/CUTOVER_RUNBOOK.md +95 -0
- package/docs/REQUIREMENTS_COMPLIANCE.md +157 -0
- package/docs/ROLLOUT_PLAN.md +273 -0
- package/docs/SESSION_HANDOFF.md +298 -0
- package/docs/STORAGE_METHOD_WIRING.md +176 -0
- package/docs/client.md +3765 -1325
- package/docs/monitor.md +255 -33
- package/docs/services.md +304 -280
- package/docs/setup.md +24 -24
- package/docs/storage.md +2783 -251
- package/docs/v3-upgrade/index.html +911 -0
- package/docs/wallet.md +4956 -9455
- package/out/src/Wallet.d.ts.map +1 -1
- package/out/src/Wallet.js.map +1 -1
- package/out/src/WalletLogger.d.ts.map +1 -1
- package/out/src/WalletLogger.js.map +1 -1
- package/out/src/__tests/CWIStyleWalletManager.test.js.map +1 -1
- package/out/src/__tests/WalletPermissionsManager.fixtures.d.ts.map +1 -1
- package/out/src/__tests/WalletPermissionsManager.fixtures.js.map +1 -1
- package/out/src/entropy/EntropyCollector.d.ts.map +1 -1
- package/out/src/entropy/EntropyCollector.js.map +1 -1
- package/out/src/monitor/LeasedMonitorTask.d.ts +43 -0
- package/out/src/monitor/LeasedMonitorTask.d.ts.map +1 -0
- package/out/src/monitor/LeasedMonitorTask.js +89 -0
- package/out/src/monitor/LeasedMonitorTask.js.map +1 -0
- package/out/src/monitor/Monitor.d.ts +7 -0
- package/out/src/monitor/Monitor.d.ts.map +1 -1
- package/out/src/monitor/Monitor.js +7 -0
- package/out/src/monitor/Monitor.js.map +1 -1
- package/out/src/monitor/MonitorDaemon.d.ts.map +1 -1
- package/out/src/monitor/MonitorDaemon.js.map +1 -1
- package/out/src/monitor/V7LeasedTask.d.ts +43 -0
- package/out/src/monitor/V7LeasedTask.d.ts.map +1 -0
- package/out/src/monitor/V7LeasedTask.js +89 -0
- package/out/src/monitor/V7LeasedTask.js.map +1 -0
- package/out/src/monitor/index.all.d.ts +1 -0
- package/out/src/monitor/index.all.d.ts.map +1 -1
- package/out/src/monitor/index.all.js +1 -0
- package/out/src/monitor/index.all.js.map +1 -1
- package/out/src/monitor/tasks/TaskCheckForProofs.d.ts +2 -0
- package/out/src/monitor/tasks/TaskCheckForProofs.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskCheckForProofs.js +55 -0
- package/out/src/monitor/tasks/TaskCheckForProofs.js.map +1 -1
- package/out/src/monitor/tasks/TaskSendWaiting.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskSendWaiting.js.map +1 -1
- package/out/src/sdk/WalletStorage.interfaces.d.ts +59 -59
- package/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -1
- package/out/src/sdk/types.d.ts +32 -0
- package/out/src/sdk/types.d.ts.map +1 -1
- package/out/src/sdk/types.js +50 -1
- package/out/src/sdk/types.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageBase.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageBase.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/createDefaultIdbChaintracksOptions.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/createDefaultIdbChaintracksOptions.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/createDefaultKnexChaintracksOptions.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/createDefaultKnexChaintracksOptions.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/createDefaultNoDbChaintracksOptions.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/createDefaultNoDbChaintracksOptions.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/createIdbChaintracks.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/createIdbChaintracks.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/createKnexChaintracks.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/createKnexChaintracks.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/createNoDbChaintracks.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/createNoDbChaintracks.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/util/BulkFilesReader.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/util/BulkFilesReader.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/util/ChaintracksFs.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/util/ChaintracksFs.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/util/SingleWriterMultiReaderLock.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/util/SingleWriterMultiReaderLock.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/util/__tests/SingleWriterMultiReaderLock.test.js.map +1 -1
- package/out/src/storage/StorageIdb.d.ts.map +1 -1
- package/out/src/storage/StorageIdb.js +10 -5
- package/out/src/storage/StorageIdb.js.map +1 -1
- package/out/src/storage/StorageKnex.d.ts +133 -3
- package/out/src/storage/StorageKnex.d.ts.map +1 -1
- package/out/src/storage/StorageKnex.js +691 -94
- package/out/src/storage/StorageKnex.js.map +1 -1
- package/out/src/storage/StorageProvider.d.ts +114 -1
- package/out/src/storage/StorageProvider.d.ts.map +1 -1
- package/out/src/storage/StorageProvider.js +164 -4
- package/out/src/storage/StorageProvider.js.map +1 -1
- package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
- package/out/src/storage/WalletStorageManager.js.map +1 -1
- package/out/src/storage/idbHelpers.d.ts +5 -0
- package/out/src/storage/idbHelpers.d.ts.map +1 -1
- package/out/src/storage/idbHelpers.js +42 -0
- package/out/src/storage/idbHelpers.js.map +1 -1
- package/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts.map +1 -1
- package/out/src/storage/methods/attemptToPostReqsToNetwork.js +116 -4
- package/out/src/storage/methods/attemptToPostReqsToNetwork.js.map +1 -1
- package/out/src/storage/methods/createAction.d.ts.map +1 -1
- package/out/src/storage/methods/createAction.js +22 -5
- package/out/src/storage/methods/createAction.js.map +1 -1
- package/out/src/storage/methods/internalizeAction.d.ts.map +1 -1
- package/out/src/storage/methods/internalizeAction.js +172 -5
- package/out/src/storage/methods/internalizeAction.js.map +1 -1
- package/out/src/storage/methods/listActionsKnex.d.ts +49 -0
- package/out/src/storage/methods/listActionsKnex.d.ts.map +1 -1
- package/out/src/storage/methods/listActionsKnex.js +179 -69
- package/out/src/storage/methods/listActionsKnex.js.map +1 -1
- package/out/src/storage/methods/listOutputsKnex.d.ts.map +1 -1
- package/out/src/storage/methods/listOutputsKnex.js +51 -4
- package/out/src/storage/methods/listOutputsKnex.js.map +1 -1
- package/out/src/storage/methods/processAction.d.ts.map +1 -1
- package/out/src/storage/methods/processAction.js +82 -14
- package/out/src/storage/methods/processAction.js.map +1 -1
- package/out/src/storage/methods/purgeData.d.ts.map +1 -1
- package/out/src/storage/methods/purgeData.js +22 -14
- package/out/src/storage/methods/purgeData.js.map +1 -1
- package/out/src/storage/methods/reviewStatus.d.ts.map +1 -1
- package/out/src/storage/methods/reviewStatus.js +18 -9
- package/out/src/storage/methods/reviewStatus.js.map +1 -1
- package/out/src/storage/schema/KnexMigrations.d.ts.map +1 -1
- package/out/src/storage/schema/KnexMigrations.js +134 -0
- package/out/src/storage/schema/KnexMigrations.js.map +1 -1
- package/out/src/storage/schema/StorageIdbSchema.d.ts +43 -2
- package/out/src/storage/schema/StorageIdbSchema.d.ts.map +1 -1
- package/out/src/storage/schema/__tests/backfill.runner.test.d.ts +2 -0
- package/out/src/storage/schema/__tests/backfill.runner.test.d.ts.map +1 -0
- package/out/src/storage/schema/__tests/backfill.runner.test.js +148 -0
- package/out/src/storage/schema/__tests/backfill.runner.test.js.map +1 -0
- package/out/src/storage/schema/__tests/backfill.test.d.ts +2 -0
- package/out/src/storage/schema/__tests/backfill.test.d.ts.map +1 -0
- package/out/src/storage/schema/__tests/backfill.test.js +96 -0
- package/out/src/storage/schema/__tests/backfill.test.js.map +1 -0
- package/out/src/storage/schema/__tests/processingFsm.test.d.ts +2 -0
- package/out/src/storage/schema/__tests/processingFsm.test.d.ts.map +1 -0
- package/out/src/storage/schema/__tests/processingFsm.test.js +42 -0
- package/out/src/storage/schema/__tests/processingFsm.test.js.map +1 -0
- package/out/src/storage/schema/__tests/processingFsmLegacyMapping.test.d.ts +2 -0
- package/out/src/storage/schema/__tests/processingFsmLegacyMapping.test.d.ts.map +1 -0
- package/out/src/storage/schema/__tests/processingFsmLegacyMapping.test.js +82 -0
- package/out/src/storage/schema/__tests/processingFsmLegacyMapping.test.js.map +1 -0
- package/out/src/storage/schema/__tests/spendabilityRule.test.d.ts +2 -0
- package/out/src/storage/schema/__tests/spendabilityRule.test.d.ts.map +1 -0
- package/out/src/storage/schema/__tests/spendabilityRule.test.js +29 -0
- package/out/src/storage/schema/__tests/spendabilityRule.test.js.map +1 -0
- package/out/src/storage/schema/__tests/v7FsmLegacyMapping.test.d.ts +2 -0
- package/out/src/storage/schema/__tests/v7FsmLegacyMapping.test.d.ts.map +1 -0
- package/out/src/storage/schema/__tests/v7FsmLegacyMapping.test.js +77 -0
- package/out/src/storage/schema/__tests/v7FsmLegacyMapping.test.js.map +1 -0
- package/out/src/storage/schema/backfill.d.ts +35 -0
- package/out/src/storage/schema/backfill.d.ts.map +1 -0
- package/out/src/storage/schema/backfill.idb.d.ts +32 -0
- package/out/src/storage/schema/backfill.idb.d.ts.map +1 -0
- package/out/src/storage/schema/backfill.idb.js +95 -0
- package/out/src/storage/schema/backfill.idb.js.map +1 -0
- package/out/src/storage/schema/backfill.js +150 -0
- package/out/src/storage/schema/backfill.js.map +1 -0
- package/out/src/storage/schema/backfill.knex.d.ts +32 -0
- package/out/src/storage/schema/backfill.knex.d.ts.map +1 -0
- package/out/src/storage/schema/backfill.knex.js +240 -0
- package/out/src/storage/schema/backfill.knex.js.map +1 -0
- package/out/src/storage/schema/backfill.runner.d.ts +63 -0
- package/out/src/storage/schema/backfill.runner.d.ts.map +1 -0
- package/out/src/storage/schema/backfill.runner.js +64 -0
- package/out/src/storage/schema/backfill.runner.js.map +1 -0
- package/out/src/storage/schema/coinbaseMaturityBackfill.d.ts +25 -0
- package/out/src/storage/schema/coinbaseMaturityBackfill.d.ts.map +1 -0
- package/out/src/storage/schema/coinbaseMaturityBackfill.js +75 -0
- package/out/src/storage/schema/coinbaseMaturityBackfill.js.map +1 -0
- package/out/src/storage/schema/monitorLease.d.ts +57 -0
- package/out/src/storage/schema/monitorLease.d.ts.map +1 -0
- package/out/src/storage/schema/monitorLease.js +101 -0
- package/out/src/storage/schema/monitorLease.js.map +1 -0
- package/out/src/storage/schema/processingFsm.d.ts +27 -0
- package/out/src/storage/schema/processingFsm.d.ts.map +1 -0
- package/out/src/storage/schema/processingFsm.js +132 -0
- package/out/src/storage/schema/processingFsm.js.map +1 -0
- package/out/src/storage/schema/schemaCutover.d.ts +34 -0
- package/out/src/storage/schema/schemaCutover.d.ts.map +1 -0
- package/out/src/storage/schema/schemaCutover.js +230 -0
- package/out/src/storage/schema/schemaCutover.js.map +1 -0
- package/out/src/storage/schema/schemaCutoverIdb.d.ts +26 -0
- package/out/src/storage/schema/schemaCutoverIdb.d.ts.map +1 -0
- package/out/src/storage/schema/schemaCutoverIdb.js +90 -0
- package/out/src/storage/schema/schemaCutoverIdb.js.map +1 -0
- package/out/src/storage/schema/spendabilityRefresh.d.ts +49 -0
- package/out/src/storage/schema/spendabilityRefresh.d.ts.map +1 -0
- package/out/src/storage/schema/spendabilityRefresh.js +120 -0
- package/out/src/storage/schema/spendabilityRefresh.js.map +1 -0
- package/out/src/storage/schema/spendabilityRule.d.ts +45 -0
- package/out/src/storage/schema/spendabilityRule.d.ts.map +1 -0
- package/out/src/storage/schema/spendabilityRule.js +52 -0
- package/out/src/storage/schema/spendabilityRule.js.map +1 -0
- package/out/src/storage/schema/tables/TableAction.d.ts +3 -3
- package/out/src/storage/schema/tables/TableAction.d.ts.map +1 -1
- package/out/src/storage/schema/tables/TableChainTip.d.ts +1 -1
- package/out/src/storage/schema/tables/TableMonitorLease.d.ts +1 -1
- package/out/src/storage/schema/tables/TableOutput.d.ts +7 -0
- package/out/src/storage/schema/tables/TableOutput.d.ts.map +1 -1
- package/out/src/storage/schema/tables/TableOutput.js.map +1 -1
- package/out/src/storage/schema/tables/TableTransactionNew.d.ts +50 -0
- package/out/src/storage/schema/tables/TableTransactionNew.d.ts.map +1 -0
- package/out/src/storage/schema/tables/TableTransactionNew.js +3 -0
- package/out/src/storage/schema/tables/TableTransactionNew.js.map +1 -0
- package/out/src/storage/schema/tables/TableTxAudit.d.ts +1 -1
- package/out/src/storage/schema/tables/index.d.ts +5 -0
- package/out/src/storage/schema/tables/index.d.ts.map +1 -1
- package/out/src/storage/schema/tables/index.js +5 -0
- package/out/src/storage/schema/tables/index.js.map +1 -1
- package/out/src/storage/schema/transactionCrud.d.ts +41 -0
- package/out/src/storage/schema/transactionCrud.d.ts.map +1 -0
- package/out/src/storage/schema/transactionCrud.js +205 -0
- package/out/src/storage/schema/transactionCrud.js.map +1 -0
- package/out/src/storage/schema/transactionService.d.ts +315 -0
- package/out/src/storage/schema/transactionService.d.ts.map +1 -0
- package/out/src/storage/schema/transactionService.js +783 -0
- package/out/src/storage/schema/transactionService.js.map +1 -0
- package/out/src/storage/schema/txAudit.d.ts +33 -0
- package/out/src/storage/schema/txAudit.d.ts.map +1 -0
- package/out/src/storage/schema/txAudit.js +64 -0
- package/out/src/storage/schema/txAudit.js.map +1 -0
- package/out/src/storage/schema/v7Backfill.d.ts.map +1 -1
- package/out/src/storage/schema/v7Backfill.js +4 -1
- package/out/src/storage/schema/v7Backfill.js.map +1 -1
- package/out/src/storage/schema/v7Backfill.runner.d.ts.map +1 -1
- package/out/src/storage/schema/v7Backfill.runner.js +3 -1
- package/out/src/storage/schema/v7Backfill.runner.js.map +1 -1
- package/out/src/storage/schema/v7CoinbaseMaturityBackfill.d.ts +25 -0
- package/out/src/storage/schema/v7CoinbaseMaturityBackfill.d.ts.map +1 -0
- package/out/src/storage/schema/v7CoinbaseMaturityBackfill.js +75 -0
- package/out/src/storage/schema/v7CoinbaseMaturityBackfill.js.map +1 -0
- package/out/src/storage/schema/v7Crud.d.ts +5 -3
- package/out/src/storage/schema/v7Crud.d.ts.map +1 -1
- package/out/src/storage/schema/v7Crud.js +11 -9
- package/out/src/storage/schema/v7Crud.js.map +1 -1
- package/out/src/storage/schema/v7Cutover.d.ts +34 -0
- package/out/src/storage/schema/v7Cutover.d.ts.map +1 -0
- package/out/src/storage/schema/v7Cutover.js +223 -0
- package/out/src/storage/schema/v7Cutover.js.map +1 -0
- package/out/src/storage/schema/v7CutoverIdb.d.ts +26 -0
- package/out/src/storage/schema/v7CutoverIdb.d.ts.map +1 -0
- package/out/src/storage/schema/v7CutoverIdb.js +90 -0
- package/out/src/storage/schema/v7CutoverIdb.js.map +1 -0
- package/out/src/storage/schema/v7Fsm.d.ts.map +1 -1
- package/out/src/storage/schema/v7Fsm.js +22 -6
- package/out/src/storage/schema/v7Fsm.js.map +1 -1
- package/out/src/storage/schema/v7Service.d.ts +305 -0
- package/out/src/storage/schema/v7Service.d.ts.map +1 -0
- package/out/src/storage/schema/v7Service.js +757 -0
- package/out/src/storage/schema/v7Service.js.map +1 -0
- package/out/src/storage/schema/v7SpendabilityRefresh.d.ts +49 -0
- package/out/src/storage/schema/v7SpendabilityRefresh.d.ts.map +1 -0
- package/out/src/storage/schema/v7SpendabilityRefresh.js +111 -0
- package/out/src/storage/schema/v7SpendabilityRefresh.js.map +1 -0
- package/out/src/storage/storageProviderHelpers.js +1 -1
- package/out/src/storage/storageProviderHelpers.js.map +1 -1
- package/out/src/utility/Format.js.map +1 -1
- package/package.json +7 -4
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runIdbSchemaCutover = runIdbSchemaCutover;
|
|
4
|
+
const idb_1 = require("idb");
|
|
5
|
+
/**
|
|
6
|
+
* IDB-side schema cutover.
|
|
7
|
+
*
|
|
8
|
+
* IndexedDB has no `RENAME STORE` primitive, and store creation/deletion is
|
|
9
|
+
* only permitted during a version-upgrade transaction. The cutover therefore:
|
|
10
|
+
*
|
|
11
|
+
* 1. Re-opens the database at a higher version, supplying an `upgrade`
|
|
12
|
+
* callback that does the rename via copy-and-delete on the upgrade trx.
|
|
13
|
+
* 2. For each table that needs renaming:
|
|
14
|
+
* a. Read every row from the source store.
|
|
15
|
+
* b. Create the destination store with the same indexes.
|
|
16
|
+
* c. Write rows into the destination store.
|
|
17
|
+
* d. Delete the source store.
|
|
18
|
+
* 3. Returns the upgraded database handle (caller is responsible for
|
|
19
|
+
* closing it).
|
|
20
|
+
*
|
|
21
|
+
* Safe to call twice — the second call sees the post-cutover layout, skips
|
|
22
|
+
* the rename block, and returns without error.
|
|
23
|
+
*
|
|
24
|
+
* `targetVersion` defaults to 2; bump it if the caller already operates on a
|
|
25
|
+
* higher schema version.
|
|
26
|
+
*/
|
|
27
|
+
async function runIdbSchemaCutover(dbName, targetVersion = 2) {
|
|
28
|
+
return await (0, idb_1.openDB)(dbName, targetVersion, {
|
|
29
|
+
async upgrade(db, oldVersion, _newVersion, trx) {
|
|
30
|
+
if (oldVersion >= 2)
|
|
31
|
+
return;
|
|
32
|
+
if (!db.objectStoreNames.contains('transactions_new'))
|
|
33
|
+
return;
|
|
34
|
+
await renameStore(db, trx, 'transactions', 'transactions_legacy', store => {
|
|
35
|
+
store.createIndex('userId', 'userId');
|
|
36
|
+
store.createIndex('status', 'status');
|
|
37
|
+
store.createIndex('status_userId', ['status', 'userId']);
|
|
38
|
+
store.createIndex('provenTxId', 'provenTxId');
|
|
39
|
+
store.createIndex('reference', 'reference', { unique: true });
|
|
40
|
+
});
|
|
41
|
+
await renameStore(db, trx, 'proven_tx_reqs', 'proven_tx_reqs_legacy', store => {
|
|
42
|
+
store.createIndex('provenTxId', 'provenTxId');
|
|
43
|
+
store.createIndex('txid', 'txid', { unique: true });
|
|
44
|
+
store.createIndex('status', 'status');
|
|
45
|
+
store.createIndex('batch', 'batch');
|
|
46
|
+
});
|
|
47
|
+
await renameStore(db, trx, 'proven_txs', 'proven_txs_legacy', store => {
|
|
48
|
+
store.createIndex('txid', 'txid', { unique: true });
|
|
49
|
+
});
|
|
50
|
+
await renameStore(db, trx, 'transactions_new', 'transactions', store => {
|
|
51
|
+
store.createIndex('txid', 'txid', { unique: true });
|
|
52
|
+
store.createIndex('processing', 'processing');
|
|
53
|
+
store.createIndex('batch', 'batch');
|
|
54
|
+
store.createIndex('idempotencyKey', 'idempotencyKey', { unique: true });
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async function renameStore(db, trx, fromName, toName, applyIndexes) {
|
|
60
|
+
if (!db.objectStoreNames.contains(fromName))
|
|
61
|
+
return;
|
|
62
|
+
if (db.objectStoreNames.contains(toName)) {
|
|
63
|
+
// Target already exists — assume a prior partial cutover. Drop the source
|
|
64
|
+
// and continue rather than fail; the application is expected to verify
|
|
65
|
+
// post-cutover state via its own smoke tests before resuming traffic.
|
|
66
|
+
db.deleteObjectStore(fromName);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const sourceStore = trx.objectStore(fromName);
|
|
70
|
+
const sourceKeyPath = sourceStore.keyPath;
|
|
71
|
+
const sourceAutoIncrement = sourceStore.autoIncrement;
|
|
72
|
+
const rows = await sourceStore.getAll();
|
|
73
|
+
const keys = await sourceStore.getAllKeys();
|
|
74
|
+
db.deleteObjectStore(fromName);
|
|
75
|
+
const dest = db.createObjectStore(toName, {
|
|
76
|
+
keyPath: sourceKeyPath !== null && sourceKeyPath !== void 0 ? sourceKeyPath : undefined,
|
|
77
|
+
autoIncrement: sourceAutoIncrement
|
|
78
|
+
});
|
|
79
|
+
applyIndexes(dest);
|
|
80
|
+
const destStore = trx.objectStore(toName);
|
|
81
|
+
for (let i = 0; i < rows.length; i++) {
|
|
82
|
+
if (sourceAutoIncrement || sourceKeyPath != null) {
|
|
83
|
+
await destStore.put(rows[i]);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
await destStore.put(rows[i], keys[i]);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=schemaCutoverIdb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaCutoverIdb.js","sourceRoot":"","sources":["../../../../src/storage/schema/schemaCutoverIdb.ts"],"names":[],"mappings":";;AAyBA,kDA4DC;AArFD,6BAA2D;AAG3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACI,KAAK,UAAU,mBAAmB,CACvC,MAAc,EACd,aAAa,GAAG,CAAC;IAEjB,OAAO,MAAM,IAAA,YAAM,EAAmB,MAAM,EAAE,aAAa,EAAE;QAC3D,KAAK,CAAC,OAAO,CAAE,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG;YAC7C,IAAI,UAAU,IAAI,CAAC;gBAAE,OAAM;YAC3B,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,kBAAkB,CAAC;gBAAE,OAAM;YAE7D,MAAM,WAAW,CACf,EAAE,EACF,GAA8D,EAC9D,cAAc,EACd,qBAAqB,EACrB,KAAK,CAAC,EAAE;gBACN,KAAK,CAAC,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;gBACrC,KAAK,CAAC,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;gBACrC,KAA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IAAI,IAAI,EAAE,CAAC;YACjD,MAAM,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;QAC9B,CAAC;aAAM,CAAC;YACN,MAAM,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;QACvC,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Knex } from 'knex';
|
|
2
|
+
import * as sdk from '../../sdk';
|
|
3
|
+
/**
|
|
4
|
+
* Recompute and persist `outputs.spendable` for every output whose current
|
|
5
|
+
* cached value disagrees with the §4 rule.
|
|
6
|
+
*
|
|
7
|
+
* The §4 rule depends on three inputs:
|
|
8
|
+
* - The owning transaction's `processing` state.
|
|
9
|
+
* - Whether the output has been spent.
|
|
10
|
+
* - For coinbase outputs, whether maturity height has been reached on the
|
|
11
|
+
* current chain tip.
|
|
12
|
+
*
|
|
13
|
+
* Strategy: stream outputs joined with their owning transaction's processing
|
|
14
|
+
* state in batches, evaluate the rule per row in JS, and update only rows
|
|
15
|
+
* whose persisted `spendable` flag differs from the freshly-computed value.
|
|
16
|
+
*
|
|
17
|
+
* Returns counts so callers can detect drift and emit metrics.
|
|
18
|
+
*/
|
|
19
|
+
export interface RefreshSpendabilityStats {
|
|
20
|
+
examined: number;
|
|
21
|
+
flipped: number;
|
|
22
|
+
}
|
|
23
|
+
export interface RefreshSpendabilityArgs {
|
|
24
|
+
/** Limit to outputs owned by this user. Default: refresh all users. */
|
|
25
|
+
userId?: number;
|
|
26
|
+
/** Reuse a chain tip already fetched by the caller. */
|
|
27
|
+
chainTip?: {
|
|
28
|
+
height: number;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export declare function refreshOutputsSpendable(knex: Knex, args?: RefreshSpendabilityArgs): Promise<RefreshSpendabilityStats>;
|
|
32
|
+
/**
|
|
33
|
+
* Fast-path counter used by the new-schema hot query in §2.3:
|
|
34
|
+
*
|
|
35
|
+
* SELECT * FROM outputs
|
|
36
|
+
* WHERE user_id = ? AND spendable = true AND basketId = default
|
|
37
|
+
* ORDER BY satoshis DESC LIMIT 100
|
|
38
|
+
*
|
|
39
|
+
* Returns the count of spendable outputs visible to the user in a basket
|
|
40
|
+
* without joining transactions. Used by tests to assert that the cached
|
|
41
|
+
* `outputs.spendable` column stays in sync with processing state.
|
|
42
|
+
*/
|
|
43
|
+
export declare function countCachedSpendable(knex: Knex, args: {
|
|
44
|
+
userId: number;
|
|
45
|
+
basketId?: number;
|
|
46
|
+
}): Promise<number>;
|
|
47
|
+
/** Snapshot of every spendable processing state. Mostly informational. */
|
|
48
|
+
export declare function spendableProcessingStates(): readonly sdk.ProcessingStatus[];
|
|
49
|
+
//# sourceMappingURL=spendabilityRefresh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spendabilityRefresh.d.ts","sourceRoot":"","sources":["../../../../src/storage/schema/spendabilityRefresh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,KAAK,GAAG,MAAM,WAAW,CAAA;AAOhC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,uBAAuB;IACtC,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,uDAAuD;IACvD,QAAQ,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CAC9B;AAED,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,IAAI,EACV,IAAI,GAAE,uBAA4B,GACjC,OAAO,CAAC,wBAAwB,CAAC,CAkEnC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,IAAI,EACV,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1C,OAAO,CAAC,MAAM,CAAC,CAKjB;AAED,0EAA0E;AAC1E,wBAAgB,yBAAyB,IAAK,SAAS,GAAG,CAAC,gBAAgB,EAAE,CAE5E"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.refreshOutputsSpendable = refreshOutputsSpendable;
|
|
37
|
+
exports.countCachedSpendable = countCachedSpendable;
|
|
38
|
+
exports.spendableProcessingStates = spendableProcessingStates;
|
|
39
|
+
const sdk = __importStar(require("../../sdk"));
|
|
40
|
+
const spendabilityRule_1 = require("./spendabilityRule");
|
|
41
|
+
const REFRESH_BATCH = 500;
|
|
42
|
+
const SPENDABLE_STATES = sdk.ProcessingSpendableStatus.slice();
|
|
43
|
+
async function refreshOutputsSpendable(knex, args = {}) {
|
|
44
|
+
var _a, _b, _c, _d, _e;
|
|
45
|
+
const stats = { examined: 0, flipped: 0 };
|
|
46
|
+
const tip = (_a = args.chainTip) !== null && _a !== void 0 ? _a : (await knex('chain_tip').where({ id: 1 }).first('height'));
|
|
47
|
+
const tipHeight = tip === null || tip === void 0 ? void 0 : tip.height;
|
|
48
|
+
let lastId = 0;
|
|
49
|
+
/* eslint-disable-next-line no-constant-condition */
|
|
50
|
+
while (true) {
|
|
51
|
+
const baseQuery = knex('outputs as o')
|
|
52
|
+
.leftJoin('transactions as t', 't.transactionId', 'o.transactionId')
|
|
53
|
+
.where('o.outputId', '>', lastId)
|
|
54
|
+
.orderBy('o.outputId')
|
|
55
|
+
.limit(REFRESH_BATCH)
|
|
56
|
+
.select(knex.ref('o.outputId').as('outputId'), knex.ref('o.spendable').as('spendable'), knex.ref('o.spentBy').as('spentBy'), knex.ref('o.lockingScript').as('lockingScript'), knex.raw('o.scriptLength as scriptLength'), knex.raw('o.matures_at_height as maturesAtHeight'), knex.ref('t.processing').as('processing'), knex.ref('t.is_coinbase').as('isCoinbase'));
|
|
57
|
+
const rows = args.userId != null
|
|
58
|
+
? await baseQuery.andWhere('o.userId', args.userId)
|
|
59
|
+
: await baseQuery;
|
|
60
|
+
if (rows.length === 0)
|
|
61
|
+
return stats;
|
|
62
|
+
for (const row of rows) {
|
|
63
|
+
lastId = row.outputId;
|
|
64
|
+
stats.examined += 1;
|
|
65
|
+
// Reorg rule (bsv_wallet_transaction_requirements v1.0 §6):
|
|
66
|
+
// "Reorg: Revert transaction status; preserve the current spendable
|
|
67
|
+
// value of outputs (do not flip to false)."
|
|
68
|
+
// We honor this by skipping refresh while the owning transaction is
|
|
69
|
+
// in the `reorging` state. Whatever spendable value was cached at
|
|
70
|
+
// entry into reorg is preserved until the reorg resolves and the
|
|
71
|
+
// transaction transitions back to a normal state.
|
|
72
|
+
if (row.processing === 'reorging')
|
|
73
|
+
continue;
|
|
74
|
+
const desired = (0, spendabilityRule_1.isOutputSpendable)({
|
|
75
|
+
spentBy: (_b = row.spentBy) !== null && _b !== void 0 ? _b : null,
|
|
76
|
+
// Treat presence of scriptLength as equivalent to presence of
|
|
77
|
+
// locking script — the §4 rule only requires that some locking
|
|
78
|
+
// script exists, not that it has been fetched into memory.
|
|
79
|
+
lockingScript: (_d = ((_c = row.lockingScript) !== null && _c !== void 0 ? _c : null)) !== null && _d !== void 0 ? _d : (row.scriptLength != null ? [0] : null),
|
|
80
|
+
isCoinbase: row.isCoinbase === 1 || row.isCoinbase === true,
|
|
81
|
+
// Read the persisted maturity height from the new outputs column.
|
|
82
|
+
// A null value for a coinbase row means maturity has not been
|
|
83
|
+
// computed yet; the §4 rule treats that as not-yet-mature and
|
|
84
|
+
// refuses spendability until backfill populates the column.
|
|
85
|
+
maturesAtHeight: (_e = row.maturesAtHeight) !== null && _e !== void 0 ? _e : null
|
|
86
|
+
}, { processing: row.processing }, tipHeight != null ? { height: tipHeight } : undefined);
|
|
87
|
+
const current = row.spendable === 1 || row.spendable === true;
|
|
88
|
+
if (current !== desired) {
|
|
89
|
+
await knex('outputs')
|
|
90
|
+
.where({ outputId: row.outputId })
|
|
91
|
+
.update({ spendable: desired });
|
|
92
|
+
stats.flipped += 1;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Fast-path counter used by the new-schema hot query in §2.3:
|
|
99
|
+
*
|
|
100
|
+
* SELECT * FROM outputs
|
|
101
|
+
* WHERE user_id = ? AND spendable = true AND basketId = default
|
|
102
|
+
* ORDER BY satoshis DESC LIMIT 100
|
|
103
|
+
*
|
|
104
|
+
* Returns the count of spendable outputs visible to the user in a basket
|
|
105
|
+
* without joining transactions. Used by tests to assert that the cached
|
|
106
|
+
* `outputs.spendable` column stays in sync with processing state.
|
|
107
|
+
*/
|
|
108
|
+
async function countCachedSpendable(knex, args) {
|
|
109
|
+
var _a;
|
|
110
|
+
const q = knex('outputs').where({ userId: args.userId, spendable: true });
|
|
111
|
+
if (args.basketId != null)
|
|
112
|
+
q.andWhere({ basketId: args.basketId });
|
|
113
|
+
const row = await q.count({ c: '*' }).first();
|
|
114
|
+
return (_a = row === null || row === void 0 ? void 0 : row.c) !== null && _a !== void 0 ? _a : 0;
|
|
115
|
+
}
|
|
116
|
+
/** Snapshot of every spendable processing state. Mostly informational. */
|
|
117
|
+
function spendableProcessingStates() {
|
|
118
|
+
return SPENDABLE_STATES;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=spendabilityRefresh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spendabilityRefresh.js","sourceRoot":"","sources":["../../../../src/storage/schema/spendabilityRefresh.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,0DAqEC;AAaD,oDAQC;AAGD,8DAEC;AAlID,+CAAgC;AAChC,yDAAsD;AAEtD,MAAM,aAAa,GAAG,GAAG,CAAA;AAEzB,MAAM,gBAAgB,GAA2B,GAAG,CAAC,yBAAyB,CAAC,KAAK,EAAE,CAAA;AA8B/E,KAAK,UAAU,uBAAuB,CAC3C,IAAU,EACV,OAAgC,EAAE;;IAElC,MAAM,KAAK,GAA6B,EAAE,QAAQ,EAAE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C,IAAI,GAAG,CAAC,SAAS,KAAK,IAAI,CAAA;YAC7D,IAAI,OAAO,KAAK,OAAO,EAAE,CAAC;gBACxB,MAAM,IAAI,CAAC,SAAS,CAAC;qBAClB,KAAK,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC;qBACjC,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAA;gBACjC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAA;YACpB,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;;;GAUG;AACI,KAAK,UAAU,oBAAoB,CACxC,IAAU,EACV,IAA2C;;IAE3C,MAAM,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IACzE,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI;QAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;IAClE,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,KAAK,CAAgB,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,KAAK,EAAE,CAAA;IAC5D,OAAO,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,CAAC,mCAAI,CAAC,CAAA;AACpB,CAAC;AAED,0EAA0E;AAC1E,SAAgB,yBAAyB;IACvC,OAAO,gBAAgB,CAAA;AACzB,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as sdk from '../../sdk';
|
|
2
|
+
import { TableChainTip, TableOutput, TableTransactionNew } from './tables';
|
|
3
|
+
/**
|
|
4
|
+
* Per-output inputs for the new-schema spendability check.
|
|
5
|
+
*
|
|
6
|
+
* Only the fields needed by §4 of PROD_REQ_V7_TS.md are required; callers are
|
|
7
|
+
* free to pass full rows. `spentBy` is the legacy `outputs.spentBy` column;
|
|
8
|
+
* coinbase fields use the names introduced in §2.3.
|
|
9
|
+
*/
|
|
10
|
+
export interface SpendabilityOutputInput {
|
|
11
|
+
spentBy?: number | null;
|
|
12
|
+
lockingScript?: number[] | null;
|
|
13
|
+
isCoinbase?: boolean;
|
|
14
|
+
maturesAtHeight?: number | null;
|
|
15
|
+
}
|
|
16
|
+
export interface SpendabilityTxInput {
|
|
17
|
+
processing: sdk.ProcessingStatus;
|
|
18
|
+
}
|
|
19
|
+
export interface SpendabilityTipInput {
|
|
20
|
+
height: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Pure implementation of the §4 spendability rule:
|
|
24
|
+
*
|
|
25
|
+
* ```
|
|
26
|
+
* spendable = (transactions.processing IN ('sent','seen','seen_multi','unconfirmed','confirmed'))
|
|
27
|
+
* AND outputs.spent_by IS NULL
|
|
28
|
+
* AND outputs.locking_script IS NOT NULL
|
|
29
|
+
* AND (NOT outputs.is_coinbase OR outputs.matures_at_height <= chain_tip.height)
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* The function never reads from storage — call sites are responsible for
|
|
33
|
+
* loading the matching transaction row and chain tip. This keeps the rule
|
|
34
|
+
* testable in isolation and lets the refresh helpers batch loads efficiently.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isOutputSpendable(out: SpendabilityOutputInput, tx: SpendabilityTxInput, tip: SpendabilityTipInput | undefined): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Convenience wrapper that takes whole table rows and forwards to the pure
|
|
39
|
+
* predicate. Returns `false` when the matching transaction row is missing.
|
|
40
|
+
*/
|
|
41
|
+
export declare function isTableOutputSpendable(out: TableOutput & {
|
|
42
|
+
isCoinbase?: boolean;
|
|
43
|
+
maturesAtHeight?: number | null;
|
|
44
|
+
}, tx: TableTransactionNew | undefined, tip: TableChainTip | undefined): boolean;
|
|
45
|
+
//# sourceMappingURL=spendabilityRule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spendabilityRule.d.ts","sourceRoot":"","sources":["../../../../src/storage/schema/spendabilityRule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAG1E;;;;;;GAMG;AACH,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,aAAa,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAChC;AAED,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,GAAG,CAAC,gBAAgB,CAAA;CACjC;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,uBAAuB,EAC5B,EAAE,EAAE,mBAAmB,EACvB,GAAG,EAAE,oBAAoB,GAAG,SAAS,GACpC,OAAO,CAUT;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,WAAW,GAAG;IAAE,UAAU,CAAC,EAAE,OAAO,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EAC5E,EAAE,EAAE,mBAAmB,GAAG,SAAS,EACnC,GAAG,EAAE,aAAa,GAAG,SAAS,GAC7B,OAAO,CAYT"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isOutputSpendable = isOutputSpendable;
|
|
4
|
+
exports.isTableOutputSpendable = isTableOutputSpendable;
|
|
5
|
+
const processingFsm_1 = require("./processingFsm");
|
|
6
|
+
/**
|
|
7
|
+
* Pure implementation of the §4 spendability rule:
|
|
8
|
+
*
|
|
9
|
+
* ```
|
|
10
|
+
* spendable = (transactions.processing IN ('sent','seen','seen_multi','unconfirmed','confirmed'))
|
|
11
|
+
* AND outputs.spent_by IS NULL
|
|
12
|
+
* AND outputs.locking_script IS NOT NULL
|
|
13
|
+
* AND (NOT outputs.is_coinbase OR outputs.matures_at_height <= chain_tip.height)
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* The function never reads from storage — call sites are responsible for
|
|
17
|
+
* loading the matching transaction row and chain tip. This keeps the rule
|
|
18
|
+
* testable in isolation and lets the refresh helpers batch loads efficiently.
|
|
19
|
+
*/
|
|
20
|
+
function isOutputSpendable(out, tx, tip) {
|
|
21
|
+
if (!(0, processingFsm_1.isProcessingSpendable)(tx.processing))
|
|
22
|
+
return false;
|
|
23
|
+
if (out.spentBy != null)
|
|
24
|
+
return false;
|
|
25
|
+
if (out.lockingScript == null)
|
|
26
|
+
return false;
|
|
27
|
+
if (out.isCoinbase === true) {
|
|
28
|
+
if (tip == null)
|
|
29
|
+
return false;
|
|
30
|
+
if (out.maturesAtHeight == null)
|
|
31
|
+
return false;
|
|
32
|
+
if (out.maturesAtHeight > tip.height)
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Convenience wrapper that takes whole table rows and forwards to the pure
|
|
39
|
+
* predicate. Returns `false` when the matching transaction row is missing.
|
|
40
|
+
*/
|
|
41
|
+
function isTableOutputSpendable(out, tx, tip) {
|
|
42
|
+
var _a, _b, _c;
|
|
43
|
+
if (tx === undefined)
|
|
44
|
+
return false;
|
|
45
|
+
return isOutputSpendable({
|
|
46
|
+
spentBy: (_a = out.spentBy) !== null && _a !== void 0 ? _a : null,
|
|
47
|
+
lockingScript: (_b = out.lockingScript) !== null && _b !== void 0 ? _b : null,
|
|
48
|
+
isCoinbase: out.isCoinbase === true,
|
|
49
|
+
maturesAtHeight: (_c = out.maturesAtHeight) !== null && _c !== void 0 ? _c : null
|
|
50
|
+
}, { processing: tx.processing }, tip != null ? { height: tip.height } : undefined);
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=spendabilityRule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spendabilityRule.js","sourceRoot":"","sources":["../../../../src/storage/schema/spendabilityRule.ts"],"names":[],"mappings":";;AAwCA,8CAcC;AAMD,wDAgBC;AA1ED,mDAAuD;AAwBvD;;;;;;;;;;;;;GAaG;AACH,SAAgB,iBAAiB,CAC/B,GAA4B,EAC5B,EAAuB,EACvB,GAAqC;IAErC,IAAI,CAAC,IAAA,qCAAqB,EAAC,EAAE,CAAC,UAAU,CAAC;QAAE,OAAO,KAAK,CAAA;IACvD,IAAI,GAAG,CAAC,OAAO,IAAI,IAAI;QAAE,OAAO,KAAK,CAAA;IACrC,IAAI,GAAG,CAAC,aAAa,IAAI,IAAI;QAAE,OAAO,KAAK,CAAA;IAC3C,IAAI,GAAG,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;QAC5B,IAAI,GAAG,IAAI,IAAI;YAAE,OAAO,KAAK,CAAA;QAC7B,IAAI,GAAG,CAAC,eAAe,IAAI,IAAI;YAAE,OAAO,KAAK,CAAA;QAC7C,IAAI,GAAG,CAAC,eAAe,GAAG,GAAG,CAAC,MAAM;YAAE,OAAO,KAAK,CAAA;IACpD,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;GAGG;AACH,SAAgB,sBAAsB,CACpC,GAA4E,EAC5E,EAAmC,EACnC,GAA8B;;IAE9B,IAAI,EAAE,KAAK,SAAS;QAAE,OAAO,KAAK,CAAA;IAClC,OAAO,iBAAiB,CACtB;QACE,OAAO,EAAE,MAAA,GAAG,CAAC,OAAO,mCAAI,IAAI;QAC5B,aAAa,EAAE,MAAA,GAAG,CAAC,aAAa,mCAAI,IAAI;QACxC,UAAU,EAAE,GAAG,CAAC,UAAU,KAAK,IAAI;QACnC,eAAe,EAAE,MAAA,GAAG,CAAC,eAAe,mCAAI,IAAI;KAC7C,EACD,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,EAC7B,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CACjD,CAAA;AACH,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as sdk from '../../../sdk';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* per-user view of a transaction.
|
|
4
4
|
*
|
|
5
5
|
* Migrated from the legacy `transactions` table. Holds everything that is truly
|
|
6
6
|
* per-user (description, labels via tx_labels_map -> actionId, soft-delete flags,
|
|
7
|
-
* notification subscribers). All on-chain status lives in the
|
|
7
|
+
* notification subscribers). All on-chain status lives in the new `transactions`
|
|
8
8
|
* table addressed by `transactionId`.
|
|
9
9
|
*
|
|
10
10
|
* UNIQUE(userId, transactionId).
|
|
@@ -15,7 +15,7 @@ export interface TableAction extends sdk.EntityTimeStamp {
|
|
|
15
15
|
/** PK */
|
|
16
16
|
actionId: number;
|
|
17
17
|
userId: number;
|
|
18
|
-
/** FK ->
|
|
18
|
+
/** FK -> new transactions.transactionId (per-txid record) */
|
|
19
19
|
transactionId: number;
|
|
20
20
|
/** Application reference, hex/Base64, max 64 chars */
|
|
21
21
|
reference: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableAction.d.ts","sourceRoot":"","sources":["../../../../../src/storage/schema/tables/TableAction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AAEnC;;;;;;;;;GASG;AACH,MAAM,WAAW,WAAY,SAAQ,GAAG,CAAC,eAAe;IACtD,UAAU,EAAE,IAAI,CAAA;IAChB,UAAU,EAAE,IAAI,CAAA;IAChB,SAAS;IACT,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,
|
|
1
|
+
{"version":3,"file":"TableAction.d.ts","sourceRoot":"","sources":["../../../../../src/storage/schema/tables/TableAction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AAEnC;;;;;;;;;GASG;AACH,MAAM,WAAW,WAAY,SAAQ,GAAG,CAAC,eAAe;IACtD,UAAU,EAAE,IAAI,CAAA;IAChB,UAAU,EAAE,IAAI,CAAA;IAChB,SAAS;IACT,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,6DAA6D;IAC7D,aAAa,EAAE,MAAM,CAAA;IACrB,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,+DAA+D;IAC/D,UAAU,EAAE,OAAO,CAAA;IACnB,gEAAgE;IAChE,aAAa,EAAE,MAAM,CAAA;IACrB,+BAA+B;IAC/B,UAAU,EAAE,OAAO,CAAA;IACnB,mDAAmD;IACnD,MAAM,EAAE,OAAO,CAAA;IACf,0BAA0B;IAC1B,WAAW,EAAE,OAAO,CAAA;IACpB,+EAA+E;IAC/E,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,mCAAmC;IACnC,UAAU,EAAE,MAAM,CAAA;CACnB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as sdk from '../../../sdk';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* singleton row tracking the most recently observed chain tip.
|
|
4
4
|
* Used by spendability checks and coinbase maturity calculations.
|
|
5
5
|
*/
|
|
6
6
|
export interface TableChainTip extends sdk.EntityTimeStamp {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as sdk from '../../../sdk';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* monitor_lease record so at most one Monitor daemon owns a given task at a time.
|
|
4
4
|
*
|
|
5
5
|
* The Monitor acquires a lease by upserting `(taskName, ownerId, expiresAt)`
|
|
6
6
|
* and renews periodically. Stale leases (`expiresAt < now`) may be claimed by
|
|
@@ -28,6 +28,13 @@ export interface TableOutput extends sdk.EntityTimeStamp {
|
|
|
28
28
|
scriptLength?: number;
|
|
29
29
|
scriptOffset?: number;
|
|
30
30
|
lockingScript?: number[];
|
|
31
|
+
/**
|
|
32
|
+
* new-schema: minimum block height at which a coinbase output becomes spendable.
|
|
33
|
+
* NULL for non-coinbase outputs and for pre-new schema rows that have not yet been
|
|
34
|
+
* backfilled. The §4 spendability rule treats a non-coinbase output as
|
|
35
|
+
* mature regardless of this column.
|
|
36
|
+
*/
|
|
37
|
+
maturesAtHeight?: number;
|
|
31
38
|
}
|
|
32
39
|
export interface TableOutputX extends TableOutput {
|
|
33
40
|
basket?: TableOutputBasket;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableOutput.d.ts","sourceRoot":"","sources":["../../../../../src/storage/schema/tables/TableOutput.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,2BAA2B,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AAEnC,MAAM,WAAW,WAAY,SAAQ,GAAG,CAAC,eAAe;IACtD,UAAU,EAAE,IAAI,CAAA;IAChB,UAAU,EAAE,IAAI,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,OAAO,CAAA;IAClB,MAAM,EAAE,OAAO,CAAA;IACf,iBAAiB,EAAE,2BAA2B,CAAA;IAC9C,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB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AAE,MAAM,CAAA;IACjB,SAAS,EAAE,OAAO,CAAA;IAClB,MAAM,EAAE,OAAO,CAAA;IACf,iBAAiB,EAAE,2BAA2B,CAAA;IAC9C,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,GAAG,CAAC,iBAAiB,CAAA;IACjC,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,iBAAiB,CAAC,EAAE,SAAS,CAAA;IAC7B,gBAAgB,CAAC,EAAE,YAAY,CAAA;IAC/B,gBAAgB,CAAC,EAAE,YAAY,CAAA;IAC/B,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;IACxB;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,MAAM,CAAC,EAAE,iBAAiB,CAAA;IAC1B,IAAI,CAAC,EAAE,cAAc,EAAE,CAAA;CACxB;AAED,eAAO,MAAM,iCAAiC,UA0B7C,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableOutput.js","sourceRoot":"","sources":["../../../../../src/storage/schema/tables/TableOutput.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"TableOutput.js","sourceRoot":"","sources":["../../../../../src/storage/schema/tables/TableOutput.ts"],"names":[],"mappings":";;;AA6Ca,QAAA,iCAAiC,GAAG;IAC/C,YAAY;IACZ,YAAY;IACZ,UAAU;IACV,QAAQ;IACR,eAAe;IACf,UAAU;IACV,WAAW;IACX,QAAQ;IACR,MAAM;IACN,UAAU;IACV,YAAY;IACZ,SAAS;IACT,MAAM;IACN,mBAAmB;IACnB,MAAM;IACN,mBAAmB;IACnB,kBAAkB;IAClB,kBAAkB;IAClB,oBAAoB;IACpB,SAAS;IACT,gBAAgB;IAChB,qBAAqB;IACrB,cAAc;IACd,cAAc;IACd,mBAAmB;CACpB,CAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as sdk from '../../../sdk';
|
|
2
|
+
/**
|
|
3
|
+
* new canonical per-txid table.
|
|
4
|
+
*
|
|
5
|
+
* Single source of truth for everything about a transaction on the network.
|
|
6
|
+
* Merges the legacy `proven_tx_reqs` (broadcast queue + processing state) and
|
|
7
|
+
* `proven_txs` (final Merkle proof) tables into one row per txid.
|
|
8
|
+
*
|
|
9
|
+
* Per-user metadata (description, labels, hidden, etc.) lives in `actions`.
|
|
10
|
+
*/
|
|
11
|
+
export interface TableTransactionNew extends sdk.EntityTimeStamp {
|
|
12
|
+
created_at: Date;
|
|
13
|
+
updated_at: Date;
|
|
14
|
+
/** PK */
|
|
15
|
+
transactionId: number;
|
|
16
|
+
/** UNIQUE — Bitcoin txid, hex */
|
|
17
|
+
txid: string;
|
|
18
|
+
/** Granular FSM state (see ProcessingStatus) */
|
|
19
|
+
processing: sdk.ProcessingStatus;
|
|
20
|
+
/** Wall-clock of the most recent processing transition */
|
|
21
|
+
processingChangedAt: Date;
|
|
22
|
+
/** Wall-clock at which the next monitor pass should consider this row */
|
|
23
|
+
nextActionAt?: Date;
|
|
24
|
+
/** Cumulative network-service attempt count */
|
|
25
|
+
attempts: number;
|
|
26
|
+
/** Count of times this row has been reset for rebroadcast (circuit-breaker) */
|
|
27
|
+
rebroadcastCycles: number;
|
|
28
|
+
/** true once the row has reached a state implying successful broadcast */
|
|
29
|
+
wasBroadcast: boolean;
|
|
30
|
+
/** Application-supplied idempotency key (unique when present) */
|
|
31
|
+
idempotencyKey?: string;
|
|
32
|
+
/** Optional batch tag for grouped broadcast */
|
|
33
|
+
batch?: string;
|
|
34
|
+
rawTx?: number[];
|
|
35
|
+
inputBeef?: number[];
|
|
36
|
+
/** Merkle proof fields — populated on transition to `proven` */
|
|
37
|
+
height?: number;
|
|
38
|
+
merkleIndex?: number;
|
|
39
|
+
merklePath?: number[];
|
|
40
|
+
merkleRoot?: string;
|
|
41
|
+
blockHash?: string;
|
|
42
|
+
isCoinbase: boolean;
|
|
43
|
+
lastProvider?: string;
|
|
44
|
+
lastProviderStatus?: string;
|
|
45
|
+
/** Reason a row is in `frozen` state, free text */
|
|
46
|
+
frozenReason?: string;
|
|
47
|
+
/** Optimistic concurrency token */
|
|
48
|
+
rowVersion: number;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=TableTransactionNew.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableTransactionNew.d.ts","sourceRoot":"","sources":["../../../../../src/storage/schema/tables/TableTransactionNew.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AAEnC;;;;;;;;GAQG;AACH,MAAM,WAAW,mBAAoB,SAAQ,GAAG,CAAC,eAAe;IAC9D,UAAU,EAAE,IAAI,CAAA;IAChB,UAAU,EAAE,IAAI,CAAA;IAChB,SAAS;IACT,aAAa,EAAE,MAAM,CAAA;IACrB,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,gDAAgD;IAChD,UAAU,EAAE,GAAG,CAAC,gBAAgB,CAAA;IAChC,0DAA0D;IAC1D,mBAAmB,EAAE,IAAI,CAAA;IACzB,yEAAyE;IACzE,YAAY,CAAC,EAAE,IAAI,CAAA;IACnB,+CAA+C;IAC/C,QAAQ,EAAE,MAAM,CAAA;IAChB,+EAA+E;IAC/E,iBAAiB,EAAE,MAAM,CAAA;IACzB,0EAA0E;IAC1E,YAAY,EAAE,OAAO,CAAA;IACrB,iEAAiE;IACjE,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,OAAO,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,mDAAmD;IACnD,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,mCAAmC;IACnC,UAAU,EAAE,MAAM,CAAA;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableTransactionNew.js","sourceRoot":"","sources":["../../../../../src/storage/schema/tables/TableTransactionNew.ts"],"names":[],"mappings":""}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as sdk from '../../../sdk';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* per-event audit log for transactions and actions.
|
|
4
4
|
*
|
|
5
5
|
* Each row records a single observable event scoped to either a transaction
|
|
6
6
|
* (per-txid) or an action (per-user) or both. Append-only.
|
|
@@ -14,4 +14,9 @@ export * from './TableTxLabel';
|
|
|
14
14
|
export * from './TableTxLabelMap';
|
|
15
15
|
export * from './TableMonitorEvent';
|
|
16
16
|
export * from './TableSyncState';
|
|
17
|
+
export * from './TableAction';
|
|
18
|
+
export * from './TableTransactionNew';
|
|
19
|
+
export * from './TableChainTip';
|
|
20
|
+
export * from './TableTxAudit';
|
|
21
|
+
export * from './TableMonitorLease';
|
|
17
22
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/storage/schema/tables/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,oBAAoB,CAAA;AAClC,cAAc,yBAAyB,CAAA;AACvC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/storage/schema/tables/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,oBAAoB,CAAA;AAClC,cAAc,yBAAyB,CAAA;AACvC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA"}
|
|
@@ -30,4 +30,9 @@ __exportStar(require("./TableTxLabel"), exports);
|
|
|
30
30
|
__exportStar(require("./TableTxLabelMap"), exports);
|
|
31
31
|
__exportStar(require("./TableMonitorEvent"), exports);
|
|
32
32
|
__exportStar(require("./TableSyncState"), exports);
|
|
33
|
+
__exportStar(require("./TableAction"), exports);
|
|
34
|
+
__exportStar(require("./TableTransactionNew"), exports);
|
|
35
|
+
__exportStar(require("./TableChainTip"), exports);
|
|
36
|
+
__exportStar(require("./TableTxAudit"), exports);
|
|
37
|
+
__exportStar(require("./TableMonitorLease"), exports);
|
|
33
38
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/storage/schema/tables/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B;AAC/B,kDAA+B;AAC/B,qDAAkC;AAClC,8CAA2B;AAC3B,qDAAkC;AAClC,0DAAuC;AACvC,sDAAmC;AACnC,qDAAkC;AAClC,oDAAiC;AACjC,gDAA6B;AAC7B,mDAAgC;AAChC,sDAAmC;AACnC,iDAA8B;AAC9B,oDAAiC;AACjC,sDAAmC;AACnC,mDAAgC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/storage/schema/tables/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B;AAC/B,kDAA+B;AAC/B,qDAAkC;AAClC,8CAA2B;AAC3B,qDAAkC;AAClC,0DAAuC;AACvC,sDAAmC;AACnC,qDAAkC;AAClC,oDAAiC;AACjC,gDAA6B;AAC7B,mDAAgC;AAChC,sDAAmC;AACnC,iDAA8B;AAC9B,oDAAiC;AACjC,sDAAmC;AACnC,mDAAgC;AAChC,gDAA6B;AAC7B,wDAAqC;AACrC,kDAA+B;AAC/B,iDAA8B;AAC9B,sDAAmC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Knex } from 'knex';
|
|
2
|
+
import * as sdk from '../../sdk';
|
|
3
|
+
import { TableAction, TableChainTip, TableTransactionNew } from './tables';
|
|
4
|
+
/** Read a single `transactions` (new canonical) row by txid, returning `undefined` if absent. */
|
|
5
|
+
export declare function findTransactionNewByTxid(knex: Knex, txid: string): Promise<TableTransactionNew | undefined>;
|
|
6
|
+
/** Read a single `transactions` (new canonical) row by PK. */
|
|
7
|
+
export declare function findTransactionNew(knex: Knex, transactionId: number): Promise<TableTransactionNew | undefined>;
|
|
8
|
+
/** Insert a new `transactions` (new canonical) row. Caller supplies the full body. */
|
|
9
|
+
export declare function insertTransactionNew(knex: Knex, row: Omit<TableTransactionNew, 'transactionId' | 'created_at' | 'updated_at'>, now?: Date): Promise<number>;
|
|
10
|
+
/**
|
|
11
|
+
* Transition the processing column atomically and append a `tx_audit` row.
|
|
12
|
+
* Returns the new `TableTransactionNew` on success and `undefined` when the
|
|
13
|
+
* source state did not match the row (CAS failed) or the transition was
|
|
14
|
+
* rejected by the FSM.
|
|
15
|
+
*
|
|
16
|
+
* Optimistic concurrency: the caller passes the `expectedFromState` they
|
|
17
|
+
* read in the same logical operation; the update only fires when the row's
|
|
18
|
+
* current `processing` still equals that value.
|
|
19
|
+
*/
|
|
20
|
+
export declare function transitionProcessing(knex: Knex, args: {
|
|
21
|
+
transactionId: number;
|
|
22
|
+
expectedFromState: sdk.ProcessingStatus;
|
|
23
|
+
toState: sdk.ProcessingStatus;
|
|
24
|
+
details?: Record<string, unknown>;
|
|
25
|
+
provider?: string;
|
|
26
|
+
providerStatus?: string;
|
|
27
|
+
}, now?: Date): Promise<TableTransactionNew | undefined>;
|
|
28
|
+
/** Find an action row by `(userId, transactionId)`. */
|
|
29
|
+
export declare function findAction(knex: Knex, userId: number, transactionId: number): Promise<TableAction | undefined>;
|
|
30
|
+
export declare function insertAction(knex: Knex, row: Omit<TableAction, 'actionId' | 'created_at' | 'updated_at'>, now?: Date): Promise<number>;
|
|
31
|
+
/** Get the singleton chain tip row (`id = 1`). */
|
|
32
|
+
export declare function getChainTip(knex: Knex): Promise<TableChainTip | undefined>;
|
|
33
|
+
/** Upsert the singleton chain tip. Always uses `id = 1`. */
|
|
34
|
+
export declare function setChainTip(knex: Knex, args: {
|
|
35
|
+
height: number;
|
|
36
|
+
blockHash: string;
|
|
37
|
+
merkleRoot?: string;
|
|
38
|
+
}, now?: Date): Promise<void>;
|
|
39
|
+
export declare function mapTransactionRow(row: any): TableTransactionNew;
|
|
40
|
+
export declare function mapActionRow(row: any): TableAction;
|
|
41
|
+
//# sourceMappingURL=transactionCrud.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactionCrud.d.ts","sourceRoot":"","sources":["../../../../src/storage/schema/transactionCrud.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,KAAK,GAAG,MAAM,WAAW,CAAA;AAChC,OAAO,EACL,WAAW,EACX,aAAa,EACb,mBAAmB,EACpB,MAAM,UAAU,CAAA;AAGjB,iGAAiG;AACjG,wBAAsB,wBAAwB,CAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAGlH;AAED,8DAA8D;AAC9D,wBAAsB,kBAAkB,CAAE,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAGrH;AAED,sFAAsF;AACtF,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,IAAI,CAAC,mBAAmB,EAAE,eAAe,GAAG,YAAY,GAAG,YAAY,CAAC,EAC7E,GAAG,GAAE,IAAiB,GACrB,OAAO,CAAC,MAAM,CAAC,CAKjB;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,IAAI,EACV,IAAI,EAAE;IACJ,aAAa,EAAE,MAAM,CAAA;IACrB,iBAAiB,EAAE,GAAG,CAAC,gBAAgB,CAAA;IACvC,OAAO,EAAE,GAAG,CAAC,gBAAgB,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