MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ParseHashOrHeight

Function ParseHashOrHeight

src/rpc/blockchain.cpp:136–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134}
135
136static const CBlockIndex* ParseHashOrHeight(const UniValue& param, ChainstateManager& chainman)
137{
138 LOCK(::cs_main);
139 CChain& active_chain = chainman.ActiveChain();
140
141 if (param.isNum()) {
142 const int height{param.getInt<int>()};
143 if (height < 0) {
144 throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Target block height %d is negative", height));
145 }
146 const int current_tip{active_chain.Height()};
147 if (height > current_tip) {
148 throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Target block height %d after current tip %d", height, current_tip));
149 }
150
151 return active_chain[height];
152 } else {
153 const uint256 hash{ParseHashV(param, "hash_or_height")};
154 const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(hash);
155
156 if (!pindex) {
157 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
158 }
159
160 return pindex;
161 }
162}
163
164UniValue blockheaderToJSON(const CBlockIndex& tip, const CBlockIndex& blockindex, const uint256 pow_limit)
165{

Callers 3

gettxoutsetinfoFunction · 0.85
getblockstatsFunction · 0.85
dumptxoutsetFunction · 0.85

Calls 5

JSONRPCErrorFunction · 0.85
ParseHashVFunction · 0.85
isNumMethod · 0.80
HeightMethod · 0.80
LookupBlockIndexMethod · 0.80

Tested by

no test coverage detected