Skip to content

Commit f5ae6c9

Browse files
author
Philip Kaufmann
committed
add NetworkIDString() to chainparams
- returns the BIP70 network string - use that new function in the core and GUI code and remove unused code and functions
1 parent 3f39b9d commit f5ae6c9

File tree

8 files changed

+14
-33
lines changed

8 files changed

+14
-33
lines changed

src/chainparams.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class CMainParams : public CChainParams {
9999
public:
100100
CMainParams() {
101101
networkID = CChainParams::MAIN;
102+
strNetworkID = "main";
102103
// The message start string is designed to be unlikely to occur in normal data.
103104
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
104105
// a large 4-byte int at any alignment.
@@ -189,6 +190,7 @@ class CTestNetParams : public CMainParams {
189190
public:
190191
CTestNetParams() {
191192
networkID = CChainParams::TESTNET;
193+
strNetworkID = "test";
192194
// The message start string is designed to be unlikely to occur in normal data.
193195
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
194196
// a large 4-byte int at any alignment.
@@ -240,6 +242,7 @@ class CRegTestParams : public CTestNetParams {
240242
public:
241243
CRegTestParams() {
242244
networkID = CChainParams::REGTEST;
245+
strNetworkID = "regtest";
243246
pchMessageStart[0] = 0xfa;
244247
pchMessageStart[1] = 0xbf;
245248
pchMessageStart[2] = 0xb5;

src/chainparams.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ class CChainParams
7979
* until nGenProcLimit blocks are generated */
8080
bool MineBlocksOnDemand() const { return fMineBlocksOnDemand; }
8181
Network NetworkID() const { return networkID; }
82+
/* Return the BIP70 network string (main, test or regtest) */
83+
std::string NetworkIDString() const { return strNetworkID; }
8284
const vector<CDNSSeedData>& DNSSeeds() const { return vSeeds; }
8385
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
8486
const vector<CAddress>& FixedSeeds() const { return vFixedSeeds; }
@@ -102,6 +104,7 @@ class CChainParams
102104
vector<CDNSSeedData> vSeeds;
103105
std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
104106
Network networkID;
107+
std::string strNetworkID;
105108
CBlock genesis;
106109
vector<CAddress> vFixedSeeds;
107110
bool fRequireRPCPassword;

src/qt/clientmodel.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,6 @@ void ClientModel::updateAlert(const QString &hash, int status)
142142
emit alertsChanged(getStatusBarWarnings());
143143
}
144144

145-
QString ClientModel::getNetworkName() const
146-
{
147-
QString netname(QString::fromStdString(Params().DataDir()));
148-
if(netname.isEmpty())
149-
netname = "main";
150-
return netname;
151-
}
152-
153145
bool ClientModel::inInitialBlockDownload() const
154146
{
155147
return IsInitialBlockDownload();

src/qt/clientmodel.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ class ClientModel : public QObject
5656
double getVerificationProgress() const;
5757
QDateTime getLastBlockDate() const;
5858

59-
//! Return network (main, testnet3, regtest)
60-
QString getNetworkName() const;
6159
//! Return true if core is doing initial block download
6260
bool inInitialBlockDownload() const;
6361
//! Return true if core is importing blocks

src/qt/paymentserver.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -490,17 +490,6 @@ bool PaymentServer::readPaymentRequest(const QString& filename, PaymentRequestPl
490490
return request.parse(data);
491491
}
492492

493-
std::string PaymentServer::mapNetworkIdToName(CChainParams::Network networkId)
494-
{
495-
if (networkId == CChainParams::MAIN)
496-
return "main";
497-
if (networkId == CChainParams::TESTNET)
498-
return "test";
499-
if (networkId == CChainParams::REGTEST)
500-
return "regtest";
501-
return "";
502-
}
503-
504493
bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoinsRecipient& recipient)
505494
{
506495
if (!optionsModel)
@@ -510,7 +499,7 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoins
510499
const payments::PaymentDetails& details = request.getDetails();
511500

512501
// Payment request network matches client network?
513-
if (details.network() != mapNetworkIdToName(Params().NetworkID()))
502+
if (details.network() != Params().NetworkIDString())
514503
{
515504
emit message(tr("Payment request rejected"), tr("Payment request network doesn't match client network."),
516505
CClientUIInterface::MSG_ERROR);

src/qt/paymentserver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ private slots:
118118

119119
private:
120120
static bool readPaymentRequest(const QString& filename, PaymentRequestPlus& request);
121-
std::string mapNetworkIdToName(CChainParams::Network networkId);
122121
bool processPaymentRequest(PaymentRequestPlus& request, SendCoinsRecipient& recipient);
123122
void fetchRequest(const QUrl& url);
124123

src/qt/rpcconsole.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ void RPCConsole::setClientModel(ClientModel *model)
316316
ui->buildDate->setText(model->formatBuildDate());
317317
ui->startupTime->setText(model->formatClientStartupTime());
318318

319-
ui->networkName->setText(model->getNetworkName());
319+
ui->networkName->setText(QString::fromStdString(Params().NetworkIDString()));
320320
}
321321
}
322322

src/rpcblockchain.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -451,14 +451,11 @@ Value getblockchaininfo(const Array& params, bool fHelp)
451451
);
452452

453453
Object obj;
454-
std::string chain = Params().DataDir();
455-
if(chain.empty())
456-
chain = "main";
457-
obj.push_back(Pair("chain", chain));
458-
obj.push_back(Pair("blocks", (int)chainActive.Height()));
459-
obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex()));
460-
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
461-
obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(chainActive.Tip())));
462-
obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex()));
454+
obj.push_back(Pair("chain", Params().NetworkIDString()));
455+
obj.push_back(Pair("blocks", (int)chainActive.Height()));
456+
obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex()));
457+
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
458+
obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(chainActive.Tip())));
459+
obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex()));
463460
return obj;
464461
}

0 commit comments

Comments
 (0)