UNPKG

ton-assembly

Version:

TON assembler and disassembler

64 lines 2.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseLogs = parseLogs; const logs_1 = require("../logs"); /** * Parses a TVM Sandbox log into a list of transactions, each containing a list of log entries. */ function parseLogs(log) { const vmLines = (0, logs_1.parse)(log); const transactions = []; let entries = []; let currentStack = []; let currentGas = 1_000_000; for (const vmLine of vmLines) { if (vmLine.$ === "VmStack") { currentStack = vmLine.stack; } if (vmLine.$ === "VmLoc") { entries.push({ hash: vmLine.hash.toLowerCase(), offset: vmLine.offset, stack: currentStack, gas: currentGas, implicit: false, gasCost: 0, }); currentStack = []; } if (vmLine.$ === "VmExecute" && vmLine.instr === "implicit RET") { const lastEntry = entries.at(-1); if (lastEntry) { entries.push({ ...lastEntry, implicit: true, gasCost: 5, }); } } if (vmLine.$ === "VmGasRemaining") { const newGasValue = vmLine.gas; const diff = currentGas - newGasValue; const cost = diff < 0 ? 10_000_000 - newGasValue : diff; const lastEntry = entries.at(-1); if (lastEntry) { lastEntry.gasCost = cost; } currentGas = newGasValue; } if (vmLine.$ === "VmLimitChanged") { currentGas = vmLine.limit; // reset gas } if (vmLine.$ === "VmUnknown" && vmLine.text.includes("console.log")) { // new transaction currentGas = 1_000_000; transactions.push([...entries]); entries = []; } } if (entries.length > 0) { transactions.push([...entries]); } return transactions; } //# sourceMappingURL=logs.js.map