"use strict";
/**
 * Composes {@link makeWsErrorReporter} + decode-then-fire +
 * {@link AccountSubscriptionManager.subscribeProgramAccounts} for token /
 * reserve / obligation listeners.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.createManagerSubscription = createManagerSubscription;
const wsErrorReporter_1 = require("./wsErrorReporter");
function createManagerSubscription(opts) {
    const errorReporter = (0, wsErrorReporter_1.makeWsErrorReporter)(opts.errorPrefix, opts.onError);
    const subscribeOptions = {
        commitment: opts.commitment,
        onReconnect: opts.onReconnect,
        throttleMs: opts.throttleMs,
        scheduler: opts.scheduler,
    };
    return opts.manager.subscribeProgramAccounts(opts.programId, opts.filters, (address, buffer, slot) => {
        try {
            const event = opts.decode(address, buffer, slot);
            if (event !== undefined)
                opts.onChange(event);
        }
        catch (e) {
            errorReporter.reportError(e);
        }
    }, subscribeOptions);
}
//# sourceMappingURL=createManagerSubscription.js.map