Bitcoin Forum
April 18, 2024, 09:38:40 AM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: PHP+JSON-RPC move command failing  (Read 1888 times)
lego (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
June 11, 2011, 07:47:04 AM
 #1

I'm new here and I'm not sure if this is the right place to post a question like this, but this is starting to get frustrating, anyway here is my problem.

I've been running into some trouble using the jsonRPCClient.php. It seems to work flawlessly for most everything except when trying to execute a move command. Every time I try to do a move it throws an exception stating that it can't connect to the json-rpc server. I've searched the forums, the wiki, and google several times but to no avail. Has anyone run into this issue before and if so how can I fix it?

I'm providing some sample code to show what I am trying to achieve. It's not the code I'm using just a summary of whats going on so please don't be too critical.

Sample code

Code:
<?php 
require_once 'jsonRPCClient.php';

$bitcoin = new jsonRPCClient("http://rpcuser:rpcpassword@127.0.0.1:8332/");

$accounts=array('a'=>'userA''b'=>'userB');

try{
print_r($bitcoin->getinfo()); //shows data

print_r($bitcoin->listaccounts()); //shows userA and userB with their balances

echo($bitcoin->getbalance($accounts['a'])); //echos 1.00

echo($bitcoin->getbalance($accounts['b'])); //echos 0.00

$bitcoin->move($accounts['a'], $accounts['b'], 0.5); 
//throws exception "Unable to connect to http://rpcuser:rpcpassword@127.0.0.1:8332/"

}catch(Exception $e){
die(
nl2br($e->getMessage()));
}


?>

The trust scores you see are subjective; they will change depending on who you have in your trust list.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713433120
Hero Member
*
Offline Offline

Posts: 1713433120

View Profile Personal Message (Offline)

Ignore
1713433120
Reply with quote  #2

1713433120
Report to moderator
1713433120
Hero Member
*
Offline Offline

Posts: 1713433120

View Profile Personal Message (Offline)

Ignore
1713433120
Reply with quote  #2

1713433120
Report to moderator
lego (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
June 11, 2011, 09:11:26 AM
 #2

nvm I found the issue.

What I said I was doing

Code:
$bitcoin->move($accounts['a'], $accounts['b'], 0.5);


What I was actually doing

Code:
$amount = $_POST['amount']; //stored as string value
$bitcoin->move($accounts['a'], $accounts['b'], $amount);

What I should have been doing

Code:
$amount = floatval($_POST['amount']); //convert string to float value
$bitcoin->move($accounts['a'], $accounts['b'], $amount);

Didn't even occur to me that the answer was in the sample code I had written. Embarrassed
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!