Skip to content

Commit fe03773

Browse files
Merge pull request #4399 from vijaydasmp/backport_v18_vijay_batch2
Backport v18 vijay batch2
2 parents 4dbe320 + 158b03e commit fe03773

12 files changed

+141
-12
lines changed

src/dash-cli.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <memory>
2121
#include <stdio.h>
22+
#include <tuple>
2223

2324
#include <event2/buffer.h>
2425
#include <event2/keyvalq_struct.h>
@@ -540,6 +541,10 @@ int main(int argc, char* argv[])
540541
RegisterPrettyTerminateHander();
541542
RegisterPrettySignalHandlers();
542543

544+
#ifdef WIN32
545+
util::WinCmdLineArgs winArgs;
546+
std::tie(argc, argv) = winArgs.get();
547+
#endif
543548
SetupEnvironment();
544549
if (!SetupNetworking()) {
545550
fprintf(stderr, "Error: Initializing networking failed\n");

src/dashd.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ int main(int argc, char* argv[])
199199
RegisterPrettyTerminateHander();
200200
RegisterPrettySignalHandlers();
201201

202+
#ifdef WIN32
203+
util::WinCmdLineArgs winArgs;
204+
std::tie(argc, argv) = winArgs.get();
205+
#endif
202206
SetupEnvironment();
203207

204208
// Connect dashd signal handlers

src/init.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,15 @@ void InitParameterInteraction()
11611161
// Warn if network-specific options (-addnode, -connect, etc) are
11621162
// specified in default section of config file, but not overridden
11631163
// on the command line or in this network's section of the config file.
1164-
gArgs.WarnForSectionOnlyArgs();
1164+
std::string network = gArgs.GetChainName();
1165+
for (const auto& arg : gArgs.GetUnsuitableSectionOnlyArgs()) {
1166+
InitWarning(strprintf(_("Config setting for %s only applied on %s network when in [%s] section."), arg, network, network));
1167+
}
1168+
1169+
// Warn if unrecognized section name are present in the config file.
1170+
for (const auto& section : gArgs.GetUnrecognizedSections()) {
1171+
InitWarning(strprintf(_("Section [%s] is not recognized."), section));
1172+
}
11651173
}
11661174

11671175
static std::string ResolveErrMsg(const char * const optname, const std::string& strBind)

src/qt/dash.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,10 @@ int main(int argc, char *argv[])
569569
RegisterPrettyTerminateHander();
570570
RegisterPrettySignalHandlers();
571571

572+
#ifdef WIN32
573+
util::WinCmdLineArgs winArgs;
574+
std::tie(argc, argv) = winArgs.get();
575+
#endif
572576
SetupEnvironment();
573577
util::ThreadRename("main");
574578

src/rpc/client.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
5353
{ "listreceivedbyaddress", 1, "addlocked" },
5454
{ "listreceivedbyaddress", 2, "include_empty" },
5555
{ "listreceivedbyaddress", 3, "include_watchonly" },
56-
{ "listreceivedbyaddress", 4, "address_filter" },
5756
{ "listreceivedbyaccount", 0, "minconf" },
5857
{ "listreceivedbyaccount", 1, "addlocked" },
5958
{ "listreceivedbyaccount", 2, "include_empty" },

src/util/system.cpp

+68-7
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
#include <codecvt>
6767

6868
#include <io.h> /* for _commit */
69+
#include <shellapi.h>
6970
#include <shlobj.h>
7071
#endif
7172

@@ -399,15 +400,17 @@ ArgsManager::ArgsManager() :
399400
// nothing to do
400401
}
401402

402-
void ArgsManager::WarnForSectionOnlyArgs()
403+
const std::set<std::string> ArgsManager::GetUnsuitableSectionOnlyArgs() const
403404
{
405+
std::set<std::string> unsuitables;
406+
404407
LOCK(cs_args);
405408

406409
// if there's no section selected, don't worry
407-
if (m_network.empty()) return;
410+
if (m_network.empty()) return std::set<std::string> {};
408411

409412
// if it's okay to use the default section for this network, don't worry
410-
if (m_network == CBaseChainParams::MAIN) return;
413+
if (m_network == CBaseChainParams::MAIN) return std::set<std::string> {};
411414

412415
for (const auto& arg : m_network_only_args) {
413416
std::pair<bool, std::string> found_result;
@@ -425,8 +428,29 @@ void ArgsManager::WarnForSectionOnlyArgs()
425428
if (!found_result.first) continue;
426429

427430
// otherwise, issue a warning
428-
LogPrintf("Warning: Config setting for %s only applied on %s network when in [%s] section.\n", arg, m_network, m_network);
431+
unsuitables.insert(arg);
429432
}
433+
return unsuitables;
434+
}
435+
436+
437+
const std::set<std::string> ArgsManager::GetUnrecognizedSections() const
438+
{
439+
// Section names to be recognized in the config file.
440+
static const std::set<std::string> available_sections{
441+
CBaseChainParams::REGTEST,
442+
CBaseChainParams::TESTNET,
443+
CBaseChainParams::MAIN,
444+
CBaseChainParams::DEVNET
445+
};
446+
std::set<std::string> diff;
447+
448+
LOCK(cs_args);
449+
std::set_difference(
450+
m_config_sections.begin(), m_config_sections.end(),
451+
available_sections.begin(), available_sections.end(),
452+
std::inserter(diff, diff.end()));
453+
return diff;
430454
}
431455

432456
void ArgsManager::SelectConfigNetwork(const std::string& network)
@@ -887,7 +911,7 @@ static std::string TrimString(const std::string& str, const std::string& pattern
887911
return str.substr(front, end - front + 1);
888912
}
889913

890-
static bool GetConfigOptions(std::istream& stream, std::string& error, std::vector<std::pair<std::string, std::string>> &options)
914+
static bool GetConfigOptions(std::istream& stream, std::string& error, std::vector<std::pair<std::string, std::string>>& options, std::set<std::string>& sections)
891915
{
892916
std::string str, prefix;
893917
std::string::size_type pos;
@@ -902,7 +926,9 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
902926
str = TrimString(str, pattern);
903927
if (!str.empty()) {
904928
if (*str.begin() == '[' && *str.rbegin() == ']') {
905-
prefix = str.substr(1, str.size() - 2) + '.';
929+
const std::string section = str.substr(1, str.size() - 2);
930+
sections.insert(section);
931+
prefix = section + '.';
906932
} else if (*str.begin() == '-') {
907933
error = strprintf("parse error on line %i: %s, options in configuration file must be specified without leading -", linenr, str);
908934
return false;
@@ -914,6 +940,9 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
914940
return false;
915941
}
916942
options.emplace_back(name, value);
943+
if ((pos = name.rfind('.')) != std::string::npos) {
944+
sections.insert(name.substr(0, pos));
945+
}
917946
} else {
918947
error = strprintf("parse error on line %i: %s", linenr, str);
919948
if (str.size() >= 2 && str.substr(0, 2) == "no") {
@@ -931,7 +960,8 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, std::string& error, boo
931960
{
932961
LOCK(cs_args);
933962
std::vector<std::pair<std::string, std::string>> options;
934-
if (!GetConfigOptions(stream, error, options)) {
963+
m_config_sections.clear();
964+
if (!GetConfigOptions(stream, error, options, m_config_sections)) {
935965
return false;
936966
}
937967
for (const std::pair<std::string, std::string>& option : options) {
@@ -1298,6 +1328,10 @@ void SetupEnvironment()
12981328
} catch (const std::runtime_error&) {
12991329
setenv("LC_ALL", "C.UTF-8", 1);
13001330
}
1331+
#elif defined(WIN32)
1332+
// Set the default input/output charset is utf-8
1333+
SetConsoleCP(CP_UTF8);
1334+
SetConsoleOutputCP(CP_UTF8);
13011335
#endif
13021336
// The path locale is lazy initialized and to avoid deinitialization errors
13031337
// in multithreading environments, it is set explicitly by the main thread.
@@ -1367,3 +1401,30 @@ int ScheduleBatchPriority()
13671401
return 1;
13681402
#endif
13691403
}
1404+
1405+
namespace util {
1406+
#ifdef WIN32
1407+
WinCmdLineArgs::WinCmdLineArgs()
1408+
{
1409+
wchar_t** wargv = CommandLineToArgvW(GetCommandLineW(), &argc);
1410+
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> utf8_cvt;
1411+
argv = new char*[argc];
1412+
args.resize(argc);
1413+
for (int i = 0; i < argc; i++) {
1414+
args[i] = utf8_cvt.to_bytes(wargv[i]);
1415+
argv[i] = &*args[i].begin();
1416+
}
1417+
LocalFree(wargv);
1418+
}
1419+
1420+
WinCmdLineArgs::~WinCmdLineArgs()
1421+
{
1422+
delete[] argv;
1423+
}
1424+
1425+
std::pair<int, char**> WinCmdLineArgs::get()
1426+
{
1427+
return std::make_pair(argc, argv);
1428+
}
1429+
#endif
1430+
} // namespace util

src/util/system.h

+23-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <string>
3636
#include <unordered_map>
3737
#include <unordered_set>
38+
#include <utility>
3839
#include <vector>
3940

4041
#include <boost/thread/condition_variable.hpp> // for boost::thread_interrupted
@@ -177,6 +178,7 @@ class ArgsManager
177178
std::string m_network GUARDED_BY(cs_args);
178179
std::set<std::string> m_network_only_args GUARDED_BY(cs_args);
179180
std::map<OptionsCategory, std::map<std::string, Arg>> m_available_args GUARDED_BY(cs_args);
181+
std::set<std::string> m_config_sections GUARDED_BY(cs_args);
180182

181183
[[nodiscard]] bool ReadConfigStream(std::istream& stream, std::string& error, bool ignore_invalid_keys = false);
182184

@@ -197,7 +199,12 @@ class ArgsManager
197199
* on the command line or in a network-specific section in the
198200
* config file.
199201
*/
200-
void WarnForSectionOnlyArgs();
202+
const std::set<std::string> GetUnsuitableSectionOnlyArgs() const;
203+
204+
/**
205+
* Log warnings for unrecognized section names in the config file.
206+
*/
207+
const std::set<std::string> GetUnrecognizedSections() const;
201208

202209
/**
203210
* Return a vector of strings of the given argument
@@ -397,6 +404,21 @@ inline void insert(std::set<TsetT>& dst, const Tsrc& src) {
397404
dst.insert(src.begin(), src.end());
398405
}
399406

407+
#ifdef WIN32
408+
class WinCmdLineArgs
409+
{
410+
public:
411+
WinCmdLineArgs();
412+
~WinCmdLineArgs();
413+
std::pair<int, char**> get();
414+
415+
private:
416+
int argc;
417+
char** argv;
418+
std::vector<std::string> args;
419+
};
420+
#endif
421+
400422
} // namespace util
401423

402424
#endif // BITCOIN_UTIL_SYSTEM_H

src/wallet/db.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ void BerkeleyEnvironment::Flush(bool fShutdown)
725725
{
726726
int64_t nStart = GetTimeMillis();
727727
// Flush log data to the actual data file on all files that are not in use
728-
LogPrint(BCLog::DB, "BerkeleyEnvironment::Flush: Flush(%s)%s\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " database not started");
728+
LogPrint(BCLog::DB, "BerkeleyEnvironment::Flush: [%s] Flush(%s)%s\n", strPath, fShutdown ? "true" : "false", fDbEnvInit ? "" : " database not started");
729729
if (!fDbEnvInit)
730730
return;
731731
{

test/functional/feature_config_args.py

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ def test_config_file_parser(self):
4343
conf.write('server=1\nrpcuser=someuser\nrpcpassword=some#pass')
4444
self.nodes[0].assert_start_raises_init_error(expected_msg='Error reading configuration file: parse error on line 3, using # in rpcpassword can be ambiguous and should be avoided')
4545

46+
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
47+
conf.write('testnot.datadir=1\n[testnet]\n')
48+
self.restart_node(0)
49+
self.nodes[0].stop_node(expected_stderr='Warning: Section [testnet] is not recognized.' + os.linesep + 'Warning: Section [testnot] is not recognized.')
50+
4651
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
4752
conf.write('') # clear
4853

test/functional/feature_uacomment.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def run_test(self):
3131
self.nodes[0].assert_start_raises_init_error(["-uacomment=" + 'a' * 256], expected, match=ErrorMatch.FULL_REGEX)
3232

3333
self.log.info("test -uacomment unsafe characters")
34-
for unsafe_char in ['/', ':', '(', ')']:
34+
for unsafe_char in ['/', ':', '(', ')', '₿', '🏃']:
3535
expected = "Error: User Agent comment \(" + re.escape(unsafe_char) + "\) contains unsafe characters."
3636
self.nodes[0].assert_start_raises_init_error(["-uacomment=" + unsafe_char], expected, match=ErrorMatch.FULL_REGEX)
3737

test/functional/rpc_help.py

+17
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@
77
from test_framework.test_framework import BitcoinTestFramework, is_zmq_enabled
88
from test_framework.util import assert_equal, assert_raises_rpc_error
99

10+
import os
11+
12+
1013
class HelpRpcTest(BitcoinTestFramework):
1114
def set_test_params(self):
1215
self.num_nodes = 1
1316

1417
def run_test(self):
18+
self.test_categories()
19+
self.dump_help()
20+
21+
def test_categories(self):
1522
node = self.nodes[0]
1623

1724
# wrong argument count, note: Dash's help allows for two options since we utilize subcommands
@@ -33,5 +40,15 @@ def run_test(self):
3340

3441
assert_equal(titles, components)
3542

43+
def dump_help(self):
44+
dump_dir = os.path.join(self.options.tmpdir, 'rpc_help_dump')
45+
os.mkdir(dump_dir)
46+
calls = [line.split(' ', 1)[0] for line in self.nodes[0].help().splitlines() if line and not line.startswith('==')]
47+
for call in calls:
48+
with open(os.path.join(dump_dir, call), 'w', encoding='utf-8') as f:
49+
# Make sure the node can generate the help at runtime without crashing
50+
f.write(self.nodes[0].help(call))
51+
52+
3653
if __name__ == '__main__':
3754
HelpRpcTest().main()

test/functional/wallet_listreceivedby.py

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ def run_test(self):
6565
res = self.nodes[1].listreceivedbyaddress(minconf=0, addlocked=False, include_empty=True, include_watchonly=True, address_filter=addr)
6666
assert_array_result(res, {"address": addr}, expected)
6767
assert_equal(len(res), 1)
68+
# Test for regression on CLI calls with address string (#14173)
69+
cli_res = self.nodes[1].cli.listreceivedbyaddress(0, True, True, True, addr)
70+
assert_array_result(cli_res, {"address": addr}, expected)
71+
assert_equal(len(cli_res), 1)
6872
# Error on invalid address
6973
assert_raises_rpc_error(-4, "address_filter parameter was invalid", self.nodes[1].listreceivedbyaddress, minconf=0, addlocked=True, include_empty=True, include_watchonly=True, address_filter="bamboozling")
7074
# Another address receive money

0 commit comments

Comments
 (0)