<commit_before><?php

namespace BitWasp\Bitcoin\Rpc\Client;

use BitWasp\Bitcoin\Block\BlockFactory;
use BitWasp\Buffertools\Buffer;
use BitWasp\Bitcoin\JsonRpc\JsonRpcClient;
use BitWasp\Bitcoin\Transaction\TransactionFactory;
use BitWasp\Bitcoin\Transaction\TransactionInterface;

class Bitcoind
{
    /**
     * @var JsonRpcClient
     */
    protected $client;

    /**
     * @param JsonRpcClient $client
     */
    public function __construct(JsonRpcClient $client)
    {
        $this->client = $client;
    }

    public function getinfo()
    {
        $info = $this->client->execute('getinfo');
        return $info;
    }

    /**
     * @return mixed
     */
    public function getbestblockhash()
    {
        $hash = $this->client->execute('getbestblockhash');
        return $hash;
    }

    /**
     * @param $blockHeight
     * @return mixed
     */
    public function getblockhash($blockHeight)
    {
        $hash = $this->client->execute('getblockhash', array($blockHeight));
        return $hash;
    }

    /**
     * @param $blockhash
     * @return \BitWasp\Bitcoin\Block\Block
     */
    public function getblock($blockhash)
    {
        $blockArray = $this->client->execute('getblock', array($blockhash, true));
        $block = BlockFactory::create();

        // Build block header
        $block->getHeader()
            ->setVersion($blockArray['version'])
            ->setBits(Buffer::hex($blockArray['bits']))
            ->setTimestamp($blockArray['time'])
            ->setMerkleRoot($blockArray['merkleroot'])
            ->setNonce($blockArray['nonce'])
            ->setPrevBlock(@$blockArray['previousblockhash']) // only @ this because of genesis block
            ->setNextBlock(@$blockArray['nextblockhash']);

        // Establish batch query for loading transactions
        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
            $block->getTransactions()->addTransactions(
                array_map(function ($value) {
                    return TransactionFactory::fromHex($value);
                }, $result)
            );

        }

        return $block;
    }

    /**
     * @param $txid
     * @param bool $verbose
     * @return TransactionInterface
     * @throws \Exception
     */
    public function getrawtransaction($txid, $verbose = false)
    {
        $tx = $this->client->execute('getrawtransaction', array($txid));
        if ($tx === false) {
            throw new \Exception('FALSE from rpc?');
        }
        if ($verbose) {
            $tx = TransactionFactory::fromHex($tx);
        }

        return $tx;
    }

    /**
     * @param TransactionInterface $transaction
     * @param bool $allowExtremeFees
     * @return mixed
     */
    public function sendrawtransaction(TransactionInterface $transaction, $allowExtremeFees = false)
    {
        $hex = $transaction->getBuffer()->getHex();
        $send = $this->client->execute('sendrawtransaction', array($hex, $allowExtremeFees));
        return $send;
    }
}<commit_msg>Bitcoind RPC Add function to throw exception when null is returned. Also removed check against false in bitcoind<commit_after><?php

namespace BitWasp\Bitcoin\Rpc\Client;

use BitWasp\Bitcoin\Block\BlockFactory;
use BitWasp\Buffertools\Buffer;
use BitWasp\Bitcoin\JsonRpc\JsonRpcClient;
use BitWasp\Bitcoin\Transaction\TransactionFactory;
use BitWasp\Bitcoin\Transaction\TransactionInterface;

class Bitcoind
{
    /**
     * @var JsonRpcClient
     */
    protected $client;

    /**
     * @param JsonRpcClient $client
     */
    public function __construct(JsonRpcClient $client)
    {
        $this->client = $client;
    }

    private function checkNotNull($result)
    {
        if (null === $result) {
            throw new \Exception('Received no response from server');
        }
    }

    public function getinfo()
    {
        $info = $this->client->execute('getinfo');
        $this->checkNotNull($info);

        return $info;
    }

    /**
     * @return mixed
     */
    public function getbestblockhash()
    {
        $hash = $this->client->execute('getbestblockhash');
        return $hash;
    }

    /**
     * @param $blockHeight
     * @return mixed
     */
    public function getblockhash($blockHeight)
    {
        $hash = $this->client->execute('getblockhash', array($blockHeight));
        return $hash;
    }

    /**
     * @param $blockhash
     * @return \BitWasp\Bitcoin\Block\Block
     */
    public function getblock($blockhash)
    {
        $blockArray = $this->client->execute('getblock', array($blockhash, true));
        $block = BlockFactory::create();

        // Build block header
        $block->getHeader()
            ->setVersion($blockArray['version'])
            ->setBits(Buffer::hex($blockArray['bits']))
            ->setTimestamp($blockArray['time'])
            ->setMerkleRoot($blockArray['merkleroot'])
            ->setNonce($blockArray['nonce'])
            ->setPrevBlock(@$blockArray['previousblockhash']) // only @ this because of genesis block
            ->setNextBlock(@$blockArray['nextblockhash']);

        // Establish batch query for loading transactions
        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
            $block->getTransactions()->addTransactions(
                array_map(function ($value) {
                    return TransactionFactory::fromHex($value);
                }, $result)
            );

        }

        return $block;
    }

    /**
     * @param $txid
     * @param bool $verbose
     * @return TransactionInterface
     * @throws \Exception
     */
    public function getrawtransaction($txid, $verbose = false)
    {
        $tx = $this->client->execute('getrawtransaction', array($txid));
        $this->checkNotNull($tx);

        if ($verbose) {
            $tx = TransactionFactory::fromHex($tx);
        }

        return $tx;
    }

    /**
     * @param TransactionInterface $transaction
     * @param bool $allowExtremeFees
     * @return mixed
     */
    public function sendrawtransaction(TransactionInterface $transaction, $allowExtremeFees = false)
    {
        $hex = $transaction->getBuffer()->getHex();
        $send = $this->client->execute('sendrawtransaction', array($hex, $allowExtremeFees));
        return $send;
    }
}
{'fraction_non_alphanumeric': 0.14015654999261556, 'fraction_numerical': 0.0002953773445576724, 'mean_word_length': 2.2636144578313253, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2460025', 'n_tokens_mistral': 1905, 'n_tokens_neox': 1868, 'n_words': 360}