Author

Topic: PHP JSON sendfrom function (Read 4644 times)

sr. member
Activity: 868
Merit: 251
May 19, 2011, 07:31:20 PM
#6
Note that original Sergio Vaccaro's jsonRPCClient class is modified.
full member
Activity: 154
Merit: 100
May 19, 2011, 07:15:10 PM
#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
sr. member
Activity: 868
Merit: 251
May 19, 2011, 07:01:46 PM
#4
Look how I solved it here:
https://github.com/m0Ray/bitcoin_account
Requires PHP 5.2 or higher.
full member
Activity: 154
Merit: 100
May 19, 2011, 01: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.
newbie
Activity: 88
Merit: 0
May 09, 2011, 06: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:
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 
"
"
;

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


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...
newbie
Activity: 88
Merit: 0
May 09, 2011, 04: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:
$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]
";
}
?>


I get this error:
Code:
Warning: fopen(http://[email protected]: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 ) )
Jump to: