user974435
user974435

Reputation: 397

Dynamic PHP Array used in sendmany bitcoin command issue

I have following problem with dynamic array be used in sendmany transaction in bitcoin engine, problem described in code comments.

step 1 create array
step 2 inserting values to array
step 3 print an array to check the result which is correct
step 4 sendmany (here is a problem) see below

<?php
//step 1 create array
$to = array();
//step 2 inserting values to array
while ( $row_users = mysqli_fetch_array($getting_allowed_users) )
{
          $to[] = array($row_users['user_bitcoin_wallet'] => $currency);
}

//step 3 print an array to check the result which is correct
print_r(array_values($to)); 

//step 4 sendmany (here is a problem)

// if I do it that way sendmany is only sending to first wallet which is indexed [0]
// I cannot to foreach as php  code structure is not allowing {} inside the command
$bitcoin->sendmany($BuyerAccount,$to[0]); 

//Question: How I can display all the values from my array in following place
$bitcoin->sendmany($BuyerAccount,ALL THE VALUES); 

//example
$bitcoin->sendmany($BuyerAccount,"walet1"=>0.1,"walet2"=>0.1,"walet2"=>0.1.....); 

Upvotes: 1

Views: 1177

Answers (3)

Pierre
Pierre

Reputation: 430

Paolo gave a good answer, you can find ->sendmany() official documentation here: on the Mike Gogulski's bitcoin-php official Documentation

Upvotes: 0

Bennett
Bennett

Reputation: 11

You might consider spliiting that array up as too many in one request can be a bit much for the bitcoin daemon.

$chunks=array_chunk($to,100,true);
forach($chunks as $row) $bitcoin->sendmany($BuyerAccount,$row);

Upvotes: 1

Paolo
Paolo

Reputation: 15847

You're bulding the $to array in the wrong way. You need a key-value pairs array, you can build it up this way:

$to[$row_users['user_bitcoin_wallet']] = $currency;

Then you can call sendmany this way:

$bitcoin->sendmany($BuyerAccount,$to);

Your code became:

<?php
//step 1 create array
$to = array();

//step 2 inserting values to array
while ( $row_users = mysqli_fetch_array($getting_allowed_users) )
{
          $to[$row_users['user_bitcoin_wallet']] = $currency;
}

//step 3 print an array to check the result which is correct
print_r(array_values($to)); 

//step 4 sendmany

$bitcoin->sendmany($BuyerAccount,$to); 

Upvotes: 9

Related Questions