diff --git a/composer.json b/composer.json index 03450b5..22d937a 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "php": ">=7.2.0", "ext-bcmath": "*", "ext-curl": "*", - "ext-json": "*" + "ext-json": "*", + "guzzlehttp/guzzle": "^7.7" }, "suggest": { "ext-gmp": "Used to have a multiple math precision for generating address" diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..77f185a --- /dev/null +++ b/composer.lock @@ -0,0 +1,620 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "0413d2a14424d4a82faeb5b697f0b5af", + "packages": [ + { + "name": "guzzlehttp/guzzle", + "version": "7.7.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "fb7566caccf22d74d1ab270de3551f72a58399f5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/fb7566caccf22d74d1ab270de3551f72a58399f5", + "reference": "fb7566caccf22d74d1ab270de3551f72a58399f5", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/promises": "^1.5.3 || ^2.0", + "guzzlehttp/psr7": "^1.9.1 || ^2.4.5", + "php": "^7.2.5 || ^8.0", + "psr/http-client": "^1.0", + "symfony/deprecation-contracts": "^2.2 || ^3.0" + }, + "provide": { + "psr/http-client-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.1", + "ext-curl": "*", + "php-http/client-integration-tests": "dev-master#2c025848417c1135031fdf9c728ee53d0a7ceaee as 3.0.999", + "php-http/message-factory": "^1.1", + "phpunit/phpunit": "^8.5.29 || ^9.5.23", + "psr/log": "^1.1 || ^2.0 || ^3.0" + }, + "suggest": { + "ext-curl": "Required for CURL handler support", + "ext-intl": "Required for Internationalized Domain Name (IDN) support", + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Jeremy Lindblom", + "email": "jeremeamia@gmail.com", + "homepage": "https://github.com/jeremeamia" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "psr-18", + "psr-7", + "rest", + "web service" + ], + "support": { + "issues": "https://github.com/guzzle/guzzle/issues", + "source": "https://github.com/guzzle/guzzle/tree/7.7.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle", + "type": "tidelift" + } + ], + "time": "2023-05-21T14:04:53+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "111166291a0f8130081195ac4556a5587d7f1b5d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/111166291a0f8130081195ac4556a5587d7f1b5d", + "reference": "111166291a0f8130081195ac4556a5587d7f1b5d", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.1", + "phpunit/phpunit": "^8.5.29 || ^9.5.23" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "support": { + "issues": "https://github.com/guzzle/promises/issues", + "source": "https://github.com/guzzle/promises/tree/2.0.1" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises", + "type": "tidelift" + } + ], + "time": "2023-08-03T15:11:55+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "2.6.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "8bd7c33a0734ae1c5d074360512beb716bef3f77" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/8bd7c33a0734ae1c5d074360512beb716bef3f77", + "reference": "8bd7c33a0734ae1c5d074360512beb716bef3f77", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.1 || ^2.0", + "ralouphie/getallheaders": "^3.0" + }, + "provide": { + "psr/http-factory-implementation": "1.0", + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.1", + "http-interop/http-factory-tests": "^0.9", + "phpunit/phpunit": "^8.5.29 || ^9.5.23" + }, + "suggest": { + "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" + ], + "support": { + "issues": "https://github.com/guzzle/psr7/issues", + "source": "https://github.com/guzzle/psr7/tree/2.6.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7", + "type": "tidelift" + } + ], + "time": "2023-08-03T15:06:02+00:00" + }, + { + "name": "psr/http-client", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-client.git", + "reference": "0955afe48220520692d2d09f7ab7e0f93ffd6a31" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/0955afe48220520692d2d09f7ab7e0f93ffd6a31", + "reference": "0955afe48220520692d2d09f7ab7e0f93ffd6a31", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", + "keywords": [ + "http", + "http-client", + "psr", + "psr-18" + ], + "support": { + "source": "https://github.com/php-fig/http-client/tree/1.0.2" + }, + "time": "2023-04-10T20:12:12+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "e616d01114759c4c489f93b099585439f795fe35" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/e616d01114759c4c489f93b099585439f795fe35", + "reference": "e616d01114759c4c489f93b099585439f795fe35", + "shasum": "" + }, + "require": { + "php": ">=7.0.0", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-factory/tree/1.0.2" + }, + "time": "2023-04-10T20:10:41+00:00" + }, + { + "name": "psr/http-message", + "version": "2.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/2.0" + }, + "time": "2023-04-04T09:54:51+00:00" + }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, + "time": "2019-03-08T08:55:37+00:00" + }, + { + "name": "symfony/deprecation-contracts", + "version": "v2.5.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/e8b495ea28c1d97b5e0c121748d6f9b53d075c66", + "reference": "e8b495ea28c1d97b5e0c121748d6f9b53d075c66", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.5-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "files": [ + "function.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A generic function and convention to trigger deprecation notices", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/deprecation-contracts/tree/v2.5.2" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-01-02T09:53:40+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=7.2.0", + "ext-bcmath": "*", + "ext-curl": "*", + "ext-json": "*" + }, + "platform-dev": [], + "plugin-api-version": "2.0.0" +} diff --git a/src/daemonRPC.php b/src/daemonRPC.php index 5c568a5..2f850c1 100644 --- a/src/daemonRPC.php +++ b/src/daemonRPC.php @@ -107,9 +107,9 @@ function __construct($host = '127.0.0.1', $port = 18081, $SSL = true, $user = nu * @return string Call result * */ - protected function _run($method, $params = null, $path = 'json_rpc') + protected function _run($method, $params = [], $path = 'json_rpc') { - return $this->client->_run($method, $params, $path); + return $this->client->call($method, $params, $path); } /** diff --git a/src/jsonRPCClient.php b/src/jsonRPCClient.php index 056b66c..a4e3a5f 100644 --- a/src/jsonRPCClient.php +++ b/src/jsonRPCClient.php @@ -9,172 +9,78 @@ * http://implix.com */ namespace MoneroIntegrations\MoneroPhp; +require 'vendor/autoload.php'; + +use GuzzleHttp\Client as GuzzleClient; +use GuzzleHttp\Exception\GuzzleException; +use GuzzleHttp\Psr7\Request; +use Psr\Http\Message\ResponseInterface; -use InvalidArgumentException; use RuntimeException; -class jsonRPCClient +class JsonRpcClient { - protected $url = null, $is_debug = false, $parameters_structure = 'array'; - private $username; - private $password; - protected $curl_options = array( - CURLOPT_CONNECTTIMEOUT => 8, - CURLOPT_TIMEOUT => 8 - ); - - - private $httpErrors = array( - 400 => '400 Bad Request', - 401 => '401 Unauthorized', - 403 => '403 Forbidden', - 404 => '404 Not Found', - 405 => '405 Method Not Allowed', - 406 => '406 Not Acceptable', - 408 => '408 Request Timeout', - 500 => '500 Internal Server Error', - 502 => '502 Bad Gateway', - 503 => '503 Service Unavailable' - ); + protected $client; + protected $isDebug = false; - public function __construct($pUrl, $pUser, $pPass, $check_SSL) + public function __construct(string $url, string $username, string $password, bool $checkSSL = true) { - $this->validate(false === extension_loaded('curl'), 'The curl extension must be loaded to use this class!'); - $this->validate(false === extension_loaded('json'), 'The json extension must be loaded to use this class!'); - - $this->url = $pUrl; - $this->username = $pUser; - $this->password = $pPass; - $this->SSL = $check_SSL; + $this->client = new GuzzleClient([ + 'base_uri' => $url, + 'auth' => [$username, $password, 'digest'], + 'verify' => $checkSSL, + ]); } - public function setDebug($pIsDebug) + public function setDebug(bool $isDebug): self { - $this->is_debug = !empty($pIsDebug); + $this->isDebug = $isDebug; return $this; } - public function setCurlOptions($pOptionsArray) + public function call(string $method, array $params = [], string $path = 'json_rpc'): ?array { - if (is_array($pOptionsArray)) - { - $this->curl_options = $pOptionsArray + $this->curl_options; - } - else - { - throw new InvalidArgumentException('Invalid options type.'); - } - return $this; - } + $requestData = [ + 'jsonrpc' => '2.0', + 'method' => $method, + 'params' => $params, + ]; - public function _run($pMethod, $pParams, $path) - { - // check if given params are correct - $this->validate(false === is_scalar($pMethod), 'Method name has no scalar value'); - // send params as an object or an array - // Request (method invocation) - $request = json_encode(array('jsonrpc' => '2.0', 'method' => $pMethod, 'params' => $pParams)); - // if is_debug mode is true then add url and request to is_debug - $this->debug('Url: ' . $this->url . "\r\n", false); - $this->debug('Request: ' . $request . "\r\n", false); - $responseMessage = $this->getResponse($request, $path); - // if is_debug mode is true then add response to is_debug and display it - $this->debug('Response: ' . $responseMessage . "\r\n", true); - // decode and create array ( can be object, just set to false ) - $responseDecoded = json_decode($responseMessage, true); - // check if decoding json generated any errors - $jsonErrorMsg = json_last_error_msg(); - $this->validate( !is_null($jsonErrorMsg) && $jsonErrorMsg !== 'No error' , $jsonErrorMsg . ': ' . $responseMessage); - if (isset($responseDecoded['error'])) - { - $errorMessage = 'Request have return error: ' . $responseDecoded['error']['message'] . '; ' . "\n" . - 'Request: ' . $request . '; '; - if (isset($responseDecoded['error']['data'])) - { - $errorMessage .= "\n" . 'Error data: ' . $responseDecoded['error']['data']; - } - $this->validate( !is_null($responseDecoded['error']), $errorMessage); + $this->debug('Request: ' . json_encode($requestData)); + + try { + $response = $this->client->post('/' . $path, [ + 'json' => $requestData, + ]); + + $responseBody = $response->getBody()->getContents(); + $this->debug('Response: ' . $responseBody); + + return $this->handleResponse($responseBody); + } catch (GuzzleException $e) { + throw new RuntimeException('Response HTTP Error - ' . $e->getMessage()); } - return $responseDecoded['result'] ?? -1; } - protected function & getResponse(&$pRequest, &$path) + protected function handleResponse(string $responseBody): ?array { - // do the actual connection - $ch = curl_init(); - if (!$ch) - { - throw new RuntimeException('Could\'t initialize a cURL session'); + $response = json_decode($responseBody, true); + if (json_last_error() !== JSON_ERROR_NONE) { + throw new RuntimeException('Invalid JSON response'); } - curl_setopt($ch, CURLOPT_URL, $this->url.$path); - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); - curl_setopt($ch, CURLOPT_USERPWD, $this->username . ":" . $this->password); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, $pRequest); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json')); - curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - if ($this->SSL) - { - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '2'); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); - }else{ - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - } - if (!curl_setopt_array($ch, $this->curl_options)) - { - throw new RuntimeException('Error while setting curl options'); - } - // send the request - $response = curl_exec($ch); - // check http status code - $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - if (isset($this->httpErrors[$httpCode])) - { - throw new RuntimeException('Response Http Error - ' . $this->httpErrors[$httpCode]); - } - // check for curl error - if (0 < curl_errno($ch)) - { - throw new RuntimeException('Unable to connect to '.$this->url . ' Error: ' . curl_error($ch)); + if (!isset($response['result'])) { + $error = $response['error']['message'] ?? 'Unknown error'; + throw new RuntimeException($error); } - // close the connection - curl_close($ch); - return $response; - } - public function validate($pFailed, $pErrMsg) - { - if ($pFailed) - { - throw new RuntimeException($pErrMsg); - } + return $response['result']; } - protected function debug($pAdd, $pShow = false) + protected function debug(string $message): void { - static $debug, $startTime; - // is_debug off return - if (false === $this->is_debug) - { - return; - } - // add - $debug .= $pAdd; - // get starttime - $startTime = empty($startTime) ? array_sum(explode(' ', microtime())) : $startTime; - if (true === $pShow and !empty($debug)) - { - // get endtime - $endTime = array_sum(explode(' ', microtime())); - // performance summary - $debug .= 'Request time: ' . round($endTime - $startTime, 3) . ' s Memory usage: ' . round(memory_get_usage() / 1024) . " kb\r\n"; - echo nl2br($debug); - // send output immediately - flush(); - // clean static - $debug = $startTime = null; + if ($this->isDebug) { + echo $message . PHP_EOL; } } } diff --git a/src/walletRPC.php b/src/walletRPC.php index 825c9cb..b8e3935 100644 --- a/src/walletRPC.php +++ b/src/walletRPC.php @@ -106,9 +106,9 @@ function __construct($host = '127.0.0.1', $port = 18081, $SSL = true, $user = nu * @return string Call result * */ - private function _run($method, $params = null, $path = 'json_rpc') + private function _run($method, $params = [], $path = 'json_rpc') { - $result = $this->client->_run($method, $params, $path); + $result = $this->client->call($method, $params, $path); return $result; }