コード例 #1
0
ファイル: DepositManager.php プロジェクト: RinWorld/Ponzi-1
 /**
  * @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;
 }
コード例 #2
0
ファイル: RoundFixtures.php プロジェクト: RinWorld/Ponzi-1
 public function load(ObjectManager $manager)
 {
     $round = new Round();
     $round->setStarted(true);
     $round->setWalletAccount('ponzi');
     $manager->persist($round);
     $manager->flush();
 }
コード例 #3
0
 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');
     }
 }
コード例 #4
0
ファイル: WalletManager.php プロジェクト: RinWorld/Ponzi-1
 /**
  * @param Payout[] $payouts
  * @return PayoutTx the tx out
  */
 public function sendPayouts(array $payouts)
 {
     $amounts = [];
     foreach ($payouts as $payout) {
         if (!isset($amounts[$payout->getAccount()->getWithdrawAddress()])) {
             $amounts[$payout->getAccount()->getWithdrawAddress()] = 0;
         }
         $amounts[$payout->getAccount()->getWithdrawAddress()] += $payout->getAmount();
     }
     $tx = $this->manager->sendMany($this->round->getWalletAccount(), $amounts);
     $walletTx = $this->manager->getTransaction($tx);
     $tx = new PayoutTx();
     $tx->setTxFee($walletTx->getFee());
     $tx->setTxOut($walletTx->getTxId());
     $this->em->persist($tx);
     $this->em->flush();
     return $tx;
 }
コード例 #5
0
ファイル: PayoutManager.php プロジェクト: RinWorld/Ponzi-1
 /**
  * @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;
 }
コード例 #6
0
ファイル: AdminController.php プロジェクト: RinWorld/Ponzi-1
 /**
  * @Route("/round/{round}", name="admin_round", defaults={"round" = null})
  * @Template()
  */
 public function roundAction(Request $request, Round $round = null)
 {
     $this->checkIp($request);
     // new round defining
     if (!$round) {
         $round = new Round();
         if (!($currentRound = $this->roundRepo->findOneBy(['started' => true, 'finished' => false]))) {
             // first round auto start
             $roundId = 1;
         } else {
             $lastRound = $this->roundRepo->findOneBy([], ['id' => 'desc']);
             $roundId = $lastRound->getId() + 1;
         }
     } else {
         $roundId = $round->getId();
     }
     $form = $this->createForm(new RoundType(), $round);
     if ($request->isMethod('post')) {
         $form->submit($request);
         if ($form->isValid()) {
             if ($roundId == 1) {
                 $round->setStarted(true);
             }
             $this->em->persist($round);
             $this->em->flush();
             $this->roundManager->defineWalletAccount($round);
             return $this->redirect($this->generateUrl('admin'));
         }
     }
     return $this->render('AppBundle:Admin:round.html.twig', ['round' => $round, 'roundId' => $roundId, 'form' => $form->createView()]);
 }
コード例 #7
0
ファイル: RoundManager.php プロジェクト: RinWorld/Ponzi-1
 public function defineWalletAccount(Round $round)
 {
     $round->setWalletAccount($this->walletAccountPrefix . $round->getId());
     $this->em->flush($round);
 }