public static function BTC_processing() { $transaction_hash = Core::validate($_POST['transaction_hash']); $address = Core::validate($_POST['address']); $value_in_btc = Core::validate($_POST['amount']); $confirmations = Core::validate($_POST['confirmations']); if ($_GET['test'] == true) { exit; } $at_btc = new AtBtc(); $exist = $at_btc->findBy(array('address' => $address, 'type' => 0, 'done' => 0)); if ($exist == false) { return; } if ($confirmations >= BTC_CONFIRMATIONS) { $currency = new Currency(); $currency->findBy(array('Name' => 'BTC')); $limits = self::transactionLimits($currency->getId(), 'BTC', 0); if ($value_in_btc < $limits['min'] || $limits['max'] != null && $value_in_btc > $limits['max']) { return; } $bitcoin = new jsonRPCClient('http://' . BTC_RPC_USER . ':' . BTC_RPC_PASSWORD . '@' . BTC_RPC_HOST . ":" . BTC_RPC_PORT . '/'); try { $account = $bitcoin->getaccount($address); } catch (Exception $e) { return; } $wallets = WalletsBtc::findBy(array('account' => $account)); if (empty($wallets)) { return; } $feeVolume = $value_in_btc * $limits['fee']; $feeVolume = Core::round_up($feeVolume, 8); $purses = Purse::findBy(array('UID' => $at_btc->getUID(), 'CurId' => $currency->getId())); $purse = new Purse(); $purse->findById($purses[0]['id']); $purse->addValue($value_in_btc - $feeVolume); $purse->save(); $wallet = new WalletsBtc(); $wallet->findById($wallets[0]['id']); $profit = $feeVolume * $wallet->getShare(); $wallet->setProfit($wallet->getProfit() + $profit); $wallet->save(); $at_btc->setDone(1); $at_btc->setTransactionHash($transaction_hash); $at_btc->setValue($value_in_btc); $at_btc->setTimestamp(Core::timestamp_gmp()); $at_btc->save(); } }
public static function addNewBTCWallet() { $account = Core::validate($_POST['ACCOUNT']); $share = Core::validate($_POST['SHARE']); // percent if ($account == null || $share == null || !Core::isDouble($share)) { print 'Incorrect input data'; exit; } $result = WalletsBtc::findBy(array('account' => $account)); if (!empty($result)) { print 'This account already exists'; exit; } $bitcoin = new jsonRPCClient('http://' . BTC_RPC_USER . ':' . BTC_RPC_PASSWORD . '@' . BTC_RPC_HOST . ':' . BTC_RPC_PORT . '/'); try { $balance = $bitcoin->getbalance($account); } catch (Exception $e) { print $e; exit; } $wallet = new WalletsBtc(); $wallet->setAccount($account); $wallet->setValue($balance); $wallet->setShare($share / 100.0); $wallet->insert(); header('Location: /admin/btc'); }