Skip to content

Commit

Permalink
Add version suffix to getversioninfo (#1211)
Browse files Browse the repository at this point in the history
* Add version suffix to getversioninfo
  • Loading branch information
dcorral authored Apr 29, 2022
1 parent e92bcf9 commit 1600ae0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
32 changes: 13 additions & 19 deletions src/clientversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@ const std::string CLIENT_NAME("DeFiChain");
* * first, if HAVE_BUILD_INFO is defined, include build.h, a file that is
* generated by the build environment, possibly containing the output
* of git-describe in a macro called BUILD_DESC
* * secondly, if this is an exported version of the code, GIT_ARCHIVE will
* be defined (automatically using the export-subst git attribute), and
* GIT_COMMIT will contain the commit id.
* * then, three options exist for determining CLIENT_BUILD:
* * then, two options exist for determining CLIENT_BUILD:
* * if BUILD_DESC is defined, use that literally (output of git-describe)
* * if not, but GIT_COMMIT is defined, use v[maj].[min].[rev].[build]-g[commit]
* * otherwise, use v[maj].[min].[rev].[build]-unk
* * otherwise, use v[maj].[min].[rev].[build]-unknown
* finally CLIENT_VERSION_SUFFIX is added
*/

Expand All @@ -46,32 +42,25 @@ const std::string CLIENT_NAME("DeFiChain");
#define BUILD_SUFFIX release
#endif

//! git will put "#define GIT_ARCHIVE 1" on the next line inside archives. $Format:%n#define GIT_ARCHIVE 1$
#ifdef GIT_ARCHIVE
#define GIT_COMMIT_ID "$Format:%H$"
#define GIT_COMMIT_DATE "$Format:%cD$"
#endif

#define BUILD_DESC_WITH_SUFFIX(maj, min, rev, build, suffix) \
"v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-" DO_STRINGIZE(suffix)

#define BUILD_DESC_FROM_COMMIT(maj, min, rev, build, commit) \
"v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-g" commit

#define BUILD_DESC_FROM_UNKNOWN(maj, min, rev, build) \
"v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-unk"
"v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-unknown"
#define BUILD_SUFFIX_TAIL(suffix) \
DO_STRINGIZE(suffix)

#ifndef BUILD_DESC
#ifdef BUILD_SUFFIX
#define BUILD_DESC BUILD_DESC_WITH_SUFFIX(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, BUILD_SUFFIX)
#elif defined(GIT_COMMIT_ID)
#define BUILD_DESC BUILD_DESC_FROM_COMMIT(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, GIT_COMMIT_ID)
#define BUILD_DESC_SUFFIX BUILD_SUFFIX_TAIL(BUILD_SUFFIX)
#else
#define BUILD_DESC BUILD_DESC_FROM_UNKNOWN(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD)
#define BUILD_DESC_SUFFIX "unknown"
#endif
#endif

const std::string CLIENT_BUILD(BUILD_DESC CLIENT_VERSION_SUFFIX);
const std::string CLIENT_BUILD_SUFFIX(BUILD_DESC_SUFFIX CLIENT_VERSION_SUFFIX);

std::string FormatVersion(int nVersion)
{
Expand All @@ -86,6 +75,11 @@ std::string FormatVersionAndSuffix()
return CLIENT_BUILD;
}

std::string FormatVersionSuffixTail()
{
return CLIENT_BUILD_SUFFIX;
}

/**
* Format the subversion field according to BIP 14 spec (https://github.com/bitcoin/bips/blob/master/bip-0014.mediawiki)
*/
Expand Down
1 change: 1 addition & 0 deletions src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extern const std::string CLIENT_BUILD;

std::string FormatVersion(int nVersion);
std::string FormatVersionAndSuffix();
std::string FormatVersionSuffixTail();
std::string FormatUserAgentString(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);

#endif // WINDRES_PREPROC
Expand Down
24 changes: 12 additions & 12 deletions src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,15 +518,16 @@ static UniValue getversioninfo(const JSONRPCRequest& request){
{},
RPCResult{
"{\n"
" \"name\": DeFiChain (string) Node name\n"
" \"version\": \"xxxxx\", (string) Node version string\n"
" \"numericVersion\": xxxxx, (number) Node numeric version\n"
" \"fullVersion\": \"DefiChain:x.x.x\", (string) Full node version string including name and version\n"
" \"userAgent\": \"/DefiChain:x.x.x/\", (string) P2P user agent string (subversion string conforming to BIP-14)\n"
" \"protoVersion\": \"xxxxx\", (number) Operating protocol version\n"
" \"protoVersionMin\": \"xxxxx\", (number) Minimum protocol that's supported by the node\n"
" \"rpcVersion\": \"xxxxx\", (string) RPC version\n"
" \"rpcVersionMin\": \"xxxxx\", (string) Minimum RPC version supported\n"
" \"name\": DeFiChain (string) Node name\n"
" \"version\": \"xxxxx\", (string) Node version string\n"
" \"versionSuffix\": \"xxxxx\", (string) Version suffix\n"
" \"numericVersion\": xxxxx, (number) Node numeric version\n"
" \"fullVersion\": \"DefiChain:x.x.x-suffix\", (string) Full node version string including name and full version including suffix\n"
" \"userAgent\": \"/DefiChain:x.x.x/\", (string) P2P user agent string (subversion string conforming to BIP-14)\n"
" \"protoVersion\": \"xxxxx\", (number) Operating protocol version\n"
" \"protoVersionMin\": \"xxxxx\", (number) Minimum protocol that's supported by the node\n"
" \"rpcVersion\": \"xxxxx\", (string) RPC version\n"
" \"rpcVersionMin\": \"xxxxx\", (string) Minimum RPC version supported\n"
" \"spv\":\n"
" \"{\n"
" \"btc\":\n"
Expand All @@ -546,8 +547,6 @@ static UniValue getversioninfo(const JSONRPCRequest& request){

UniValue nodeInfoObj(UniValue::VOBJ);



UniValue btcInfoObj(UniValue::VOBJ);
btcInfoObj.pushKV("version", BR_PROTOCOL_VERSION);
btcInfoObj.pushKV("min", BR_MIN_PROTO_VERSION);
Expand All @@ -557,10 +556,11 @@ static UniValue getversioninfo(const JSONRPCRequest& request){
spvInfoObj.pushKV("btc", btcInfoObj);

std::ostringstream strFullVersion;
strFullVersion << CLIENT_NAME << ":" << FormatVersion(CLIENT_VERSION);
strFullVersion << CLIENT_NAME << ":" << FormatVersionAndSuffix();

nodeInfoObj.pushKV("name", CLIENT_NAME);
nodeInfoObj.pushKV("version", FormatVersion(CLIENT_VERSION));
nodeInfoObj.pushKV("versionSuffix", FormatVersionSuffixTail());
nodeInfoObj.pushKV("numericVersion", CLIENT_VERSION);
nodeInfoObj.pushKV("fullVersion",strFullVersion.str());
nodeInfoObj.pushKV("userAgent",strSubVersion);
Expand Down

0 comments on commit 1600ae0

Please sign in to comment.