(#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.
This commit is contained in:
j4s0n 2014-02-10 12:07:08 -05:00
parent 6ea257ac20
commit 8c3205a8b2
2 changed files with 21 additions and 7 deletions

View File

@ -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 <u>SET and INVALID</u>";
}
} 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']);

View File

@ -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;
}
}