<commit_before>/**
 * Broadcast updates to client when the model changes
 */

'use strict';

var Wallet = require('./../wallet/wallet.model');
var ripple = require('ripple-lib');

var Remote = ripple.Remote;
var remote = new Remote({
    // see the API Reference for available options
    servers: [ 'ws://localhost:6006' ]
});

// TODO Move this
var ROOT_RIPPLE_ACCOUNT = {
  address : 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
  secret  : 'masterpassphrase'
};

function create_wallet(callback) {
  // Wait for randomness to have been added.
  // The entropy of the random generator is increased
  // by random data received from a rippled
  // TODO: This is event is never received?
  // See: https://github.com/ripple/ripple-lib/blob/develop/docs/GUIDES.md
  //remote.connect(function(err, res) {
  //     if (!err) {
  //       console.log('Remote connected');
  //       remote.once('random', function(err, info) {
           var wallet = ripple.Wallet.generate();
           callback(wallet);
  //       });
  //     } else {
  //       console.warn('Creating Ripple Address in offline mode');
  //       var wallet = ripple.Wallet.generate();
  //       callback(wallet);
  //     }
  //    });
}

function fund_wallet(ripple_address, amount) {
  var amount = amount || 60;

  remote.setSecret(ROOT_RIPPLE_ACCOUNT.address , ROOT_RIPPLE_ACCOUNT.secret);

  var options = { account: ROOT_RIPPLE_ACCOUNT.address,
                  destination: ripple_address,
                  amount : amount * 1000000
                };
  remote.connect(function(err, res) {
    if (!err) {
        console.log('Remote connected');
        var transaction = remote.createTransaction('Payment', options);
        transaction.submit(function (err, res) {
            if (err) {
                console.log('Failed to make initial XRP transfer because: ' +
                              err);
            }
            if (res) {
              console.log('Successfully funded wallet ' + ripple_address +
                          ' with 60 XRP');
            }
          });<commit_msg>Fixed remote not reconnecting<commit_after>/**
 * Broadcast updates to client when the model changes
 */

'use strict';

var Wallet = require('./../wallet/wallet.model');
var ripple = require('ripple-lib');

var Remote = ripple.Remote;
// TODO Move this
var ROOT_RIPPLE_ACCOUNT = {
  address : 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh',
  secret  : 'masterpassphrase'
};

function create_wallet(callback) {
  // Wait for randomness to have been added.
  // The entropy of the random generator is increased
  // by random data received from a rippled
  // TODO: This is event is never received?
  // See: https://github.com/ripple/ripple-lib/blob/develop/docs/GUIDES.md
  //remote.connect(function(err, res) {
  //     if (!err) {
  //       console.log('Remote connected');
  //       remote.once('random', function(err, info) {
           var wallet = ripple.Wallet.generate();
           callback(wallet);
  //       });
  //     } else {
  //       console.warn('Creating Ripple Address in offline mode');
  //       var wallet = ripple.Wallet.generate();
  //       callback(wallet);
  //     }
  //    });
}

function fund_wallet(ripple_address, callback, amount) {
  var amount = amount || 60;

  var remote = new Remote({
      // see the API Reference for available options
      servers: [ 'ws://localhost:6006' ]
  });

  remote.setSecret(ROOT_RIPPLE_ACCOUNT.address , ROOT_RIPPLE_ACCOUNT.secret);

  var options = { account: ROOT_RIPPLE_ACCOUNT.address,
                  destination: ripple_address,
                  amount : amount * 1000000
                };
  remote.connect(function(err, res) {
    if (!err) {
        console.log('Remote connected');
        var transaction = remote.createTransaction('Payment', options);
        transaction.submit(function (err, res) {
            if (err) {
                console.log('Failed to make initial XRP transfer because: ' +
                              err);
            }
            if (res) {
              console.log('Successfully funded wallet ' + ripple_address +
                          ' with 60 XRP');
            }
          });
{'fraction_non_alphanumeric': 0.12476053639846743, 'fraction_numerical': 0.01053639846743295, 'mean_word_length': 2.161998485995458, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2133864', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1220, 'n_words': 302}