Bitcoin Forum
May 02, 2024, 07:56:15 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: PHP Help with bitcoind->listttransactions() ★0.02 btc bounty★  (Read 870 times)
theyounggun (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
January 31, 2015, 08:11:43 PM
 #1

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.
1714679775
Hero Member
*
Offline Offline

Posts: 1714679775

View Profile Personal Message (Offline)

Ignore
1714679775
Reply with quote  #2

1714679775
Report to moderator
1714679775
Hero Member
*
Offline Offline

Posts: 1714679775

View Profile Personal Message (Offline)

Ignore
1714679775
Reply with quote  #2

1714679775
Report to moderator
1714679775
Hero Member
*
Offline Offline

Posts: 1714679775

View Profile Personal Message (Offline)

Ignore
1714679775
Reply with quote  #2

1714679775
Report to moderator
"In a nutshell, the network works like a distributed timestamp server, stamping the first transaction to spend a coin. It takes advantage of the nature of information being easy to spread but hard to stifle." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714679775
Hero Member
*
Offline Offline

Posts: 1714679775

View Profile Personal Message (Offline)

Ignore
1714679775
Reply with quote  #2

1714679775
Report to moderator
1714679775
Hero Member
*
Offline Offline

Posts: 1714679775

View Profile Personal Message (Offline)

Ignore
1714679775
Reply with quote  #2

1714679775
Report to moderator
1714679775
Hero Member
*
Offline Offline

Posts: 1714679775

View Profile Personal Message (Offline)

Ignore
1714679775
Reply with quote  #2

1714679775
Report to moderator
Nikinger
Full Member
***
Offline Offline

Activity: 141
Merit: 100



View Profile
January 31, 2015, 09:12:33 PM
 #2

This works for me, here's a full example:
Code:
<?php
//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 "<CHANGEME!>"//Insert RPC username here
    
public $pass "<CHANGEME!>"//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 
"<html><body>";
echo 
"<h1>Transactions</h1>";

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

    if (!
$result->result) break;

    echo 
"<h2>Tranaction at offset $offset, max count $count</h2>";
    echo 
"<pre>".htmlspecialchars(print_r($resulttrue))."</pre>";
    
$offset += $count;
}

echo 
"</body></html>";

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

1EwKrY5Bn3T47r4tYqSv6mMQkUyu7hZckV
theyounggun (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
January 31, 2015, 09:57:00 PM
 #3

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.
theyounggun (OP)
Newbie
*
Offline Offline

Activity: 12
Merit: 0


View Profile
February 02, 2015, 06:09:06 AM
 #4

Solved.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!