From 8c3205a8b218f5b29e7713da9bc275738ece3b88 Mon Sep 17 00:00:00 2001 From: j4s0n Date: Mon, 10 Feb 2014 12:07:08 -0500 Subject: [PATCH 1/2] (#1725) Fix cold wallet check FP and added testnet detection Without this patch, admin.php checks if it can connect to the wallet service. Regardless of if that check passes or fails, it then checks if the cold wallet address is valid. If the can_connect() test failed, the validateaddress() check will also fail, even if the address is not invalid. To fix this, the validateaddress() check is move to an elseif block in the can_connect() chain. Additionally, this patch checks to see if the wallet service is running as a testnet. While running as a testnet is perfectly acceptable when testing, the suer should be warned. A lot of folks using the quickstart guide miss this. A function was added to the Bitcoin class to detect when we are running in a test net. A check was added to admin.php, and the existing can_connect and validateaddress() calls were restructured to solve these issues. --- public/include/admin_checks.php | 16 +++++++++------- public/include/classes/bitcoin.class.php | 12 ++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/public/include/admin_checks.php b/public/include/admin_checks.php index dad3070e..940e076c 100644 --- a/public/include/admin_checks.php +++ b/public/include/admin_checks.php @@ -65,17 +65,19 @@ if (@$_SESSION['USERDATA']['is_admin'] && $user->isAdmin(@$_SESSION['USERDATA'][ if ($bitcoin->can_connect() !== true) { $error[] = "Unable to connect to coin daemon using provided credentials"; } - } catch (Exception $e) { - } - // if coldwallet is not empty, check if the address is valid -> error - if (!empty($config['coldwallet']['address'])) { - try { - if ($bitcoin->can_connect() == true) { + else { + // validate that the wallet service is not in test mode + if ($bitcoin->is_testnet() == true) { + $error[] = "The coin daemon service is running as a testnet. Check the TESTNET seeing in your coin daemon config and make sure the correct port is set in the MPOS config."; + } + + // if coldwallet is not empty, check if the address is valid -> error + if (!empty($config['coldwallet']['address'])) { if (!$bitcoin->validateaddress($config['coldwallet']['address'])) $error[] = "Your cold wallet address is SET and INVALID"; } - } catch (Exception $e) { } + } catch (Exception $e) { } // if database connection fails -> error $db_connect = new mysqli($config['db']['host'], $config['db']['user'], $config['db']['pass'], $config['db']['name'], $config['db']['port']); diff --git a/public/include/classes/bitcoin.class.php b/public/include/classes/bitcoin.class.php index 11e82f70..03e63e6f 100644 --- a/public/include/classes/bitcoin.class.php +++ b/public/include/classes/bitcoin.class.php @@ -308,4 +308,16 @@ class BitcoinClient extends jsonRPCClient { } return true; } + + public function is_testnet() { + try { + $r = parent::getinfo(); + if ($r['testnet']) { + return true; + } + } catch (Exception $e) { + return false; + } + return false; + } } From 4f7dcb4f9ca75a8cb59e5fc262fb18cd3cb82ce3 Mon Sep 17 00:00:00 2001 From: j4s0n Date: Mon, 10 Feb 2014 23:46:56 -0500 Subject: [PATCH 2/2] Typo correction. --- public/include/admin_checks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/include/admin_checks.php b/public/include/admin_checks.php index 940e076c..f29c67d4 100644 --- a/public/include/admin_checks.php +++ b/public/include/admin_checks.php @@ -68,7 +68,7 @@ if (@$_SESSION['USERDATA']['is_admin'] && $user->isAdmin(@$_SESSION['USERDATA'][ else { // validate that the wallet service is not in test mode if ($bitcoin->is_testnet() == true) { - $error[] = "The coin daemon service is running as a testnet. Check the TESTNET seeing in your coin daemon config and make sure the correct port is set in the MPOS config."; + $error[] = "The coin daemon service is running as a testnet. Check the TESTNET setting in your coin daemon config and make sure the correct port is set in the MPOS config."; } // if coldwallet is not empty, check if the address is valid -> error