0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-05 14:06:27 -05:00

rpc: add GetTarget helper

This commit is contained in:
Sjors Provoost 2025-01-08 13:03:08 +01:00
parent d20d96fa41
commit 341f932516
No known key found for this signature in database
GPG key ID: 57FF9BDBCC301009
2 changed files with 18 additions and 0 deletions

View file

@ -4,6 +4,7 @@
#include <bitcoin-build-config.h> // IWYU pragma: keep #include <bitcoin-build-config.h> // IWYU pragma: keep
#include <chain.h>
#include <clientversion.h> #include <clientversion.h>
#include <common/args.h> #include <common/args.h>
#include <common/messages.h> #include <common/messages.h>
@ -13,6 +14,7 @@
#include <key_io.h> #include <key_io.h>
#include <node/types.h> #include <node/types.h>
#include <outputtype.h> #include <outputtype.h>
#include <pow.h>
#include <rpc/util.h> #include <rpc/util.h>
#include <script/descriptor.h> #include <script/descriptor.h>
#include <script/interpreter.h> #include <script/interpreter.h>
@ -1418,3 +1420,9 @@ std::vector<RPCResult> ScriptPubKeyDoc() {
{RPCResult::Type::STR, "type", "The type (one of: " + GetAllOutputTypes() + ")"}, {RPCResult::Type::STR, "type", "The type (one of: " + GetAllOutputTypes() + ")"},
}; };
} }
uint256 GetTarget(const CBlockIndex& blockindex, const uint256 pow_limit)
{
arith_uint256 target{*CHECK_NONFATAL(DeriveTarget(blockindex.nBits, pow_limit))};
return ArithToUint256(target);
}

View file

@ -516,4 +516,14 @@ void PushWarnings(const std::vector<bilingual_str>& warnings, UniValue& obj);
std::vector<RPCResult> ScriptPubKeyDoc(); std::vector<RPCResult> ScriptPubKeyDoc();
/***
* Get the target for a given block index.
*
* @param[in] blockindex the block
* @param[in] pow_limit PoW limit (consensus parameter)
*
* @return the target
*/
uint256 GetTarget(const CBlockIndex& blockindex, const uint256 pow_limit);
#endif // BITCOIN_RPC_UTIL_H #endif // BITCOIN_RPC_UTIL_H