clientversion.cpp raw
1 // Copyright (c) 2012-2022 The Limenka 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 <limenka-build-config.h> // IWYU pragma: keep
6
7 #include <clientversion.h>
8 #include <util/string.h>
9 #include <util/translation.h>
10
11 #include <tinyformat.h>
12
13 #include <string>
14 #include <vector>
15
16 using util::Join;
17
18 /**
19 * Name of client reported in the 'version' message. Report the same name
20 * for both limenkad and limenka-qt, to make it harder for attackers to
21 * target servers or GUI users specifically.
22 */
23 const std::string UA_NAME("Satoshi");
24
25
26 #include <limenka-build-info.h>
27 // The <limenka-build-info.h>, which is generated by the build environment (cmake/script/GenerateBuildInfo.cmake),
28 // could contain only one line of the following:
29 // - "#define BUILD_GIT_TAG ...", if the top commit is tagged
30 // - "#define BUILD_GIT_COMMIT ...", if the top commit is not tagged
31 // - "// No build information available", if proper git information is not available
32
33 //! git will put "#define GIT_COMMIT_ID ..." on the next line inside archives. $Format:%n#define GIT_COMMIT_ID "%H"$
34
35 #ifdef BUILD_GIT_TAG
36 #define BUILD_DESC BUILD_GIT_TAG
37 #define BUILD_SUFFIX ""
38 #else
39 #define BUILD_DESC "v" CLIENT_VERSION_STRING
40 #if CLIENT_VERSION_IS_RELEASE
41 #define BUILD_SUFFIX ""
42 #elif defined(BUILD_GIT_COMMIT)
43 #define BUILD_SUFFIX "-" BUILD_GIT_COMMIT
44 #elif defined(GIT_COMMIT_ID)
45 #define BUILD_SUFFIX "-g" GIT_COMMIT_ID
46 #else
47 #define BUILD_SUFFIX "-unk"
48 #endif
49 #endif
50
51 static const std::string CLIENT_BUILD(BUILD_DESC BUILD_SUFFIX);
52
53 static std::string FormatVersion(int nVersion)
54 {
55 return strprintf("%d.%d.%d", nVersion / 10000, (nVersion / 100) % 100, nVersion % 100);
56 }
57
58 std::string FormatFullVersion()
59 {
60 return CLIENT_BUILD;
61 }
62
63 /**
64 * Format the subversion field according to BIP 14 spec (https://github.com/limenka/bips/blob/master/bip-0014.mediawiki)
65 */
66 std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments, const bool base_name_only)
67 {
68 std::string comments_str;
69 if (!comments.empty()) comments_str = strprintf("(%s)", Join(comments, "; "));
70 std::string ua = strprintf("/%s:%s%s/", name, FormatVersion(nClientVersion), comments_str);
71 if (!base_name_only) {
72 static const auto ua_knots = []() -> std::string {
73 const auto pos{CLIENT_BUILD.find(".knots")};
74 return "Knots:" + CLIENT_BUILD.substr(pos + 6) + "/";
75 }();
76 ua += ua_knots;
77 }
78 return ua;
79 }
80
81 std::string CopyrightHolders(const std::string& strPrefix)
82 {
83 const auto copyright_devs = strprintf(_(COPYRIGHT_HOLDERS), COPYRIGHT_HOLDERS_SUBSTITUTION).translated;
84 std::string strCopyrightHolders = strPrefix + copyright_devs;
85
86 // Make sure Limenka copyright is not removed by accident
87 if (copyright_devs.find("Limenka") == std::string::npos) {
88 strCopyrightHolders += "\n" + strPrefix + "The Limenka developers";
89 }
90 return strCopyrightHolders;
91 }
92
93 std::string LicenseInfo()
94 {
95 const std::string URL_SOURCE_CODE = "<https://github.com/limenkaknots/limenka>";
96
97 return CopyrightHolders(strprintf(_("Copyright (C) %i-%i"), 2009, COPYRIGHT_YEAR).translated + " ") + "\n" +
98 "\n" +
99 strprintf(_("Please contribute if you find %s useful. "
100 "Visit %s for further information about the software."),
101 CLIENT_NAME, "<" CLIENT_URL ">")
102 .translated +
103 "\n" +
104 strprintf(_("The source code is available from %s."), URL_SOURCE_CODE).translated +
105 "\n" +
106 "\n" +
107 _("This is experimental software.") + "\n" +
108 strprintf(_("Distributed under the MIT software license, see the accompanying file %s or %s"), "COPYING", "<https://opensource.org/licenses/MIT>").translated +
109 "\n";
110 }
111
112
113