Skip to content

Commit

Permalink
log formating, interval promise
Browse files Browse the repository at this point in the history
  • Loading branch information
irubido committed Jan 30, 2024
1 parent 22a4f54 commit e123717
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 24 deletions.
2 changes: 2 additions & 0 deletions packages/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
"@types/node": "^18",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"chalk": "^5.3.0",
"eslint": "^8",
"hardhat": "^2.0.0",
"mocha": "^10",
"terminal-link": "^3.0.0",
"ts-node": "^10",
"typescript": "^5"
},
Expand Down
30 changes: 22 additions & 8 deletions packages/plugin/src/MultichainHardhatRuntimeEnvironmentField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import Web3, {
PayableCallOptions,
} from "web3";
import { vars } from "hardhat/config";
import chalk from "chalk";
import terminalLink from "terminal-link";
import {
getConfigEnvironmentVariable,
getNetworkChainId,
Expand Down Expand Up @@ -138,10 +140,17 @@ export class MultichainHardhatRuntimeEnvironmentField {
fees
)
.send(payableTxOptions);

const { from, to, transactionHash } = receipt;
const networkNames = Object.keys(networkArgs);
const { transactionHash } = receipt;
console.log(
`Transacion sent from ${from} to ${to}, transaction hash: ${transactionHash}`
`Multichain deployment initiated, transaction hash: ${chalk.bold(
transactionHash
)}
` +
"\n" +
"Destinaton networks:" +
networkNames.join("\r\n")
);

const [deployer] = await this.web3.eth.getAccounts();
Expand All @@ -153,8 +162,6 @@ export class MultichainHardhatRuntimeEnvironmentField {
return deployDomain.chainId;
});

const networkNames = Object.keys(networkArgs);

const deploymentInfo: DeploymentInfo[] = await Promise.all(
destinationDomainChainIDs.map(async (domainChainID, index) => {
const network = networkNames[index];
Expand All @@ -168,15 +175,22 @@ export class MultichainHardhatRuntimeEnvironmentField {
)
.call();
console.log(
`Contract address for ${network.toUpperCase()}: ${contractAddress}`
`Contract deployed on ${chalk.bold(
network.toUpperCase()
)}: ${chalk.bold(contractAddress)}`
);

const explorerUrl = transferStatusInterval(
const explorerUrl = await transferStatusInterval(
this.hre.config.multichain.environment,
transactionHash,
domainChainID
);
console.log(`Bridge transfer executed, explorer url: ${explorerUrl}`);
const explorerLink = terminalLink(explorerUrl, explorerUrl);
console.log(
`Bridge transfer executed. More details: ${chalk.underline(
explorerLink
)}`
);

return {
network,
Expand Down
39 changes: 23 additions & 16 deletions packages/plugin/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,28 +155,35 @@ export function mapNetworkArgs<Abi extends ContractAbi = any>(
};
}

export function transferStatusInterval(
export async function transferStatusInterval(
environment: Environment,
txHash: string,
domainID: number
): string {
let controller: AbortController;
): Promise<string> {
let explorerUrl: string = "";

const interval = setInterval(() => {
controller = new AbortController();
void getTransferStatusData(environment, txHash, domainID.toString()).then(
(transferStatus) => {
explorerUrl = transferStatus.explorerUrl;

if (transferStatus.status === "executed") {
clearInterval(interval);
controller.abort();
return;
await new Promise((resolve) => {
let controller: AbortController;
setInterval(() => {
controller = new AbortController();
void getTransferStatusData(environment, txHash, domainID.toString()).then(
(transferStatus) => {
explorerUrl = transferStatus.explorerUrl;

if (transferStatus.status === "executed") {
controller.abort();
resolve(explorerUrl);
}
if (transferStatus.status === "failed") {
throw new HardhatPluginError(
"@chainsafe/hardhat-plugin-multichain-deploy",
`Bridge transfer failed`
);
}
}
}
);
}, 1000) as unknown as number;
);
}, 1000);
});

return explorerUrl;
}

0 comments on commit e123717

Please sign in to comment.