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.
1// Copyright (c) The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <printer.h>7#include <init.capnp.h>8#include <init.capnp.proxy.h> // NOLINT(misc-include-cleaner) // IWYU pragma: keep10#include <charconv>11#include <cstring>12#include <fstream>13#include <iostream>14#include <kj/async.h>15#include <kj/common.h>16#include <kj/memory.h>17#include <memory>18#include <mp/proxy-io.h>19#include <stdexcept>20#include <string>21#include <system_error>23class PrinterImpl : public Printer24{25public:26void print(const std::string& message) override { std::cout << "mpprinter: " << message << std::endl; }27};29class InitImpl : public Init30{31public:32std::unique_ptr<Printer> makePrinter() override { return std::make_unique<PrinterImpl>(); }33};35static void LogPrint(mp::LogMessage log_data)36{37if (log_data.level == mp::Log::Raise) throw std::runtime_error(log_data.message);38std::ofstream("debug.log", std::ios_base::app) << log_data.message << std::endl;39}41int main(int argc, char** argv)42{43if (argc != 2) {44std::cout << "Usage: mpprinter <fd>\n";45return 1;46}47int fd;48if (std::from_chars(argv[1], argv[1] + strlen(argv[1]), fd).ec != std::errc{}) {49std::cerr << argv[1] << " is not a number or is larger than an int\n";50return 1;51}52mp::EventLoop loop("mpprinter", LogPrint);53std::unique_ptr<Init> init = std::make_unique<InitImpl>();54mp::ServeStream<InitInterface>(loop, fd, *init);55loop.loop();56return 0;57}
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.