function generateMigrations()
 {
     $result = array();
     foreach ($this->getAccounts() as $account) {
         $instance = Accounts::getInstance($account);
         $result[] = new GeneratedAccountInstanceMigration($instance);
     }
     return $result;
 }
 function run(Connection $db, Logger $logger)
 {
     $job = $this->job;
     switch ($job['job_type']) {
         // average jobs
         case "average":
             require __DIR__ . "/../jobs/average.php";
             break;
             // account jobs
         // account jobs
         case "generic":
             require __DIR__ . "/../jobs/generic.php";
             break;
         case "cryptostocks":
             require __DIR__ . "/../jobs/cryptostocks.php";
             break;
         case "securities_cryptostocks":
             require __DIR__ . "/../jobs/securities_cryptostocks.php";
             break;
         case "havelock":
             require __DIR__ . "/../jobs/havelock.php";
             break;
         case "securities_havelock":
             require __DIR__ . "/../jobs/securities_havelock.php";
             break;
         case "securities_crypto-trade":
             require __DIR__ . "/../jobs/securities_cryptotrade.php";
             break;
         case "796":
             require __DIR__ . "/../jobs/796.php";
             break;
         case "securities_796":
             require __DIR__ . "/../jobs/securities_796.php";
             break;
         case "litecoininvest":
             require __DIR__ . "/../jobs/litecoininvest.php";
             break;
             // individual securities jobs
         // individual securities jobs
         case "individual_cryptostocks":
             require __DIR__ . "/../jobs/individual_cryptostocks.php";
             break;
         case "individual_havelock":
             require __DIR__ . "/../jobs/individual_havelock.php";
             break;
         case "individual_crypto-trade":
             require __DIR__ . "/../jobs/individual_crypto-trade.php";
             break;
         case "individual_796":
             require __DIR__ . "/../jobs/individual_796.php";
             break;
         case "individual_litecoininvest":
             require __DIR__ . "/../jobs/individual_litecoininvest.php";
             break;
             // summary jobs
         // summary jobs
         case "sum":
             require __DIR__ . "/../jobs/sum.php";
             break;
         case "securities_count":
             require __DIR__ . "/../jobs/securities_count.php";
             break;
             // notification jobs
         // notification jobs
         case "notification":
             require __DIR__ . "/../jobs/notification.php";
             break;
             // system jobs
         // system jobs
         case "securities_update":
             require __DIR__ . "/../jobs/securities_update.php";
             break;
         case "version_check":
             require __DIR__ . "/../jobs/version_check.php";
             break;
         case "vote_coins":
             require __DIR__ . "/../jobs/vote_coins.php";
             break;
         case "missing_average_find":
             require __DIR__ . "/../jobs/missing_average_find.php";
             break;
         case "missing_average":
             require __DIR__ . "/../jobs/missing_average.php";
             break;
             // transaction jobs
         // transaction jobs
         case "transaction_creator":
             require __DIR__ . "/../jobs/transaction_creator.php";
             break;
         case "transactions":
             require __DIR__ . "/../jobs/transactions.php";
             break;
             // cleanup jobs, admin jobs etc
         // cleanup jobs, admin jobs etc
         case "outstanding":
             require __DIR__ . "/../jobs/outstanding.php";
             break;
         case "expiring":
             require __DIR__ . "/../jobs/expiring.php";
             break;
         case "expire":
             require __DIR__ . "/../jobs/expire.php";
             break;
         case "cleanup":
             require __DIR__ . "/../jobs/cleanup.php";
             break;
         case "disable_warning":
             require __DIR__ . "/../jobs/disable_warning.php";
             break;
         case "disable":
             require __DIR__ . "/../jobs/disable.php";
             break;
         case "delete_user":
             require __DIR__ . "/../jobs/delete_user.php";
             break;
         default:
             if (substr($job['job_type'], 0, strlen("address_")) === "address_") {
                 // address job
                 $currency = substr($job['job_type'], strlen("address_"));
                 if (!in_array($currency, get_address_currencies())) {
                     throw new JobException("Currency {$currency} is not a valid address currency");
                 }
                 if (in_array($currency, \DiscoveredComponents\Currencies::getBalanceCurrencies())) {
                     require __DIR__ . "/../jobs/addresses/discovered.php";
                 } else {
                     // TODO eventually remove this block once we have no currencies that are also in getBalanceCurrencies()
                     if (!file_exists(__DIR__ . "/../jobs/addresses/" . safe_include_arg($currency) . ".php")) {
                         throw new JobException("Could not find any addresses/{$currency}.php include");
                     }
                     require __DIR__ . "/../jobs/addresses/" . safe_include_arg($currency) . ".php";
                 }
                 break;
             }
             if (substr($job['job_type'], 0, strlen("blockcount_")) === "blockcount_") {
                 // address job
                 $currency = substr($job['job_type'], strlen("blockcount_"));
                 if (!in_array($currency, \DiscoveredComponents\Currencies::getBlockCurrencies())) {
                     throw new JobException("Currency {$currency} is not a valid block currency");
                 }
                 require __DIR__ . "/../jobs/blockcount/discovered.php";
                 break;
             }
             if (substr($job['job_type'], 0, strlen("difficulty_")) === "difficulty_") {
                 // address job
                 $currency = substr($job['job_type'], strlen("difficulty_"));
                 if (!in_array($currency, \DiscoveredComponents\Currencies::getDifficultyCurrencies())) {
                     throw new JobException("Currency {$currency} is not a valid difficulty currency");
                 }
                 require __DIR__ . "/../jobs/difficulty/discovered.php";
                 break;
             }
             if (substr($job['job_type'], 0, strlen("markets_")) === "markets_") {
                 // address job
                 $exchange = substr($job['job_type'], strlen("markets_"));
                 if (!in_array($exchange, \DiscoveredComponents\Exchanges::getKeys())) {
                     throw new JobException("Exchange {$exchange} is not a valid exchange");
                 }
                 require __DIR__ . "/../jobs/markets/discovered.php";
                 break;
             }
             if (substr($job['job_type'], 0, strlen("ticker_")) === "ticker_") {
                 // address job
                 $exchange = substr($job['job_type'], strlen("ticker_"));
                 if (!in_array($exchange, \DiscoveredComponents\Exchanges::getKeys())) {
                     throw new JobException("Exchange {$exchange} is not a valid exchange");
                 }
                 require __DIR__ . "/../jobs/ticker/discovered.php";
                 break;
             }
             if (substr($job['job_type'], 0, strlen("currencies_")) === "currencies_") {
                 // address job
                 $exchange = substr($job['job_type'], strlen("currencies_"));
                 if (!in_array($exchange, \DiscoveredComponents\Accounts::getKeys())) {
                     throw new JobException("Account {$exchange} is not a valid account");
                 }
                 require __DIR__ . "/../jobs/currencies/discovered.php";
                 break;
             }
             if (substr($job['job_type'], 0, strlen("hashrates_")) === "hashrates_") {
                 // address job
                 $exchange = substr($job['job_type'], strlen("hashrates_"));
                 if (!in_array($exchange, \DiscoveredComponents\Accounts::getMiners())) {
                     throw new JobException("Account {$exchange} is not a valid miner");
                 }
                 require __DIR__ . "/../jobs/hashrates/discovered.php";
                 break;
             }
             if (substr($job['job_type'], 0, strlen("account_")) === "account_") {
                 // address job
                 $exchange = substr($job['job_type'], strlen("account_"));
                 if (!in_array($exchange, \DiscoveredComponents\Accounts::getKeys())) {
                     throw new JobException("Account {$exchange} is not a valid account");
                 }
                 require __DIR__ . "/../jobs/account/discovered.php";
                 break;
             }
             throw new JobException("Unknown job type '" . htmlspecialchars($job['job_type']) . "'");
     }
 }
Esempio n. 3
0
<?php

/**
 * Discovered account currencies.
 */
if (!$exchange) {
    throw new JobException("No exchange defined");
}
$factory = new \Core\DiscoveredCurrencyFactory();
$instance = \DiscoveredComponents\Accounts::getInstance($exchange);
$currencies = $instance->fetchSupportedCurrencies($factory, $logger);
$logger->info("Found " . count($currencies) . " currencies: " . implode(", ", $currencies));
$persistent = new \Core\PersistentAccountType($instance, db());
$persistent->storeSupportedCurrencies($currencies, $logger);
Esempio n. 4
0
function get_accounts_wizard_config_basic($exchange)
{
    switch ($exchange) {
        // --- securities ---
        case "btct":
            return array('inputs' => array('api_key' => array('title' => 'Read-Only API key', 'callback' => 'is_valid_btct_apikey')), 'table' => 'accounts_btct');
        case "litecoinglobal":
            return array('inputs' => array('api_key' => array('title' => 'Read-Only API key', 'callback' => 'is_valid_litecoinglobal_apikey')), 'table' => 'accounts_litecoinglobal');
        case "cryptostocks":
            return array('inputs' => array('api_email' => array('title' => 'Account e-mail', 'callback' => 'is_valid_generic_key'), 'api_key_coin' => array('title' => 'get_coin_balances API key', 'callback' => 'is_valid_generic_key'), 'api_key_share' => array('title' => 'get_share_balances API key', 'callback' => 'is_valid_generic_key')), 'table' => 'accounts_cryptostocks');
        case "havelock":
            return array('inputs' => array('api_key' => array('title' => 'API key', 'callback' => 'is_valid_havelock_apikey')), 'table' => 'accounts_havelock');
        case "bitfunder":
            return array('inputs' => array('btc_address' => array('title' => 'BTC Address', 'callback' => array(Currencies::getInstance('btc'), 'isValid'))), 'table' => 'accounts_bitfunder');
        case "796":
            return array('inputs' => array('api_app_id' => array('title' => 'Application ID', 'callback' => 'is_numeric'), 'api_key' => array('title' => 'API Key', 'callback' => 'is_valid_796_apikey'), 'api_secret' => array('title' => 'API Secret', 'callback' => 'is_valid_796_apisecret')), 'table' => 'accounts_796');
        case "litecoininvest":
            return array('inputs' => array('api_key' => array('title' => 'API key', 'callback' => 'is_valid_litecoininvest_apikey')), 'table' => 'accounts_litecoininvest');
        case "btcinve":
            return array('inputs' => array('api_key' => array('title' => 'API key', 'callback' => 'is_valid_litecoininvest_apikey')), 'table' => 'accounts_btcinve');
            // --- securities ---
        // --- securities ---
        case "individual_litecoinglobal":
            return array('inputs' => array('quantity' => array('title' => t('Quantity'), 'callback' => 'is_valid_quantity'), 'security_id' => array('title' => t('Security'), 'dropdown' => 'dropdown_get_litecoinglobal_securities', 'callback' => 'is_valid_id')), 'table' => 'accounts_individual_litecoinglobal');
        case "individual_btct":
            return array('inputs' => array('quantity' => array('title' => t('Quantity'), 'callback' => 'is_valid_quantity'), 'security_id' => array('title' => t('Security'), 'dropdown' => 'dropdown_get_btct_securities', 'callback' => 'is_valid_id')), 'table' => 'accounts_individual_btct');
        case "individual_bitfunder":
            return array('inputs' => array('quantity' => array('title' => t('Quantity'), 'callback' => 'is_valid_quantity'), 'security_id' => array('title' => t('Security'), 'dropdown' => 'dropdown_get_bitfunder_securities', 'callback' => 'is_valid_id')), 'table' => 'accounts_individual_bitfunder');
        case "individual_cryptostocks":
            return array('inputs' => array('quantity' => array('title' => t('Quantity'), 'callback' => 'is_valid_quantity'), 'security_id' => array('title' => t('Security'), 'dropdown' => 'dropdown_get_cryptostocks_securities', 'callback' => 'is_valid_id')), 'table' => 'accounts_individual_cryptostocks');
        case "individual_havelock":
            return array('inputs' => array('quantity' => array('title' => t('Quantity'), 'callback' => 'is_valid_quantity'), 'security_id' => array('title' => t('Security'), 'dropdown' => 'dropdown_get_havelock_securities', 'callback' => 'is_valid_id')), 'table' => 'accounts_individual_havelock');
        case "individual_crypto-trade":
            return array('inputs' => array('quantity' => array('title' => t('Quantity'), 'callback' => 'is_valid_quantity'), 'security_id' => array('title' => t('Security'), 'dropdown' => 'dropdown_get_cryptotrade_securities', 'callback' => 'is_valid_id')), 'table' => 'accounts_individual_cryptotrade');
        case "individual_796":
            return array('inputs' => array('quantity' => array('title' => t('Quantity'), 'callback' => 'is_valid_quantity'), 'security_id' => array('title' => t('Security'), 'dropdown' => 'dropdown_get_796_securities', 'callback' => 'is_valid_id')), 'table' => 'accounts_individual_796');
        case "individual_litecoininvest":
            return array('inputs' => array('quantity' => array('title' => t('Quantity'), 'callback' => 'is_valid_quantity'), 'security_id' => array('title' => t('Security'), 'dropdown' => 'dropdown_get_litecoininvest_securities', 'callback' => 'is_valid_id')), 'table' => 'accounts_individual_litecoininvest');
        case "individual_btcinve":
            return array('inputs' => array('quantity' => array('title' => t('Quantity'), 'callback' => 'is_valid_quantity'), 'security_id' => array('title' => t('Security'), 'dropdown' => 'dropdown_get_btcinve_securities', 'callback' => 'is_valid_id')), 'table' => 'accounts_individual_btcinve');
            // --- other ---
        // --- other ---
        case "generic":
            return array('inputs' => array('api_url' => array('title' => 'URL', 'callback' => 'is_valid_generic_url', 'length' => 255), 'currency' => array('title' => t('Currency'), 'dropdown' => 'dropdown_currency_list', 'callback' => 'is_valid_currency', 'style_prefix' => 'currency_name_'), 'multiplier' => array('title' => t('Multiplier'), 'inline_title' => t('value'), 'callback' => 'is_numeric', 'length' => 6, 'default' => 1, 'number' => true)), 'table' => 'accounts_generic', 'title' => 'Generic API');
        default:
            // --- discovered accounts ---
            if (Accounts::hasKey($exchange)) {
                $account = Accounts::getInstance($exchange);
                $inputs = array();
                foreach ($account->getFields() as $key => $field) {
                    $inputs[$key] = array('title' => $field['title'], 'callback' => array(new AccountFieldCheck($field), 'check'));
                    if (isset($field['type']) && $field['type'] == "confirm") {
                        $inputs[$key]['checkbox'] = true;
                    }
                    if (isset($field['note']) && $field['note']) {
                        $inputs[$key]['note'] = t($field['note'][0], $field['note'][1]);
                    }
                    if (isset($field['interaction']) && $field['interaction']) {
                        $inputs[$key]['interaction'] = $field['interaction'];
                    }
                }
                return array('inputs' => $inputs, 'table' => 'accounts_' . safe_table_name($exchange), 'interaction' => $account instanceof \Account\UserInteractionAccount ? array($account, 'interaction') : false);
            }
            // --- offsets ---
            if (substr($exchange, 0, strlen("offset_")) === "offset_") {
                $cur = substr($exchange, strlen("offset_"));
                return array('inputs' => array('balance' => array('title' => t('Value'), 'inline_title' => t('value'), 'callback' => 'is_numeric', 'length' => 6, 'default' => 1, 'number' => true)), 'fixed_inputs' => array('currency' => $cur), 'table' => 'offsets', 'title' => get_currency_abbr($cur) . " offset");
            }
            throw new Exception("Unknown accounts type '{$exchange}'");
    }
}
Esempio n. 5
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;
 }