"use strict";
// Copyright 2017-2020 @polkadot/api authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const logging_1 = __importDefault(require("./logging"));
function filterEvents(extHash, { block: { extrinsics, header } }, allEvents) {
    // extrinsics to hashes
    const myHash = extHash.toHex();
    const allHashes = extrinsics.map((ext) => ext.hash.toHex());
    // find the index of our extrinsic in the block
    const index = allHashes.indexOf(myHash);
    // if we do get the block after finalized, it _should_ be there
    if (index === -1) {
        logging_1.default.warn(`block ${header.hash}: Unable to find extrinsic ${myHash} inside ${allHashes}`);
        return;
    }
    return allEvents.filter(({ phase }) => 
    // only ApplyExtrinsic has the extrinsic index
    phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(index));
}
exports.default = filterEvents;
