aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/blockchain.cpp12
-rw-r--r--src/rpc/mining.cpp12
-rw-r--r--src/rpc/net.cpp12
-rw-r--r--src/rpc/util.cpp17
-rw-r--r--src/rpc/util.h2
5 files changed, 46 insertions, 9 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index eed004806a..c9997ae063 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -47,7 +47,6 @@
#include <validation.h>
#include <validationinterface.h>
#include <versionbits.h>
-#include <warnings.h>
#include <stdint.h>
@@ -1260,7 +1259,14 @@ RPCHelpMan getblockchaininfo()
{RPCResult::Type::NUM, "pruneheight", /*optional=*/true, "height of the last block pruned, plus one (only present if pruning is enabled)"},
{RPCResult::Type::BOOL, "automatic_pruning", /*optional=*/true, "whether automatic pruning is enabled (only present if pruning is enabled)"},
{RPCResult::Type::NUM, "prune_target_size", /*optional=*/true, "the target size used by pruning (only present if automatic pruning is enabled)"},
- {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{
HelpExampleCli("getblockchaininfo", "")
@@ -1298,7 +1304,7 @@ RPCHelpMan getblockchaininfo()
}
}
- obj.pushKV("warnings", GetWarnings(false).original);
+ obj.pushKV("warnings", GetNodeWarnings(IsDeprecatedRPCEnabled("warnings")));
return obj;
},
};
diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp
index 454c262803..f36665a819 100644
--- a/src/rpc/mining.cpp
+++ b/src/rpc/mining.cpp
@@ -39,7 +39,6 @@
#include <util/translation.h>
#include <validation.h>
#include <validationinterface.h>
-#include <warnings.h>
#include <memory>
#include <stdint.h>
@@ -426,7 +425,14 @@ static RPCHelpMan getmininginfo()
{RPCResult::Type::NUM, "networkhashps", "The network hashes per second"},
{RPCResult::Type::NUM, "pooledtx", "The size of the mempool"},
{RPCResult::Type::STR, "chain", "current network name (main, test, signet, regtest)"},
- {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{
HelpExampleCli("getmininginfo", "")
@@ -448,7 +454,7 @@ static RPCHelpMan getmininginfo()
obj.pushKV("networkhashps", getnetworkhashps().HandleRequest(request));
obj.pushKV("pooledtx", (uint64_t)mempool.size());
obj.pushKV("chain", chainman.GetParams().GetChainTypeString());
- obj.pushKV("warnings", GetWarnings(false).original);
+ obj.pushKV("warnings", GetNodeWarnings(IsDeprecatedRPCEnabled("warnings")));
return obj;
},
};
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp
index 739ff1a48e..04f9410b32 100644
--- a/src/rpc/net.cpp
+++ b/src/rpc/net.cpp
@@ -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;
},
};
diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp
index f683878054..0ac2c4e7b0 100644
--- a/src/rpc/util.cpp
+++ b/src/rpc/util.cpp
@@ -18,16 +18,19 @@
#include <script/signingprovider.h>
#include <script/solver.h>
#include <tinyformat.h>
+#include <univalue.h>
#include <util/check.h>
#include <util/result.h>
#include <util/strencodings.h>
#include <util/string.h>
#include <util/translation.h>
+#include <warnings.h>
#include <algorithm>
#include <iterator>
#include <string_view>
#include <tuple>
+#include <utility>
const std::string UNIX_EPOCH_TIME = "UNIX epoch time";
const std::string EXAMPLE_ADDRESS[2] = {"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl", "bc1q02ad21edsxd23d32dfgqqsz4vv4nmtfzuklhy3"};
@@ -1357,3 +1360,17 @@ void PushWarnings(const std::vector<bilingual_str>& warnings, UniValue& obj)
if (warnings.empty()) return;
obj.pushKV("warnings", BilingualStringsToUniValue(warnings));
}
+
+UniValue GetNodeWarnings(bool use_deprecated)
+{
+ if (use_deprecated) {
+ const auto all_warnings{GetWarnings()};
+ return all_warnings.empty() ? "" : all_warnings.back().original;
+ }
+
+ UniValue warnings{UniValue::VARR};
+ for (auto&& warning : GetWarnings()) {
+ warnings.push_back(std::move(warning.original));
+ }
+ return warnings;
+}
diff --git a/src/rpc/util.h b/src/rpc/util.h
index 177af90c05..0e4dcc27b5 100644
--- a/src/rpc/util.h
+++ b/src/rpc/util.h
@@ -513,4 +513,6 @@ private:
void PushWarnings(const UniValue& warnings, UniValue& obj);
void PushWarnings(const std::vector<bilingual_str>& warnings, UniValue& obj);
+UniValue GetNodeWarnings(bool use_deprecated);
+
#endif // BITCOIN_RPC_UTIL_H