<commit_before>/**
 * @module utils
 */

'use strict';

const dnode = require('dnode');
const net = require('net');
const fs = require('fs');
const storj = require('storj-lib');
const {bitcore} = storj.deps;
const du = require('du');          // Get amount used
const disk = require('diskusage'); // Get amount free
const assert = require('assert');
const bytes = require('bytes');

/**
 * Validate the given payout address
 * @param {String} address
 */
exports._isValidPayoutAddress = function(address) {
  return bitcore.Address.isValid(address) ||
         bitcore.Address.isValid(address, bitcore.Networks.testnet) ||
         this.isValidEthereumAddress(address);
};

/**
 * Validate the given payout address is an Ethereum address
 * @param {String} address
 */
exports.isValidEthereumAddress = function(address) {
  //Disallow contract and contract owner addresses
  //Stops users from accidentally copying the wrong address
  const disallowAddresses = [
    '0xb64ef51c888972c908cfacf59b47c1afbc0ab8ac',
    '0x00f6bf3c5033e944feddb3dc8ffb4d47af17ef0b'
  ];
  if (typeof address !== 'string') {
    return false;
  } else if (disallowAddresses.indexOf(address.toLowerCase()) >= 0) {
    return false;
  }
  return /^0x([0-9A-Fa-f]{2}){20}$/.test(address);
};

/**
 * Validate the given dataserv directory
 * @param {String} directory
 */
exports._isValidDirectory = function(directory) {
  return this.existsSync(directory);
};

/**
 * Validate the given size
 * @param {String} size
 */
exports._isValidSize = function(size) {
  return typeof size === 'number'
    && size >= 0
    && size <= 8e+12; // 8TB
};

/**
 * Validates a given tab config
 * @param {Object} config
 */
exports.validate = function(config) {
  assert(this._isValidPayoutAddress(config.paymentAddress),
         'Invalid payout address');
  assert(this._isValidDirectory(config.storagePath), 'Invalid directory');
  assert(this._isValidSize(bytes.parse(config.storageAllocation)),
         'Invalid storage size');
  assert(this._isValidDirectory(config.storagePath),
         'Could not create Shard Directory');
};

/**
 * Attempts to apply common fixes to a config
 * @param {Object} config
 */
exports.repairConfig = function(config) {
  // Check to see if the size is not using a storage unit<commit_msg>Allow nodes with an allocated space size of up to 8TiB.<commit_after>/**
 * @module utils
 */

'use strict';

const dnode = require('dnode');
const net = require('net');
const fs = require('fs');
const storj = require('storj-lib');
const {bitcore} = storj.deps;
const du = require('du');          // Get amount used
const disk = require('diskusage'); // Get amount free
const assert = require('assert');
const bytes = require('bytes');

/**
 * Validate the given payout address
 * @param {String} address
 */
exports._isValidPayoutAddress = function(address) {
  return bitcore.Address.isValid(address) ||
         bitcore.Address.isValid(address, bitcore.Networks.testnet) ||
         this.isValidEthereumAddress(address);
};

/**
 * Validate the given payout address is an Ethereum address
 * @param {String} address
 */
exports.isValidEthereumAddress = function(address) {
  //Disallow contract and contract owner addresses
  //Stops users from accidentally copying the wrong address
  const disallowAddresses = [
    '0xb64ef51c888972c908cfacf59b47c1afbc0ab8ac',
    '0x00f6bf3c5033e944feddb3dc8ffb4d47af17ef0b'
  ];
  if (typeof address !== 'string') {
    return false;
  } else if (disallowAddresses.indexOf(address.toLowerCase()) >= 0) {
    return false;
  }
  return /^0x([0-9A-Fa-f]{2}){20}$/.test(address);
};

/**
 * Validate the given dataserv directory
 * @param {String} directory
 */
exports._isValidDirectory = function(directory) {
  return this.existsSync(directory);
};

/**
 * Validate the given size
 * @param {String} size
 */
exports._isValidSize = function(size) {
  return typeof size === 'number'
    && size >= 0
    && size <= 8 * Math.pow(2, 30); // 8TiB
};

/**
 * Validates a given tab config
 * @param {Object} config
 */
exports.validate = function(config) {
  assert(this._isValidPayoutAddress(config.paymentAddress),
         'Invalid payout address');
  assert(this._isValidDirectory(config.storagePath), 'Invalid directory');
  assert(this._isValidSize(bytes.parse(config.storageAllocation)),
         'Invalid storage size');
  assert(this._isValidDirectory(config.storagePath),
         'Could not create Shard Directory');
};

/**
 * Attempts to apply common fixes to a config
 * @param {Object} config
 */
exports.repairConfig = function(config) {
  // Check to see if the size is not using a storage unit
{'fraction_non_alphanumeric': 0.1351584393188187, 'fraction_numerical': 0.02328087949989222, 'mean_word_length': 4.076586433260394, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '595801', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1424, 'n_words': 373}