Merge pull request #4623

e84843c Broken addresses on command line no longer trigger testnet. (Ross Nicoll)
This commit is contained in:
Wladimir J. van der Laan 2014-09-10 14:29:16 +02:00
commit f23869e14b
No known key found for this signature in database
GPG key ID: 74810B012346C9A6
5 changed files with 26 additions and 13 deletions

View file

@ -215,9 +215,13 @@ bool CBitcoinAddress::Set(const CTxDestination &dest) {
}
bool CBitcoinAddress::IsValid() const {
return IsValid(Params());
}
bool CBitcoinAddress::IsValid(const CChainParams &params) const {
bool fCorrectSize = vchData.size() == 20;
bool fKnownVersion = vchVersion == Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS) ||
vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS);
bool fKnownVersion = vchVersion == params.Base58Prefix(CChainParams::PUBKEY_ADDRESS) ||
vchVersion == params.Base58Prefix(CChainParams::SCRIPT_ADDRESS);
return fCorrectSize && fKnownVersion;
}

View file

@ -104,6 +104,7 @@ public:
bool Set(const CScriptID &id);
bool Set(const CTxDestination &dest);
bool IsValid() const;
bool IsValid(const CChainParams &params) const;
CBitcoinAddress() {}
CBitcoinAddress(const CTxDestination &dest) { Set(dest); }

View file

@ -221,24 +221,25 @@ const CChainParams &Params() {
return *pCurrentParams;
}
void SelectParams(CBaseChainParams::Network network) {
SelectBaseParams(network);
CChainParams &Params(CBaseChainParams::Network network) {
switch (network) {
case CBaseChainParams::MAIN:
pCurrentParams = &mainParams;
break;
return mainParams;
case CBaseChainParams::TESTNET:
pCurrentParams = &testNetParams;
break;
return testNetParams;
case CBaseChainParams::REGTEST:
pCurrentParams = &regTestParams;
break;
return regTestParams;
default:
assert(false && "Unimplemented network");
return;
return mainParams;
}
}
void SelectParams(CBaseChainParams::Network network) {
SelectBaseParams(network);
pCurrentParams = &Params(network);
}
bool SelectParamsFromCommandLine() {
if (!SelectBaseParamsFromCommandLine())
return false;

View file

@ -111,6 +111,9 @@ protected:
*/
const CChainParams &Params();
/** Return parameters for the given network. */
CChainParams &Params(CBaseChainParams::Network network);
/** Sets the params returned by Params() to those for the given network. */
void SelectParams(CBaseChainParams::Network network);

View file

@ -10,6 +10,7 @@
#include "optionsmodel.h"
#include "base58.h"
#include "chainparams.h"
#include "ui_interface.h"
#include "util.h"
#include "wallet.h"
@ -200,8 +201,11 @@ bool PaymentServer::ipcParseCommandLine(int argc, char* argv[])
{
CBitcoinAddress address(r.address.toStdString());
SelectParams(CBaseChainParams::MAIN);
if (!address.IsValid())
if (address.IsValid(Params(CBaseChainParams::MAIN)))
{
SelectParams(CBaseChainParams::MAIN);
}
else if (address.IsValid(Params(CBaseChainParams::TESTNET)))
{
SelectParams(CBaseChainParams::TESTNET);
}