Skip to content

Commit

Permalink
rpc: implement getgeneralinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
brakmic committed Jan 18, 2020
1 parent a654626 commit b9683a5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/rpc/misc.cpp
Expand Up @@ -14,6 +14,8 @@
#include <util/strencodings.h>
#include <util/system.h>
#include <util/validation.h>
#include <clientversion.h>
#include <net.h>

#include <stdint.h>
#include <tuple>
Expand Down Expand Up @@ -449,6 +451,36 @@ static UniValue getmemoryinfo(const JSONRPCRequest& request)
}
}

static UniValue getgeneralinfo(const JSONRPCRequest& request)
{
RPCHelpMan{"getgeneralinfo",
"\nReturns data about the bitcoin daemon.\n",
{},
RPCResult{
" {\n"
" \"clientversion\": \"string\", (string) Client version\n"
" \"useragent\":\"string\", (string) Client name\n"
" \"datadir\":\"path\", (string) Data directory path\n"
" \"blocksdir\":\"path\", (string) Blocks directory path\n"
" \"startuptime\":\"datetime\", (string) Startup time\n"
" }\n"
},
RPCExamples{
HelpExampleCli("getgeneralinfo", "")
+ HelpExampleRpc("getgeneralinfo", "")
},
}.Check(request);

UniValue obj(UniValue::VOBJ);
obj.pushKV("clientversion", FormatFullVersion());
obj.pushKV("useragent", strSubVersion);
obj.pushKV("datadir", GetDataDir().string());
obj.pushKV("blocksdir", GetBlocksDir().string());
obj.pushKV("startuptime", FormatISO8601DateTime(GetStartupTime()));
return obj;

}

static void EnableOrDisableLogCategories(UniValue cats, bool enable) {
cats = cats.get_array();
for (unsigned int i = 0; i < cats.size(); ++i) {
Expand Down Expand Up @@ -560,6 +592,7 @@ static const CRPCCommand commands[] =
{ // category name actor (function) argNames
// --------------------- ------------------------ ----------------------- ----------
{ "control", "getmemoryinfo", &getmemoryinfo, {"mode"} },
{ "control", "getgeneralinfo", &getgeneralinfo, {} },
{ "control", "logging", &logging, {"include", "exclude"}},
{ "util", "validateaddress", &validateaddress, {"address"} },
{ "util", "createmultisig", &createmultisig, {"nrequired","keys","address_type"} },
Expand Down
28 changes: 28 additions & 0 deletions test/functional/rpc_getgeneralinfo.py
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
# Copyright (c) 2020 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test the getgeneralinfo RPC."""

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, try_rpc

class GetGeneralInfoTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = False
self.num_nodes = 1

def skip_test_if_missing_module(self):
self.skip_if_no_cli()

def run_test(self):
"""Test getgeneralinfo."""
"""check if 'getgeneralinfo' is callable"""
try_rpc(None, None, self.nodes[0].getgeneralinfo, None, None)
"""check if 'getgeneralinfo' is idempotent (multiple requests return same data)"""
json1 = self.nodes[0].getgeneralinfo()
json2 = self.nodes[0].getgeneralinfo()
assert_equal(json1, json2)

if __name__ == '__main__':
GetGeneralInfoTest().main()
1 change: 1 addition & 0 deletions test/functional/test_runner.py
Expand Up @@ -213,6 +213,7 @@
'feature_blocksdir.py',
'feature_config_args.py',
'rpc_getaddressinfo_labels_purpose_deprecation.py',
'rpc_getgeneralinfo.py',
'rpc_help.py',
'feature_help.py',
'feature_shutdown.py',
Expand Down

0 comments on commit b9683a5

Please sign in to comment.