Author

Topic: [SOLVED] Json-RPC PHP send array (Read 4679 times)

full member
Activity: 235
Merit: 100
October 14, 2013, 11:46:54 AM
#16
Solved. It seems type conversion bug in PHP, just need to explicitly convert amount to float type.
Code:
$params[$address] = doubleval($amount);

Worked for me, using floatval()
hero member
Activity: 812
Merit: 1000
July 21, 2012, 12:25:52 AM
#15
thanks for the help... i'm off this for now, but will reply again if i find out anything else (when i try a different version, etc).
legendary
Activity: 2940
Merit: 1333
July 21, 2012, 12:10:04 AM
#14
It shouldn't matter whether you use bitcoin -server or bitcoind - they should react the same way to RPC calls.

I'm unable to reproduce having bitcoin fail like it is for you - but also I've not been able to find version 40101.

I only see the following tags in the repository:

$ git tag -l | grep v0.4
v0.4.0
v0.4.00rc1
v0.4.00rc2

and when I build v0.4.0:

$ ./bitcoind getinfo
{
    "version" : 40000,
    [...]

the version string is 40000.

I'm using Linux not Windows.

I'd suggest updating to a recent version of bitcoin and see if that fixes the problem for you.

I'm also wondering what happens if you try running bitcoind from the command line rather than using the PHP interface:

Code:
$ ./bitcoind sendmany '' '{"1tipznMYcN4SFijpcVXomcynKWAGnNBQ3":1}'
error: {"code":-6,"message":"Account has insufficient funds"}

You may find you need to omit the single quotes around the {...} in Windows - I'm not sure - try it with and without.
hero member
Activity: 812
Merit: 1000
July 20, 2012, 10:25:55 PM
#13
oh one other thing (maybe this is where some people will say 'well, duh'), this isn't actually bitcoind. this is bitcoin.exe with server=1 in the config.

this seems to work fine for sendtoaddress... when i call sendtoaddress via json it works and i suddenly see the transaction come up in the GUI.
hero member
Activity: 812
Merit: 1000
July 20, 2012, 10:22:31 PM
#12
Code:
Array
(
    [http] => Array
        (
            [method] => POST
            [header] => Content-type: application/json
            [content] => {"method":"sendmany","params":["",{"175WNXmJ1WVhFgVGKUqEhYtAQGRYAvqPA":1.2,"13QTW27b3SgqrEjefB9PbiZ6hcrVCJAxfx":1.3}],"id":1}
        )

)


Warning:  fopen(http://[email protected]:8332/) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error

 in [full path redacted]\jsonRPCClient.php on line 137

caught exception: object(Exception)#2 (7) {
  ["message":protected]=>
  string(68) "Unable to connect to http://myusername:[email protected]:8332/"
  ["string":"Exception":private]=>
  string(0) ""
  ["code":protected]=>
  int(0)
  ["file":protected]=>
  string(83) "[full path redacted]\jsonRPCClient.php"
  ["line":protected]=>
  int(145)
  ["trace":"Exception":private]=>
  array(2) {
    [0]=>
    array(6) {
      ["file"]=>
      string(76) "[full path redacted]\index2.php"
      ["line"]=>
      int(16)
      ["function"]=>
      string(6) "__call"
      ["class"]=>
      string(13) "jsonRPCClient"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(2) {
        [0]=>
        string(8) "sendmany"
        [1]=>
        array(2) {
          [0]=>
          string(0) ""
          [1]=>
          array(2) {
            ["175WNXmJ1WVhFgVGKUqEhYtAQGRYAvqPA"]=>
            float(1.2)
            ["13QTW27b3SgqrEjefB9PbiZ6hcrVCJAxfx"]=>
            float(1.3)
          }
        }
      }
    }
    [1]=>
    array(6) {
      ["file"]=>
      string(76) "[full path redacted]\index2.php"
      ["line"]=>
      int(16)
      ["function"]=>
      string(8) "sendmany"
      ["class"]=>
      string(13) "jsonRPCClient"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(2) {
        [0]=>
        string(0) ""
        [1]=>
        array(2) {
          ["175WNXmJ1WVhFgVGKUqEhYtAQGRYAvqPA"]=>
          float(1.2)
          ["13QTW27b3SgqrEjefB9PbiZ6hcrVCJAxfx"]=>
          float(1.3)
        }
      }
    }
  }
  ["previous":"Exception":private]=>
  NULL
}

line 137 of the rpc client is this:

Code:
if ($fp = fopen($this->url, 'r', false, $context)) {
legendary
Activity: 2940
Merit: 1333
July 20, 2012, 10:13:08 PM
#11
I just built a version 4 bitcoind.  I didn't let it touch my wallet, so I don't know if it would work fully, but it gets as far as complaining that the account I'm sending from has insufficient funds.

Can you try code like this and tell me what it shows?

Code:
$params = array();

$params['1addr1'] = 1.2;
$params['1addr2'] = 1.3;

try {
    $bitcoin->sendmany('', $params);
}
catch (Exception $e) {
    print "caught exception: ";
    var_dump($e);
}
hero member
Activity: 812
Merit: 1000
July 20, 2012, 09:18:23 PM
#10
Do you get any kind of an error message when it quits?  Is there a logfile with errors in maybe?

Where did you get your copy of jsonRPCClient.php from?

What's 40101 the version number of?

1. the php log file is just the usual... Warning: fopen(http://[email protected]:8332/) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in... etc, etc. same as what's printed on the browser with full error reporting.

this was in the tail of bitcoin's debug.log:

Code:

ThreadRPCServer method=getinfo
keypool reserve 1353
keypool return 1353
ThreadRPCServer method=sendmany
askfor tx 2e60cb02f1d7961d518e   0
sending getdata: tx 2e60cb02f1d7961d518e
askfor tx 2e60cb02f1d7961d518e   1342836949000000
askfor tx 2e60cb02f1d7961d518e   1342837069000000
ERROR: ConnectInputs() : 2e60cb02f1 mapTransactions prev not found 9612453f24
ERROR: AcceptToMemoryPool() : ConnectInputs failed 2e60cb02f1
storing orphan tx 2e60cb02f1
askfor tx cc505b8b6973449c51af   0
sending getdata: tx cc505b8b6973449c51af
askfor tx cc505b8b6973449c51af   1342836951000000
AcceptToMemoryPool(): accepted cc505b8b69
askfor tx 0d43330369bb8cf84053   0
sending getdata: tx 0d43330369bb8cf84053
received getdata for: tx cc505b8b6973449c51af
askfor tx 0d43330369bb8cf84053   1342836952000000
askfor tx 3e68f2e0f7bcdede4c9b   0
sending getdata: tx 3e68f2e0f7bcdede4c9b
askfor tx 3e68f2e0f7bcdede4c9b   1342836953000000

are those ERROR's related to the sendmany?

2. i don't remember where my copy came from, but it's worked for every other function i've thrown at it.

3. 40101 is the bitcoin client, as returned by getinfo()

legendary
Activity: 2940
Merit: 1333
July 20, 2012, 09:06:05 PM
#9
Do you get any kind of an error message when it quits?  Is there a logfile with errors in maybe?

Where did you get your copy of jsonRPCClient.php from?

What's 40101 the version number of?
hero member
Activity: 812
Merit: 1000
July 20, 2012, 08:09:37 PM
#8
i found out how to output what's actually being sent through json:

Code:
Array
(
    [http] => Array
        (
            [method] => POST
            [header] => Content-type: application/json
            [content] => {"method":"sendmany","params":["",{"175WNXmJ1WVhFgVGKUqEhYtAQGRYAvqPA":0.02,"13QTW27b3SgqrEjefB9PbiZ6hcrVCJAxfx":0.03}],"id":1}
        )

)

can't see anything wrong there though.
hero member
Activity: 812
Merit: 1000
July 20, 2012, 07:59:48 PM
#7
no, it dies before the 3rd vardump can output anything:

Code:
array(0) {
}

array(2) {
  ["175WNXmJ1WVhFgVGKUqEhYtAQGRYAvqPA"]=>
  float(0.02)
  ["13QTW27b3SgqrEjefB9PbiZ6hcrVCJAxfx"]=>
  float(0.03)
}

just before that, the json connection is alive and well; i do a getinfo and it works, and sendtoaddress still works.

i am trying this first on an older box, but this [version] => 40101 should be able to handle it, shouldn't it?

also, i don't actually know a 'from' account because i'm using a wallet that's only ever been used in the GUI, so no account names. so I'm leaving that blank:

Code:
var_dump($bitcoin->sendmany('', $params));
legendary
Activity: 2940
Merit: 1333
July 20, 2012, 07:09:01 PM
#6
this isn't working for me... i've tried every different combination of single quote / double quote but the following just kills the json-rpc connection:

What do you see if you do this:

Quote
$params = array();

var_dump($params);

$params['1addr1'] = 1.2;
$params['1addr2'] = 1.3;

var_dump($params);

var_dump($bitcoin->sendmany('account', $params));

The var_dump should show you what's going wrong.

Maybe it's
  "PHP Fatal error:  Uncaught exception 'Exception' with message 'Request error: {"code":-6,"message":"Account has insufficient funds"}'"
or
  "PHP Fatal error:  Uncaught exception 'Exception' with message 'Request error: {"code":-13,"message":"Error: Please enter the wallet passphrase with walletpassphrase first."}'"
or some such other error.

It should give you an idea of what's going wrong though.
full member
Activity: 168
Merit: 100
Firstbits: 175wn
July 18, 2011, 05:32:51 PM
#5
Glad it's working.
legendary
Activity: 1582
Merit: 1002
July 18, 2011, 05:31:56 PM
#4
Solved. It seems type conversion bug in PHP, just need to explicitly convert amount to float type.
Code:
$params[$address] = doubleval($amount);
legendary
Activity: 1582
Merit: 1002
July 18, 2011, 05:21:36 PM
#3
Code:
$bitcoin->sendmany("", array('address1' => 0.001, 'address2' => 0.002));
Now works. But dynamically created array doesn't works...
Code:
tried
$params[$address] = $amount;
and
$params["$address"] = $amount;
...
$bitcoin->sendmany("", $params);
full member
Activity: 168
Merit: 100
Firstbits: 175wn
July 18, 2011, 05:07:54 PM
#2
The first parameter is the account name - "" by default.

So, instead of:
Code:
$bitcoin->sendmany($params);
try:
Code:
$bitcoin->sendmany("", $params);
legendary
Activity: 1582
Merit: 1002
July 18, 2011, 04:58:35 PM
#1
I want to send multiple payments at once, so I use "sendmany", but seems I wrongly pass arrays. Tried
Code:
for($i = 0; $i < sizeof($list); $i++) {
...
$params[$address] = $amount;
}
$bitcoin->sendmany($params);
and
Code:
$bitcoin->sendmany(array('address1' => 0.001, 'address2' => 0.002));

both doesn't work. What I am doing incorrectly?



Jump to: