Author

Topic: Perl Client Problems (Read 1682 times)

legendary
Activity: 1316
Merit: 1000
May 31, 2013, 09:28:56 AM
#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.
sr. member
Activity: 298
Merit: 252
October 09, 2011, 09:58:05 AM
#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],
   };
sr. member
Activity: 298
Merit: 252
October 09, 2011, 09:19:11 AM
#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??
sr. member
Activity: 298
Merit: 252
October 08, 2011, 08:35:29 PM
#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.
vip
Activity: 447
Merit: 258
October 08, 2011, 08:27:17 PM
#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:[email protected]:8332';
my $api = Finance::Bitcoin::API->new( endpoint => $uri );
my $received = $api->call( 'listreceivedbyaddress', 0, $JSON::true );
print Dumper($received);
sr. member
Activity: 298
Merit: 252
October 08, 2011, 07:27:39 PM
#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.
legendary
Activity: 2128
Merit: 1073
October 08, 2011, 06: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".
sr. member
Activity: 298
Merit: 252
October 08, 2011, 04: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?
Jump to: