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.
1751self.block_transactions.deserialize(f)1753def serialize(self):1754r = b""1755r += self.block_transactions.serialize()1756return r1758def __repr__(self):1759return "msg_blocktxn(block_transactions=%s)" % (repr(self.block_transactions))1762class msg_no_witness_blocktxn(msg_blocktxn):1763__slots__ = ()1765def serialize(self):1766return self.block_transactions.serialize(with_witness=False)1769class msg_getcfilters:1770__slots__ = ("filter_type", "start_height", "stop_hash")1771msgtype = b"getcfilters"1773def __init__(self, filter_type=None, start_height=None, stop_hash=None):1774self.filter_type = filter_type1775self.start_height = start_height1776self.stop_hash = stop_hash1778def deserialize(self, f):1779self.filter_type = int.from_bytes(f.read(1), "little")1780self.start_height = int.from_bytes(f.read(4), "little")1781self.stop_hash = deser_uint256(f)1783def serialize(self):1784r = b""1785r += self.filter_type.to_bytes(1, "little")1786r += self.start_height.to_bytes(4, "little")1787r += ser_uint256(self.stop_hash)1788return r1790def __repr__(self):1791return "msg_getcfilters(filter_type={:#x}, start_height={}, stop_hash={:x})".format(1792self.filter_type, self.start_height, self.stop_hash)1794class msg_cfilter:1795__slots__ = ("filter_type", "block_hash", "filter_data")1796msgtype = b"cfilter"1798def __init__(self, filter_type=None, block_hash=None, filter_data=None):1799self.filter_type = filter_type1800self.block_hash = block_hash1801self.filter_data = filter_data1803def deserialize(self, f):1804self.filter_type = int.from_bytes(f.read(1), "little")1805self.block_hash = deser_uint256(f)1806self.filter_data = deser_string(f)1808def serialize(self):1809r = b""1810r += self.filter_type.to_bytes(1, "little")1811r += ser_uint256(self.block_hash)1812r += ser_string(self.filter_data)1813return r1815def __repr__(self):1816return "msg_cfilter(filter_type={:#x}, block_hash={:x})".format(1817self.filter_type, self.block_hash)1819class msg_getcfheaders:1820__slots__ = ("filter_type", "start_height", "stop_hash")1821msgtype = b"getcfheaders"1823def __init__(self, filter_type=None, start_height=None, stop_hash=None):1824self.filter_type = filter_type1825self.start_height = start_height1826self.stop_hash = stop_hash1828def deserialize(self, f):1829self.filter_type = int.from_bytes(f.read(1), "little")1830self.start_height = int.from_bytes(f.read(4), "little")1831self.stop_hash = deser_uint256(f)1833def serialize(self):1834r = b""1835r += self.filter_type.to_bytes(1, "little")1836r += self.start_height.to_bytes(4, "little")1837r += ser_uint256(self.stop_hash)1838return r1840def __repr__(self):1841return "msg_getcfheaders(filter_type={:#x}, start_height={}, stop_hash={:x})".format(1842self.filter_type, self.start_height, self.stop_hash)1844class msg_cfheaders:1845__slots__ = ("filter_type", "stop_hash", "prev_header", "hashes")1846msgtype = b"cfheaders"1848def __init__(self, filter_type=None, stop_hash=None, prev_header=None, hashes=None):1849self.filter_type = filter_type1850self.stop_hash = stop_hash1851self.prev_header = prev_header1852self.hashes = hashes1854def deserialize(self, f):1855self.filter_type = int.from_bytes(f.read(1), "little")1856self.stop_hash = deser_uint256(f)1857self.prev_header = deser_uint256(f)1858self.hashes = deser_uint256_vector(f)1860def serialize(self):1861r = b""1862r += self.filter_type.to_bytes(1, "little")1863r += ser_uint256(self.stop_hash)1864r += ser_uint256(self.prev_header)1865r += ser_uint256_vector(self.hashes)1866return r1868def __repr__(self):1869return "msg_cfheaders(filter_type={:#x}, stop_hash={:x})".format(1870self.filter_type, self.stop_hash)1872class msg_getcfcheckpt:1873__slots__ = ("filter_type", "stop_hash")1874msgtype = b"getcfcheckpt"1876def __init__(self, filter_type=None, stop_hash=None):1877self.filter_type = filter_type1878self.stop_hash = stop_hash1880def deserialize(self, f):1881self.filter_type = int.from_bytes(f.read(1), "little")1882self.stop_hash = deser_uint256(f)1884def serialize(self):1885r = b""1886r += self.filter_type.to_bytes(1, "little")1887r += ser_uint256(self.stop_hash)1888return r1890def __repr__(self):1891return "msg_getcfcheckpt(filter_type={:#x}, stop_hash={:x})".format(1892self.filter_type, self.stop_hash)1894class msg_cfcheckpt:1895__slots__ = ("filter_type", "stop_hash", "headers")1896msgtype = b"cfcheckpt"1898def __init__(self, filter_type=None, stop_hash=None, headers=None):1899self.filter_type = filter_type1900self.stop_hash = stop_hash1901self.headers = headers1903def deserialize(self, f):1904self.filter_type = int.from_bytes(f.read(1), "little")1905self.stop_hash = deser_uint256(f)1906self.headers = deser_uint256_vector(f)1908def serialize(self):1909r = b""1910r += self.filter_type.to_bytes(1, "little")1911r += ser_uint256(self.stop_hash)1912r += ser_uint256_vector(self.headers)1913return r1915def __repr__(self):1916return "msg_cfcheckpt(filter_type={:#x}, stop_hash={:x})".format(1917self.filter_type, self.stop_hash)1919class msg_sendtxrcncl:1920__slots__ = ("version", "salt")1921msgtype = b"sendtxrcncl"1923def __init__(self):1924self.version = 01925self.salt = 01927def deserialize(self, f):1928self.version = int.from_bytes(f.read(4), "little")1929self.salt = int.from_bytes(f.read(8), "little")1931def serialize(self):1932r = b""1933r += self.version.to_bytes(4, "little")1934r += self.salt.to_bytes(8, "little")1935return r1937def __repr__(self):1938return "msg_sendtxrcncl(version=%lu, salt=%lu)" %\1939(self.version, self.salt)1941class msg_feature:1942"""FEATURE message for negotiating optional features."""1943__slots__ = ("feature_id", "feature_data")1944msgtype = b"feature"1946def __init__(self, feature_id="", feature_data=b""):1947self.feature_id = feature_id1948self.feature_data = feature_data1950def deserialize(self, f):1951self.feature_id = deser_string(f).decode()1952self.feature_data = deser_string(f)1954def serialize(self):1955r = ser_string(self.feature_id.encode())1956r += ser_string(self.feature_data)1957return r1959def __repr__(self):1960return f"msg_feature(feature_id={self.feature_id}, data={self.feature_data.hex()})"1963class TestFrameworkScript(unittest.TestCase):1964def test_addrv2_encode_decode(self):1965def check_addrv2(ip, net):1966addr = CAddress()1967addr.net, addr.ip = net, ip1968ser = addr.serialize_v2()1969actual = CAddress()1970actual.deserialize_v2(BytesIO(ser))1971self.assertEqual(actual, addr)1973check_addrv2("1.65.195.98", CAddress.NET_IPV4)1974check_addrv2("2001:41f0::62:6974:636f:696e", CAddress.NET_IPV6)1975check_addrv2("2bqghnldu6mcug4pikzprwhtjjnsyederctvci6klcwzepnjd46ikjyd.onion", CAddress.NET_TORV3)1976check_addrv2("255fhcp6ajvftnyo7bwz3an3t4a4brhopm3bamyh2iu5r3gnr2rq.b32.i2p", CAddress.NET_I2P)1977check_addrv2("fc32:17ea:e415:c3bf:9808:149d:b5a2:c9aa", CAddress.NET_CJDNS)1979def test_varint_encode_decode(self):1980def check_varint(num, expected_encoding_hex):1981expected_encoding = bytes.fromhex(expected_encoding_hex)1982self.assertEqual(ser_varint(num), expected_encoding)1983self.assertEqual(deser_varint(BytesIO(expected_encoding)), num)1985# test cases from serialize_tests.cpp:varint_bitpatterns1986check_varint(0, "00")1987check_varint(0x7f, "7f")1988check_varint(0x80, "8000")1989check_varint(0x1234, "a334")1990check_varint(0xffff, "82fe7f")1991check_varint(0x123456, "c7e756")1992check_varint(0x80123456, "86ffc7e756")1993check_varint(0xffffffff, "8efefefe7f")1994check_varint(0xffffffffffffffff, "80fefefefefefefefe7f")
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.