Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show All 20 Lines | |||||
#include <index/coinstatsindex.h> | #include <index/coinstatsindex.h> | ||||
#include <node/blockstorage.h> | #include <node/blockstorage.h> | ||||
#include <node/coinstats.h> | #include <node/coinstats.h> | ||||
#include <node/context.h> | #include <node/context.h> | ||||
#include <node/utxo_snapshot.h> | #include <node/utxo_snapshot.h> | ||||
#include <policy/policy.h> | #include <policy/policy.h> | ||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#include <rpc/server.h> | #include <rpc/server.h> | ||||
#include <rpc/server_util.h> | |||||
#include <rpc/util.h> | #include <rpc/util.h> | ||||
#include <script/descriptor.h> | #include <script/descriptor.h> | ||||
#include <streams.h> | #include <streams.h> | ||||
#include <txdb.h> | #include <txdb.h> | ||||
#include <txmempool.h> | #include <txmempool.h> | ||||
#include <undo.h> | #include <undo.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <util/system.h> | |||||
#include <util/translation.h> | #include <util/translation.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <validationinterface.h> | #include <validationinterface.h> | ||||
#include <versionbits.h> | #include <versionbits.h> | ||||
#include <warnings.h> | #include <warnings.h> | ||||
#include <condition_variable> | #include <condition_variable> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <memory> | #include <memory> | ||||
#include <mutex> | #include <mutex> | ||||
struct CUpdatedBlock { | struct CUpdatedBlock { | ||||
BlockHash hash; | BlockHash hash; | ||||
int height; | int height; | ||||
}; | }; | ||||
static Mutex cs_blockchange; | static Mutex cs_blockchange; | ||||
static std::condition_variable cond_blockchange; | static std::condition_variable cond_blockchange; | ||||
static CUpdatedBlock latestblock GUARDED_BY(cs_blockchange); | static CUpdatedBlock latestblock GUARDED_BY(cs_blockchange); | ||||
NodeContext &EnsureAnyNodeContext(const std::any &context) { | |||||
auto node_context = util::AnyPtr<NodeContext>(context); | |||||
if (!node_context) { | |||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Node context not found"); | |||||
} | |||||
return *node_context; | |||||
} | |||||
CTxMemPool &EnsureMemPool(const NodeContext &node) { | |||||
if (!node.mempool) { | |||||
throw JSONRPCError(RPC_CLIENT_MEMPOOL_DISABLED, | |||||
"Mempool disabled or instance not found"); | |||||
} | |||||
return *node.mempool; | |||||
} | |||||
CTxMemPool &EnsureAnyMemPool(const std::any &context) { | |||||
return EnsureMemPool(EnsureAnyNodeContext(context)); | |||||
} | |||||
ChainstateManager &EnsureChainman(const NodeContext &node) { | |||||
if (!node.chainman) { | |||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Node chainman not found"); | |||||
} | |||||
return *node.chainman; | |||||
} | |||||
ChainstateManager &EnsureAnyChainman(const std::any &context) { | |||||
return EnsureChainman(EnsureAnyNodeContext(context)); | |||||
} | |||||
/** | /** | ||||
* Calculate the difficulty for a given block index. | * Calculate the difficulty for a given block index. | ||||
*/ | */ | ||||
double GetDifficulty(const CBlockIndex *blockindex) { | double GetDifficulty(const CBlockIndex *blockindex) { | ||||
CHECK_NONFATAL(blockindex); | CHECK_NONFATAL(blockindex); | ||||
int nShift = (blockindex->nBits >> 24) & 0xff; | int nShift = (blockindex->nBits >> 24) & 0xff; | ||||
double dDiff = double(0x0000ffff) / double(blockindex->nBits & 0x00ffffff); | double dDiff = double(0x0000ffff) / double(blockindex->nBits & 0x00ffffff); | ||||
▲ Show 20 Lines • Show All 3,287 Lines • Show Last 20 Lines |