"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const OneTimePromise_1 = require("../util/OneTimePromise");
const log_1 = require("../log/log");
class ValidationContext {
    constructor(api, delegator, voter, voteorder) {
        this.postLoader = new OneTimePromise_1.OneTimePromise(10 * 1000);
        this.dgpLoader = new OneTimePromise_1.OneTimePromise(10 * 1000);
        this.accountInfoLoaders = [];
        this.api = api;
        this.delegator = delegator;
        this.voter = voter;
        this.voteorder = voteorder;
        log_1.Log.log().cheapDebug(() => "ValidationContext.construct(delegator=" + delegator + ", voter=" + voter + ", voteorder=" + JSON.stringify(voteorder, undefined, 2));
    }
    getPost() {
        return this.postLoader.execute(() => this.api.loadPost(this.voteorder.author, this.voteorder.permlink));
    }
    getDynamicGlobalProperties() {
        return this.dgpLoader.execute(() => this.api.getDynamicGlobalProperties());
    }
    getAccountInfo(username) {
        for (let i = 0; i < this.accountInfoLoaders.length; i++) {
            const loaderTuple = this.accountInfoLoaders[i];
            if (loaderTuple[0] === username) {
                return loaderTuple[1].execute(() => this.api.getAccountInfo(username));
            }
        }
        const loader = new OneTimePromise_1.OneTimePromise(10 * 1000);
        this.accountInfoLoaders.push([username, loader]);
        return loader.execute(() => this.api.getAccountInfo(username));
    }
    getDelegatorUsername() {
        return this.delegator;
    }
    getVoterUsername() {
        return this.voter;
    }
    /**
     * Returns WISE operations related to given username that are newer than until.
     * @param username - steem username
     * @param until - the oldest date to search for operations.
     */
    getWiseOperations(username, until) {
        return this.api.getWiseOperations(username, until);
    }
    /**
     * Returns last user blog entries from follow_api. They are sorted from the newest to the oldest,
     * trimmed to the limit.
     * @param username - steem username
     * @param startFrom - number of the entry to start from counting from the newest to the oldest
     *      (startFrom=0 will return the newest entry)
     * @param limit - limit the number of returned entries (maximal limit is 500).
     */
    getBlogEntries(username, startFrom, limit) {
        return this.api.getBlogEntries(username, startFrom, limit);
    }
}
exports.ValidationContext = ValidationContext;
//# sourceMappingURL=ValidationContext.js.map