Exemple #1
0
 /**
  * @param array|TransactionListResult[] $transactions
  * @return Deposit[]
  */
 public function saveNewDeposits(array $transactions)
 {
     $deposits = [];
     foreach ($transactions as $transaction) {
         $this->round->getStats()->setLastCheckedTx($transaction->getTxId());
         if ($account = $this->accountRepo->findOneBy(['depositAddress' => $transaction->getAddress(), 'round' => $this->round])) {
             /* @var $account Account */
             if ($transaction->getAmount() < $this->round->getMinDeposit()) {
                 $this->round->getStats()->addTotalDonation($transaction->getAmount());
                 continue;
             }
             $amount = min($this->round->getMaxDeposit(), $transaction->getAmount());
             $donation = $transaction->getAmount() - $amount;
             if ($donation) {
                 $this->round->getStats()->addTotalDonation($donation);
             }
             $deposit = $deposits[] = new Deposit();
             $deposit->setAmount($amount);
             $deposit->setConfirmations($transaction->getConfirmations());
             $deposit->setReceivedTime($transaction->getTime());
             if ($deposit->getConfirmations() >= $this->round->getMinConfirmations()) {
                 $deposit->setConfirmed(true);
             }
             $deposit->setTxIn($transaction->getTxId());
             $deposit->setAccount($account);
             $this->payoutManager->createPayout($deposit);
             $this->em->persist($deposit);
             $this->em->flush();
         }
     }
     $this->em->flush();
     return $deposits;
 }
 private function checkRoundEnd()
 {
     $time1 = new \DateTime();
     $time1->modify('-' . $this->round->getRoundTime() . ' hours');
     if ($this->round->getRoundTimeType() == Round::ROUND_TIME_TYPE_LAST_DEPOSIT) {
         $time2 = $this->round->getStats()->getLastDeposit();
     } else {
         $time2 = $this->round->getStats()->getLastPayout();
     }
     if ($time2 && $time1 > $time2) {
         $this->writeln('Round finished');
         $this->payoutManager->realiseRoundEndPayouts();
         $this->roundManager->startNextRound();
     } else {
         $this->writeln('Round not finished');
     }
 }