Bitcoin Forum
December 04, 2016, 12:20:40 PM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Perl Client Problems  (Read 1457 times)
jfreak53
Sr. Member
****
Offline Offline

Activity: 297



View Profile WWW
October 08, 2011, 09:51:41 PM
 #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?

"Those who would give up essential Liberty, to purchase a little temporary Safety, deserve neither Liberty nor Safety." -Benjamin Franklin 1755
█ █ http://www.microthosting.com -- Free reseller web hosting, OpenVZ-XEN-HVM VPS', ATOM Dedicateds!
1480854040
Hero Member
*
Offline Offline

Posts: 1480854040

View Profile Personal Message (Offline)

Ignore
1480854040
Reply with quote  #2

1480854040
Report to moderator
1480854040
Hero Member
*
Offline Offline

Posts: 1480854040

View Profile Personal Message (Offline)

Ignore
1480854040
Reply with quote  #2

1480854040
Report to moderator
1480854040
Hero Member
*
Offline Offline

Posts: 1480854040

View Profile Personal Message (Offline)

Ignore
1480854040
Reply with quote  #2

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

Posts: 1480854040

View Profile Personal Message (Offline)

Ignore
1480854040
Reply with quote  #2

1480854040
Report to moderator
2112
Legendary
*
Offline Offline

Activity: 1708



View Profile
October 08, 2011, 11:26:20 PM
 #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
Sr. Member
****
Offline Offline

Activity: 297



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.

"Those who would give up essential Liberty, to purchase a little temporary Safety, deserve neither Liberty nor Safety." -Benjamin Franklin 1755
█ █ http://www.microthosting.com -- Free reseller web hosting, OpenVZ-XEN-HVM VPS', ATOM Dedicateds!
mndrix
Michael Hendricks
VIP
Sr. Member
*
Offline Offline

Activity: 447


View Profile
October 09, 2011, 01:27:17 AM
 #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
Sr. Member
****
Offline Offline

Activity: 297



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.

"Those who would give up essential Liberty, to purchase a little temporary Safety, deserve neither Liberty nor Safety." -Benjamin Franklin 1755
█ █ http://www.microthosting.com -- Free reseller web hosting, OpenVZ-XEN-HVM VPS', ATOM Dedicateds!
jfreak53
Sr. Member
****
Offline Offline

Activity: 297



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??

"Those who would give up essential Liberty, to purchase a little temporary Safety, deserve neither Liberty nor Safety." -Benjamin Franklin 1755
█ █ http://www.microthosting.com -- Free reseller web hosting, OpenVZ-XEN-HVM VPS', ATOM Dedicateds!
jfreak53
Sr. Member
****
Offline Offline

Activity: 297



View Profile WWW
October 09, 2011, 02:58:05 PM
 #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],
   };

"Those who would give up essential Liberty, to purchase a little temporary Safety, deserve neither Liberty nor Safety." -Benjamin Franklin 1755
█ █ http://www.microthosting.com -- Free reseller web hosting, OpenVZ-XEN-HVM VPS', ATOM Dedicateds!
ethought
Legendary
*
Offline Offline

Activity: 1190



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:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!