Changeset View
Changeset View
Standalone View
Standalone View
chronik/chronik-cpp/chronik_bridge.cpp
Show First 20 Lines • Show All 206 Lines • ▼ Show 20 Lines | ChronikBridge::load_block_undo(const CBlockIndex &bindex) const { | ||||
if (bindex.nHeight > 0) { | if (bindex.nHeight > 0) { | ||||
if (!node::UndoReadFromDisk(block_undo, &bindex)) { | if (!node::UndoReadFromDisk(block_undo, &bindex)) { | ||||
throw std::runtime_error("Reading block undo data failed"); | throw std::runtime_error("Reading block undo data failed"); | ||||
} | } | ||||
} | } | ||||
return std::make_unique<CBlockUndo>(std::move(block_undo)); | return std::make_unique<CBlockUndo>(std::move(block_undo)); | ||||
} | } | ||||
Tx ChronikBridge::load_tx(uint32_t file_num, uint32_t data_pos, | |||||
uint32_t undo_pos) const { | |||||
CMutableTransaction tx; | |||||
CTxUndo txundo{}; | |||||
const bool isCoinbase = undo_pos == 0; | |||||
if (!node::ReadTxFromDisk(tx, FlatFilePos(file_num, data_pos))) { | |||||
throw std::runtime_error("Reading tx data from disk failed"); | |||||
} | |||||
if (!isCoinbase) { | |||||
if (!node::ReadTxUndoFromDisk(txundo, | |||||
FlatFilePos(file_num, undo_pos))) { | |||||
throw std::runtime_error("Reading tx undo data from disk failed"); | |||||
} | |||||
} | |||||
return BridgeTx(isCoinbase, CTransaction(std::move(tx)), txundo.vprevout); | |||||
} | |||||
rust::Vec<uint8_t> ChronikBridge::load_raw_tx(uint32_t file_num, | |||||
uint32_t data_pos) const { | |||||
CMutableTransaction tx; | |||||
if (!node::ReadTxFromDisk(tx, FlatFilePos(file_num, data_pos))) { | |||||
throw std::runtime_error("Reading tx data from disk failed"); | |||||
} | |||||
CDataStream raw_tx{SER_NETWORK, PROTOCOL_VERSION}; | |||||
raw_tx << tx; | |||||
return chronik::util::ToRustVec<uint8_t>(raw_tx); | |||||
} | |||||
Tx bridge_tx(const CTransaction &tx, const std::vector<::Coin> &spent_coins) { | Tx bridge_tx(const CTransaction &tx, const std::vector<::Coin> &spent_coins) { | ||||
return BridgeTx(false, tx, spent_coins); | return BridgeTx(false, tx, spent_coins); | ||||
} | } | ||||
const CBlockIndex &ChronikBridge::find_fork(const CBlockIndex &index) const { | const CBlockIndex &ChronikBridge::find_fork(const CBlockIndex &index) const { | ||||
const CBlockIndex *fork = WITH_LOCK( | const CBlockIndex *fork = WITH_LOCK( | ||||
cs_main, | cs_main, | ||||
return m_node.chainman->ActiveChainstate().m_chain.FindFork(&index)); | return m_node.chainman->ActiveChainstate().m_chain.FindFork(&index)); | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
chronik_bridge::Block bridge_block(const CBlock &block, | chronik_bridge::Block bridge_block(const CBlock &block, | ||||
const CBlockUndo &block_undo, | const CBlockUndo &block_undo, | ||||
const CBlockIndex &bindex) { | const CBlockIndex &bindex) { | ||||
return BridgeBlock(block, block_undo, bindex); | return BridgeBlock(block, block_undo, bindex); | ||||
} | } | ||||
Tx load_tx(uint32_t file_num, uint32_t data_pos, uint32_t undo_pos) { | |||||
CMutableTransaction tx; | |||||
CTxUndo txundo{}; | |||||
const bool isCoinbase = undo_pos == 0; | |||||
if (!node::ReadTxFromDisk(tx, FlatFilePos(file_num, data_pos))) { | |||||
throw std::runtime_error("Reading tx data from disk failed"); | |||||
} | |||||
if (!isCoinbase) { | |||||
if (!node::ReadTxUndoFromDisk(txundo, | |||||
FlatFilePos(file_num, undo_pos))) { | |||||
throw std::runtime_error("Reading tx undo data from disk failed"); | |||||
} | |||||
} | |||||
return BridgeTx(isCoinbase, CTransaction(std::move(tx)), txundo.vprevout); | |||||
} | |||||
rust::Vec<uint8_t> load_raw_tx(uint32_t file_num, uint32_t data_pos) { | |||||
CMutableTransaction tx; | |||||
if (!node::ReadTxFromDisk(tx, FlatFilePos(file_num, data_pos))) { | |||||
throw std::runtime_error("Reading tx data from disk failed"); | |||||
} | |||||
CDataStream raw_tx{SER_NETWORK, PROTOCOL_VERSION}; | |||||
raw_tx << tx; | |||||
return chronik::util::ToRustVec<uint8_t>(raw_tx); | |||||
} | |||||
BlockInfo get_block_info(const CBlockIndex &bindex) { | BlockInfo get_block_info(const CBlockIndex &bindex) { | ||||
return { | return { | ||||
.hash = chronik::util::HashToArray(bindex.GetBlockHash()), | .hash = chronik::util::HashToArray(bindex.GetBlockHash()), | ||||
.height = bindex.nHeight, | .height = bindex.nHeight, | ||||
}; | }; | ||||
} | } | ||||
const CBlockIndex &get_block_ancestor(const CBlockIndex &index, | const CBlockIndex &get_block_ancestor(const CBlockIndex &index, | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |