UNPKG

@g4g/eth-gas-reporter

Version:

Mocha reporter which shows gas used per unit test.

51 lines (43 loc) 1.57 kB
const etherRouter = require("./etherRouter"); const SyncRequest = require("./syncRequest"); class ProxyResolver { constructor(data, config) { this.unresolvedCalls = 0; this.data = data; this.sync = new SyncRequest(config.url); if (typeof config.proxyResolver === "function") { this.resolve = config.proxyResolver.bind(this); } else if (config.proxyResolver === "EtherRouter") { this.resolve = etherRouter.bind(this); } else { this.resolve = this.resolveByMethodSignature; } } /** * Searches all known contracts for the method signature and returns the first * found (if any). Undefined if none * @param {Object} transaction result of web3.eth.getTransaction * @return {String} contract name */ resolveByMethodSignature(transaction) { const signature = transaction.input.slice(2, 10); const matches = this.data.getAllContractsWithMethod(signature); if (matches.length >= 1) return matches[0].contract; } /** * Tries to match bytecode deployed at address to deployedBytecode listed * in artifacts. If found, adds this to the code-hash name mapping and * returns name. * @param {String} address contract address * @return {String} contract name */ resolveByDeployedBytecode(address) { const code = this.sync.getCode(address); const match = this.data.getContractByDeployedBytecode(code); if (match) { this.data.trackNameByAddress(match.name, address); return match.name; } } } module.exports = ProxyResolver;