"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 type_1 = require("../type");
const util_1 = require("../util");
/**
 * @name subscribeNewHeads
 * @returns An array containing the block header and the block author
 * @description An observable of the current block header and it's author
 * @example
 * <BR>
 *
 * ```javascript
 * api.derive.chain.subscribeNewHeads((header) => {
 *   console.log(`block #${header.number} was authored by ${header.author}`);
 * });
 * ```
 */
function subscribeNewHeads(api) {
    return util_1.memo(() => rxjs_1.combineLatest([
        api.rpc.chain.subscribeNewHeads(),
        api.query.session
            ? api.query.session.validators()
            : rxjs_1.of([])
    ]).pipe(operators_1.map(([header, validators]) => new type_1.HeaderExtended(api.registry, header, validators))));
}
exports.subscribeNewHeads = subscribeNewHeads;
