diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -9,6 +9,7 @@ #include "chainparamsbase.h" #include "clientversion.h" +#include "fs.h" #include "rpc/client.h" #include "rpc/protocol.h" #include "support/events.h" @@ -66,7 +67,7 @@ "until EOF/Ctrl-D (recommended for sensitive information " "such as passphrases)")); strUsage += HelpMessageOpt( - "-usewallet=", + "-rpcwallet=", _("Send RPC for non-default wallet on RPC server (argument is wallet " "filename in bitcoind directory, required if bitcoind/-Qt runs with " "multiple wallets)")); @@ -215,8 +216,14 @@ #endif UniValue CallRPC(const std::string &strMethod, const UniValue ¶ms) { - std::string host = gArgs.GetArg("-rpcconnect", DEFAULT_RPCCONNECT); - int port = gArgs.GetArg("-rpcport", BaseParams().RPCPort()); + std::string host; + // In preference order, we choose the following for the port: + // 1. -rpcport + // 2. port in -rpcconnect (ie following : in ipv4 or ]: in ipv6) + // 3. default port for chain + int port = BaseParams().RPCPort(); + SplitHostPort(gArgs.GetArg("-rpcconnect", DEFAULT_RPCCONNECT), port, host); + port = gArgs.GetArg("-rpcport", port); // Obtain event base raii_event_base base = obtain_event_base(); @@ -274,7 +281,7 @@ // check if we should use a special wallet endpoint std::string endpoint = "/"; - std::string walletName = gArgs.GetArg("-usewallet", ""); + std::string walletName = gArgs.GetArg("-rpcwallet", ""); if (!walletName.empty()) { char *encodedURI = evhttp_uriencode(walletName.c_str(), walletName.size(), false); diff --git a/src/httpserver.cpp b/src/httpserver.cpp --- a/src/httpserver.cpp +++ b/src/httpserver.cpp @@ -11,6 +11,7 @@ #include "sync.h" #include "ui_interface.h" #include "util.h" +#include "utilstrencodings.h" #include #include diff --git a/src/netbase.h b/src/netbase.h --- a/src/netbase.h +++ b/src/netbase.h @@ -39,7 +39,6 @@ enum Network ParseNetwork(std::string net); std::string GetNetworkName(enum Network net); -void SplitHostPort(std::string in, int &portOut, std::string &hostOut); bool SetProxy(enum Network net, const proxyType &addrProxy); bool GetProxy(enum Network net, proxyType &proxyInfoOut); bool IsProxy(const CNetAddr &addr); diff --git a/src/netbase.cpp b/src/netbase.cpp --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -62,30 +62,6 @@ } } -void SplitHostPort(std::string in, int &portOut, std::string &hostOut) { - size_t colon = in.find_last_of(':'); - // if a : is found, and it either follows a [...], or no other : is in the - // string, treat it as port separator - bool fHaveColon = colon != in.npos; - // if there is a colon, and in[0]=='[', colon is not 0, so in[colon-1] is - // safe - bool fBracketed = fHaveColon && (in[0] == '[' && in[colon - 1] == ']'); - bool fMultiColon = - fHaveColon && (in.find_last_of(':', colon - 1) != in.npos); - if (fHaveColon && (colon == 0 || fBracketed || !fMultiColon)) { - int32_t n; - if (ParseInt32(in.substr(colon + 1), &n) && n > 0 && n < 0x10000) { - in = in.substr(0, colon); - portOut = n; - } - } - if (in.size() > 0 && in[0] == '[' && in[in.size() - 1] == ']') { - hostOut = in.substr(1, in.size() - 2); - } else { - hostOut = in; - } -} - static bool LookupIntern(const char *pszName, std::vector &vIP, unsigned int nMaxSolutions, bool fAllowLookup) { vIP.clear(); diff --git a/src/test/netbase_tests.cpp b/src/test/netbase_tests.cpp --- a/src/test/netbase_tests.cpp +++ b/src/test/netbase_tests.cpp @@ -4,6 +4,7 @@ #include "netbase.h" #include "test/test_bitcoin.h" +#include "utilstrencodings.h" #include diff --git a/src/utilstrencodings.h b/src/utilstrencodings.h --- a/src/utilstrencodings.h +++ b/src/utilstrencodings.h @@ -52,6 +52,7 @@ std::string EncodeBase32(const uint8_t *pch, size_t len); std::string EncodeBase32(const std::string &str); +void SplitHostPort(std::string in, int &portOut, std::string &hostOut); std::string i64tostr(int64_t n); std::string itostr(int n); int64_t atoi64(const char *psz); diff --git a/src/utilstrencodings.cpp b/src/utilstrencodings.cpp --- a/src/utilstrencodings.cpp +++ b/src/utilstrencodings.cpp @@ -84,6 +84,32 @@ return ParseHex(str.c_str()); } +void SplitHostPort(std::string in, int &portOut, std::string &hostOut) { + size_t colon = in.find_last_of(':'); + // if a : is found, and it either follows a [...], or no other : is in the + // string, treat it as port separator + bool fHaveColon = colon != in.npos; + bool fBracketed = + fHaveColon && + (in[0] == '[' && in[colon - 1] == ']'); // if there is a colon, and + // in[0]=='[', colon is not 0, + // so in[colon-1] is safe + bool fMultiColon = + fHaveColon && (in.find_last_of(':', colon - 1) != in.npos); + if (fHaveColon && (colon == 0 || fBracketed || !fMultiColon)) { + int32_t n; + if (ParseInt32(in.substr(colon + 1), &n) && n > 0 && n < 0x10000) { + in = in.substr(0, colon); + portOut = n; + } + } + if (in.size() > 0 && in[0] == '[' && in[in.size() - 1] == ']') { + hostOut = in.substr(1, in.size() - 2); + } else { + hostOut = in; + } +} + std::string EncodeBase64(const uint8_t *pch, size_t len) { static const char *pbase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";