Beispiel #1
0
 /**
  * create, sign and send a transaction
  *
  * @param array    $outputs             [address => value, ] or [[address, value], ] or [['address' => address, 'value' => value], ] coins to send
  *                                      value should be INT
  * @param string   $changeAddress       change address to use (autogenerated if NULL)
  * @param bool     $allowZeroConf
  * @param bool     $randomizeChangeIdx  randomize the location of the change (for increased privacy / anonimity)
  * @param string   $feeStrategy
  * @param null|int $forceFee            set a fixed fee instead of automatically calculating the correct fee, not recommended!
  * @param null|int  $returnFee          if fee is not set manually return the amount of fees in this variable
  * @return string the txid / transaction hash
  * @throws \Exception
  */
 public function pay(array $outputs, $changeAddress = null, $allowZeroConf = false, $randomizeChangeIdx = true, $feeStrategy = self::FEE_STRATEGY_OPTIMAL, $forceFee = null, &$returnFee = null)
 {
     if ($this->locked) {
         throw new \Exception("Wallet needs to be unlocked to pay");
     }
     $outputs = self::normalizeOutputsStruct($outputs);
     $txBuilder = new TransactionBuilder();
     $txBuilder->randomizeChangeOutput($randomizeChangeIdx);
     $txBuilder->setFeeStrategy($feeStrategy);
     foreach ($outputs as $output) {
         $txBuilder->addRecipient($output['address'], $output['value']);
     }
     $this->coinSelectionForTxBuilder($txBuilder, true, $allowZeroConf, $forceFee);
     $apiCheckFee = $forceFee === null;
     return $this->sendTx($txBuilder, $apiCheckFee, $returnFee);
 }