/** * Process Bitcoin checkout. * * @param string $separator * @param integer $sessionid * @todo Document better */ function gateway_bitcoin($separator, $sessionid) { global $wpdb, $wpsc_cart; include_once "library/bitcoin.inc"; $bitcoin_client = new BitcoinClient(get_option("bitcoin_scheme"), get_option("bitcoin_username"), get_option("bitcoin_password"), get_option("bitcoin_address"), get_option("bitcoin_port"), get_option("bitcoin_certificate_path")); if (TRUE !== ($fault = $bitcoin_client->can_connect())) { bitcoin_checkout_fail($session, 'The Bitcoin server is presently unavailable. Please contact the site administrator.', $fault); return; } $row = $wpdb->get_row("SELECT id,totalprice FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE sessionid=" . $sessionid); $label = $row->id . " " . $row->totalprice; try { $address = $bitcoin_client->query("getnewaddress", $label); } catch (BitcoinClientException $e) { bitcoin_checkout_fail($session, 'The Bitcoin server is presently unavailable. Please contact the site administrator.', $e->getMessage()); return; } if (!Bitcoin::checkAddress($address)) { bitcoin_checkout_fail($session, 'The Bitcoin server returned an invalid address. Please contact the site administrator.', $e->getMessage()); return; } //var_dump($_SESSION); unset($_SESSION['WpscGatewayErrorMessage']); // Set the transaction to pending payment and log the Bitcoin address as its transaction ID $wpdb->query("UPDATE " . WPSC_TABLE_PURCHASE_LOGS . " SET processed='1', transactid='" . $address . "' WHERE sessionid=" . $sessionid); $_SESSION['bitcoin'] = 'success'; $_SESSION['bitcoin_address_display'] = $address; $_SESSION['bitcoin_address_mail'] = $address; header("Location: " . get_option('transact_url') . $separator . "sessionid=" . $sessionid); exit; }
public $txid; public $time; public function __construct($address, $category, $amount, $fee, $confirmations, $txid, $time) { $this->address = $address; $this->category = $category; $this->amount = $amount; $this->fee = $fee; $this->confirmations = $confirmations; $this->txid = $txid; $this->time = $time; } } $accounts = array(); $bitcoinController = new BitcoinClient($rpcType, $rpcUsername, $rpcPassword, $rpcHost); $bitAccounts = $bitcoinController->query("listaccounts"); foreach ($bitAccounts as $name => $balance) { $account = new BAccount($name, $balance); $accounts[] = $account; $bitTransactions = $bitcoinController->query("listtransactions", $name, 10000); foreach ($bitTransactions as $bitT) { $account->txns[] = new BTxn(@$bitT['address'], $bitT['category'], $bitT['amount'], @$bitT['fee'], $bitT['confirmations'], $bitT['txid'], $bitT['time']); } usort($account->txns, function ($a, $b) { return $b->time - $a->time; }); } ?> <html> <head> <title>Wallet</title>
<div id="logo"> <table width="100%" cellspacing="0" cellpadding="0" border="0"> <tr> <td rowspan="2"><img src="images/logo.png"></td> <td align="right" valign="bottom" id="currentRates"> <? echo "<table class=\"hashrate\">"; $result = apc_fetch("serverstats:common"); if ($result !== FALSE) { echo $result; } else { $output = ''; $ourHashrate = $settings->getsetting('currenthashrate'); $output .= "<tr><td>Current Hashrate</td><td>".number_format($ourHashrate/1000,3)." MH/s</td></tr>"; $bitcoinController = new BitcoinClient($rpcType, $rpcUsername, $rpcPassword, $rpcHost); $networkHashrate = (intval($bitcoinController->query('getnetworkhashps'))/1000); $output .= "<tr><td>Network Hashrate</td><td>".number_format($networkHashrate/1000, 3)." MH/s </td></tr>"; $output .= "<tr><td>Info</td><td>We are ".number_format($ourHashrate/$networkHashrate*100, 2)."%</td></tr>"; $output .= "<tr><td>Current Workers</td><td>".$settings->getsetting('currentworkers')."</td></tr>"; echo $output; apc_store("serverstats:common", $output, 20); } ?> </table> </tr> </table> </div> </div> <?php include "menu.php";
} ELSE { echo "Idle Workers is running<br/>"; } ?> <br/> <h3>Info</h3> <hr size="1" width="80%"></hr> <? $sitewallet = mysql_query("SELECT sum(balance) FROM `accountBalance` WHERE `balance` > 0") or sqlerr(__FILE__, __LINE__); $sitewalletq = mysql_fetch_row($sitewallet); $usersbalance = $sitewalletq[0]; $balance = $bitcoinController->query("getbalance"); $total = $balance - $usersbalance; echo "Block Number: ".$bitcoinController->getblocknumber()."<br>"; echo "Difficulty: ".$bitcoinController->query("getdifficulty")."<br>"; echo "Wallet Balance: ".$balance."<br>"; echo "UnPaid: ".$usersbalance."<br>"; echo "Total Left: <font color=red>$total</font><br>"; echo "<a href=/wallet.php>Everything Wallet</a><br/>"; ?> <br><h3>News Control</h3> <hr size="1" width="80%"></hr> <? $getnews = mysql_query("SELECT id, `timestamp`, `title`, `message` FROM `news` ORDER BY `timestamp` DESC LIMIT 3") or sqlerr(__FILE__, __LINE__);
$useridq = mysql_query("SELECT id FROM webUsers WHERE api_key = '" . $apikey . "'") or sqlerr(__FILE__, __LINE__); $userida = mysql_fetch_object($useridq); $id = $userida->id; $user = new User(); /* $estq = mysql_query("SELECT estimate FROM roundDetails WHERE userId = '$id' ORDER BY estimate DESC"); $esta = mysql_fetch_object($estq); if($esta->estimate == NULL) { $user->last_paid = '0'; } ELSE { $user->last_paid = $esta->estimate;} */ $blockq = mysql_query("SELECT blockNumber FROM networkBlocks WHERE confirms > '0' ORDER BY blockNumber DESC"); $blocka = mysql_fetch_object($blockq); $user->last_block = $blocka->blockNumber; $bitcoinController = new BitcoinClient($rpcType, $rpcUsername, $rpcPassword, $rpcHost); $user->current_block = $bitcoinController->query("getblocknumber"); $resultU = mysql_query("SELECT u.id, u.hashrate, u.round_estimate, shares_this_round, b.balance, b.paid from webUsers u, accountBalance b WHERE u.id = b.userId AND u.api_key='" . $apikey . "'"); if ($userobj = mysql_fetch_object($resultU)) { $userid = $userobj->id; $user->current_balance = $userobj->balance; $user->hashrate = $userobj->hashrate; $user->payout_history = $userobj->paid; $user->round_estimate = $userobj->round_estimate; $user->shares_this_round = $userobj->shares_this_round; } if (isset($_GET["api_key"])) { $userQ = mysql_query("SELECT id FROM webUsers WHERE api_key = '" . $apikey . "'"); $userA = mysql_fetch_object($userQ); $userId1 = $userA->id; $resultW = mysql_query("SELECT username, hashrate, active, hashes FROM pool_worker WHERE associatedUserId={$userId1}"); while ($workerobj = mysql_fetch_object($resultW)) {
// along with this program. If not, see <http://www.gnu.org/licenses/>. // BTC Donations: 163Pv9cUDJTNUbadV4HMRQSSj3ipwLURRc error_reporting(E_ALL); ini_set('display_errors', '1'); $includeDirectory = "/var/www/includes/"; include $includeDirectory . "requiredFunctions.php"; //Verify source of cron job request if (isset($cronRemoteIP) && $_SERVER['REMOTE_ADDR'] !== $cronRemoteIP) { die(header("Location: /")); } lock("workers.php"); mysql_query("BEGIN"); /////////Update workers $bitcoinController = new BitcoinClient($rpcType, $rpcUsername, $rpcPassword, $rpcHost); //Get difficulty $difficulty = $bitcoinController->query("getdifficulty"); //Get site percentage $sitePercent = 0; $sitePercentQ = mysql_query("SELECT value FROM settings WHERE setting='sitepercent'"); if ($sitePercentR = mysql_fetch_object($sitePercentQ)) { $sitePercent = $sitePercentR->value; } //Setup score variables $c = 0.001; $f = 1; if ($sitePercent > 0) { $f = $sitePercent / 100; } else { $f = -$c / (1 - $c); } $p = 1.0 / $difficulty;
/** * Process the payment * @param string $order_number * @param float $order_total * @param array $d * @return boolean true if bitcoin */ function process_payment($order_number, $order_total, &$d) { include_once CLASSPATH . "payment/ps_bitcoin.cfg.php"; // TODO: handle conversions via to-be-written converter script // it's also available as global $vendor_currency //"currency_code" => $_SESSION['vendor_currency'], global $vmLogger; $bitcoin_client = new BitcoinClient(BITCOIN_SCHEME, BITCOIN_USERNAME, BITCOIN_PASSWORD, BITCOIN_HOST, BITCOIN_PORT, BITCOIN_CERTIFICATE); if (TRUE !== ($fault = $bitcoin_client->can_connect())) { $vmLogger->err("The Bitcoin server is presently unavailable. Please contact the site administrator."); return false; } // stuff the (long) order number, the total order price and a timestamp into the bitcoin address's label $label = $order_number . " " . number_format($order_total, 2, ".", "") . " " . time(); try { $address = $bitcoin_client->query("getnewaddress", $label); } catch (BitcoinClientException $e) { $vmLogger->err("The Bitcoin server was unable to generate an address for your payment. Please contact the site administrator."); return false; } if (!Bitcoin::checkAddress($address)) { $vmLogger->err("The Bitcoin server returned an invalid address. Please contact the site administrator."); return false; } // stuff the payment address into the session so the "extra info" code can access it // TODO: There's gotta be a better way... $_SESSION["bitcoin_address"] = $address; $d['include_comment'] = "Y"; $d['order_comment'] = "Please send your payment to Bitcoin address " . $address; return true; }
} require_once CLASSPATH . 'ps_order.php'; require_once CLASSPATH . "payment/ps_bitcoin.php"; // prepare the JSON-RPC client $bitcoin_client = new BitcoinClient(BITCOIN_SCHEME, BITCOIN_USERNAME, BITCOIN_PASSWORD, BITCOIN_HOST, BITCOIN_PORT, BITCOIN_CERTIFICATE); if (TRUE !== ($fault = $bitcoin_client->can_connect())) { $vmLogger->err("Bitcoin cronjob: Unable to connect to Bitcoin server, fault: " . $fault); die("Bitcoin cronjob: Unable to connect to Bitcoin server, fault: " . $fault); } //$bitcoin_client->setDebug(2); // loop through the open transactions do { // check for transaction completion $address = $db->f("order_payment_name"); try { $paid = $bitcoin_client->query("getreceivedbyaddress", $address, intval(BITCOIN_CONFIRMS)); } catch (BitcoinClientException $e) { $vmLogger->err("Bitcoin server communication failed on getreceivedbyaddress " . $address . " with fault string " . $e->getMessage()); continue; } $ps_order = new ps_order(); $order_id = $db->f("order_id"); $d['order_id'] = $order_id; // TODO: Handle overpayment if ($paid >= $db->f("order_total")) { // PAID IN FULL // TODO: If the product was a downloadable, mark the order as SHIPPED $d['order_status'] = BITCOIN_VERIFIED_STATUS; $d['notify_customer'] = "Y"; $ps_order->order_status_update($d); continue;