I'm assuming people have done this? If so, might anyone be willing to post a sample of their code?
Something to get you started. It's not exactly automated, but shouldn't take too much extra work to get it that step further.
coincontrol.php will give you an overview of all blocks in a wallet, and let you select which blocks to include in a transaction, as well as define an output address.
This will be passed on to createraw.php which will create the "createrawtransaction" string. NB This script will only display the transaction string. You will have to manually run the "createrawtransaction" string on the daemon (followed, of course, by "signrawtransaction" and "sendrawtransaction").
Code is provided as-is. Hope it helps.
coincontrol.php
$user="rpcuser";
$pass="rpcpass";
$ip="127.0.0.1";
$port="18889";
class Coin {
private $username;
private $password;
private $proto;
private $host;
private $port;
private $url;
public $status;
public $error;
public $raw_response;
public $response;
private $id = 0;
public function __construct($username, $password, $host = 'localhost', $port = 8332) {
$this->username = $username;
$this->password = $password;
$this->host = $host;
$this->port = $port;
}
public function __call($method, $params) {
$this->status = null;
$this->error = null;
$this->raw_response = null;
$this->response = null;
$params = array_values($params);
$this->id++;
$request = json_encode(array(
'method' => $method,
'params' => $params,
'id' => $this->id));
$curl = curl_init("http://{$this->host}:{$this->port}/");
$options = array(
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => $this->username . ':' . $this->password,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_HTTPHEADER => array('Content-type: application/json'),
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $request);
curl_setopt_array($curl, $options);
$this->raw_response = curl_exec($curl);
$this->response = json_decode($this->raw_response, true);
$this->status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$curl_error = curl_error($curl);
curl_close($curl);
if (!empty($curl_error)) {
$this->error = $curl_error;
}
if ($this->response['error']) {
$this->error = $this->response['error']['message'];
} elseif ($this->status != 200) {
switch ($this->status) {
case 400:
$this->error = 'HTTP_BAD_REQUEST';
break;
case 401:
$this->error = 'HTTP_UNAUTHORIZED';
break;
case 403:
$this->error = 'HTTP_FORBIDDEN';
break;
case 404:
$this->error = 'HTTP_NOT_FOUND';
break;
}
}
if ($this->error) {
return false;
}
return $this->response['result'];
}
}
echo "\n";
echo "\n";
echo "\n\n";
echo "\n";
echo "
echo $name."
;
echo "
Recipient:
";
echo "\n";
echo "\n";
echo "
\n";
echo "\n";
mysqli_close($con);
?>
createraw.php
$addr=$_POST['addr'];
$in=0;
$am=0;
$rawstr="";
echo "\n";
echo "\n";
echo "\n\n";
echo "\n";
echo "
foreach ($tx as $txs) {
echo $txs."
";
$txdata=explode(":",$txs);
$txid=$txdata[0];
$vout=$txdata[1];
$amnt=$txdata[2];
$in=$in+1;
$am=$am+$amnt;
if (strlen($rawstr)==0) {
$rawstr="createrawtransaction '[{\"txid\":\"".$txid."\",\"vout\":".$vout."}";
} else {
$rawstr=$rawstr.",{\"txid\":\"".$txid."\",\"vout\":".$vout."}";
}
}
$rawstr=$rawstr."]'";
$txsize=$in*149 + 44;
$txfee=ceil($txsize/1000)*0.0001;
$txout=$am-$txfee;
$rawstr=$rawstr." '{\"".$addr."\":".$txout."}'";
echo "
Input count: ".$in."
";
echo "Input amount: ".$am."
";
echo "TX Size: ".$txsize."
";
echo "TX Fee: ".$txfee."
";
echo "To be sent: ".$txout."
";
echo ".$rawstr."";
echo "
\n";
echo "\n";
?>