1 // Copyright (c) 2012-2014 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or https://www.opensource.org/licenses/mit-license.php .
5 #include "clientversion.h"
7 #include "tinyformat.h"
11 #include <boost/preprocessor/arithmetic/add.hpp>
12 #include <boost/preprocessor/arithmetic/sub.hpp>
13 #include <boost/preprocessor/comparison/equal.hpp>
14 #include <boost/preprocessor/comparison/less.hpp>
15 #include <boost/preprocessor/control/if.hpp>
18 * Name of client reported in the 'version' message. Report the same name
19 * for both bitcoind and bitcoin-core, to make it harder for attackers to
20 * target servers or GUI users specifically.
22 const std::string CLIENT_NAME("MagicBean");
25 * Client version number
27 #define CLIENT_VERSION_SUFFIX ""
31 * The following part of the code determines the CLIENT_BUILD variable.
32 * Several mechanisms are used for this:
33 * * first, if HAVE_BUILD_INFO is defined, include build.h, a file that is
34 * generated by the build environment, possibly containing the output
35 * of git-describe in a macro called BUILD_DESC
36 * * secondly, if this is an exported version of the code, GIT_ARCHIVE will
37 * be defined (automatically using the export-subst git attribute), and
38 * GIT_COMMIT will contain the commit id.
39 * * then, three options exist for determining CLIENT_BUILD:
40 * * if BUILD_DESC is defined, use that literally (output of git-describe)
41 * * if not, but GIT_COMMIT is defined, use v[maj].[min].[rev].[build]-g[commit]
42 * * otherwise, use v[maj].[min].[rev].[build]-unk
43 * finally CLIENT_VERSION_SUFFIX is added
46 //! First, include build.h if requested
47 #ifdef HAVE_BUILD_INFO
51 //! git will put "#define GIT_ARCHIVE 1" on the next line inside archives.
54 #define GIT_COMMIT_ID "a86845f3dc"
55 #define GIT_COMMIT_DATE "Wed, 21 Feb 2018 16:15:11 +0200"
58 #define RENDER_BETA_STRING(num) "-beta" DO_STRINGIZE(num)
59 #define RENDER_RC_STRING(num) "-rc" DO_STRINGIZE(num)
60 #define RENDER_DEV_STRING(num) "-" DO_STRINGIZE(num)
62 #define RENDER_BUILD(build) \
64 BOOST_PP_LESS(build, 25), \
65 RENDER_BETA_STRING(BOOST_PP_ADD(build, 1)), \
67 BOOST_PP_LESS(build, 50), \
68 RENDER_RC_STRING(BOOST_PP_SUB(build, 24)), \
70 BOOST_PP_EQUAL(build, 50), \
72 RENDER_DEV_STRING(BOOST_PP_SUB(build, 50)))))
74 #define BUILD_DESC_WITH_SUFFIX(maj, min, rev, build, suffix) \
75 "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) RENDER_BUILD(build) "-" DO_STRINGIZE(suffix)
77 #define BUILD_DESC_FROM_COMMIT(maj, min, rev, build, commit) \
78 "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) RENDER_BUILD(build) "-g" commit
80 #define BUILD_DESC_FROM_UNKNOWN(maj, min, rev, build) \
81 "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) RENDER_BUILD(build) "-unk"
85 #define BUILD_DESC BUILD_DESC_WITH_SUFFIX(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, BUILD_SUFFIX)
86 #elif defined(GIT_COMMIT_ID)
87 #define BUILD_DESC BUILD_DESC_FROM_COMMIT(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, GIT_COMMIT_ID)
89 #define BUILD_DESC BUILD_DESC_FROM_UNKNOWN(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD)
94 #ifdef GIT_COMMIT_DATE
95 #define BUILD_DATE GIT_COMMIT_DATE
97 #define BUILD_DATE __DATE__ ", " __TIME__
101 const std::string CLIENT_BUILD(BUILD_DESC CLIENT_VERSION_SUFFIX);
102 const std::string CLIENT_DATE(BUILD_DATE);
104 std::string FormatVersion(int nVersion)
106 if (nVersion % 100 < 25)
107 return strprintf("%d.%d.%d-beta%d", nVersion / 1000000, (nVersion / 10000) % 100, (nVersion / 100) % 100, (nVersion % 100)+1);
108 if (nVersion % 100 < 50)
109 return strprintf("%d.%d.%d-rc%d", nVersion / 1000000, (nVersion / 10000) % 100, (nVersion / 100) % 100, (nVersion % 100)-24);
110 else if (nVersion % 100 == 50)
111 return strprintf("%d.%d.%d", nVersion / 1000000, (nVersion / 10000) % 100, (nVersion / 100) % 100);
113 return strprintf("%d.%d.%d-%d", nVersion / 1000000, (nVersion / 10000) % 100, (nVersion / 100) % 100, (nVersion % 100)-50);
116 std::string FormatFullVersion()
122 * Format the subversion field according to BIP 14 spec (https://github.com/bitcoin/bips/blob/master/bip-0014.mediawiki)
124 std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments)
126 std::ostringstream ss;
128 ss << name << ":" << FormatVersion(nClientVersion);
129 if (!comments.empty())
131 std::vector<std::string>::const_iterator it(comments.begin());
133 for(++it; it != comments.end(); ++it)