Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1251MAKE_RANGE_METHOD(Entries, ChainView, &ChainView::CountEntries, &ChainView::GetByHeight, *this)1252};1254template <typename Derived>1255class CoinApi1256{1257private:1258auto impl() const1259{1260return static_cast<const Derived*>(this)->get();1261}1263friend Derived;1264CoinApi() = default;1266public:1267uint32_t GetConfirmationHeight() const { return btck_coin_confirmation_height(impl()); }1269bool IsCoinbase() const { return btck_coin_is_coinbase(impl()) == 1; }1271TransactionOutputView GetOutput() const1272{1273return TransactionOutputView{btck_coin_get_output(impl())};1274}1275};1277class CoinView : public View<btck_Coin>, public CoinApi<CoinView>1278{1279public:1280explicit CoinView(const btck_Coin* ptr) : View{ptr} {}1281};1283class Coin : public Handle<btck_Coin, btck_coin_copy, btck_coin_destroy>, public CoinApi<Coin>1284{1285public:1286Coin(btck_Coin* coin) : Handle{coin} {}1288Coin(const CoinView& view) : Handle{view} {}1289};1291template <typename Derived>1292class TransactionSpentOutputsApi1293{1294private:1295auto impl() const1296{1297return static_cast<const Derived*>(this)->get();1298}1300friend Derived;1301TransactionSpentOutputsApi() = default;1303public:1304size_t Count() const1305{1306return btck_transaction_spent_outputs_count(impl());1307}1309CoinView GetCoin(size_t index) const1310{1311return CoinView{btck_transaction_spent_outputs_get_coin_at(impl(), index)};1312}1314MAKE_RANGE_METHOD(Coins, Derived, &TransactionSpentOutputsApi<Derived>::Count, &TransactionSpentOutputsApi<Derived>::GetCoin, *static_cast<const Derived*>(this))1315};1317class TransactionSpentOutputsView : public View<btck_TransactionSpentOutputs>, public TransactionSpentOutputsApi<TransactionSpentOutputsView>1318{1319public:1320explicit TransactionSpentOutputsView(const btck_TransactionSpentOutputs* ptr) : View{ptr} {}1321};1323class TransactionSpentOutputs : public Handle<btck_TransactionSpentOutputs, btck_transaction_spent_outputs_copy, btck_transaction_spent_outputs_destroy>,1324public TransactionSpentOutputsApi<TransactionSpentOutputs>1325{1326public:1327TransactionSpentOutputs(btck_TransactionSpentOutputs* transaction_spent_outputs) : Handle{transaction_spent_outputs} {}1329TransactionSpentOutputs(const TransactionSpentOutputsView& view) : Handle{view} {}1330};1332class BlockSpentOutputs : public Handle<btck_BlockSpentOutputs, btck_block_spent_outputs_copy, btck_block_spent_outputs_destroy>1333{1334public:1335BlockSpentOutputs(btck_BlockSpentOutputs* block_spent_outputs)1336: Handle{block_spent_outputs}1337{1338}1340size_t Count() const1341{1342return btck_block_spent_outputs_count(get());1343}1345TransactionSpentOutputsView GetTxSpentOutputs(size_t tx_undo_index) const1346{1347return TransactionSpentOutputsView{btck_block_spent_outputs_get_transaction_spent_outputs_at(get(), tx_undo_index)};1348}1350MAKE_RANGE_METHOD(TxsSpentOutputs, BlockSpentOutputs, &BlockSpentOutputs::Count, &BlockSpentOutputs::GetTxSpentOutputs, *this)1351};1353class ChainMan : UniqueHandle<btck_ChainstateManager, btck_chainstate_manager_destroy>1354{1355public:1356ChainMan(const Context& context, const ChainstateManagerOptions& chainman_opts)1357: UniqueHandle{btck_chainstate_manager_create(chainman_opts.get())}1358{1359}1361bool ImportBlocks(const std::span<const std::string> paths)1362{1363std::vector<const char*> c_paths;1364std::vector<size_t> c_paths_lens;1365c_paths.reserve(paths.size());1366c_paths_lens.reserve(paths.size());1367for (const auto& path : paths) {1368c_paths.push_back(path.c_str());1369c_paths_lens.push_back(path.length());1370}1372return btck_chainstate_manager_import_blocks(get(), c_paths.data(), c_paths_lens.data(), c_paths.size()) == 0;1373}1375bool ProcessBlock(const Block& block, bool* new_block)1376{1377int _new_block;1378int res = btck_chainstate_manager_process_block(get(), block.get(), &_new_block);1379if (new_block) *new_block = _new_block == 1;1380return res == 0;1381}1383BlockValidationState ProcessBlockHeader(const BlockHeader& header)1384{1385auto state = btck_chainstate_manager_process_block_header(get(), header.get());1386return BlockValidationState{state};1387}1389ChainView GetChain() const1390{1391return ChainView{btck_chainstate_manager_get_active_chain(get())};1392}1394std::optional<BlockTreeEntry> GetBlockTreeEntry(const BlockHash& block_hash) const1395{1396auto entry{btck_chainstate_manager_get_block_tree_entry_by_hash(get(), block_hash.get())};1397if (!entry) return std::nullopt;1398return entry;1399}1401BlockTreeEntry GetBestEntry() const1402{1403return btck_chainstate_manager_get_best_entry(get());1404}1406std::optional<Block> ReadBlock(const BlockTreeEntry& entry) const1407{1408auto block{btck_block_read(get(), entry.get())};1409if (!block) return std::nullopt;1410return block;1411}1413BlockSpentOutputs ReadBlockSpentOutputs(const BlockTreeEntry& entry) const1414{1415return btck_block_spent_outputs_read(get(), entry.get());1416}1417};1419inline void set_mock_time(std::chrono::seconds timestamp)1420{1421if (btck_set_mock_time(timestamp.count()) != 0) {1422throw std::runtime_error("timestamp out of range");1423}1424}1426} // namespace btck1428#endif // BITCOIN_KERNEL_BITCOINKERNEL_WRAPPER_H