<commit_before>/*
 * @fileOverview Background service running for the wallet
 */
define(['model/keyring', 'backend/port'],
function(IdentityKeyRing, Port) {
  'use strict';

  function WalletService(core) {
    var keyRing = new IdentityKeyRing();
    var self = this;

    // Some scope variables
    var currentIdentity = false;

    this.currentHeight = 0;

    // Wallet port
    Port.listen('wallet', function() {
      }, function(port) {
          // Connected
          console.log('[bus] wallet client connected');
          if (currentIdentity && keyRing.identities.hasOwnProperty(currentIdentity)) {
              port.postMessage({'type': 'ready', 'identity': currentIdentity});
          }
      }, function(port) {
          // Disconnected
          console.log('[bus] wallet client disconnected');
    });

    /***************************************
    /* Identities
     */

    var startIdentity = function(identity, callback) {
        currentIdentity = identity.name;

        //Load up tasks
        var openTasks = identity.tasks.getOpenTasks();
        if (openTasks) {
             chrome.browserAction.setBadgeText({text: ""+openTasks});
        }

        // Inform gui and other services
        identity.history.update = function() { Port.post('gui', {name: 'update'}); };

        Port.post('wallet', {'type': 'ready', 'identity': identity.name});
        Port.post('wallet', {'type': 'loaded', 'identity': identity.name});

        callback ? callback(identity) : null;
    }

    this.createIdentity = function(name, secret, password, callback) {
        console.log("[wallet] Create identity", name);
        if (currentIdentity) {
            Port.post('wallet', {'type': 'closing', 'identity': currentIdentity});
        }
        var identity = keyRing.createIdentity(name, secret, password);
        startIdentity(identity, callback);
    }

    this.loadIdentity = function(idx, callback) {
        var name = keyRing.availableIdentities[idx];
        if (currentIdentity != name) {
            Port.post('wallet', {'type': 'closing', 'identity': currentIdentity});
            console.log("[wallet] Load identity", name);
            keyRing.get(name, function(identity) {
                startIdentity(identity, callback);
            });
        }
    };

    // Get an identity from the keyring
    this.getIdentity = function(idx) {
        if (idx === null || idx === undefined) {
            return self.getCurrentIdentity();
        }
        var name = keyRing.availableIdentities[idx];
        currentIdentity = name;
        return keyRing.identities[name];
    };

    this.getCurrentIdentity = function() {
        return keyRing.identities[currentIdentity];
    };

    // Notify frontend of history row updates
    var notifyRow = function(newRow, height) {
        if (newRow && (newRow.myOutValue - newRow.myInValue) > 0) {
            if (height) {
                Port.post('gui', {type: "note", text: 'Received: ' + newRow.myOutValue - newRow.myInValue});
            } else {
                Port.post('gui', {type: "note", text: 'Unconfirmed: ' + newRow.myOutValue - newRow.myInValue});
            }
        }
    };

    /***************************************
    /* History and address subscription
     */
    function historyFetched(err, walletAddress, history) {
        if (err) {
            core.servicesStatus.obelisk = 'error';
            console.log("[wallet] Error fetching history for", walletAddress.address);
            return;
        }
        core.servicesStatus.obelisk = 'ok';
        var client = core.getClient();
        var identity = self.getCurrentIdentity();

        // pass to the wallet to process outputs
        identity.wallet.processHistory(walletAddress, history);

        // now subscribe the address for notifications
        console.log("[wallet] subscribing", walletAddress.address);
        client.subscribe(walletAddress.address, function(err, res) {
            console.log("[wallet] subscribed", walletAddress.address, err, res);

            // fill history after subscribing to ensure we got all histories already (for now).
            identity.history.fillHistory(walletAddress, history);
        }, function(addressUpdate) {
            console.log("[wallet] update", addressUpdate);

            // Get variables from the update
            var height = addressUpdate.height;
            var tx = addressUpdate.tx;
            // var block_hash = addressUpdate.block_hash;
            var address = addressUpdate.address;

            // Process
            var walletAddress = identity.wallet.getWalletAddress(address);
            if (walletAddress) {
                var newRow = identity.wallet.processTx(walletAddress, tx, height);
                // Show a notification for incoming transactions
                notifyRow(newRow, height);
            }
        });
        Port.post('gui', {type: "balance"});
    }
<commit_msg>remove some debug logs from the wallet service.<commit_after>/*
 * @fileOverview Background service running for the wallet
 */
define(['model/keyring', 'backend/port'],
function(IdentityKeyRing, Port) {
  'use strict';

  function WalletService(core) {
    var keyRing = new IdentityKeyRing();
    var self = this;

    // Some scope variables
    var currentIdentity = false;

    this.currentHeight = 0;

    // Wallet port
    Port.listen('wallet', function() {
      }, function(port) {
          // Client connected
          if (currentIdentity && keyRing.identities.hasOwnProperty(currentIdentity)) {
              port.postMessage({'type': 'ready', 'identity': currentIdentity});
          }
      }, function(port) {
          // Client disconnected
    });

    /***************************************
    /* Identities
     */

    var startIdentity = function(identity, callback) {
        currentIdentity = identity.name;

        //Load up tasks
        var openTasks = identity.tasks.getOpenTasks();
        if (openTasks) {
             chrome.browserAction.setBadgeText({text: ""+openTasks});
        }

        // Inform gui and other services
        identity.history.update = function() { Port.post('gui', {name: 'update'}); };

        Port.post('wallet', {'type': 'ready', 'identity': identity.name});
        Port.post('wallet', {'type': 'loaded', 'identity': identity.name});

        callback ? callback(identity) : null;
    }

    this.createIdentity = function(name, secret, password, callback) {
        console.log("[wallet] Create identity", name);
        if (currentIdentity) {
            Port.post('wallet', {'type': 'closing', 'identity': currentIdentity});
        }
        var identity = keyRing.createIdentity(name, secret, password);
        startIdentity(identity, callback);
    }

    this.loadIdentity = function(idx, callback) {
        var name = keyRing.availableIdentities[idx];
        if (currentIdentity != name) {
            Port.post('wallet', {'type': 'closing', 'identity': currentIdentity});
            console.log("[wallet] Load identity", name);
            keyRing.get(name, function(identity) {
                startIdentity(identity, callback);
            });
        }
    };

    // Get an identity from the keyring
    this.getIdentity = function(idx) {
        if (idx === null || idx === undefined) {
            return self.getCurrentIdentity();
        }
        var name = keyRing.availableIdentities[idx];
        currentIdentity = name;
        return keyRing.identities[name];
    };

    this.getCurrentIdentity = function() {
        return keyRing.identities[currentIdentity];
    };

    // Notify frontend of history row updates
    var notifyRow = function(newRow, height) {
        if (newRow && (newRow.myOutValue - newRow.myInValue) > 0) {
            if (height) {
                Port.post('gui', {type: "note", text: 'Received: ' + newRow.myOutValue - newRow.myInValue});
            } else {
                Port.post('gui', {type: "note", text: 'Unconfirmed: ' + newRow.myOutValue - newRow.myInValue});
            }
        }
    };

    /***************************************
    /* History and address subscription
     */
    function historyFetched(err, walletAddress, history) {
        if (err) {
            core.servicesStatus.obelisk = 'error';
            console.log("[wallet] Error fetching history for", walletAddress.address);
            return;
        }
        core.servicesStatus.obelisk = 'ok';
        var client = core.getClient();
        var identity = self.getCurrentIdentity();

        // pass to the wallet to process outputs
        identity.wallet.processHistory(walletAddress, history);

        // now subscribe the address for notifications
        client.subscribe(walletAddress.address, function(err, res) {

            // fill history after subscribing to ensure we got all histories already (for now).
            identity.history.fillHistory(walletAddress, history);
        }, function(addressUpdate) {
            console.log("[wallet] update", addressUpdate);

            // Get variables from the update
            var height = addressUpdate.height;
            var tx = addressUpdate.tx;
            // var block_hash = addressUpdate.block_hash;
            var address = addressUpdate.address;

            // Process
            var walletAddress = identity.wallet.getWalletAddress(address);
            if (walletAddress) {
                var newRow = identity.wallet.processTx(walletAddress, tx, height);
                // Show a notification for incoming transactions
                notifyRow(newRow, height);
            }
        });
        Port.post('gui', {type: "balance"});
    }

{'fraction_non_alphanumeric': 0.13803427627503614, 'fraction_numerical': 0.00041296716911005574, 'mean_word_length': 2.300511073253833, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2203435', 'n_tokens_mistral': 2521, 'n_tokens_neox': 2471, 'n_words': 609}