private static function BTC_MinAndMaxWallets()
 {
     $wallets = WalletsBtc::getAllWallets();
     if (empty($wallets)) {
         return null;
     }
     $maxBalance = null;
     $keyMax = null;
     $minBalance = null;
     $keyMin = null;
     $bitcoin = new jsonRPCClient('http://' . BTC_RPC_USER . ':' . BTC_RPC_PASSWORD . '@' . BTC_RPC_HOST . ":" . BTC_RPC_PORT . '/');
     foreach ($wallets as $key => $value) {
         try {
             $balance = $bitcoin->getbalance($value['account']);
         } catch (Exception $e) {
             $balance = null;
         }
         if ($balance !== null) {
             $wallets[$key]['current_balance'] = $balance;
             if ($minBalance === null || $minBalance > $balance) {
                 $minBalance = $balance;
                 $keyMin = $key;
             }
             if ($maxBalance === null || $maxBalance < $balance) {
                 $maxBalance = $balance;
                 $keyMax = $key;
             }
         }
     }
     $result['min'] = $wallets[$keyMin];
     $result['max'] = $wallets[$keyMax];
     return $result;
 }
 public static function addNewBTCWallet()
 {
     $account = Core::validate($_POST['ACCOUNT']);
     $share = Core::validate($_POST['SHARE']);
     // percent
     if ($account == null || $share == null || !Core::isDouble($share)) {
         print 'Incorrect input data';
         exit;
     }
     $result = WalletsBtc::findBy(array('account' => $account));
     if (!empty($result)) {
         print 'This account already exists';
         exit;
     }
     $bitcoin = new jsonRPCClient('http://' . BTC_RPC_USER . ':' . BTC_RPC_PASSWORD . '@' . BTC_RPC_HOST . ':' . BTC_RPC_PORT . '/');
     try {
         $balance = $bitcoin->getbalance($account);
     } catch (Exception $e) {
         print $e;
         exit;
     }
     $wallet = new WalletsBtc();
     $wallet->setAccount($account);
     $wallet->setValue($balance);
     $wallet->setShare($share / 100.0);
     $wallet->insert();
     header('Location: /admin/btc');
 }