diff --git a/src/commands/contract/deploy.ts b/src/commands/contract/deploy.ts index 7b2e5482..22ca3d89 100644 --- a/src/commands/contract/deploy.ts +++ b/src/commands/contract/deploy.ts @@ -97,6 +97,22 @@ export class DeployContract extends SwankyCommand { return new ChainAccount(mnemonic); }, "Initialising")) as ChainAccount; + const buildMode = await contract.getBuildMode(); + if(buildMode !== 'Release') { + await inquirer.prompt([ + { + type: "confirm", + message: `You are deploying a contract in debug mode. Are you sure you want to continue?`, + name: "confirm", + }, + ]).then((answers) => { + if(!answers.confirm) { + this.log(`${chalk.redBright('✖')} Aborted deployment of ${chalk.yellowBright(args.contractName)}`); + process.exit(0); + } + }) + } + const { abi, wasm } = (await this.spinner.runCommand(async () => { const abi = await contract.getABI(); const wasm = await contract.getWasm(); diff --git a/src/lib/contract.ts b/src/lib/contract.ts index 482c0ae2..d65d4f42 100644 --- a/src/lib/contract.ts +++ b/src/lib/contract.ts @@ -3,6 +3,7 @@ import { ContractData, DeploymentData } from "../types/index.js"; import { pathExists, readJSON } from "fs-extra/esm"; import path from "node:path"; import { FileError } from "./errors.js"; +import fs from "fs"; export class Contract { static artifactTypes = [".json", ".contract"]; @@ -49,6 +50,16 @@ export class Contract { return readJSON(path.resolve(this.artifactsPath, `${this.moduleName}.json`)); } + async getBuildMode(): Promise { + const check = await this.artifactsExist(); + if (!check.result && check.missingTypes.includes(".contract")) { + throw new FileError( + `Cannot read .contract bundle, path not found: ${check.missingPaths.toString()}` + ); + } + const contractJson = JSON.parse(fs.readFileSync(path.resolve(this.artifactsPath, `${this.moduleName}.json`), 'utf8')); + return contractJson.source.build_info.build_mode; + } async getBundle() { const check = await this.artifactsExist(); if (!check.result && check.missingTypes.includes(".contract")) { @@ -56,7 +67,7 @@ export class Contract { `Cannot read .contract bundle, path not found: ${check.missingPaths.toString()}` ); } - return readJSON(path.resolve(this.artifactsPath, `${this.moduleName}.contract`)); + return readJSON(path.resolve(this.artifactsPath, `${this.moduleName}.contract`), 'utf8'); } async getWasm(): Promise {