Bitcoin Core  26.99.0
P2P Digital Currency
clientversion.cpp
Go to the documentation of this file.
1 // Copyright (c) 2012-2022 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <clientversion.h>
6 #include <util/translation.h>
7 
8 #include <tinyformat.h>
9 
10 #include <sstream>
11 #include <string>
12 #include <vector>
13 
19 const std::string CLIENT_NAME("Satoshi");
20 
21 
22 #ifdef HAVE_BUILD_INFO
23 #include <obj/build.h>
24 // The <obj/build.h>, which is generated by the build environment (share/genbuild.sh),
25 // could contain only one line of the following:
26 // - "#define BUILD_GIT_TAG ...", if the top commit is tagged
27 // - "#define BUILD_GIT_COMMIT ...", if the top commit is not tagged
28 // - "// No build information available", if proper git information is not available
29 #endif
30 
32 
33 #ifdef BUILD_GIT_TAG
34  #define BUILD_DESC BUILD_GIT_TAG
35  #define BUILD_SUFFIX ""
36 #else
37  #define BUILD_DESC "v" PACKAGE_VERSION
38  #if CLIENT_VERSION_IS_RELEASE
39  #define BUILD_SUFFIX ""
40  #elif defined(BUILD_GIT_COMMIT)
41  #define BUILD_SUFFIX "-" BUILD_GIT_COMMIT
42  #elif defined(GIT_COMMIT_ID)
43  #define BUILD_SUFFIX "-g" GIT_COMMIT_ID
44  #else
45  #define BUILD_SUFFIX "-unk"
46  #endif
47 #endif
48 
49 static std::string FormatVersion(int nVersion)
50 {
51  return strprintf("%d.%d.%d", nVersion / 10000, (nVersion / 100) % 100, nVersion % 100);
52 }
53 
54 std::string FormatFullVersion()
55 {
56  static const std::string CLIENT_BUILD(BUILD_DESC BUILD_SUFFIX);
57  return CLIENT_BUILD;
58 }
59 
63 std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments)
64 {
65  std::ostringstream ss;
66  ss << "/";
67  ss << name << ":" << FormatVersion(nClientVersion);
68  if (!comments.empty())
69  {
70  std::vector<std::string>::const_iterator it(comments.begin());
71  ss << "(" << *it;
72  for(++it; it != comments.end(); ++it)
73  ss << "; " << *it;
74  ss << ")";
75  }
76  ss << "/";
77  return ss.str();
78 }
79 
80 std::string CopyrightHolders(const std::string& strPrefix)
81 {
82  const auto copyright_devs = strprintf(_(COPYRIGHT_HOLDERS).translated, COPYRIGHT_HOLDERS_SUBSTITUTION);
83  std::string strCopyrightHolders = strPrefix + copyright_devs;
84 
85  // Make sure Bitcoin Core copyright is not removed by accident
86  if (copyright_devs.find("Bitcoin Core") == std::string::npos) {
87  strCopyrightHolders += "\n" + strPrefix + "The Bitcoin Core developers";
88  }
89  return strCopyrightHolders;
90 }
91 
92 std::string LicenseInfo()
93 {
94  const std::string URL_SOURCE_CODE = "<https://github.com/bitcoin/bitcoin>";
95 
96  return CopyrightHolders(strprintf(_("Copyright (C) %i-%i").translated, 2009, COPYRIGHT_YEAR) + " ") + "\n" +
97  "\n" +
98  strprintf(_("Please contribute if you find %s useful. "
99  "Visit %s for further information about the software.").translated, PACKAGE_NAME, "<" PACKAGE_URL ">") +
100  "\n" +
101  strprintf(_("The source code is available from %s.").translated, URL_SOURCE_CODE) +
102  "\n" +
103  "\n" +
104  _("This is experimental software.").translated + "\n" +
105  strprintf(_("Distributed under the MIT software license, see the accompanying file %s or %s").translated, "COPYING", "<https://opensource.org/licenses/MIT>") +
106  "\n";
107 }
#define PACKAGE_NAME
#define COPYRIGHT_YEAR
#define PACKAGE_URL
#define COPYRIGHT_HOLDERS_SUBSTITUTION
#define COPYRIGHT_HOLDERS
const std::string CLIENT_NAME("Satoshi")
Name of client reported in the 'version' message.
std::string CopyrightHolders(const std::string &strPrefix)
std::string FormatSubVersion(const std::string &name, int nClientVersion, const std::vector< std::string > &comments)
Format the subversion field according to BIP 14 spec (https://github.com/bitcoin/bips/blob/master/bip...
#define BUILD_SUFFIX
#define BUILD_DESC
git will put "#define GIT_COMMIT_ID ..." on the next line inside archives.
static std::string FormatVersion(int nVersion)
std::string FormatFullVersion()
std::string LicenseInfo()
Returns licensing information (for -version)
const char * name
Definition: rest.cpp:45
std::string translated
Definition: translation.h:20
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1162
bilingual_str _(const char *psz)
Translation function.
Definition: translation.h:74