Exemplo n.º 1
0
foreach ($data as $tx) {
    $outputs = $tx->out;
    foreach ($outputs as $output) {
        $btc = $output->value;
        $value = $btc * 100000000;
        $script = $output->scriptPubKey;
        $scriptparts = explode(" ", $script);
        $hash = "";
        for ($i = 0; $i < count($scriptparts); $i++) {
            if ($scriptparts[$i] == "OP_HASH160") {
                $hash = $scriptparts[$i + 1];
                break;
            }
        }
        if ($hash != "") {
            $address = $bc->hash160ToAddress($hash);
            $txhash = $tx->hash;
            /*
                                    $stmt = $db->prepare("INSERT INTO `unconfirmed_tx` (`txhash`, `to`, `value`, `timestamp`) VALUES (?, ?, ?, NOW())");
                                    $stmt->bind_param('ssi', $txhash, $address, $value);
                                    $db->insert($stmt);
            */
            $stmt = $db->prepare("\n                            SELECT order_address.order_id FROM `order_address`\n                            JOIN orders on orders.order_id = order_address.`order_id`\n                            WHERE orders.confirmations = 0 AND orders.active = 1\n                            AND order_address.address = ?\n                            ");
            $stmt->bind_param('s', $address);
            $db->select($stmt);
            $stmt->bind_result($orderid);
            while ($stmt->fetch()) {
                $istmt = $db->prepare("INSERT INTO active_uncomfirmed_monitors (order_id, tx_hash, address, value) VALUES (?, ?, ?, ?)");
                $istmt->bind_param('issi', $orderid, $txhash, $address, $value);
                $db->insert($istmt);
            }
Exemplo n.º 2
0
//Select 10000 new outputs, if there are more the script will slowly catch up (Unless bitcoin grows to where 10.000 outputs are used each minute)
$res = $db->queryAbe("SELECT `pubkey_hash` as `pubkey`, `txout_value` as `value`, `tx_id`, `block_id` FROM txout_detail WHERE `tx_id` > ".$lasttx." LIMIT 10000");
if ($res) {
    $num = $res->num_rows;
    echo "Found $num new transactions \r\n";
    flush();

//For now we calculate the address from the hash of each transaction, if there is alot of transactions it would be better to calculate the hash of the monitored addresses, and store it in the database.
    $bc = new Bitcoin();

    if ($num > 0) {
        $txid = $lasttx;

        while ($row = $res->fetch_array()) {
            $address = $bc->hash160ToAddress($row['pubkey']);
            $txid = $row['tx_id'];
            $value = $row['value'];

//		echo $row['tx_id']." - ".$row['pubkey']." (".$address.") = ".$row['value']."\r\n";
//		flush();

            if (isset($addresses[$address])) {
                echo "$address is a monitored address !! \r\n";
                foreach ($addresses[$address] as $orderid) {
                    $db->query("INSERT IGNORE INTO active_monitors (`order_id`, `tx_id`, `address`, `value`) VALUES (".$orderid.", ".$txid.", '".$address."', ".$value.")");
                }
            }
        }

        $stmt = $db->prepare("UPDATE `sequence` SET `value`=? WHERE `key`=?");
Exemplo n.º 3
0
    echo "$start -- $url -- $address -- $key-- $confirmations \r\n";

    //Check if there are any payments made after $start with $confirmations
    $res = $db->queryAbe("SELECT `pubkey_hash` as `pubkey`, `txout_value` as `value`, `tx_id`, `block_id` FROM txout_detail WHERE `tx_id` > ".$start."");
    if ($res) {
        $num = $res->num_rows;
        echo "Found $num new transactions \r\n";
        flush();

        //For now we calculate the address from the hash of each transaction.
	//If there is alot of transactions it would be better to calculate the hash of the monitored addresses, and store it in the database.
        $bc = new Bitcoin();

        if ($num > 0) {
            while ($row = $res->fetch_array()) {
                $payee = $bc->hash160ToAddress($row['pubkey']);
                $tx = $row['tx_id'];
                $orderid = $row['order_id'];
                $value = $row['value'];
                $btc = round($value / 100000000,8);

                if ($address == $payee) {
                    echo "MATCH for $payee !!!";



                    $blockres = $db->queryAbe("SELECT block_id FROM block_tx WHERE tx_id = ".$row['tx_id']."");
                    if ($blockres) {
                        $blockrow = $blockres->fetch_array();
                        $block = $blockrow["block_id"];
                        echo "Block for tx is ".$block."\r\n";
Exemplo n.º 4
0
 $output["rows"][$ri] = array();
 if (isset($row["acceptedshares"])) {
     $luck = 100 * ($row["network_difficulty"] / $row["acceptedshares"]);
 } else {
     $luck = 0;
 }
 if ($row["confirmations"] >= 120) {
     $row["confirmations"] = 120;
 }
 list($seconds, $minutes, $hours) = extractTime($row["duration"]);
 $seconds = sprintf("%02d", $seconds);
 $minutes = sprintf("%02d", $minutes);
 $hours = sprintf("%02d", $hours);
 $hashrate = $row["acceptedshares"] * 4294967296 / $row["duration"];
 if (isset($row['keyhash'])) {
     $fulladdress = \Bitcoin::hash160ToAddress(bits2hex($row['keyhash']));
 } else {
     $fulladdress = "UNKNOWN_USER";
 }
 $output["rows"][$ri]["luck"] = $luck;
 $output["rows"][$ri]["confirmations"] = $row["confirmations"];
 $output["rows"][$ri]["blockhash"] = $row["blockhash"];
 $output["rows"][$ri]["height"] = $row["height"];
 $output["rows"][$ri]["duration"] = $row["duration"];
 $output["rows"][$ri]["age"] = $row["age"];
 $output["rows"][$ri]["roundstart"] = $row["start_unix"];
 $output["rows"][$ri]["roundend"] = $row["time_unix"];
 $output["rows"][$ri]["hashrate"] = sprintf("%u", $hashrate);
 $output["rows"][$ri]["percent_of_network"] = 100 * ($hashrate / ($row["network_difficulty"] * 7158278.82667));
 $output["rows"][$ri]["accepted_shares"] = sprintf("%u", $row["acceptedshares"]);
 $output["rows"][$ri]["network_difficulty"] = sprintf("%.4f", $row["network_difficulty"]);
Exemplo n.º 5
0
function block_table_row($row, $isodd)
{
    $blocks_row = "";
    if (isset($row["acceptedshares"])) {
        $luck = 100 * ($row["network_difficulty"] / $row["acceptedshares"]);
    } else {
        $luck = 0;
    }
    if ($luck > 9000) {
        $luck = "<A STYLE=\"color:#3B4033;font-weight:normal;text-decoration:none;cursor:default\" HREF=\"9000.php\">&gt;9,000%</A>";
    } else {
        $luck = number_format(round($luck, 1), 1) . "%";
    }
    $roundstart = substr($row["roundstart"], 0, 19);
    if ($row["confirmations"] >= 120) {
        $confs = "Confirmed";
    } else {
        if ($row["confirmations"] == 0) {
            $confs = "Stale";
            $luck = "n/a";
            $roundstart = "<SMALL>(" . substr($row["time"], 0, 19);
            $roundstart .= ")</SMALL>";
        } else {
            $confs = $row["confirmations"] . " of 120";
        }
    }
    $dbid = $row["blockid"];
    if ($row["confirmations"] == 0) {
        $blocks_row .= "<TR id=\"blockrow{$dbid}\" BGCOLOR=\"#FFDFDF\" class=\"{$isodd}" . "blockorphan\">";
    } else {
        if ($row["confirmations"] >= 120) {
            $blocks_row .= "<TR id=\"blockrow{$dbid}\" class=\"{$isodd}" . "blockconfirmed\">";
        } else {
            $rowcolour = $isodd ? array(0xd3, 0xeb, 0xe3) : array(0xeb, 0xed, 0xe9);
            $uccolour = array(0xff, 0x7f, 0);
            $rowcolour = blend_colours($uccolour, $rowcolour, $row["confirmations"] / 120);
            $blocks_row .= "<TR class=\"{$isodd}" . "blockunconfirmed\" id=\"blockrow{$dbid}\" style=\"background-color: " . csscolour($rowcolour) . "\">";
        }
    }
    $blocks_row .= "<TD sorttable_customkey=\"" . $row["age"] . "\" style=\"font-size: 0.9em;\">" . prettyDuration($row["age"], false, 1) . "</TD>";
    $blocks_row .= "<TD style=\"font-size: 0.8em;\">" . $roundstart . "</TD>";
    if (isset($row["duration"])) {
        list($seconds, $minutes, $hours) = extractTime($row["duration"]);
        $seconds = sprintf("%02d", $seconds);
        $minutes = sprintf("%02d", $minutes);
        $hours = sprintf("%02d", $hours);
        $blocks_row .= "<td sorttable_customkey=\"" . $row["duration"] . "\" style=\"width: 1.5em;  text-align: right;\">{$hours}:{$minutes}:{$seconds}</td>";
        $hashrate = $row["acceptedshares"] * 4294967296 / $row["duration"];
        $hashratenum = $hashrate;
        $hashrate = prettyHashrate($hashrate);
        $hashrate = substr($hashrate, 0, -2);
        $percentofnetwork = $hashratenum / ($row["network_difficulty"] * 7158278.82667);
        $percentofnetwork = sprintf("%.2f%% of network", $percentofnetwork * 100);
        $hashrate = "<span title=\"{$percentofnetwork}\">{$hashrate}</span>";
    } else {
        $blocks_row .= "<td style=\"text-align: right;\">n/a</td>";
        $hashrate = "n/a";
    }
    $blocks_row .= "<TD style=\"text-align: right;\" sorttable_customkey=\"" . $row["acceptedshares"] . "\">" . ($row["acceptedshares"] > 0 ? number_format($row["acceptedshares"]) : "n/a") . "</TD>";
    $blocks_row .= "<TD style=\"text-align: right;\" sorttable_customkey=\"" . $row["network_difficulty"] . "\">" . formatSI($row["network_difficulty"], 2) . "</TD>";
    $blocks_row .= "<TD style=\"text-align: right;\">" . $luck . "</TD>";
    $hashratenum = sprintf("%.0f", $hashratenum);
    $blocks_row .= "<TD style=\"text-align: right; font-size: 0.9em;\" sorttable_customkey=\"" . $hashratenum . "\" >" . $hashrate . "</TD>";
    $blocks_row .= "<TD class=\"blockconfirms\" style=\"text-align: right;\">" . $confs . "</TD>";
    if (isset($row['keyhash'])) {
        $fulladdress = \Bitcoin::hash160ToAddress(bits2hex($row['keyhash']));
        $address = substr($fulladdress, 0, 10) . "...";
    } else {
        $fulladdress = "";
        $address = "(Unknown user)";
    }
    $blocks_row .= "<TD style=\"font-family:monospace;\"><A HREF=\"userstats.php/" . $fulladdress . "\">" . $address . "</A></TD>";
    if (isset($row["height"]) && $row["height"] > 0) {
        $ht = number_format($row["height"]);
    } else {
        $ht = "n/a";
    }
    $blocks_row .= "<TD style=\"text-align: right;\">{$ht}</TD>";
    $nicehash = "..." . substr($row["blockhash"], 46, 18);
    $blocks_row .= "<TD style=\"font-family:monospace;\"><A HREF=\"blockinfo.php/" . $row["blockhash"] . "\">" . $nicehash . "</A></TD>";
    $blocks_row .= "</TR>";
    return $blocks_row;
}