Проблема подключения JSON-RPC!

Я использую биткойн. И у меня есть простой биткойн-кошелек с простой системой входа-регистрации.

Код ошибки;

Fatal error: Uncaught exception 'Exception' with message 'Incorrect response id (request id: 1, response id: )' in /var/www/ponzi/htdocs/wallet/includes/jsonRPCClient.php:146 Stack trace: #0 /var/www/ponzi/htdocs/wallet/account.php(38): jsonRPCClient->__call('getaccountaddre...', Array) #1 /var/www/ponzi/htdocs/wallet/account.php(38): jsonRPCClient->getaccountaddress('kaka') #2 {main} thrown in /var/www/ponzi/htdocs/wallet/includes/jsonRPCClient.php on line 146

Страница аккаунта;

<?php include("includes/auth.php"); //include auth.php file on all secure pages ?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>MyCoinWallet - Account</title>
        <link rel="stylesheet" href="css/styles.css"  type="text/css" />
    </head>
    <body>
        <div id="main">
            <div id="top"><div style='float:left;position:relative;top:25px;'><h2>MyCoinWallet</h2></div><div class="logomargin"><img src='images/logo-mockup2.png' /></div></div>
            <div id="wrapper">
                <div id="content">
                    <div class="innermargin">
                        <h1>MyCoinWallet Account</h1>
                        <br />
                        <form>
                            <br>
                            <p>Welcome <?php echo $_SESSION['username']; ?>!</p><br><br>

                            <?php
                            require_once('includes/db.php');
                            require_once('includes/config.php');
                            require_once('includes/jsonRPCClient.php');
                            require_once('includes/bcfunctions.php');

                            $bitcoin = new jsonRPCClient('http://MYUSER:MYPASS@localhost:8332');

                            $kadi = $_SESSION['username'];


                            // check for session address
                            if(isset($_SESSION['sendaddress'])) {
                                $sendaddress = refreshAddressIfStale($bitcoin,$_SESSION['sendaddress']); // session exists, check if its been used before
                                $_SESSION['sendaddress'] = $sendaddress;
                            } else {
                                // if address already exists in wallet (or new unfortunately), check the balance and set as main receivable address if zero
                                $curaddress = $bitcoin->getaccountaddress($kadi);
                                $sendaddress = refreshAddressIfStale($bitcoin,$curaddress);
                                $_SESSION['sendaddress'] = $sendaddress;
                            }

                            // save current balance
                            saveCurrentBalance($bitcoin, $_SESSION['sendaddress']);

                            $userBalance = $_SESSION['userbalance'];
                            $singleconfirmBalance = number_format($bitcoin->getbalance($_SESSION['username'], 0),8); // set to zero, this is near instant, set to one one on the side of caution
                            if($singleconfirmBalance > 0) {     // user has unconfirmed transactions
                                $unconfirmedBalance = $singleconfirmBalance - $userBalance;
                            }
                            echo "Current Balance: ". $userBalance ."<br />";
                            if((isset($unconfirmedBalance)) && ($unconfirmedBalance > 0)) {
                                echo "Unconfirmed Balance: ". $unconfirmedBalance ."<br />";
                            }

                            echo "<h2>Recent Transactions:</h2><table>";
                            $transactions = $bitcoin->listtransactions($_SESSION['username']);
                            foreach($transactions as $trans) {
                                if(isset($trans['account'])) {
                                    $transacct = $trans['account'];
                                } else {
                                    $transacct = '';
                                }
                                if(isset($trans['address'])) {
                                    $transaddress = $trans['address'];
                                } else {
                                    $transaddress = '';
                                }
                                if(isset($trans['category'])) {
                                    $transcategory = $trans['category'];
                                } else {
                                    $transcategory = '';
                                }
                                if(isset($trans['amount'])) {
                                    $transamount = $trans['amount'];
                                } else {
                                    $transamount = '';
                                }
                                if(isset($trans['confirmations'])) {
                                    $transconfirmations = $trans['confirmations'];
                                } else {
                                    $transconfirmations = '';
                                }
                                if(isset($trans['blockhash'])) {
                                    $transblockhash = $trans['blockhash'];
                                } else {
                                    $transblockhash = '';
                                }
                                if(isset($trans['blockindex'])) {
                                    $transblockindex = $trans['blockindex'];
                                } else {
                                    $transblockindex = '';
                                }
                                if(isset($trans['blocktime'])) {
                                    $transblocktime = $trans['blocktime'];
                                } else {
                                    $transblocktime = '';
                                }
                                if(isset($trans['txid'])) {
                                    $transtxid = $trans['txid'];
                                } else {
                                    $transtxid = '';
                                }
                                if(isset($trans['time'])) {
                                    $transtime = $trans['time'];
                                } else {
                                    $transtime = '';
                                }
                                if(isset($trans['timereceived'])) {
                                    $transtimereceived = $trans['timereceived'];
                                } else {
                                    $transtimereceived = '';
                                }
                                /*
                                $transaddress = $trans['address'];
                                $transcategory = $trans['category'];
                                $transamount = $trans['amount'];
                                $transconfirmations = $trans['confirmations'];
                                $transblockhash = $trans['blockhash'];
                                $transblockindex = $trans['blockindex'];
                                $transblocktime = $trans['blocktime'];
                                $transtxid = $trans['txid'];
                                $transtime = $trans['time'];
                                $transtimereceived = $trans['timereceived'];
                                */

                                echo "<tr><td>Address:</td><td>". $transaddress ."</td></tr>";
                                echo "<tr><td>Amount:</td><td>". number_format($transamount, 8) ."</td></tr>";
                                echo "<tr><td>Category:</td><td>". $transcategory ."</td></tr>";
                                echo "<tr><td>Confirmations:</td><td>". $transconfirmations ."</td></tr>";
                                echo "<tr><td>Blockhash:</td><td>". $transblockhash ."</td></tr>";
                                echo "<tr><td>txid:</td><td>". $transtxid ."</td></tr>";
                                echo "<tr><td>Time:</td><td>". date("Y - M - d H:i:s", $transtime) ."</td></tr>";
                                echo "<tr><td>&nbsp;</td></tr>";
                            }
                            ?>
                        </table></form>
                    </div>
                </div>
            </div>
            <div id="menu">
                <div class="menumargin">
                    <a href='index.php'>Home</a>
                    <a href='account.php'>Account</a>
                    <a href='deposit.php'>Deposit</a>
                    <a href='withdraw.php'>Withdraw</a>
                    <a href='contact.php'>Contact</a>
                    <a href='#'>Logout</a>
                </div>
            </div>
            <div id="footer"><a href="index.php">Home</a> | <a href="account.php">Account</a> | <a href="deposit.php">Deposit</a> | <a href="withdraw.php">Withdraw</a> | <a href="contact.php">Contact</a> | <a href="#">Logout</a> | </div>
        </div>
    </body>
</html>

jsonRPCClient.php;

    <?php
/*
                    COPYRIGHT

Copyright 2007 Sergio Vaccaro <sergio@inservibile.org>

This file is part of JSON-RPC PHP.

JSON-RPC PHP is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

JSON-RPC PHP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with JSON-RPC PHP; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

/**
 * The object of this class are generic jsonRPC 1.0 clients
 * http://json-rpc.org/wiki/specification
 *
 * @author sergio <jsonrpcphp@inservibile.org>
 */

 /* converted old fopen method to curl and added ability to use ssl - Galen */

class jsonRPCClient {  
    /**
     * Debug state
     *
     * @var boolean
     */
    private $debug;

    /**
     * The server URL
     *
     * @var string
     */
    private $url;
    /**
     * The request id
     *
     * @var integer
     */
    private $id;
    /**
     * If true, notifications are performed instead of requests
     *
     * @var boolean
     */
    private $notification = false;

    /**
     * Takes the connection parameters
     *
     * @param string $url
     * @param boolean $debug
     */
    public function __construct($url,$debug = false) {
        // server URL
        $this->url = $url;
        // proxy
        empty($proxy) ? $this->proxy = '' : $this->proxy = $proxy;
        // debug state
        empty($debug) ? $this->debug = false : $this->debug = true;
        // message id
        $this->id = 1;
    }

    /**
     * Sets the notification state of the object. In this state, notifications are performed, instead of requests.
     *
     * @param boolean $notification
     */
    public function setRPCNotification($notification) {
        empty($notification) ?
        $this->notification = false
        :
        $this->notification = true;
    }

    /**
     * Performs a jsonRCP request and gets the results as an array
     *
     * @param string $method
     * @param array $params
     * @return array
     */
        public function __call($method,$params) {
        // check
        if (!is_scalar($method)) {
            throw new Exception('Method name has no scalar value');
        }

        // check
        if (is_array($params)) {
            // no keys
            $params = array_values($params);
        } else {
            throw new Exception('Params must be given as array');
        }

        // sets notification or request task
        if ($this->notification) {
            $currentId = NULL;
        } else {
            $currentId = $this->id;
        }

        // prepares the request
        $request = array(
            'method' => $method,
            'params' => $params,
            'id' => $currentId
        );
        $request = json_encode($request);
        $this->debug && $this->debug='***** Request *****'."\n".$request."\n".'***** End Of request *****'."\n\n";

        // performs the HTTP POST
        $ch = curl_init($this->url);
        // curl ssl options
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
        $response = json_decode(curl_exec($ch),true);
        curl_close($ch);
        // debug output
        if ($this->debug) {
            echo nl2br($this->debug);
        }

        // final checks and return
        if (!$this->notification) {
            // check
            if ($response['id'] != $currentId) {
                throw new Exception('Incorrect response id (request id: '.$currentId.', response id: '.$response['id'].')');
            }
            if (!is_null($response['error'])) {
                throw new Exception('Request error: '.$response['error']);
            }
            return $response['result'];
        } else {
            return true;
        }
    }
}
?>

Пожалуйста помогите!!

ВАУ, понци /var/www/ponzi/htdocs/wallet/account.php просто ВАУ.....
может быть, владельца сервера просто зовут Карло?

Ответы (1)

Клиент jsonRPC плохо обрабатывает ошибки от bitcoind. источник

Вместо этого рекомендуется использовать php-библиотеку easybitcoin, доступную на github здесь . Его использование простое, и он правильно выводит ошибки 404 и 500.

require("easybitcoin.php");
$bitcoin = new Bitcoin("someusername", "somepassword");

$txid = $_GET["tx"];
$txinfo = $bitcoin->gettransaction($txid);
$amount = $txinfo["amount"]; 
echo $amount ? $amount : $bitcoin->error;