@@ -949,10 +949,7 @@ static RPCHelpMan addpeeraddress()
949
949
},
950
950
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
951
951
{
952
- NodeContext& node = EnsureAnyNodeContext(request.context);
953
- if (!node.addrman) {
954
- throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Address manager functionality missing or disabled");
955
- }
952
+ AddrMan& addrman = EnsureAnyAddrman(request.context);
956
953
957
954
const std::string& addr_string{request.params[0].get_str()};
958
955
const auto port{request.params[1].getInt<uint16_t>()};
@@ -968,11 +965,11 @@ static RPCHelpMan addpeeraddress()
968
965
address.nTime = Now<NodeSeconds>();
969
966
// The source address is set equal to the address. This is equivalent to the peer
970
967
// announcing itself.
971
- if (node. addrman-> Add({address}, address)) {
968
+ if (addrman. Add({address}, address)) {
972
969
success = true;
973
970
if (tried) {
974
971
// Attempt to move the address to the tried addresses table.
975
- node. addrman-> Good(address);
972
+ addrman. Good(address);
976
973
}
977
974
}
978
975
}
@@ -1048,25 +1045,22 @@ static RPCHelpMan getaddrmaninfo()
1048
1045
}},
1049
1046
RPCExamples{HelpExampleCli("getaddrmaninfo", "") + HelpExampleRpc("getaddrmaninfo", "")},
1050
1047
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
1051
- NodeContext& node = EnsureAnyNodeContext(request.context);
1052
- if (!node.addrman) {
1053
- throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Address manager functionality missing or disabled");
1054
- }
1048
+ AddrMan& addrman = EnsureAnyAddrman(request.context);
1055
1049
1056
1050
UniValue ret(UniValue::VOBJ);
1057
1051
for (int n = 0; n < NET_MAX; ++n) {
1058
1052
enum Network network = static_cast<enum Network>(n);
1059
1053
if (network == NET_UNROUTABLE || network == NET_INTERNAL) continue;
1060
1054
UniValue obj(UniValue::VOBJ);
1061
- obj.pushKV("new", node. addrman-> Size(network, true));
1062
- obj.pushKV("tried", node. addrman-> Size(network, false));
1063
- obj.pushKV("total", node. addrman-> Size(network));
1055
+ obj.pushKV("new", addrman. Size(network, true));
1056
+ obj.pushKV("tried", addrman. Size(network, false));
1057
+ obj.pushKV("total", addrman. Size(network));
1064
1058
ret.pushKV(GetNetworkName(network), obj);
1065
1059
}
1066
1060
UniValue obj(UniValue::VOBJ);
1067
- obj.pushKV("new", node. addrman-> Size(std::nullopt, true));
1068
- obj.pushKV("tried", node. addrman-> Size(std::nullopt, false));
1069
- obj.pushKV("total", node. addrman-> Size());
1061
+ obj.pushKV("new", addrman. Size(std::nullopt, true));
1062
+ obj.pushKV("tried", addrman. Size(std::nullopt, false));
1063
+ obj.pushKV("total", addrman. Size());
1070
1064
ret.pushKV("all_networks", obj);
1071
1065
return ret;
1072
1066
},
@@ -1128,14 +1122,11 @@ static RPCHelpMan getrawaddrman()
1128
1122
+ HelpExampleRpc("getrawaddrman", "")
1129
1123
},
1130
1124
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue {
1131
- NodeContext& node = EnsureAnyNodeContext(request.context);
1132
- if (!node.addrman) {
1133
- throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Address manager functionality missing or disabled");
1134
- }
1125
+ AddrMan& addrman = EnsureAnyAddrman(request.context);
1135
1126
1136
1127
UniValue ret(UniValue::VOBJ);
1137
- ret.pushKV("new", AddrmanTableToJSON(node. addrman-> GetEntries(false)));
1138
- ret.pushKV("tried", AddrmanTableToJSON(node. addrman-> GetEntries(true)));
1128
+ ret.pushKV("new", AddrmanTableToJSON(addrman. GetEntries(false)));
1129
+ ret.pushKV("tried", AddrmanTableToJSON(addrman. GetEntries(true)));
1139
1130
return ret;
1140
1131
},
1141
1132
};
0 commit comments