@solarity/hardhat-migrate
Version:
The simplest way to deploy smart contracts
77 lines • 3.07 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TransactionRunner = void 0;
exports.createTransactionRunner = createTransactionRunner;
exports.resetTransactionRunner = resetTransactionRunner;
const Reporter_1 = require("../reporters/Reporter");
const NetworkManager_1 = require("../network/NetworkManager");
const utils_1 = require("../../utils");
const errors_1 = require("../../errors");
let BaseTransactionRunner = class BaseTransactionRunner {
_config;
totalCost = 0n;
totalTransactions = 0n;
constructor(config) {
this._config = config;
}
async reportTransactionResponse(tx, instanceName) {
// Switch the default provider to the Wrapped provider, incorporating network error handling
Object.defineProperty(tx, "provider", {
value: NetworkManager_1.networkManager.provider,
writable: true,
configurable: true,
});
Reporter_1.Reporter.reportTransactionResponseHeader(tx, instanceName);
let receipt;
if (tx.isMined()) {
receipt = (await tx.wait());
}
else {
receipt = await this._showTransactionMining(tx);
}
await Reporter_1.Reporter.reportTransactionReceipt(receipt);
this.totalCost += BigInt(receipt.fee ?? 0n) + BigInt(tx.value ?? 0n);
this.totalTransactions++;
}
summary() {
Reporter_1.Reporter.summary(this.totalTransactions, this.totalCost);
}
async _showTransactionMining(tx) {
await Reporter_1.Reporter.startTxReporting(tx);
let receipt;
try {
// We will wait for both contract deployment and common transactions
receipt = (await tx.wait(this._config.execution.wait));
}
catch (e) {
throw new errors_1.MigrateError(`Transaction failed: ${e.message}`);
}
finally {
Reporter_1.Reporter.stopSpinner();
}
return receipt;
}
};
BaseTransactionRunner = __decorate([
utils_1.catchError
], BaseTransactionRunner);
exports.TransactionRunner = null;
function createTransactionRunner(hre) {
if (exports.TransactionRunner) {
return;
}
exports.TransactionRunner = new BaseTransactionRunner(hre.config.migrate);
}
/**
* Used only in test environments to ensure test atomicity
*/
function resetTransactionRunner() {
exports.TransactionRunner = null;
}
//# sourceMappingURL=TransactionRunner.js.map