diff --git a/backend/src/api/common.ts b/backend/src/api/common.ts index 9836559ae..735e240c1 100644 --- a/backend/src/api/common.ts +++ b/backend/src/api/common.ts @@ -86,19 +86,19 @@ export class Common { const match = spendMap.get(`${vin.txid}:${vin.vout}`); if (match && match.txid !== tx.txid) { replaced.add(match); + // remove this tx from the spendMap + // prevents the same tx being replaced more than once + for (const replacedVin of match.vin) { + const key = `${replacedVin.txid}:${replacedVin.vout}`; + spendMap.delete(key); + } } + const key = `${vin.txid}:${vin.vout}`; + spendMap.delete(key); } if (replaced.size) { matches[tx.txid] = { replaced: Array.from(replaced), replacedBy: tx }; } - // remove this tx from the spendMap - // prevents the same tx being replaced more than once - for (const vin of tx.vin) { - const key = `${vin.txid}:${vin.vout}`; - if (spendMap.get(key)?.txid === tx.txid) { - spendMap.delete(key); - } - } } return matches; }