import { API as e } from "../../../API/API.mjs";
import { Logger as t } from "../../../error-handling/logger.mjs";
import { BlockchainEvent as n } from "../../BlockchainEvent/BlockchainEvent.mjs";
//#region libs/shared/common/src/data-structures/event-service/helpers/ClientEventHelper.ts
var r = 5e3, i = class {
	chainId;
	eventCategory;
	pollIntervalId;
	constructor(e, t) {
		this.chainId = e, this.eventCategory = t;
	}
	clear() {
		this.pollIntervalId != null && (clearInterval(this.pollIntervalId), this.pollIntervalId = void 0);
	}
	startUpdateListener(i, a, o) {
		let s = a, c = async () => {
			try {
				let { events: t, latestBlockNumber: r } = await e.getSnapshotServerEvents(this.chainId, this.eventCategory, s);
				t.length > 0 && await i(t.map((e) => n.fromSerialized(e))), r >= s && (s = r + 1, o(s));
			} catch (e) {
				t.error("Snapshot events poll error", e);
			}
		};
		this.pollIntervalId = setInterval(c, r);
	}
};
//#endregion
export { i as ClientEventHelper };
