From 09b62a75aa3f68b4ee23775a7c260d08a8980ca8 Mon Sep 17 00:00:00 2001 From: Igor Papandinas Date: Mon, 25 Mar 2024 16:51:11 +0400 Subject: [PATCH] Revert "feat: Detect build mode on deploy (#104)" This reverts commit 749ceaa8c6ffb165564f5ffb2771c579fafeebd0. --- src/commands/contract/compile.ts | 5 ---- src/commands/contract/deploy.ts | 33 ++------------------- src/commands/init/index.ts | 4 +-- src/lib/contract.ts | 51 ++++++++++++++++---------------- src/types/index.ts | 7 ----- 5 files changed, 30 insertions(+), 70 deletions(-) diff --git a/src/commands/contract/compile.ts b/src/commands/contract/compile.ts index 56d87283..e56f1638 100644 --- a/src/commands/contract/compile.ts +++ b/src/commands/contract/compile.ts @@ -5,7 +5,6 @@ import { pathExists } from "fs-extra/esm"; import { SwankyCommand } from "../../lib/swankyCommand.js"; import { ensureCargoContractVersionCompatibility, extractCargoContractVersion, Spinner, storeArtifacts } from "../../lib/index.js"; import { ConfigError, InputError, ProcessError } from "../../lib/errors.js"; -import { BuildMode } from "../../index.js"; export class CompileContract extends SwankyCommand { static description = "Compile the smart contract(s) in your contracts directory"; @@ -64,7 +63,6 @@ export class CompileContract extends SwankyCommand { throw new InputError(`Contract folder not found at expected path`); } - let buildMode = BuildMode.Debug; const compilationResult = await spinner.runCommand( async () => { return new Promise((resolve, reject) => { @@ -75,11 +73,9 @@ export class CompileContract extends SwankyCommand { `contracts/${contractName}/Cargo.toml`, ]; if (flags.release && !flags.verifiable) { - buildMode = BuildMode.Release; compileArgs.push("--release"); } if (flags.verifiable) { - buildMode = BuildMode.Verifiable; const cargoContractVersion = extractCargoContractVersion(); if (cargoContractVersion === null) throw new InputError( @@ -133,7 +129,6 @@ export class CompileContract extends SwankyCommand { this.swankyConfig.contracts[contractName].build = { timestamp: Date.now(), artifactsPath, - buildMode, isVerified: false, }; diff --git a/src/commands/contract/deploy.ts b/src/commands/contract/deploy.ts index ac3489b4..a0b2ca0a 100644 --- a/src/commands/contract/deploy.ts +++ b/src/commands/contract/deploy.ts @@ -2,13 +2,13 @@ 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 { AbiType, ChainAccount, ChainApi, decrypt, resolveNetworkUrl } from "../../lib/index.js"; -import { BuildMode, Encrypted } from "../../types/index.js"; +import { resolveNetworkUrl, ChainApi, ChainAccount, decrypt, AbiType } from "../../lib/index.js"; +import { Encrypted } from "../../types/index.js"; import inquirer from "inquirer"; import chalk from "chalk"; import { Contract } from "../../lib/contract.js"; import { SwankyCommand } from "../../lib/swankyCommand.js"; -import { ApiError, ConfigError, FileError, ProcessError } from "../../lib/errors.js"; +import { ApiError, ConfigError, FileError } from "../../lib/errors.js"; export class DeployContract extends SwankyCommand { static description = "Deploy contract to a running node"; @@ -70,33 +70,6 @@ export class DeployContract extends SwankyCommand { ); } - if (contract.buildMode === undefined) { - throw new ProcessError( - `Build mode is undefined for contract ${args.contractName}. Please ensure the contract is correctly compiled.` - ); - } else if (contract.buildMode !== BuildMode.Verifiable) { - await inquirer - .prompt([ - { - type: "confirm", - message: `You are deploying a not verified contract in ${ - contract.buildMode === BuildMode.Release ? "release" : "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 accountData = this.findAccountByAlias(flags.account); const mnemonic = accountData.isDev ? (accountData.mnemonic as string) diff --git a/src/commands/init/index.ts b/src/commands/init/index.ts index a8915be3..226cdacf 100644 --- a/src/commands/init/index.ts +++ b/src/commands/init/index.ts @@ -463,7 +463,7 @@ async function detectModuleNames(copyList: CopyCandidates): Promise { - const missingPaths: string[] = []; - let result = true; - + async artifactsExist() { + const result: { result: boolean; missingPaths: string[]; missingTypes: string[] } = { + result: true, + missingPaths: [], + missingTypes: [], + }; for (const artifactType of Contract.artifactTypes) { const artifactPath = path.resolve(this.artifactsPath, `${this.moduleName}${artifactType}`); + if (!(await pathExists(artifactPath))) { - result = false; - missingPaths.push(artifactPath); + result.result = false; + result.missingPaths.push(artifactPath); + result.missingTypes.push(artifactType); } } - - return { result, missingPaths }; + return result; } async typedContractExists(contractName: string) { @@ -56,20 +55,27 @@ export class Contract { } async getABI(): Promise { - const jsonArtifactPath = `${this.moduleName}.json`; - await this.ensureArtifactExists(jsonArtifactPath); - return readJSON(path.resolve(this.artifactsPath, jsonArtifactPath)); + const check = await this.artifactsExist(); + if (!check.result && check.missingTypes.includes(".json")) { + throw new FileError(`Cannot read ABI, path not found: ${check.missingPaths.toString()}`); + } + return readJSON(path.resolve(this.artifactsPath, `${this.moduleName}.json`)); } async getBundle() { - const contractArtifactPath = `${this.moduleName}.contract`; - await this.ensureArtifactExists(contractArtifactPath); - return readJSON(path.resolve(this.artifactsPath, contractArtifactPath), 'utf8'); + 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`), 'utf-8'); } async getWasm(): Promise { const bundle = await this.getBundle(); if (bundle.source?.wasm) return bundle.source.wasm; + throw new FileError(`Cannot find wasm field in the .contract bundle!`); } @@ -77,11 +83,4 @@ export class Contract { const abi = await this.getABI(); printContractInfo(abi); } - - private async ensureArtifactExists(artifactFileName: string): Promise { - const artifactPath = path.resolve(this.artifactsPath, artifactFileName); - if (!(await pathExists(artifactPath))) { - throw new FileError(`Artifact file not found at path: ${artifactPath}`); - } - } } diff --git a/src/types/index.ts b/src/types/index.ts index 0dab9358..aa574dda 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -30,7 +30,6 @@ export interface ContractData { export interface BuildData { timestamp: number; artifactsPath: string; - buildMode: BuildMode; isVerified: boolean; } @@ -52,12 +51,6 @@ export interface SwankyConfig { networks: Record } -export enum BuildMode { - Debug = "Debug", - Release = "Release", - Verifiable = "Verifiable", -} - export type SupportedPlatforms = "darwin" | "linux"; export type SupportedArch = "arm64" | "x64";