diff options
author | MacroFake <falke.marco@gmail.com> | 2022-07-14 11:20:31 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-07-14 12:20:50 +0200 |
commit | fa23c197509f692a815193acc1b50bad2fcbedfe (patch) | |
tree | cc963094a514aea0f5dcb5d4126b4550b60530dd /src/rpc | |
parent | fa3a9a1e8d9b6dffda772e97c279f3c0af6813f9 (diff) | |
download | bitcoin-fa23c197509f692a815193acc1b50bad2fcbedfe.tar.xz |
univalue: Avoid narrowing and verbose int constructors
As UniValue provides several constructors for integral types, the
compiler is unable to select one if the passed type does not exactly
match. This is unintuitive for developers and forces them to write
verbose and brittle code.
For example, there are many places where an unsigned int is cast to a
signed int. While the cast is safe in practice, it is still needlessly
verbose and confusing as the value can never be negative. In fact it
might even be unsafe if the unsigned value is large enough to map to a
negative signed one.
Diffstat (limited to 'src/rpc')
-rw-r--r-- | src/rpc/net.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index fad92629c5..69bbae96c1 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -60,7 +60,7 @@ static RPCHelpMan getconnectioncount() NodeContext& node = EnsureAnyNodeContext(request.context); const CConnman& connman = EnsureConnman(node); - return (int)connman.GetNodeCount(ConnectionDirection::Both); + return connman.GetNodeCount(ConnectionDirection::Both); }, }; } @@ -639,9 +639,9 @@ static RPCHelpMan getnetworkinfo() obj.pushKV("timeoffset", GetTimeOffset()); if (node.connman) { obj.pushKV("networkactive", node.connman->GetNetworkActive()); - obj.pushKV("connections", (int)node.connman->GetNodeCount(ConnectionDirection::Both)); - obj.pushKV("connections_in", (int)node.connman->GetNodeCount(ConnectionDirection::In)); - obj.pushKV("connections_out", (int)node.connman->GetNodeCount(ConnectionDirection::Out)); + obj.pushKV("connections", node.connman->GetNodeCount(ConnectionDirection::Both)); + obj.pushKV("connections_in", node.connman->GetNodeCount(ConnectionDirection::In)); + obj.pushKV("connections_out", node.connman->GetNodeCount(ConnectionDirection::Out)); } obj.pushKV("networks", GetNetworksInfo()); obj.pushKV("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())); |