/**
  * Check if we can complete a transaction (has it got enough confirms),
  * if so, set to complete and increment the users balance
  * @param $t
  * @param $tran
  * @return bool
  */
 function completeTransaction($t, Transaction $tran)
 {
     if ($t['confirmations'] > 0) {
         if ($tran->user_id > 0) {
             $u = $tran->user;
             DB::table('users')->where('id', $u->id)->increment('balance', $t['amount']);
             $this->info("Incremented user '{$u->username}' balance by {$tran->amount}");
         } else {
             if ($tran->project_id > 0) {
                 $p = $tran->project;
                 DB::table('projects')->where('id', $p->id)->increment('project_balance', $t['amount']);
                 DB::table('projects')->where('id', $p->id)->increment('total_pledged', $t['amount']);
                 $this->info("Incremented project '{$p->id}' balance by {$tran->amount}");
                 // track anonymous pledges
                 $pledge = new Pledge();
                 $pledge->amount = $t['amount'];
                 $pledge->user_id = 0;
                 $pledge->type = "anon";
                 $pledge->project_id = $p->id;
                 $pledge->save();
             } else {
                 return false;
             }
         }
         $tran->confirmations = $t['confirmations'];
         $tran->status = 'complete';
     }
     $tran->save();
     return true;
 }
 function storePledge($amount, $type, Project $project, $user)
 {
     $pledge = new Pledge();
     $pledge->amount = $amount;
     $pledge->user_id = $user->id;
     $pledge->type = $type;
     $pledge->project_id = $project->id;
     $pledge->save();
 }