Browse Source

Broken addresses on command line no longer trigger testnet.

When passing a bitcoin: URI on the command line, invalid addresses do not incorrectly send the
user to the test network.
0.10
Ross Nicoll 10 years ago
parent
commit
e84843c0db
  1. 8
      src/base58.cpp
  2. 1
      src/base58.h
  3. 19
      src/chainparams.cpp
  4. 3
      src/chainparams.h
  5. 6
      src/qt/paymentserver.cpp

8
src/base58.cpp

@ -215,9 +215,13 @@ bool CBitcoinAddress::Set(const CTxDestination &dest) { @@ -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;
}

1
src/base58.h

@ -104,6 +104,7 @@ public: @@ -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); }

19
src/chainparams.cpp

@ -220,22 +220,23 @@ const CChainParams &Params() { @@ -220,22 +220,23 @@ 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() {

3
src/chainparams.h

@ -111,6 +111,9 @@ protected: @@ -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);

6
src/qt/paymentserver.cpp

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

Loading…
Cancel
Save