games_app/backend/dist-test-faq/repositories/depositScannerRepository.js

30 lines
1.3 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getState = getState;
exports.updateState = updateState;
const connection_1 = require("../db/connection");
/**
* Repository for deposit scanner checkpoint state.
* Tracks the last processed blockchain block per wallet type.
*/
/**
* Retrieves the last scanned block for a wallet type.
* @param walletTypeId - ID of the wallet type to query.
* @returns The last scanned block number as text, or null if no state exists.
*/
async function getState(walletTypeId) {
const rows = await (0, connection_1.query)('SELECT last_block::text as last_block FROM deposit_scanner_state WHERE wallet_type_id = $1', [walletTypeId]);
return rows[0] || null;
}
/**
* Upserts the last scanned block for a wallet type.
* @param walletTypeId - ID of the wallet type to update.
* @param lastBlock - Latest block number that has been fully processed.
* @returns Resolves when the state row has been inserted or updated.
*/
async function updateState(walletTypeId, lastBlock) {
await (0, connection_1.query)(`INSERT INTO deposit_scanner_state (wallet_type_id, last_block, updated_at)
VALUES ($1, $2, NOW())
ON CONFLICT (wallet_type_id) DO UPDATE SET last_block = $2, updated_at = NOW()`, [walletTypeId, lastBlock.toString()]);
}
//# sourceMappingURL=depositScannerRepository.js.map