rpc: return warnings as an array instead of just a single one

The RPC documentation for `getblockchaininfo`, `getmininginfo` and
`getnetworkinfo` states that "warnings" returns "any network and
blockchain warnings". In practice, only a single warning is returned.

Fix that by returning all warnings as an array.

As a side benefit, cleans up the GetWarnings() logic.
This commit is contained in:
stickies-v
2024-04-10 12:16:21 +02:00
parent 842f7fdf78
commit 42fb5311b1
10 changed files with 71 additions and 37 deletions

View File

@@ -29,7 +29,6 @@
#include <util/time.h>
#include <util/translation.h>
#include <validation.h>
#include <warnings.h>
#include <optional>
@@ -657,7 +656,14 @@ static RPCHelpMan getnetworkinfo()
{RPCResult::Type::NUM, "score", "relative score"},
}},
}},
{RPCResult::Type::STR, "warnings", "any network and blockchain warnings"},
(IsDeprecatedRPCEnabled("warnings") ?
RPCResult{RPCResult::Type::STR, "warnings", "any network and blockchain warnings (DEPRECATED)"} :
RPCResult{RPCResult::Type::ARR, "warnings", "any network and blockchain warnings (run with `-deprecatedrpc=warnings` to return the latest warning as a single string)",
{
{RPCResult::Type::STR, "", "warning"},
}
}
),
}
},
RPCExamples{
@@ -707,7 +713,7 @@ static RPCHelpMan getnetworkinfo()
}
}
obj.pushKV("localaddresses", localAddresses);
obj.pushKV("warnings", GetWarnings(false).original);
obj.pushKV("warnings", GetNodeWarnings(IsDeprecatedRPCEnabled("warnings")));
return obj;
},
};