"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("./utils");
/**
 * Generic class factory for all of the contract wrapper classes.
 */
class ContractWrapperFactory {
    /**
     * Connstructor to create a contract wrapper factory for the given
     * Arc contract name and wrapper class.
     * @param solidityContract Name of the contract
     * @param wrapper - Class of the contract
     */
    constructor(solidityContractName, wrapper) {
        this.solidityContractName = solidityContractName;
        this.wrapper = wrapper;
    }
    /**
     * Deploy a new instance of the contract and return a wrapper around it.
     * @param rest Optional arguments to the Arc contracts constructor.
     */
    new(...rest) {
        return __awaiter(this, void 0, void 0, function* () {
            yield this.ensureSolidityContract();
            return new this.wrapper(this.solidityContract).hydrateFromNew(...rest);
        });
    }
    /**
     * Return a wrapper around the contract, hydrated from the given address.
     * Throws an exception if the contract is not found at the given address.
     * @param address
     */
    at(address) {
        return __awaiter(this, void 0, void 0, function* () {
            yield this.ensureSolidityContract();
            return new this.wrapper(this.solidityContract).hydrateFromAt(address);
        });
    }
    /**
     * Return a wrapper around the contract as deployed by the current version of Arc.js.
     * Note this is usually not needed as the WrapperService provides these
     * wrappers already hydrated.
     */
    deployed() {
        return __awaiter(this, void 0, void 0, function* () {
            yield this.ensureSolidityContract();
            return new this.wrapper(this.solidityContract).hydrateFromDeployed();
        });
    }
    ensureSolidityContract() {
        return __awaiter(this, void 0, void 0, function* () {
            if (!this.solidityContract) {
                this.solidityContract = yield utils_1.Utils.requireContract(this.solidityContractName);
            }
        });
    }
}
exports.default = ContractWrapperFactory;
//# sourceMappingURL=contractWrapperFactory.js.map