コード例 #1
0
ファイル: Uri.php プロジェクト: nmarley/bitcoin-php
 /**
  * @param NetworkInterface|null $network
  * @return string
  */
 public function uri(NetworkInterface $network = null)
 {
     if ($this->rule === self::BIP0072) {
         $address = $this->address === null ? '' : $this->address->getAddress($network);
     } else {
         $address = $this->address->getAddress($network);
     }
     $url = 'bitcoin:' . $address;
     $params = [];
     if (null !== $this->amount) {
         $params['amount'] = $this->amount;
     }
     if (null !== $this->label) {
         $params['label'] = $this->label;
     }
     if (null !== $this->message) {
         $params['message'] = $this->message;
     }
     if (null !== $this->request) {
         $params['r'] = $this->request;
     }
     if (count($params) > 0) {
         $url .= '?' . http_build_query($params);
     }
     return $url;
 }
コード例 #2
0
 /**
  * @param AddressInterface $address
  * @param NetworkInterface $network
  * @return \React\Promise\Promise
  */
 public function addressListUnspent(AddressInterface $address, NetworkInterface $network = null)
 {
     return $this->client->request('blockchain.address.listunspent', [$address->getAddress($network)])->then(function (Response $response) use($address) {
         return array_map(function (array $value) use($address) {
             return new Utxo($value['tx_hash'], $value['tx_pos'], new TransactionOutput($value['value'], ScriptFactory::scriptPubKey()->payToAddress($address)));
         }, $response->getResult());
     });
 }
コード例 #3
0
 /**
  * @param AddressInterface $address
  * @return ScriptInterface
  */
 public function payToAddress(AddressInterface $address)
 {
     $script = $address instanceof ScriptHashAddress ? ScriptFactory::create()->op('OP_HASH160')->push(Buffer::hex($address->getHash(), 20))->op('OP_EQUAL') : ScriptFactory::create()->op('OP_DUP')->op('OP_HASH160')->push(Buffer::hex($address->getHash(), 20))->op('OP_EQUALVERIFY')->op('OP_CHECKSIG');
     return $script->getScript();
 }