<commit_before>angular.module('omniwallet')
  .factory('enumerated_addresses', function($http, $q, $timeout, $injector) {
    var count = 1;
    return {
      "getData": function() {
        var deferred = $q.defer();

        _.defer(function() {
          var wallet = $injector.get('userService').getWallet();
          if (wallet && wallet.addresses.length > 0) {

            deferred.resolve({
              addresses: wallet.addresses
            });
          } else {
            deferred.resolve({
              addresses: []
            });
          }
        });
        return deferred.promise;
      }
    };
  })
  .controller('AddAddressController', function($modal, $injector, $scope, userService, enumerated_addresses) {

  function decodeAddressFromPrivateKey(key) {

    //  Return the address decoded from the private key.
    var eckey = new Bitcoin.ECKey(key);
    var addr = eckey.getBitcoinAddress().toString();

    return addr;
  }
  ;

  function encodePrivateKey(key, passphrase) {

    //  Return encoded key.  Forget the passphrase forever.
    var eckey = new Bitcoin.ECKey(key);
    var enc = eckey.getEncryptedFormat(passphrase);

    return enc;
  }
  ;

  $scope.backupWallet = function() {
    $scope.login = {
      uuid: userService.data.wallet.uuid,
      action: 'verify',
      disable: true //disable UUID field in template
    }
    var modalInstance = $modal.open({
      templateUrl: '/partials/login_modal.html',
      controller: LoginController,
      scope: $scope
    });

    modalInstance.result.then(function(wallet) {
      var walletAddresses = userService.data.wallet.addresses;
      var blob = {
        addresses: []
      };
      walletAddresses.forEach(function(obj) {
        console.log('wallet addrs', obj)
        var ecKey = Bitcoin.ECKey.decodeEncryptedFormat(obj.privkey, obj.address);
        var addr = ecKey.getBitcoinAddress().toString();
        var key = ecKey.getWalletImportFormat();
        blob.addresses.push({ address: addr, privkey: key });
      })
      var exportBlob = new Blob([JSON.stringify(blob)], {
        type: 'application/json;charset=utf-8'
      });
      saveAs(exportBlob, "wallet.json");
    });
  }

  // Begin Import watch only Form Code
  $scope.openImportWatchOnlyForm = function() {
    var modalInstance = $modal.open({
      templateUrl: '/partials/import_watch_only.html',
      controller: AddBtcAddressModal
    });

    modalInstance.result.then(function(result) {
<commit_msg>remove debug and check for privkey before dump<commit_after>angular.module('omniwallet')
  .factory('enumerated_addresses', function($http, $q, $timeout, $injector) {
    var count = 1;
    return {
      "getData": function() {
        var deferred = $q.defer();

        _.defer(function() {
          var wallet = $injector.get('userService').getWallet();
          if (wallet && wallet.addresses.length > 0) {

            deferred.resolve({
              addresses: wallet.addresses
            });
          } else {
            deferred.resolve({
              addresses: []
            });
          }
        });
        return deferred.promise;
      }
    };
  })
  .controller('AddAddressController', function($modal, $injector, $scope, userService, enumerated_addresses) {

  function decodeAddressFromPrivateKey(key) {

    //  Return the address decoded from the private key.
    var eckey = new Bitcoin.ECKey(key);
    var addr = eckey.getBitcoinAddress().toString();

    return addr;
  }
  ;

  function encodePrivateKey(key, passphrase) {

    //  Return encoded key.  Forget the passphrase forever.
    var eckey = new Bitcoin.ECKey(key);
    var enc = eckey.getEncryptedFormat(passphrase);

    return enc;
  }
  ;

  $scope.backupWallet = function() {
    $scope.login = {
      uuid: userService.data.wallet.uuid,
      action: 'verify',
      disable: true //disable UUID field in template
    }
    var modalInstance = $modal.open({
      templateUrl: '/partials/login_modal.html',
      controller: LoginController,
      scope: $scope
    });

    modalInstance.result.then(function(wallet) {
      var walletAddresses = userService.data.wallet.addresses;
      var blob = {
        addresses: []
      };
      walletAddresses.forEach(function(obj) {
        if(obj.privkey) {
          var ecKey = Bitcoin.ECKey.decodeEncryptedFormat(obj.privkey, obj.address);
          var addr = ecKey.getBitcoinAddress().toString();
          var key = ecKey.getWalletImportFormat();
          blob.addresses.push({ address: addr, privkey: key });
        }
      })
      var exportBlob = new Blob([JSON.stringify(blob)], {
        type: 'application/json;charset=utf-8'
      });
      saveAs(exportBlob, "wallet.json");
    });
  }

  // Begin Import watch only Form Code
  $scope.openImportWatchOnlyForm = function() {
    var modalInstance = $modal.open({
      templateUrl: '/partials/import_watch_only.html',
      controller: AddBtcAddressModal
    });

    modalInstance.result.then(function(result) {

{'fraction_non_alphanumeric': 0.12534874451972897, 'fraction_numerical': 0.0011956954962136308, 'mean_word_length': 2.4805825242718447, 'pattern_counts': {'":': 2, '<': 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': '5965067', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1456, 'n_words': 301}