예제 #1
0
 /**
  * Get to account.
  */
 public function getToAccount()
 {
     if (!$this->toAccount) {
         $this->toAccount = Account::findOne($this->toAccountId);
     }
     if (!$this->toAccount) {
         throw new Exception("No target account for transaction!");
     }
     return $this->toAccount;
 }
 /**
  * Process incomming request.
  */
 public function process($payload)
 {
     if ($payload["type"] != "address") {
         return;
     }
     $data = $payload["data"];
     if (!$data["txid"]) {
         throw new Exception("No transaction id");
     }
     if (!$data["address"]) {
         throw new Exception("No address");
     }
     if (!$data["balance_change"]) {
         throw new Exception("No amount data");
     }
     $transaction = Transaction::findOneBy("transactionHash", $data["txid"]);
     if (!$transaction) {
         $account = Account::findOneBy("depositAddress", $data["address"]);
         if (!$account) {
             throw new Exception("No matching account.");
         }
         $transaction = new Transaction();
         $transaction->notice = "Deposit";
         $transaction->transactionHash = $data["txid"];
         $transaction->toAccountId = $account->id;
         $transaction->state = Transaction::CONFIRMING;
         $transaction->amount = BitcoinUtil::toSatoshi("btc", $data["balance_change"]);
         $transaction->save();
         $account->getPubSub()->publish();
     }
     if ($transaction->getState() == Transaction::COMPLETE) {
         return;
     }
     $transaction->confirmations = intval($data["confirmations"]);
     $account = $transaction->getToAccount();
     if (!$account) {
         throw new Exception("unable to find account");
     }
     if ($transaction->confirmations >= get_option("blockchainaccounts_notifications")) {
         $account->balance += $transaction->amount;
         $account->save();
         $transaction->toAccountBalance = $account->balance;
         $transaction->timestamp = time();
         $transaction->state = Transaction::COMPLETE;
         $transaction->save();
     }
     $transaction->save();
     $account->getPubSub()->publish();
 }
 /**
  * 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;
 }
 /**
  * Uninstall.
  */
 public static function uninstall()
 {
     Account::uninstall();
     Transaction::uninstall();
 }
예제 #5
0
<?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.";
 function bca_entity_account($entity_type, $entity_id)
 {
     return Account::getEntityAccount($entity_type, $entity_id);
 }
예제 #7
0
 /**
  * Get pub sub.
  */
 public function getPubSub()
 {
     if (!$this->pubSub) {
         Account::ensureNotificationsDirExists();
         $dir = Account::getNotificationsDir();
         $fn = $this->entity_type . ":" . $this->entity_id;
         $this->pubSub = new PubSub($dir . "/" . $fn);
     }
     return $this->pubSub;
 }
    $account = Account::findOneBy("depositAddress", $_REQUEST["input_address"]);
    if (!$account) {
        exit("no associated account or transaction");
    }
    $transaction = new Transaction();
    $transaction->notice = "Deposit";
    $transaction->transactionHash = $_REQUEST["transaction_hash"];
    $transaction->toAccountId = $account->id;
    $transaction->state = Transaction::CONFIRMING;
    $transaction->amount = $_REQUEST["value"];
    $transaction->save();
}
if ($transaction->state == Transaction::COMPLETE) {
    exit("*ok*");
}
$transaction->confirmations = $_REQUEST["confirmations"];
if ($transaction->confirmations >= get_option("blockchainaccounts_notifications")) {
    $account = Account::findOneBy("id", $transaction->toAccountId);
    if (!$account) {
        exit("unable to find account");
    }
    $account->balance += $transaction->amount;
    $account->save();
    $transaction->toAccountBalance = $account->balance;
    $transaction->timestamp = time();
    $transaction->state = Transaction::COMPLETE;
    $transaction->save();
    exit("*ok*");
}
$transaction->save();
echo "processing...";