<commit_before>var Web3 = require('web3');
var web3 = new Web3();
var elasticsearch = require('elasticsearch');
var config = require('config');

var index = config.get('elasticsearch.index');

web3.setProvider(new web3.providers.HttpProvider(config.get('ethereum.provider')));


var abi = require('./config/' + process.env.NODE_ENV + '.abi.json');
var contract = web3.eth.contract(abi);

var client = new elasticsearch.Client({
  host: config.get('elasticsearch.host')
});

var callbacks = require('./config/' + process.env.NODE_ENV + '.callbacks.js');
callbacks.onInit();

var lastBlockNumber = -1;
var lastLogIndex;

// Get last log processed.
client.get({
  index: index,
  type: 'elastic-ethereum',
  id: 0
}, function (error, response) {
  if (!error) {
    lastBlockNumber = response._source.lastBlockNumber;
    lastLogIndex = response._source.lastLogIndex;
  }
  else {
    callbacks.onCreate();
  }

  watch();
});

function watch() {
  var filter = web3.eth.filter({fromBlock: lastBlockNumber, toBlock: 'latest', address: config.get('ethereum.contract_address')});

  filter.watch(function(error, result) {
    // Check if we have indexed this log before.
    if (result.blockNumber == lastBlockNumber && result.logIndex <= lastLogIndex)  {<commit_msg>Fix starting a new index.<commit_after>var Web3 = require('web3');
var web3 = new Web3();
var elasticsearch = require('elasticsearch');
var config = require('config');

var index = config.get('elasticsearch.index');

web3.setProvider(new web3.providers.HttpProvider(config.get('ethereum.provider')));


var abi = require('./config/' + process.env.NODE_ENV + '.abi.json');
var contract = web3.eth.contract(abi);

var client = new elasticsearch.Client({
  host: config.get('elasticsearch.host')
});

var callbacks = require('./config/' + process.env.NODE_ENV + '.callbacks.js');
callbacks.onInit();

var lastBlockNumber;
var lastLogIndex;

// Get last log processed.
client.get({
  index: index,
  type: 'elastic-ethereum',
  id: 0
}, function (error, response) {
  if (!error) {
    lastBlockNumber = response._source.lastBlockNumber;
    lastLogIndex = response._source.lastLogIndex;
  }
  else {
    lastBlockNumber = 0;
    callbacks.onCreate();
  }

  watch();
});

function watch() {
  var filter = web3.eth.filter({fromBlock: lastBlockNumber, toBlock: 'latest', address: config.get('ethereum.contract_address')});

  filter.watch(function(error, result) {
    // Check if we have indexed this log before.
    if (result.blockNumber == lastBlockNumber && result.logIndex <= lastLogIndex)  {
{'fraction_non_alphanumeric': 0.155320813771518, 'fraction_numerical': 0.00782472613458529, 'mean_word_length': 4.558695652173913, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1313124', 'n_tokens_mistral': 809, 'n_tokens_neox': 803, 'n_words': 187}