<commit_before>var prompt = require('prompt');
var async = require('async');

var util = require('./util.js');

var unlockDuration = 999999;
var defaultPassword = '';
var defaultAccountName = 'unset';
var web3 = null;
var web3IPC = null;
var contactList = [];
var accountMapping = {};
var myId = null;

prompt.start();

function setWeb3(_web3){
  web3 = _web3;
}

function setWeb3IPC(_web3IPC){
  web3IPC = _web3IPC;
}

function setWhisperId(whisperId){
  myId = whisperId;
}

// TODO: add check for where these messages are coming from
function startAddressBookListeners(){
  web3.shh.filter({"topics":["Addressbook"]}).watch(function(err, msg) {
    if(err){console.log("ERROR:", err);};
    var message = util.Hex2a(msg.payload);
    if(message.indexOf('request|contacts') >= 0){
      util.GetThisNodesConstellationPubKey(function(constellationKey){
        var obj = [];
        for(var account in accountMapping){
          obj.push({
            address: account,
            name: accountMapping[account],
            constellationKey: constellationKey
          });
        }
        var message = 'contacts|'+JSON.stringify(obj);
        var hexString = new Buffer(message).toString('hex');
        web3.shh.post({
          "topics": ["Addressbook"],
          "from": myId,
          "payload": hexString,
          "ttl": 10,
          "workToProve": 1
        }, function(err, res){
          if(err){console.log('err', err);}
        });
      });
    } else if(message.indexOf('contacts') >= 0){
      var messageArr = message.split('|');
      var contactObj = JSON.parse(messageArr[1]);
      for(var i in contactObj){
        var newContact = contactObj[i];
        var found = false;
        for(var j in contactList){
          var contact = contactList[j];
          if(contact && contact.address == newContact.address){
            found = true;
            contacts.name = newContact.name;
            break; 
          }
        }
        if(found == false){
          contactList.push(newContact);
        } 
      }
    }
  });<commit_msg>changed contacts to contact<commit_after>var prompt = require('prompt');
var async = require('async');

var util = require('./util.js');

var unlockDuration = 999999;
var defaultPassword = '';
var defaultAccountName = 'unset';
var web3 = null;
var web3IPC = null;
var contactList = [];
var accountMapping = {};
var myId = null;

prompt.start();

function setWeb3(_web3){
  web3 = _web3;
}

function setWeb3IPC(_web3IPC){
  web3IPC = _web3IPC;
}

function setWhisperId(whisperId){
  myId = whisperId;
}

// TODO: add check for where these messages are coming from
function startAddressBookListeners(){
  web3.shh.filter({"topics":["Addressbook"]}).watch(function(err, msg) {
    if(err){console.log("ERROR:", err);};
    var message = util.Hex2a(msg.payload);
    if(message.indexOf('request|contacts') >= 0){
      util.GetThisNodesConstellationPubKey(function(constellationKey){
        var obj = [];
        for(var account in accountMapping){
          obj.push({
            address: account,
            name: accountMapping[account],
            constellationKey: constellationKey
          });
        }
        var message = 'contacts|'+JSON.stringify(obj);
        var hexString = new Buffer(message).toString('hex');
        web3.shh.post({
          "topics": ["Addressbook"],
          "from": myId,
          "payload": hexString,
          "ttl": 10,
          "workToProve": 1
        }, function(err, res){
          if(err){console.log('err', err);}
        });
      });
    } else if(message.indexOf('contacts') >= 0){
      var messageArr = message.split('|');
      var contactObj = JSON.parse(messageArr[1]);
      for(var i in contactObj){
        var newContact = contactObj[i];
        var found = false;
        for(var j in contactList){
          var contact = contactList[j];
          if(contact && contact.address == newContact.address){
            found = true;
            contact.name = newContact.name;
            break; 
          }
        }
        if(found == false){
          contactList.push(newContact);
        } 
      }
    }
  });
{'fraction_non_alphanumeric': 0.14185765983112184, 'fraction_numerical': 0.012062726176115802, 'mean_word_length': 2.478187919463087, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 7, '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': '4959655', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1238, 'n_words': 277}