<commit_before>#!/usr/bin/env node

'use strict'

// Imports
const version = require('project-version')
const program = require('commander')
const logUpdate = require('log-update')
const ethtaint = require('..')

// Configure interface
program
  .version(version)
  .description('Taint tracking for Ethereum.')
  .arguments('<address>')
  .usage('<address>')
  .parse(process.argv)

// Extract address argument
const sourceHex = program.args[0]
if (!sourceHex) {
  program.help()
}

// Output machinery
let tainted = 1
let traced = 0
let txs = 0
function update () {
  let s = 'Tainted ' + tainted
  s += ' / Traced ' + traced
  s += ' / Txs ' + txs
  logUpdate(s)
}
function log () {
  logUpdate.clear()
  console.log(...arguments)
  update()
}

// Trace taint from specified address
async function traceAddresses (sourceHex) {
  log('Tracing taint from: ' + sourceHex)
  update()
  const tracker = new ethtaint.Tracker()
  try {
    tracker.on('taint', address => {
      tainted++
      log(address.hex)
    })
    tracker.on('tracedAddress', address => {
      traced++
      update()
    })
    tracker.on('processedTransaction', () => {
      txs++
      update()<commit_msg>Add file output of bin/ethtaint traces<commit_after>#!/usr/bin/env node

'use strict'

// Imports
const fs = require('fs')
const mkdirp = require('mkdirp')
const version = require('project-version')
const program = require('commander')
const logUpdate = require('log-update')
const ethtaint = require('..')

// Configure interface
program
  .version(version)
  .description('Taint tracking for Ethereum.')
  .arguments('<address>')
  .usage('<address>')
  .parse(process.argv)

// Extract address argument
const sourceHex = program.args[0]
if (!sourceHex) {
  program.help()
}

// Output machinery
let tainted = 1
let traced = 0
let txs = 0
function update () {
  let s = 'Tainted ' + tainted
  s += ' / Traced ' + traced
  s += ' / Txs ' + txs
  logUpdate(s)
}
function log () {
  logUpdate.clear()
  console.log(...arguments)
  update()
}

// Trace taint from specified address
mkdirp.sync('trace')
const fileName = 'trace/' + sourceHex
async function traceAddresses (sourceHex) {
  log('Tracing taint from: ' + sourceHex)
  update()
  fs.writeFileSync(fileName, sourceHex + '\n')
  const tracker = new ethtaint.Tracker()
  try {
    tracker.on('taint', address => {
      tainted++
      log(address.hex)
      fs.appendFileSync(fileName, address.hex + '\n')
    })
    tracker.on('tracedAddress', address => {
      traced++
      update()
    })
    tracker.on('processedTransaction', () => {
      txs++
      update()
{'fraction_non_alphanumeric': 0.1543186180422265, 'fraction_numerical': 0.003071017274472169, 'mean_word_length': 3.350584307178631, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5153491', 'n_tokens_mistral': 866, 'n_tokens_neox': 844, 'n_words': 213}