Bitcoin Forum
May 08, 2024, 06:44:06 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: PHP JSON sendfrom function  (Read 4622 times)
sentry (OP)
Newbie
*
Offline Offline

Activity: 88
Merit: 0


View Profile
May 09, 2011, 09:51:00 PM
Last edit: May 09, 2011, 10:29:34 PM by sentry
 #1

Would someone mind taking a look at this, I can't figure out what I'm doing wrong, it seems like it shouldn't be this difficult. I think the problem is my typecasts, whether its a string, int, or float.

Code:
<?php
$bitcoin 
= new jsonRPCClient("http://".BC_USER.":".BC_PASS."@".BC_HOST.":".BC_PORT);

$to "1FN8m1bzfzqo761p4vAwU6Rb2vJD3dFs7a";

//print_r($bitcoin->listreceivedbyaccount());

foreach($bitcoin->listreceivedbyaccount() as $key=>$value){
if($bitcoin->getbalance((string)$value['account']) > "0")
$bitcoin->sendfrom((string)$value['account'], (string)$to, (float)$bitcoin->getbalance((string)$value['account']));
//echo "$value[account] => $value[amount]<br>";
}
?>


I get this error:
Code:
Warning: fopen(http://...@127.0.0.1:8332) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in \www\classes\jsonRPCClient.php on line 132

Fatal error: Uncaught exception 'Exception' with message 'Unable to connect to http://****:****@127.0.0.1:8332' in \www\classes\jsonRPCClient.php:140 Stack trace: #0 \www\bitcoin.php(20): jsonRPCClient->__call('sendfrom', Array) #1\www\bitcoin.php(20): jsonRPCClient->sendfrom(0, '1FN8m1bzfzqo761...', 3.07) #2 {main} thrown in \www\classes\jsonRPCClient.php on line 140

print_r shows this for $bitcoin->listreceivedbyaccount()

Code:
Array ( [0] => Array ( [account] => Mining [label] => Mining [amount] => 3.07 [confirmations] => 424 ) [1] => Array ( [account] => Personal [label] => Personal [amount] => 0.99 [confirmations] => 1021 ) [2] => Array ( [account] => f899139df5e1059396431415e770c6dd [label] => f899139df5e1059396431415e770c6dd [amount] => 0.3 [confirmations] => 873 ) )
1715193846
Hero Member
*
Offline Offline

Posts: 1715193846

View Profile Personal Message (Offline)

Ignore
1715193846
Reply with quote  #2

1715193846
Report to moderator
1715193846
Hero Member
*
Offline Offline

Posts: 1715193846

View Profile Personal Message (Offline)

Ignore
1715193846
Reply with quote  #2

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

Posts: 1715193846

View Profile Personal Message (Offline)

Ignore
1715193846
Reply with quote  #2

1715193846
Report to moderator
sentry (OP)
Newbie
*
Offline Offline

Activity: 88
Merit: 0


View Profile
May 09, 2011, 11:04:37 PM
 #2

I have figured this out, I overlooked that the wallet has no balance to send anything from  Grin . I was able to use move though as the whole point of all this was to consolidate balances into one account. Although strangely enough I'm seeing ghost accounts that do not show up in the wallet but are listed by the RPC, oh well. For anyone following this and interested in the code, here ya go!

Code:
<?php
require_once dirname(__FILE__) . "/classes/jsonRPCClient.php";

define ("BC_HOST""127.0.0.1");
define ("BC_USER""***");
define ("BC_PASS""***");
define ("BC_PORT""8332");

$bitcoin = new jsonRPCClient("http://".BC_USER.":".BC_PASS."@".BC_HOST.":".BC_PORT);

$to "ACCOUNT_NAME";

print_r($bitcoin->listaccounts());

echo 
"<hr>";

foreach(
$bitcoin->listaccounts() as $key=>$value){
if($bitcoin->getbalance((string)$key) > "0")
$bitcoin->move((string)$key, (string)$to, (float)$value);
echo "$key => ".(float)$value."<br>";
}
?>


This simply moves all balances from accounts greater than 0 into the account you tell it to. I would really like to settle the negative accounts somehow, but I'll get into that soon. Needed this because on my bank project I have been working on my account shows I have a value > 0, but the wallet total shows 0...
Alex Beckenham
Full Member
***
Offline Offline

Activity: 154
Merit: 100


View Profile
May 19, 2011, 06:44:06 PM
 #3

I've been trying to find documentation on what the sendfrom function actually returns...

True or false or something more detailed?

Code:
try {
$bitcoin->sendfrom($acc,$addr,(float)$amt);
} catch (Exception $e) {
die($e);
}

Edit: Okay just did a test and it appears to return a txid... is this documented anywhere handy yet? Had no luck searching for it in Google.

m0Ray
Sr. Member
****
Offline Offline

Activity: 868
Merit: 251


View Profile
May 20, 2011, 12:01:46 AM
 #4

Look how I solved it here:
https://github.com/m0Ray/bitcoin_account
Requires PHP 5.2 or higher.
Alex Beckenham
Full Member
***
Offline Offline

Activity: 154
Merit: 100


View Profile
May 20, 2011, 12:15:10 AM
 #5

Thanks m0Ray, I'm taking a look now.

I also updated the 'sendfrom' details on this page:

https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list#Full_list

m0Ray
Sr. Member
****
Offline Offline

Activity: 868
Merit: 251


View Profile
May 20, 2011, 12:31:20 AM
 #6

Note that original Sergio Vaccaro's jsonRPCClient class is modified.
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!