"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = __importDefault(require("./utils"));
const withdrawal_1 = require("./withdrawal");
const transaction_1 = __importDefault(require("./transaction"));
class Bundlr {
    constructor(url, arbundles) {
        this.url = url;
        this.arbundles = arbundles;
        this.bundlrTransaction = (0, transaction_1.default)(this);
    }
    get signer() {
        return this.currencyConfig.getSigner();
    }
    withdrawBalance(amount) {
        return __awaiter(this, void 0, void 0, function* () {
            return (0, withdrawal_1.withdrawBalance)(this.utils, this.api, amount);
        });
    }
    /**
     * Gets the balance for the loaded wallet
     * @returns balance (in winston)
     */
    getLoadedBalance() {
        return __awaiter(this, void 0, void 0, function* () {
            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)
     */
    getBalance(address) {
        return __awaiter(this, void 0, void 0, function* () {
            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
     */
    fund(amount, multiplier) {
        return __awaiter(this, void 0, void 0, function* () {
            return this.funder.fund(amount, multiplier);
        });
    }
    /**
     * Calculates the price for [bytes] bytes for the loaded currency and Bundlr node.
     * @param bytes
     * @returns
     */
    getPrice(bytes) {
        return __awaiter(this, void 0, void 0, function* () {
            return this.utils.getPrice(this.currency, bytes);
        });
    }
    verifyReceipt(receipt) {
        return __awaiter(this, void 0, void 0, function* () {
            return utils_1.default.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();
    }
    upload(data, opts) {
        return __awaiter(this, void 0, void 0, function* () {
            return this.uploader.uploadData(data, opts);
        });
    }
    uploadWithReceipt(data, opts) {
        return __awaiter(this, void 0, void 0, function* () {
            return this.uploader.uploadData(data, Object.assign(Object.assign({}, opts), { upload: { getReceiptSignature: true } }));
        });
    }
    ready() {
        return __awaiter(this, void 0, void 0, function* () {
            this.currencyConfig.ready ? yield 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 });
            },
        };
    }
}
Bundlr.VERSION = "0.11.16";
exports.default = Bundlr;
//# sourceMappingURL=bundlr.js.map