aboutsummaryrefslogtreecommitdiff
path: root/src/bitcoin-cli.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bitcoin-cli.cpp')
-rw-r--r--src/bitcoin-cli.cpp54
1 files changed, 45 insertions, 9 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
index b7e4e64103..44fc273163 100644
--- a/src/bitcoin-cli.cpp
+++ b/src/bitcoin-cli.cpp
@@ -42,6 +42,9 @@
#include <event2/keyvalq_struct.h>
#include <support/events.h>
+using util::Join;
+using util::ToString;
+
// The server returns time values from a mockable system clock, but it is not
// trivial to get the mocked time from the server, nor is it needed for now, so
// just use a plain system_clock.
@@ -297,8 +300,8 @@ public:
total += counts.at(i);
}
addresses.pushKV("total", total);
- result.pushKV("addresses_known", addresses);
- return JSONRPCReplyObj(std::move(result), NullUniValue, /*id=*/1, JSONRPCVersion::V1_LEGACY);
+ result.pushKV("addresses_known", std::move(addresses));
+ return JSONRPCReplyObj(std::move(result), NullUniValue, /*id=*/1, JSONRPCVersion::V2);
}
};
@@ -348,7 +351,7 @@ public:
connections.pushKV("in", batch[ID_NETWORKINFO]["result"]["connections_in"]);
connections.pushKV("out", batch[ID_NETWORKINFO]["result"]["connections_out"]);
connections.pushKV("total", batch[ID_NETWORKINFO]["result"]["connections"]);
- result.pushKV("connections", connections);
+ result.pushKV("connections", std::move(connections));
result.pushKV("networks", batch[ID_NETWORKINFO]["result"]["networks"]);
result.pushKV("difficulty", batch[ID_BLOCKCHAININFO]["result"]["difficulty"]);
@@ -367,7 +370,7 @@ public:
}
result.pushKV("relayfee", batch[ID_NETWORKINFO]["result"]["relayfee"]);
result.pushKV("warnings", batch[ID_NETWORKINFO]["result"]["warnings"]);
- return JSONRPCReplyObj(std::move(result), NullUniValue, /*id=*/1, JSONRPCVersion::V1_LEGACY);
+ return JSONRPCReplyObj(std::move(result), NullUniValue, /*id=*/1, JSONRPCVersion::V2);
}
};
@@ -622,7 +625,7 @@ public:
}
}
- return JSONRPCReplyObj(UniValue{result}, NullUniValue, /*id=*/1, JSONRPCVersion::V1_LEGACY);
+ return JSONRPCReplyObj(UniValue{result}, NullUniValue, /*id=*/1, JSONRPCVersion::V2);
}
const std::string m_help_doc{
@@ -709,7 +712,7 @@ public:
UniValue result(UniValue::VOBJ);
result.pushKV("address", address_str);
result.pushKV("blocks", reply.get_obj()["result"]);
- return JSONRPCReplyObj(std::move(result), NullUniValue, /*id=*/1, JSONRPCVersion::V1_LEGACY);
+ return JSONRPCReplyObj(std::move(result), NullUniValue, /*id=*/1, JSONRPCVersion::V2);
}
protected:
std::string address_str;
@@ -743,8 +746,41 @@ static UniValue CallRPC(BaseRequestHandler* rh, const std::string& strMethod, co
// 2. port in -rpcconnect (ie following : in ipv4 or ]: in ipv6)
// 3. default port for chain
uint16_t port{BaseParams().RPCPort()};
- SplitHostPort(gArgs.GetArg("-rpcconnect", DEFAULT_RPCCONNECT), port, host);
- port = static_cast<uint16_t>(gArgs.GetIntArg("-rpcport", port));
+ {
+ uint16_t rpcconnect_port{0};
+ const std::string rpcconnect_str = gArgs.GetArg("-rpcconnect", DEFAULT_RPCCONNECT);
+ if (!SplitHostPort(rpcconnect_str, rpcconnect_port, host)) {
+ // Uses argument provided as-is
+ // (rather than value parsed)
+ // to aid the user in troubleshooting
+ throw std::runtime_error(strprintf("Invalid port provided in -rpcconnect: %s", rpcconnect_str));
+ } else {
+ if (rpcconnect_port != 0) {
+ // Use the valid port provided in rpcconnect
+ port = rpcconnect_port;
+ } // else, no port was provided in rpcconnect (continue using default one)
+ }
+
+ if (std::optional<std::string> rpcport_arg = gArgs.GetArg("-rpcport")) {
+ // -rpcport was specified
+ const uint16_t rpcport_int{ToIntegral<uint16_t>(rpcport_arg.value()).value_or(0)};
+ if (rpcport_int == 0) {
+ // Uses argument provided as-is
+ // (rather than value parsed)
+ // to aid the user in troubleshooting
+ throw std::runtime_error(strprintf("Invalid port provided in -rpcport: %s", rpcport_arg.value()));
+ }
+
+ // Use the valid port provided
+ port = rpcport_int;
+
+ // If there was a valid port provided in rpcconnect,
+ // rpcconnect_port is non-zero.
+ if (rpcconnect_port != 0) {
+ tfm::format(std::cerr, "Warning: Port specified in both -rpcconnect and -rpcport. Using -rpcport %u\n", port);
+ }
+ }
+ }
// Obtain event base
raii_event_base base = obtain_event_base();
@@ -940,7 +976,7 @@ static void GetWalletBalances(UniValue& result)
const UniValue& balance = getbalances.find_value("result")["mine"]["trusted"];
balances.pushKV(wallet_name, balance);
}
- result.pushKV("balances", balances);
+ result.pushKV("balances", std::move(balances));
}
/**