Changeset View
Changeset View
Standalone View
Standalone View
chronik/chronik-cpp/chronik_bridge.cpp
| Show First 20 Lines • Show All 224 Lines • ▼ Show 20 Lines | for (int height = start; height <= end; height++) { | ||||
| // ones also will not exist. | // ones also will not exist. | ||||
| return chronik::util::ToRustVec<RawBlockHeader>(headers); | return chronik::util::ToRustVec<RawBlockHeader>(headers); | ||||
| } | } | ||||
| headers.push_back({.data = get_block_header(*pindex)}); | headers.push_back({.data = get_block_header(*pindex)}); | ||||
| } | } | ||||
| return chronik::util::ToRustVec<RawBlockHeader>(headers); | return chronik::util::ToRustVec<RawBlockHeader>(headers); | ||||
| } | } | ||||
| rust::Vec<RawBlockHash> | |||||
| ChronikBridge::get_block_hashes_by_range(int start, int end) const { | |||||
| if (start < 0 || end < start) { | |||||
| throw invalid_block_range(); | |||||
| } | |||||
| LOCK(cs_main); | |||||
| std::vector<RawBlockHash> block_hashes; | |||||
| for (int height = start; height <= end; height++) { | |||||
| const CBlockIndex *pindex = m_node.chainman->ActiveChain()[height]; | |||||
| if (!pindex) { | |||||
| throw block_index_not_found(); | |||||
| } | |||||
| block_hashes.push_back( | |||||
| {.data = chronik::util::HashToArray(pindex->GetBlockHash())}); | |||||
| } | |||||
| return chronik::util::ToRustVec<RawBlockHash>(block_hashes); | |||||
| } | |||||
| std::unique_ptr<CBlock> | std::unique_ptr<CBlock> | ||||
| ChronikBridge::load_block(const CBlockIndex &bindex) const { | ChronikBridge::load_block(const CBlockIndex &bindex) const { | ||||
| CBlock block; | CBlock block; | ||||
| if (!m_node.chainman->m_blockman.ReadBlockFromDisk(block, bindex)) { | if (!m_node.chainman->m_blockman.ReadBlockFromDisk(block, bindex)) { | ||||
| throw std::runtime_error("Reading block data failed"); | throw std::runtime_error("Reading block data failed"); | ||||
| } | } | ||||
| return std::make_unique<CBlock>(std::move(block)); | return std::make_unique<CBlock>(std::move(block)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 201 Lines • Show Last 20 Lines | |||||