@@ -702,9 +702,7 @@ static RPCHelpMan setban()
702702 throw std::runtime_error (help.ToString ());
703703 }
704704 NodeContext& node = EnsureAnyNodeContext (request.context );
705- if (!node.banman ) {
706- throw JSONRPCError (RPC_DATABASE_ERROR, " Error: Ban database not loaded" );
707- }
705+ BanMan& banman = EnsureBanman (node);
708706
709707 CSubNet subNet;
710708 CNetAddr netAddr;
@@ -726,7 +724,7 @@ static RPCHelpMan setban()
726724
727725 if (strCommand == " add" )
728726 {
729- if (isSubnet ? node. banman -> IsBanned (subNet) : node. banman -> IsBanned (netAddr)) {
727+ if (isSubnet ? banman. IsBanned (subNet) : banman. IsBanned (netAddr)) {
730728 throw JSONRPCError (RPC_CLIENT_NODE_ALREADY_ADDED, " Error: IP/Subnet already banned" );
731729 }
732730
@@ -741,20 +739,20 @@ static RPCHelpMan setban()
741739 }
742740
743741 if (isSubnet) {
744- node. banman -> Ban (subNet, banTime, absolute);
742+ banman. Ban (subNet, banTime, absolute);
745743 if (node.connman ) {
746744 node.connman ->DisconnectNode (subNet);
747745 }
748746 } else {
749- node. banman -> Ban (netAddr, banTime, absolute);
747+ banman. Ban (netAddr, banTime, absolute);
750748 if (node.connman ) {
751749 node.connman ->DisconnectNode (netAddr);
752750 }
753751 }
754752 }
755753 else if (strCommand == " remove" )
756754 {
757- if (!( isSubnet ? node. banman -> Unban (subNet) : node. banman -> Unban (netAddr) )) {
755+ if (!( isSubnet ? banman. Unban (subNet) : banman. Unban (netAddr) )) {
758756 throw JSONRPCError (RPC_CLIENT_INVALID_IP_OR_SUBNET, " Error: Unban failed. Requested address/subnet was not previously manually banned." );
759757 }
760758 }
@@ -785,13 +783,10 @@ static RPCHelpMan listbanned()
785783 },
786784 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
787785{
788- NodeContext& node = EnsureAnyNodeContext (request.context );
789- if (!node.banman ) {
790- throw JSONRPCError (RPC_DATABASE_ERROR, " Error: Ban database not loaded" );
791- }
786+ BanMan& banman = EnsureAnyBanman (request.context );
792787
793788 banmap_t banMap;
794- node. banman -> GetBanned (banMap);
789+ banman. GetBanned (banMap);
795790 const int64_t current_time{GetTime ()};
796791
797792 UniValue bannedAddresses (UniValue::VARR);
@@ -825,12 +820,9 @@ static RPCHelpMan clearbanned()
825820 },
826821 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
827822{
828- NodeContext& node = EnsureAnyNodeContext (request.context );
829- if (!node.banman ) {
830- throw JSONRPCError (RPC_DATABASE_ERROR, " Error: Ban database not loaded" );
831- }
823+ BanMan& banman = EnsureAnyBanman (request.context );
832824
833- node. banman -> ClearBanned ();
825+ banman. ClearBanned ();
834826
835827 return UniValue::VNULL;
836828},
0 commit comments