aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoss Nicoll <jrn@jrn.me.uk>2014-08-02 19:54:57 +0100
committerRoss Nicoll <jrn@jrn.me.uk>2014-08-30 09:39:59 +0100
commite84843c0dbb9cb853b912c09858b01c5c9302b09 (patch)
treeda59bc29ef10f63bc53ccba2e392c4979f37d353 /src
parent9d26dc3b2973252cc4dbe0f46edb56bfcea1cb78 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/base58.cpp8
-rw-r--r--src/base58.h1
-rw-r--r--src/chainparams.cpp19
-rw-r--r--src/chainparams.h3
-rw-r--r--src/qt/paymentserver.cpp8
5 files changed, 26 insertions, 13 deletions
diff --git a/src/base58.cpp b/src/base58.cpp
index c9e91beef1..76f0404a18 100644
--- a/src/base58.cpp
+++ b/src/base58.cpp
@@ -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;
}
diff --git a/src/base58.h b/src/base58.h
index 70681f589a..0f11f7c6d3 100644
--- a/src/base58.h
+++ b/src/base58.h
@@ -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); }
diff --git a/src/chainparams.cpp b/src/chainparams.cpp
index f32d4ed235..84cfd11feb 100644
--- a/src/chainparams.cpp
+++ b/src/chainparams.cpp
@@ -220,24 +220,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;
diff --git a/src/chainparams.h b/src/chainparams.h
index 446256ba82..34aaf1fb47 100644
--- a/src/chainparams.h
+++ b/src/chainparams.h
@@ -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);
diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp
index a9f1566d62..3360dd36eb 100644
--- a/src/qt/paymentserver.cpp
+++ b/src/qt/paymentserver.cpp
@@ -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[])
{
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);
}