"use strict";
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
Object.defineProperty(exports, "__esModule", { value: true });
const rxjs_1 = require("rxjs");
const operators_1 = require("rxjs/operators");
const util_1 = require("../util");
/**
 * @description Retrieve latest list of validators
 */
function validators(api) {
    return util_1.memo(() => 
    // Sadly the node-template is (for some obscure reason) not comprehensive, so while the derive works
    // in all actual real-world deployed chains, it does create some confusion for limited template chains
    // NOTE: Not doing multi queries here, since we have validators as a single in the derived newHead
    rxjs_1.combineLatest([
        api.query.session
            ? api.query.session.validators()
            : rxjs_1.of([]),
        api.query.staking
            ? api.query.staking.currentElected()
            : rxjs_1.of([])
    ]).pipe(operators_1.map(([validators, currentElected]) => ({
        currentElected, validators
    }))));
}
exports.validators = validators;
