deth
Version:
Ethereum node focused on Developer Experience
55 lines (54 loc) • 2.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const chalk_1 = require("chalk");
const primitives_1 = require("../../primitives");
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 ${chalk_1.blue(decoded.signature)}` : ''}`);
}
logEvent(data, topics) {
const decodedLog = this.abiDecoder.decodeLog({
data,
topics,
});
if (decodedLog) {
// @todo improve output here
console.log(header('LOG'), chalk_1.blue(decodedLog.signature), stringifyEthersValue(decodedLog.values));
}
else {
console.log(header('LOG'), '(unrecognized)');
}
}
logRevert(reason, address) {
console.log(header('REVERT'), chalk_1.red(`Reason ${reason} on ${formatAddress(address)}`));
}
logNodeInfo(walletManager) {
const wallets = walletManager.getWallets();
console.log(`Unlocked wallets: ${chalk_1.green(wallets.length)}`);
console.log('No:\t Address:\t Private key:');
for (const [i, wallet] of wallets.entries()) {
console.log(`${i}\t ${chalk_1.yellow(primitives_1.makeAddress(wallet.address))}\t ${wallet.privateKey}`);
}
console.log('');
}
}
exports.CliLogger = CliLogger;
function header(name) {
return chalk_1.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 chalk_1.yellow(`${address.substr(0, 8)}...${address.substr(address.length - 3, 3)}`);
}