Skip to content

Commit

Permalink
fix: Add build mod enum and check verifiable build
Browse files Browse the repository at this point in the history
  • Loading branch information
prxgr4mm3r committed Feb 5, 2024
1 parent 589e8be commit a45ae84
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/commands/contract/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Args, Flags } from "@oclif/core";
import path from "node:path";
import { writeJSON } from "fs-extra/esm";
import { cryptoWaitReady } from "@polkadot/util-crypto/crypto";
import { resolveNetworkUrl, ChainApi, ChainAccount, decrypt, AbiType } from "../../lib/index.js";
import { AccountData, Encrypted } from "../../types/index.js";
import { AbiType, ChainAccount, ChainApi, decrypt, resolveNetworkUrl } from "../../lib/index.js";
import { AccountData, BuildMode, Encrypted } from "../../types/index.js";
import inquirer from "inquirer";
import chalk from "chalk";
import { Contract } from "../../lib/contract.js";
Expand Down Expand Up @@ -98,11 +98,11 @@ export class DeployContract extends SwankyCommand<typeof DeployContract> {
}, "Initialising")) as ChainAccount;

const buildMode = await contract.getBuildMode();
if(buildMode !== 'Release') {
if(buildMode !== BuildMode.Verifiable) {
await inquirer.prompt([
{
type: "confirm",
message: `You are deploying a contract in debug mode. Are you sure you want to continue?`,
message: `You are deploying a not verified contract in ${buildMode === BuildMode.Release ? "release" : "debug"} mode. Are you sure you want to continue?`,
name: "confirm",
},
]).then((answers) => {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/contract.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbiType, consts, printContractInfo } from "./index.js";
import { ContractData, DeploymentData } from "../types/index.js";
import { BuildMode, ContractData, DeploymentData } from "../types/index.js";
import { pathExists, readJSON } from "fs-extra/esm";
import path from "node:path";
import { FileError } from "./errors.js";
Expand Down Expand Up @@ -50,15 +50,15 @@ export class Contract {
return readJSON(path.resolve(this.artifactsPath, `${this.moduleName}.json`));
}

async getBuildMode(): Promise<string> {
async getBuildMode(): Promise<BuildMode> {
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;
return contractJson.image && (contractJson.image as string).startsWith("paritytech/contracts-verifiable") ? BuildMode.Verifiable : contractJson.source.build_info.build_mode;
}
async getBundle() {
const check = await this.artifactsExist();
Expand Down
6 changes: 6 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,11 @@ export interface SwankyConfig {
networks: Record<string, {url: string}>
}

export enum BuildMode {
Debug = "Debug",
Release = "Release",
Verifiable = "Verifiable",
}

export type SupportedPlatforms = "darwin" | "linux";
export type SupportedArch = "arm64" | "x64";

0 comments on commit a45ae84

Please sign in to comment.