Bitcoin Forum
May 26, 2024, 07:35:45 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Bitcoind sendmany: json parsing error?  (Read 4269 times)
SlickTheNick (OP)
Full Member
***
Offline Offline

Activity: 220
Merit: 100


View Profile
December 17, 2012, 03:42:08 AM
 #1

Hey guys, so im trying to use the sendmany command via the jsonRPCClient.php script, however it keeps failing. Iv tried running the same command through the command line, but I keep getting a JSON parsing error:

Code:
# bitcoind sendmany "Main Account" {"1GawMPab9B7Bbt5FXPVDbHt6T2NrfH2EgC":0.0001}
error: Error parsing JSON:{1GawMPab9B7Bbt5FXPVDbHt6T2NrfH2EgC:0.0001}

iv tried wrapping the command in tripple quotes as well (read it on some other posts with similar problems), but it seems to change nothing.

As for the PHP end, here is the code I have:

Code:
		$senders = array();
foreach($getPayouts as $payout){

if(!isset($senders[$payout['address']])){
$senders[$payout['address']] = floatval($payout['amount']);
}
else{
$senders[$payout['address']] += floatval($payout['amount']);
}

}


try{
$payoutMoney = $bitcoin->sendmany("Main Account", json_encode($senders));
}
catch(Exception $e){
return false;
}

this section of code also fails, and gives me a bunch of failed http request errors.

Anyone have any ideas? Im pretty sure im formatting the queries correctly.. but I feel like theres something simple im missing here

Looking for a way to get some bitcoins for free? Check out http://earnfreebitcoins.com !
Get easy bitcoins at  https://coincontroller.com?r=eaef398b5 !
kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1025



View Profile
December 17, 2012, 04:51:07 AM
 #2

Unix shell quoting can be confusing if you aren't used to it.  Try:

Code:
bitcoind sendmany "Main Account" '{"1GawMPab9B7Bbt5FXPVDbHt6T2NrfH2EgC":0.0001}'

As for the PHP one, just hand the $senders array to $bitcoin->sendmany() directly, no need to pre-encode it.

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
SlickTheNick (OP)
Full Member
***
Offline Offline

Activity: 220
Merit: 100


View Profile
December 17, 2012, 05:04:20 AM
 #3

cool, that worked for the command line issue! however I tried taking the json_decode() out of the PHP, still fails everytime I try the command. commands like getinfo, listaccounts, getbalance etc. work fine though

Looking for a way to get some bitcoins for free? Check out http://earnfreebitcoins.com !
Get easy bitcoins at  https://coincontroller.com?r=eaef398b5 !
SlickTheNick (OP)
Full Member
***
Offline Offline

Activity: 220
Merit: 100


View Profile
December 17, 2012, 05:08:42 AM
 #4

if it helps, here is what is showing up in debug.log after I try the sendmany command via PHP


Code:
ThreadRPCServer method=sendmany
CTxMemPool::accept() : accepted 1c5ee41fa5 (poolsz 604)
Added 1 addresses from 141.238.223.79: 27 tried, 10658 new
Added 1 addresses from 91.225.164.20: 27 tried, 10658 new
CTxMemPool::accept() : accepted c2b6d38360 (poolsz 605)
received getdata for: tx afab87781697bdca4e4d
CTxMemPool::accept() : accepted 1b83ea1411 (poolsz 606)
received getdata for: tx 1b83ea1411605920b8de
received getdata for: tx 1b83ea1411605920b8de
received getdata for: tx 1b83ea1411605920b8de
received getdata for: tx 1b83ea1411605920b8de
received getdata for: tx 1b83ea1411605920b8de
received getdata for: tx 1b83ea1411605920b8de
CTxMemPool::accept() : accepted e5738700ee (poolsz 607)
received getdata (10 invsz)
received getdata for: tx a4c3433c44aced87923d
CTxMemPool::accept() : accepted 3bb646a5a9 (poolsz 608)

Looking for a way to get some bitcoins for free? Check out http://earnfreebitcoins.com !
Get easy bitcoins at  https://coincontroller.com?r=eaef398b5 !
kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1025



View Profile
December 17, 2012, 12:14:11 PM
 #5

Put print_r($senders); before the try block so that you can see exactly what is getting passed to bitcoin.

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
SlickTheNick (OP)
Full Member
***
Offline Offline

Activity: 220
Merit: 100


View Profile
December 17, 2012, 03:28:31 PM
 #6

Put print_r($senders); before the try block so that you can see exactly what is getting passed to bitcoin.

Code:
Array
(
    [1GawMPab9B7Bbt5FXPVDbHt6T2NrfH2EgC] => 0.0016
    [1MvX1RB5ERDx1xMaWQeH4zWZgCBB5i8BxD] => 0.00072
)

should be the correct format right?

Looking for a way to get some bitcoins for free? Check out http://earnfreebitcoins.com !
Get easy bitcoins at  https://coincontroller.com?r=eaef398b5 !
kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1025



View Profile
December 17, 2012, 04:35:30 PM
 #7

Put print_r($senders); before the try block so that you can see exactly what is getting passed to bitcoin.

Code:
Array
(
    [1GawMPab9B7Bbt5FXPVDbHt6T2NrfH2EgC] => 0.0016
    [1MvX1RB5ERDx1xMaWQeH4zWZgCBB5i8BxD] => 0.00072
)

should be the correct format right?

That looks right to me.  In your exception block, instead of just returning false, echo $e; first to see if you can get any useful information that way.

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
SlickTheNick (OP)
Full Member
***
Offline Offline

Activity: 220
Merit: 100


View Profile
December 18, 2012, 03:34:36 AM
 #8

Heres what im getting:

Code:
exception 'Exception' with message 'Unable to connect to http://mybituser:mybitpass@127.0.0.1:8332/' in jsonRPCClient.php:140
Stack trace:
#0 [internal function]: Slick_jsonRPCClient->__call('sendmany', Array)
#1 Model.php(427): Slick_jsonRPCClient->sendmany('Main Account', Array)
#2 Controller.php(20): Slick_BTC_Visit_Model->sendPayouts()
#3 index.php(46): Slick_BTC_Visit_Controller->visitSite()
#4 {main}

it seems like any time any command to the bitcoin client fails it just gives me the 'unable to connect to..' error rather then giving me any actual error info.. seems kind of odd

Looking for a way to get some bitcoins for free? Check out http://earnfreebitcoins.com !
Get easy bitcoins at  https://coincontroller.com?r=eaef398b5 !
kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1025



View Profile
December 18, 2012, 07:03:03 AM
 #9

Heres what im getting:

Code:
exception 'Exception' with message 'Unable to connect to http://mybituser:mybitpass@127.0.0.1:8332/' in jsonRPCClient.php:140
Stack trace:
#0 [internal function]: Slick_jsonRPCClient->__call('sendmany', Array)
#1 Model.php(427): Slick_jsonRPCClient->sendmany('Main Account', Array)
#2 Controller.php(20): Slick_BTC_Visit_Model->sendPayouts()
#3 index.php(46): Slick_BTC_Visit_Controller->visitSite()
#4 {main}

it seems like any time any command to the bitcoin client fails it just gives me the 'unable to connect to..' error rather then giving me any actual error info.. seems kind of odd

Hmm.  That doesn't seem right.  I'm almost positive that I've seen useful error messages from RPC calls from PHP before.  I'll fire up your code on my box tomorrow if I get time, just to see.

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
SlickTheNick (OP)
Full Member
***
Offline Offline

Activity: 220
Merit: 100


View Profile
December 18, 2012, 09:32:25 PM
 #10

I wonder if there is maybe some setting in bitcoin.conf, or even the rpcClient.php that would enable better error reporting? Seems very weird to me that it just says connection refused when something goes wrong..

Looking for a way to get some bitcoins for free? Check out http://earnfreebitcoins.com !
Get easy bitcoins at  https://coincontroller.com?r=eaef398b5 !
SlickTheNick (OP)
Full Member
***
Offline Offline

Activity: 220
Merit: 100


View Profile
December 18, 2012, 09:50:21 PM
 #11

I wonder if there is maybe some setting in bitcoin.conf, or even the rpcClient.php that would enable better error reporting? Seems very weird to me that it just says connection refused when something goes wrong..

I mean how much better do you want it to be? The connection was refused plain and simple and straightforward, check your firewall, your ports, your username, your password, make sure your rpcallowip is right, check everything.

I have double checked all those and none of that is the issue. I can do the following no problem:

Code:
$bitcoin->listtransactions();
$bitcoin->getbalance();
$bitcoin->move();
$bitcoin->listaccounts();
$bitcoin->getnewaddress();
$bitcoin->validateaddress();
$bitcoin->listreceivedbyaddress();
$bitcoin->listreceivedbyaccount();

All of those commands work fine for me, no errors or anything. There is no passphrase or anything currently on my wallet, and I can use both the sendtoaddress and sendmany command via command line, but using them via the jsonRPCClient, all I get is the connection refused. And its all on the localhost, no external server involved.

Looking for a way to get some bitcoins for free? Check out http://earnfreebitcoins.com !
Get easy bitcoins at  https://coincontroller.com?r=eaef398b5 !
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!