Bitcoin Forum
December 05, 2016, 08:33:22 AM *
News: Latest stable version of Bitcoin Core: 0.13.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: PHP JSON sendfrom function  (Read 4271 times)
sentry
Newbie
*
Offline Offline

Activity: 27


View Profile WWW
May 09, 2011, 09:51:00 PM
 #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 ) )

Donations @ http://www.bitcoinplus.com/generate?for=533592
You don't have to give anything, just your idle time if you like what I'm doing.

Use Bitcoin7 (https://www.bitcoin7.com/?ref=8986)!
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
sentry
Newbie
*
Offline Offline

Activity: 27


View Profile WWW
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...

Donations @ http://www.bitcoinplus.com/generate?for=533592
You don't have to give anything, just your idle time if you like what I'm doing.

Use Bitcoin7 (https://www.bitcoin7.com/?ref=8986)!
Alex Beckenham
Full Member
***
Offline Offline

Activity: 154


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: 364



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.

IT-услуги широкого профиля за биткойн.
V for Vendetta, not for «vvhite ribbon»
Alex Beckenham
Full Member
***
Offline Offline

Activity: 154


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: 364



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

Note that original Sergio Vaccaro's jsonRPCClient class is modified.

IT-услуги широкого профиля за биткойн.
V for Vendetta, not for «vvhite ribbon»
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!