Bitcoin Core 22.99.0
P2P Digital Currency
clientversion.cpp
Go to the documentation of this file.
1// Copyright (c) 2012-2020 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
9
15const std::string CLIENT_NAME("Satoshi");
16
17
18#ifdef HAVE_BUILD_INFO
19#include <obj/build.h>
20// The <obj/build.h>, which is generated by the build environment (share/genbuild.sh),
21// could contain only one line of the following:
22// - "#define BUILD_GIT_TAG ...", if the top commit is tagged
23// - "#define BUILD_GIT_COMMIT ...", if the top commit is not tagged
24// - "// No build information available", if proper git information is not available
25#endif
26
28
29#ifdef BUILD_GIT_TAG
30 #define BUILD_DESC BUILD_GIT_TAG
31 #define BUILD_SUFFIX ""
32#else
33 #define BUILD_DESC "v" PACKAGE_VERSION
34 #if CLIENT_VERSION_IS_RELEASE
35 #define BUILD_SUFFIX ""
36 #elif defined(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
45static std::string FormatVersion(int nVersion)
46{
47 return strprintf("%d.%d.%d", nVersion / 10000, (nVersion / 100) % 100, nVersion % 100);
48}
49
50std::string FormatFullVersion()
51{
52 static const std::string CLIENT_BUILD(BUILD_DESC BUILD_SUFFIX);
53 return CLIENT_BUILD;
54}
55
59std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments)
60{
61 std::ostringstream ss;
62 ss << "/";
63 ss << name << ":" << FormatVersion(nClientVersion);
64 if (!comments.empty())
65 {
66 std::vector<std::string>::const_iterator it(comments.begin());
67 ss << "(" << *it;
68 for(++it; it != comments.end(); ++it)
69 ss << "; " << *it;
70 ss << ")";
71 }
72 ss << "/";
73 return ss.str();
74}
const std::string CLIENT_NAME("Satoshi")
Name of client reported in the 'version' message.
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()
const char * name
Definition: rest.cpp:43
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1164