Skip to content

Commit

Permalink
Merge pull request #72 from sotatek-dev/fix/crawler
Browse files Browse the repository at this point in the history
fix: duplicate events
  • Loading branch information
Sotatek-TanHoang authored Sep 24, 2024
2 parents d2c403a + 6d99492 commit e8273ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/modules/crawler/crawler.evmbridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export class BlockchainEVMCrawler {
}

public async handlerLockEvent(event: EventData, queryRunner: QueryRunner) {
const isExist = await queryRunner.manager.findOneBy(EventLog, { txHashLock: event.transactionHash });
if (isExist) {
this.logger.warn('Duplicated event', event.transactionHash);
}
const blockTimeOfBlockNumber = await this.ethBridgeContract.getBlockTimeByBlockNumber(event.blockNumber);
const eventUnlock = {
senderAddress: event.returnValues.locker,
Expand Down
8 changes: 7 additions & 1 deletion src/modules/crawler/crawler.minabridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,14 @@ export class SCBridgeMinaCrawler {
}

public async handlerLockEvent(event: any, queryRunner: QueryRunner) {
const txHashLock = event.event.transactionInfo.transactionHash;
const field = Field.from(event.event.data.receipt.toString());
const receiveAddress = DEFAULT_ADDRESS_PREFIX + field.toBigInt().toString(16);

const isExist = await queryRunner.manager.findOneBy(EventLog, { txHashLock });
if (isExist) {
this.logger.warn('Duplicated event', txHashLock);
}
const eventUnlock = {
senderAddress: JSON.parse(JSON.stringify(event.event.data.locker)),
amountFrom: event.event.data.amount.toString(),
Expand All @@ -105,7 +111,7 @@ export class SCBridgeMinaCrawler {
networkReceived: ENetworkName.ETH,
tokenFromName: EAsset.WETH,
tokenReceivedAddress: this.configService.get(EEnvKey.ETH_TOKEN_BRIDGE_ADDRESS),
txHashLock: event.event.transactionInfo.transactionHash,
txHashLock,
receiveAddress: receiveAddress,
blockNumber: event.blockHeight.toString(),
blockTimeLock: Number(Math.floor(dayjs().valueOf() / 1000)),
Expand Down

0 comments on commit e8273ab

Please sign in to comment.