/** * Get balance update. */ public function balanceUpdate() { set_exception_handler(array($this, "handleException")); session_write_close(); $account = Account::getCurrentUserAccount(); if (!$account) { throw new Exception("Not logged in"); } $pubSub = $account->getPubSub(); //$pubSub->setTimeout(5); $pubSub->subscribe(); $account = Account::getCurrentUserAccount(); if ($account->getBalance("satoshi") != $_REQUEST["balance"] || $account->getConfirmingAmount("satoshi") != $_REQUEST["confirming"] || $account->getConfirmingBalance("satoshi") != $_REQUEST["confirmingBalance"]) { $this->printAccountResponse($account); $pubSub->close(); exit; } $pubSub->wait(); $account = Account::getCurrentUserAccount(); $this->printAccountResponse($account); exit; }
<?php require_once __DIR__ . "/src/utils/WpUtil.php"; require_once __DIR__ . "/src/model/Transaction.php"; require_once __DIR__ . "/src/model/Account.php"; use wpblockchainaccounts\WpUtil; use wpblockchainaccounts\Transaction; use wpblockchainaccounts\Account; require_once WpUtil::getWpLoadPath(); $account = Account::getCurrentUserAccount(); if (!$account) { return "<i>not logged in</i>"; } try { if (!$_REQUEST["address"]) { throw new Exception("Please enter the address to withdraw to."); } if (!$_REQUEST["amount"]) { throw new Exception("Please enter the amount to withdraw."); } $address = $_REQUEST["address"]; $amount = $_REQUEST["amount"]; $_REQUEST["address"] = ""; $_REQUEST["amount"] = ""; $t = $account->withdraw($_REQUEST["denomination"], $address, $amount); switch ($t->getState()) { case Transaction::COMPLETE: $_SESSION["bca_withdraw_success"] = "The withdrawal has been processed."; break; case Transaction::SCHEDULED: $_SESSION["bca_withdraw_success"] = "Your withdrawal has been initiated.<br/>" . "Please see your account history for progress.";