Skip to content

Commit a5de7c9

Browse files
committed
refactor: separate clientversion from version
1 parent 8b77857 commit a5de7c9

22 files changed

+140
-185
lines changed

.gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
src/version.cpp export-subst
1+
src/clientversion.cpp export-subst
22

33
# Auto detect text files and perform LF normalization
44
* text=auto

Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ nobase_icons_DATA = $(DIST_ICONS)
6161
endif
6262

6363
dist-hook:
64-
-$(GIT) archive --format=tar HEAD -- src/version.cpp | $(AMTAR) -C $(top_distdir) -xf -
64+
-$(GIT) archive --format=tar HEAD -- src/clientversion.cpp | $(AMTAR) -C $(top_distdir) -xf -
6565

6666
$(BITCOIN_WIN_INSTALLER): all-recursive
6767
$(MKDIR_P) $(top_builddir)/release

src/Makefile.am

+3-2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ GRIDCOIN_CORE_H = \
7373
chainparams.h \
7474
chainparamsbase.h \
7575
checkpoints.h \
76+
clientversion.h \
7677
compat.h \
7778
compat/assumptions.h \
7879
compat/byteswap.h \
@@ -203,6 +204,7 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \
203204
chainparams.cpp \
204205
chainparamsbase.cpp \
205206
checkpoints.cpp \
207+
clientversion.cpp \
206208
consensus/merkle.cpp \
207209
consensus/tx_verify.cpp \
208210
crypter.cpp \
@@ -282,7 +284,6 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \
282284
util/time.cpp \
283285
util.cpp \
284286
validation.cpp \
285-
version.cpp \
286287
wallet/db.cpp \
287288
wallet/rpcdump.cpp \
288289
wallet/rpcwallet.cpp \
@@ -294,7 +295,7 @@ obj/build.h: FORCE
294295
@$(MKDIR_P) $(builddir)/obj
295296
@$(top_srcdir)/share/genbuild.sh "$(abs_top_builddir)/src/obj/build.h" \
296297
"$(abs_top_srcdir)"
297-
libgridcoin_util_a-version.$(OBJEXT): obj/build.h
298+
libgridcoin_util_a-clientversion.$(OBJEXT): obj/build.h
298299

299300
# util: shared between all executables.
300301
# This library *must* be included to make sure that the glibc

src/addrdb.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <addrman.h>
99
#include <chainparams.h>
10-
// #include <clientversion.h>
10+
#include <clientversion.h>
1111
#include <hash.h>
1212
// #include <random.h>
1313
// #include <streams.h>

src/alert.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "alert.h"
1212
#include "chainparams.h"
13+
#include "clientversion.h"
1314
#include "key.h"
1415
#include "net.h"
1516
#include "streams.h"

src/clientversion.cpp

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) 2012-2020 The Bitcoin Core developers
2+
// Copyright (c) 2021 The Gridcoin developers
3+
// Distributed under the MIT software license, see the accompanying
4+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
#include <clientversion.h>
7+
8+
#include <tinyformat.h>
9+
10+
11+
/**
12+
* Name of client reported in the 'version' message. Report the same name
13+
* for both gridcoinresearchd and gridcoinresearch-qt, to make it harder for attackers to
14+
* target servers or GUI users specifically.
15+
*/
16+
const std::string CLIENT_NAME("Halford");
17+
18+
19+
#ifdef HAVE_BUILD_INFO
20+
#include "build.h"
21+
// The <obj/build.h>, which is generated by the build environment (share/genbuild.sh),
22+
// could contain only one line of the following:
23+
// - "#define BUILD_GIT_TAG ...", if the top commit is tagged
24+
// - "#define BUILD_GIT_COMMIT ...", if the top commit is not tagged
25+
// - "// No build information available", if proper git information is not available
26+
#endif
27+
28+
//! git will put "#define GIT_COMMIT_ID ..." on the next line inside archives. $Format:%n#define GIT_COMMIT_ID "%H"$
29+
30+
#ifdef BUILD_GIT_TAG
31+
#define BUILD_DESC BUILD_GIT_TAG
32+
#define BUILD_SUFFIX ""
33+
#else
34+
#define BUILD_DESC "v" PACKAGE_VERSION
35+
#if CLIENT_VERSION_IS_RELEASE
36+
#define BUILD_SUFFIX ""
37+
#elif defined(BUILD_GIT_COMMIT)
38+
#define BUILD_SUFFIX "-" BUILD_GIT_COMMIT
39+
#elif defined(GIT_COMMIT_ID)
40+
#define BUILD_SUFFIX "-g" GIT_COMMIT_ID
41+
#else
42+
#define BUILD_SUFFIX "-unk"
43+
#endif
44+
#endif
45+
46+
static std::string FormatVersion(int nVersion)
47+
{
48+
return strprintf("%d.%d.%d", nVersion / 10000, (nVersion / 100) % 100, nVersion % 100);
49+
}
50+
51+
std::string FormatFullVersion()
52+
{
53+
static const std::string CLIENT_BUILD(BUILD_DESC BUILD_SUFFIX);
54+
return CLIENT_BUILD;
55+
}
56+
57+
/**
58+
* Format the subversion field according to BIP 14 spec (https://github.com/bitcoin/bips/blob/master/bip-0014.mediawiki)
59+
*/
60+
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments)
61+
{
62+
std::ostringstream ss;
63+
ss << "/";
64+
ss << name << ":" << FormatVersion(nClientVersion);
65+
if (!comments.empty())
66+
{
67+
std::vector<std::string>::const_iterator it(comments.begin());
68+
ss << "(" << *it;
69+
for(++it; it != comments.end(); ++it)
70+
ss << "; " << *it;
71+
ss << ")";
72+
}
73+
ss << "/";
74+
return ss.str();
75+
}

src/clientversion.h

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) 2009-2020 The Bitcoin Core developers
2+
// Copyright (c) 2021 The Gridcoin developers
3+
// Distributed under the MIT software license, see the accompanying
4+
// file COPYING or https://www.opensource.org/licenses/mit-license.php.
5+
6+
#ifndef BITCOIN_CLIENTVERSION_H
7+
#define BITCOIN_CLIENTVERSION_H
8+
9+
#include <util/macros.h>
10+
11+
#if defined(HAVE_CONFIG_H)
12+
#include <config/gridcoin-config.h>
13+
#endif //HAVE_CONFIG_H
14+
15+
// Check that required client information is defined
16+
#if !defined(CLIENT_VERSION_MAJOR) || !defined(CLIENT_VERSION_MINOR) || !defined(CLIENT_VERSION_BUILD) || !defined(CLIENT_VERSION_IS_RELEASE) || !defined(COPYRIGHT_YEAR)
17+
#error Client version information missing: version is not defined by gridcoin-config.h or in any other way
18+
#endif
19+
20+
//! Copyright string used in Windows .rc files
21+
#define COPYRIGHT_STR "2009-" STRINGIZE(COPYRIGHT_YEAR) " " COPYRIGHT_HOLDERS_FINAL
22+
23+
/**
24+
* bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
25+
* WINDRES_PREPROC is defined to indicate that its pre-processor is running.
26+
* Anything other than a define should be guarded below.
27+
*/
28+
29+
#if !defined(WINDRES_PREPROC)
30+
31+
#include <string>
32+
#include <vector>
33+
34+
static const int CLIENT_VERSION =
35+
10000 * CLIENT_VERSION_MAJOR
36+
+ 100 * CLIENT_VERSION_MINOR
37+
+ 1 * CLIENT_VERSION_BUILD;
38+
39+
extern const std::string CLIENT_NAME;
40+
41+
42+
std::string FormatFullVersion();
43+
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);
44+
45+
#endif // WINDRES_PREPROC
46+
47+
#endif // BITCOIN_CLIENTVERSION_H

src/dbwrapper.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55

66
#include <map>
77

8-
#include <boost/version.hpp>
9-
108
#include <leveldb/env.h>
119
#include <leveldb/cache.h>
1210
#include <leveldb/filter_policy.h>
1311
#include <leveldb/helpers/memenv/memenv.h>
1412

1513
#include "chainparams.h"
14+
#include "clientversion.h"
1615
#include "gridcoin/staking/kernel.h"
1716
#include "txdb.h"
1817
#include "main.h"

src/dbwrapper.h

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef BITCOIN_DBWRAPPER_H
77
#define BITCOIN_DBWRAPPER_H
88

9+
#include "clientversion.h"
910
#include "main.h"
1011
#include "streams.h"
1112

src/gridcoinresearchd-res.rc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <windows.h> // needed for VERSIONINFO
2-
#include "version.h" // holds the needed client version information
2+
#include "clientversion.h" // holds the needed client version information
33

44
#define VER_PRODUCTVERSION CLIENT_VERSION_MAJOR,CLIENT_VERSION_MINOR,CLIENT_VERSION_REVISION,CLIENT_VERSION_BUILD
55
#define VER_PRODUCTVERSION_STR STRINGIZE(CLIENT_VERSION_MAJOR) "." STRINGIZE(CLIENT_VERSION_MINOR) "." STRINGIZE(CLIENT_VERSION_REVISION) "." STRINGIZE(CLIENT_VERSION_BUILD)

src/init.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ void InitLogging()
711711
#else
712712
build_type = "release build";
713713
#endif
714-
LogPrintf(PACKAGE_NAME " version %s (%s - %s)", FormatFullVersion(), build_type, CLIENT_DATE);
714+
LogPrintf(PACKAGE_NAME " version %s (%s)", FormatFullVersion(), build_type);
715715
}
716716

717717

src/node/blockstorage.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

66
#include "chainparams.h"
7+
#include "clientversion.h"
78
#include "main.h"
89
#include "protocol.h"
910
#include "serialize.h"

src/qt/clientmodel.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "transactiontablemodel.h"
88

99
#include "alert.h"
10+
#include "clientversion.h"
1011
#include "main.h"
1112
#include "gridcoin/scraper/fwd.h"
1213
#include "gridcoin/staking/difficulty.h"
@@ -250,11 +251,6 @@ QString ClientModel::formatFullVersion() const
250251
return QString::fromStdString(FormatFullVersion());
251252
}
252253

253-
QString ClientModel::formatBuildDate() const
254-
{
255-
return QString::fromStdString(CLIENT_DATE);
256-
}
257-
258254
QString ClientModel::clientName() const
259255
{
260256
return QString::fromStdString(CLIENT_NAME);

src/qt/clientmodel.h

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class ClientModel : public QObject
5555
QString getMinerWarnings() const;
5656

5757
QString formatFullVersion() const;
58-
QString formatBuildDate() const;
5958
QString clientName() const;
6059
QString formatClientStartupTime() const;
6160

src/qt/forms/rpcconsole.ui

-23
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,6 @@
107107
</property>
108108
</widget>
109109
</item>
110-
<item row="8" column="0">
111-
<widget class="QLabel" name="buildDateLabel">
112-
<property name="text">
113-
<string>Build date</string>
114-
</property>
115-
</widget>
116-
</item>
117110
<item row="47" column="0">
118111
<spacer name="verticalSpacer_2">
119112
<property name="orientation">
@@ -166,22 +159,6 @@
166159
</property>
167160
</widget>
168161
</item>
169-
<item row="8" column="2">
170-
<widget class="QLabel" name="buildDate">
171-
<property name="cursor">
172-
<cursorShape>IBeamCursor</cursorShape>
173-
</property>
174-
<property name="text">
175-
<string>N/A</string>
176-
</property>
177-
<property name="textFormat">
178-
<enum>Qt::PlainText</enum>
179-
</property>
180-
<property name="textInteractionFlags">
181-
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
182-
</property>
183-
</widget>
184-
</item>
185162
<item row="45" column="2">
186163
<widget class="QLabel" name="totalBlocks">
187164
<property name="cursor">

src/qt/res/gridcoinresearch.rc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ IDI_ICON1 ICON DISCARDABLE "icons/gridcoin.ico"
22
IDI_ICON2 ICON DISCARDABLE "icons/gridcoin_testnet.ico"
33

44
#include <windows.h> // needed for VERSIONINFO
5-
#include "../../version.h" // holds the needed client version information
5+
#include "../../clientversion.h" // holds the needed client version information
66

77
#define VER_PRODUCTVERSION CLIENT_VERSION_MAJOR,CLIENT_VERSION_MINOR,CLIENT_VERSION_REVISION,CLIENT_VERSION_BUILD
88
#define VER_PRODUCTVERSION_STR STRINGIZE(CLIENT_VERSION_MAJOR) "." STRINGIZE(CLIENT_VERSION_MINOR) "." STRINGIZE(CLIENT_VERSION_REVISION) "." STRINGIZE(CLIENT_VERSION_BUILD)

src/qt/rpcconsole.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ void RPCConsole::setClientModel(ClientModel *model)
389389

390390
ui->clientVersion->setText(cvi);
391391
ui->clientName->setText(model->clientName());
392-
ui->buildDate->setText(model->formatBuildDate());
393392
ui->startupTime->setText(model->formatClientStartupTime());
394393

395394
setNumConnections(model->getNumConnections());

src/util.cpp

-34
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#include <util/strencodings.h>
1414
#include <util/string.h>
1515

16-
#include <boost/algorithm/string/join.hpp>
17-
#include <boost/algorithm/string/predicate.hpp> // for startswith() and endswith()
1816
#include <boost/date_time/posix_time/posix_time.hpp> //For day of year
1917
#include <cmath>
2018
#include <boost/lexical_cast.hpp>
@@ -485,25 +483,6 @@ void seed_insecure_rand(bool fDeterministic)
485483
}
486484
}
487485

488-
string FormatVersion(int nVersion)
489-
{
490-
if (nVersion%100 == 0)
491-
return strprintf("%d.%d.%d", nVersion/1000000, (nVersion/10000)%100, (nVersion/100)%100);
492-
else
493-
return strprintf("%d.%d.%d.%d", nVersion/1000000, (nVersion/10000)%100, (nVersion/100)%100, nVersion%100);
494-
}
495-
496-
#ifndef UPGRADERFLAG
497-
// avoid including unnecessary files for standalone upgrader
498-
499-
500-
string FormatFullVersion()
501-
{
502-
return CLIENT_BUILD;
503-
}
504-
505-
#endif
506-
507486
double Round(double d, int place)
508487
{
509488
const double accuracy = std::pow(10, place);
@@ -553,19 +532,6 @@ std::vector<std::string> split(const std::string& s, const std::string& delim)
553532
return elems;
554533
}
555534

556-
// Format the subversion field according to BIP 14 spec (https://en.bitcoin.it/wiki/BIP_0014)
557-
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments)
558-
{
559-
std::ostringstream ss;
560-
ss << "/";
561-
ss << name << ":" << FormatVersion(nClientVersion);
562-
563-
if (!comments.empty()) ss << "(" << boost::algorithm::join(comments, "; ") << ")";
564-
565-
ss << "/";
566-
return ss.str();
567-
}
568-
569535
void runCommand(std::string strCommand)
570536
{
571537
int nErr = ::system(strCommand.c_str());

0 commit comments

Comments
 (0)