Пример #1
0
function get_external_apis()
{
    $external_apis_addresses = array();
    foreach (Currencies::getBalanceCurrencies() as $key) {
        $currency = Currencies::getInstance($key);
        if ($currency->getExplorerURL()) {
            $link = link_to($currency->getExplorerURL(), $currency->getExplorerName());
        } else {
            $link = htmlspecialchars($currency->getExplorerName());
        }
        $external_apis_addresses["address_" . $key] = array('link' => $link, 'package' => Currencies::getDefiningPackage($key));
    }
    $external_apis_blockcounts = array();
    foreach (Currencies::getBlockCurrencies() as $key) {
        $currency = Currencies::getInstance($key);
        if ($currency->getExplorerURL()) {
            $link = link_to($currency->getExplorerURL(), $currency->getExplorerName());
        } else {
            $link = htmlspecialchars($currency->getExplorerName());
        }
        $external_apis_blockcounts["blockcount_" . $key] = array('link' => $link, 'package' => Currencies::getDefiningPackage($key));
    }
    $exchange_tickers = array();
    foreach (Exchanges::getAllInstances() as $key => $exchange) {
        if (in_array($key, Exchanges::getDisabled())) {
            // do not list disabled exchanges
            continue;
        }
        $link = link_to($exchange->getURL(), $exchange->getName());
        $exchange_tickers["ticker_" . $key] = array('link' => $link, 'package' => Exchanges::getDefiningPackage($key));
    }
    $mining_pools = array();
    $exchange_wallets = array();
    foreach (Accounts::getKeys() as $key) {
        if (in_array($key, Accounts::getDisabled())) {
            // do not list disabled accounts
            continue;
        }
        $instance = Accounts::getInstance($key);
        if (in_array($key, Accounts::getMiners())) {
            // a miner
            $mining_pools["account_" . $key] = array('link' => link_to($instance->getURL(), $instance->getName()), 'package' => Accounts::getDefiningPackage($key));
        } else {
            // otherwise, assume exchange wallet
            $exchange_wallets["account_" . $key] = array('link' => link_to($instance->getURL(), $instance->getName()), 'package' => Accounts::getDefiningPackage($key));
        }
    }
    $external_apis = array("Address balances" => $external_apis_addresses, "Block counts" => $external_apis_blockcounts, "Mining pool wallets" => $mining_pools, "Exchange wallets" => $exchange_wallets, "Exchange tickers" => $exchange_tickers, "Security exchanges" => array('securities_796' => '<a href="https://796.com">796 Xchange</a>', 'ticker_crypto-trade' => '<a href="https://crypto-trade.com">Crypto-Trade</a>', 'securities_cryptostocks' => '<a href="http://cryptostocks.com">Cryptostocks</a>', 'securities_havelock' => '<a href="https://www.havelockinvestments.com">Havelock Investments</a>', 'securities_update_cryptostocks' => '<a href="http://cryptostocks.com">Cryptostocks</a> Securities list', 'securities_update_havelock' => '<a href="https://www.havelockinvestments.com">Havelock Investments</a> Securities list', 'securities_update_litecoininvest' => '<a href="https://litecoininvest.com">Litecoininvest</a> Securities list', 'cryptostocks' => '<a href="http://cryptostocks.com">Cryptostocks</a>', 'havelock' => '<a href="https://www.havelockinvestments.com">Havelock Investments</a>', 'litecoininvest' => '<a href="https://litecoininvest.com">Litecoininvest</a>'), "Individual securities" => array('individual_crypto-trade' => '<a href="https://crypto-trade.com">Crypto-Trade</a>', 'individual_cryptostocks' => '<a href="http://cryptostocks.com">Cryptostocks</a>', 'individual_havelock' => '<a href="https://www.havelockinvestments.com">Havelock Investments</a>', 'individual_litecoininvest' => '<a href="https://litecoininvest.com">Litecoininvest</a>'), "Other" => array('outstanding' => '<a href="' . htmlspecialchars(url_for('premium')) . '">Premium account</a> processing'));
    // convert to new format
    foreach ($external_apis as $group => $data) {
        foreach ($data as $key => $value) {
            if (!is_array($value)) {
                $external_apis[$group][$key] = array('link' => $value);
            }
        }
    }
    return $external_apis;
}
 /**
  * Get all the accounts that we want to create tables for.
  */
 function getAccounts()
 {
     return array_diff(Accounts::getKeys(), Accounts::getDisabled());
 }
Пример #3
0
 /**
  * Get a list of all jobs that need to be queued, as an array of associative
  * arrays with (job_type, arg_id, [user_id]).
  *
  * This could use e.g. {@link JobTypeFinder}
  */
 function findJobs(Connection $db, Logger $logger)
 {
     $standard_jobs = self::getStandardJobs();
     $logger->info("Current time: " . date('r'));
     // get all disabled users
     $disabled = array();
     $q = $db->prepare("SELECT * FROM user_properties WHERE is_disabled=1");
     $q->execute();
     while ($d = $q->fetch()) {
         $disabled[$d['id']] = $d;
     }
     foreach (array(true, false) as $is_premium_only) {
         $job_count = 0;
         foreach ($standard_jobs as $standard) {
             $always = isset($standard['always']) && $standard['always'];
             $field = isset($standard['user_id_field']) ? $standard['user_id_field'] : 'user_id';
             $query_extra = isset($standard['query']) ? $standard['query'] : "";
             $args_extra = isset($standard['args']) ? $standard['args'] : array();
             if (isset($standard['failure']) && $standard['failure']) {
                 $query_extra .= " AND is_disabled=0";
             }
             $args = array();
             if (!$always) {
                 // we want to run system jobs at least every 0.1 hours = 6 minutes
                 $args[] = isset($standard['hours']) ? $standard['hours'] : (isset($standard['user_id']) && $standard['user_id'] == get_site_config('system_user_id') ? get_site_config('refresh_queue_hours_system') : ($is_premium_only ? get_site_config('refresh_queue_hours_premium') : get_site_config('refresh_queue_hours')));
             }
             $queue_field = isset($standard['queue_field']) ? $standard['queue_field'] : 'last_queue';
             if ($is_premium_only && (!isset($standard['user_id']) || $standard['user_id'] != get_site_config('system_user_id'))) {
                 $query_extra .= " AND {$field} IN (SELECT id FROM user_properties WHERE is_premium=1)";
             }
             // multiply queue_hours by 0.8 to ensure that user jobs are always executed within the specified timeframe
             try {
                 $q = $db->prepare("SELECT * FROM " . $standard['table'] . " WHERE " . ($always ? "1" : "({$queue_field} <= DATE_SUB(NOW(), INTERVAL (? * 0.8) HOUR) OR ISNULL({$queue_field}))") . " {$query_extra}");
                 $q->execute(array_join($args, $args_extra));
             } catch (\PdoException $e) {
                 throw new \Exception("Could not find jobs for table '" . $standard['table'] . "': " . $e->getMessage(), $e->getCode(), $e);
             }
             $disabled_count = 0;
             while ($address = $q->fetch()) {
                 $job = array("job_type" => $standard['type'], "user_id" => isset($standard['user_id']) ? $standard['user_id'] : $address[$field], "arg_id" => $address['id'], "queue_field" => $queue_field, "object" => $address, "table" => $standard['table']);
                 // check that this user is not disabled
                 if (isset($disabled[$job['user_id']])) {
                     if ($disabled_count == 0) {
                         $logger->info("Skipping job '" . $standard['type'] . "' for user " . $job['user_id'] . ": user is disabled");
                     }
                     $disabled_count++;
                     continue;
                 }
                 $result[] = $job;
                 $job_count++;
             }
             if ($disabled_count > 1) {
                 $logger->info("Also skipped another " . number_format($disabled_count) . " " . $standard['type'] . " jobs due to disabled users");
             }
         }
         $logger->info($is_premium_only ? "Found {$job_count} premium jobs" : "Found {$job_count} general user jobs");
     }
     $block_jobs = array('version_check', 'vote_coins', 'average', 'missing_average_find');
     foreach ($block_jobs as $name) {
         // as often as we can (or on request), run litecoin_block jobs
         $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
     }
     // block count jobs (using the new Currencies framework)
     foreach (\DiscoveredComponents\Currencies::getBlockCurrencies() as $cur) {
         $name = "blockcount_" . $cur;
         $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
     }
     // difficulty jobs (using the new Currencies framework)
     foreach (\DiscoveredComponents\Currencies::getDifficultyCurrencies() as $cur) {
         $name = "difficulty_" . $cur;
         $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
     }
     // markets jobs (using the new Exchanges framework: #400)
     foreach (\DiscoveredComponents\Exchanges::getKeys() as $exchange) {
         if (!in_array($exchange, \DiscoveredComponents\Exchanges::getDisabled())) {
             $name = "markets_" . $exchange;
             $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
             $name = "ticker_" . $exchange;
             $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
         }
     }
     // supported currencies jobs (using the new Accounts framework)
     foreach (\DiscoveredComponents\Accounts::getKeys() as $key) {
         if (!in_array($key, \DiscoveredComponents\Accounts::getDisabled())) {
             $name = "currencies_" . $key;
             $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
         }
     }
     // supported hashrates jobs (using the new Accounts framework)
     foreach (\DiscoveredComponents\Accounts::getMiners() as $key) {
         if (!in_array($key, \DiscoveredComponents\Accounts::getDisabled())) {
             $name = "hashrates_" . $key;
             $result[] = array('job_type' => $name, 'user_id' => get_site_config('system_user_id'), 'arg_id' => -1);
         }
     }
     return $result;
 }