txq
Version:
TXQ: Bitcoin Transaction Storage Queue Service
31 lines (26 loc) • 1.12 kB
text/typescript
import { Service, Inject } from 'typedi';
('spendService')
export default class SpendService {
constructor(('txinModel') private txinModel, ('txoutModel') private txoutModel, ('logger') private logger) {}
public async updateSpendIndex(
txid: string, index: string, spendTxId: string, spendIndex: number
) {
await this.txoutModel.updateSpendIndex(txid, index, spendTxId, spendIndex);
}
/**
* Backfill any required spend_txid and spend_index for transactions created out of orde
*
* @param txid txid to check if spent
* @param index index of txid to check if spent
*/
public async backfillSpendIndexIfNeeded(
txid: string, index: string
) {
// We must also check to see if a tx that spends the current txid+index already exists
// The user could have inserted a child tx first, therefore we must make sure to update spend index if needed
const foundSpend = await this.txinModel.getTxinByPrev(txid, index);
if (foundSpend) {
await this.txoutModel.updateSpendIndex(txid, index, foundSpend.txid, foundSpend.index);
}
}
}