Inside Bitcoin
Opening the selected file…
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) 2019-present 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#ifndef BITCOIN_NET_TYPES_H6#define BITCOIN_NET_TYPES_H8#include <cstdint>9#include <map>11class CSubNet;12class UniValue;14class CBanEntry15{16public:17static constexpr int CURRENT_VERSION{1};18int nVersion{CBanEntry::CURRENT_VERSION};19int64_t nCreateTime{0};20int64_t nBanUntil{0};22CBanEntry() = default;24explicit CBanEntry(int64_t nCreateTimeIn)25: nCreateTime{nCreateTimeIn} {}27/**28* Create a ban entry from JSON.29* @param[in] json A JSON representation of a ban entry, as created by `ToJson()`.30* @throw std::runtime_error if the JSON does not have the expected fields.31*/32explicit CBanEntry(const UniValue& json);34/**35* Generate a JSON representation of this ban entry.36* @return JSON suitable for passing to the `CBanEntry(const UniValue&)` constructor.37*/38UniValue ToJson() const;39};41using banmap_t = std::map<CSubNet, CBanEntry>;43/**44* Convert a `banmap_t` object to a JSON array.45* @param[in] bans Bans list to convert.46* @return a JSON array, similar to the one returned by the `listbanned` RPC. Suitable for47* passing to `BanMapFromJson()`.48*/49UniValue BanMapToJson(const banmap_t& bans);51/**52* Convert a JSON array to a `banmap_t` object.53* @param[in] bans_json JSON to convert, must be as returned by `BanMapToJson()`.54* @param[out] bans Bans list to create from the JSON.55* @throws std::runtime_error if the JSON does not have the expected fields or they contain56* unparsable values.57*/58void BanMapFromJson(const UniValue& bans_json, banmap_t& bans);60#endif // BITCOIN_NET_TYPES_H