[IMPROVED] Payout logging and indent

This commit is contained in:
Sebastian Grewe 2014-01-15 15:16:54 +01:00
parent c42fc60742
commit f2f539ef53
2 changed files with 76 additions and 75 deletions

View File

@ -68,7 +68,7 @@ if ($setting->getValue('disable_manual_payouts') != 1) {
try { try {
$txid = $bitcoin->sendtoaddress($aData['coin_address'], $dBalance - $config['txfee_manual']); $txid = $bitcoin->sendtoaddress($aData['coin_address'], $dBalance - $config['txfee_manual']);
} catch (Exception $e) { } catch (Exception $e) {
$log->logError('Failed to send requested balance to coin address, please check payout process. Does the wallet cover the amount?'); $log->logError('Failed to send requested balance to coin address, please check payout process. Does the wallet cover the amount? Error:' . $e->getMessage());
continue; continue;
} }

View File

@ -1,6 +1,6 @@
<?php <?php
/* /*
COPYRIGHT COPYRIGHT
Copyright 2007 Sergio Vaccaro <sergio@inservibile.org> Copyright 2007 Sergio Vaccaro <sergio@inservibile.org>
@ -19,7 +19,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with JSON-RPC PHP; if not, write to the Free Software along with JSON-RPC PHP; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
/** /**
* The object of this class are generic jsonRPC 1.0 clients * The object of this class are generic jsonRPC 1.0 clients
@ -28,41 +28,41 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* @author sergio <jsonrpcphp@inservibile.org> * @author sergio <jsonrpcphp@inservibile.org>
*/ */
class jsonRPCClient { class jsonRPCClient {
/** /**
* Debug state * Debug state
* *
* @var boolean * @var boolean
*/ */
private $debug; private $debug;
private $debug_output; private $debug_output;
/** /**
* The server URL * The server URL
* *
* @var string * @var string
*/ */
private $url; private $url;
/** /**
* The request id * The request id
* *
* @var integer * @var integer
*/ */
private $id; private $id;
/** /**
* Takes the connection parameters * Takes the connection parameters
* *
* @param string $url * @param string $url
* @param boolean $debug * @param boolean $debug
*/ */
public function __construct($url, $debug = false) { public function __construct($url, $debug = false) {
$this->url = $url; $this->url = $url;
$this->debug = $debug; $this->debug = $debug;
$this->debug_output = ''; $this->debug_output = '';
$this->id = rand(1, 100); $this->id = rand(1, 100);
} }
/** /**
* Fetch debug information * Fetch debug information
* @param none * @param none
@ -72,42 +72,43 @@ class jsonRPCClient {
return $this->debug_output; return $this->debug_output;
} }
/** /**
* Performs a jsonRCP request and gets the results as an array * Performs a jsonRCP request and gets the results as an array
* *
* @param string $method * @param string $method
* @param array $params * @param array $params
* @return array * @return array
*/ */
public function __call($method, $params) { public function __call($method, $params) {
if (!is_scalar($method)) throw new Exception('Method name has no scalar value'); if (!is_scalar($method)) throw new Exception('Method name has no scalar value');
if (is_array($params)) { if (is_array($params)) {
// no keys // no keys
$params = array_values($params); $params = array_values($params);
} else { } else {
throw new Exception('Params must be given as array'); throw new Exception('Params must be given as array');
} }
// prepares the request // prepares the request
$request = array( $request = array(
'method' => $method, 'method' => $method,
'params' => $params, 'params' => $params,
'id' => $this->id 'id' => $this->id
); );
$request = json_encode($request); $request = json_encode($request);
if ($this->debug) $this->debug_output[] = 'Request: '.$request; if ($this->debug) $this->debug_output[] = 'Request: '.$request;
// performs the HTTP POST // performs the HTTP POST
// extract information from URL for proper authentication // extract information from URL for proper authentication
$url = parse_url($this->url); $url = parse_url($this->url);
$ch = curl_init($url['scheme'].'://'.$url['host'].':'.$url['port'].$url['path']); $ch = curl_init($url['scheme'].'://'.$url['host'].':'.$url['port'].$url['path']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json')); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_USERPWD, $url['user'] . ":" . $url['pass']); curl_setopt($ch, CURLOPT_USERPWD, $url['user'] . ":" . $url['pass']);
curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request); curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch); $response = curl_exec($ch);
$this->debug = true;
if ($this->debug) $this->debug_output[] = 'Response: ' . $response; if ($this->debug) $this->debug_output[] = 'Response: ' . $response;
$response = json_decode($response, true); $response = json_decode($response, true);
$resultStatus = curl_getinfo($ch); $resultStatus = curl_getinfo($ch);
@ -116,11 +117,11 @@ class jsonRPCClient {
throw new Exception('RPC call did not return 200: HTTP error: ' . $resultStatus['http_code']); throw new Exception('RPC call did not return 200: HTTP error: ' . $resultStatus['http_code']);
} }
if (curl_errno($ch)) throw new Exception('RPC call failed: ' . curl_error($ch)); if (curl_errno($ch)) throw new Exception('RPC call failed: ' . curl_error($ch));
curl_close($ch); curl_close($ch);
// final checks and return // final checks and return
if (!is_null($response['error']) || is_null($response)) throw new Exception('Response error or empty: ' . @$response['error']); if (!is_null($response['error']) || is_null($response)) throw new Exception('Response error or empty: ' . @$response['error']);
if ($response['id'] != $this->id) throw new Exception('Incorrect response id (request id: ' . $this->id . ', response id: ' . $response['id'] . ')'); if ($response['id'] != $this->id) throw new Exception('Incorrect response id (request id: ' . $this->id . ', response id: ' . $response['id'] . ')');
return $response['result']; return $response['result'];
} }
} }