hardhat-tracer
Advanced tools
Comparing version 1.1.0-rc.5 to 1.1.0-rc.6
@@ -10,5 +10,7 @@ "use strict"; | ||
async function formatLog(log, currentAddress, dependencies) { | ||
var _a; | ||
const nameTag = currentAddress | ||
? (0, utils_2.getFromNameTags)(currentAddress, dependencies) | ||
: undefined; | ||
const names = await dependencies.artifacts.getAllFullyQualifiedNames(); | ||
const code = currentAddress | ||
const code = !nameTag && currentAddress | ||
? (await dependencies.provider.send("eth_getCode", [ | ||
@@ -20,3 +22,3 @@ currentAddress, | ||
let str; | ||
let contractName; | ||
let contractName = nameTag; | ||
for (const name of names) { | ||
@@ -35,3 +37,3 @@ const artifact = await dependencies.artifacts.readArtifact(name); | ||
} | ||
catch (_b) { } | ||
catch (_a) { } | ||
// if we got both the contract name and arguments parsed so far, we can stop | ||
@@ -42,5 +44,6 @@ if (contractName && str) { | ||
} | ||
return ((_a = `<${(0, colors_1.colorContract)("UnknownContract")} ${currentAddress}>.` + str) !== null && _a !== void 0 ? _a : `${(0, colors_1.colorEvent)("UnknownEvent")}(${(0, param_1.formatParam)(log.data, dependencies)}, ${(0, param_1.formatParam)(log.topics, dependencies)})`); | ||
return (`<${(0, colors_1.colorContract)("UnknownContract")} ${(0, param_1.formatParam)(currentAddress, dependencies)}>.` + | ||
(str !== null && str !== void 0 ? str : `${(0, colors_1.colorEvent)("UnknownEvent")}(${(0, param_1.formatParam)(log.data, dependencies)}, ${(0, param_1.formatParam)(log.topics, dependencies)})`)); | ||
} | ||
exports.formatLog = formatLog; | ||
//# sourceMappingURL=log.js.map |
@@ -10,2 +10,3 @@ "use strict"; | ||
const contract_1 = require("./format/contract"); | ||
const log_1 = require("./format/log"); | ||
const call_2 = require("./opcodes/call"); | ||
@@ -26,34 +27,55 @@ const callcode_1 = require("./opcodes/callcode"); | ||
async function printTrace(txHash, dependencies) { | ||
var _a; | ||
try { | ||
if ((0, utils_2.isOnlyLogs)(dependencies.tracerEnv)) { | ||
await printLogs(txHash, dependencies); | ||
} | ||
else { | ||
try { | ||
await printDebugTraceTransaction(txHash, dependencies); | ||
} | ||
catch (error) { | ||
if (!isDebugTTNotSupportedError(error)) { | ||
console.log((0, colors_1.colorWarning)(`If you think the above error is a bug, please report it to https://github.com/zemse/hardhat-tracer/issues/new, meanwhile fallbacking to --logs:`)); | ||
} | ||
await printLogs(txHash, dependencies); | ||
} | ||
} | ||
} | ||
catch (error) { | ||
console.error("Error in printTrace:", error); | ||
return; | ||
} | ||
} | ||
exports.printTrace = printTrace; | ||
function isDebugTTNotSupportedError(error) { | ||
return error.message.includes("debug_traceTransaction"); | ||
} | ||
async function printLogs(txHash, dependencies) { | ||
const rc = await dependencies.provider.send("eth_getTransactionReceipt", [ | ||
txHash, | ||
]); | ||
const addressStack = []; | ||
await printTopLevel(txHash, addressStack, dependencies); | ||
if (rc && rc.logs && rc.logs.length) { | ||
for (const log of rc.logs) { | ||
console.log(constants_1.DEPTH_INDENTATION + (await (0, log_1.formatLog)(log, log.address, dependencies))); | ||
} | ||
} | ||
} | ||
async function printDebugTraceTransaction(txHash, dependencies) { | ||
let trace; | ||
try { | ||
const res = await dependencies.provider.send("debug_traceTransaction", [ | ||
trace = await dependencies.provider.send("debug_traceTransaction", [ | ||
txHash, | ||
{ disableStorage: true }, | ||
]); | ||
const tx = await dependencies.provider.send("eth_getTransactionByHash", [ | ||
txHash, | ||
]); | ||
if (tx.to !== null && | ||
tx.to !== "0x" && | ||
tx.to !== "0x0000000000000000000000000000000000000000") { | ||
// normal transaction | ||
console.log((0, colors_1.colorLabel)("CALL") + | ||
" " + | ||
(await (0, call_1.formatCall)(tx.to, tx.input, "0x", tx.value, tx.gas, dependencies))); | ||
addressStack.push(tx.to); | ||
const addressStack = []; | ||
await printTopLevel(txHash, addressStack, dependencies); | ||
for (const [i, structLog] of trace.structLogs.entries()) { | ||
await printStructLog(structLog, i, trace.structLogs, addressStack, dependencies); | ||
} | ||
else { | ||
// contract deploy transaction | ||
const str = await (0, contract_1.formatContract)(tx.input, (0, utils_2.parseUint)((_a = tx.value) !== null && _a !== void 0 ? _a : "0x"), null, (0, utils_1.getContractAddress)(tx), dependencies); | ||
addressStack.push((0, utils_1.getContractAddress)(tx)); | ||
console.log((0, colors_1.colorLabel)("CREATE") + " " + str); | ||
} | ||
for (const [i, structLog] of res.structLogs.entries()) { | ||
await printStructLog(structLog, i, res.structLogs, addressStack, dependencies); | ||
} | ||
} | ||
catch (error) { | ||
// if debug_traceTransaction failed then print warning | ||
if (error.message.includes("debug_traceTransaction")) { | ||
if (isDebugTTNotSupportedError(error)) { | ||
console.log((0, colors_1.colorWarning)(`Warning! Debug Transaction not supported on this network`)); | ||
@@ -63,7 +85,28 @@ } | ||
// else print what the error is | ||
console.error(error); | ||
console.error("Error in printDebugTraceTransaction:", error); | ||
} | ||
throw error; | ||
} | ||
} | ||
exports.printTrace = printTrace; | ||
async function printTopLevel(txHash, addressStack, dependencies) { | ||
var _a; | ||
const tx = await dependencies.provider.send("eth_getTransactionByHash", [ | ||
txHash, | ||
]); | ||
if (tx.to !== null && | ||
tx.to !== "0x" && | ||
tx.to !== "0x0000000000000000000000000000000000000000") { | ||
// normal transaction | ||
console.log((0, colors_1.colorLabel)("CALL") + | ||
" " + | ||
(await (0, call_1.formatCall)(tx.to, tx.input, "0x", tx.value, tx.gas, dependencies))); | ||
addressStack.push(tx.to); | ||
} | ||
else { | ||
// contract deploy transaction | ||
const str = await (0, contract_1.formatContract)(tx.input, (0, utils_2.parseUint)((_a = tx.value) !== null && _a !== void 0 ? _a : "0x"), null, (0, utils_1.getContractAddress)(tx), dependencies); | ||
addressStack.push((0, utils_1.getContractAddress)(tx)); | ||
console.log((0, colors_1.colorLabel)("CREATE") + " " + str); | ||
} | ||
} | ||
async function printStructLog(structLog, index, structLogs, addressStack, dependencies) { | ||
@@ -70,0 +113,0 @@ // if running in logs mode exit if opcode is not a LOG |
{ | ||
"name": "hardhat-tracer", | ||
"version": "1.1.0-rc.5", | ||
"version": "1.1.0-rc.6", | ||
"description": "Hardhat Tracer plugin", | ||
@@ -22,3 +22,3 @@ "repository": "github:zemse/hardhat-tracer", | ||
"lint": "tslint --config tslint.json --project tsconfig.json", | ||
"test": "mocha --exit --recursive 'test/**/*.test.ts'", | ||
"test": "mocha -t 300000 --exit --recursive 'test/**/*.test.ts'", | ||
"build": "tsc", | ||
@@ -25,0 +25,0 @@ "prepublish": "rm -rf dist && yarn build", |
@@ -6,3 +6,3 @@ import { Interface, LogDescription } from "ethers/lib/utils"; | ||
import { TracerDependenciesExtended } from "../../types"; | ||
import { compareBytecode } from "../../utils"; | ||
import { compareBytecode, getFromNameTags } from "../../utils"; | ||
@@ -17,12 +17,16 @@ import { formatParam } from "./param"; | ||
) { | ||
const nameTag = currentAddress | ||
? getFromNameTags(currentAddress, dependencies) | ||
: undefined; | ||
const names = await dependencies.artifacts.getAllFullyQualifiedNames(); | ||
const code = currentAddress | ||
? ((await dependencies.provider.send("eth_getCode", [ | ||
currentAddress, | ||
"latest", | ||
])) as string) | ||
: undefined; | ||
const code = | ||
!nameTag && currentAddress | ||
? ((await dependencies.provider.send("eth_getCode", [ | ||
currentAddress, | ||
"latest", | ||
])) as string) | ||
: undefined; | ||
let str: string | undefined; | ||
let contractName: string | undefined; | ||
let contractName: string | undefined = nameTag; | ||
for (const name of names) { | ||
@@ -57,8 +61,12 @@ const artifact = await dependencies.artifacts.readArtifact(name); | ||
return ( | ||
`<${colorContract("UnknownContract")} ${currentAddress}>.` + str ?? | ||
`${colorEvent("UnknownEvent")}(${formatParam( | ||
log.data, | ||
`<${colorContract("UnknownContract")} ${formatParam( | ||
currentAddress, | ||
dependencies | ||
)}, ${formatParam(log.topics, dependencies)})` | ||
)}>.` + | ||
(str ?? | ||
`${colorEvent("UnknownEvent")}(${formatParam( | ||
log.data, | ||
dependencies | ||
)}, ${formatParam(log.topics, dependencies)})`) | ||
); | ||
} |
@@ -11,2 +11,3 @@ import { ethers } from "ethers"; | ||
import { formatContract } from "./format/contract"; | ||
import { formatLog } from "./format/log"; | ||
import { printCall } from "./opcodes/call"; | ||
@@ -31,48 +32,65 @@ import { printCallCode } from "./opcodes/callcode"; | ||
) { | ||
try { | ||
if (isOnlyLogs(dependencies.tracerEnv)) { | ||
await printLogs(txHash, dependencies); | ||
} else { | ||
try { | ||
await printDebugTraceTransaction(txHash, dependencies); | ||
} catch (error) { | ||
if (!isDebugTTNotSupportedError(error)) { | ||
console.log( | ||
colorWarning( | ||
`If you think the above error is a bug, please report it to https://github.com/zemse/hardhat-tracer/issues/new, meanwhile fallbacking to --logs:` | ||
) | ||
); | ||
} | ||
await printLogs(txHash, dependencies); | ||
} | ||
} | ||
} catch (error) { | ||
console.error("Error in printTrace:", error); | ||
return; | ||
} | ||
} | ||
function isDebugTTNotSupportedError(error: any) { | ||
return (error as any).message.includes("debug_traceTransaction"); | ||
} | ||
async function printLogs( | ||
txHash: string, | ||
dependencies: TracerDependenciesExtended | ||
) { | ||
const rc = await dependencies.provider.send("eth_getTransactionReceipt", [ | ||
txHash, | ||
]); | ||
const addressStack: Array<string | undefined> = []; | ||
await printTopLevel(txHash, addressStack, dependencies); | ||
if (rc && rc.logs && rc.logs.length) { | ||
for (const log of rc.logs) { | ||
console.log( | ||
DEPTH_INDENTATION + (await formatLog(log, log.address, dependencies)) | ||
); | ||
} | ||
} | ||
} | ||
async function printDebugTraceTransaction( | ||
txHash: string, | ||
dependencies: TracerDependenciesExtended | ||
) { | ||
let trace; | ||
try { | ||
const res = await dependencies.provider.send("debug_traceTransaction", [ | ||
trace = await dependencies.provider.send("debug_traceTransaction", [ | ||
txHash, | ||
{ disableStorage: true }, | ||
]); | ||
const tx = await dependencies.provider.send("eth_getTransactionByHash", [ | ||
txHash, | ||
]); | ||
if ( | ||
tx.to !== null && | ||
tx.to !== "0x" && | ||
tx.to !== "0x0000000000000000000000000000000000000000" | ||
) { | ||
// normal transaction | ||
console.log( | ||
colorLabel("CALL") + | ||
" " + | ||
(await formatCall( | ||
tx.to, | ||
tx.input, | ||
"0x", | ||
tx.value, | ||
tx.gas, | ||
dependencies | ||
)) | ||
); | ||
addressStack.push(tx.to); | ||
} else { | ||
// contract deploy transaction | ||
const str = await formatContract( | ||
tx.input, | ||
parseUint(tx.value ?? "0x"), | ||
null, | ||
getContractAddress(tx), | ||
dependencies | ||
); | ||
addressStack.push(getContractAddress(tx)); | ||
console.log(colorLabel("CREATE") + " " + str); | ||
} | ||
for (const [i, structLog] of (res.structLogs as StructLog[]).entries()) { | ||
const addressStack: Array<string | undefined> = []; | ||
await printTopLevel(txHash, addressStack, dependencies); | ||
for (const [i, structLog] of (trace.structLogs as StructLog[]).entries()) { | ||
await printStructLog( | ||
structLog, | ||
i, | ||
res.structLogs, | ||
trace.structLogs, | ||
addressStack, | ||
@@ -84,3 +102,3 @@ dependencies | ||
// if debug_traceTransaction failed then print warning | ||
if ((error as any).message.includes("debug_traceTransaction")) { | ||
if (isDebugTTNotSupportedError(error)) { | ||
console.log( | ||
@@ -91,7 +109,50 @@ colorWarning(`Warning! Debug Transaction not supported on this network`) | ||
// else print what the error is | ||
console.error(error); | ||
console.error("Error in printDebugTraceTransaction:", error); | ||
} | ||
throw error; | ||
} | ||
} | ||
async function printTopLevel( | ||
txHash: string, | ||
addressStack: Array<string | undefined>, | ||
dependencies: TracerDependenciesExtended | ||
) { | ||
const tx = await dependencies.provider.send("eth_getTransactionByHash", [ | ||
txHash, | ||
]); | ||
if ( | ||
tx.to !== null && | ||
tx.to !== "0x" && | ||
tx.to !== "0x0000000000000000000000000000000000000000" | ||
) { | ||
// normal transaction | ||
console.log( | ||
colorLabel("CALL") + | ||
" " + | ||
(await formatCall( | ||
tx.to, | ||
tx.input, | ||
"0x", | ||
tx.value, | ||
tx.gas, | ||
dependencies | ||
)) | ||
); | ||
addressStack.push(tx.to); | ||
} else { | ||
// contract deploy transaction | ||
const str = await formatContract( | ||
tx.input, | ||
parseUint(tx.value ?? "0x"), | ||
null, | ||
getContractAddress(tx), | ||
dependencies | ||
); | ||
addressStack.push(getContractAddress(tx)); | ||
console.log(colorLabel("CREATE") + " " + str); | ||
} | ||
} | ||
async function printStructLog( | ||
@@ -98,0 +159,0 @@ structLog: StructLog, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
193577
3312