Bitcoin Forum
April 19, 2024, 05:11:47 AM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Perl Client Problems  (Read 1661 times)
jfreak53 (OP)
Sr. Member
****
Offline Offline

Activity: 298
Merit: 252



View Profile WWW
October 08, 2011, 09:51:41 PM
Merited by ABCbits (1)
 #1

Anyone have any experience developing a perl client with bitcoin and JSON?  Having a problem when sending parameters to the RPC.  When sending params it comes back "500 Internal Server Error", without params RPC works fine.

Have tried a bunch of way but this is how it should be, right?

Code:
my $obj = {
      method  => 'listreceivedbyaddress',
      params  => [ 0, true ],
   };

Keep getting that 500 error with params, like I said without params works fine.  Tried ', " and I don't know how many other combinations.  Anyone else ever have this problem?

█ █ microtronixdc.com - Performance VPS, Dedicated Servers, Colocation, Full-Rack options!
Massive Network Bandwidth options with Fiber throughout! Always-On DDoS Mitigation for all traffic!
1713503507
Hero Member
*
Offline Offline

Posts: 1713503507

View Profile Personal Message (Offline)

Ignore
1713503507
Reply with quote  #2

1713503507
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713503507
Hero Member
*
Offline Offline

Posts: 1713503507

View Profile Personal Message (Offline)

Ignore
1713503507
Reply with quote  #2

1713503507
Report to moderator
2112
Legendary
*
Offline Offline

Activity: 2128
Merit: 1065



View Profile
October 08, 2011, 11:26:20 PM
Last edit: October 09, 2011, 02:01:40 AM by 2112
 #2

Post the whole non-working but runnable code snippet. Otherwise it is hard to guess.

Edit: yeah, I'm slow. Change "true" to "JSON::true".

Please comment, critique, criticize or ridicule BIP 2112: https://bitcointalk.org/index.php?topic=54382.0
Long-term mining prognosis: https://bitcointalk.org/index.php?topic=91101.0
jfreak53 (OP)
Sr. Member
****
Offline Offline

Activity: 298
Merit: 252



View Profile WWW
October 09, 2011, 12:27:39 AM
 #3

It's off the API page.

Code:
my $obj = {
      method  => 'listreceivedbyaddress',
      params  => [ 0, true ],
   };
 
  my $res = $client->call( $uri, $obj );
 
  if ($res) {
if ($res->is_error) { print "Error : ", $res->error_message; exit; }
else {
print Dumper($myres);
}
  } else {
        print $client->status_line;
exit;
  }

As stated it works without the params part just fine, but if I include the params in any form it hits the line:

Code:
print $client->status_line;
exit;

Because it doesn't work with params for some reason, well I figure we have them in wrong some how but not sure how.

█ █ microtronixdc.com - Performance VPS, Dedicated Servers, Colocation, Full-Rack options!
Massive Network Bandwidth options with Fiber throughout! Always-On DDoS Mitigation for all traffic!
mndrix
Michael Hendricks
VIP
Sr. Member
*
Offline Offline

Activity: 447
Merit: 258


View Profile
October 09, 2011, 01:27:17 AM
Merited by ABCbits (1)
 #4

Without seeing your entire program (for example, variables $client and $uri aren't defined in your snippet above), it's hard to say for sure what's going wrong.  I'm suspicious of "true" in the params line since Perl has no native boolean type.  In this context, you probably need $JSON::true

I use Finance::Bitcoin::API for Perl programs that interact with the Bitcoin API.  It works great.  Here's an example:

Code:
use strict;
use warnings;
use Finance::Bitcoin::API;
use Data::Dumper;

my $uri = 'http://username:password@127.0.0.1:8332';
my $api = Finance::Bitcoin::API->new( endpoint => $uri );
my $received = $api->call( 'listreceivedbyaddress', 0, $JSON::true );
print Dumper($received);
jfreak53 (OP)
Sr. Member
****
Offline Offline

Activity: 298
Merit: 252



View Profile WWW
October 09, 2011, 01:35:29 AM
 #5

Beautiful, that's actually what it was.  Didn't really think it would matter since it was passing it to the bitcoind program and it was handling the boolean.  But that worked thank you.

█ █ microtronixdc.com - Performance VPS, Dedicated Servers, Colocation, Full-Rack options!
Massive Network Bandwidth options with Fiber throughout! Always-On DDoS Mitigation for all traffic!
jfreak53 (OP)
Sr. Member
****
Offline Offline

Activity: 298
Merit: 252



View Profile WWW
October 09, 2011, 02:19:11 PM
 #6

Ok now the same problem am having with the 'sendtoaddress' command.  The amount is the problem here.  Bitcoind is expecting a real constant, and it's giving the same error.

Have tried Data::Types and to_real, to_float and to_decimal, none seem to work.  Also tried just sending the amount, for instance, this doesn't work with any of the above or alone:

Code:
my $obj = {
      method  => 'sendtoaddress',
      params  => ["$in{address}", $in{amount}],
   };

But this does:

Code:
my $obj = {
      method  => 'sendtoaddress',
      params  => ["$in{address}", 0.005],
   };

Any other ideas on how to convert that amount to a real in perl??

█ █ microtronixdc.com - Performance VPS, Dedicated Servers, Colocation, Full-Rack options!
Massive Network Bandwidth options with Fiber throughout! Always-On DDoS Mitigation for all traffic!
jfreak53 (OP)
Sr. Member
****
Offline Offline

Activity: 298
Merit: 252



View Profile WWW
October 09, 2011, 02:58:05 PM
Merited by ABCbits (1)
 #7

Ok nevermind did a small trick and made it work, don't know if it's the right way but it works for future reference anyone looking.

Correct way is:

Code:
$amt = $in{amount} + 0.0;
  my $obj = {
      method  => 'sendtoaddress',
      params  => ["$in{address}", $amt],
   };

█ █ microtronixdc.com - Performance VPS, Dedicated Servers, Colocation, Full-Rack options!
Massive Network Bandwidth options with Fiber throughout! Always-On DDoS Mitigation for all traffic!
ethought
Legendary
*
Offline Offline

Activity: 1316
Merit: 1000



View Profile
May 31, 2013, 02:28:56 PM
 #8

Ok nevermind did a small trick and made it work, don't know if it's the right way but it works for future reference anyone looking.

Correct way is:

Code:
$amt = $in{amount} + 0.0;
  my $obj = {
      method  => 'sendtoaddress',
      params  => ["$in{address}", $amt],
   };

Thank you - just what I was looking for.
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!