[
  {
    "path": ".gitattributes",
    "content": "test/ export-ignore\nphpunit.xml.dist export-ignore\n"
  },
  {
    "path": ".gitignore",
    "content": "bin/\nbuild/logs/\ndocs/api/\ndocs/code-coverage/\nvendor/\ncomposer.lock\nphpdoc.xml\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: php\n\nphp:\n    - 7\n    - 5.6\n    - 5.5\n    - 5.4\n\nbranches:\n    only:\n        - 1.x\n        - 2.x\n        - master\n\nnotifications:\n    email: false\n    irc: \"chat.freenode.net#dspacelabs\"\n\ninstall:\n    - composer require \"codeclimate/php-test-reporter:*\" -n\n    - composer install\n\nscript:\n    - php bin/phpunit\n\nafter_script:\n    - bin/test-reporter --stdout > codeclimate.json\n    - \"curl -X POST -d @codeclimate.json -H 'Content-Type: application/json' -H 'User-Agent: Code Climate (PHP Test Reporter v0.1.1)' https://codeclimate.com/test_reports\"\n"
  },
  {
    "path": "Berksfile",
    "content": "source \"https://supermarket.chef.io\"\n\ncookbook \"bitcoind\"\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "Change log\n==========\n\n## [Unreleased]\n\n### Added\n### Updated\n### Fixed\n### Changed\n\n\n## [2.1.0] - 2017-12-22\n\n### Added\n\n- travis notifies irc channel #dspacelabs\n\n### Updated\n\n- [#18] Avoid reliance on own PSR-7 implementation\n- [#29] Added Test Case for CurlDriver\n\n## [2.0.2] - 2015-05-27\n\n### Fixed\n\n- [#16] incompatible with psr/http-message current version\n\n## [2.0.1] - 2015-03-27\n\n### Added\n\n- Added Vagrant file to setup and configure nodes\n\n### Fixed\n\n- Small issue with the CurlDriver\n\n\n## [2.0.0] - 2015-03-22\n\nInitial release of 2.x\n\n### Added\n\n- Message\n- Streamable\n- Request\n- Response\n- Command\n\n### Changed\n\n- Complete Rewrite of Library\n\n### Deprecated\n\n- 1.x Releases\n\n[unreleased]: https://github.com/nbobtc/bitcoind-php/compare/2.1.0...2.x\n[2.1.0]: https://github.com/nbobtc/bitcoind-php/compare/2.0.2...2.1.0\n[2.0.2]: https://github.com/nbobtc/bitcoind-php/compare/2.0.1...2.0.2\n[2.0.1]: https://github.com/nbobtc/bitcoind-php/compare/2.0.0...2.0.1\n[2.0.0]: https://github.com/nbobtc/bitcoind-php/compare/2d30e2f9ee617f44336581386cd0734613c7353d...2.0.0\n[#16]: https://github.com/nbobtc/bitcoind-php/issues/16\n[#18]: https://github.com/nbobtc/bitcoind-php/pull/18\n[#29]: https://github.com/nbobtc/bitcoind-php/pull/29\n"
  },
  {
    "path": "CONTRIBUTING.md",
    "content": "Contributing Guidelines\n=======================\n\nThis project uses some standards such as [PSR-1], [PSR-2], [PSR-3], and [PSR-4]\nalong with some standards that are being purposed.\n\n## Getting Started\n\n* Fork repository\n* Pull requests should be on the develop branch.\n* Code must conform to [PSR-1] and [PSR-2] standards.\n\n## Finding Something to Work on\n\n- Check out the [CodeClimate] issues page for this project.\n- Check out the [GitHub Issues] page for this project.\n- Check out [SensioLabs Insight] page for this project.\n\n## Documentation\n\nFeel free to add your own examples or usage to the documentation. If something\nisn't clear, go head and submit a PR with your updated paragraph.\n\n## Donate\n\nConsider donating some [16yRSB46xMeWKfWtqcuqSVV7B2eSjkd92D]\n\n\n[PSR-1]: http://www.php-fig.org/psr/psr-1/\n[PSR-2]: http://www.php-fig.org/psr/psr-2/\n[PSR-3]: http://www.php-fig.org/psr/psr-3/\n[PSR-4]: http://www.php-fig.org/psr/psr-4/\n[CodeClimate]: https://codeclimate.com/github/nbobtc/bitcoind-php/issues\n[GitHub Issues]: https://github.com/nbobtc/bitcoind-php/issues\n[SensioLabs Insight]: https://insight.sensiolabs.com/projects/c7af9182-f53b-4164-820d-46e7499252f3\n[16yRSB46xMeWKfWtqcuqSVV7B2eSjkd92D]: bitcoin://16yRSB46xMeWKfWtqcuqSVV7B2eSjkd92D\n"
  },
  {
    "path": "LICENSE",
    "content": "Copyright (C) 2012-2015 Joshua Estes\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "nbobtc/bitcoind-php [![Travis branch](https://img.shields.io/travis/nbobtc/bitcoind-php/2.x.svg)](https://travis-ci.org/nbobtc/bitcoind-php) [![Packagist](https://img.shields.io/packagist/v/nbobtc/bitcoind-php.svg)](https://packagist.org/packages/nbobtc/bitcoind-php) [![Packagist Pre Release](https://img.shields.io/packagist/vpre/nbobtc/bitcoind-php.svg)](https://packagist.org/packages/nbobtc/bitcoind-php)\n===================\n\n[![Code Climate](https://img.shields.io/codeclimate/github/nbobtc/bitcoind-php.svg)](https://codeclimate.com/github/nbobtc/bitcoind-php) [![Code Climate](https://img.shields.io/codeclimate/coverage/github/nbobtc/bitcoind-php.svg)](https://codeclimate.com/github/nbobtc/bitcoind-php) [![SensioLabs Insight](https://img.shields.io/sensiolabs/i/c7af9182-f53b-4164-820d-46e7499252f3.svg)](https://insight.sensiolabs.com/projects/c7af9182-f53b-4164-820d-46e7499252f3)\n\nThis project is used to interact with a headless bitcoin program called\nbitcoind. It also contains various utility classes for working with Bitcoin as a\nPHP Developer.\n\n## Installation\n\nYou can install this library by using [Composer]. You can also view more info\nabout this on [Packagist].\n\n```bash\ncomposer require nbobtc/bitcoind-php\n```\n\n## Usage\n\nTo use the project you need to just create a new instance of the class.\n\n```php\n<?php\n\nrequire __DIR__ . '/vendor/autoload.php';\n\n$command = new \\Nbobtc\\Command\\Command('getinfo');\n$client  = new \\Nbobtc\\Http\\Client('https://username:password@localhost:18332');\n\n/** @var \\Nbobtc\\Http\\Message\\Response */\n$response = $client->sendCommand($command);\n\n/** @var string */\n$contents = $response->getBody()->getContents();\necho $contents;\n\n\n```\n\nYou are able to get the [Request] and [Response] objects back from\nthe client with the correct getters: `getRequest()` and `getResponse()`.\n\nYou can also parse the response however you wish to do so since the result is\nreturned to you as a string. See below for some ideas!\n\n## Commands\n\nCommands are created in such a way that this will support any future updates the\n[Bitcoin API] by providing you with an easy class that sets all the required\ninformation.\n\nYou are able to pass into the object the `method` and the `parameters` that are\nrequired. Here are a few examples:\n\n```php\n// No Parameters\n$command = new Command('getinfo');\n\n// One Parameter\n$command = new Command('getblock', '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f');\n\n// Multiple Parameters\n$command = new Command('sendfrom', array('fromaccount', 'tobitcoinaddress', 'amount'));\n```\n\nThe second argument MUST be in the same order as on the [Bitcoin API] wiki page.\nThere is no need to assign the values any keys.\n\n### Parameters\n\nParameters are the second argument when creating a new Command. This argument\ncan either be a string OR an array. For example, both of these are valid.\n\n```php\n$command = new Command('getblock', array('000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'));\n$command = new Command('getblock', '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f');\n```\n\nMost commands in the [Bitcoin API] take one parameter. If it takes MORE than\none, you must pass the parameters in as an array in the ORDER you find them on\nthat page.\n\n### Extending Commands\n\nIf, for any reason, you need to extend a command, it MUST implement\n[CommandInterface]. You can find documentation within the interface on how to\nimplement this.\n\n## Drivers\n\nDrivers are used by the ClientInterface for connecting to a bitcoind service and\nsending Requests. The return a Response. If you need to implement a new driver\ntake a look at the [DriverInterface].\n\n### cURL Driver\n\nThis is used by default and allows you a lot of options for customizing it to\nyour needs.\n\nYou can set various [cURL Options] by passing them into the function\n`addCurlOption($option, $value)`.\n\nHere's an example of how to configure and use the driver.\n\n```php\n$driver = new \\Nbobtc\\Http\\Driver\\CurlDriver();\n$driver\n    ->addCurlOption(CURLOPT_VERBOSE, true)\n    ->addCurlOption(CURLOPT_STDERR, '/var/logs/curl.err');\n\n$client = new \\Nbobtc\\Http\\Client('https://username:password@localhost:18332');\n$client->withDriver($driver);\n```\n\nFeel free to take a look at the `CurlDriver` source code.\n\n## Cookbook\n\n### How to enable a Keep-Alive ie Persistent Connection\n\nThis example shows how you are able to set the client up to [Persistent\nConnection].\n\n```php\n$client = new \\Nbobtc\\Http\\Client('https://username:password@localhost:18332');\n$client->getRequest()->withHeader('Connection', 'Keep-Alive');\n```\n\n### How to set a CA Cert\n\nThis library provides some wonderful flexibility that will allow you to\nconfigure the client to use your own CA Cert.\n\n```php\n$driver = new \\Nbobtc\\Http\\Driver\\CurlDriver();\n$driver->addCurlOption(CURLOPT_CAINFO, '/path/to/cert');\n\n$client = new \\Nbobtc\\Http\\Client('https://username:password@localhost:18332');\n$client->withDriver($driver);\n```\n\n### How to Convert Output to an Array\n\nSome like the arrays\n\n```php\n$response = $client->sendCommand($command);\n$output   = json_decode($response->getBody()->getContents(), true);\n```\n\n### How to Convert Output to a stdClass object\n\nSome like the objects\n\n```php\n$response = $client->sendCommand($command);\n$output   = json_decode($response->getBody()->getContents());\n```\n\n## Testing\n\nAll testing is done using PHPUnit. You should be able to run `phpunit` in the\nroot directory of this project (the directory where phpunit.xml.dist is located)\nand the tests will run.\n\nIf submitting a pull request or working on this library, please make sure that\nthe tests will pass.\n\n## Change log\n\nSee [CHANGELOG.md].\n\nContains information on releases such as what was added, changed, etc. It's good\nto look at to see what has changed from release to release.\n\n## Contributing\n\nSee [CONTRIBUTING.md].\n\nVarious ways on contributing to this project.\n\n## Branching\n\n### master\n\nThis is the latest and greatest, it should not be used an is considered\ndevelopment for testing new features and functionality. This should NOT be used\nin a production environment.\n\n### 2.x\n\nCurrent production branch. All 2.x tags come off of this branch.\n\n### 1.x\n\nDeprecated, only used for bug fixes and for historical records.\n\n## License (MIT) [![Packagist](https://img.shields.io/packagist/l/nbobtc/bitcoind-php.svg)](https://github.com/nbobtc/bitcoind-php/blob/2.x/LICENSE)\n\nCopyright (C) 2012-2018 Joshua Estes\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n[Composer]: https://getcomposer.org/\n[Packagist]: https://packagist.org/packages/nbobtc/bitcoind-php\n[CHANGELOG.md]: https://github.com/nbobtc/bitcoind-php/blob/2.x/CHANGELOG.md\n[CONTRIBUTING.md]: https://github.com/nbobtc/bitcoind-php/blob/2.x/CONTRIBUTING.md\n[Bitcoin API]: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list\n[Persistent Connection]: http://en.wikipedia.org/wiki/HTTP_persistent_connection\n[cURL Options]: http://php.net/manual/en/function.curl-setopt.php\n[Releases]: https://github.com/nbobtc/bitcoind-php/releases\n[CommandInterface]: https://github.com/nbobtc/bitcoind-php/blob/2.x/src/Command/CommandInterface.php\n[Request]: https://github.com/nbobtc/bitcoind-php/blob/2.x/src/Http/Message/Request.php\n[Response]: https://github.com/nbobtc/bitcoind-php/blob/2.x/src/Http/Message/Response.php\n[DriverInterface]: https://github.com/nbobtc/bitcoind-php/blob/2.x/src/Http/Driver/DriverInterface.php\n"
  },
  {
    "path": "Vagrantfile",
    "content": "# -*- mode: ruby -*-\n# vi: set ft=ruby :\nVagrant.configure(2) do |config|\n  config.berkshelf.enabled = true\n  config.vm.box = \"ubuntu/trusty64\"\n\n  config.vm.define \"node01\" do |node01|\n    node01.vm.network \"private_network\", ip: \"192.168.33.10\"\n    node01.vm.network \"forwarded_port\", guest: 19332, host: 18332\n   node01.vm.provision \"chef_solo\" do |chef|\n      chef.add_recipe \"bitcoind\"\n      chef.json = {\n        \"bitcoind\" => {\n          \"config\" => {\n            \"options\" => {\n              \"regtest\"     => 1,\n              \"gen\"         => 1,\n              \"dnsseed\"     => 0,\n              \"unpnp\"       => 0,\n              \"port\"        => 19000,\n              \"server\"      => 1,\n              \"rpcuser\"     => \"username\",\n              \"rpcpassword\" => \"password\",\n              \"rpcallowip\"  => [\"0.0.0.0/0\"],\n              \"rpcport\"     => 19332\n            }\n          }\n        }\n      }\n    end\n  end\n\n  config.vm.define \"node02\" do |node02|\n    node02.vm.network \"private_network\", ip: \"192.168.33.20\"\n    node02.vm.network \"forwarded_port\", guest: 19332, host: 18333\n    node02.vm.provision \"chef_solo\" do |chef|\n      chef.add_recipe \"bitcoind\"\n      chef.json = {\n        \"bitcoind\" => {\n          \"config\" => {\n            \"options\" => {\n              \"regtest\"     => 1,\n              \"dnsseed\"     => 0,\n              \"unpnp\"       => 0,\n              \"port\"        => 19000,\n              \"server\"      => 1,\n              \"listen\"      => 0,\n              \"connect\"     => \"192.168.33.10:19000\",\n              \"rpcuser\"     => \"username\",\n              \"rpcpassword\" => \"password\",\n              \"rpcallowip\"  => [\"0.0.0.0/0\"],\n              \"rpcport\"     => 19332\n            }\n          }\n        }\n      }\n    end\n  end\n\nend\n"
  },
  {
    "path": "composer.json",
    "content": "{\n    \"name\": \"nbobtc/bitcoind-php\",\n    \"homepage\": \"https://github.com/nbobtc/bitcoind-php\",\n    \"type\": \"library\",\n    \"description\": \"PHP Wrapper for a bitcoind daemon\",\n    \"keywords\": [\"bitcoin\", \"bitcoind\", \"bitcoins\"],\n    \"license\": \"MIT\",\n    \"authors\": [\n        {\n            \"name\": \"Joshua Estes\"\n        }\n    ],\n    \"support\": {\n        \"issues\": \"https://github.com/nbobtc/bitcoind-php/issues\",\n        \"source\": \"https://github.com/nbobtc/bitcoind-php\"\n    },\n    \"autoload\": {\n        \"psr-4\": { \"Nbobtc\\\\\": \"src/\" }\n    },\n    \"autoload-dev\": {\n        \"psr-4\": { \"Tests\\\\Nbobtc\\\\\": \"tests/\" }\n    },\n    \"extra\": {\n        \"branch-alias\": {\n            \"1.x-dev\": \"1.3.x-dev\",\n            \"2.x-dev\": \"2.1.x-dev\"\n        }\n    },\n    \"require\": {\n        \"php\": \">=5.4\",\n        \"ext-curl\": \"*\",\n        \"ext-json\": \"*\",\n        \"psr/log\": \"~1.0\",\n        \"psr/http-message\": \"~1.0\",\n        \"zendframework/zend-diactoros\": \"^1.3\"\n    },\n    \"require-dev\": {\n        \"phpunit/phpunit\": \"~4.5.0\",\n        \"mockery/mockery\": \"~0.9.0\",\n        \"fzaninotto/faker\": \"~1.4.0\"\n    },\n    \"config\": {\n        \"bin-dir\": \"bin\"\n    },\n    \"non-feature-branches\": [\"master\"]\n}\n"
  },
  {
    "path": "docs/.gitkeep",
    "content": ""
  },
  {
    "path": "phpdoc.dist.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<phpdoc>\n    <title>API Documentation</title>\n    <parser>\n        <target>docs/api/</target>\n    </parser>\n    <transformer>\n        <target>docs/api/</target>\n    </transformer>\n    <files>\n        <directory>src/</directory>\n    </files>\n    <logging>\n        <paths>\n            <default>build/logs/phpdoc.log</default>\n            <errors>build/logs/phpdoc.err</errors>\n        </paths>\n    </logging>\n</phpdoc>\n"
  },
  {
    "path": "phpunit.xml.dist",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<phpunit\n    backupGlobals=\"false\"\n    backupStaticAttributes=\"false\"\n    bootstrap=\"vendor/autoload.php\"\n    colors=\"true\"\n    convertErrorsToExceptions=\"true\"\n    convertNoticesToExceptions=\"true\"\n    convertWarningsToExceptions=\"true\"\n    processIsolation=\"false\"\n    stopOnError=\"false\"\n    stopOnFailure=\"false\"\n    stopOnIncomplete=\"false\"\n    stopOnSkipped=\"false\"\n    verbose=\"false\">\n\n    <testsuites>\n        <testsuite name=\"Test Suite\">\n            <directory>tests/</directory>\n        </testsuite>\n    </testsuites>\n\n    <filter>\n        <whitelist>\n            <directory>src/</directory>\n        </whitelist>\n    </filter>\n\n    <listeners>\n        <listener class=\"\\Mockery\\Adapter\\Phpunit\\TestListener\"></listener>\n    </listeners>\n\n    <logging>\n        <log type=\"coverage-html\" target=\"docs/code-coverage\" charset=\"UTF-8\" />\n        <log type=\"coverage-clover\" target=\"build/logs/clover.xml\"/>\n    </logging>\n</phpunit>\n"
  },
  {
    "path": "src/Command/Command.php",
    "content": "<?php\n/**\n * @author Joshua Estes\n * @copyright 2012-2015 Joshua Estes\n * @license https://github.com/nbobtc/bitcoind-php/blob/2.x/LICENSE MIT\n */\n\nnamespace Nbobtc\\Command;\n\n/**\n * @since 2.0.0\n */\nclass Command implements CommandInterface\n{\n    /**\n     * @var string\n     */\n    protected $method;\n\n    /**\n     * @var array\n     */\n    protected $parameters;\n\n    /**\n     * @var string\n     */\n    protected $id;\n\n    /**\n     * Creates a new Command object\n     *\n     * @since 2.0.0\n     * @param string     $method\n     * @param array|null $parameters\n     * @param string     $id\n     */\n    public function __construct($method = null, $parameters = null, $id = null)\n    {\n        if (null !== $method) {\n            $this->withMethod($method);\n        }\n\n        if (null !== $parameters) {\n            $this->withParameters($parameters);\n        }\n\n        if (null !== $id) {\n            $this->withId($id);\n        }\n    }\n\n    /**\n     * @since 2.0.0\n     * {@inheritdoc}\n     */\n    public function getMethod()\n    {\n        return $this->method;\n    }\n\n    /**\n     * @since 2.0.0\n     * {@inheritdoc}\n     */\n    public function getParameters()\n    {\n        return $this->parameters;\n    }\n\n    /**\n     * @since 2.0.0\n     * {@inheritdoc}\n     */\n    public function getId()\n    {\n        return $this->id;\n    }\n\n    /**\n     * @since 2.0.0\n     * {@inheritdoc}\n     */\n    public function withMethod($method)\n    {\n        $this->method = $method;\n\n        return $this;\n    }\n\n    /**\n     * @since 2.0.0\n     * {@inheritdoc}\n     */\n    public function withParameters($parameters)\n    {\n        if (is_array($parameters)) {\n            $this->parameters = $parameters;\n        } else {\n            $this->parameters = array($parameters);\n        }\n\n        return $this;\n    }\n\n    /**\n     * @since 2.0.0\n     * {@inheritdoc}\n     */\n    public function withId($id)\n    {\n        $this->id = $id;\n\n        return $this;\n    }\n}\n"
  },
  {
    "path": "src/Command/CommandInterface.php",
    "content": "<?php\n/**\n * @author Joshua Estes\n * @copyright 2012-2015 Joshua Estes\n * @license https://github.com/nbobtc/bitcoind-php/blob/2.x/LICENSE MIT\n */\n\nnamespace Nbobtc\\Command;\n\n/**\n * @since 2.0.0\n */\ninterface CommandInterface\n{\n    /**\n     * @since 2.0.0\n     * @return string\n     */\n    public function getId();\n\n    /**\n     * @since 2.0.0\n     * @return array\n     */\n    public function getParameters();\n\n    /**\n     * @since 2.0.0\n     * @return string\n     */\n    public function getMethod();\n\n    /**\n     * @since 2.0.0\n     * @param string $method\n     * @return self\n     */\n    public function withMethod($method);\n\n    /**\n     * @since 2.0.0\n     * @param array|string $parameters\n     * @return self\n     */\n    public function withParameters($parameters);\n\n    /**\n     * @since 2.0.0\n     * @param string $id\n     * @return self\n     */\n    public function withId($id);\n}\n"
  },
  {
    "path": "src/Http/Client.php",
    "content": "<?php\n/**\n * @author Joshua Estes\n * @copyright 2012-2015 Joshua Estes\n * @license https://github.com/nbobtc/bitcoind-php/blob/2.x/LICENSE MIT\n */\n\nnamespace Nbobtc\\Http;\n\nuse Nbobtc\\Command\\CommandInterface;\nuse Nbobtc\\Http\\Driver\\CurlDriver;\nuse Nbobtc\\Http\\Driver\\DriverInterface;\nuse Psr\\Http\\Message\\RequestInterface;\nuse Psr\\Http\\Message\\ResponseInterface;\nuse Zend\\Diactoros\\Request;\n\n/**\n * @since 2.0.0\n */\nclass Client implements ClientInterface\n{\n    /**\n     * @var \\Psr\\Http\\Message\\RequestInterface\n     */\n    protected $request;\n\n    /**\n     * @var \\Psr\\Http\\Message\\ResponseInterface\n     */\n    protected $response;\n\n    /**\n     * @var \\Nbobtc\\Http\\Driver\\DriverInterface\n     */\n    protected $driver;\n\n    /**\n     * Creates a new Client object\n     *\n     * Currently you MUST pass in a DSN so the client knows where to send\n     * commands to.\n     *\n     * ```php\n     * $client = new \\Nbobtc\\Http\\Client('https://username:password@localhost:18332');\n     * ```\n     *\n     * @since 2.0.0\n     * @param string $dsn Data Source Name\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function __construct($dsn)\n    {\n        $this->driver  = new CurlDriver();\n        $this->request = (new Request($dsn))->withHeader('Content-Type', 'application/json');\n    }\n\n    /**\n     * @since 2.0.0\n     * {@inheritdoc}\n     */\n    public function sendCommand(CommandInterface $command)\n    {        \n        $body = new \\Zend\\Diactoros\\Stream('php://temp', 'w+');\n        $body->write(json_encode(\n            array(\n                'method' => $command->getMethod(),\n                'params' => $command->getParameters(),\n                'id'     => $command->getId(),\n            )\n        ));\n\n        $request = $this->request->withBody($body);\n        \n        /** @var \\Psr\\Http\\Message\\ResponseInterface */\n        $this->response = $this->driver->execute($request);\n\n        return $this->response;\n    }\n\n    /**\n     * Configures the Client to use a specific driver\n     *\n     * @since 2.0.0\n     * @param \\Nbobtc\\Http\\Driver\\DriverInterface $driver\n     * @return self\n     */\n    public function withDriver(DriverInterface $driver)\n    {\n        $this->driver = $driver;\n\n        return $this;\n    }\n\n    /**\n     * Return the current Request object\n     *\n     * @since 2.0.0\n     * @return \\Psr\\Http\\Message\\RequestInterface\n     */\n    public function getRequest()\n    {\n        return $this->request;\n    }\n\n    /**\n     * Returns the current Response object\n     *\n     * @since 2.0.0\n     * @return \\Psr\\Http\\Message\\ResponseInterface\n     */\n    public function getResponse()\n    {\n        return $this->response;\n    }\n}\n"
  },
  {
    "path": "src/Http/ClientInterface.php",
    "content": "<?php\n/**\n * @author Joshua Estes\n * @copyright 2012-2015 Joshua Estes\n * @license https://github.com/nbobtc/bitcoind-php/blob/2.x/LICENSE MIT\n */\n\nnamespace Nbobtc\\Http;\n\nuse Nbobtc\\Command\\CommandInterface;\n\n/**\n * Client used to send commands to bitcoin servers/nodes\n *\n * Client is used to send commands to bitcoin servers and receives the\n * responses back from those servers. The client does little to no processing\n * or minipulation of the Command, Request, and Response objects.\n *\n * @since 2.0.0\n */\ninterface ClientInterface\n{\n    /**\n     * Send Command to configured server\n     *\n     * Sends a command to a server and returns a Response object. If there was\n     * an error it will throw an Exception.\n     *\n     * @since 2.0.0\n     * @params \\Nbobtc\\Command\\CommandInterface $command\n     * @return \\Psr\\Http\\Message\\ResponseInterface\n     * @throws \\Exception\n     */\n    public function sendCommand(CommandInterface $command);\n}\n"
  },
  {
    "path": "src/Http/Driver/CurlDriver.php",
    "content": "<?php\n/**\n * @author Joshua Estes\n * @copyright 2012-2015 Joshua Estes\n * @license https://github.com/nbobtc/bitcoind-php/blob/2.x/LICENSE MIT\n */\n\nnamespace Nbobtc\\Http\\Driver;\n\nuse Psr\\Http\\Message\\RequestInterface;\nuse Zend\\Diactoros\\Response;\n\n/**\n * Uses cURL to send Requests\n *\n * @since 2.0.0\n */\nclass CurlDriver implements DriverInterface\n{\n    /**\n     * @var resource\n     */\n    protected static $ch;\n\n    /**\n     * @var array\n     */\n    protected $curlOptions = array();\n\n    /**\n     * @since 2.0.0\n     */\n    public function __destruct()\n    {\n        if (null !== self::$ch) {\n            curl_close(self::$ch);\n            self::$ch = null; // Nulling to avoid calling curl_close again\n        }\n    }\n\n    /**\n     * @since 2.0.0\n     * {@inheritDoc}\n     */\n    public function execute(RequestInterface $request)\n    {\n        $uri = $request->getUri();\n\n        if (null === self::$ch || gettype(self::$ch) != 'curl') {\n            self::$ch = curl_init();\n        }\n\n        curl_setopt_array(self::$ch, $this->getDefaultCurlOptions());\n\n        curl_setopt(self::$ch, CURLOPT_URL, sprintf('%s://%s@%s', $uri->getScheme(), $uri->getUserInfo(), $uri->getHost()));\n        curl_setopt(self::$ch, CURLOPT_PORT, $uri->getPort());\n\n        $headers = array();\n        foreach ($request->getHeaders() as $header => $values) {\n            $headers[] = $header.': '.implode(', ', $values);\n        }\n        curl_setopt(self::$ch, CURLOPT_HTTPHEADER, $headers);\n        curl_setopt(self::$ch, CURLOPT_POSTFIELDS, (string) $request->getBody());\n\n        // Allows user to override any option, may cause errors\n        curl_setopt_array(self::$ch, $this->curlOptions);\n\n        /** @var string|false */\n        $result = curl_exec(self::$ch);\n        /** @var array|false */\n        $info = curl_getinfo(self::$ch);\n        /** @var string */\n        $error = curl_error(self::$ch);\n\n        if (!empty($error)) {\n            throw new \\Exception($error);\n        }\n\n        $response = new Response();\n\n        $response = $response->withStatus($info['http_code']);\n\n        $response->getBody()->write($result);\n        $response->getBody()->rewind(); // empty getContents() without rewind()\n\n        return $response;\n    }\n\n    /**\n     * Add options to use for cURL requests\n     *\n     * @since 2.0.0\n     * @param integer $option\n     * @param mixed   $value\n     */\n    public function addCurlOption($option, $value)\n    {\n        $this->curlOptions[$option] = $value;\n\n        return $this;\n    }\n\n    /**\n     * Returns an array of cURL options\n     *\n     * @since 2.0.0\n     * @return array\n     */\n    protected function getDefaultCurlOptions()\n    {\n        return array(\n            CURLOPT_POST           => true,\n            CURLOPT_RETURNTRANSFER => true,\n            CURLOPT_CONNECTTIMEOUT => 5,\n            CURLOPT_TIMEOUT        => 10,\n        );\n    }\n}\n"
  },
  {
    "path": "src/Http/Driver/DriverInterface.php",
    "content": "<?php\n/**\n * @author Joshua Estes\n * @copyright 2012-2015 Joshua Estes\n * @license https://github.com/nbobtc/bitcoind-php/blob/2.x/LICENSE MIT\n */\n\nnamespace Nbobtc\\Http\\Driver;\n\nuse Psr\\Http\\Message\\RequestInterface;\n\n/**\n * @since 2.0.0\n */\ninterface DriverInterface\n{\n    /**\n     * Sends Request to server and returns a response.\n     *\n     * This will throw an Exception if there was an error\n     *\n     * @since 2.0.0\n     * @param \\Psr\\Http\\Message\\RequestInterface $request\n     * @return \\Psr\\Http\\Message\\ResponseInterface;\n     * @throws \\Exception\n     */\n    public function execute(RequestInterface $request);\n}\n"
  },
  {
    "path": "src/Http/Message/Message.php",
    "content": "<?php\n/**\n * @author Joshua Estes\n * @copyright 2012-2015 Joshua Estes\n * @license https://github.com/nbobtc/bitcoind-php/blob/2.x/LICENSE MIT\n */\n\nnamespace Nbobtc\\Http\\Message;\n\nuse Psr\\Http\\Message\\MessageInterface;\nuse Psr\\Http\\Message\\StreamInterface;\n\n/**\n * @since 2.0.0\n *\n * @deprecated - please use a separate PSR-7 message implementation\n */\nclass Message implements MessageInterface\n{\n    /**\n     * @var string\n     */\n    protected $version = '1.1';\n\n    /**\n     * @var array\n     */\n    protected $headers = array();\n\n    /**\n     * @var \\Psr\\Http\\Message\\StreamInterface\n     */\n    protected $body;\n\n    /**\n     * @since 2.0.0\n     * {@inheritDoc}\n     */\n    public function getProtocolVersion()\n    {\n        return $this->version;\n    }\n\n    /**\n     * @since 2.0.0\n     * {@inheritDoc}\n     */\n    public function withProtocolVersion($version)\n    {\n        $this->version = (string) $version;\n\n        return $this;\n    }\n\n    /**\n     * @since 2.0.0\n     * {@inheritDoc}\n     */\n    public function getHeaders()\n    {\n        return $this->headers;\n    }\n\n    /**\n     * @since 2.0.0\n     * {@inheritDoc}\n     */\n    public function hasHeader($name)\n    {\n        foreach ($this->headers as $header => $values) {\n            if (0 === strcasecmp($header, $name)) {\n                return true;\n            }\n        }\n\n        return false;\n    }\n\n    /**\n     * @since 2.0.0\n     * {@inheritDoc}\n     */\n    public function getHeader($name)\n    {\n        foreach ($this->headers as $header => $values) {\n            if (0 === strcasecmp($header, $name)) {\n                return $this->headers[$header];\n            }\n        }\n\n        return null;\n    }\n\n    /**\n     * @todo\n     * @since 2.0.2\n     * {@inheritDoc}\n     */\n    public function getHeaderLine($name)\n    {\n        return '';\n    }\n\n    /**\n     * @since 2.0.0\n     * {@inheritDoc}\n     */\n    public function getHeaderLines($name)\n    {\n        if ($lines = $this->getHeader($name)) {\n            return $lines;\n        }\n\n        return array();\n    }\n\n    /**\n     * @since 2.0.0\n     * {@inheritDoc}\n     */\n    public function withHeader($name, $value)\n    {\n        if (is_array($value)) {\n            $this->headers[$name] = $value;\n        } else {\n            $this->headers[$name] = array($value);\n        }\n\n        return $this;\n    }\n\n    /**\n     * @since 2.0.0\n     * {@inheritDoc}\n     */\n    public function withAddedHeader($name, $value)\n    {\n        $this->headers[$name] = $value;\n\n        return $this;\n    }\n\n    /**\n     * @since 2.0.0\n     * {@inheritDoc}\n     */\n    public function withoutHeader($name)\n    {\n        foreach ($this->headers as $header => $values) {\n            if (0 === strcasecmp($header, $name)) {\n                unset($this->headers[$header]);\n            }\n        }\n\n        return $this;\n    }\n\n    /**\n     * @since 2.0.0\n     * {@inheritDoc}\n     */\n    public function getBody()\n    {\n        if (null === $this->body) {\n            $this->body = new Streamable();\n        }\n\n        return $this->body;\n    }\n\n    /**\n     * @since 2.0.0\n     * {@inheritDoc}\n     */\n    public function withBody(StreamInterface $body)\n    {\n        $this->body = $body;\n\n        return $this;\n    }\n}\n"
  },
  {
    "path": "src/Http/Message/Request.php",
    "content": "<?php\n/**\n * @author Joshua Estes\n * @copyright 2012-2015 Joshua Estes\n * @license https://github.com/nbobtc/bitcoind-php/blob/2.x/LICENSE MIT\n */\n\nnamespace Nbobtc\\Http\\Message;\n\nuse Zend\\Diactoros\\Request as DiactorosRequest;\n\n/**\n * @since 2.0.0\n *\n * @deprecated - please use a separate PSR-7 request implementation\n */\nclass Request extends DiactorosRequest\n{\n    /**\n     * HTTP Methods\n     *\n     * @var string\n     *\n     * @deprecated - constant was kept just for BC compliance\n     */\n    const HTTP_POST = 'POST';\n}\n"
  },
  {
    "path": "src/Http/Message/Response.php",
    "content": "<?php\n/**\n * @author Joshua Estes\n * @copyright 2012-2015 Joshua Estes\n * @license https://github.com/nbobtc/bitcoind-php/blob/2.x/LICENSE MIT\n */\n\nnamespace Nbobtc\\Http\\Message;\n\nuse Zend\\Diactoros\\Response as DiactorosResponse;\n\n/**\n * @since 2.0.0\n *\n * @deprecated - please use a separate PSR-7 response implementation\n */\nclass Response extends DiactorosResponse\n{\n    /**\n     * Status Code Constants\n     *\n     * @var integer\n     *\n     * @deprecated - constant was kept just for BC compliance\n     */\n    const HTTP_OK = 200;\n}\n"
  },
  {
    "path": "src/Http/Message/Streamable.php",
    "content": "<?php\n/**\n * @author Joshua Estes\n * @copyright 2012-2015 Joshua Estes\n * @license https://github.com/nbobtc/bitcoind-php/blob/2.x/LICENSE MIT\n */\n\nnamespace Nbobtc\\Http\\Message;\n\nuse Zend\\Diactoros\\Stream;\n\n/**\n * Represents the body of the request/response\n *\n * This object does not use every function in the interface. Please be aware of\n * this.\n *\n * @since 2.0.0\n *\n * @deprecated - please use a separate PSR-7 stream implementation\n */\nclass Streamable extends Stream\n{\n    public function __construct()\n    {\n        parent::__construct('php://memory', 'wb+');\n    }\n}\n"
  },
  {
    "path": "src/Http/Message/Uri.php",
    "content": "<?php\n/**\n * @author Joshua Estes\n * @copyright 2012-2015 Joshua Estes\n * @license https://github.com/nbobtc/bitcoind-php/blob/2.x/LICENSE MIT\n */\n\nnamespace Nbobtc\\Http\\Message;\n\nuse Zend\\Diactoros\\Uri as DiactorosUri;\n\n/**\n * @since 2.0.0\n *\n * @deprecated - please use a separate PSR-7 URI implementation\n */\nclass Uri extends DiactorosUri\n{\n}\n"
  },
  {
    "path": "tests/Command/CommandTest.php",
    "content": "<?php\n/**\n * @author Joshua Estes\n * @copyright 2012-2015 Joshua Estes\n * @license https://github.com/nbobtc/bitcoind-php/blob/2.x/LICENSE MIT\n */\n\nnamespace Tests\\Nbobtc\\Command;\n\nuse Nbobtc\\Command\\Command;\n\n/**\n */\nclass CommandTest extends \\PHPUnit_Framework_TestCase\n{\n    /**\n     * @dataProvider commandDataProvider\n     */\n    public function testCommand($method, $parameters, $id)\n    {\n        $command = new Command($method, $parameters, $id);\n\n        $this->assertEquals($method, $command->getMethod());\n        $this->assertEquals($parameters, $command->getParameters());\n        $this->assertEquals($id, $command->getId());\n\n        $command = new Command();\n        $this->assertNull($command->getMethod());\n        $this->assertEmpty($command->getParameters());\n        $this->assertNull($command->getId());\n\n        $this->assertInstanceOf('Nbobtc\\Command\\CommandInterface', $command->withMethod($method));\n        $this->assertEquals($method, $command->getMethod());\n        $this->assertInstanceOf('Nbobtc\\Command\\CommandInterface', $command->withParameters($parameters));\n        $this->assertEquals($parameters, $command->getParameters());\n        $this->assertInstanceOf('Nbobtc\\Command\\CommandInterface', $command->withId($id));\n        $this->assertEquals($id, $command->getId());\n    }\n\n    public function commandDataProvider()\n    {\n        return array(\n            array('getinfo', array('one'), 1),\n        );\n    }\n\n    public function testCommandWithParameters()\n    {\n        $command = new Command();\n        $this->assertEmpty($command->getParameters());\n        $command->withParameters('a');\n        $this->assertEquals(array('a'), $command->getParameters());\n\n        $command = new Command();\n        $this->assertEmpty($command->getParameters());\n        $command->withParameters(array('a'));\n        $this->assertEquals(array('a'), $command->getParameters());\n    }\n}\n"
  },
  {
    "path": "tests/Http/ClientTest.php",
    "content": "<?php\n/**\n * @author Joshua Estes\n * @copyright 2012-2015 Joshua Estes\n * @license https://github.com/nbobtc/bitcoind-php/blob/2.x/LICENSE MIT\n */\n\nnamespace Tests\\Nbobtc\\Http;\n\nuse Nbobtc\\Http\\Client;\nuse Nbobtc\\Command\\Command;\n\n/**\n */\nclass ClientTest extends \\PHPUnit_Framework_TestCase\n{\n    public function testClient()\n    {\n        $client = new Client('https://username:password@localhost:18332');\n        $this->assertNull($client->getResponse());\n\n        $request = $client->getRequest();\n        $this->assertInstanceOf('Psr\\Http\\Message\\RequestInterface', $request);\n\n        $uri = $request->getUri();\n        $this->assertInstanceOf('Psr\\Http\\Message\\UriInterface', $uri);\n        $this->assertEquals('https', $uri->getScheme());\n        $this->assertEquals('username:password', $uri->getUserInfo());\n        $this->assertEquals('localhost', $uri->getHost());\n        $this->assertEquals(18332, $uri->getPort());\n    }\n\n    public function testWithKeepAlive()\n    {\n        $client = new Client('https://username:password@localhost:18332');\n        $client->getRequest()->withHeader('Connection', 'Keep-Alive');\n    }\n\n    public function testSendCommand()\n    {\n        $response = \\Mockery::mock('\\Psr\\Http\\Message\\ResponseInterface');\n        $driver   = \\Mockery::mock('\\Nbobtc\\Http\\Driver\\DriverInterface');\n        $driver\n            ->shouldReceive('execute')\n            ->andReturn($response);\n\n        $client = new Client('https://username:password@localhost:18332');\n        $client->withDriver($driver);\n        $command  = new Command('gettransaction', array('transactionId'));\n        $response = $client->sendCommand($command);\n    }\n}\n"
  },
  {
    "path": "tests/Http/Driver/CurlDriverTest.php",
    "content": "<?php\n/**\n * @author Thomas Kerin\n * @copyright 2017 Thomas Kerin\n * @license https://github.com/nbobtc/bitcoind-php/blob/2.x/LICENSE MIT\n */\n\nnamespace Tests\\Nbobtc\\Http\\Driver;\nuse Nbobtc\\Http\\Driver\\CurlDriver;\nuse Psr\\Http\\Message\\ResponseInterface;\nuse Zend\\Diactoros\\Request;\n\n/**\n */\nclass CurlDriverTest extends \\PHPUnit_Framework_TestCase\n{\n    public function testExplodesWithTwo() {\n        $body = new \\Zend\\Diactoros\\Stream('php://temp', 'w+');\n        $body->write(\"test\");\n\n        $request = (new Request(\"https://google.com\"));\n        $request = $request->withBody($body);\n\n        $driver = new CurlDriver();\n        /** @var \\Psr\\Http\\Message\\ResponseInterface */\n        $response = $driver->execute($request);\n        $this->assertInstanceOf(\"Psr\\Http\\Message\\ResponseInterface\", $response);\n\n        $driver = new CurlDriver();\n        /** @var \\Psr\\Http\\Message\\ResponseInterface */\n        $response = $driver->execute($request);\n        $this->assertInstanceOf(\"Psr\\Http\\Message\\ResponseInterface\", $response);\n    }\n}\n"
  }
]