"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 types_1 = require("../../types");
const util_1 = require("../util");
// query via constants (current applicable path)
function queryConstants(api) {
    return rxjs_1.of([
        // deprecated
        api.consts.contracts.creationFee || types_1.createType(api.registry, 'Balance'),
        api.consts.contracts.transferFee || types_1.createType(api.registry, 'Balance'),
        // current
        api.consts.contracts.callBaseFee,
        api.consts.contracts.contractFee,
        api.consts.contracts.rentByteFee,
        api.consts.contracts.rentDepositOffset,
        api.consts.contracts.tombstoneDeposit,
        api.consts.contracts.transactionBaseFee,
        api.consts.contracts.transactionByteFee
    ]);
}
/**
 * @name fees
 * @returns An object containing the combined results of the queries for
 * all relevant contract fees as declared in the substrate chain spec.
 * @example
 * <BR>
 *
 * ```javascript
 * api.derive.contracts.fees(([creationFee, transferFee]) => {
 *   console.log(`The fee for creating a new contract on this chain is ${creationFee} units. The fee required to call this contract is ${transferFee} units.`);
 * });
 * ```
 */
function fees(api) {
    return util_1.memo(() => {
        return queryConstants(api).pipe(operators_1.map(([creationFee, transferFee, callBaseFee, contractFee, rentByteFee, rentDepositOffset, tombstoneDeposit, transactionBaseFee, transactionByteFee]) => ({
            callBaseFee,
            contractFee,
            creationFee,
            rentByteFee,
            rentDepositOffset,
            tombstoneDeposit,
            transactionBaseFee,
            transactionByteFee,
            transferFee
        })));
    });
}
exports.fees = fees;
