UNPKG

deth

Version:

Ethereum node focused on Developer Experience

52 lines (51 loc) 1.89 kB
import { gray, yellow, red, blue, green } from 'chalk'; import { makeAddress } from '../../primitives'; export class CliLogger { constructor(abiDecoder) { this.abiDecoder = abiDecoder; } logTransaction(tx) { const deploying = tx.to === undefined; const data = deploying ? tx.data : undefined; const decoded = data ? this.abiDecoder.decodeCalldata(data) : undefined; console.log(header('TX'), `From ${formatAddress(tx.from)} to ${tx.to ? formatAddress(tx.to) : '[NEW CONTRACT]'} ${decoded ? `with ${blue(decoded.signature)}` : ''}`); } logEvent(data, topics) { const decodedLog = this.abiDecoder.decodeLog({ data, topics, }); if (decodedLog) { // @todo improve output here console.log(header('LOG'), blue(decodedLog.signature), stringifyEthersValue(decodedLog.values)); } else { console.log(header('LOG'), '(unrecognized)'); } } logRevert(reason, address) { console.log(header('REVERT'), red(`Reason ${reason} on ${formatAddress(address)}`)); } logNodeInfo(walletManager) { const wallets = walletManager.getWallets(); console.log(`Unlocked wallets: ${green(wallets.length)}`); console.log('No:\t Address:\t Private key:'); for (const [i, wallet] of wallets.entries()) { console.log(`${i}\t ${yellow(makeAddress(wallet.address))}\t ${wallet.privateKey}`); } console.log(''); } } function header(name) { return gray(`[${name}]\t`); } function stringifyEthersValue(value) { const result = []; for (let i = 0; i < value.length; i++) { result.push(value[i]); } return result.join(', '); } function formatAddress(address) { return yellow(`${address.substr(0, 8)}...${address.substr(address.length - 3, 3)}`); }