function bca_make_transaction($denomination, $fromAccount, $toAccount, $amount, $options = array())
 {
     $t = new Transaction();
     $t->setFromAccount($fromAccount);
     $t->setToAccount($toAccount);
     $t->setAmount($denomination, $amount);
     if (isset($options["notice"])) {
         $t->setNotice($options["notice"]);
     }
     if (isset($options["confirming"])) {
         $t->setUseConfirming($options["confirming"]);
     }
     $t->perform();
     return $t->id;
 }
Esempio n. 2
0
 /**
  * Withdraw funds.
  * If withdraw processing is manual, the transaction will
  * be stored as scheduled. If withdraw processing is automatic
  * the transaction will be performed immediately.
  */
 public function withdraw($denomination, $address, $amount)
 {
     if ($amount < 0 || $amount > $this->getBalance($denomination)) {
         throw new Exception("Insufficient funds on account.");
     }
     if ($this->hasConfirming()) {
         throw new Exception("There are unconfirmed transactions for the account.");
     }
     if ($this->entity_type != "user") {
         throw new Exception("Can only withdraw from user accounts.");
     }
     $this->balance -= BitcoinUtil::toSatoshi($denomination, $amount);
     $t = new Transaction();
     $t->withdrawAddress = $address;
     $t->fromAccountId = $this->id;
     $t->fromAccountBalance = $this->balance;
     $t->setAmount($denomination, $amount);
     $t->state = Transaction::SCHEDULED;
     $t->notice = "Withdraw";
     $t->save();
     $this->save();
     if (get_option("blockchainaccounts_withdraw_processing") == "auto") {
         $t->performWithdraw();
     }
     return $t;
 }