import { saveDepths as e } from "../../../constants/save-depths.mjs";
import { AbstractEventService as t } from "./AbstractEventService.mjs";
//#region libs/shared/common/src/data-structures/event-service/evm/AbstractSnapshotService.ts
var n = class extends t {
	savedLatestBlockNumber = 0;
	constructor(e, t) {
		super(e, t);
	}
	async init() {
		await this.loadSnapshot();
	}
	async retrieveEventsFromLatestBlock() {
		await this.blockchainEventEmitter.retrieveEvents(this.latestBlockNumber);
	}
	get isReady() {
		return this.blockchainEventEmitter.isReady;
	}
	async loadSnapshot() {
		let e = await this.fetchSnapshot(), t = this.deserializeSnapshot(e);
		this.populateSnapshot(t), this.blockchainEventEmitter.syncFromAtMost(t.latestBlockNumber), this.savedLatestBlockNumber = t.latestBlockNumber;
	}
	saveSnapshot() {
		return this.savedLatestBlockNumber = this.latestBlockNumber, this.persistSnapshot(this.serializeSnapshot({
			latestBlockNumber: this.latestBlockNumber,
			payload: this.getSnapshotPayload()
		}));
	}
	async afterEventsAccepted(t) {
		(t > 0 || this.savedLatestBlockNumber + e[this.chainId] < this.latestBlockNumber) && await this.saveSnapshot();
	}
};
//#endregion
export { n as AbstractSnapshotService };
