|
| 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 | +} |
0 commit comments