Bitcoin ABC  0.28.12
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 
16 #ifdef HAVE_BUILD_INFO
17 #include <obj/build.h>
18 // The <obj/build.h>, which is generated by the build environment
19 // (share/genbuild.sh), could contain only one line of the following:
20 // - "#define BUILD_GIT_TAG ...", if the top commit is tagged
21 // - "#define BUILD_GIT_COMMIT ...", if the top commit is not tagged
22 // - "// No build information available", if proper git information is not
23 // available
24 #endif
25 
28 
29 #ifdef BUILD_GIT_TAG
30 #define BUILD_DESC BUILD_GIT_TAG
31 #define BUILD_SUFFIX ""
32 #else
33 #define BUILD_DESC \
34  "v" STRINGIZE(CLIENT_VERSION_MAJOR) "." STRINGIZE( \
35  CLIENT_VERSION_MINOR) "." STRINGIZE(CLIENT_VERSION_REVISION)
36 #ifdef BUILD_GIT_COMMIT
37 #define BUILD_SUFFIX "-" BUILD_GIT_COMMIT
38 #elif defined(GIT_COMMIT_ID)
39 #define BUILD_SUFFIX "-g" GIT_COMMIT_ID
40 #else
41 #define BUILD_SUFFIX "-unk"
42 #endif
43 #endif
44 
46 
47 std::string FormatVersion(int nVersion) {
48  if (nVersion % 100 == 0) {
49  return strprintf("%d.%d.%d", nVersion / 1000000,
50  (nVersion / 10000) % 100, (nVersion / 100) % 100);
51  } else {
52  return strprintf("%d.%d.%d.%d", nVersion / 1000000,
53  (nVersion / 10000) % 100, (nVersion / 100) % 100,
54  nVersion % 100);
55  }
56 }
57 
58 std::string FormatFullVersion() {
59  return CLIENT_BUILD;
60 }
61 
66 std::string FormatUserAgent(const std::string &name, const std::string &version,
67  const std::vector<std::string> &comments) {
68  std::ostringstream ss;
69  ss << "/";
70  ss << name << ":" << version;
71  if (!comments.empty()) {
72  std::vector<std::string>::const_iterator it(comments.begin());
73  ss << "(" << *it;
74  for (++it; it != comments.end(); ++it) {
75  ss << "; " << *it;
76  }
77  ss << ")";
78  }
79  ss << "/";
80  return ss.str();
81 }
const std::string CLIENT_NAME("Bitcoin ABC")
Name of client reported in the 'version' message.
#define BUILD_SUFFIX
#define BUILD_DESC
git will put "#define GIT_COMMIT_ID ..." on the next line inside archives.
std::string FormatVersion(int nVersion)
std::string FormatFullVersion()
const std::string CLIENT_BUILD(BUILD_DESC BUILD_SUFFIX)
std::string FormatUserAgent(const std::string &name, const std::string &version, const std::vector< std::string > &comments)
Format the subversion field according to BIP 14 spec.
const char * name
Definition: rest.cpp:48
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1202