@solarity/hardhat-migrate
Version:
The simplest way to deploy smart contracts
63 lines • 2.73 kB
JavaScript
;
/* eslint-disable no-console */
Object.defineProperty(exports, "__esModule", { value: true });
exports.PublicReporter = void 0;
const prettier_1 = require("prettier");
const Reporter_1 = require("./Reporter");
const NetworkManager_1 = require("../network/NetworkManager");
const TransactionRunner_1 = require("../runners/TransactionRunner");
const errors_1 = require("../../errors");
class PublicReporter {
static async reportTransactionByHash(txHash, name) {
const tx = await NetworkManager_1.networkManager.provider.getTransaction(txHash);
if (!tx) {
throw new errors_1.MigrateError("Transaction not found.");
}
await TransactionRunner_1.TransactionRunner.reportTransactionResponse(tx, name || "Unknown");
}
static reportContracts(...contracts) {
const table = contracts.map(([contract, address]) => ({
Contract: contract,
Address: address,
}));
console.log();
console.table(table);
console.log();
Reporter_1.Reporter.notifyStorageAboutContracts(this.normalizeContractInputs(contracts, ""));
}
static async reportContractsMD(...contracts) {
const explorer = await Reporter_1.Reporter.getExplorerUrl();
let normalizedExplorer;
try {
normalizedExplorer = explorer !== "" ? new URL("address/", explorer).toString() : `address/`;
}
catch {
normalizedExplorer = `address/`;
}
let markdownContent;
const headers = [
"| Contract | Address |",
"|---------------|--------------------------------------------|",
];
const rows = contracts.map(([contract, address]) => {
return `| ${contract} | [${address}](${normalizedExplorer}${address}) |`;
});
markdownContent = [...headers, ...rows].join("\n");
console.log();
console.log(await (0, prettier_1.format)(markdownContent, {
parser: "markdown",
printWidth: 80,
proseWrap: "always",
}));
Reporter_1.Reporter.notifyStorageAboutContracts(this.normalizeContractInputs(contracts, explorer));
}
static normalizeContractInputs(contracts, explorerLink) {
const explorer = explorerLink || "";
const normalizedExplorer = explorer !== "" ? new URL("address/", explorer).toString() : ``;
return contracts.map(([contract, address]) => {
return [contract, normalizedExplorer !== "" ? `[${address}](${normalizedExplorer}${address})` : address];
});
}
}
exports.PublicReporter = PublicReporter;
//# sourceMappingURL=PublicReporter.js.map