Skip to content

Commit 148f882

Browse files
authored
feat: address filtering on the basis of active and inactive field (#358)
Signed-off-by: Ravindra Meena <rmeena840@gmail.com>
1 parent c1e492f commit 148f882

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

packages/btcindexer/src/btcindexer.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,24 @@ describe("Indexer.findNbtcDeposits", () => {
151151
expect(deposits[1]![0]!.suiRecipient).toEqual(REGTEST_DATA[327]!.txs[2]!.suiAddr);
152152
expect(deposits[1]![0]!.amount).toEqual(REGTEST_DATA[327]!.txs[2]!.amount);
153153
});
154+
155+
it("should skip inactive deposit addresses", () => {
156+
const block = Block.fromHex(REGTEST_DATA[329]!.rawBlockHex);
157+
const targetTx = block.transactions?.find(
158+
(tx) => tx.getId() === REGTEST_DATA[329]!.txs[1]!.id,
159+
);
160+
expect(targetTx).toBeDefined();
161+
162+
const originalMap = indexer.nbtcDepositAddrMap;
163+
indexer.nbtcDepositAddrMap = new Map([
164+
[REGTEST_DATA[329]!.depositAddr, { setup_id: 1, is_active: false }],
165+
]);
166+
167+
const deposits = indexer.findNbtcDeposits(targetTx!, networks.regtest);
168+
expect(deposits.length).toEqual(0);
169+
170+
indexer.nbtcDepositAddrMap = originalMap;
171+
});
154172
});
155173

156174
describe("Indexer.processBlock", () => {

packages/btcindexer/src/btcindexer.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,17 @@ export class Indexer {
385385
}
386386
try {
387387
const btcAddress = address.fromOutputScript(vout.script, network);
388-
const pkgId = this.nbtcDepositAddrMap.get(btcAddress)?.setup_id;
389-
if (pkgId === undefined) continue;
390-
const config = this.getPackageConfig(pkgId);
388+
const depositInfo = this.nbtcDepositAddrMap.get(btcAddress);
389+
if (!depositInfo) continue;
390+
if (!depositInfo.is_active) {
391+
logger.debug({
392+
msg: "Skipping inactive deposit address",
393+
txId: tx.getId(),
394+
btcAddress,
395+
});
396+
continue;
397+
}
398+
const config = this.getPackageConfig(depositInfo.setup_id);
391399

392400
logger.debug({
393401
msg: "Found matching nBTC deposit output",

packages/btcindexer/src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ export default {
5151
count: batch.messages.length,
5252
queue: batch.queue,
5353
});
54-
// TODO: Add support for active/inactive nBTC addresses.
55-
// The current implementation fetches all addresses, but we need to distinguish it,
56-
// probably a active (boolean) column in the table.
5754
const indexer = await indexerFromEnv(env);
5855
return processBlockBatch(batch, indexer);
5956
},

0 commit comments

Comments
 (0)