public function getBalance() { $api_url = 'https://blockchain.info/merchant/' . Config::get('bitcoin.guid') . '/balance'; $api_url .= '?password='******'bitcoin.password')); $api_url .= '&address=' . urlencode(Config::get('bitcoin.wallet_address')); $api_url .= '&confirmations=0'; $response = file_get_contents($api_url); $object = json_decode($response); return array('usd' => Bitcoin::toUSD($object->balance), 'btc' => Bitcoin::toBTC($object->balance), 'satoshi' => $object->balance); }
public function handleWinner() { if ($this->winner_paid) { return false; } $btc_price = Bitcoin::toUSD(); if ($this->type == 'above') { $winner = $btc_price > $this->target_price ? $this->created_by_user_id : $this->accepted_by_user_id; } else { if ($this->type == 'under') { $winner = $btc_price < $this->target_price ? $this->created_by_user_id : $this->accepted_by_user_id; } } $this->winner_user_id = $winner; $winnings = (1 - Config::get('bitcoin.winnings_fee')) * (intval($this->bet_amount) + intval($this->cross_bet_amount)); $winner_model = User::where('id', $winner)->first(); $winner_model->addToBalance($winnings); Notify::alert("User {$winner} paid " . Bitcoin::toBTC($winnings) . " BTC"); $this->winner_paid = 1; $this->save(); return true; }
public function postDelete() { if (!Input::has('bet_id')) { return array('success' => false); } $bet_id = Input::get('bet_id'); $bet = Bet::where('id', $bet_id)->where('created_by_user_id', Auth::user()->id)->first(); if (is_null($bet)) { return array('success' => false); } else { if ($bet->canBeDeleted()) { $bet->deleted = 1; $bet->price_when_deleted = Bitcoin::toUSD(); $bet->deleted_at = time(); $bet->save(); Auth::user()->addToBalance($bet->bet_amount); return array('success' => true); } else { return array('success' => false); } } }
$token = Request::ajax() ? Request::header('X-CSRF-Token') : Input::get('_token'); if (Session::token() != $token) { throw new Illuminate\Session\TokenMismatchException(); } }); Route::filter('internal_only', function () { if ($_SERVER['REMOTE_ADDR'] != $_SERVER['SERVER_ADDR']) { die(var_dump($_SERVER['REMOTE_ADDR'])); } }); App::before(function ($request) { if ($request->getMethod() === 'POST') { Route::callRouteFilter('custom_csrf', array(), '', $request); } }); $btc_price = Bitcoin::toUSD(); View::share('btc_price', $btc_price); $updated_at = strtotime(DB::table('price_hist')->orderBy('id', 'desc')->pluck('created_at')); View::share('updated_at', $updated_at); Bet::checkExpired(); Route::get('logout', function () { Auth::logout(); return Redirect::to('/'); }); Route::get('/', function () { $prices = DB::table('price_hist')->get(); $bets = Bet::available()->paginate(4); $server_time = date('H:i:s'); return View::make('hello', compact('server_time', 'bets', 'prices')); }); Route::post('/contact/submit', function () {