| 200 | |
| 201 | template<typename T> |
| 202 | static bool GetBlockAndTxFromMerkleBlock(uint256& block_hash, uint256& tx_hash, unsigned int& tx_index, T& merkle_block, const std::vector<unsigned char>& merkle_block_raw) |
| 203 | { |
| 204 | try { |
| 205 | std::vector<uint256> tx_hashes; |
| 206 | std::vector<unsigned int> tx_indices; |
| 207 | CDataStream merkle_block_stream(merkle_block_raw, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS); |
| 208 | merkle_block_stream >> merkle_block; |
| 209 | block_hash = merkle_block.header.GetHash(); |
| 210 | |
| 211 | if (!merkle_block_stream.empty()) { |
| 212 | return false; |
| 213 | } |
| 214 | if (merkle_block.txn.ExtractMatches(tx_hashes, tx_indices) != merkle_block.header.hashMerkleRoot || tx_hashes.size() != 1) { |
| 215 | return false; |
| 216 | } |
| 217 | tx_hash = tx_hashes[0]; |
| 218 | tx_index = tx_indices[0]; |
| 219 | } catch (std::exception&) { |
| 220 | // Invalid encoding of merkle block |
| 221 | return false; |
| 222 | } |
| 223 | return true; |
| 224 | } |
| 225 | |
| 226 | bool CheckParentProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params) |
| 227 | { |
no test coverage detected