private static function LTC_MinAndMaxWallets()
 {
     $wallets = WalletsLtc::getAllWallets();
     if (empty($wallets)) {
         return null;
     }
     $maxBalance = null;
     $keyMax = null;
     $minBalance = null;
     $keyMin = null;
     $litecoin = new jsonRPCClient('http://' . LTC_RPC_USER . ':' . LTC_RPC_PASSWORD . '@' . LTC_RPC_HOST . ":" . LTC_RPC_PORT . '/');
     foreach ($wallets as $key => $value) {
         try {
             $balance = $litecoin->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 addNewLTCWallet()
 {
     $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 = WalletsLtc::findBy(array('account' => $account));
     if (!empty($result)) {
         print 'This account already exists';
         exit;
     }
     $litecoin = new jsonRPCClient('http://' . LTC_RPC_USER . ':' . LTC_RPC_PASSWORD . '@' . LTC_RPC_HOST . ':' . LTC_RPC_PORT . '/');
     try {
         $balance = $litecoin->getbalance($account);
     } catch (Exception $e) {
         print $e;
         exit;
     }
     $wallet = new WalletsLtc();
     $wallet->setAccount($account);
     $wallet->setValue($balance);
     $wallet->setShare($share / 100.0);
     $wallet->insert();
     header('Location: /admin/ltc');
 }