<commit_before>"use strict";
cApp.factory("Wallet",["Blockchaininfo","DecentralStorage",function(Blockchaininfo,DecentralStorage){


  var Wallet = function(Name) {
      var self = this;
	    this.Assets=[];
      this.Name=Name;
      this.Addresses=[];
      this.Txs=[];
      this.Balance=0;
      this.CurrentAddress='';
      this.privatekey;
      this.storage= DecentralStorage;
      this.blockchain=new Blockchaininfo();
      this.Txfee =10000;

	this.initialize=function(wallet)
	{
		this.Assets = wallet.Assets;
		this.Addresses=wallet.Addresses;
		this.Txs=wallet.Txs;
		this.Balance=wallet.Balance;
		this.CurrentAddress=wallet.CurrentAddress;
		this.privatekey=wallet.privatekey;
		//this.storage=wallet.storage;
		this.blockchain=wallet.blockchain;
		this.Txfee =wallet.Txfee;

	}
  
	this.getName = function() {
    return this.Name;
  };

	this.addAsset = function(asset) {
		this.Assets.push(asset);
	};
	
	this.getAllAssets = function() {
		return this.Assets;
	};
	
	this.addAddress = function(address) {
		this.Addresses.push(address);
	}
	  
    this.getCurrentAddress = function(){
          return CurrentAddress;
	};
     
    this.setCurrentAddress = function(hash){
          CurrentAddress = hash;
	};

	this.getTransactions = function() {
		return this.Txs;
	};
	
	this.addTransaction = function(transaction) {
		this.Txs.push(transaction);
	};
	
    this.getAddresses = function(){
      return this.Addresses;
    }

    this.setBalance = function(balance){
        Balance = balance;
	};
	
	this.getBalance = function() {
		return this.Balance;
	};

	this.updateBalance=function(balance) {
		this.blockchain.multiAddr(this.getAllAddresses,function(result){
			this.Balance=result;
		});
	}

   console.log('Wallet instantiated'+Name);
}
	
  
  //TODO: finish method and test it
    Wallet.prototype.isAuthenticated=function(callback){
      this.storage.get( "security", function(data) {
    
      })
    }

    Wallet.prototype.authenticate=function (password){
      var passwordDigest = Crypto.SHA256(password);
      var decrypted = this.Addresses[0].decrypt(passwordDigest);
      if (decrypted === true) {
        this.storage.set( "security", "passwordDigest", passwordDigest );
        return true;
      }
      return false;
    }


  Wallet.prototype.loadWallet= function(callback){
      var _name=this.Name;
      var walletData=[]
      var _addresses=this.getAddresses();
      this.storage.get('wallet', function(data) {

        if (data === undefined) {
          data = {}
        }
          
        var addresses ={};
        addresses=data['wallet'][_name];
        var addresses2 = Object.keys(addresses );
        console.log(addresses2)
                 console.log(_addresses);
         for ( var i = 0; i < addresses2.length; i++ ) {

          walletData.push(addresses2[i]);  
          _addresses.push(addresses2[i])    
        }

         console.log(_addresses)
        callback(_addresses);
   
        });
      //console.log(this.getAddresses())
       // console.log(this.Addresses);
        // console.log(hello);
  }

  Wallet.prototype.changePassword=function(){
    
  }

  Wallet.prototype.getCurrentAddress=function() {
      return this.CurrentAddress;
    }

//todo: validate addresses
  Wallet.prototype.getAllAddresses=function(){
     var addressArr = [];
      for ( var i = 0; i < this.Addresses.length; i++ ) {
          addressArr.push(this.Addresses[i]);
      }
      return addressArr;
  }  

    Wallet.prototype.generatePublicAddress =function() {
      var key = Bitcoin.ECKey.makeRandom();
      var hash=key.pub.getAddress().toString();
	  var newAddress = {};
	  newAddress['address'] = hash;
	  this.Addresses.push(newAddress);
      console.log(this.Addresses)
       //this.save(key.toWIF(),hash);
      return hash;
    }
    
    Wallet.prototype.utxofetcher=function(Addresses, callback){

    //  var addresses  = this.getAddresses(), 
      this.blockchain.getUnspent(Addresses,function(data){
      var unspents = {};
      unspents._value=[];
      unspents._script=[];
      unspents._tx_index=[];
      unspents._tx_hash=[];
      console.log(data)
      for(var i=0;i<data.length;i++){
         unspents._value.push(data[i].value_hex);
         unspents._script.push(data[i].tx_output_n);<commit_msg>hash:key dictionary<commit_after>"use strict";
cApp.factory("Wallet",["Blockchaininfo","DecentralStorage",function(Blockchaininfo,DecentralStorage){


  var Wallet = function(Name) {
      var self = this;
	    this.Assets=[];
      this.Name=Name;
      this.Addresses=[];
      this.Txs=[];
      this.Balance=0;
      this.CurrentAddress='';
      this.privatekey;
      this.storage= DecentralStorage;
      this.blockchain=new Blockchaininfo();
      this.Txfee =10000;

	this.initialize=function(wallet)
	{
		this.Assets = wallet.Assets;
		this.Addresses=wallet.Addresses;
		this.Txs=wallet.Txs;
		this.Balance=wallet.Balance;
		this.CurrentAddress=wallet.CurrentAddress;
		this.privatekey=wallet.privatekey;
		//this.storage=wallet.storage;
		this.blockchain=wallet.blockchain;
		this.Txfee =wallet.Txfee;

	}
  
	this.getName = function() {
    return this.Name;
  };

	this.addAsset = function(asset) {
		this.Assets.push(asset);
	};
	
	this.getAllAssets = function() {
		return this.Assets;
	};
	
	this.addAddress = function(address) {
		this.Addresses.push(address);
	}
	  
    this.getCurrentAddress = function(){
          return CurrentAddress;
	};
     
    this.setCurrentAddress = function(hash){
          CurrentAddress = hash;
	};

	this.getTransactions = function() {
		return this.Txs;
	};
	
	this.addTransaction = function(transaction) {
		this.Txs.push(transaction);
	};
	
    this.getAddresses = function(){
      return this.Addresses;
    }

    this.setBalance = function(balance){
        Balance = balance;
	};
	
	this.getBalance = function() {
		return this.Balance;
	};

	this.updateBalance=function(balance) {
		this.blockchain.multiAddr(this.getAllAddresses,function(result){
			this.Balance=result;
		});
	}

   console.log('Wallet instantiated'+Name);
}
	
  
  //TODO: finish method and test it
    Wallet.prototype.isAuthenticated=function(callback){
      this.storage.get( "security", function(data) {
    
      })
    }

    Wallet.prototype.authenticate=function (password){
      var passwordDigest = <PASSWORD>256(password);
      var decrypted = this.Addresses[0].decrypt(passwordDigest);
      if (decrypted === true) {
        this.storage.set( "security", "passwordDigest", passwordDigest );
        return true;
      }
      return false;
    }


  Wallet.prototype.loadWallet= function(callback){
      var _name=this.Name;
      var walletData=[]
      var _addresses=this.getAddresses();
      this.storage.get('wallet', function(data) {

        if (data === undefined) {
          data = {}
        }

        var addresses ={};
        addresses=data['wallet'][_name];
        var addresses2 = Object.keys(addresses );
        console.log(addresses2)
                 console.log(_addresses);
         for ( var i = 0; i < addresses2.length; i++ ) {

          walletData.push(addresses2[i]);  
          _addresses.push(addresses2[i])    
        }

         console.log(_addresses)
        callback(_addresses);
   
        });
      //console.log(this.getAddresses())
       // console.log(this.Addresses);
        // console.log(hello);
  }

  Wallet.prototype.changePassword=function(){
    
  }

  Wallet.prototype.getCurrentAddress=function() {
      return this.CurrentAddress;
    }

//todo: validate addresses
  Wallet.prototype.getAllAddresses=function(){
     var addressArr = [];
      for ( var i = 0; i < this.Addresses.length; i++ ) {
          addressArr.push(this.Addresses[i]);
      }
      return addressArr;
  }  

    Wallet.prototype.generatePublicAddress =function() {
      var key = Bitcoin.ECKey.makeRandom();
      var hash=key.pub.getAddress().toString();
	  var newAddress = {};
	  newAddress[hash] = key;
	  this.Addresses.push(newAddress);
      console.log(this.Addresses)
       //this.save(key.toWIF(),hash);
      return hash;
    }
    
    Wallet.prototype.utxofetcher=function(Addresses, callback){

    //  var addresses  = this.getAddresses(), 
      this.blockchain.getUnspent(Addresses,function(data){
      var unspents = {};
      unspents._value=[];
      unspents._script=[];
      unspents._tx_index=[];
      unspents._tx_hash=[];
      console.log(data)
      for(var i=0;i<data.length;i++){
         unspents._value.push(data[i].value_hex);
         unspents._script.push(data[i].tx_output_n);
{'fraction_non_alphanumeric': 0.13794705062703205, 'fraction_numerical': 0.0041802136553646075, 'mean_word_length': 2.7693654266958423, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 4, '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': '2836260', 'n_tokens_mistral': 2839, 'n_tokens_neox': 2753, 'n_words': 396}