import Utils from "./utils.js";
import { withdrawBalance } from "./withdrawal.js";
import buildBundlrTransaction from "./transaction.js";
export default class Bundlr {
    api;
    utils;
    uploader;
    funder;
    address;
    currency;
    currencyConfig;
    _readyPromise;
    url;
    arbundles;
    bundlrTransaction;
    static VERSION = "0.11.16";
    constructor(url, arbundles) {
        this.url = url;
        this.arbundles = arbundles;
        this.bundlrTransaction = buildBundlrTransaction(this);
    }
    get signer() {
        return this.currencyConfig.getSigner();
    }
    async withdrawBalance(amount) {
        return withdrawBalance(this.utils, this.api, amount);
    }
    /**
     * Gets the balance for the loaded wallet
     * @returns balance (in winston)
     */
    async getLoadedBalance() {
        if (!this.address)
            throw new Error("address is undefined");
        return this.utils.getBalance(this.address);
    }
    /**
     * Gets the balance for the specified address
     * @param address address to query for
     * @returns the balance (in winston)
     */
    async getBalance(address) {
        return this.utils.getBalance(address);
    }
    /**
     * Sends amount atomic units to the specified bundler
     * @param amount amount to send in atomic units
     * @returns details about the fund transaction
     */
    async fund(amount, multiplier) {
        return this.funder.fund(amount, multiplier);
    }
    /**
     * Calculates the price for [bytes] bytes for the loaded currency and Bundlr node.
     * @param bytes
     * @returns
     */
    async getPrice(bytes) {
        return this.utils.getPrice(this.currency, bytes);
    }
    async verifyReceipt(receipt) {
        return Utils.verifyReceipt(this.arbundles, receipt);
    }
    /**
     * Create a new BundlrTransactions (flex currency arbundles dataItem)
     * @param data
     * @param opts - dataItemCreateOptions
     * @returns - a new BundlrTransaction instance
     */
    createTransaction(data, opts) {
        return new this.bundlrTransaction(data, this, opts);
    }
    /**
     * Returns the signer for the loaded currency
     */
    getSigner() {
        return this.currencyConfig.getSigner();
    }
    async upload(data, opts) {
        return this.uploader.uploadData(data, opts);
    }
    async uploadWithReceipt(data, opts) {
        return this.uploader.uploadData(data, { ...opts, upload: { getReceiptSignature: true } });
    }
    async ready() {
        this.currencyConfig.ready ? await this.currencyConfig.ready() : true;
        this.address = this.currencyConfig.address;
    }
    // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
    get transaction() {
        // eslint-disable-next-line @typescript-eslint/no-this-alias
        const oThis = this;
        return {
            fromRaw(rawTransaction) {
                return new oThis.bundlrTransaction(rawTransaction, oThis, { dataIsRawTransaction: true });
            },
        };
    }
}
//# sourceMappingURL=bundlr.js.map