diff --git a/README b/README
index 4d15448..02c8ec8 100644
--- a/README
+++ b/README
@@ -1,3 +1,7 @@
+*warning* personal fork of simplecoin, work in progress, no guarantees it will work for you, just trying to fix php warnings for empty sets, short open tags . . . and make it more secure for my own use
+
+---
+
Simplecoin Web Mining Framework
Requirements:
@@ -22,3 +26,8 @@ Tom Lightspeed : tomlightspeed@gmail.com : 16p56JHwLna29dFhTRcTAurj4Zc2eScxTD
Please remember to include credit from previous authors in all forks and derivative works.
Thanks!
+
+[](http://coderwall.com/neofutur)
+
+"!http://api.coderwall.com/neofutur/endorsecount.png!":http://coderwall.com/neofutur
+
diff --git a/about.php b/about.php
index d370cbc..c759805 100644
--- a/about.php
+++ b/about.php
@@ -1,35 +1,35 @@
-
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see .
-
-// BTC Donations: 163Pv9cUDJTNUbadV4HMRQSSj3ipwLURRc
-
-$pageTitle = "- About";
-include ("includes/header.php");
-?>
-
-About Bitcoins
-
-About This Site
-This site is run by completely opensource software.
-Hosted on a Xen Virtual Machine
-Running Ubuntu
-PHP pages served by Apache webserver
-Official Bitcoin server
-Pushpool Bitcoin pool
-Simplecoin front-end
-
-
-
+
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+// BTC Donations: 163Pv9cUDJTNUbadV4HMRQSSj3ipwLURRc
+
+$pageTitle = "- About";
+include ("includes/header.php");
+?>
+
+About Bitcoins
+
+About This Site
+This site is run by completely opensource software.
+Hosted on a Xen Virtual Machine
+Running Ubuntu
+PHP pages served by Apache webserver
+Official Bitcoin server
+Pushpool Bitcoin pool
+Simplecoin front-end
+
+
+
diff --git a/accountdetails.php b/accountdetails.php
index c3dd1a0..e24168d 100644
--- a/accountdetails.php
+++ b/accountdetails.php
@@ -87,7 +87,7 @@
mysql_query("UPDATE accountBalance SET balance = '0', paid = '$paid' WHERE userId = $userId");
if ($bitcoinController->sendtoaddress($paymentAddress, $currentBalance)) {
$goodMessage = "You have successfully sent ".$currentBalance." to the following address:".$paymentAddress;
- mail("$userEmail", "Simplecoin Manual Payout Notification", "Hello,\n\nYour requested manual payout of ". $currentBalance." BTC has been sent to your payment address ".$paymentAddress.".", "From: Simplecoin Notifications ");
+ mail("$userEmail", $poolname. "Manual Payout Notification", "Hello,\n\nYour requested manual payout of ". $currentBalance." BTC has been sent to your payment address : ".$paymentAddress.".", "From: ".$poolname. " Notifications <".$mailfrom.">");
//Set new variables so it appears on the page flawlessly
$currentBalance = 0;
mysql_query("COMMIT");
@@ -248,7 +248,7 @@
Permanently lock Bitcoin address to this account
Donation %:
Automatic Payout: (1-25 BTC, 0 for manual)
-
Authorize Pin:
+
Authorize Pin:
@@ -260,7 +260,7 @@
Account Balance:
Payout to:
-
Authorize Pin:
+
Authorize Pin:
@@ -269,9 +269,9 @@
Change Password
diff --git a/adminPanel.php b/adminPanel.php
index 998eda0..356b36d 100644
--- a/adminPanel.php
+++ b/adminPanel.php
@@ -1,98 +1,99 @@
-
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see .
-
-// BTC Donations: 163Pv9cUDJTNUbadV4HMRQSSj3ipwLURRc
-
+
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+// BTC Donations: 163Pv9cUDJTNUbadV4HMRQSSj3ipwLURRc
+
$pageTitle = "- Admin Panel";
-include ("includes/header.php");
+include ("includes/header.php");
+include ("includes/settings.php");
-$goodMessage = "";
-$returnError = "";
-//Scince this is the Admin panel we'll make sure the user is logged in and "isAdmin" enabled boolean; If this is not a logged in user that is enabled as admin, redirect to a 404 error page
-
-if(!$cookieValid || $isAdmin != 1) {
- header('Location: /');
- exit;
-}
-
+$goodMessage = "";
+$returnError = "";
+//Scince this is the Admin panel we'll make sure the user is logged in and "isAdmin" enabled boolean; If this is not a logged in user that is enabled as admin, redirect to a 404 error page
+
+if(!$cookieValid || $isAdmin != 1) {
+ header('Location: /');
+ exit;
+}
+$settings= new Settings;
if (isset($_POST["act"]) && isset($_POST["authPin"]))
-{
+{
if (isset($_POST["authPin"])) {
$inputAuthPin = hash("sha256", $_POST["authPin"].$salt);
} else {
$inputAuthPin = NULL;
}
-
- //Make sure an authPin is set and valid when $act is active
+
+ //Make sure an authPin is set and valid when $act is active
if(isset($_POST["act"]) && $authPin == $inputAuthPin) {
$act = $_POST["act"];
- //Update information if needed
- if($act == "UpdateMainPageSettings"){
- try {
- $settings->setsetting("sitepayoutaddress", mysql_real_escape_string($_POST["paymentAddress"]));
- $settings->setsetting("sitepercent", mysql_real_escape_string($_POST["percentageFee"]));
- $settings->setsetting("websitename", mysql_real_escape_string($_POST["headerTitle"]));
- $settings->setsetting("pagetitle", mysql_real_escape_string($_POST["pageTitle"]));
- $settings->setsetting("slogan", mysql_real_escape_string($_POST["headerSlogan"]));
- $settings->setsetting("siterewardtype", mysql_real_escape_string($_POST["rewardType"]));
+ //Update information if needed
+ if($act == "UpdateMainPageSettings"){
+ try {
+ $settings->setsetting("sitepayoutaddress", mysql_real_escape_string($_POST["paymentAddress"]));
+ $settings->setsetting("sitepercent", mysql_real_escape_string($_POST["percentageFee"]));
+ $settings->setsetting("websitename", mysql_real_escape_string($_POST["headerTitle"]));
+ $settings->setsetting("pagetitle", mysql_real_escape_string($_POST["pageTitle"]));
+ $settings->setsetting("slogan", mysql_real_escape_string($_POST["headerSlogan"]));
+ $settings->setsetting("siterewardtype", mysql_real_escape_string($_POST["rewardType"]));
$settings->setsetting("sitetxfee", mysql_real_escape_string($_POST["transactionFee"]));
- $settings->loadsettings(); //refresh settings
- $goodMessage = "Successfully updated general settings";
- } catch (Exception $e) {
- $returnError = "Database Failed - General settings was not updated";
- }
- }
- } else if($act && $authPin != $inputAuthPin){
- $returnError = "Authorization Pin # - Invalid";
- }
-}
-
-//Display Error and Good Messages(If Any)
-echo "".antiXss($goodMessage)." ";
-echo "".antiXss($returnError)."";
-
-?>
-
-
-
\ No newline at end of file
+
diff --git a/api.php b/api.php
index f1185f4..69702f7 100644
--- a/api.php
+++ b/api.php
@@ -1,90 +1,88 @@
-
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see .
-
-// BTC Donations: 163Pv9cUDJTNUbadV4HMRQSSj3ipwLURRc
-
-if (!isset($_GET["api_key"]))
- exit;
-
-$includeDirectory = "/var/www/includes/";
-
-include($includeDirectory."requiredFunctions.php");
-include($includeDirectory."stats.php");
-$stats = new Stats();
-
-class User {
- var $confirmed_rewards = null;
- var $hashrate = null;
- var $payout_history = null;
- var $estimated_rewards = null;
- var $workers = array();
-}
-
-class Worker {
- var $alive = null;
- var $hashrate = null;
-}
-
-$apikey = mysql_real_escape_string($_GET["api_key"]);
-
-$user = new User();
-$userid = 0;
-$resultU = mysql_query_cache("SELECT u.id, b.balance, b.paid, u.username from webUsers u, accountBalance b WHERE u.id = b.userId AND u.api_key = '$apikey'", 300);
-if (count($resultU) > 0) {
- $userobj = $resultU[0];
- $username = $userobj->username;
- $userid = $userobj->id;
- $user->confirmed_rewards = $userobj->balance;
- $user->hashrate = $stats->userhashrate($username);
- $user->estimated_rewards = 0;
- $user->payout_history = $userobj->paid;
-
- if (is_numeric($settings->getsetting("sitepercent")))
- $sitePercent = $settings->getsetting("sitepercent");
-
- $totalUserShares = $stats->usersharecount($userid);
-
- //Get current round share information, estimated total earnings
- $totalOverallShares = $stats->currentshares();
-
- //Prevent divide by zero
- if($totalUserShares > 0 && $totalOverallShares > 0){
- //Get site percentage
- $sitePercent = 0;
- if (is_numeric($settings->getsetting('sitepercent')))
- $sitePercent = $settings->getsetting('sitepercent')/100;
-
- if ($totalOverallShares > $bitcoinDifficulty)
- $estimatedTotalEarnings = $totalUserShares/$totalOverallShares;
- else
- $estimatedTotalEarnings = $totalUserShares/$bitcoinDifficulty;
-
- $estimatedTotalEarnings *= $bonusCoins*(1-$sitePercent); //The expected BTC to be givin out
- $user->estimated_rewards = round($estimatedTotalEarnings, 8);
- }
-
-}
-$resultW = mysql_query_cache("SELECT username FROM pool_worker WHERE associatedUserId = $userid", 300);
-foreach ($resultW as $workerobj) {
- $worker = new Worker();
- $worker->alive = ($stats->workerhashrate($workerobj->username) > 0);
- $worker->hashrate = $stats->workerhashrate($workerobj->username);
- $user->workers[$workerobj->username] = $worker;
-}
-
-echo json_encode($user);
-
-?>
\ No newline at end of file
+
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+// BTC Donations: 163Pv9cUDJTNUbadV4HMRQSSj3ipwLURRc
+
+if (!isset($_GET["api_key"]))
+ exit;
+
+include(dirname(__FILE__) . "/include/requiredFunctions.php");
+include($includedir."stats.php");
+$stats = new Stats();
+
+class User {
+ var $confirmed_rewards = null;
+ var $hashrate = null;
+ var $payout_history = null;
+ var $estimated_rewards = null;
+ var $workers = array();
+}
+
+class Worker {
+ var $alive = null;
+ var $hashrate = null;
+}
+
+$apikey = mysql_real_escape_string($_GET["api_key"]);
+
+$user = new User();
+$userid = 0;
+$resultU = mysql_query_cache("SELECT u.id, b.balance, b.paid, u.username from webUsers u, accountBalance b WHERE u.id = b.userId AND u.api_key = '$apikey'", 300);
+if (count($resultU) > 0) {
+ $userobj = $resultU[0];
+ $username = $userobj->username;
+ $userid = $userobj->id;
+ $user->confirmed_rewards = $userobj->balance;
+ $user->hashrate = $stats->userhashrate($username);
+ $user->estimated_rewards = 0;
+ $user->payout_history = $userobj->paid;
+
+ if (is_numeric($settings->getsetting("sitepercent")))
+ $sitePercent = $settings->getsetting("sitepercent");
+
+ $totalUserShares = $stats->usersharecount($userid);
+
+ //Get current round share information, estimated total earnings
+ $totalOverallShares = $stats->currentshares();
+
+ //Prevent divide by zero
+ if($totalUserShares > 0 && $totalOverallShares > 0){
+ //Get site percentage
+ $sitePercent = 0;
+ if (is_numeric($settings->getsetting('sitepercent')))
+ $sitePercent = $settings->getsetting('sitepercent')/100;
+
+ if ($totalOverallShares > $bitcoinDifficulty)
+ $estimatedTotalEarnings = $totalUserShares/$totalOverallShares;
+ else
+ $estimatedTotalEarnings = $totalUserShares/$bitcoinDifficulty;
+
+ $estimatedTotalEarnings *= $bonusCoins*(1-$sitePercent); //The expected BTC to be givin out
+ $user->estimated_rewards = round($estimatedTotalEarnings, 8);
+ }
+
+}
+$resultW = mysql_query_cache("SELECT username FROM pool_worker WHERE associatedUserId = $userid", 300);
+foreach ($resultW as $workerobj) {
+ $worker = new Worker();
+ $worker->alive = ($stats->workerhashrate($workerobj->username) > 0);
+ $worker->hashrate = $stats->workerhashrate($workerobj->username);
+ $user->workers[$workerobj->username] = $worker;
+}
+
+echo json_encode($user);
+
+?>
diff --git a/chat.php b/chat.php
index 0ab50a2..c9fd185 100644
--- a/chat.php
+++ b/chat.php
@@ -2,4 +2,4 @@
$pageTitle = "- IRC Webchat";
include ("includes/header.php");
?>
-
\ No newline at end of file
+
diff --git a/cronjobs/archive.php b/cronjobs/archive.php
index f078e3f..ee518c8 100644
--- a/cronjobs/archive.php
+++ b/cronjobs/archive.php
@@ -1,38 +1,36 @@
-
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see .
-
-// BTC Donations: 163Pv9cUDJTNUbadV4HMRQSSj3ipwLURRc
-
-//Set page starter variables//
-$includeDirectory = "/var/www/includes/";
-
-//Include hashing functions
-include($includeDirectory."requiredFunctions.php");
-
-//Check that script is run locally
-ScriptIsRunLocally();
-
-//Include Block class
-include($includeDirectory."block.php");
-$block = new Block();
-
-$siterewardtype = $settings->getsetting("siterewardtype");
-
-if ($block->NeedsArchiving($siterewardtype, $bitcoinDifficulty))
- $block->Archive($siterewardtype, $bitcoinDifficulty);
-
-?>
\ No newline at end of file
+
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+// BTC Donations: 163Pv9cUDJTNUbadV4HMRQSSj3ipwLURRc
+
+//Set page starter variables//
+//Include hashing functions
+include(dirname(__FILE__) . "/../includes/requiredFunctions.php");
+
+//Check that script is run locally
+ScriptIsRunLocally();
+
+//Include Block class
+include($includedir."block.php");
+$block = new Block();
+
+$siterewardtype = $settings->getsetting("siterewardtype");
+
+if ($block->NeedsArchiving($siterewardtype, $bitcoinDifficulty))
+ $block->Archive($siterewardtype, $bitcoinDifficulty);
+
+?>
diff --git a/cronjobs/backupwallet.php b/cronjobs/backupwallet.php
index 788ba58..be049b1 100644
--- a/cronjobs/backupwallet.php
+++ b/cronjobs/backupwallet.php
@@ -1,12 +1,9 @@
backupwallet("/home/simplecoin/walletbackup/wallet.dat.".date("Ymd"));
-?>
\ No newline at end of file
+$bitcoinController->backupwallet($backupwalletfilename . ".".date("Ymd"));
+?>
diff --git a/cronjobs/cronjob.php b/cronjobs/cronjob.php
index 68662fd..d43a356 100644
--- a/cronjobs/cronjob.php
+++ b/cronjobs/cronjob.php
@@ -18,13 +18,10 @@
//Set page starter variables//
-$includeDirectory = "/var/www/includes/";
-
-//Include site functions
-include($includeDirectory."requiredFunctions.php");
+include(dirname(__FILE__) . "/../includes/requiredFunctions.php");
//Include Reward class
-include($includeDirectory.'reward.php');
+include($includedir.'reward.php');
$reward = new Reward();
//Check that script is run locally
@@ -33,7 +30,7 @@
lock("shares");
//Include Block class
- include($includeDirectory."block.php");
+ include($includedir."block.php");
$block = new Block();
//Get current block number
@@ -46,7 +43,7 @@
//Do block work if new block
if ($latestDbBlock < $lastBlockNumber) {
//Insert last block number into networkBlocks
- include($includeDirectory."stats.php");
+ include($includedir."stats.php");
$stats = new Stats();
$lastwinningid = $stats->lastWinningShareId();
$block->InsertNetworkBlocks($lastBlockNumber, $lastwinningid);
@@ -101,4 +98,4 @@
}
-?>
\ No newline at end of file
+?>
diff --git a/cronjobs/hashrate.php b/cronjobs/hashrate.php
index c83b9ff..76d7c1e 100644
--- a/cronjobs/hashrate.php
+++ b/cronjobs/hashrate.php
@@ -1,59 +1,57 @@
-.
-
-// BTC Donations: 163Pv9cUDJTNUbadV4HMRQSSj3ipwLURRc
-
-$includeDirectory = "/var/www/includes/";
-
-include($includeDirectory."requiredFunctions.php");
-include($includeDirectory."stats.php");
-$stats = new Stats();
-
-//Check that script is run locally
-ScriptIsRunLocally();
-
-//Remove cached items (in case they get stuck)
-removeCache("worker_hashrates");
-removeCache("pool_hashrate");
-removeCache("user_hashrates");
-
-//Hashrate by user
-$hashrates = $stats->userhashratesbyid();
-mysql_query("BEGIN");
-$i = 0;
-$sql = "";
-foreach ($hashrates as $userid => $hashrate) {
- if ($i == 0)
- $sql = "INSERT INTO userHashrates (userId, hashrate) VALUES ";
- else
- $sql .= ",";
- $i++;
- $sql .= "($userid, $hashrate)";
- if ($i > 20)
- {
- mysql_query($sql);
- $sql = "";
- $i = 0;
- }
-}
-if (strlen($sql) > 0)
- mysql_query($sql);
-mysql_query("COMMIT");
-
-$currentTime = time();
+.
+
+// BTC Donations: 163Pv9cUDJTNUbadV4HMRQSSj3ipwLURRc
+
+include(dirname(__FILE__) . "/../includes/requiredFunctions.php");
+include($includedir."stats.php");
+$stats = new Stats();
+
+//Check that script is run locally
+ScriptIsRunLocally();
+
+//Remove cached items (in case they get stuck)
+removeCache("worker_hashrates");
+removeCache("pool_hashrate");
+removeCache("user_hashrates");
+
+//Hashrate by user
+$hashrates = $stats->userhashratesbyid();
+mysql_query("BEGIN");
+$i = 0;
+$sql = "";
+foreach ($hashrates as $userid => $hashrate) {
+ if ($i == 0)
+ $sql = "INSERT INTO userHashrates (userId, hashrate) VALUES ";
+ else
+ $sql .= ",";
+ $i++;
+ $sql .= "($userid, $hashrate)";
+ if ($i > 20)
+ {
+ mysql_query($sql);
+ $sql = "";
+ $i = 0;
+ }
+}
+if (strlen($sql) > 0)
+ mysql_query($sql);
+mysql_query("COMMIT");
+
+$currentTime = time();
$settings->setsetting("statstime", $currentTime);
-
-?>
\ No newline at end of file
+
+?>
diff --git a/cronjobs/loadavg b/cronjobs/loadavg
new file mode 100644
index 0000000..b9b739e
--- /dev/null
+++ b/cronjobs/loadavg
@@ -0,0 +1 @@
+*/10 * * * * cat /proc/loadavg > /path/to/your/pool/html/loadavg.html
diff --git a/cronjobs/payout.php b/cronjobs/payout.php
index d485496..fe4dc9a 100644
--- a/cronjobs/payout.php
+++ b/cronjobs/payout.php
@@ -1,75 +1,73 @@
-
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see .
-
-// BTC Donations: 163Pv9cUDJTNUbadV4HMRQSSj3ipwLURRc
-
-
-$includeDirectory = "/var/www/includes/";
-
-include($includeDirectory."requiredFunctions.php");
-
-//Check that script is run locally
-ScriptIsRunLocally();
-
-$txfee = 0;
-if ($settings->getsetting("sitetxfee") > 0)
- $txfee = $settings->getsetting("sitetxfee");
-
-$sitepercent = $settings->getsetting("sitepercent");
+
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+// BTC Donations: 163Pv9cUDJTNUbadV4HMRQSSj3ipwLURRc
+
+
+include(dirname(__FILE__) . "/../includes/requiredFunctions.php");
+
+//Check that script is run locally
+ScriptIsRunLocally();
+
+$txfee = 0;
+if ($settings->getsetting("sitetxfee") > 0)
+ $txfee = $settings->getsetting("sitetxfee");
+
+$sitepercent = $settings->getsetting("sitepercent");
/////////Pay users who have reached their threshold payout
-
-$resultQ = mysql_query("SELECT b.userId, b.balance, IFNULL(b.paid, 0) as paid, IFNULL(b.sendAddress,'') as sendAddress, u.email, u.donate_percent FROM accountBalance b, webUsers u WHERE b.userId = u.id AND b.threshold >= 1 AND b.balance >= threshold");
-lock("money");
-try {
- while ($resultR = mysql_fetch_object($resultQ)) {
- $currentBalance = $resultR->balance;
- $paid = $resultR->paid;
- $paymentAddress = $resultR->sendAddress;
- $userId = $resultR->userId;
- $donatepercent = $resultR->donate_percent;
- if ($paymentAddress != '')
- {
+
+$resultQ = mysql_query("SELECT b.userId, b.balance, IFNULL(b.paid, 0) as paid, IFNULL(b.sendAddress,'') as sendAddress, u.email, u.donate_percent FROM accountBalance b, webUsers u WHERE b.userId = u.id AND b.threshold >= 1 AND b.balance >= threshold");
+lock("money");
+try {
+ while ($resultR = mysql_fetch_object($resultQ)) {
+ $currentBalance = $resultR->balance;
+ $paid = $resultR->paid;
+ $paymentAddress = $resultR->sendAddress;
+ $userId = $resultR->userId;
+ $donatepercent = $resultR->donate_percent;
+ if ($paymentAddress != '')
+ {
$isValidAddress = $bitcoinController->validateaddress($paymentAddress);
- if($isValidAddress){
- //Subtract TX fee, donation and site fees
- $currentBalance = ($currentBalance*(1-$sitepercent/100)*(1-$donatepercent/100)) - $txfee;
- $paid += $currentBalance;
- //Send money//
- mysql_query("BEGIN");
- try {
- //Reduce balance amount to zero
- //echo "UPDATE accountBalance SET balance = '0', paid = '$paid' WHERE userId = $userId\n";
+ if($isValidAddress){
+ //Subtract TX fee, donation and site fees
+ $currentBalance = ($currentBalance*(1-$sitepercent/100)*(1-$donatepercent/100)) - $txfee;
+ $paid += $currentBalance;
+ //Send money//
+ mysql_query("BEGIN");
+ try {
+ //Reduce balance amount to zero
+ //echo "UPDATE accountBalance SET balance = '0', paid = '$paid' WHERE userId = $userId\n";
mysql_query("UPDATE accountBalance SET balance = '0', paid = '$paid' WHERE userId = $userId");
if($bitcoinController->sendtoaddress($paymentAddress, $currentBalance)) {
mysql_query("INSERT INTO payoutHistory (userId, address, amount) VALUES ('".$resultR->userId."', '".$paymentAddress."', '".$currentBalance."')");
- mail($resultR->email, "Simplecoin.us Automatic Payout Notification", "Hello,\n\nYour balance of ".$currentBalance." BTC has exceeded your automatic payment threshold and has been sent to your payment address ".$paymentAddress.".", "From: Simplecoin.us Notifications ");
- mysql_query("COMMIT");
- } else {
- mysql_query("ROLLBACK");
- echo "Commodity $currentBalance failed to send to $paymentAddress for userid $userId\n";
- }
- } catch (Exception $e) {
- mysql_query("ROLLBACK");
- echo "Commodity $currentBalance failed to send to $paymentAddress for userid $userId\n";
- }
-
- }
- }
- }
-} catch (Exception $ex) {
- echo $ex-getMessage();
-}
-unlock("money");
+ mail($resultR->email, "Simplecoin.us Automatic Payout Notification", "Hello,\n\nYour balance of ".$currentBalance." BTC has exceeded your automatic payment threshold and has been sent to your payment address ".$paymentAddress.".", "From: Simplecoin.us Notifications ");
+ mysql_query("COMMIT");
+ } else {
+ mysql_query("ROLLBACK");
+ echo "Commodity $currentBalance failed to send to $paymentAddress for userid $userId\n";
+ }
+ } catch (Exception $e) {
+ mysql_query("ROLLBACK");
+ echo "Commodity $currentBalance failed to send to $paymentAddress for userid $userId\n";
+ }
+
+ }
+ }
+ }
+} catch (Exception $ex) {
+ echo $ex-getMessage();
+}
+unlock("money");
diff --git a/cronjobs/shares.php b/cronjobs/shares.php
index 29d65ba..d1985bb 100644
--- a/cronjobs/shares.php
+++ b/cronjobs/shares.php
@@ -1,42 +1,40 @@
-
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see .
-
-// BTC Donations: 163Pv9cUDJTNUbadV4HMRQSSj3ipwLURRc
-
-$includeDirectory = "/var/www/includes/";
-
-include($includeDirectory."requiredFunctions.php");
-
-//Check that script is run locally
-ScriptIsRunLocally();
-////Update share counts
-
-//Update past shares
-$sql = "UPDATE webUsers u, ".
- " (SELECT DISTINCT userId, sum(count) AS valid, sum(invalid) AS invalid, id FROM shares_counted GROUP BY userId) s ".
- "SET u.share_count = s.valid, u.stale_share_count = s.invalid WHERE u.id = s.userId";
-mysql_query ($sql);
-
-//
-////Update current round shares
-$sql = "UPDATE webUsers u, ".
- " (SELECT IFNULL(count(s.id),0) AS id, p.associatedUserId FROM pool_worker p ".
- " LEFT JOIN shares s ON p.username=s.username ".
- " WHERE s.our_result='Y' GROUP BY p.associatedUserId) a ".
- "SET shares_this_round = a.id WHERE u.id = a.associatedUserId ";
-mysql_query($sql);
-
-?>
\ No newline at end of file
+
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+// BTC Donations: 163Pv9cUDJTNUbadV4HMRQSSj3ipwLURRc
+
+include(dirname(__FILE__) . "/../includes/requiredFunctions.php");
+
+//Check that script is run locally
+ScriptIsRunLocally();
+////Update share counts
+
+//Update past shares
+$sql = "UPDATE webUsers u, ".
+ " (SELECT DISTINCT userId, sum(count) AS valid, sum(invalid) AS invalid, id FROM shares_counted GROUP BY userId) s ".
+ "SET u.share_count = s.valid, u.stale_share_count = s.invalid WHERE u.id = s.userId";
+mysql_query ($sql);
+
+//
+////Update current round shares
+$sql = "UPDATE webUsers u, ".
+ " (SELECT IFNULL(count(s.id),0) AS id, p.associatedUserId FROM pool_worker p ".
+ " LEFT JOIN shares s ON p.username=s.username ".
+ " WHERE s.our_result='Y' GROUP BY p.associatedUserId) a ".
+ "SET shares_this_round = a.id WHERE u.id = a.associatedUserId ";
+mysql_query($sql);
+
+?>
diff --git a/gettingstarted.php b/gettingstarted.php
index 3192d09..4bfac3e 100644
--- a/gettingstarted.php
+++ b/gettingstarted.php
@@ -1,59 +1,60 @@
-
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see .
-
-// BTC Donations: 163Pv9cUDJTNUbadV4HMRQSSj3ipwLURRc
-
-$pageTitle = "- Getting Started";
-include ("includes/header.php");
-
-?>
-
-Get a Bitcoin Address
-Download the client to your PC from: bitcoin.org
-
-Setup a bitcoin miner
-
-ATI/AMD Users
-You will need to download and install the AMD Stream SDK from HERE before you can begin mining
-
-Advanced Windows & Linux (for best mining results)
- Download cgminer HERE
- Follow the directions for your operating system in the above link to install
- Run cgminer: cgminer -o http://pool.simplecoin.us:8337 -u username.1 -p x
- Run cgminer for max performance: cgminer -o http://pool.simplecoin.us:8337 -u username.1 -p x -I 8
-
- Easy Windows
- Download GUIMiner: HERE
-
- GUIMiner options
- Server: Other
- Host: pool.simplecoin.us
- Port: 8337
- Username: <your user name>.<miner name (default is 1)>
- Password: <your miner password (default is 'x')>
- Device: Select the graphics card/cpu you would like to use
- Extra Flags: Can be blank, but I find "-v -w128 -f 60" to work well
-
- Easy Linux
- Download hashkill: HERE
- Decompress (tar zxvf hashkill-0.2.4-x86.tar.gz)
- Change directory to hashkill
- Run: sudo ./install.sh
- Run hashkill: hashkill-gpu -p bitcoin minername:password:pool.simplecoin.us:8337
-
-
-
-
+
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+// BTC Donations: 163Pv9cUDJTNUbadV4HMRQSSj3ipwLURRc
+
+$pageTitle = "- Getting Started";
+include ("includes/config.php");
+include ("includes/header.php");
+
+?>
+
+Get a Bitcoin Address
+Download the client to your PC from: bitcoin.org
+
+Setup a bitcoin miner
+
+ATI/AMD Users
+You will need to download and install the AMD Stream SDK from HERE before you can begin mining
+
+Advanced Windows & Linux (for best mining results)
+ Download cgminer HERE
+ Follow the directions for your operating system in the above link to install
+ Run cgminer: cgminer -o http://: -u username.1 -p x
+ Run cgminer for max performance: cgminer -o http://: -u username.1 -p x -I 8
+
+ Easy Windows
+ Download GUIMiner: HERE
+
+ GUIMiner options
+ Server: Other
+ Host:
+ Port:
+ Username: <your user name>.<miner name (default is 1)>
+ Password: <your miner password (default is 'x')>
+ Device: Select the graphics card/cpu you would like to use
+ Extra Flags: Can be blank, but I find "-v -w128 -f 60" to work well
+
+ Easy Linux
+ Download hashkill: HERE
+ Decompress (tar zxvf hashkill-0.2.4-x86.tar.gz)
+ Change directory to hashkill
+ Run: sudo ./install.sh
+ Run hashkill: hashkill-gpu -p bitcoin minername:password::
+
+
+
+
diff --git a/images/pool1.jpg b/images/pool1.jpg
new file mode 100755
index 0000000..302b0b1
Binary files /dev/null and b/images/pool1.jpg differ
diff --git a/includes/bitcoinController/bitcoin.inc.php b/includes/bitcoinController/bitcoin.inc.php
index b4aedc8..fa256c6 100644
--- a/includes/bitcoinController/bitcoin.inc.php
+++ b/includes/bitcoinController/bitcoin.inc.php
@@ -1,897 +1,897 @@
- hexdec($addressversion)) {
- return false;
- }
- $check = substr($addr, 0, strlen($addr) - 8);
- $check = pack("H*", $check);
- $check = strtoupper(hash("sha256", hash("sha256", $check, true)));
- $check = substr($check, 0, 8);
- return $check == substr($addr, strlen($addr) - 8);
- }
-
- /**
- * Convert the input to its 160-bit Bitcoin hash
- *
- * @param string $data
- * @return string
- * @access private
- */
- private function hash160($data) {
- $data = pack("H*", $data);
- return strtoupper(hash("ripemd160", hash("sha256", $data, true)));
- }
-
- /**
- * Convert a Bitcoin public key to a 160-bit Bitcoin hash
- *
- * @param string $pubkey
- * @return string
- * @access public
- */
- public static function pubKeyToAddress($pubkey) {
- return self::hash160ToAddress($this->hash160($pubkey));
- }
-
- /**
- * Remove leading "0x" from a hex value if present.
- *
- * @param string $string
- * @return string
- * @access public
- */
- public static function remove0x($string) {
- if (substr($string, 0, 2) == "0x" || substr($string, 0, 2) == "0X") {
- $string = substr($string, 2);
- }
- return $string;
- }
-}
-
-/**
- * Exception class for BitcoinClient
- *
- * @author Mike Gogulski
- * http://www.gogulski.com/ http://www.nostate.com/
- */
-class BitcoinClientException extends ErrorException {
- // Redefine the exception so message isn't optional
- public function __construct($message, $code = 0, $severity = E_USER_NOTICE, Exception $previous = null) {
- parent::__construct($message, $code, $severity, $previous);
- }
-
- public function __toString() {
- return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
- }
-}
-
-require_once(dirname(__FILE__) . "/includes/xmlrpc.inc.php");
-require_once(dirname(__FILE__) . "/includes/jsonrpc.inc.php");
-
-/**
- * Bitcoin client class for access to a Bitcoin server via JSON-RPC-HTTP[S]
- *
- * Implements the methods documented at https://www.bitcoin.org/wiki/doku.php?id=api
- *
- * @version 0.3.19
- * @author Mike Gogulski
- * http://www.gogulski.com/ http://www.nostate.com/
- */
-class BitcoinClient extends jsonrpc_client {
-
- /**
- * Create a jsonrpc_client object to talk to the bitcoin server and return it,
- * or false on failure.
- *
- * @param string $scheme
- * "http" or "https"
- * @param string $username
- * User name to use in connection the Bitcoin server's JSON-RPC interface
- * @param string $password
- * Server password
- * @param string $address
- * Server hostname or IP address
- * @param mixed $port
- * Server port (string or integer)
- * @param string $certificate_path
- * Path on the local filesystem to server's PEM certificate (ignored if $scheme != "https")
- * @param integer $debug_level
- * 0 (default) = no debugging;
- * 1 = echo JSON-RPC messages received to stdout;
- * 2 = log transmitted messages also
- * @return jsonrpc_client
- * @access public
- * @throws BitcoinClientException
- */
- public function __construct($scheme, $username, $password, $address = "localhost", $port = 8332, $certificate_path = '', $debug_level = 0) {
- $scheme = strtolower($scheme);
- if ($scheme != "http" && $scheme != "https")
- throw new BitcoinClientException("Scheme must be http or https");
- if (empty($username))
- throw new BitcoinClientException("Username must be non-blank");
- if (empty($password))
- throw new BitcoinClientException("Password must be non-blank");
- $port = (string) $port;
- if (!$port || empty($port) || !is_numeric($port) || $port < 1 || $port > 65535 || floatval($port) != intval($port))
- throw new BitcoinClientException("Port must be an integer and between 1 and 65535");
- if (!empty($certificate_path) && !is_readable($certificate_path))
- throw new BitcoinClientException("Certificate file " . $certificate_path . " is not readable");
- $uri = $scheme . "://" . $username . ":" . $password . "@" . $address . ":" . $port . "/";
- parent::__construct($uri);
- $this->setDebug($debug_level);
- $this->setSSLVerifyHost(0);
- if ($scheme == "https")
- if (!empty($certificate_path))
- $this->setCaCertificate($certificate_path);
- else
- $this->setSSLVerifyPeer(false);
- }
-
- /**
- * Test if the connection to the Bitcoin JSON-RPC server is working
- *
- * The check is done by calling the server's getinfo() method and checking
- * for a fault.
- *
- * @return mixed boolean TRUE if successful, or a fault string otherwise
- * @access public
- * @throws none
- */
- public function can_connect() {
- try {
- $r = $this->getinfo();
- } catch (BitcoinClientException $e) {
- return $e->getMessage();
- }
- return true;
- }
-
- /**
- * Convert a Bitcoin server query argument to a jsonrpcval
- *
- * @param mixed $argument
- * @return jsonrpcval
- * @throws none
- * @todo Make this method private.
- */
- public function query_arg_to_parameter($argument) {
- $type = "";// "string" is encoded as this default type value in xmlrpc.inc
- if (is_numeric($argument)) {
- if (intval($argument) != floatval($argument)) {
- $argument = floatval($argument);
- $type = "double";
- } else {
- $argument = intval($argument);
- $type = "int";
- }
- }
- if (is_bool($argument))
- $type = "boolean";
- if (is_int($argument))
- $type = "int";
- if (is_float($argument))
- $type = "double";
- if (is_array($argument))
- $type = "array";
- return new jsonrpcval($argument, $type);
- }
-
- /**
- * Send a JSON-RPC message and optional parameter arguments to the server.
- *
- * Use the API functions if possible. This method remains public to support
- * changes being made to the API before this libarary can be updated.
- *
- * @param string $message
- * @param mixed $args, ...
- * @return mixed
- * @throws BitcoinClientException
- * @see xmlrpc.inc:php_xmlrpc_decode()
- */
- public function query($message) {
- if (!$message || empty($message))
- throw new BitcoinClientException("Bitcoin client query requires a message");
- $msg = new jsonrpcmsg($message);
- if (func_num_args() > 1) {
- for ($i = 1; $i < func_num_args(); $i++) {
- $msg->addParam(self::query_arg_to_parameter(func_get_arg($i)));
- }
- }
- $response = $this->send($msg);
- if ($response->faultCode()) {
- throw new BitcoinClientException($response->faultString());
- }
- return php_xmlrpc_decode($response->value());
- }
-
- /*
- * The following functions implement the Bitcoin RPC API as documented at https://www.bitcoin.org/wiki/doku.php?id=api
- */
-
- /**
- * Safely copies wallet.dat to destination, which can be a directory or
- * a path with filename.
- *
- * @param string $destination
- * @return mixed Nothing, or an error array
- * @throws BitcoinClientException
- */
- public function backupwallet($destination) {
- if (!$destination || empty($destination))
- throw new BitcoinClientException("backupwallet requires a destination");
- return $this->query("backupwallet", $destination);
- }
-
- /**
- * Returns the server's available balance, or the balance for $account with
- * at least $minconf confirmations.
- *
- * @param string $account Account to check. If not provided, the server's
- * total available balance is returned.
- * @param integer $minconf If specified, only transactions with at least
- * $minconf confirmations will be included in the returned total.
- * @return float Bitcoin balance
- * @throws BitcoinClientException
- */
- public function getbalance($account = NULL, $minconf = 1) {
- if (!is_numeric($minconf) || $minconf < 0)
- throw new BitcoinClientException('getbalance requires a numeric minconf >= 0');
- if ($account == NULL)
- return $this->query("getbalance");
- return $this->query("getbalance", $account, $minconf);
- }
-
- /**
- * Returns the number of blocks in the longest block chain.
- *
- * @return integer Current block count
- * @throws BitcoinClientException
- */
- public function getblockcount() {
- return $this->query("getblockcount");
- }
-
- /**
- * Returns the block number of the latest block in the longest block chain.
- *
- * @return integer Block number
- * @throws BitcoinClientException
- */
- public function getblocknumber() {
- return $this->query("getblocknumber");
- }
-
- /**
- * Returns the number of connections to other nodes.
- *
- * @return integer Connection count
- * @throws BitcoinClientException
- */
- public function getconnectioncount() {
- return $this->query("getconnectioncount");
- }
-
- /**
- * Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
- *
- * @return float Difficulty
- * @throws BitcoinClientException
- */
- public function getdifficulty() {
- return $this->query("getdifficulty");
- }
-
- /**
- * Returns boolean true if server is trying to generate bitcoins, false otherwise.
- *
- * @return boolean Generation status
- * @throws BitcoinClientException
- */
- public function getgenerate() {
- return $this->query("getgenerate");
- }
-
- /**
- * Tell Bitcoin server to generate Bitcoins or not, and how many processors
- * to use.
- *
- * @param boolean $generate
- * @param integer $maxproc
- * Limit generation to $maxproc processors, unlimited if -1
- * @return mixed Nothing if successful, error array if not
- * @throws BitcoinClientException
- */
- public function setgenerate($generate = TRUE, $maxproc = -1) {
- if (!is_numeric($maxproc) || $maxproc < -1)
- throw new BitcoinClientException('setgenerate: $maxproc must be numeric and >= -1');
- return $this->query("setgenerate", $generate, $maxproc);
- }
-
- /**
- * Returns an array containing server information.
- *
- * @return array Server information
- * @throws BitcoinClientException
- */
- public function getinfo() {
- return $this->query("getinfo");
- }
-
- /**
- * Returns the account associated with the given address.
- *
- * @param string $address
- * @return string Account
- * @throws BitcoinClientException
- * @since 0.3.17
- */
- public function getaccount($address) {
- if (!$address || empty($address))
- throw new BitcoinClientException("getaccount requires an address");
- return $this->query("getaccount", $address);
- }
-
- /**
- * Returns the label associated with the given address.
- *
- * @param string $address
- * @return string Label
- * @throws BitcoinClientException
- * @deprecated Since 0.3.17
- */
- public function getlabel($address) {
- if (!$address || empty($address))
- throw new BitcoinClientException("getlabel requires an address");
- return $this->query("getlabel", $address);
- }
-
- /**
- * Sets the account associated with the given address.
- * $account may be omitted to remove an account from an address.
- *
- * @param string $address
- * @param string $account
- * @return NULL
- * @throws BitcoinClientException
- * @since 0.3.17
- */
- public function setaccount($address, $account = "") {
- if (!$address || empty($address))
- throw new BitcoinClientException("setaccount requires an address");
- return $this->query("setaccount", $address, $account);
- }
-
- /**
- * Sets the label associated with the given address.
- * $label may be omitted to remove a label from an address.
- *
- * @param string $address
- * @param string $label
- * @return NULL
- * @throws BitcoinClientException
- * @deprecated Since 0.3.17
- */
- public function setlabel($address, $label = "") {
- if (!$address || empty($address))
- throw new BitcoinClientException("setlabel requires an address");
- return $this->query("setlabel", $address, $label);
- }
-
- /**
- * Returns a new bitcoin address for receiving payments.
- *
- * If $account is specified (recommended), it is added to the address book so
- * payments received with the address will be credited to $account.
- *
- * @param string $account Label to apply to the new address
- * @return string Bitcoin address
- * @throws BitcoinClientException
- */
- public function getnewaddress($account = NULL) {
- if (!$account || empty($account))
- return $this->query("getnewaddress");
- return $this->query("getnewaddress", $account);
- }
-
- /**
- * Returns the total amount received by $address in transactions with at least
- * $minconf confirmations.
- *
- * @param string $address
- * Bitcoin address
- * @param integer $minconf
- * Minimum number of confirmations for transactions to be counted
- * @return float Bitcoin total
- * @throws BitcoinClientException
- */
- public function getreceivedbyaddress($address, $minconf = 1) {
- if (!is_numeric($minconf) || $minconf < 0)
- throw new BitcoinClientException('getreceivedbyaddress requires a numeric minconf >= 0');
- if (!$address || empty($address))
- throw new BitcoinClientException("getreceivedbyaddress requires an address");
- return $this->query("getreceivedbyaddress", $address, $minconf);
- }
-
- /**
- * Returns the total amount received by addresses associated with $account
- * in transactions with at least $minconf confirmations.
- *
- * @param string $account
- * @param integer $minconf
- * Minimum number of confirmations for transactions to be counted
- * @return float Bitcoin total
- * @throws BitcoinClientException
- * @since 0.3.17
- */
- public function getreceivedbyaccount($account, $minconf = 1) {
- if (!is_numeric($minconf) || $minconf < 0)
- throw new BitcoinClientException('getreceivedbyaccount requires a numeric minconf >= 0');
- if (!$account || empty($account))
- throw new BitcoinClientException("getreceivedbyaccount requires an account");
- return $this->query("getreceivedbyaccount", $account, $minconf);
- }
-
- /**
- * Returns the total amount received by addresses with $label in
- * transactions with at least $minconf confirmations.
- *
- * @param string $label
- * @param integer $minconf
- * Minimum number of confirmations for transactions to be counted
- * @return float Bitcoin total
- * @throws BitcoinClientException
- * @deprecated Since 0.3.17
- */
- public function getreceivedbylabel($label, $minconf = 1) {
- if (!is_numeric($minconf) || $minconf < 0)
- throw new BitcoinClientException('getreceivedbylabel requires a numeric minconf >= 0');
- if (!$label || empty($label))
- throw new BitcoinClientException("getreceivedbylabel requires a label");
- return $this->query("getreceivedbylabel", $label, $minconf);
- }
-
- /**
- * Return a list of server RPC commands or help for $command, if specified.
- *
- * @param string $command
- * @return string Help text
- * @throws BitcoinClientException
- */
- public function help($command = NULL) {
- if (!$command || empty($command))
- return $this->query("help");
- return $this->query("help", $command);
- }
-
- /**
- * Return an array of arrays showing how many Bitcoins have been received by
- * each address in the server's wallet.
- *
- * @param integer $minconf Minimum number of confirmations before payments are included.
- * @param boolean $includeempty Whether to include addresses that haven't received any payments.
- * @return array An array of arrays. The elements are:
- * "address" => receiving address
- * "account" => the account of the receiving address
- * "amount" => total amount received by the address
- * "confirmations" => number of confirmations of the most recent transaction included
- * @throws BitcoinClientException
- */
- public function listreceivedbyaddress($minconf = 1, $includeempty = FALSE) {
- if (!is_numeric($minconf) || $minconf < 0)
- throw new BitcoinClientException('listreceivedbyaddress requires a numeric minconf >= 0');
- return $this->query("listreceivedbyaddress", $minconf, $includeempty);
- }
-
- /**
- * Return an array of arrays showing how many Bitcoins have been received by
- * each account in the server's wallet.
- *
- * @param integer $minconf
- * Minimum number of confirmations before payments are included.
- * @param boolean $includeempty
- * Whether to include addresses that haven't received any payments.
- * @return array An array of arrays. The elements are:
- * "account" => the label of the receiving address
- * "amount" => total amount received by the address
- * "confirmations" => number of confirmations of the most recent transaction included
- * @throws BitcoinClientException
- * @since 0.3.17
- */
- public function listreceivedbyaccount($minconf = 1, $includeempty = FALSE) {
- if (!is_numeric($minconf) || $minconf < 0)
- throw new BitcoinClientException('listreceivedbyaccount requires a numeric minconf >= 0');
- return $this->query("listreceivedbyaccount", $minconf, $includeempty);
- }
-
- /**
- * Return an array of arrays showing how many Bitcoins have been received by
- * each label in the server's wallet.
- *
- * @param integer $minconf Minimum number of confirmations before payments are included.
- * @param boolean $includeempty Whether to include addresses that haven't received any payments.
- * @return array An array of arrays. The elements are:
- * "label" => the label of the receiving address
- * "amount" => total amount received by the address
- * "confirmations" => number of confirmations of the most recent transaction included
- * @throws BitcoinClientException
- * @deprecated Since 0.3.17
- */
- public function listreceivedbylabel($minconf = 1, $includeempty = FALSE) {
- if (!is_numeric($minconf) || $minconf < 0)
- throw new BitcoinClientException('listreceivedbylabel requires a numeric minconf >= 0');
- return $this->query("listreceivedbylabel", $minconf, $includeempty);
- }
-
- /**
- * Send amount from the server's available balance.
- *
- * $amount is a real and is rounded to the nearest 0.01. Returns string "sent" on success.
- *
- * @param string $address Destination Bitcoin address or IP address
- * @param float $amount Amount to send. Will be rounded to the nearest 0.01.
- * @param string $comment
- * @param string $comment_to
- * @return string Hexadecimal transaction ID on success.
- * @throws BitcoinClientException
- * @todo Document the comment arguments better.
- */
- public function sendtoaddress($address, $amount, $comment = NULL, $comment_to = NULL) {
- if (!$address || empty($address))
- throw new BitcoinClientException("sendtoaddress requires a destination address");
- if (!$amount || empty($amount))
- throw new BitcoinClientException("sendtoaddress requires an amount to send");
- if (!is_numeric($amount) || $amount <= 0)
- throw new BitcoinClientException("sendtoaddress requires the amount sent to be a number > 0");
- $amount = floatval($amount);
- if (!$comment && !$comment_to)
- return $this->query("sendtoaddress", $address, $amount);
- if (!$comment_to)
- return $this->query("sendtoaddress", $address, $amount, $comment);
- return $this->query("sendtoaddress", $address, $amount, $comment, $comment_to);
- }
-
- /**
- * Stop the Bitcoin server.
- *
- * @throws BitcoinClientException
- */
- public function stop() {
- return $this->query("stop");
- }
-
- /**
- * Check that $address looks like a proper Bitcoin address.
- *
- * @param string $address String to test for validity as a Bitcoin address
- * @return array An array containing:
- * "isvalid" => true or false
- * "ismine" => true if the address is in the server's wallet
- * "address" => bitcoinaddress
- * Note: ismine and address are only returned if the address is valid.
- * @throws BitcoinClientException
- */
- public function validateaddress($address) {
- if (!$address || empty($address))
- throw new BitcoinClientException("validateaddress requires a Bitcoin address");
- return $this->query("validateaddress", $address);
- }
-
- /**
- * Return information about a specific transaction.
- *
- * @param string $txid 64-digit hexadecimal transaction ID
- * @return array An error array, or an array containing:
- * "amount" => float Transaction amount
- * "fee" => float Transaction fee
- * "confirmations" => integer Network confirmations of this transaction
- * "txid" => string The transaction ID
- * "message" => string Transaction "comment" message
- * "to" => string Transaction "to" message
- * @throws BitcoinClientException
- * @since 0.3.18
- */
- public function gettransaction($txid) {
- if (!$txid || empty($txid) || strlen($txid) != 64 || !preg_match('/^[0-9a-fA-F]+$/', $txid))
- throw new BitcoinClientException("gettransaction requires a valid hexadecimal transaction ID");
- return $this->query("getttransaction", $txid);
- }
-
- /**
- * Move bitcoins between accounts.
- *
- * @param string $fromaccount
- * Account to move from. If given as an empty string ("") or NULL, bitcoins will
- * be moved from the wallet balance to the target account.
- * @param string $toaccount
- * Account to move to
- * @param float $amount
- * Amount to move
- * @param integer $minconf
- * Minimum number of confirmations on bitcoins being moved
- * @param string $comment
- * Transaction comment
- * @throws BitcoinClientException
- * @since 0.3.18
- */
- public function move($fromaccount = "", $toaccount, $amount, $minconf = 1, $comment = NULL) {
- if (!$fromaccount)
- $fromaccount = "";
- if (!$toaccount || empty($toaccount) || !$amount || !is_numeric($amount) || $amount <= 0)
- throw new BitcoinClientException("move requires a from account, to account and numeric amount > 0");
- if (!is_numeric($minconf) || $minconf < 0)
- throw new BitcoinClientException('move requires a numeric $minconf >= 0');
- if (!$comment || empty($comment))
- return $this->query("move", $fromaccount, $toaccount, $amount, $minconf);
- return $this->query("move", $fromaccount, $toaccount, $amount, $minconf, $comment);
- }
-
- /**
- * Send $amount from $account's balance to $toaddress. This method will fail
- * if there is less than $amount bitcoins with $minconf confirmations in the
- * account's balance (unless $account is the empty-string-named default
- * account; it behaves like the sendtoaddress method). Returns transaction
- * ID on success.
- *
- * @param string $account Account to send from
- * @param string $toaddress Bitcoin address to send to
- * @param float $amount Amount to send
- * @param integer $minconf Minimum number of confirmations on bitcoins being sent
- * @param string $comment
- * @param string $comment_to
- * @return string Hexadecimal transaction ID
- * @throws BitcoinClientException
- * @since 0.3.18
- */
- public function sendfrom($account, $toaddress, $amount, $minconf = 1, $comment = NULL, $comment_to = NULL) {
- if (!$account || !$toaddress || empty($toaddress) || !$amount || !is_numeric($amount) || $amount <= 0)
- throw new BitcoinClientException("sendfrom requires a from account, to account and numeric amount > 0");
- if (!is_numeric($minconf) || $minconf < 0)
- throw new BitcoinClientException('sendfrom requires a numeric $minconf >= 0');
- if (!$comment && !$comment_to)
- return $this->query("sendfrom", $account, $toaddress, $amount, $minconf);
- if (!$comment_to)
- return $this->query("sendfrom", $account, $toaddress, $amount, $minconf, $comment);
- $this->query("sendfrom", $account, $toaddress, $amount, $minconf, $comment, $comment_to);
- }
-
- /**
- * Return formatted hash data to work on, or try to solve specified block.
- *
- * If $data is provided, tries to solve the block and returns true if successful.
- * If $data is not provided, returns formatted hash data to work on.
- *
- * @param string $data Block data
- * @return mixed
- * boolean TRUE if $data provided and block solving successful
- * array otherwise, containing:
- * "midstate" => string, precomputed hash state after hashing the first half of the data
- * "data" => string, block data
- * "hash1" => string, formatted hash buffer for second hash
- * "target" => string, little endian hash target
- * @throws BitcoinClientException
- * @since 0.3.18
- */
- public function getwork($data = NULL) {
- if (!$data)
- return $this->query("getwork");
- return $this->query("getwork", $data);
- }
-
- /**
- * Return the current bitcoin address for receiving payments to $account.
- * The account and address will be created if $account doesn't exist.
- *
- * @param string $account Account name
- * @return string Bitcoin address for $account
- * @throws BitcoinClientException
- * @since 0.3.18
- */
- public function getaccountaddress($account) {
- if (!$account || empty($account))
- throw new BitcoinClientException("getaccountaddress requires an account");
- return $this->query("getaccountaddress", $account);
- }
-
- /**
- * Return a recent hashes per second performance measurement.
- *
- * @return integer Hashes per second
- * @throws BitcoinClientException
- */
- public function gethashespersec() {
- return $this->query("gethashespersec");
- }
-
- /**
- * Returns the list of addresses associated with the given account.
- *
- * @param string $account
- * @return array
- * A simple array of Bitcoin addresses associated with $account, empty
- * if the account doesn't exist.
- * @throws BitcoinClientException
- */
- public function getaddressesbyaccount($account) {
- if (!$account || empty($account))
- throw new BitcoinClientException("getaddressesbyaccount requires an account");
- return $this->query("getaddressesbyaccount", $account);
- }
-
-}
+ hexdec($addressversion)) {
+ return false;
+ }
+ $check = substr($addr, 0, strlen($addr) - 8);
+ $check = pack("H*", $check);
+ $check = strtoupper(hash("sha256", hash("sha256", $check, true)));
+ $check = substr($check, 0, 8);
+ return $check == substr($addr, strlen($addr) - 8);
+ }
+
+ /**
+ * Convert the input to its 160-bit Bitcoin hash
+ *
+ * @param string $data
+ * @return string
+ * @access private
+ */
+ private function hash160($data) {
+ $data = pack("H*", $data);
+ return strtoupper(hash("ripemd160", hash("sha256", $data, true)));
+ }
+
+ /**
+ * Convert a Bitcoin public key to a 160-bit Bitcoin hash
+ *
+ * @param string $pubkey
+ * @return string
+ * @access public
+ */
+ public static function pubKeyToAddress($pubkey) {
+ return self::hash160ToAddress($this->hash160($pubkey));
+ }
+
+ /**
+ * Remove leading "0x" from a hex value if present.
+ *
+ * @param string $string
+ * @return string
+ * @access public
+ */
+ public static function remove0x($string) {
+ if (substr($string, 0, 2) == "0x" || substr($string, 0, 2) == "0X") {
+ $string = substr($string, 2);
+ }
+ return $string;
+ }
+}
+
+/**
+ * Exception class for BitcoinClient
+ *
+ * @author Mike Gogulski
+ * http://www.gogulski.com/ http://www.nostate.com/
+ */
+class BitcoinClientException extends ErrorException {
+ // Redefine the exception so message isn't optional
+ public function __construct($message, $code = 0, $severity = E_USER_NOTICE, Exception $previous = null) {
+ parent::__construct($message, $code, $severity, $previous);
+ }
+
+ public function __toString() {
+ return __CLASS__ . ": [{$this->code}]: {$this->message}\n";
+ }
+}
+
+require_once(dirname(__FILE__) . "/includes/xmlrpc.inc.php");
+require_once(dirname(__FILE__) . "/includes/jsonrpc.inc.php");
+
+/**
+ * Bitcoin client class for access to a Bitcoin server via JSON-RPC-HTTP[S]
+ *
+ * Implements the methods documented at https://www.bitcoin.org/wiki/doku.php?id=api
+ *
+ * @version 0.3.19
+ * @author Mike Gogulski
+ * http://www.gogulski.com/ http://www.nostate.com/
+ */
+class BitcoinClient extends jsonrpc_client {
+
+ /**
+ * Create a jsonrpc_client object to talk to the bitcoin server and return it,
+ * or false on failure.
+ *
+ * @param string $scheme
+ * "http" or "https"
+ * @param string $username
+ * User name to use in connection the Bitcoin server's JSON-RPC interface
+ * @param string $password
+ * Server password
+ * @param string $address
+ * Server hostname or IP address
+ * @param mixed $port
+ * Server port (string or integer)
+ * @param string $certificate_path
+ * Path on the local filesystem to server's PEM certificate (ignored if $scheme != "https")
+ * @param integer $debug_level
+ * 0 (default) = no debugging;
+ * 1 = echo JSON-RPC messages received to stdout;
+ * 2 = log transmitted messages also
+ * @return jsonrpc_client
+ * @access public
+ * @throws BitcoinClientException
+ */
+ public function __construct($scheme, $username, $password, $address = "localhost", $port = 8332, $certificate_path = '', $debug_level = 0) {
+ $scheme = strtolower($scheme);
+ if ($scheme != "http" && $scheme != "https")
+ throw new BitcoinClientException("Scheme must be http or https");
+ if (empty($username))
+ throw new BitcoinClientException("Username must be non-blank");
+ if (empty($password))
+ throw new BitcoinClientException("Password must be non-blank");
+ $port = (string) $port;
+ if (!$port || empty($port) || !is_numeric($port) || $port < 1 || $port > 65535 || floatval($port) != intval($port))
+ throw new BitcoinClientException("Port must be an integer and between 1 and 65535");
+ if (!empty($certificate_path) && !is_readable($certificate_path))
+ throw new BitcoinClientException("Certificate file " . $certificate_path . " is not readable");
+ $uri = $scheme . "://" . $username . ":" . $password . "@" . $address . ":" . $port . "/";
+ parent::__construct($uri);
+ $this->setDebug($debug_level);
+ $this->setSSLVerifyHost(0);
+ if ($scheme == "https")
+ if (!empty($certificate_path))
+ $this->setCaCertificate($certificate_path);
+ else
+ $this->setSSLVerifyPeer(false);
+ }
+
+ /**
+ * Test if the connection to the Bitcoin JSON-RPC server is working
+ *
+ * The check is done by calling the server's getinfo() method and checking
+ * for a fault.
+ *
+ * @return mixed boolean TRUE if successful, or a fault string otherwise
+ * @access public
+ * @throws none
+ */
+ public function can_connect() {
+ try {
+ $r = $this->getinfo();
+ } catch (BitcoinClientException $e) {
+ return $e->getMessage();
+ }
+ return true;
+ }
+
+ /**
+ * Convert a Bitcoin server query argument to a jsonrpcval
+ *
+ * @param mixed $argument
+ * @return jsonrpcval
+ * @throws none
+ * @todo Make this method private.
+ */
+ public function query_arg_to_parameter($argument) {
+ $type = "";// "string" is encoded as this default type value in xmlrpc.inc
+ if (is_numeric($argument)) {
+ if (intval($argument) != floatval($argument)) {
+ $argument = floatval($argument);
+ $type = "double";
+ } else {
+ $argument = intval($argument);
+ $type = "int";
+ }
+ }
+ if (is_bool($argument))
+ $type = "boolean";
+ if (is_int($argument))
+ $type = "int";
+ if (is_float($argument))
+ $type = "double";
+ if (is_array($argument))
+ $type = "array";
+ return new jsonrpcval($argument, $type);
+ }
+
+ /**
+ * Send a JSON-RPC message and optional parameter arguments to the server.
+ *
+ * Use the API functions if possible. This method remains public to support
+ * changes being made to the API before this libarary can be updated.
+ *
+ * @param string $message
+ * @param mixed $args, ...
+ * @return mixed
+ * @throws BitcoinClientException
+ * @see xmlrpc.inc:php_xmlrpc_decode()
+ */
+ public function query($message) {
+ if (!$message || empty($message))
+ throw new BitcoinClientException("Bitcoin client query requires a message");
+ $msg = new jsonrpcmsg($message);
+ if (func_num_args() > 1) {
+ for ($i = 1; $i < func_num_args(); $i++) {
+ $msg->addParam(self::query_arg_to_parameter(func_get_arg($i)));
+ }
+ }
+ $response = $this->send($msg);
+ if ($response->faultCode()) {
+ throw new BitcoinClientException($response->faultString());
+ }
+ return php_xmlrpc_decode($response->value());
+ }
+
+ /*
+ * The following functions implement the Bitcoin RPC API as documented at https://www.bitcoin.org/wiki/doku.php?id=api
+ */
+
+ /**
+ * Safely copies wallet.dat to destination, which can be a directory or
+ * a path with filename.
+ *
+ * @param string $destination
+ * @return mixed Nothing, or an error array
+ * @throws BitcoinClientException
+ */
+ public function backupwallet($destination) {
+ if (!$destination || empty($destination))
+ throw new BitcoinClientException("backupwallet requires a destination");
+ return $this->query("backupwallet", $destination);
+ }
+
+ /**
+ * Returns the server's available balance, or the balance for $account with
+ * at least $minconf confirmations.
+ *
+ * @param string $account Account to check. If not provided, the server's
+ * total available balance is returned.
+ * @param integer $minconf If specified, only transactions with at least
+ * $minconf confirmations will be included in the returned total.
+ * @return float Bitcoin balance
+ * @throws BitcoinClientException
+ */
+ public function getbalance($account = NULL, $minconf = 1) {
+ if (!is_numeric($minconf) || $minconf < 0)
+ throw new BitcoinClientException('getbalance requires a numeric minconf >= 0');
+ if ($account == NULL)
+ return $this->query("getbalance");
+ return $this->query("getbalance", $account, $minconf);
+ }
+
+ /**
+ * Returns the number of blocks in the longest block chain.
+ *
+ * @return integer Current block count
+ * @throws BitcoinClientException
+ */
+ public function getblockcount() {
+ return $this->query("getblockcount");
+ }
+
+ /**
+ * Returns the block number of the latest block in the longest block chain.
+ *
+ * @return integer Block number
+ * @throws BitcoinClientException
+ */
+ public function getblocknumber() {
+ return $this->query("getblocknumber");
+ }
+
+ /**
+ * Returns the number of connections to other nodes.
+ *
+ * @return integer Connection count
+ * @throws BitcoinClientException
+ */
+ public function getconnectioncount() {
+ return $this->query("getconnectioncount");
+ }
+
+ /**
+ * Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
+ *
+ * @return float Difficulty
+ * @throws BitcoinClientException
+ */
+ public function getdifficulty() {
+ return $this->query("getdifficulty");
+ }
+
+ /**
+ * Returns boolean true if server is trying to generate bitcoins, false otherwise.
+ *
+ * @return boolean Generation status
+ * @throws BitcoinClientException
+ */
+ public function getgenerate() {
+ return $this->query("getgenerate");
+ }
+
+ /**
+ * Tell Bitcoin server to generate Bitcoins or not, and how many processors
+ * to use.
+ *
+ * @param boolean $generate
+ * @param integer $maxproc
+ * Limit generation to $maxproc processors, unlimited if -1
+ * @return mixed Nothing if successful, error array if not
+ * @throws BitcoinClientException
+ */
+ public function setgenerate($generate = TRUE, $maxproc = -1) {
+ if (!is_numeric($maxproc) || $maxproc < -1)
+ throw new BitcoinClientException('setgenerate: $maxproc must be numeric and >= -1');
+ return $this->query("setgenerate", $generate, $maxproc);
+ }
+
+ /**
+ * Returns an array containing server information.
+ *
+ * @return array Server information
+ * @throws BitcoinClientException
+ */
+ public function getinfo() {
+ return $this->query("getinfo");
+ }
+
+ /**
+ * Returns the account associated with the given address.
+ *
+ * @param string $address
+ * @return string Account
+ * @throws BitcoinClientException
+ * @since 0.3.17
+ */
+ public function getaccount($address) {
+ if (!$address || empty($address))
+ throw new BitcoinClientException("getaccount requires an address");
+ return $this->query("getaccount", $address);
+ }
+
+ /**
+ * Returns the label associated with the given address.
+ *
+ * @param string $address
+ * @return string Label
+ * @throws BitcoinClientException
+ * @deprecated Since 0.3.17
+ */
+ public function getlabel($address) {
+ if (!$address || empty($address))
+ throw new BitcoinClientException("getlabel requires an address");
+ return $this->query("getlabel", $address);
+ }
+
+ /**
+ * Sets the account associated with the given address.
+ * $account may be omitted to remove an account from an address.
+ *
+ * @param string $address
+ * @param string $account
+ * @return NULL
+ * @throws BitcoinClientException
+ * @since 0.3.17
+ */
+ public function setaccount($address, $account = "") {
+ if (!$address || empty($address))
+ throw new BitcoinClientException("setaccount requires an address");
+ return $this->query("setaccount", $address, $account);
+ }
+
+ /**
+ * Sets the label associated with the given address.
+ * $label may be omitted to remove a label from an address.
+ *
+ * @param string $address
+ * @param string $label
+ * @return NULL
+ * @throws BitcoinClientException
+ * @deprecated Since 0.3.17
+ */
+ public function setlabel($address, $label = "") {
+ if (!$address || empty($address))
+ throw new BitcoinClientException("setlabel requires an address");
+ return $this->query("setlabel", $address, $label);
+ }
+
+ /**
+ * Returns a new bitcoin address for receiving payments.
+ *
+ * If $account is specified (recommended), it is added to the address book so
+ * payments received with the address will be credited to $account.
+ *
+ * @param string $account Label to apply to the new address
+ * @return string Bitcoin address
+ * @throws BitcoinClientException
+ */
+ public function getnewaddress($account = NULL) {
+ if (!$account || empty($account))
+ return $this->query("getnewaddress");
+ return $this->query("getnewaddress", $account);
+ }
+
+ /**
+ * Returns the total amount received by $address in transactions with at least
+ * $minconf confirmations.
+ *
+ * @param string $address
+ * Bitcoin address
+ * @param integer $minconf
+ * Minimum number of confirmations for transactions to be counted
+ * @return float Bitcoin total
+ * @throws BitcoinClientException
+ */
+ public function getreceivedbyaddress($address, $minconf = 1) {
+ if (!is_numeric($minconf) || $minconf < 0)
+ throw new BitcoinClientException('getreceivedbyaddress requires a numeric minconf >= 0');
+ if (!$address || empty($address))
+ throw new BitcoinClientException("getreceivedbyaddress requires an address");
+ return $this->query("getreceivedbyaddress", $address, $minconf);
+ }
+
+ /**
+ * Returns the total amount received by addresses associated with $account
+ * in transactions with at least $minconf confirmations.
+ *
+ * @param string $account
+ * @param integer $minconf
+ * Minimum number of confirmations for transactions to be counted
+ * @return float Bitcoin total
+ * @throws BitcoinClientException
+ * @since 0.3.17
+ */
+ public function getreceivedbyaccount($account, $minconf = 1) {
+ if (!is_numeric($minconf) || $minconf < 0)
+ throw new BitcoinClientException('getreceivedbyaccount requires a numeric minconf >= 0');
+ if (!$account || empty($account))
+ throw new BitcoinClientException("getreceivedbyaccount requires an account");
+ return $this->query("getreceivedbyaccount", $account, $minconf);
+ }
+
+ /**
+ * Returns the total amount received by addresses with $label in
+ * transactions with at least $minconf confirmations.
+ *
+ * @param string $label
+ * @param integer $minconf
+ * Minimum number of confirmations for transactions to be counted
+ * @return float Bitcoin total
+ * @throws BitcoinClientException
+ * @deprecated Since 0.3.17
+ */
+ public function getreceivedbylabel($label, $minconf = 1) {
+ if (!is_numeric($minconf) || $minconf < 0)
+ throw new BitcoinClientException('getreceivedbylabel requires a numeric minconf >= 0');
+ if (!$label || empty($label))
+ throw new BitcoinClientException("getreceivedbylabel requires a label");
+ return $this->query("getreceivedbylabel", $label, $minconf);
+ }
+
+ /**
+ * Return a list of server RPC commands or help for $command, if specified.
+ *
+ * @param string $command
+ * @return string Help text
+ * @throws BitcoinClientException
+ */
+ public function help($command = NULL) {
+ if (!$command || empty($command))
+ return $this->query("help");
+ return $this->query("help", $command);
+ }
+
+ /**
+ * Return an array of arrays showing how many Bitcoins have been received by
+ * each address in the server's wallet.
+ *
+ * @param integer $minconf Minimum number of confirmations before payments are included.
+ * @param boolean $includeempty Whether to include addresses that haven't received any payments.
+ * @return array An array of arrays. The elements are:
+ * "address" => receiving address
+ * "account" => the account of the receiving address
+ * "amount" => total amount received by the address
+ * "confirmations" => number of confirmations of the most recent transaction included
+ * @throws BitcoinClientException
+ */
+ public function listreceivedbyaddress($minconf = 1, $includeempty = FALSE) {
+ if (!is_numeric($minconf) || $minconf < 0)
+ throw new BitcoinClientException('listreceivedbyaddress requires a numeric minconf >= 0');
+ return $this->query("listreceivedbyaddress", $minconf, $includeempty);
+ }
+
+ /**
+ * Return an array of arrays showing how many Bitcoins have been received by
+ * each account in the server's wallet.
+ *
+ * @param integer $minconf
+ * Minimum number of confirmations before payments are included.
+ * @param boolean $includeempty
+ * Whether to include addresses that haven't received any payments.
+ * @return array An array of arrays. The elements are:
+ * "account" => the label of the receiving address
+ * "amount" => total amount received by the address
+ * "confirmations" => number of confirmations of the most recent transaction included
+ * @throws BitcoinClientException
+ * @since 0.3.17
+ */
+ public function listreceivedbyaccount($minconf = 1, $includeempty = FALSE) {
+ if (!is_numeric($minconf) || $minconf < 0)
+ throw new BitcoinClientException('listreceivedbyaccount requires a numeric minconf >= 0');
+ return $this->query("listreceivedbyaccount", $minconf, $includeempty);
+ }
+
+ /**
+ * Return an array of arrays showing how many Bitcoins have been received by
+ * each label in the server's wallet.
+ *
+ * @param integer $minconf Minimum number of confirmations before payments are included.
+ * @param boolean $includeempty Whether to include addresses that haven't received any payments.
+ * @return array An array of arrays. The elements are:
+ * "label" => the label of the receiving address
+ * "amount" => total amount received by the address
+ * "confirmations" => number of confirmations of the most recent transaction included
+ * @throws BitcoinClientException
+ * @deprecated Since 0.3.17
+ */
+ public function listreceivedbylabel($minconf = 1, $includeempty = FALSE) {
+ if (!is_numeric($minconf) || $minconf < 0)
+ throw new BitcoinClientException('listreceivedbylabel requires a numeric minconf >= 0');
+ return $this->query("listreceivedbylabel", $minconf, $includeempty);
+ }
+
+ /**
+ * Send amount from the server's available balance.
+ *
+ * $amount is a real and is rounded to the nearest 0.01. Returns string "sent" on success.
+ *
+ * @param string $address Destination Bitcoin address or IP address
+ * @param float $amount Amount to send. Will be rounded to the nearest 0.01.
+ * @param string $comment
+ * @param string $comment_to
+ * @return string Hexadecimal transaction ID on success.
+ * @throws BitcoinClientException
+ * @todo Document the comment arguments better.
+ */
+ public function sendtoaddress($address, $amount, $comment = NULL, $comment_to = NULL) {
+ if (!$address || empty($address))
+ throw new BitcoinClientException("sendtoaddress requires a destination address");
+ if (!$amount || empty($amount))
+ throw new BitcoinClientException("sendtoaddress requires an amount to send");
+ if (!is_numeric($amount) || $amount <= 0)
+ throw new BitcoinClientException("sendtoaddress requires the amount sent to be a number > 0");
+ $amount = floatval($amount);
+ if (!$comment && !$comment_to)
+ return $this->query("sendtoaddress", $address, $amount);
+ if (!$comment_to)
+ return $this->query("sendtoaddress", $address, $amount, $comment);
+ return $this->query("sendtoaddress", $address, $amount, $comment, $comment_to);
+ }
+
+ /**
+ * Stop the Bitcoin server.
+ *
+ * @throws BitcoinClientException
+ */
+ public function stop() {
+ return $this->query("stop");
+ }
+
+ /**
+ * Check that $address looks like a proper Bitcoin address.
+ *
+ * @param string $address String to test for validity as a Bitcoin address
+ * @return array An array containing:
+ * "isvalid" => true or false
+ * "ismine" => true if the address is in the server's wallet
+ * "address" => bitcoinaddress
+ * Note: ismine and address are only returned if the address is valid.
+ * @throws BitcoinClientException
+ */
+ public function validateaddress($address) {
+ if (!$address || empty($address))
+ throw new BitcoinClientException("validateaddress requires a Bitcoin address");
+ return $this->query("validateaddress", $address);
+ }
+
+ /**
+ * Return information about a specific transaction.
+ *
+ * @param string $txid 64-digit hexadecimal transaction ID
+ * @return array An error array, or an array containing:
+ * "amount" => float Transaction amount
+ * "fee" => float Transaction fee
+ * "confirmations" => integer Network confirmations of this transaction
+ * "txid" => string The transaction ID
+ * "message" => string Transaction "comment" message
+ * "to" => string Transaction "to" message
+ * @throws BitcoinClientException
+ * @since 0.3.18
+ */
+ public function gettransaction($txid) {
+ if (!$txid || empty($txid) || strlen($txid) != 64 || !preg_match('/^[0-9a-fA-F]+$/', $txid))
+ throw new BitcoinClientException("gettransaction requires a valid hexadecimal transaction ID");
+ return $this->query("getttransaction", $txid);
+ }
+
+ /**
+ * Move bitcoins between accounts.
+ *
+ * @param string $fromaccount
+ * Account to move from. If given as an empty string ("") or NULL, bitcoins will
+ * be moved from the wallet balance to the target account.
+ * @param string $toaccount
+ * Account to move to
+ * @param float $amount
+ * Amount to move
+ * @param integer $minconf
+ * Minimum number of confirmations on bitcoins being moved
+ * @param string $comment
+ * Transaction comment
+ * @throws BitcoinClientException
+ * @since 0.3.18
+ */
+ public function move($fromaccount = "", $toaccount, $amount, $minconf = 1, $comment = NULL) {
+ if (!$fromaccount)
+ $fromaccount = "";
+ if (!$toaccount || empty($toaccount) || !$amount || !is_numeric($amount) || $amount <= 0)
+ throw new BitcoinClientException("move requires a from account, to account and numeric amount > 0");
+ if (!is_numeric($minconf) || $minconf < 0)
+ throw new BitcoinClientException('move requires a numeric $minconf >= 0');
+ if (!$comment || empty($comment))
+ return $this->query("move", $fromaccount, $toaccount, $amount, $minconf);
+ return $this->query("move", $fromaccount, $toaccount, $amount, $minconf, $comment);
+ }
+
+ /**
+ * Send $amount from $account's balance to $toaddress. This method will fail
+ * if there is less than $amount bitcoins with $minconf confirmations in the
+ * account's balance (unless $account is the empty-string-named default
+ * account; it behaves like the sendtoaddress method). Returns transaction
+ * ID on success.
+ *
+ * @param string $account Account to send from
+ * @param string $toaddress Bitcoin address to send to
+ * @param float $amount Amount to send
+ * @param integer $minconf Minimum number of confirmations on bitcoins being sent
+ * @param string $comment
+ * @param string $comment_to
+ * @return string Hexadecimal transaction ID
+ * @throws BitcoinClientException
+ * @since 0.3.18
+ */
+ public function sendfrom($account, $toaddress, $amount, $minconf = 1, $comment = NULL, $comment_to = NULL) {
+ if (!$account || !$toaddress || empty($toaddress) || !$amount || !is_numeric($amount) || $amount <= 0)
+ throw new BitcoinClientException("sendfrom requires a from account, to account and numeric amount > 0");
+ if (!is_numeric($minconf) || $minconf < 0)
+ throw new BitcoinClientException('sendfrom requires a numeric $minconf >= 0');
+ if (!$comment && !$comment_to)
+ return $this->query("sendfrom", $account, $toaddress, $amount, $minconf);
+ if (!$comment_to)
+ return $this->query("sendfrom", $account, $toaddress, $amount, $minconf, $comment);
+ $this->query("sendfrom", $account, $toaddress, $amount, $minconf, $comment, $comment_to);
+ }
+
+ /**
+ * Return formatted hash data to work on, or try to solve specified block.
+ *
+ * If $data is provided, tries to solve the block and returns true if successful.
+ * If $data is not provided, returns formatted hash data to work on.
+ *
+ * @param string $data Block data
+ * @return mixed
+ * boolean TRUE if $data provided and block solving successful
+ * array otherwise, containing:
+ * "midstate" => string, precomputed hash state after hashing the first half of the data
+ * "data" => string, block data
+ * "hash1" => string, formatted hash buffer for second hash
+ * "target" => string, little endian hash target
+ * @throws BitcoinClientException
+ * @since 0.3.18
+ */
+ public function getwork($data = NULL) {
+ if (!$data)
+ return $this->query("getwork");
+ return $this->query("getwork", $data);
+ }
+
+ /**
+ * Return the current bitcoin address for receiving payments to $account.
+ * The account and address will be created if $account doesn't exist.
+ *
+ * @param string $account Account name
+ * @return string Bitcoin address for $account
+ * @throws BitcoinClientException
+ * @since 0.3.18
+ */
+ public function getaccountaddress($account) {
+ if (!$account || empty($account))
+ throw new BitcoinClientException("getaccountaddress requires an account");
+ return $this->query("getaccountaddress", $account);
+ }
+
+ /**
+ * Return a recent hashes per second performance measurement.
+ *
+ * @return integer Hashes per second
+ * @throws BitcoinClientException
+ */
+ public function gethashespersec() {
+ return $this->query("gethashespersec");
+ }
+
+ /**
+ * Returns the list of addresses associated with the given account.
+ *
+ * @param string $account
+ * @return array
+ * A simple array of Bitcoin addresses associated with $account, empty
+ * if the account doesn't exist.
+ * @throws BitcoinClientException
+ */
+ public function getaddressesbyaccount($account) {
+ if (!$account || empty($account))
+ throw new BitcoinClientException("getaddressesbyaccount requires an account");
+ return $this->query("getaddressesbyaccount", $account);
+ }
+
+}
diff --git a/includes/block.php b/includes/block.php
index 2814f31..ed5adfd 100644
--- a/includes/block.php
+++ b/includes/block.php
@@ -3,6 +3,7 @@ class Block {
function getLatestDbBlockNumber() {
$result = mysql_query("SELECT blockNumber FROM networkBlocks ORDER BY blockNumber DESC LIMIT 1");
+ if ($result )
if ($row = mysql_fetch_row($result)) {
if (count($row) > 0)
return $row[0];
@@ -13,7 +14,9 @@ function getLatestDbBlockNumber() {
function InsertNetworkBlocks($lastBlockNumber,$lastwinningid) {
//Check to see if last block number exists in the db.
$inDatabaseQ = mysql_query("SELECT id FROM networkBlocks WHERE blockNumber = $lastBlockNumber LIMIT 0,1");
+ if ( $inDatabaseQ )
$inDatabase = mysql_num_rows($inDatabaseQ);
+ if ( isset( $inDatabase ) )
if(!$inDatabase) {
//If not, insert it.
$currentTime = time();
@@ -21,6 +24,7 @@ function InsertNetworkBlocks($lastBlockNumber,$lastwinningid) {
//Save winning share (if there is one)
$winningShareQ = mysql_query("SELECT id, username FROM shares where upstream_result = 'Y' AND id > $lastwinningid");
+ if ( $winningShareQ )
while ($winningShareR = mysql_fetch_object($winningShareQ)) {
mysql_query("INSERT INTO winning_shares (blockNumber, username, share_id) VALUES ($lastBlockNumber,'$winningShareR->username',$winningShareR->id)");
removeCache("last_winning_share_id");
@@ -30,6 +34,7 @@ function InsertNetworkBlocks($lastBlockNumber,$lastwinningid) {
function UpdateConfirms($bitcoinController) {
$winningAccountQ = mysql_query("SELECT id, txid FROM winning_shares WHERE txid <> '' AND confirms < 120");
+ if ( $winningAccountQ )
while ($winningAccountR = mysql_fetch_object($winningAccountQ)) {
$txInfo = $bitcoinController->query("gettransaction", $winningAccountR->txid);
if (count($txInfo["confirmations"]) > 0) {
@@ -100,9 +105,13 @@ function NeedsArchiving($siterewardtype, $difficulty) {
}
} else {
$result = mysql_query("SELECT count(s.id) FROM shares s, (SELECT max(share_id) as share_id FROM winning_shares WHERE rewarded='Y') w WHERE s.id < w.share_id");
- $row = mysql_fetch_row($result);
- if ($row[0] > 0)
+ if ( $result )
+ {
+ $row = mysql_fetch_row($result);
+ if ($row[0] > 0)
return true;
+ }
+ else return false;
}
return false;
}
@@ -175,4 +184,4 @@ function Archive($siterewardtype, $difficulty) {
}
}
}
-?>
\ No newline at end of file
+?>
diff --git a/includes/config.php.example b/includes/config.php.example
new file mode 100644
index 0000000..c1077ca
--- /dev/null
+++ b/includes/config.php.example
@@ -0,0 +1,72 @@
+
diff --git a/includes/footer.php b/includes/footer.php
index 56249ca..e1e6fbe 100644
--- a/includes/footer.php
+++ b/includes/footer.php
@@ -1,8 +1,8 @@
-