Skip to content

Commit

Permalink
feat(bridge): prepare libplanet sloth update
Browse files Browse the repository at this point in the history
  • Loading branch information
moreal committed May 30, 2024
1 parent 2303299 commit 63d70ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -14,7 +14,7 @@ export class NineChroniclesTransferredEventMonitor extends TriggerableMonitor<NC
headlessGraphQLClient: IHeadlessGraphQLClient,
address: string
) {
super(latestTransactionLocation);
super(latestTransactionLocation, DefaultDelayMilliseconds, 1);

this._headlessGraphQLClient = headlessGraphQLClient;
this._address = address;
Expand Down
9 changes: 7 additions & 2 deletions bridge/src/monitors/triggerable-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,27 @@ type RemainedEvent<TEventData> = {
events: (TEventData & TransactionLocation)[];
};

export const DefaultDelayMilliseconds = 15 * 1000;

export abstract class TriggerableMonitor<TEventData> extends Monitor<
TEventData & TransactionLocation
> {
private latestBlockNumber: number | undefined;

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<{
Expand All @@ -62,7 +67,7 @@ export abstract class TriggerableMonitor<TEventData> 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
);
Expand Down

0 comments on commit 63d70ee

Please sign in to comment.