From 63d70eee6c116eec57852364502b75a3b3ddc5bb Mon Sep 17 00:00:00 2001 From: moreal Date: Thu, 30 May 2024 14:35:28 +0900 Subject: [PATCH] feat(bridge): prepare libplanet sloth update --- .../nine-chronicles-transferred-event-monitor.ts | 4 ++-- bridge/src/monitors/triggerable-monitor.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bridge/src/monitors/nine-chronicles-transferred-event-monitor.ts b/bridge/src/monitors/nine-chronicles-transferred-event-monitor.ts index bbc23f2..c1aa4b0 100644 --- a/bridge/src/monitors/nine-chronicles-transferred-event-monitor.ts +++ b/bridge/src/monitors/nine-chronicles-transferred-event-monitor.ts @@ -1,4 +1,4 @@ -import { TriggerableMonitor } from "./triggerable-monitor"; +import { DefaultDelayMilliseconds, TriggerableMonitor } from "./triggerable-monitor"; import { IHeadlessGraphQLClient } from "../interfaces/headless-graphql-client"; import { NCGTransferredEvent } from "../types/ncg-transferred-event"; import { TransactionLocation } from "../types/transaction-location"; @@ -14,7 +14,7 @@ export class NineChroniclesTransferredEventMonitor extends TriggerableMonitor = { events: (TEventData & TransactionLocation)[]; }; +export const DefaultDelayMilliseconds = 15 * 1000; + export abstract class TriggerableMonitor extends Monitor< TEventData & TransactionLocation > { @@ -27,15 +29,18 @@ export abstract class TriggerableMonitor extends Monitor< private readonly _latestTransactionLocation: TransactionLocation | null; private readonly _delayMilliseconds: number; + private readonly _intervalWithTipIndex: number; constructor( latestTransactionLocation: TransactionLocation | null, - delayMilliseconds: number = 15 * 1000 + delayMilliseconds: number = DefaultDelayMilliseconds, + intervalWithTipIndex = 0 ) { super(); this._latestTransactionLocation = latestTransactionLocation; this._delayMilliseconds = delayMilliseconds; + this._intervalWithTipIndex = intervalWithTipIndex; } async *loop(): AsyncIterableIterator<{ @@ -62,7 +67,7 @@ export abstract class TriggerableMonitor extends Monitor< "Try to check trigger at", this.latestBlockNumber + 1 ); - if (this.latestBlockNumber + 1 <= tipIndex) { + if (this.latestBlockNumber + 1 + this._intervalWithTipIndex <= tipIndex) { const trigerredBlockIndexes = this.triggerredBlocks( this.latestBlockNumber + 1 );