Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect build mode from metadata on deploy #193

Merged
merged 5 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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') {
ipapandinas marked this conversation as resolved.
Show resolved Hide resolved
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> {
ipapandinas marked this conversation as resolved.
Show resolved Hide resolved
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
Loading