| 210 | } |
| 211 | |
| 212 | bool BlockFilterIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex) |
| 213 | { |
| 214 | CBlockUndo block_undo; |
| 215 | uint256 prev_header; |
| 216 | |
| 217 | if (pindex->nHeight > 0) { |
| 218 | if (!UndoReadFromDisk(block_undo, pindex)) { |
| 219 | return false; |
| 220 | } |
| 221 | |
| 222 | std::pair<uint256, DBVal> read_out; |
| 223 | if (!m_db->Read(DBHeightKey(pindex->nHeight - 1), read_out)) { |
| 224 | return false; |
| 225 | } |
| 226 | |
| 227 | uint256 expected_block_hash = pindex->pprev->GetBlockHash(); |
| 228 | if (read_out.first != expected_block_hash) { |
| 229 | return error("%s: previous block header belongs to unexpected block %s; expected %s", |
| 230 | __func__, read_out.first.ToString(), expected_block_hash.ToString()); |
| 231 | } |
| 232 | |
| 233 | prev_header = read_out.second.header; |
| 234 | } |
| 235 | |
| 236 | BlockFilter filter(m_filter_type, block, block_undo); |
| 237 | |
| 238 | size_t bytes_written = WriteFilterToDisk(m_next_filter_pos, filter); |
| 239 | if (bytes_written == 0) return false; |
| 240 | |
| 241 | std::pair<uint256, DBVal> value; |
| 242 | value.first = pindex->GetBlockHash(); |
| 243 | value.second.hash = filter.GetHash(); |
| 244 | value.second.header = filter.ComputeHeader(prev_header); |
| 245 | value.second.pos = m_next_filter_pos; |
| 246 | |
| 247 | if (!m_db->Write(DBHeightKey(pindex->nHeight), value)) { |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | m_next_filter_pos.nPos += bytes_written; |
| 252 | return true; |
| 253 | } |
| 254 | |
| 255 | static bool CopyHeightIndexToHashIndex(CDBIterator& db_it, CDBBatch& batch, |
| 256 | const std::string& index_name, |
nothing calls this directly
no test coverage detected