"use strict";
// Copyright 2021-2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.Client = void 0;
const client_method_handler_1 = require("./client-method-handler");
const client_1 = require("../types/client");
const block_1 = require("../types/block");
const types_1 = require("../types");
const api_1 = require("../types/models/api");
const class_transformer_1 = require("class-transformer");
/** The Client to interact with nodes. */
class Client {
    /**
     * @param options client options or a client method handler.
     */
    constructor(options) {
        this.methodHandler = new client_method_handler_1.ClientMethodHandler(options);
    }
    async destroy() {
        return this.methodHandler.destroy();
    }
    /**
     * Get the node information together with the url of the used node.
     */
    async getInfo() {
        const response = await this.methodHandler.callMethod({
            name: 'getInfo',
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get network related information such as protocol parameters and minimum pow score.
     */
    async getNetworkInfo() {
        const response = await this.methodHandler.callMethod({
            name: 'getNetworkInfo',
        });
        return JSON.parse(response).payload;
    }
    /**
     * Fetch basic output IDs based on the given query parameters.
     */
    async basicOutputIds(queryParameters) {
        const response = await this.methodHandler.callMethod({
            name: 'basicOutputIds',
            data: {
                queryParameters,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get output from a given output ID.
     */
    async getOutput(outputId) {
        const response = await this.methodHandler.callMethod({
            name: 'getOutput',
            data: {
                outputId,
            },
        });
        const parsed = JSON.parse(response);
        return (0, class_transformer_1.plainToInstance)(api_1.OutputResponse, parsed.payload);
    }
    /**
     * Fetch OutputResponse from given output IDs. Requests are sent in parallel.
     */
    async getOutputs(outputIds) {
        const response = await this.methodHandler.callMethod({
            name: 'getOutputs',
            data: {
                outputIds,
            },
        });
        const parsed = JSON.parse(response);
        return (0, class_transformer_1.plainToInstance)(api_1.OutputResponse, parsed.payload);
    }
    /**
     * Build and post a block.
     *
     * @param secretManager One of the supported secret managers.
     * @param options Options on how to build a block.
     * @returns The block ID and the posted block itself.
     */
    async buildAndPostBlock(secretManager, options) {
        if (options &&
            options.output &&
            typeof options.output.amount === 'bigint') {
            options.output.amount = options.output.amount.toString(10);
        }
        if (options &&
            options.outputHex &&
            typeof options.outputHex.amount === 'bigint') {
            options.outputHex.amount = options.outputHex.amount.toString(10);
        }
        const response = await this.methodHandler.callMethod({
            name: 'buildAndPostBlock',
            data: {
                secretManager,
                options,
            },
        });
        const parsed = JSON.parse(response);
        const block = (0, class_transformer_1.plainToInstance)(block_1.Block, parsed.payload[1]);
        return [parsed.payload[0], block];
    }
    /**
     * Request tips from the node.
     * The tips can be considered as non-lazy and are therefore ideal for attaching a block to the Tangle.
     * @returns An array of tips represented by their block IDs.
     */
    async getTips() {
        const response = await this.methodHandler.callMethod({
            name: 'getTips',
        });
        return JSON.parse(response).payload;
    }
    /**
     * Post a block in JSON format.
     *
     * @param block The block to post.
     * @returns The block ID once the block has been posted.
     */
    async postBlock(block) {
        const response = await this.methodHandler.callMethod({
            name: 'postBlock',
            data: {
                block,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get a block in JSON format.
     *
     * @param blockId The corresponding block ID of the requested block.
     * @returns The requested block.
     */
    async getBlock(blockId) {
        const response = await this.methodHandler.callMethod({
            name: 'getBlock',
            data: {
                blockId,
            },
        });
        const parsed = JSON.parse(response);
        return (0, class_transformer_1.plainToInstance)(block_1.Block, parsed.payload);
    }
    /**
     * Get the metadata of a block.
     *
     * @param blockId The corresponding block ID of the requested block metadata.
     * @returns The requested block metadata.
     */
    async getBlockMetadata(blockId) {
        const response = await this.methodHandler.callMethod({
            name: 'getBlockMetadata',
            data: {
                blockId,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Find inputs from addresses for a given amount (useful for offline signing).
     *
     * @param addresses A list of included addresses.
     * @param amount The amount to find inputs for.
     * @returns An array of UTXO inputs.
     */
    async findInputs(addresses, amount) {
        const response = await this.methodHandler.callMethod({
            name: 'findInputs',
            data: {
                addresses,
                amount: Number(amount),
            },
        });
        const parsed = JSON.parse(response);
        return (0, class_transformer_1.plainToInstance)(types_1.UTXOInput, parsed.payload);
    }
    /**
     * Prepare a transaction for signing.
     *
     * @param secretManager One of the supported secret managers.
     * @param options Options to build a block.
     * @returns An instance of `PreparedTransactionData`.
     */
    async prepareTransaction(secretManager, options) {
        const response = await this.methodHandler.callMethod({
            name: 'prepareTransaction',
            data: {
                secretManager,
                options,
            },
        });
        const parsed = JSON.parse(response);
        return (0, class_transformer_1.plainToInstance)(client_1.PreparedTransactionData, parsed.payload);
    }
    /**
     * Sign a transaction.
     *
     * @param secretManager One of the supported secret managers.
     * @param preparedTransactionData An instance of `PreparedTransactionData`.
     * @returns The corresponding transaction payload.
     */
    async signTransaction(secretManager, preparedTransactionData) {
        const response = await this.methodHandler.callMethod({
            name: 'signTransaction',
            data: {
                secretManager,
                preparedTransactionData,
            },
        });
        const parsed = JSON.parse(response);
        return (0, class_transformer_1.plainToInstance)(block_1.TransactionPayload, parsed.payload);
    }
    /**
     * Create a signature unlock using the given secret manager.
     *
     * @param secretManager One of the supported secret managers.
     * @param transactionEssenceHash The hash of the transaction essence.
     * @param chain A BIP44 chain
     * @returns The corresponding unlock condition.
     */
    async signatureUnlock(secretManager, transactionEssenceHash, chain) {
        const response = await this.methodHandler.callMethod({
            name: 'signatureUnlock',
            data: {
                secretManager,
                transactionEssenceHash,
                chain,
            },
        });
        return block_1.UnlockCondition.parse(JSON.parse(response).payload);
    }
    /**
     * Submit a payload in a block.
     *
     * @param payload The payload to post.
     * @returns The block ID followed by the block containing the payload.
     */
    async postBlockPayload(payload) {
        const response = await this.methodHandler.callMethod({
            name: 'postBlockPayload',
            data: {
                payload,
            },
        });
        const parsed = JSON.parse(response);
        const block = (0, class_transformer_1.plainToInstance)(block_1.Block, parsed.payload[1]);
        return [parsed.payload[0], block];
    }
    /**
     * Get a node candidate from the healthy node pool.
     */
    async getNode() {
        const response = await this.methodHandler.callMethod({
            name: 'getNode',
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get the ID of the network the node is connected to.
     */
    async getNetworkId() {
        const response = await this.methodHandler.callMethod({
            name: 'getNetworkId',
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get the Bech32 HRP (human readable part) of the network the node is connected to.
     */
    async getBech32Hrp() {
        const response = await this.methodHandler.callMethod({
            name: 'getBech32Hrp',
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get the minimum PoW score.
     */
    async getMinPowScore() {
        const response = await this.methodHandler.callMethod({
            name: 'getMinPowScore',
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get the tips interval.
     */
    async getTipsInterval() {
        const response = await this.methodHandler.callMethod({
            name: 'getTipsInterval',
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get the token supply.
     */
    async getTokenSupply() {
        return (await this.getProtocolParameters()).tokenSupply;
    }
    /**
     * Get the protocol parameters.
     */
    async getProtocolParameters() {
        const response = await this.methodHandler.callMethod({
            name: 'getProtocolParameters',
        });
        return JSON.parse(response).payload;
    }
    /**
     * Check whether local pow should be used or not.
     */
    async getLocalPow() {
        const response = await this.methodHandler.callMethod({
            name: 'getLocalPow',
        });
        return JSON.parse(response).payload;
    }
    /**
     * Check whether to fallback to local proof of work in case the node doesn't support remote PoW.
     */
    async getFallbackToLocalPow() {
        const response = await this.methodHandler.callMethod({
            name: 'getFallbackToLocalPow',
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get the health of a node.
     *
     * @param url The URL of the node.
     */
    async getHealth(url) {
        const response = await this.methodHandler.callMethod({
            name: 'getHealth',
            data: {
                url,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get the info about the node.
     *
     * @param url The URL of the node.
     * @param auth An authentication object (e.g. JWT).
     */
    async getNodeInfo(url, auth) {
        const response = await this.methodHandler.callMethod({
            name: 'getNodeInfo',
            data: {
                url,
                auth,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get the peers of the node.
     */
    async getPeers() {
        const response = await this.methodHandler.callMethod({
            name: 'getPeers',
        });
        return JSON.parse(response).payload;
    }
    /**
     * Post block as raw bytes, returns the block ID.
     *
     * @param block The block.
     * @returns The ID of the posted block.
     */
    async postBlockRaw(block) {
        const response = await this.methodHandler.callMethod({
            name: 'postBlockRaw',
            data: {
                block,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get block as raw bytes.
     *
     * @param blockId The block ID of the requested block.
     * @returns The raw bytes of the requested block.
     */
    async getBlockRaw(blockId) {
        const response = await this.methodHandler.callMethod({
            name: 'getBlockRaw',
            data: {
                blockId,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get a milestone payload by its ID.
     *
     * @param milestoneId The ID of the requested milestone.
     * @returns The corresponding milestone payload.
     */
    async getMilestoneById(milestoneId) {
        const response = await this.methodHandler.callMethod({
            name: 'getMilestoneById',
            data: {
                milestoneId,
            },
        });
        const parsed = JSON.parse(response);
        return (0, class_transformer_1.plainToInstance)(block_1.MilestonePayload, parsed.payload);
    }
    /**
     * Get all UTXO changes of a milestone by its ID.
     *
     * @param milestoneId The ID of the milestone that applied the UTXO changes.
     * @returns A milestone UTXO changes response.
     */
    async getUtxoChangesById(milestoneId) {
        const response = await this.methodHandler.callMethod({
            name: 'getUtxoChangesById',
            data: {
                milestoneId,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get a milestone payload by its index.
     *
     * @param index The index of the requested milestone.
     * @returns The corresponding milestone payload.
     */
    async getMilestoneByIndex(index) {
        const response = await this.methodHandler.callMethod({
            name: 'getMilestoneByIndex',
            data: {
                index,
            },
        });
        const parsed = JSON.parse(response);
        return (0, class_transformer_1.plainToInstance)(block_1.MilestonePayload, parsed.payload);
    }
    /**
     * Get all UTXO changes of a milestone by its index.
     *
     * @param index The index of the milestone that applied the UTXO changes.
     * @returns A milestone UTXO changes response.
     */
    async getUtxoChangesByIndex(index) {
        const response = await this.methodHandler.callMethod({
            name: 'getUtxoChangesByIndex',
            data: {
                index,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get all receipts.
     */
    async getReceipts() {
        const response = await this.methodHandler.callMethod({
            name: 'getReceipts',
        });
        const parsed = JSON.parse(response);
        return (0, class_transformer_1.plainToInstance)(api_1.ReceiptsResponse, parsed.payload);
    }
    /**
     * Get the receipts at a given milestone index.
     *
     * @param milestoneIndex The index of the milestone that migrated funds to the new network.
     */
    async getReceiptsMigratedAt(milestoneIndex) {
        const response = await this.methodHandler.callMethod({
            name: 'getReceiptsMigratedAt',
            data: {
                milestoneIndex,
            },
        });
        const parsed = JSON.parse(response);
        return (0, class_transformer_1.plainToInstance)(api_1.ReceiptsResponse, parsed.payload);
    }
    /**
     * Get the treasury output.
     */
    async getTreasury() {
        const response = await this.methodHandler.callMethod({
            name: 'getTreasury',
        });
        return block_1.Output.parse(JSON.parse(response).payload);
    }
    /**
     * Get the included block of a given transaction.
     *
     * @param transactionId The ID of the transaction.
     * @returns The included block that contained the transaction.
     */
    async getIncludedBlock(transactionId) {
        const response = await this.methodHandler.callMethod({
            name: 'getIncludedBlock',
            data: {
                transactionId,
            },
        });
        const parsed = JSON.parse(response);
        return (0, class_transformer_1.plainToInstance)(block_1.Block, parsed.payload);
    }
    /**
     * Get the metadata of the included block of a given transaction.
     *
     * @param transactionId The ID of the transaction.
     * @returns The included block that contained the transaction.
     */
    async getIncludedBlockMetadata(transactionId) {
        const response = await this.methodHandler.callMethod({
            name: 'getIncludedBlockMetadata',
            data: {
                transactionId,
            },
        });
        const parsed = JSON.parse(response);
        return (0, class_transformer_1.plainToInstance)(block_1.Block, parsed.payload);
    }
    /**
     * Convert a hex encoded address to a Bech32 encoded address.
     *
     * @param hex The hexadecimal string representation of an address.
     * @param bech32Hrp The Bech32 HRP (human readable part) to be used.
     * @returns The corresponding Bech32 address.
     */
    async hexToBech32(hex, bech32Hrp) {
        const response = await this.methodHandler.callMethod({
            name: 'hexToBech32',
            data: {
                hex,
                bech32Hrp,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Convert an Alias ID to a Bech32 encoded address.
     *
     * @param aliasId An Alias ID.
     * @param bech32Hrp The Bech32 HRP (human readable part) to be used.
     * @returns The corresponding Bech32 address.
     */
    async aliasIdToBech32(aliasId, bech32Hrp) {
        const response = await this.methodHandler.callMethod({
            name: 'aliasIdToBech32',
            data: {
                aliasId,
                bech32Hrp,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Convert an NFT ID to a Bech32 encoded address.
     *
     * @param nftId An NFT ID.
     * @param bech32Hrp The Bech32 HRP (human readable part) to be used.
     * @returns The corresponding Bech32 address.
     */
    async nftIdToBech32(nftId, bech32Hrp) {
        const response = await this.methodHandler.callMethod({
            name: 'nftIdToBech32',
            data: {
                nftId,
                bech32Hrp,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Convert a hex encoded public key to a Bech32 encoded address.
     *
     * @param hex The hexadecimal string representation of a public key.
     * @param bech32Hrp The Bech32 HRP (human readable part) to be used.
     * @returns The corresponding Bech32 address.
     */
    async hexPublicKeyToBech32Address(hex, bech32Hrp) {
        const response = await this.methodHandler.callMethod({
            name: 'hexPublicKeyToBech32Address',
            data: {
                hex,
                bech32Hrp,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get the corresponding output IDs given a list of Alias query parameters.
     *
     * @param queryParameters An array of `AliasQueryParameter`s.
     * @returns A paginated query response of corresponding output IDs.
     */
    async aliasOutputIds(queryParameters) {
        const response = await this.methodHandler.callMethod({
            name: 'aliasOutputIds',
            data: {
                queryParameters,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get the corresponding output ID from an Alias ID.
     *
     * @param aliasId An Alias ID.
     * @returns The corresponding output ID.
     */
    async aliasOutputId(aliasId) {
        const response = await this.methodHandler.callMethod({
            name: 'aliasOutputId',
            data: {
                aliasId,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get the corresponding output IDs given a list of NFT query parameters.
     *
     * @param queryParameters An array of `NftQueryParameter`s.
     * @returns A paginated query response of corresponding output IDs.
     */
    async nftOutputIds(queryParameters) {
        const response = await this.methodHandler.callMethod({
            name: 'nftOutputIds',
            data: {
                queryParameters,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get the corresponding output ID from an NFT ID.
     *
     * @param nftId An NFT ID.
     * @returns The corresponding output ID.
     */
    async nftOutputId(nftId) {
        const response = await this.methodHandler.callMethod({
            name: 'nftOutputId',
            data: {
                nftId,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get the corresponding output IDs given a list of Foundry query parameters.
     *
     * @param queryParameters An array of `FoundryQueryParameter`s.
     * @returns A paginated query response of corresponding output IDs.
     */
    async foundryOutputIds(queryParameters) {
        const response = await this.methodHandler.callMethod({
            name: 'foundryOutputIds',
            data: {
                queryParameters,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get the corresponding output ID from a Foundry ID.
     *
     * @param foundryId A Foundry ID.
     * @returns The corresponding output ID.
     */
    async foundryOutputId(foundryId) {
        const response = await this.methodHandler.callMethod({
            name: 'foundryOutputId',
            data: {
                foundryId,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Get outputs from provided output IDs (requests are sent
     * in parallel and errors are ignored, can be useful for spent outputs)
     *
     * @param outputIds An array of output IDs.
     * @returns An array of corresponding output responses.
     */
    async getOutputsIgnoreErrors(outputIds) {
        const response = await this.methodHandler.callMethod({
            name: 'getOutputsIgnoreErrors',
            data: {
                outputIds,
            },
        });
        const parsed = JSON.parse(response);
        return (0, class_transformer_1.plainToInstance)(api_1.OutputResponse, parsed.payload);
    }
    /**
     * Find blocks by their IDs.
     *
     * @param blockIds An array of `BlockId`s.
     * @returns An array of corresponding blocks.
     */
    async findBlocks(blockIds) {
        const response = await this.methodHandler.callMethod({
            name: 'findBlocks',
            data: {
                blockIds,
            },
        });
        const parsed = JSON.parse(response);
        return (0, class_transformer_1.plainToInstance)(block_1.Block, parsed.payload);
    }
    /**
     * Retry (promote or reattach) a block given its block ID.
     *
     * **Note**: Blocks should be retried only if they are valid and haven't been confirmed for some time.
     *
     * @param blockId The ID of the block to retry.
     * @returns The included block.
     */
    async retry(blockId) {
        const response = await this.methodHandler.callMethod({
            name: 'retry',
            data: {
                blockId,
            },
        });
        const parsed = JSON.parse(response);
        const block = (0, class_transformer_1.plainToInstance)(block_1.Block, parsed.payload[1]);
        return [parsed.payload[0], block];
    }
    /**
     * Retry (promote or reattach) a block given its block ID until it's included
     * (i.e. referenced by a milestone).
     *
     * @param blockId The ID of the block to retry.
     * @param interval A retry interval in seconds. Defaults to 5.
     * @param maxAttempts A maximum number of retries. Defaults to 40.
     * @returns The included block at first position and additional reattached blocks.
     */
    async retryUntilIncluded(blockId, interval, maxAttempts) {
        const response = await this.methodHandler.callMethod({
            name: 'retryUntilIncluded',
            data: {
                blockId,
                interval,
                maxAttempts,
            },
        });
        const parsed = JSON.parse(response);
        const arr = [];
        parsed.payload.forEach((payload) => {
            arr.push([payload[0], (0, class_transformer_1.plainToInstance)(block_1.Block, payload[1])]);
        });
        return arr;
    }
    /**
     * Consolidate all funds from a range of addresses to the address with the lowest index in that range.
     *
     * @param secretManager One of supported secret managers.
     * @param generateAddressesOptions Options for generating addresses.
     * @returns The address to which the funds got consolidated, if any were available.
     */
    async consolidateFunds(secretManager, generateAddressesOptions) {
        const response = await this.methodHandler.callMethod({
            name: 'consolidateFunds',
            data: {
                secretManager,
                generateAddressesOptions,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Reattach a block.
     *
     * **Note**: Blocks can be reattached only if they are valid and haven't been confirmed for some time.
     *
     * @param blockId The ID of the block to reattach.
     * @returns The included block.
     */
    async reattach(blockId) {
        const response = await this.methodHandler.callMethod({
            name: 'reattach',
            data: {
                blockId,
            },
        });
        const parsed = JSON.parse(response);
        const block = (0, class_transformer_1.plainToInstance)(block_1.Block, parsed.payload[1]);
        return [parsed.payload[0], block];
    }
    /**
     * Reattach a block without checking whether it should be reattached.
     *
     * @param blockId The ID of the block to reattach.
     * @returns The included block.
     */
    async reattachUnchecked(blockId) {
        const response = await this.methodHandler.callMethod({
            name: 'reattachUnchecked',
            data: {
                blockId,
            },
        });
        const parsed = JSON.parse(response);
        const block = (0, class_transformer_1.plainToInstance)(block_1.Block, parsed.payload[1]);
        return [parsed.payload[0], block];
    }
    /**
     * Promote a block.
     *
     * **NOTE**: The method validates whether a promotion is necessary through `get_block`. If not, the
     * method will error out and will not do unnecessary promotions.
     *
     * @param blockId The ID of the block to promote.
     * @returns The included block.
     */
    async promote(blockId) {
        const response = await this.methodHandler.callMethod({
            name: 'promote',
            data: {
                blockId,
            },
        });
        const parsed = JSON.parse(response);
        const block = (0, class_transformer_1.plainToInstance)(block_1.Block, parsed.payload[1]);
        return [parsed.payload[0], block];
    }
    /**
     * Promote a block without checking if it should be promoted.
     *
     * @param blockId The ID of the block to promote.
     * @returns The included block.
     */
    async promoteUnchecked(blockId) {
        const response = await this.methodHandler.callMethod({
            name: 'promoteUnchecked',
            data: {
                blockId,
            },
        });
        const parsed = JSON.parse(response);
        const block = (0, class_transformer_1.plainToInstance)(block_1.Block, parsed.payload[1]);
        return [parsed.payload[0], block];
    }
    /**
     * Return the unhealthy nodes.
     */
    async unhealthyNodes() {
        const response = await this.methodHandler.callMethod({
            name: 'unhealthyNodes',
        });
        return JSON.parse(response).payload;
    }
    /**
     * Build a basic output.
     *
     * @param params An instance of `BasicOutputBuilderParams`.
     */
    async buildBasicOutput(params) {
        if (params.amount && typeof params.amount === 'bigint') {
            params.amount = params.amount.toString(10);
        }
        const response = await this.methodHandler.callMethod({
            name: 'buildBasicOutput',
            data: params,
        });
        const parsed = JSON.parse(response);
        return (0, class_transformer_1.plainToInstance)(block_1.BasicOutput, parsed.payload);
    }
    /**
     * Build an alias output.
     *
     * @param params An instance of `AliasOutputBuilderParams`.
     */
    async buildAliasOutput(params) {
        if (params.amount && typeof params.amount === 'bigint') {
            params.amount = params.amount.toString(10);
        }
        const response = await this.methodHandler.callMethod({
            name: 'buildAliasOutput',
            data: params,
        });
        const parsed = JSON.parse(response);
        return (0, class_transformer_1.plainToInstance)(block_1.AliasOutput, parsed.payload);
    }
    /**
     * Build a foundry output.
     *
     * @param params An instance of `FoundryOutputBuilderParams`.
     */
    async buildFoundryOutput(params) {
        if (params.amount && typeof params.amount === 'bigint') {
            params.amount = params.amount.toString(10);
        }
        const response = await this.methodHandler.callMethod({
            name: 'buildFoundryOutput',
            data: params,
        });
        const parsed = JSON.parse(response);
        return (0, class_transformer_1.plainToInstance)(block_1.FoundryOutput, parsed.payload);
    }
    /**
     * Build an NFT output.
     *
     * @param params An instance of `NftOutputBuilderParams`.
     */
    async buildNftOutput(params) {
        if (params.amount && typeof params.amount === 'bigint') {
            params.amount = params.amount.toString(10);
        }
        const response = await this.methodHandler.callMethod({
            name: 'buildNftOutput',
            data: params,
        });
        const parsed = JSON.parse(response);
        return (0, class_transformer_1.plainToInstance)(block_1.NftOutput, parsed.payload);
    }
    /**
     * Listen to MQTT events.
     *
     * @param topics An array of MQTT topics to listen to.
     */
    async listenMqtt(topics, callback) {
        return this.methodHandler.listen(topics, callback);
    }
    /**
     * Stop listening to certain MQTT events.
     *
     * @param topics An array of MQTT topics to stop listening to.
     */
    async clearMqttListeners(topics) {
        await this.methodHandler.callMethod({
            name: 'clearListeners',
            data: {
                topics,
            },
        });
    }
    /**
     * Calculate the minimum required storage deposit for an output.
     *
     * @param output The output to calculate the minimum deposit amount for.
     * @returns The minimum required amount.
     */
    async minimumRequiredStorageDeposit(output) {
        const response = await this.methodHandler.callMethod({
            name: 'minimumRequiredStorageDeposit',
            data: {
                output,
            },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Request funds from a faucet.
     *
     * Example URLs: `https://faucet.testnet.shimmer.network/api/enqueue` or `http://localhost:8091/api/enqueue`.
     *
     * @param url The URL of the faucet.
     * @param address The address to send the funds to.
     * @returns The faucet response.
     */
    async requestFundsFromFaucet(url, address) {
        const response = await this.methodHandler.callMethod({
            name: 'requestFundsFromFaucet',
            data: { url, address },
        });
        return JSON.parse(response).payload;
    }
    /**
     * Extension method which provides request methods for plugins.
     *
     * @param basePluginPath The base path for the plugin eg indexer/v1/ .
     * @param method The http method.
     * @param endpoint The path for the plugin request.
     * @param queryParams Additional query params for the request.
     * @param request The request object.
     * @returns The response json.
     */
    async callPluginRoute(basePluginPath, method, endpoint, queryParams, request) {
        const response = await this.methodHandler.callMethod({
            name: 'callPluginRoute',
            data: {
                basePluginPath,
                method,
                endpoint,
                queryParams: queryParams ?? [],
                request,
            },
        });
        return JSON.parse(response).payload;
    }
}
exports.Client = Client;
//# sourceMappingURL=client.js.map