import { Contract } from '../contract/contract.js';
import { SentTx } from '../contract/sent_tx.js';
/**
 * A contract deployment transaction sent to the network, extending SentTx with methods to create a contract instance.
 */
export class DeploySentTx extends SentTx {
    constructor(artifact, wallet, txHashPromise, 
    /**
     * The complete address of the deployed contract
     */
    completeContractAddress) {
        super(wallet, txHashPromise);
        this.artifact = artifact;
        this.completeContractAddress = completeContractAddress;
    }
    /**
     * Awaits for the tx to be mined and returns the contract instance. Throws if tx is not mined.
     * @param opts - Options for configuring the waiting for the tx to be mined.
     * @returns The deployed contract instance.
     */
    async deployed(opts) {
        const receipt = await this.wait(opts);
        return receipt.contract;
    }
    /**
     * Awaits for the tx to be mined and returns the receipt along with a contract instance. Throws if tx is not mined.
     * @param opts - Options for configuring the waiting for the tx to be mined.
     * @returns The transaction receipt with the deployed contract instance.
     */
    async wait(opts) {
        const receipt = await super.wait(opts);
        const contract = await this.getContractInstance(opts?.wallet, receipt.contractAddress);
        return { ...receipt, contract };
    }
    getContractInstance(wallet, address) {
        const isWallet = (pxe) => !!pxe.createTxExecutionRequest;
        const contractWallet = wallet ?? (isWallet(this.pxe) && this.pxe);
        if (!contractWallet)
            throw new Error(`A wallet is required for creating a contract instance`);
        if (!address)
            throw new Error(`Contract address is missing from transaction receipt`);
        return Contract.at(address, this.artifact, contractWallet);
    }
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVwbG95X3NlbnRfdHguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY29udHJhY3RfZGVwbG95ZXIvZGVwbG95X3NlbnRfdHgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBSUEsT0FBTyxFQUFFLFFBQVEsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBRW5ELE9BQU8sRUFBRSxNQUFNLEVBQVksTUFBTSx3QkFBd0IsQ0FBQztBQWUxRDs7R0FFRztBQUNILE1BQU0sT0FBTyxZQUFvRCxT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