|--------------------------------------------------------------------------
|
| Here you may handle any errors that occur in your application, including
| logging them or displaying custom views for specific errors. You may
| even register several error handlers to handle different types of
| exceptions. If nothing is returned, the default error view is
| shown, which includes a detailed stack trace during debug.
|
*/
App::error(function (Exception $exception, $code) {
    Log::error($exception);
    $user = Auth::check() ? json_encode(Auth::user()) : 'no user';
    $visitor_ip = Request::getClientIp();
    $message = "Code: {$code}\n\nIP: {$visitor_ip}\n\nURL: " . Request::url() . "\n\nUser: {$user}\nInput: " . json_encode(Input::all()) . "\n\nexception: {$exception}";
    Log::error($exception);
    MailHelper::sendEmailPlain(['email' => Config::get('mail.admin_email'), 'subject' => "Exception code {$code}", 'text' => $message]);
});
/*
|--------------------------------------------------------------------------
| Maintenance Mode Handler
|--------------------------------------------------------------------------
|
| The "down" Artisan command gives you the ability to put an application
| into maintenance mode. Here, you will define what is displayed back
| to the user if maintenance mode is in effect for the application.
|
*/
App::down(function () {
    return Response::make("Be right back!", 503);
});
/*
 /**
  * @param $confirms
  * @param $transaction_model
  * @param $common_data
  * @param $btc_amount
  * @param $to_address
  * @param $satoshi_amount
  *
  * @return mixed
  */
 private function processUnknownAddress($confirms, $transaction_model = null, $common_data, $btc_amount, $to_address, $satoshi_amount)
 {
     if ($confirms > 0) {
         /* bitcoind sent 2nd callback for the transaction which is 1st confirmation
          * no need to shoot to the application, since application is updating first confirmation anyway on block-notify */
         Transaction::updateTxConfirmation($transaction_model, $common_data);
     } else {
         /* either its change address or somebody sent to some address that is not registered in db!
          * say some shit that address is unknown, and mail too! */
         MailHelper::sendEmailPlain(['email' => Config::get('mail.admin_email'), 'subject' => 'RECEIVED BITCOINS TO UNKNOWN ADDRESS', 'text' => 'RECEIVED ' . $btc_amount . ' BITCOINS TO UNKNOWN ADDRESS. Address that received it: ' . $to_address]);
         $initialUserBalance = Balance::getBalance($this->user->id, $this->crypto_type_id);
         $common_data['transaction_type'] = TX_RECEIVE;
         $common_data['note'] = TX_UNREGISTERED_ADDRESS;
         $common_data['user_balance'] = bcadd($initialUserBalance, $satoshi_amount);
         // new API user balance
         $common_data['previous_balance'] = $initialUserBalance->balance;
         // API user balance before that transaction, because user balance has not been updated yet
         $common_data['bitcoind_balance'] = bcmul($this->bitcoin_core->getbalance(), SATOSHIS_FRACTION);
         // bitcoind balance on received! that means this transaction is not included, because it has 0 conf
         // insert new transaction anyway
         Transaction::insertNewTransaction($common_data);
         Log::warning('Received payment to unregistered address');
     }
 }