I am creating a php script to use the sendmany() call to bitcoind. After some database calisthenics involving hitting three tables for permissions, checking user privileges and ensuring the send amounts are correct and there are enough bitcoins on the server, I wind up with the following array to send bitcoins to:
Array
(
[0] => Array
(
[coinadd] => mteCLqiEK7v5d3YbDQtxj8oKcdhtHRtXcw
[amount] => 0.21445033
)
[1] => Array
(
[coinadd] => 2N5aa9FBxGf5xmeLiDz1yJVNYdsfK9GUWWe
[amount] => 0.02588679
)
[2] => Array
(
[coinadd] => 2Muf4WEzFqNviURTdvkGSswHyrgMzR8optK
[amount] => 0.02601681
)
)
The below foreach generates the array below that.
foreach($paydata as $pay){
$mrules = getmerchrules($pay['merchant_id']);
$coinadd = get_merch_address_to_send_to($pay['merchant_id']);
if($mrules['autopay'] == 'yes'){
if($pay['balance'] > $mrules['minpay']){
if($coinadd !== ''){
$paynow[$coinadd['coinadd']] = $pay['balance'];
}
}
}
}
Array
(
[mteCLqiEK7v5d3YbDQtxj8oKcdhtHRtXcw] => 0.21445033
[2N5aa9FBxGf5xmeLiDz1yJVNYdsfK9GUWWe] => 0.02588679
[2Muf4WEzFqNviURTdvkGSswHyrgMzR8optK] => 0.02601681
)
So far so good.
Now on to the RPC call
here's the request echoed from the actual easybitcoin curl call. --
echo "here's the request -- \n".$request."\n"; <-- line 132 easybitcoin.php
{"method":"sendmany","params":["","{\"mteCLqiEK7v5d3YbDQtxj8oKcdhtHRtXcw\":\"0.24020698\",\"2N5aa9FBxGf5xmeLiDz1yJVNYdsfK9GUWWe\":\"0.02588679\",\"2Muf4WEzFqNviURTdvkGSswHyrgMzR8optK\":\"0.02601681\"}",1],"id":4}
EDIT: Some fancy echoing gets me this string which is what is actually sent to the bitcoind server through curl. This string also passes the jsonlint.com test.
Array
(
[19913] => 1
[52] => 1
[68] => 10
[10023] => Array
(
[0] => Content-type: application/json
)
[47] => 1
[10015] => {"method":"sendmany","params":["","{\"mteCLqiEK7v5d3YbDQtxj8oKcdhtHRtXcw\":\"0.24020698\",\"2N5aa9FBxGf5xmeLiDz1yJVNYdsfK9GUWWe\":\"0.02588679\",\"2Muf4WEzFqNviURTdvkGSswHyrgMzR8optK\":\"0.02601681\"}",1],"id":4}
)
EDIT: STILL NO CHANGE
Array
(
[result] =>
[error] => Array
(
[code] => -1
[message] => JSON value is not an object as expected
)
[id] => 4
)
Aaaand Kablooie! I get the following error from Bitcoind:
"JSON value is not an array as expected"
If I turn the JSON string into an object, then the error switches to
"JSON value is not an object as expected".
This snippet of code is from the library's __call method in easybitcoin.php
// If no parameters are passed, this will be an empty array
$params = array_values($params);
...
// Build the request, it's ok that params might have any empty array
$request = json_encode(array(
'method' => $method,
'params' => $params,
'id' => $this->id
));
Other than slitting my wrists and offering my blood to the programming gods, I've done everything I can think of. Can anyone spot what I am doing wrong here?
For anyone wondering, this command worked on ./bitcoin-cli
./bitcoin-cli sendmany "" "{\"mteCLqiEK7v5d3YbDQtxj8oKcdhtHRtXcw\":0.21445033, \"2N5aa9FBxGf5xmeLiDz1yJVNYdsfK9GUWWe\":0.02588679, \"2Muf4WEzFqNviURTdvkGSswHyrgMzR8optK\":0.02601681}" 1
Bitcoind response is a txid number
f4c443881a40054efbd5c3064268a91253f4cb2f7ba8caca96878d0dec46d774
<!-- This issue tracker is only for technical issues related to Bitcoin Core. General bitcoin questions and/or support requests are best directed to the Bitcoin StackExchange at https://bitcoin.stackexchange.com. For reporting security issues, please read instructions at https://bitcoincore.org/en/contact/. If the node is "stuck" during sync or giving "block checksum mismatch" errors, please ensure your hardware is stable by running memtest and observe CPU temperature with a load-test tool such as linpack before creating an issue! -->
<!-- Describe the issue -->
<!--- What behavior did you expect? -->
<!--- What was the actual behavior (provide screenshots if the issue is GUI-related)? -->
<!--- How reliably can you reproduce the issue, what are the steps to do so? -->
<!-- What version of Bitcoin Core are you using, where did you get it (website, self-compiled, etc)? -->
<!-- What type of machine are you observing the error on (OS/CPU and disk type)? -->
<!-- Any extra information that might be useful in the debugging process. -->
<!--- This is normally the contents of a `debug.log` or `config.log` file. Raw text or a link to a pastebin type site are preferred. -->