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/**********************************************************************2* Copyright (c) 2018 Pieter Wuille, Greg Maxwell, Gleb Naumenko *3* Distributed under the MIT software license, see the accompanying *4* file LICENSE or http://www.opensource.org/licenses/mit-license.php.*5**********************************************************************/7#include <stdio.h>8#include <assert.h>9#include "../include/minisketch.h"11int main(void) {13minisketch *sketch_a = minisketch_create(12, 0, 4);15for (int i = 3000; i < 3010; ++i) {16minisketch_add_uint64(sketch_a, i);17}19size_t sersize = minisketch_serialized_size(sketch_a);20assert(sersize == 12 * 4 / 8); // 4 12-bit values is 6 bytes.21unsigned char *buffer_a = malloc(sersize);22minisketch_serialize(sketch_a, buffer_a);23minisketch_destroy(sketch_a);25minisketch *sketch_b = minisketch_create(12, 0, 4); // Bob's own sketch26for (int i = 3002; i < 3012; ++i) {27minisketch_add_uint64(sketch_b, i);28}30sketch_a = minisketch_create(12, 0, 4); // Alice's sketch31minisketch_deserialize(sketch_a, buffer_a); // Load Alice's sketch32free(buffer_a);34// Merge the elements from sketch_a into sketch_b. The result is a sketch_b35// which contains all elements that occurred in Alice's or Bob's sets, but not36// in both.37minisketch_merge(sketch_b, sketch_a);39uint64_t differences[4];40ssize_t num_differences = minisketch_decode(sketch_b, 4, differences);41minisketch_destroy(sketch_a);42minisketch_destroy(sketch_b);43if (num_differences < 0) {44printf("More than 4 differences!\n");45} else {46ssize_t i;47for (i = 0; i < num_differences; ++i) {48printf("%u is in only one of the two sets\n", (unsigned)differences[i]);49}50}51}
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.