Skip to content

Commit

Permalink
feat: make verify synchronous (#77)
Browse files Browse the repository at this point in the history
* feat: make verify synchronous

* fix file path usage

* use exec sync
  • Loading branch information
milapsheth authored Oct 18, 2023
1 parent 5232be7 commit 9f8aa9b
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions axelar-chains-config/src/utils/verifyContract.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
const { exec } = require('child_process');
const { writeFile, writeFileSync, existsSync } = require('fs');
const { promisify } = require('util');

const execAsync = promisify(exec);
const writeFileAsync = promisify(writeFile);
const { execSync } = require('child_process');
const { writeFileSync } = require('fs');

/**
* Verifies a contract on etherscan-like explorer of the provided chain using hardhat.
Expand All @@ -14,31 +10,26 @@ const writeFileAsync = promisify(writeFile);
* @param {string} chain
* @param {string} contract
* @param {any[]} args
* @returns {Promise<void>}
* @returns {void}
*/
const verifyContract = async (env, chain, contract, args, options = {}) => {
const verifyContract = (env, chain, contract, args, options = {}) => {
const stringArgs = args.map((arg) => JSON.stringify(arg));
const content = `module.exports = [\n ${stringArgs.join(',\n ')}\n];`;
const file = options.dir ? `${options.dir}/temp-arguments.js` : 'temp-arguments.js';

if (!existsSync(file)) {
writeFileSync(file, '', 'utf-8');
}
const file = 'temp-arguments.js';
const filePath = options.dir ? `${options.dir}/temp-arguments.js` : 'temp-arguments.js';

const contractArg = options.contractPath ? `--contract ${options.contractPath}` : '';
const dirPrefix = options.dir ? `cd ${options.dir};` : '';
const cmd = `${dirPrefix} ENV=${env} npx hardhat verify --network ${chain.toLowerCase()} ${contractArg} --no-compile --constructor-args ${file} ${contract} --show-stack-traces`;

return writeFileAsync(file, content, 'utf-8')
.then(() => {
console.log(`Verifying contract ${contract} with args '${stringArgs.join(',')}'`);
console.log(cmd);
writeFileSync(filePath, content, 'utf-8');

console.log(`Verifying contract ${contract} with args '${stringArgs.join(',')}'`);
console.log(cmd);

execSync(cmd, { stdio: 'inherit' });

return execAsync(cmd, { stdio: 'inherit' });
})
.then(() => {
console.log('Verified!');
});
console.log('Verified!');
};

module.exports = {
Expand Down

0 comments on commit 9f8aa9b

Please sign in to comment.