"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.voters = voters;

var _operators = require("rxjs/operators");

var _types = require("@polkadot/types");

var _drr = require("../util/drr");

var _voterPositions = require("./voterPositions");

// Copyright 2017-2019 @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.

/**
 * @name voters
 * @returns An array of all current voters from all sets.
 * @example
 * <BR>
 *
 * ```javascript
 * api.derive.elections.voters((voters) => {
 *   console.log(`There are ${voters.length} current voters.`);
 * });
 * ```
 */
function voters(api) {
  return () => (0, _voterPositions.voterPositions)(api)().pipe((0, _operators.map)(voterPositions => (0, _types.createType)('Vec<AccountId>', Object.entries(voterPositions).sort((a, b) => a[1].globalIndex.cmp(b[1].globalIndex)).map((_ref) => {
    let [accountId] = _ref;
    return (0, _types.createType)('AccountId', accountId);
  }))), (0, _drr.drr)());
}