mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-28 13:02:38 +02:00
Merge 17958 via rpc_getgeneralinfo
This commit is contained in:
commit
aa5abdea95
@ -4,6 +4,9 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <chainparams.h>
|
||||
#include <clientversion.h>
|
||||
#include <common/args.h>
|
||||
#include <common/system.h>
|
||||
#include <httpserver.h>
|
||||
#include <index/blockfilterindex.h>
|
||||
#include <index/coinstatsindex.h>
|
||||
@ -14,6 +17,7 @@
|
||||
#include <interfaces/ipc.h>
|
||||
#include <kernel/cs_main.h>
|
||||
#include <logging.h>
|
||||
#include <net.h>
|
||||
#include <node/context.h>
|
||||
#include <rpc/server.h>
|
||||
#include <rpc/server_util.h>
|
||||
@ -184,6 +188,40 @@ static RPCHelpMan getmemoryinfo()
|
||||
};
|
||||
}
|
||||
|
||||
static RPCHelpMan getgeneralinfo()
|
||||
{
|
||||
return RPCHelpMan{"getgeneralinfo",
|
||||
"Returns data about the bitcoin daemon.\n",
|
||||
{},
|
||||
RPCResult{
|
||||
RPCResult::Type::OBJ, "", "",
|
||||
{
|
||||
{RPCResult::Type::STR, "clientversion", "Client version"},
|
||||
{RPCResult::Type::STR, "useragent", "Client name"},
|
||||
{RPCResult::Type::STR, "datadir", "Data directory path"},
|
||||
{RPCResult::Type::STR, "blocksdir", "Blocks directory path"},
|
||||
{RPCResult::Type::NUM, "startuptime", "Startup time"},
|
||||
}
|
||||
},
|
||||
RPCExamples{
|
||||
HelpExampleCli("getgeneralinfo", "")
|
||||
+ HelpExampleRpc("getgeneralinfo", "")
|
||||
},
|
||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||
{
|
||||
const ArgsManager& args{EnsureAnyArgsman(request.context)};
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.pushKV("clientversion", FormatFullVersion());
|
||||
obj.pushKV("useragent", strSubVersion);
|
||||
obj.pushKV("datadir", fs::PathToString(args.GetDataDirNet()));
|
||||
obj.pushKV("blocksdir", fs::PathToString(args.GetBlocksDirPath()));
|
||||
obj.pushKV("startuptime", GetStartupTime());
|
||||
return obj;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
static void EnableOrDisableLogCategories(UniValue cats, bool enable) {
|
||||
cats = cats.get_array();
|
||||
for (unsigned int i = 0; i < cats.size(); ++i) {
|
||||
@ -397,6 +435,7 @@ void RegisterNodeRPCCommands(CRPCTable& t)
|
||||
{
|
||||
static const CRPCCommand commands[]{
|
||||
{"control", &getmemoryinfo},
|
||||
{"control", &getgeneralinfo},
|
||||
{"control", &logging},
|
||||
{"util", &getindexinfo},
|
||||
{"hidden", &setmocktime},
|
||||
|
@ -132,6 +132,7 @@ const std::vector<std::string> RPC_COMMANDS_SAFE_FOR_FUZZING{
|
||||
"getdeploymentinfo",
|
||||
"getdescriptorinfo",
|
||||
"getdifficulty",
|
||||
"getgeneralinfo",
|
||||
"getindexinfo",
|
||||
"getmemoryinfo",
|
||||
"getmempoolancestors",
|
||||
|
46
test/functional/rpc_getgeneralinfo.py
Executable file
46
test/functional/rpc_getgeneralinfo.py
Executable file
@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2020-2022 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."""
|
||||
|
||||
import os.path
|
||||
import time
|
||||
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import assert_equal
|
||||
|
||||
class GetGeneralInfoTest(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = False
|
||||
self.num_nodes = 1
|
||||
self.min_starttime = int(time.time())
|
||||
|
||||
def run_test(self):
|
||||
"""Test getgeneralinfo."""
|
||||
max_starttime = int(time.time()) + 1
|
||||
|
||||
"""Check if 'getgeneralinfo' is idempotent (multiple requests return same data)."""
|
||||
json1 = self.nodes[0].getgeneralinfo()
|
||||
json2 = self.nodes[0].getgeneralinfo()
|
||||
assert_equal(json1, json2)
|
||||
|
||||
"""Check 'getgeneralinfo' result is correct."""
|
||||
ver_search = f'version {json1["clientversion"]} ('
|
||||
with open(self.nodes[0].debug_log_path, encoding='utf-8') as dl:
|
||||
for line in dl:
|
||||
if line.find(ver_search) >= 0:
|
||||
break
|
||||
else:
|
||||
raise AssertionError(f"Failed to find clientversion '{json1['clientversion']}' in debug log")
|
||||
|
||||
assert_equal(json1['useragent'], self.nodes[0].getnetworkinfo()['subversion'])
|
||||
|
||||
net_datadir = str(self.nodes[0].chain_path)
|
||||
assert_equal(json1['datadir'], net_datadir)
|
||||
assert_equal(json1['blocksdir'], os.path.join(net_datadir, "blocks"))
|
||||
# startuptime is set before mocktime param is loaded
|
||||
assert json1['startuptime'] >= self.min_starttime and json1['startuptime'] <= max_starttime
|
||||
|
||||
if __name__ == '__main__':
|
||||
GetGeneralInfoTest().main()
|
@ -391,6 +391,7 @@ BASE_SCRIPTS = [
|
||||
'feature_settings.py',
|
||||
'rpc_getdescriptorinfo.py',
|
||||
'rpc_mempool_info.py',
|
||||
'rpc_getgeneralinfo.py',
|
||||
'rpc_help.py',
|
||||
'feature_dirsymlinks.py',
|
||||
'feature_help.py',
|
||||
|
Loading…
Reference in New Issue
Block a user