@@ -949,10 +949,7 @@ static RPCHelpMan addpeeraddress()
949949 },
950950 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
951951{
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 );
956953
957954 const std::string& addr_string{request.params [0 ].get_str ()};
958955 const auto port{request.params [1 ].getInt <uint16_t >()};
@@ -968,11 +965,11 @@ static RPCHelpMan addpeeraddress()
968965 address.nTime = Now<NodeSeconds>();
969966 // The source address is set equal to the address. This is equivalent to the peer
970967 // announcing itself.
971- if (node. addrman -> Add ({address}, address)) {
968+ if (addrman. Add ({address}, address)) {
972969 success = true ;
973970 if (tried) {
974971 // Attempt to move the address to the tried addresses table.
975- node. addrman -> Good (address);
972+ addrman. Good (address);
976973 }
977974 }
978975 }
@@ -1048,25 +1045,22 @@ static RPCHelpMan getaddrmaninfo()
10481045 }},
10491046 RPCExamples{HelpExampleCli (" getaddrmaninfo" , " " ) + HelpExampleRpc (" getaddrmaninfo" , " " )},
10501047 [&](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 );
10551049
10561050 UniValue ret (UniValue::VOBJ);
10571051 for (int n = 0 ; n < NET_MAX; ++n) {
10581052 enum Network network = static_cast <enum Network>(n);
10591053 if (network == NET_UNROUTABLE || network == NET_INTERNAL) continue ;
10601054 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));
10641058 ret.pushKV (GetNetworkName (network), obj);
10651059 }
10661060 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 ());
10701064 ret.pushKV (" all_networks" , obj);
10711065 return ret;
10721066 },
@@ -1128,14 +1122,11 @@ static RPCHelpMan getrawaddrman()
11281122 + HelpExampleRpc (" getrawaddrman" , " " )
11291123 },
11301124 [&](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 );
11351126
11361127 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 )));
11391130 return ret;
11401131 },
11411132 };
0 commit comments