Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 /**
  * @param array|Payout[] $payouts
  * @return array|Payout[]
  * @throws \Bml\CoinBundle\Exception\RequestException
  * @throws \Exception
  */
 private function _realisePayouts(array $payouts)
 {
     $sumPayout = 0;
     foreach ($payouts as $payout) {
         $sumPayout += $payout->getAmount();
     }
     do {
         if ($sumPayout < $this->round->getMinDeposit()) {
             // we will not payout less than min deposit
             // this is probably only paying out referrer
             // referrer payout amount is less than payout tx fee
             // it makes no sense to pay it out alone
             return [];
         }
         try {
             $tx = $this->walletManager->sendPayouts($payouts);
         } catch (RequestException $e) {
             if ($e->getCode() != -6) {
                 throw $e;
             }
             // this is probably insufficient founds error
             // that's because of fee added by client
             // we will try to pop last payout to see if then we will fit within fee+payout_amount<balance
             $last = array_pop($payouts);
             /* @var $payout Payout */
             $sumPayout -= $last->getAmount();
             continue;
         }
         foreach ($payouts as $payout) {
             $payout->setPaid(true);
             $payout->setTx($tx);
             $payout->setPaidOutTime(new \DateTime());
         }
         $this->em->flush();
         break;
     } while (!empty($payouts));
     return $payouts;
 }