dop-stick
Version:
Source control tooling for versionable-upgradeable smart contracts
90 lines • 3.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BatchLogAdapter = void 0;
const timelineLogAdapter_1 = require("./timelineLogAdapter");
const diamond_1 = require("../../../types/diamond");
const terminal_1 = require("../core/terminal");
class BatchLogAdapter {
constructor() {
this.hasStartedBatchCreation = false;
this.totalFunctions = 0;
this.actionTotals = {
add: 0,
replace: 0,
remove: 0
};
this.timeline = new timelineLogAdapter_1.TimelineLogAdapter();
}
static getInstance() {
if (!BatchLogAdapter.instance) {
BatchLogAdapter.instance = new BatchLogAdapter();
}
return BatchLogAdapter.instance;
}
startBatchCreation() {
if (!this.hasStartedBatchCreation) {
this.timeline.startSection('BATCH CREATION');
this.timeline.logColoredStep('Creating batches sequentially...', 0, terminal_1.Terminal.colors.magenta);
this.hasStartedBatchCreation = true;
this.totalFunctions = 0;
this.actionTotals = { add: 0, replace: 0, remove: 0 };
}
}
logBatchSuccess(moduleName, batch) {
// Calculate action counts
const actions = {
add: 0,
replace: 0,
remove: 0
};
batch.functionSignatures.forEach(sig => {
const action = batch.originalActions.get(sig);
switch (action) {
case diamond_1.DiamondCutAction.Add:
actions.add++;
this.actionTotals.add++;
break;
case diamond_1.DiamondCutAction.Replace:
actions.replace++;
this.actionTotals.replace++;
break;
case diamond_1.DiamondCutAction.Remove:
actions.remove++;
this.actionTotals.remove++;
break;
}
});
this.totalFunctions += batch.functionSignatures.length;
// Format action summary
const actionParts = [];
if (actions.add > 0)
actionParts.push(`${actions.add} add`);
if (actions.replace > 0)
actionParts.push(`${actions.replace} replace`);
if (actions.remove > 0)
actionParts.push(`${actions.remove} remove`);
const actionSummary = actionParts.join(', ');
this.timeline.logArrowStep(`${moduleName}: ${batch.functionSignatures.length} functions [${actionSummary}]`, 1);
}
logBatchError(moduleName, error) {
const errorMessage = error instanceof Error ? error.message : error;
this.timeline.logError(`${moduleName}: ${errorMessage}`);
}
completeBatchCreation(success = true) {
this.timeline.logSummarySection();
this.timeline.logSummaryItem(`Total functions: ${this.totalFunctions}`);
const actionParts = [];
if (this.actionTotals.add > 0)
actionParts.push(`Add (${this.actionTotals.add})`);
if (this.actionTotals.replace > 0)
actionParts.push(`Replace (${this.actionTotals.replace})`);
if (this.actionTotals.remove > 0)
actionParts.push(`Remove (${this.actionTotals.remove})`);
this.timeline.logSummaryItem(`Actions: ${actionParts.join(', ')}`);
if (success) {
this.timeline.logSuccessWithTime('All batches created successfully');
}
}
}
exports.BatchLogAdapter = BatchLogAdapter;
//# sourceMappingURL=batchLogAdapter.js.map