Bitcoin ABC  0.22.13
P2P Digital Currency
clientversion.cpp
Go to the documentation of this file.
1 // Copyright (c) 2012-2016 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 
7 #include <tinyformat.h>
8 
14 const std::string CLIENT_NAME("Bitcoin ABC");
15 
19 #define CLIENT_VERSION_SUFFIX ""
20 
38 #ifdef HAVE_BUILD_INFO
40 #include <obj/build.h>
41 #endif
42 
45 #ifdef GIT_ARCHIVE
46 #define GIT_COMMIT_ID "$Format:%h$"
47 #define GIT_COMMIT_DATE "$Format:%cD$"
48 #endif
49 
50 #define BUILD_DESC_WITH_SUFFIX(maj, min, rev, suffix) \
51  "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE( \
52  rev) "-" DO_STRINGIZE(suffix)
53 
54 #define BUILD_DESC_FROM_COMMIT(maj, min, rev, commit) \
55  "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE( \
56  rev) "-g" commit
57 
58 #define BUILD_DESC_FROM_UNKNOWN(maj, min, rev) \
59  "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "-unk"
60 
61 #ifndef BUILD_DESC
62 #ifdef BUILD_SUFFIX
63 #define BUILD_DESC \
64  BUILD_DESC_WITH_SUFFIX(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, \
65  CLIENT_VERSION_REVISION, BUILD_SUFFIX)
66 
67 #elif defined(GIT_COMMIT_ID)
68 #define BUILD_DESC \
69  BUILD_DESC_FROM_COMMIT(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, \
70  CLIENT_VERSION_REVISION, GIT_COMMIT_ID)
71 
72 #else
73 #define BUILD_DESC \
74  BUILD_DESC_FROM_UNKNOWN(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, \
75  CLIENT_VERSION_REVISION)
76 #endif
77 #endif
78 
80 
81 static std::string FormatVersion(int nVersion) {
82  if (nVersion % 100 == 0) {
83  return strprintf("%d.%d.%d", nVersion / 1000000,
84  (nVersion / 10000) % 100, (nVersion / 100) % 100);
85  } else {
86  return strprintf("%d.%d.%d.%d", nVersion / 1000000,
87  (nVersion / 10000) % 100, (nVersion / 100) % 100,
88  nVersion % 100);
89  }
90 }
91 
92 std::string FormatFullVersion() {
93  return CLIENT_BUILD;
94 }
95 
100 std::string FormatSubVersion(const std::string &name, int nClientVersion,
101  const std::vector<std::string> &comments) {
102  std::ostringstream ss;
103  ss << "/";
104  ss << name << ":" << FormatVersion(nClientVersion);
105  if (!comments.empty()) {
106  std::vector<std::string>::const_iterator it(comments.begin());
107  ss << "(" << *it;
108  for (++it; it != comments.end(); ++it) {
109  ss << "; " << *it;
110  }
111  ss << ")";
112  }
113  ss << "/";
114  return ss.str();
115 }
const std::string CLIENT_BUILD(BUILD_DESC CLIENT_VERSION_SUFFIX)
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1201
#define CLIENT_VERSION_SUFFIX
Client version number.
const std::string CLIENT_NAME("Bitcoin ABC")
Name of client reported in the &#39;version&#39; message.
const char * name
Definition: rest.cpp:43
std::string FormatFullVersion()
static std::string FormatVersion(int nVersion)
#define BUILD_DESC
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...