"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AddressList = void 0;
const promises_1 = require("node:fs/promises");
const superstruct_1 = require("superstruct");
const abstract_1 = require("./abstract");
const fileConfig = (0, superstruct_1.defaulted)((0, superstruct_1.array)((0, superstruct_1.string)()), []);
class AddressList extends abstract_1.AbstractAdapter {
    constructor(opts) {
        const { path = "addresses.json" } = opts ?? {};
        super(opts?.name ?? `fs:${path}`, path, opts);
    }
    async update() {
        let data;
        try {
            data = await (0, promises_1.readFile)(this.path, { encoding: "utf8" });
        }
        catch (err) {
            return this.error(err);
        }
        if (!data) {
            return this.error("No addresses found");
        }
        let addresses;
        try {
            addresses = JSON.parse(data);
            if (!fileConfig.is(addresses)) {
                return this.error("Address format validation failure.");
            }
        }
        catch (err) {
            return this.error(err);
        }
        return Promise.resolve(addresses);
    }
}
exports.AddressList = AddressList;
//# sourceMappingURL=file.js.map