| 134 | } |
| 135 | |
| 136 | static 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 | |
| 164 | UniValue blockheaderToJSON(const CBlockIndex& tip, const CBlockIndex& blockindex, const uint256 pow_limit) |
| 165 | { |
no test coverage detected