Skip to content

Commit

Permalink
refactor: separate clientversion from version
Browse files Browse the repository at this point in the history
  • Loading branch information
div72 committed Oct 23, 2021
1 parent 8b77857 commit a5de7c9
Show file tree
Hide file tree
Showing 22 changed files with 140 additions and 185 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
src/version.cpp export-subst
src/clientversion.cpp export-subst

# Auto detect text files and perform LF normalization
* text=auto
Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ nobase_icons_DATA = $(DIST_ICONS)
endif

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

$(BITCOIN_WIN_INSTALLER): all-recursive
$(MKDIR_P) $(top_builddir)/release
Expand Down
5 changes: 3 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ GRIDCOIN_CORE_H = \
chainparams.h \
chainparamsbase.h \
checkpoints.h \
clientversion.h \
compat.h \
compat/assumptions.h \
compat/byteswap.h \
Expand Down Expand Up @@ -203,6 +204,7 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \
chainparams.cpp \
chainparamsbase.cpp \
checkpoints.cpp \
clientversion.cpp \
consensus/merkle.cpp \
consensus/tx_verify.cpp \
crypter.cpp \
Expand Down Expand Up @@ -282,7 +284,6 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \
util/time.cpp \
util.cpp \
validation.cpp \
version.cpp \
wallet/db.cpp \
wallet/rpcdump.cpp \
wallet/rpcwallet.cpp \
Expand All @@ -294,7 +295,7 @@ obj/build.h: FORCE
@$(MKDIR_P) $(builddir)/obj
@$(top_srcdir)/share/genbuild.sh "$(abs_top_builddir)/src/obj/build.h" \
"$(abs_top_srcdir)"
libgridcoin_util_a-version.$(OBJEXT): obj/build.h
libgridcoin_util_a-clientversion.$(OBJEXT): obj/build.h

# util: shared between all executables.
# This library *must* be included to make sure that the glibc
Expand Down
2 changes: 1 addition & 1 deletion src/addrdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <addrman.h>
#include <chainparams.h>
// #include <clientversion.h>
#include <clientversion.h>
#include <hash.h>
// #include <random.h>
// #include <streams.h>
Expand Down
1 change: 1 addition & 0 deletions src/alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "alert.h"
#include "chainparams.h"
#include "clientversion.h"
#include "key.h"
#include "net.h"
#include "streams.h"
Expand Down
75 changes: 75 additions & 0 deletions src/clientversion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (c) 2012-2020 The Bitcoin Core developers
// Copyright (c) 2021 The Gridcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <clientversion.h>

#include <tinyformat.h>


/**
* Name of client reported in the 'version' message. Report the same name
* for both gridcoinresearchd and gridcoinresearch-qt, to make it harder for attackers to
* target servers or GUI users specifically.
*/
const std::string CLIENT_NAME("Halford");


#ifdef HAVE_BUILD_INFO
#include "build.h"
// The <obj/build.h>, which is generated by the build environment (share/genbuild.sh),
// could contain only one line of the following:
// - "#define BUILD_GIT_TAG ...", if the top commit is tagged
// - "#define BUILD_GIT_COMMIT ...", if the top commit is not tagged
// - "// No build information available", if proper git information is not available
#endif

//! git will put "#define GIT_COMMIT_ID ..." on the next line inside archives. $Format:%n#define GIT_COMMIT_ID "%H"$

#ifdef BUILD_GIT_TAG
#define BUILD_DESC BUILD_GIT_TAG
#define BUILD_SUFFIX ""
#else
#define BUILD_DESC "v" PACKAGE_VERSION
#if CLIENT_VERSION_IS_RELEASE
#define BUILD_SUFFIX ""
#elif defined(BUILD_GIT_COMMIT)
#define BUILD_SUFFIX "-" BUILD_GIT_COMMIT
#elif defined(GIT_COMMIT_ID)
#define BUILD_SUFFIX "-g" GIT_COMMIT_ID
#else
#define BUILD_SUFFIX "-unk"
#endif
#endif

static std::string FormatVersion(int nVersion)
{
return strprintf("%d.%d.%d", nVersion / 10000, (nVersion / 100) % 100, nVersion % 100);
}

std::string FormatFullVersion()
{
static const std::string CLIENT_BUILD(BUILD_DESC BUILD_SUFFIX);
return CLIENT_BUILD;
}

/**
* Format the subversion field according to BIP 14 spec (https://github.com/bitcoin/bips/blob/master/bip-0014.mediawiki)
*/
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments)
{
std::ostringstream ss;
ss << "/";
ss << name << ":" << FormatVersion(nClientVersion);
if (!comments.empty())
{
std::vector<std::string>::const_iterator it(comments.begin());
ss << "(" << *it;
for(++it; it != comments.end(); ++it)
ss << "; " << *it;
ss << ")";
}
ss << "/";
return ss.str();
}
47 changes: 47 additions & 0 deletions src/clientversion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2009-2020 The Bitcoin Core developers
// Copyright (c) 2021 The Gridcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or https://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_CLIENTVERSION_H
#define BITCOIN_CLIENTVERSION_H

#include <util/macros.h>

#if defined(HAVE_CONFIG_H)
#include <config/gridcoin-config.h>
#endif //HAVE_CONFIG_H

// Check that required client information is defined
#if !defined(CLIENT_VERSION_MAJOR) || !defined(CLIENT_VERSION_MINOR) || !defined(CLIENT_VERSION_BUILD) || !defined(CLIENT_VERSION_IS_RELEASE) || !defined(COPYRIGHT_YEAR)
#error Client version information missing: version is not defined by gridcoin-config.h or in any other way
#endif

//! Copyright string used in Windows .rc files
#define COPYRIGHT_STR "2009-" STRINGIZE(COPYRIGHT_YEAR) " " COPYRIGHT_HOLDERS_FINAL

/**
* bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
* WINDRES_PREPROC is defined to indicate that its pre-processor is running.
* Anything other than a define should be guarded below.
*/

#if !defined(WINDRES_PREPROC)

#include <string>
#include <vector>

static const int CLIENT_VERSION =
10000 * CLIENT_VERSION_MAJOR
+ 100 * CLIENT_VERSION_MINOR
+ 1 * CLIENT_VERSION_BUILD;

extern const std::string CLIENT_NAME;


std::string FormatFullVersion();
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);

#endif // WINDRES_PREPROC

#endif // BITCOIN_CLIENTVERSION_H
3 changes: 1 addition & 2 deletions src/dbwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@

#include <map>

#include <boost/version.hpp>

#include <leveldb/env.h>
#include <leveldb/cache.h>
#include <leveldb/filter_policy.h>
#include <leveldb/helpers/memenv/memenv.h>

#include "chainparams.h"
#include "clientversion.h"
#include "gridcoin/staking/kernel.h"
#include "txdb.h"
#include "main.h"
Expand Down
1 change: 1 addition & 0 deletions src/dbwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#ifndef BITCOIN_DBWRAPPER_H
#define BITCOIN_DBWRAPPER_H

#include "clientversion.h"
#include "main.h"
#include "streams.h"

Expand Down
2 changes: 1 addition & 1 deletion src/gridcoinresearchd-res.rc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <windows.h> // needed for VERSIONINFO
#include "version.h" // holds the needed client version information
#include "clientversion.h" // holds the needed client version information

#define VER_PRODUCTVERSION CLIENT_VERSION_MAJOR,CLIENT_VERSION_MINOR,CLIENT_VERSION_REVISION,CLIENT_VERSION_BUILD
#define VER_PRODUCTVERSION_STR STRINGIZE(CLIENT_VERSION_MAJOR) "." STRINGIZE(CLIENT_VERSION_MINOR) "." STRINGIZE(CLIENT_VERSION_REVISION) "." STRINGIZE(CLIENT_VERSION_BUILD)
Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ void InitLogging()
#else
build_type = "release build";
#endif
LogPrintf(PACKAGE_NAME " version %s (%s - %s)", FormatFullVersion(), build_type, CLIENT_DATE);
LogPrintf(PACKAGE_NAME " version %s (%s)", FormatFullVersion(), build_type);
}


Expand Down
1 change: 1 addition & 0 deletions src/node/blockstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "chainparams.h"
#include "clientversion.h"
#include "main.h"
#include "protocol.h"
#include "serialize.h"
Expand Down
6 changes: 1 addition & 5 deletions src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "transactiontablemodel.h"

#include "alert.h"
#include "clientversion.h"
#include "main.h"
#include "gridcoin/scraper/fwd.h"
#include "gridcoin/staking/difficulty.h"
Expand Down Expand Up @@ -250,11 +251,6 @@ QString ClientModel::formatFullVersion() const
return QString::fromStdString(FormatFullVersion());
}

QString ClientModel::formatBuildDate() const
{
return QString::fromStdString(CLIENT_DATE);
}

QString ClientModel::clientName() const
{
return QString::fromStdString(CLIENT_NAME);
Expand Down
1 change: 0 additions & 1 deletion src/qt/clientmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class ClientModel : public QObject
QString getMinerWarnings() const;

QString formatFullVersion() const;
QString formatBuildDate() const;
QString clientName() const;
QString formatClientStartupTime() const;

Expand Down
23 changes: 0 additions & 23 deletions src/qt/forms/rpcconsole.ui
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,6 @@
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="buildDateLabel">
<property name="text">
<string>Build date</string>
</property>
</widget>
</item>
<item row="47" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
Expand Down Expand Up @@ -166,22 +159,6 @@
</property>
</widget>
</item>
<item row="8" column="2">
<widget class="QLabel" name="buildDate">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
</property>
<property name="text">
<string>N/A</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="45" column="2">
<widget class="QLabel" name="totalBlocks">
<property name="cursor">
Expand Down
2 changes: 1 addition & 1 deletion src/qt/res/gridcoinresearch.rc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ IDI_ICON1 ICON DISCARDABLE "icons/gridcoin.ico"
IDI_ICON2 ICON DISCARDABLE "icons/gridcoin_testnet.ico"

#include <windows.h> // needed for VERSIONINFO
#include "../../version.h" // holds the needed client version information
#include "../../clientversion.h" // holds the needed client version information

#define VER_PRODUCTVERSION CLIENT_VERSION_MAJOR,CLIENT_VERSION_MINOR,CLIENT_VERSION_REVISION,CLIENT_VERSION_BUILD
#define VER_PRODUCTVERSION_STR STRINGIZE(CLIENT_VERSION_MAJOR) "." STRINGIZE(CLIENT_VERSION_MINOR) "." STRINGIZE(CLIENT_VERSION_REVISION) "." STRINGIZE(CLIENT_VERSION_BUILD)
Expand Down
1 change: 0 additions & 1 deletion src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ void RPCConsole::setClientModel(ClientModel *model)

ui->clientVersion->setText(cvi);
ui->clientName->setText(model->clientName());
ui->buildDate->setText(model->formatBuildDate());
ui->startupTime->setText(model->formatClientStartupTime());

setNumConnections(model->getNumConnections());
Expand Down
34 changes: 0 additions & 34 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include <util/strencodings.h>
#include <util/string.h>

#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/predicate.hpp> // for startswith() and endswith()
#include <boost/date_time/posix_time/posix_time.hpp> //For day of year
#include <cmath>
#include <boost/lexical_cast.hpp>
Expand Down Expand Up @@ -485,25 +483,6 @@ void seed_insecure_rand(bool fDeterministic)
}
}

string FormatVersion(int nVersion)
{
if (nVersion%100 == 0)
return strprintf("%d.%d.%d", nVersion/1000000, (nVersion/10000)%100, (nVersion/100)%100);
else
return strprintf("%d.%d.%d.%d", nVersion/1000000, (nVersion/10000)%100, (nVersion/100)%100, nVersion%100);
}

#ifndef UPGRADERFLAG
// avoid including unnecessary files for standalone upgrader


string FormatFullVersion()
{
return CLIENT_BUILD;
}

#endif

double Round(double d, int place)
{
const double accuracy = std::pow(10, place);
Expand Down Expand Up @@ -553,19 +532,6 @@ std::vector<std::string> split(const std::string& s, const std::string& delim)
return elems;
}

// Format the subversion field according to BIP 14 spec (https://en.bitcoin.it/wiki/BIP_0014)
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments)
{
std::ostringstream ss;
ss << "/";
ss << name << ":" << FormatVersion(nClientVersion);

if (!comments.empty()) ss << "(" << boost::algorithm::join(comments, "; ") << ")";

ss << "/";
return ss.str();
}

void runCommand(std::string strCommand)
{
int nErr = ::system(strCommand.c_str());
Expand Down
Loading

0 comments on commit a5de7c9

Please sign in to comment.