<commit_before>// Adapted from <NAME>' Embark framework
// https://github.com/iurimatias/embark-framework
// Modified by ryepdx to mine at regular intervals.
(function() {
  var main = function () {
    /* TODO: Find a way to load mining config from YML.
     
    if (!loadScript("config.js")) {
      console.log("== config.js not found");
    }

    if (typeof(config) === "undefined") {
      config = {};
      console.log("== config is undefined, proceeding with defaults");
    }

    In the meantime, just set an empty config object.
    */
    config = {}

    defaults = {
      interval_ms: 15000,
      mine_pending_txns: true,
      mine_periodically: true,
      mine_normally: false,
      threads: 1
    }

    for (key in defaults) {
      if (config[key] === undefined) {
        config[key] = defaults[key];
      }
    }

    var miner_obj = (admin.miner === undefined) ? miner : admin.miner;

    if (config.mine_normally) {
        miner_obj.start(config.threads);
        return;
    }
    miner_obj.stop();

    if (config.mine_periodically) start_periodic_mining(config, miner_obj);
    if (config.mine_pending_txns) start_transaction_mining(config, miner_obj);
  };

  var pendingTransactions = function() {
    if (web3.eth.pendingTransactions === undefined || web3.eth.pendingTransactions === null) {
      return txpool.status.pending || txpool.status.queued;
    }
    else if (typeof web3.eth.pendingTransactions === "function")  {
      return web3.eth.pendingTransactions().length > 0;
    }
    else {
      return web3.eth.pendingTransactions.length > 0 || web3.eth.getBlock('pending').transactions.length > 0;
    }
  };
<commit_msg>Fund coinbase account if it hasn't been funded.<commit_after>// Adapted from <NAME>' Embark framework
// https://github.com/iurimatias/embark-framework
// Modified by ryepdx to mine at regular intervals.
(function() {
  var main = function () {
    /* TODO: Find a way to load mining config from YML.
     
    if (!loadScript("config.js")) {
      console.log("== config.js not found");
    }

    if (typeof(config) === "undefined") {
      config = {};
      console.log("== config is undefined, proceeding with defaults");
    }

    In the meantime, just set an empty config object.
    */
    config = {}

    defaults = {
      interval_ms: 15000,
      initial_ether: 15000000000000000000,
      mine_pending_txns: true,
      mine_periodically: true,
      mine_normally: false,
      threads: 1
    }

    for (key in defaults) {
      if (config[key] === undefined) {
        config[key] = defaults[key];
      }
    }

    var miner_obj = (admin.miner === undefined) ? miner : admin.miner;

    if (config.mine_normally) {
        miner_obj.start(config.threads);
        return;
    }
    miner_obj.stop();

    fundAccount(config, miner_obj, function () {
      if (config.mine_periodically) start_periodic_mining(config, miner_obj);
      if (config.mine_pending_txns) start_transaction_mining(config, miner_obj);
    });
  };

  var fundAccount = function (config, miner_obj, cb) {
    var accountFunded = function () {
      return (eth.getBalance(eth.coinbase) >= config.initial_ether);
    }

    if (accountFunded()) {
      return cb();
    }

    console.log("== Funding account");
    miner_obj.start();

    var blockWatcher = web3.eth.filter("latest").watch(function () {
      if (accountFunded()) {
        console.log("== Account funded");

        blockWatcher.stop();
        miner_obj.stop();
        cb();
      }
    });
  };

  var pendingTransactions = function() {
    if (web3.eth.pendingTransactions === undefined || web3.eth.pendingTransactions === null) {
      return txpool.status.pending || txpool.status.queued;
    }
    else if (typeof web3.eth.pendingTransactions === "function")  {
      return web3.eth.pendingTransactions().length > 0;
    }
    else {
      return web3.eth.pendingTransactions.length > 0 || web3.eth.getBlock('pending').transactions.length > 0;
    }
  };

{'fraction_non_alphanumeric': 0.13448534936138243, 'fraction_numerical': 0.012772351615326822, 'mean_word_length': 2.7257462686567164, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '2033799', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1224, 'n_words': 283}