/** * Get deposit address. * Create if it doesn't exist. */ public function getDepositAddress() { if (!CryptoAccountsPlugin::instance()->isSetup()) { return NULL; } if (!$this->depositAddress) { $wallet = CryptoAccountsPlugin::instance()->getWallet(); $this->depositAddress = $wallet->createNewAddress(); $this->save(); } return $this->depositAddress; }
/** * Perform withdrawal. */ public function performWithdraw() { if ($this->state != Transaction::SCHEDULED) { throw new Exception("Unexpected transaction state: " . $this->state); } if ($this->amount < 0) { throw new Exception("Negative amount for transaction."); } $wallet = CryptoAccountsPlugin::instance()->getWallet(); $this->transactionHash = $wallet->send($this->withdrawAddress, $this->amount); $this->state = Transaction::COMPLETE; $this->save(); }
/** * Set up the test. */ public function setUp() { parent::setUp(); CryptoAccountsPlugin::instance()->activate(); update_option("blockchainaccounts_wallet_type", "mock"); }
*/ require_once __DIR__ . "/src/plugin/CryptoAccountsPlugin.php"; require_once __DIR__ . "/src/controller/ShortcodeController.php"; require_once __DIR__ . "/src/controller/SettingsController.php"; require_once __DIR__ . "/src/utils/WpUtil.php"; require_once __DIR__ . "/src/model/Account.php"; require_once __DIR__ . "/src/model/Transaction.php"; require_once __DIR__ . "/src/controller/AccountController.php"; use wpblockchainaccounts\WpUtil; use wpblockchainaccounts\CryptoAccountsPlugin; use wpblockchainaccounts\ShortcodeController; use wpblockchainaccounts\SettingsController; use wpblockchainaccounts\Account; use wpblockchainaccounts\Transaction; use wpblockchainaccounts\AccountController; CryptoAccountsPlugin::instance(); ShortcodeController::instance(); AccountController::instance(); if (is_admin()) { SettingsController::instance(); } // Get a reference to a user account. if (!function_exists("bca_user_account")) { function bca_user_account($user) { return Account::getUserAccount($user); } } // Get a reference to an entity account. if (!function_exists("bca_entity_account")) { function bca_entity_account($entity_type, $entity_id)
/** * Create the settings page. */ public function create_settings_page() { $template = new Template(__DIR__ . "/../template/settings.tpl.php"); if (isset($_REQUEST["settings-updated"]) && $_REQUEST["settings-updated"]) { if (CryptoAccountsPlugin::instance()->isSetup()) { $wallet = CryptoAccountsPlugin::instance()->getWallet(); try { $info = $wallet->setup(); if ($info) { $template->set("message", $info); } } catch (Exception $e) { $template->set("error", "Error initializing wallet: " . $e->getMessage()); } } } $tab = "setup"; if (isset($_REQUEST["tab"])) { $tab = $_REQUEST["tab"]; } if ($tab == "withdraw" && $_REQUEST["transactionIds"]) { $wallet = CryptoAccountsPlugin::instance()->getWallet(); $wallet->setPassword($_REQUEST["password"]); try { foreach ($_REQUEST["transactionIds"] as $transactionId) { $transaction = Transaction::findOne($transactionId); $transaction->performWithdraw(); } $template->set("message", "Transactions completed."); } catch (Exception $e) { $template->set("error", $e->getMessage()); } } if ($tab == "withdraw") { $denomination = "btc"; $totalAmount = 0; $transactionViews = array(); $transactions = Transaction::findAllBy("state", Transaction::SCHEDULED); foreach ($transactions as $transaction) { $user = $transaction->getFromAccount()->getUser(); $transactionView = array("id" => $transaction->id, "when" => human_time_diff(time(), $transaction->timestamp) . " ago", "user" => $user->display_name . " (" . $user->user_email . ")", "amount" => $transaction->getAmount($denomination) . " " . $denomination); $transactionViews[] = $transactionView; $totalAmount += $transaction->getAmount($denomination); } $wallet = CryptoAccountsPlugin::instance()->getWallet(); $template->set("passwordLabel", $wallet->getPasswordLabel()); $template->set("transactions", $transactionViews); } $template->set("tab", $tab); $template->set("totalAmount", $totalAmount . " " . $denomination); $template->show(); }
public function setUp() { parent::setUp(); CryptoAccountsPlugin::instance()->activate(); }