Exemple #1
0
 /**
  * @param string $blockhash
  * @return \BitWasp\Bitcoin\Block\Block
  */
 public function getblock($blockhash)
 {
     $blockArray = $this->client->execute('getblock', [$blockhash, true]);
     $this->checkNotNull($blockArray);
     // Establish batch query for loading transactions
     $txs = [];
     if (count($blockArray['tx']) > 0) {
         $this->client->batch();
         foreach ($blockArray['tx'] as $txid) {
             $this->client->execute('getrawtransaction', array($txid));
         }
         $result = $this->client->send();
         // Build the transactions
         $txs = array_map(function ($value) {
             return TransactionFactory::fromHex($value);
         }, $result);
     }
     // Build block header
     $header = new BlockHeader($blockArray['version'], @$blockArray['previousblockhash'], $blockArray['merkleroot'], $blockArray['time'], Buffer::hex($blockArray['bits']), $blockArray['nonce']);
     if (isset($blockArray['nextblockhash'])) {
         $header->setNextBlock($blockArray['nextblockhash']);
     }
     return new Block(Bitcoin::getMath(), $header, new TransactionCollection($txs));
 }