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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 75 additions & 0 deletions
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

Lines changed: 47 additions & 0 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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)

0 commit comments

Comments
 (0)