Skip to content

Commit

Permalink
Add detection of build mode from metadata on deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
prxgr4mm3r committed Nov 17, 2023
1 parent 9a9d290 commit 589e8be
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/commands/contract/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ export class DeployContract extends SwankyCommand<typeof DeployContract> {
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();
Expand Down
13 changes: 12 additions & 1 deletion src/lib/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down Expand Up @@ -49,14 +50,24 @@ export class Contract {
return readJSON(path.resolve(this.artifactsPath, `${this.moduleName}.json`));
}

async getBuildMode(): Promise<string> {
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")) {
throw new FileError(
`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<Buffer> {
Expand Down

0 comments on commit 589e8be

Please sign in to comment.