Author

Topic: PHP Help with bitcoind->listttransactions() ★0.02 btc bounty★ (Read 891 times)

newbie
Activity: 12
Merit: 0
newbie
Activity: 12
Merit: 0
Just got back home, and I'll test it in a few minutes and let you know! Meanwhile, could you send me your email in a PM? Since I'm a newbie, I have a lot of restrictions on posts and PM's, and it'd be awesome to communicate through email. Smiley
I'll let you know if it works.
full member
Activity: 141
Merit: 100
This works for me, here's a full example:
Code:
//I don't know which class and which version you use.
//To ensure that you're not running into incompatibility issues, I decided to includes this base class
class Bitcoin
{
    public 
$id 0;
    public 
$host "127.0.0.1";
    public 
$port 8332;
    public 
$user ""//Insert RPC username here
    
public $pass ""//Insert RPC password here

    
public function __call($func$param)
    {
        
$data json_encode(
            array(
                
'id'=>$this->id++,
                
'method'=>$func,
                
'params'=>$param
            
)
        );

        
$ch curl_init("http://".$this->host.":".$this->port."");
        if (
$ch)
        {
            
curl_setopt($chCURLOPT_RETURNTRANSFER1);
            
curl_setopt($chCURLOPT_USERPWDrawurlencode($this->user).":".rawurlencode($this->pass));
            
curl_setopt($chCURLOPT_POSTtrue);
            
curl_setopt($chCURLOPT_POSTFIELDS$data);
            
$out curl_exec($ch);
            
$error curl_error($ch);
            
curl_close($ch);
            if (
$error)
            {
                throw new 
Exception($error);
            }

            
$decoded json_decode($out);
            if (
$decoded === null)
            {
                throw new 
Exception("Malformed JSON: $out");
            }

            return 
$decoded;
        }
        else
        {
            throw new 
Exception(curl_error($ch));
        }
    }
}

$bitcoin = new Bitcoin();
$count 2;
$offset 0;

//Here's the actual code which groups the transaction
header("Content-Type: text/html; charset=UTF-8");
echo 
"";
echo 
"

Transactions

"
;

while (
true)
{
    
//First parameter: Account, * = all
    //Second parameter: Max count
    //Third parameter: Offset
    
$result $bitcoin->listtransactions('*'$count$offset);

    if (!
$result->result) break;

    echo 
"

Tranaction at offset $offset, max count $count

"
;
    echo 
"
".htmlspecialchars(print_r($resulttrue))."
"
;
    
$offset += $count;
}

echo 
"";

This is the change:

$count = 5; $offset = 0;
$bitcoin->listtransactions('*', $count, $offset); //$bitcoin->listtransactions('*', 5, 0); works of course too

instead of:

$bitcoin->listtransactions("count = 5, offset = 0");


I hope this helps.
As soon as you confirm that it works, my address is 1EwKrY5Bn3T47r4tYqSv6mMQkUyu7hZckV as in the signature Wink
newbie
Activity: 12
Merit: 0
Hey there,
I'm having a little trouble with PHP and $bitcoin->listtransactions() rpc.

In PHP I run

$bitcoin->listtransactions("count = 5, offset = 0");
In the hope of getting 5 transactions only, but I get the response

bool(false)
When I run $bitcoin->listtransactions(); alone, it works fine. What am I doing wrong?
I'd be happy to tip 0.025bitcoin to whoever can help me. Thanks.
Jump to: