net: add Ensure{any}Banman

it adds `Ensure{any}Banman` functions to avoid
code repetition and make it cleaner. Similar
approach as done with argsman, chainman, connman
and others.
This commit is contained in:
brunoerg
2023-02-07 11:09:22 -03:00
parent fe86616bb4
commit 2d955ff006
3 changed files with 26 additions and 17 deletions

View File

@@ -39,6 +39,20 @@ CTxMemPool& EnsureAnyMemPool(const std::any& context)
return EnsureMemPool(EnsureAnyNodeContext(context));
}
BanMan& EnsureBanman(const NodeContext& node)
{
if (!node.banman) {
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
}
return *node.banman;
}
BanMan& EnsureAnyBanman(const std::any& context)
{
return EnsureBanman(EnsureAnyNodeContext(context));
}
ArgsManager& EnsureArgsman(const NodeContext& node)
{
if (!node.args) {