"use strict";
// Copyright 2017-2020 @polkadot/types 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 polkadot_1 = __importDefault(require("./polkadot"));
const substrate_1 = __importDefault(require("./substrate"));
// A mapping of the known signed extensions to the extra fields that they contain. Unlike in the actual extensions,
// we define the extra fields not as a Tuple, but rather as a struct so they can be named. These will be expanded
// into the various fields when added to the payload (we only support V4 onwards with these, V3 and earlier are
// deemded fixed and non-changeable)
const allExtensions = Object.assign(Object.assign({}, substrate_1.default), polkadot_1.default);
exports.allExtensions = allExtensions;
// the v4 signed extensions (the order is important here, as applied by default)
const defaultExtensions = [
    'CheckVersion',
    'CheckGenesis',
    'CheckEra',
    'CheckNonce',
    'CheckWeight',
    'ChargeTransactionPayment',
    'CheckBlockGasLimit'
];
exports.defaultExtensions = defaultExtensions;
function findUnknownExtensions(extensions) {
    const names = Object.keys(allExtensions);
    return extensions.filter((key) => !names.includes(key));
}
exports.findUnknownExtensions = findUnknownExtensions;
function expandExtensionTypes(extensions, type) {
    return extensions
        .map((key) => allExtensions[key])
        .filter((info) => !!info)
        .reduce((result, info) => (Object.assign(Object.assign({}, result), info[type])), {});
}
exports.expandExtensionTypes = expandExtensionTypes;
