mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-08 06:37:50 +02:00
Merge bitcoin/bitcoin#34741: refactor: Return std::optional from GetNameProxy/GetProxy
fa73ed467crefactor: Fix redundant conversion to std::string and then to std::string_view [performance-string-view-conversions] (MarcoFalke)fa270fdacfrefactor: Return std::optional from GetProxy (MarcoFalke)faeac1a931refactor: Return std::optional from GetNameProxy (MarcoFalke) Pull request description: Currently the getters have a mutable reference as inout param and return a bool to indicate success. This is confusing, because the success bool is redundant with the `IsValid()` state on the proxy object. So in theory, the functions could reset the mutable proxy object to an invalid state and return `void`. However, this would also be confusing, because devs can forget to check `IsValid()`. Fix all issues by using `std::optional<Proxy>`, where devs no longer have to check `IsValid()` manually, or a separate bool. Note that new code in the repo is already using `std::optional<Proxy>`, see `git grep 'std::optional<Proxy>' bitcoin-core/master`. Also, `std::optional<Proxy>` will enforce checking at compile time, whereas calling `Proxy::IsValid` is not enforced. ACKs for top commit: achow101: ACKfa73ed467csedited: ACKfa73ed467cViniciusCestarii: ACKfa73ed467cfrankomosh: Code Review ACKfa73ed467c. Good refactor, correctly replaces the bool + mutable reference output parameter pattern with `std::optional<Proxy>` across `GetProxy` and `GetNameProxy`. Semantics are preserved. Tree-SHA512: c6a1e1d1691958d2e6507e32e3484f96703fba03ccc710145ae2fb84b1254fb0e6e1d8d78e9b572daf5ea485247b73568704881762379b50bcf939a35494dd13
This commit is contained in:
@@ -187,7 +187,7 @@ public:
|
||||
args().WriteSettingsFile();
|
||||
}
|
||||
void mapPort(bool enable) override { StartMapPort(enable); }
|
||||
bool getProxy(Network net, Proxy& proxy_info) override { return GetProxy(net, proxy_info); }
|
||||
std::optional<Proxy> getProxy(Network net) override { return GetProxy(net); }
|
||||
size_t getNodeCount(ConnectionDirection flags) override
|
||||
{
|
||||
return m_context->connman ? m_context->connman->GetNodeCount(flags) : 0;
|
||||
|
||||
Reference in New Issue
Block a user