├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .vscode ├── launch.json ├── settings.json └── tasks.json ├── AUTHORS ├── COPYING ├── ChangeLog ├── INSTALL ├── Makefile.am ├── NEWS ├── README ├── README.md ├── autogen.sh ├── build.cmd ├── builds ├── cmake │ ├── CMakeLists.txt │ ├── CMakePresets.json │ └── modules │ │ └── FindBitcoin-System.cmake ├── msvc │ ├── .gitignore │ ├── build │ │ ├── build_all.bat │ │ ├── build_base.bat │ │ └── nuget_all.bat │ ├── debug.natvis │ ├── nuget.config │ ├── properties │ │ ├── Arm.props │ │ ├── Arm64.props │ │ ├── Common.props │ │ ├── DLL.props │ │ ├── Debug.props │ │ ├── DebugDEXE.props │ │ ├── DebugDLL.props │ │ ├── DebugLEXE.props │ │ ├── DebugLIB.props │ │ ├── DebugLTCG.props │ │ ├── DebugSEXE.props │ │ ├── EXE.props │ │ ├── LIB.props │ │ ├── LTCG.props │ │ ├── Link.props │ │ ├── Messages.props │ │ ├── Output.props │ │ ├── Release.props │ │ ├── ReleaseDEXE.props │ │ ├── ReleaseDLL.props │ │ ├── ReleaseLEXE.props │ │ ├── ReleaseLIB.props │ │ ├── ReleaseLTCG.props │ │ ├── ReleaseSEXE.props │ │ ├── Win32.props │ │ └── x64.props │ └── vs2022 │ │ ├── libbitcoin-database-test │ │ ├── libbitcoin-database-test.props │ │ ├── libbitcoin-database-test.vcxproj │ │ ├── libbitcoin-database-test.vcxproj.filters │ │ └── packages.config │ │ ├── libbitcoin-database-tools │ │ ├── libbitcoin-database-tools.props │ │ ├── libbitcoin-database-tools.vcxproj │ │ ├── libbitcoin-database-tools.vcxproj.filters │ │ └── packages.config │ │ ├── libbitcoin-database.import.props │ │ ├── libbitcoin-database.import.xml │ │ ├── libbitcoin-database.sln │ │ ├── libbitcoin-database │ │ ├── libbitcoin-database.props │ │ ├── libbitcoin-database.vcxproj │ │ ├── libbitcoin-database.vcxproj.filters │ │ └── packages.config │ │ ├── libbitcoin-system.import.props │ │ └── libbitcoin-system.import.xml └── vscode │ └── database.code-workspace ├── configure.ac ├── include └── bitcoin │ ├── database.hpp │ └── database │ ├── boost.hpp │ ├── define.hpp │ ├── error.hpp │ ├── file │ ├── file.hpp │ ├── rotator.hpp │ └── utilities.hpp │ ├── impl │ ├── memory │ │ └── accessor.ipp │ ├── primitives │ │ ├── arrayhead.ipp │ │ ├── arraymap.ipp │ │ ├── hashhead.ipp │ │ ├── hashmap.ipp │ │ ├── iterator.ipp │ │ ├── keys.ipp │ │ ├── linkage.ipp │ │ ├── manager.ipp │ │ └── nomap.ipp │ ├── query │ │ ├── archive_read.ipp │ │ ├── archive_write.ipp │ │ ├── confirm.ipp │ │ ├── consensus.ipp │ │ ├── context.ipp │ │ ├── extent.ipp │ │ ├── height.ipp │ │ ├── initialize.ipp │ │ ├── network.ipp │ │ ├── objects.ipp │ │ ├── optional.ipp │ │ ├── query.ipp │ │ ├── translate.ipp │ │ └── validate.ipp │ └── store.ipp │ ├── locks │ ├── file_lock.hpp │ ├── flush_lock.hpp │ ├── interprocess_lock.hpp │ └── locks.hpp │ ├── memory │ ├── accessor.hpp │ ├── finalizer.hpp │ ├── interfaces │ │ ├── memory.hpp │ │ └── storage.hpp │ ├── map.hpp │ ├── memory.hpp │ ├── reader.hpp │ ├── streamers.hpp │ └── utilities.hpp │ ├── primitives │ ├── arrayhead.hpp │ ├── arraymap.hpp │ ├── hashhead.hpp │ ├── hashmap.hpp │ ├── iterator.hpp │ ├── keys.hpp │ ├── linkage.hpp │ ├── manager.hpp │ ├── nomap.hpp │ └── primitives.hpp │ ├── query.hpp │ ├── settings.hpp │ ├── store.hpp │ ├── tables │ ├── archives │ │ ├── header.hpp │ │ ├── input.hpp │ │ ├── ins.hpp │ │ ├── output.hpp │ │ ├── outs.hpp │ │ ├── point.hpp │ │ ├── transaction.hpp │ │ └── txs.hpp │ ├── association.hpp │ ├── associations.hpp │ ├── caches │ │ ├── duplicate.hpp │ │ ├── prevout.hpp │ │ ├── validated_bk.hpp │ │ └── validated_tx.hpp │ ├── context.hpp │ ├── event.hpp │ ├── indexes │ │ ├── height.hpp │ │ └── strong_tx.hpp │ ├── names.hpp │ ├── optionals │ │ ├── address.hpp │ │ ├── filter_bk.hpp │ │ └── filter_tx.hpp │ ├── point_set.hpp │ ├── schema.hpp │ ├── states.hpp │ ├── table.hpp │ └── tables.hpp │ └── version.hpp ├── install-cmake.sh ├── install-cmakepresets.sh ├── install.sh ├── libbitcoin-database-test_runner.sh ├── libbitcoin-database.pc.in ├── m4 ├── .gitignore ├── ax_boost_base.m4 ├── ax_boost_unit_test_framework.m4 ├── ax_check_compile_flag.m4 ├── ax_check_link_flag.m4 ├── ax_check_preproc_flag.m4 └── ax_cxx_compile_stdcxx.m4 ├── src ├── error.cpp ├── file │ ├── rotator.cpp │ └── utilities.cpp ├── locks │ ├── file_lock.cpp │ ├── flush_lock.cpp │ └── interprocess_lock.cpp ├── memory │ ├── map.cpp │ ├── mman-win32 │ │ ├── mman.cpp │ │ └── mman.hpp │ └── utilities.cpp └── settings.cpp ├── test ├── error.cpp ├── file │ ├── rotator.cpp │ └── utilities.cpp ├── locks │ ├── file_lock.cpp │ ├── flush_lock.cpp │ └── interprocess_lock.cpp ├── main.cpp ├── memory │ ├── accessor.cpp │ ├── map.cpp │ └── utilities.cpp ├── mocks │ ├── blocks.cpp │ ├── blocks.hpp │ ├── chunk_storage.cpp │ ├── chunk_storage.hpp │ ├── chunk_store.hpp │ └── map_store.hpp ├── primitives │ ├── arrayhead.cpp │ ├── arraymap.cpp │ ├── hashhead.cpp │ ├── hashmap.cpp │ ├── iterator.cpp │ ├── keys.cpp │ ├── linkage.cpp │ ├── manager.cpp │ └── nomap.cpp ├── query │ ├── archive_read.cpp │ ├── archive_write.cpp │ ├── confirm.cpp │ ├── consensus.cpp │ ├── context.cpp │ ├── extent.cpp │ ├── height.cpp │ ├── initialize.cpp │ ├── network.cpp │ ├── objects.cpp │ ├── optional.cpp │ ├── translate.cpp │ └── validate.cpp ├── settings.cpp ├── store.cpp ├── tables │ ├── archives │ │ ├── header.cpp │ │ ├── input.cpp │ │ ├── output.cpp │ │ ├── point.cpp │ │ ├── puts.cpp │ │ ├── transaction.cpp │ │ └── txs.cpp │ ├── caches │ │ ├── duplicate.cpp │ │ ├── prevout.cpp │ │ ├── validated_bk.cpp │ │ └── validated_tx.cpp │ ├── indexes │ │ ├── height.cpp │ │ └── strong_tx.cpp │ └── optional │ │ ├── address.cpp │ │ ├── filter_bk.cpp │ │ └── filter_tx.cpp ├── test.cpp └── test.hpp └── tools └── initchain └── initchain.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | .deps 2 | .libs 3 | *.la 4 | *.lo 5 | *.o 6 | *.pyc 7 | Makefile 8 | Makefile.in 9 | libbitcoin-database.pc 10 | 11 | bin 12 | obj 13 | build 14 | .*.swp 15 | *~ 16 | /*.kdev4 17 | /.cproject 18 | /.project 19 | /.settings 20 | /nbproject 21 | 22 | /aclocal.m4 23 | /autom4te.cache 24 | /build-aux 25 | /config.* 26 | /configure 27 | /libtool 28 | .dirstamp 29 | 30 | *.vsidx 31 | *.lock 32 | /.vs 33 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "(gdb) Launch", 9 | "type": "cppdbg", 10 | "request": "launch", 11 | "program": "${workspaceFolder}/obj/nix-gnu-debug-static/libbitcoin-database-test", 12 | "args": [], 13 | "stopAtEntry": false, 14 | "cwd": "${workspaceFolder}/obj/nix-gnu-debug-static", 15 | "environment": [], 16 | "externalConsole": false, 17 | "MIMode": "gdb", 18 | "setupCommands": [ 19 | { 20 | "description": "Enable pretty-printing for gdb", 21 | "text": "-enable-pretty-printing", 22 | "ignoreFailures": true 23 | }, 24 | { 25 | "description": "Set Disassembly Flavor to Intel", 26 | "text": "-gdb-set disassembly-flavor intel", 27 | "ignoreFailures": true 28 | } 29 | ] 30 | } 31 | ] 32 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cmake.sourceDirectory": "${workspaceFolder}/builds/cmake", 3 | "cmake.useCMakePresets": "always" 4 | } 5 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "type": "cmake", 6 | "label": "CMake: build", 7 | "command": "build", 8 | "targets": [ 9 | "all" 10 | ], 11 | "preset": "${command:cmake.activeBuildPresetName}", 12 | "group": "build", 13 | "problemMatcher": [], 14 | "detail": "CMake template build task" 15 | }, 16 | { 17 | "type": "cmake", 18 | "label": "CMake: clean", 19 | "command": "clean", 20 | "preset": "${command:cmake.activeBuildPresetName}", 21 | "problemMatcher": [], 22 | "detail": "CMake template clean task" 23 | }, 24 | { 25 | "type": "cmake", 26 | "label": "CMake: install", 27 | "command": "install", 28 | "preset": "${command:cmake.activeBuildPresetName}", 29 | "problemMatcher": [], 30 | "detail": "CMake template install task" 31 | } 32 | ] 33 | } -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | commits libbitcoin developers 2 | -------------------------------------------- 3 | 918 Eric Voskuil (evoskuil) 4 | 262 Amir Taaki (genjix) 5 | 68 Phillip Mienk (pmienk) 6 | 5 Neill Miller (thecodefactory) 7 | 3 William Swanson (swansontec) 8 | 1 Noel Maersk (veox) 9 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | Use command 'git log --oneline --decorate' for latest change log. 2 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | See https://libbitcoin.org -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | See README.md -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This branch is not usable in its current state. Please see [version3](https://github.com/libbitcoin/libbitcoin-database/tree/version3) for the latest functional branch. 2 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ############################################################################### 3 | # Copyright (c) 2014-2025 libbitcoin-database developers (see COPYING). 4 | # 5 | # GENERATED SOURCE CODE, DO NOT EDIT EXCEPT EXPERIMENTALLY 6 | # 7 | ############################################################################### 8 | 9 | autoreconf -i 10 | -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | REM ########################################################################### 2 | REM # Copyright (c) 2014-2025 libbitcoin-database developers (see COPYING). 3 | REM # 4 | REM # GENERATED SOURCE CODE, DO NOT EDIT EXCEPT EXPERIMENTALLY 5 | REM # 6 | REM ########################################################################### 7 | @echo off 8 | SETLOCAL ENABLEEXTENSIONS 9 | SET "parent=%~dp0" 10 | SET "relative_path_base=%~1" 11 | call cd /d "%relative_path_base%" 12 | SET "path_base=%cd%" 13 | SET "nuget_pkg_path=%path_base%\.nuget\packages" 14 | SET "msbuild_args=/verbosity:minimal /p:Platform=%~2 /p:Configuration=%~3 /p:PreferredToolArchitecture=%~4" 15 | SET "proj_version=%~5" 16 | SET "msbuild_exe=msbuild" 17 | IF EXIST "%~6" SET "msbuild_exe=%~6" 18 | 19 | call :pending "Build initialized..." 20 | IF NOT EXIST "%nuget_pkg_path%" ( 21 | call mkdir "%nuget_pkg_path%" 22 | IF %ERRORLEVEL% NEQ 0 ( 23 | call :failure "mkdir %nuget_pkg_path% failed." 24 | exit /b 1 25 | ) 26 | ) 27 | 28 | call :init libbitcoin libbitcoin-system master 29 | IF %ERRORLEVEL% NEQ 0 ( 30 | call :failure "Initializing repository libbitcoin libbitcoin-system master failed." 31 | exit /b 1 32 | ) 33 | call :bld_repo libbitcoin-database 34 | IF %ERRORLEVEL% NEQ 0 ( 35 | call :failure "Building libbitcoin-database failed." 36 | exit /b 1 37 | ) 38 | 39 | call :success "Build complete." 40 | exit /b 0 41 | 42 | 43 | 44 | :init 45 | call :pending "Initializing repository %~1/%~2/%~3..." 46 | IF NOT EXIST "%path_base%\%~2" ( 47 | call git clone -q --branch=%~3 https://github.com/%~1/%~2 "%path_base%\%~2" 48 | IF %ERRORLEVEL% NEQ 0 ( 49 | call :failure "git clone %~1/%~2 failed." 50 | exit /b 1 51 | ) 52 | ) ELSE ( 53 | call :success "%path_base%\%~2 exists, assuming valid clone." 54 | ) 55 | 56 | call :bld_proj %~2 57 | IF %ERRORLEVEL% NEQ 0 ( 58 | call :failure "Building project %~2 failed." 59 | exit /b 1 60 | ) 61 | call :success "Initialization of %~1/%~2/%~3 complete." 62 | exit /b 0 63 | 64 | :bld_repo 65 | call :pending "Building respository %~1..." 66 | call :depends "%~1" 67 | IF %ERRORLEVEL% NEQ 0 ( 68 | call :failure "Initializing dependencies %~1 failed." 69 | exit /b 1 70 | ) 71 | call cd /d "%path_base%\%~1\builds\msvc\%proj_version%" 72 | call "%msbuild_exe%" %msbuild_args% %~1.sln /p:PreBuildEventUseInBuild=false /p:PostBuildEventUseInBuild=false 73 | IF %ERRORLEVEL% NEQ 0 ( 74 | call :failure "%msbuild_exe% %msbuild_args% %~1.sln failed." 75 | exit /b 1 76 | ) 77 | call :success "Building repository %~1 execution complete." 78 | call cd /d "%path_base%" 79 | exit /b 0 80 | 81 | :bld_proj 82 | call :pending "Building respository project %~1..." 83 | call :depends %~1 84 | IF %ERRORLEVEL% NEQ 0 ( 85 | call :failure "Initializing dependencies %~1 failed." 86 | exit /b 1 87 | ) 88 | call cd /d "%path_base%\%~1\builds\msvc\%proj_version%" 89 | call "%msbuild_exe%" %msbuild_args% /target:%~1:Rebuild %~1.sln /p:PreBuildEventUseInBuild=false /p:PostBuildEventUseInBuild=false 90 | IF %ERRORLEVEL% NEQ 0 ( 91 | call :failure "%msbuild_exe% %msbuild_args% /target:%~1:Rebuild %~1.sln" 92 | exit /b 1 93 | ) 94 | call :success "Building repository project %~1 execution complete." 95 | call cd /d "%path_base%" 96 | exit /b 0 97 | 98 | :depends 99 | call :pending "nuget restoring dependencies for %~1..." 100 | call nuget restore "%path_base%\%~1\builds\msvc\%proj_version%\%~1.sln" -OutputDirectory "%nuget_pkg_path%" 101 | IF %ERRORLEVEL% NEQ 0 ( 102 | call :failure "nuget restore failed." 103 | exit /b 1 104 | ) 105 | call :success "nuget restoration for %~1 complete." 106 | exit /b 0 107 | 108 | :pending 109 | echo %~1 110 | exit /b 0 111 | 112 | :success 113 | echo %~1 114 | exit /b 0 115 | 116 | :failure 117 | echo %~1 118 | exit /b 0 119 | -------------------------------------------------------------------------------- /builds/cmake/modules/FindBitcoin-System.cmake: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (c) 2014-2025 libbitcoin-protocol developers (see COPYING). 3 | # 4 | # GENERATED SOURCE CODE, DO NOT EDIT EXCEPT EXPERIMENTALLY 5 | # 6 | ############################################################################### 7 | # FindBitcoin 8 | # 9 | # Use this module by invoking find_package with the form:: 10 | # 11 | # find_package( Bitcoin-System 12 | # [version] # Minimum version 13 | # [REQUIRED] # Fail with error if bitcoin is not found 14 | # ) 15 | # 16 | # Defines the following for use: 17 | # 18 | # bitcoin_system_FOUND - true if headers and requested libraries were found 19 | # bitcoin_system_INCLUDE_DIRS - include directories for bitcoin-system libraries 20 | # bitcoin_system_LIBRARY_DIRS - link directories for bitcoin-system libraries 21 | # bitcoin_system_LIBRARIES - bitcoin-system libraries to be linked 22 | # bitcoin_system_PKG - bitcoin-system pkg-config package specification. 23 | # 24 | 25 | if (MSVC) 26 | if ( Bitcoin-System_FIND_REQUIRED ) 27 | set( _bitcoin_system_MSG_STATUS "SEND_ERROR" ) 28 | else () 29 | set( _bitcoin_system_MSG_STATUS "STATUS" ) 30 | endif() 31 | 32 | set( bitcoin_system_FOUND false ) 33 | message( ${_bitcoin_system_MSG_STATUS} "MSVC environment detection for 'bitcoin-system' not currently supported." ) 34 | else () 35 | # required 36 | if ( Bitcoin-System_FIND_REQUIRED ) 37 | set( _bitcoin_system_REQUIRED "REQUIRED" ) 38 | endif() 39 | 40 | # quiet 41 | if ( Bitcoin-System_FIND_QUIETLY ) 42 | set( _bitcoin_system_QUIET "QUIET" ) 43 | endif() 44 | 45 | # modulespec 46 | if ( Bitcoin-System_FIND_VERSION_COUNT EQUAL 0 ) 47 | set( _bitcoin_system_MODULE_SPEC "libbitcoin-system" ) 48 | else () 49 | if ( Bitcoin-System_FIND_VERSION_EXACT ) 50 | set( _bitcoin_system_MODULE_SPEC_OP "=" ) 51 | else () 52 | set( _bitcoin_system_MODULE_SPEC_OP ">=" ) 53 | endif() 54 | 55 | set( _bitcoin_system_MODULE_SPEC "libbitcoin-system ${_bitcoin_system_MODULE_SPEC_OP} ${Bitcoin-System_FIND_VERSION}" ) 56 | endif() 57 | 58 | pkg_check_modules( bitcoin_system ${_bitcoin_system_REQUIRED} ${_bitcoin_system_QUIET} "${_bitcoin_system_MODULE_SPEC}" ) 59 | set( bitcoin_system_PKG "${_bitcoin_system_MODULE_SPEC}" ) 60 | endif() 61 | -------------------------------------------------------------------------------- /builds/msvc/.gitignore: -------------------------------------------------------------------------------- 1 | *.bin 2 | *.json 3 | *.suo 4 | *.opensdf 5 | *.sdf 6 | *.log 7 | *.aps 8 | *.user 9 | *.ipch 10 | *.VC.* 11 | address_rows 12 | address_table 13 | block_table 14 | candidate_index 15 | confirmed_index 16 | file_storage 17 | hash_table 18 | record_hash_table_64bit 19 | spend_table 20 | stealth_rows 21 | transaction_index 22 | transaction_table 23 | tx_index 24 | tx_table 25 | block_lookup 26 | block_rows 27 | lookup 28 | rows 29 | spend 30 | transaction 31 | record_manager 32 | slab_manager 33 | slab_hash_table -------------------------------------------------------------------------------- /builds/msvc/build/build_all.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | CALL nuget_all.bat 3 | ECHO. 4 | CALL build_base.bat vs2022 libbitcoin-database "Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build" 5 | CALL build_base.bat vs2019 libbitcoin-database "Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build" 6 | CALL build_base.bat vs2017 libbitcoin-database "Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build" 7 | REM CALL build_base.bat vs2015 libbitcoin-database "Microsoft Visual Studio 14.0\VC" 8 | REM CALL build_base.bat vs2013 libbitcoin-database "Microsoft Visual Studio 12.0\VC" 9 | PAUSE 10 | -------------------------------------------------------------------------------- /builds/msvc/build/build_base.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | REM Usage: [buildbase.bat vs2017 libbitcoin "Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build"] 3 | REM Usage: [buildbase.bat vs2015 libbitcoin "Microsoft Visual Studio 14.0\VC"] 4 | REM Usage: [buildbase.bat vs2013 libbitcoin "Microsoft Visual Studio 12.0\VC"] 5 | 6 | SET studio=%1 7 | SET project=%2 8 | SET version=%~3 9 | 10 | SET log=%studio%.log 11 | SET solution=..\%studio%\%project%.sln 12 | SET tools=%version%\vcvarsall.bat 13 | SET environment=%programfiles(x86)%\%tools% 14 | 15 | IF NOT EXIST "%environment%" SET environment=%programfiles%\%tools% 16 | IF NOT EXIST "%environment%" GOTO no_tools 17 | 18 | ECHO Building: %solution% 19 | 20 | CALL "%environment%" x86 > nul 21 | ECHO Platform=x86 22 | 23 | ECHO Configuration=StaticDebug 24 | msbuild /m /v:n /p:Configuration=StaticDebug /p:Platform=Win32 %solution% >> %log% 25 | IF errorlevel 1 GOTO error 26 | ECHO Configuration=StaticRelease 27 | msbuild /m /v:n /p:Configuration=StaticRelease /p:Platform=Win32 %solution% >> %log% 28 | IF errorlevel 1 GOTO error 29 | 30 | CALL "%environment%" x86_amd64 > nul 31 | ECHO Platform=x64 32 | 33 | ECHO Configuration=StaticDebug 34 | msbuild /m /v:n /p:Configuration=StaticDebug /p:Platform=x64 %solution% >> %log% 35 | IF errorlevel 1 GOTO error 36 | ECHO Configuration=StaticRelease 37 | msbuild /m /v:n /p:Configuration=StaticRelease /p:Platform=x64 %solution% >> %log% 38 | IF errorlevel 1 GOTO error 39 | 40 | ECHO Complete: %solution% 41 | GOTO end 42 | 43 | :error 44 | ECHO *** ERROR, build terminated early, see: %log% 45 | GOTO end 46 | 47 | :no_tools 48 | ECHO *** ERROR, build tools not found: %tools% 49 | 50 | :end 51 | 52 | -------------------------------------------------------------------------------- /builds/msvc/build/nuget_all.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | ECHO Downloading libbitcoin vs2022 dependencies from NuGet 3 | CALL nuget.exe install ..\vs2022\libbitcoin-database\packages.config 4 | CALL nuget.exe install ..\vs2022\libbitcoin-database-tools\packages.config 5 | CALL nuget.exe install ..\vs2022\libbitcoin-database-test\packages.config 6 | ECHO. 7 | ECHO Downloading libbitcoin vs2019 dependencies from NuGet 8 | CALL nuget.exe install ..\vs2019\libbitcoin-database\packages.config 9 | CALL nuget.exe install ..\vs2019\libbitcoin-database-tools\packages.config 10 | CALL nuget.exe install ..\vs2019\libbitcoin-database-test\packages.config 11 | ECHO. 12 | ECHO Downloading libbitcoin vs2017 dependencies from NuGet 13 | CALL nuget.exe install ..\vs2017\libbitcoin-database\packages.config 14 | CALL nuget.exe install ..\vs2017\libbitcoin-database-tools\packages.config 15 | CALL nuget.exe install ..\vs2017\libbitcoin-database-test\packages.config 16 | -------------------------------------------------------------------------------- /builds/msvc/debug.natvis: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | { m_backend } 13 | 14 | 15 | 16 | 17 | { m_data } 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /builds/msvc/nuget.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 26 | 30 | 31 | -------------------------------------------------------------------------------- /builds/msvc/properties/Arm.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>ARM32 Settings 6 | 7 | 8 | 9 | 10 | 13 | WIN32;_WIN32;_ARM_;%(PreprocessorDefinitions) 14 | 15 | 16 | MachineARM 17 | 18 | 19 | /MACHINE:ARM %(AdditionalOptions) 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /builds/msvc/properties/Arm64.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>ARM64 Settings 6 | 7 | 8 | 9 | 10 | 13 | WIN32;_WIN32;_ARM64;%(PreprocessorDefinitions) 14 | 15 | 16 | MachineARM64 17 | 18 | 19 | /MACHINE:ARM64 %(AdditionalOptions) 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /builds/msvc/properties/Common.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Common Settings 6 | Unicode 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | x64 15 | 16 | 17 | 18 | 19 | UNICODE;_UNICODE;%(PreprocessorDefinitions) 20 | 21 | 22 | 23 | Level4 24 | false 25 | false 26 | true 27 | 28 | 29 | 30 | /Zc:__cplusplus %(AdditionalOptions) 31 | true 32 | true 33 | false 34 | false 35 | stdc11 36 | stdcpp14 37 | stdcpp17 38 | stdcpp20 39 | false 40 | true 41 | true 42 | 43 | 44 | 45 | 46 | Level4 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /builds/msvc/properties/DLL.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Dynamic Library 6 | dynamic 7 | .dll 8 | 9 | 10 | 11 | 12 | _DLL;_WINDLL;%(PreprocessorDefinitions) 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /builds/msvc/properties/Debug.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | <_PropertySheetDisplayName>Debug Settings 10 | Debug 11 | 12 | 13 | 14 | 15 | 16 | EnableFastChecks 17 | ProgramDatabase 18 | true 19 | true 20 | Disabled 21 | _DEBUG;%(PreprocessorDefinitions) 22 | 23 | 24 | _DEBUG;%(PreprocessorDefinitions) 25 | 26 | 27 | true 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /builds/msvc/properties/DebugDEXE.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Console Debug Dynamic 6 | dynamic 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | MultiThreadedDebugDLL 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /builds/msvc/properties/DebugDLL.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Dynamic Debug Library 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | MultiThreadedDebugDLL 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /builds/msvc/properties/DebugLEXE.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Console Debug Link Time Code Generation 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | MultiThreadedDebug 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /builds/msvc/properties/DebugLIB.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Static Debug Library 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | MultiThreadedDebug 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /builds/msvc/properties/DebugLTCG.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Static Debug Link Time Code Generation Library 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | MultiThreadedDebug 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /builds/msvc/properties/DebugSEXE.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Console Debug Static 6 | static 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | MultiThreadedDebug 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /builds/msvc/properties/EXE.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Console Application 6 | true 7 | 8 | 9 | 10 | 11 | _CONSOLE;%(PreprocessorDefinitions) 12 | 13 | 14 | Console 15 | 16 | 17 | -------------------------------------------------------------------------------- /builds/msvc/properties/LIB.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Static Library 6 | static 7 | .lib 8 | 9 | 10 | 11 | 12 | _LIB;%(PreprocessorDefinitions) 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /builds/msvc/properties/LTCG.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Link Time Code Generation Library 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /builds/msvc/properties/Link.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Link Time Code Generation Settings 6 | ltcg 7 | 8 | 9 | 10 | 11 | true 12 | 13 | 14 | UseLinkTimeCodeGeneration 15 | 16 | 17 | true 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /builds/msvc/properties/Messages.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Build Messages 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /builds/msvc/properties/Output.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Output Settings 6 | 7 | $(ProjectDir)..\..\ 8 | $(ProjectDir)..\..\..\..\ 9 | $(ProjectDir)..\..\..\..\..\ 10 | $(ProjectDir)..\..\..\..\bin\$(PlatformName)\$(DebugOrRelease)\$(PlatformToolset)\$(DefaultLinkage)\ 11 | $(ProjectDir)..\..\..\..\obj\$(TargetName)\$(PlatformName)\$(DebugOrRelease)\$(PlatformToolset)\$(DefaultLinkage)\ 12 | $(OutDir) 13 | $(TargetName) 14 | $(TargetDir)$(TargetName)$(TargetExt) 15 | 16 | 17 | 18 | 19 | $(OutDir)$(TargetName).lib 20 | 21 | 22 | $(OutDir)$(TargetName).log 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /builds/msvc/properties/Release.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | <_PropertySheetDisplayName>Release Settings 10 | Release 11 | false 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | false 20 | 21 | 22 | false 23 | true 24 | true 25 | Speed 26 | true 27 | AnySuitable 28 | true 29 | true 30 | MaxSpeed 31 | 32 | 33 | 34 | 35 | AdvancedVectorExtensions2 36 | 37 | 38 | ProgramDatabase 39 | true 40 | NDEBUG;%(PreprocessorDefinitions) 41 | 42 | 43 | NDEBUG;%(PreprocessorDefinitions) 44 | 45 | 46 | true 47 | true 48 | true 49 | 50 | 51 | -------------------------------------------------------------------------------- /builds/msvc/properties/ReleaseDEXE.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Console Release Dynamic 6 | dynamic 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | MultiThreadedDLL 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /builds/msvc/properties/ReleaseDLL.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Dynamic Release Library 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | MultiThreadedDLL 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /builds/msvc/properties/ReleaseLEXE.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Console Release Link Time Code Generation 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | MultiThreaded 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /builds/msvc/properties/ReleaseLIB.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Static Release Library 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | MultiThreaded 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /builds/msvc/properties/ReleaseLTCG.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Static Release Link Time Code Generation Library 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | MultiThreaded 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /builds/msvc/properties/ReleaseSEXE.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Console Release Static 6 | static 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | MultiThreaded 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /builds/msvc/properties/Win32.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>x86 Settings 6 | 7 | 8 | 9 | 10 | WIN32;_WIN32;%(PreprocessorDefinitions) 11 | 12 | 13 | MachineX86 14 | 15 | 16 | /MACHINE:X86 %(AdditionalOptions) 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /builds/msvc/properties/x64.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>x64 Settings 6 | 7 | 8 | 9 | 10 | 13 | WIN32;_WIN32;WIN64;_WIN64;%(PreprocessorDefinitions) 14 | 15 | 16 | MachineX64 17 | 18 | 19 | /MACHINE:X64 %(AdditionalOptions) 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /builds/msvc/vs2022/libbitcoin-database-test/libbitcoin-database-test.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Libbitcoin Database Test Common Settings 6 | AllRules.ruleset 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | $(RepoRoot)include\;(AdditionalIncludeDirectories) 15 | false 16 | 17 | 18 | "$(TargetPath)" --log_level=warning --run_test=* --show_progress=no --build_info=yes 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | ..\..\..\..\..\.nuget\packages\ 31 | 32 | 33 | 34 | dynamic 35 | dynamic 36 | dynamic 37 | 38 | 39 | ltcg 40 | ltcg 41 | ltcg 42 | 43 | 44 | static 45 | static 46 | static 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /builds/msvc/vs2022/libbitcoin-database-test/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /builds/msvc/vs2022/libbitcoin-database-tools/libbitcoin-database-tools.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Libbitcoin Database Tools Common Settings 6 | AllRules.ruleset 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | $(RepoRoot)include\;(AdditionalIncludeDirectories) 15 | false 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | ..\..\..\..\..\.nuget\packages\ 28 | 29 | 30 | 31 | dynamic 32 | dynamic 33 | dynamic 34 | 35 | 36 | ltcg 37 | ltcg 38 | ltcg 39 | 40 | 41 | static 42 | static 43 | static 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /builds/msvc/vs2022/libbitcoin-database-tools/libbitcoin-database-tools.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | {005F2A86-F937-4AB5-0000-000000000001} 12 | 13 | 14 | {005F2A86-F937-4AB5-0000-000000000000} 15 | 16 | 17 | 18 | 19 | src 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /builds/msvc/vs2022/libbitcoin-database-tools/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /builds/msvc/vs2022/libbitcoin-database.import.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Libbitcoin Database Import Settings 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | $(ProjectDir)..\..\..\..\..\libbitcoin-database\include\;%(AdditionalIncludeDirectories) 19 | BCD_STATIC;%(PreprocessorDefinitions) 20 | 21 | 22 | libbitcoin-database.lib;%(AdditionalDependencies) 23 | 24 | 25 | 26 | $(ProjectDir)..\..\..\..\..\libbitcoin-database\bin\$(PlatformName)\Debug\$(PlatformToolset)\$(Linkage-libbitcoin-database)\; 27 | $(ProjectDir)..\..\..\..\..\libbitcoin-database\obj\libbitcoin-database\$(PlatformName)\Debug\$(PlatformToolset)\$(Linkage-libbitcoin-database)\;%(AdditionalLibraryDirectories) 28 | 29 | 30 | $(ProjectDir)..\..\..\..\..\libbitcoin-database\bin\$(PlatformName)\Release\$(PlatformToolset)\$(Linkage-libbitcoin-database)\; 31 | $(ProjectDir)..\..\..\..\..\libbitcoin-database\obj\libbitcoin-database\$(PlatformName)\Release\$(PlatformToolset)\$(Linkage-libbitcoin-database)\;%(AdditionalLibraryDirectories) 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /builds/msvc/vs2022/libbitcoin-database.import.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /builds/msvc/vs2022/libbitcoin-database/libbitcoin-database.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | <_PropertySheetDisplayName>Libbitcoin Database Library Common Settings 6 | AllRules.ruleset 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | $(RepoRoot)include\;%(AdditionalIncludeDirectories) 15 | false 16 | WITH_CONSENSUS;%(PreprocessorDefinitions) 17 | BCD_DLL;%(PreprocessorDefinitions) 18 | BCD_STATIC;%(PreprocessorDefinitions) 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | ..\..\..\..\..\.nuget\packages\ 30 | 31 | 32 | 33 | dynamic 34 | dynamic 35 | 36 | 37 | ltcg 38 | ltcg 39 | 40 | 41 | static 42 | static 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /builds/msvc/vs2022/libbitcoin-database/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /builds/msvc/vs2022/libbitcoin-system.import.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 43 | 44 | -------------------------------------------------------------------------------- /builds/vscode/database.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "../../../libbitcoin-system" 5 | }, 6 | { 7 | "path": "../../../libbitcoin-database" 8 | } 9 | ], 10 | "settings": {} 11 | } 12 | -------------------------------------------------------------------------------- /include/bitcoin/database.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2014-2025 libbitcoin-database developers (see COPYING). 3 | // 4 | // GENERATED SOURCE CODE, DO NOT EDIT EXCEPT EXPERIMENTALLY 5 | // 6 | /////////////////////////////////////////////////////////////////////////////// 7 | #ifndef LIBBITCOIN_DATABASE_HPP 8 | #define LIBBITCOIN_DATABASE_HPP 9 | 10 | /** 11 | * API Users: Include only this header. Direct use of other headers is fragile 12 | * and unsupported as header organization is subject to change. 13 | * 14 | * Maintainers: Do not include this header internal to this library. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | #include 69 | #include 70 | #include 71 | #include 72 | #include 73 | #include 74 | #include 75 | #include 76 | #include 77 | #include 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /include/bitcoin/database/boost.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_BOOST_HPP 20 | #define LIBBITCOIN_DATABASE_BOOST_HPP 21 | 22 | #if defined(HAVE_MSC) 23 | #include 24 | #endif 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | namespace libbitcoin { 35 | namespace database { 36 | 37 | namespace interprocess = boost::interprocess; 38 | namespace ipcdetail = interprocess::ipcdetail; 39 | using file_handle_t = interprocess::file_handle_t; 40 | 41 | #if defined(HAVE_MSC) 42 | const file_handle_t invalid = interprocess::winapi::invalid_handle_value; 43 | #else 44 | const file_handle_t invalid = -1; 45 | #endif 46 | 47 | inline file_handle_t open_existing_file( 48 | const std::filesystem::path& file) NOEXCEPT 49 | { 50 | constexpr auto mode = interprocess::read_write; 51 | #if defined(HAVE_MSC) 52 | const auto filename = system::to_extended_path(file); 53 | #else 54 | const auto filename = file; 55 | #endif 56 | 57 | // Does not throw (unannotated). 58 | BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) 59 | return ipcdetail::open_existing_file(file.string().c_str(), mode); 60 | BC_POP_WARNING() 61 | } 62 | 63 | } // namespace database 64 | } // namespace libbitcoin 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /include/bitcoin/database/define.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_DEFINE_HPP 20 | #define LIBBITCOIN_DATABASE_DEFINE_HPP 21 | 22 | #include 23 | 24 | // map is able to support 32 bit, but because the database 25 | // requires a larger file this is neither validated nor supported. 26 | static_assert(sizeof(void*) == sizeof(uint64_t), "Not a 64 bit system!"); 27 | 28 | /// Attributes. 29 | /// --------------------------------------------------------------------------- 30 | 31 | // Now we use the generic helper definitions in libbitcoin to 32 | // define BCD_API and BCD_INTERNAL. 33 | // BCD_API is used for the public API symbols. It either DLL imports or 34 | // DLL exports (or does nothing for static build) 35 | // BCD_INTERNAL is used for non-api symbols. 36 | 37 | #if defined BCD_STATIC 38 | #define BCD_API 39 | #define BCD_INTERNAL 40 | #elif defined BCD_DLL 41 | #define BCD_API BC_HELPER_DLL_EXPORT 42 | #define BCD_INTERNAL BC_HELPER_DLL_LOCAL 43 | #else 44 | #define BCD_API BC_HELPER_DLL_IMPORT 45 | #define BCD_INTERNAL BC_HELPER_DLL_LOCAL 46 | #endif 47 | 48 | namespace libbitcoin { 49 | namespace database { 50 | 51 | using hash_digest = system::hash_digest; 52 | using hashes = system::hashes; 53 | using code = system::code; 54 | 55 | } // namespace database 56 | } // namespace libbitcoin 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /include/bitcoin/database/file/file.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_FILE_FILE_HPP 20 | #define LIBBITCOIN_DATABASE_FILE_FILE_HPP 21 | 22 | #include 23 | #include 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /include/bitcoin/database/file/rotator.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_FILE_ROTATOR_HPP 20 | #define LIBBITCOIN_DATABASE_FILE_ROTATOR_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace libbitcoin { 29 | namespace database { 30 | namespace file { 31 | 32 | /// Because device requires std::ofstream::value_type. 33 | struct ofstream_wrap 34 | { 35 | using value_type = std::ofstream::char_type; 36 | std::ofstream& stream_; 37 | }; 38 | 39 | /// Simple two file rotating stream with configurable size and file names. 40 | /// Files are rotated after full and writes are contiguous across them. 41 | class BCD_API rotator_sink 42 | : public system::device 43 | { 44 | public: 45 | using path = std::filesystem::path; 46 | struct category 47 | : system::ios::sink_tag, 48 | system::ios::flushable_tag, 49 | system::ios::optimally_buffered_tag 50 | { 51 | }; 52 | 53 | rotator_sink(const path& path1, const path& path2, size_t limit) NOEXCEPT; 54 | size_type write(const char_type* buffer, size_type count) THROWS; 55 | bool flush() THROWS; 56 | 57 | protected: 58 | size_type do_optimal_buffer_size() const NOEXCEPT override; 59 | 60 | bool start() NOEXCEPT; 61 | bool stop() NOEXCEPT; 62 | bool rotate() NOEXCEPT; 63 | bool set_remaining() NOEXCEPT; 64 | bool set_stream() NOEXCEPT; 65 | 66 | private: 67 | // These are thread safe. 68 | const path path1_; 69 | const path path2_; 70 | const size_type limit_; 71 | 72 | // This is not thread safe. 73 | std::shared_ptr stream_{}; 74 | }; 75 | 76 | namespace stream 77 | { 78 | namespace out 79 | { 80 | using rotator = system::make_stream; 81 | } 82 | } 83 | 84 | } // namespace file 85 | } // namespace database 86 | } // namespace libbitcoin 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /include/bitcoin/database/impl/memory/accessor.ipp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_MEMORY_ACCESSOR_IPP 20 | #define LIBBITCOIN_DATABASE_MEMORY_ACCESSOR_IPP 21 | 22 | ////#include 23 | #include 24 | #include 25 | 26 | // Zero/negative size is allowed (automatically handled by bc streams). 27 | 28 | namespace libbitcoin { 29 | namespace database { 30 | 31 | BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) 32 | 33 | TEMPLATE 34 | inline CLASS::accessor(Mutex& mutex) NOEXCEPT 35 | : shared_lock_(mutex) 36 | { 37 | } 38 | 39 | TEMPLATE 40 | inline void CLASS::assign(uint8_t* begin, uint8_t* end) NOEXCEPT 41 | { 42 | begin_ = begin; 43 | end_ = end; 44 | ////BC_ASSERT(!system::is_negative(size())); 45 | } 46 | 47 | TEMPLATE 48 | inline uint8_t* CLASS::offset(size_t bytes) const NOEXCEPT 49 | { 50 | if (system::is_greater(bytes, size())) 51 | return nullptr; 52 | 53 | BC_PUSH_WARNING(NO_POINTER_ARITHMETIC) 54 | return begin_ + bytes; 55 | BC_POP_WARNING() 56 | ////return std::next(begin_, bytes); 57 | } 58 | 59 | TEMPLATE 60 | inline ptrdiff_t CLASS::size() const NOEXCEPT 61 | { 62 | BC_PUSH_WARNING(NO_POINTER_ARITHMETIC) 63 | return system::possible_narrow_and_sign_cast(end_ - begin_); 64 | BC_POP_WARNING() 65 | ////return std::distance(begin_, end_); 66 | } 67 | 68 | TEMPLATE 69 | inline uint8_t* CLASS::begin() NOEXCEPT 70 | { 71 | return begin_; 72 | } 73 | 74 | TEMPLATE 75 | inline uint8_t* CLASS::end() NOEXCEPT 76 | { 77 | return end_; 78 | } 79 | 80 | BC_POP_WARNING() 81 | 82 | } // namespace database 83 | } // namespace libbitcoin 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /include/bitcoin/database/impl/primitives/linkage.ipp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_PRIMITIVES_LINKAGE_IPP 20 | #define LIBBITCOIN_DATABASE_PRIMITIVES_LINKAGE_IPP 21 | 22 | #include 23 | #include 24 | 25 | namespace libbitcoin { 26 | namespace database { 27 | 28 | TEMPLATE 29 | constexpr CLASS::linkage() NOEXCEPT 30 | : value(terminal) 31 | { 32 | } 33 | 34 | TEMPLATE 35 | constexpr CLASS::linkage(integer other) NOEXCEPT 36 | : value(other) 37 | { 38 | } 39 | 40 | TEMPLATE 41 | inline CLASS::linkage(const bytes& other) NOEXCEPT 42 | { 43 | *this = other; 44 | } 45 | 46 | TEMPLATE 47 | constexpr CLASS& CLASS::operator=(integer other) NOEXCEPT 48 | { 49 | value = other; 50 | return *this; 51 | } 52 | 53 | TEMPLATE 54 | inline CLASS& CLASS::operator=(const bytes& other) NOEXCEPT 55 | { 56 | value = 0; 57 | system::unsafe_array_cast(&value) = other; 58 | ////value = system::native_from_little_end(value); 59 | return *this; 60 | } 61 | 62 | TEMPLATE 63 | inline CLASS& CLASS::operator++() NOEXCEPT 64 | { 65 | ++value; 66 | return *this; 67 | } 68 | 69 | TEMPLATE 70 | inline CLASS CLASS::operator++(int) NOEXCEPT 71 | { 72 | auto self = *this; 73 | ++(*this); 74 | return self; 75 | } 76 | 77 | TEMPLATE 78 | constexpr CLASS::operator CLASS::integer() const NOEXCEPT 79 | { 80 | return value; 81 | } 82 | 83 | TEMPLATE 84 | inline CLASS::operator CLASS::bytes() const NOEXCEPT 85 | { 86 | ////const auto little = system::native_to_little_end(value); 87 | return system::unsafe_array_cast(&value); 88 | } 89 | 90 | TEMPLATE 91 | constexpr bool CLASS::is_terminal() const NOEXCEPT 92 | { 93 | return value == terminal; 94 | } 95 | 96 | } // namespace database 97 | } // namespace libbitcoin 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /include/bitcoin/database/locks/file_lock.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_LOCKS_FILE_LOCK_HPP 20 | #define LIBBITCOIN_DATABASE_LOCKS_FILE_LOCK_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | namespace libbitcoin { 27 | namespace database { 28 | 29 | /// This class is not thread safe, and does not throw. 30 | class BCD_API file_lock 31 | { 32 | public: 33 | DELETE_COPY_MOVE_DESTRUCT(file_lock); 34 | 35 | /// Construction does not touch the file. 36 | file_lock(const std::filesystem::path& file) NOEXCEPT; 37 | 38 | /// Path to lock file. 39 | const std::filesystem::path& file() const NOEXCEPT; 40 | 41 | protected: 42 | /// True if file exists. 43 | bool exists() const NOEXCEPT; 44 | 45 | /// True if file exists or was created. 46 | bool create() NOEXCEPT; 47 | 48 | /// True if file does not exist or was deleted. 49 | bool destroy() NOEXCEPT; 50 | 51 | private: 52 | const std::filesystem::path file_; 53 | }; 54 | 55 | } // namespace database 56 | } // namespace libbitcoin 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /include/bitcoin/database/locks/flush_lock.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_LOCKS_FLUSH_LOCK_HPP 20 | #define LIBBITCOIN_DATABASE_LOCKS_FLUSH_LOCK_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace libbitcoin { 28 | namespace database { 29 | 30 | /// This class is not thread safe, and does not throw. 31 | class BCD_API flush_lock 32 | : public file_lock 33 | { 34 | public: 35 | /// Construction does not touch the file. 36 | /// Destruction should not be used to delete the file (needs to remain). 37 | flush_lock(const std::filesystem::path& file) NOEXCEPT; 38 | 39 | /// False if file exists or fails to create. 40 | bool try_lock() NOEXCEPT; 41 | 42 | /// False if file does not exist or fails to delete. 43 | bool try_unlock() NOEXCEPT; 44 | 45 | /// True if file exists. 46 | bool is_locked() const NOEXCEPT; 47 | }; 48 | 49 | } // namespace database 50 | } // namespace libbitcoin 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /include/bitcoin/database/locks/interprocess_lock.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_LOCKS_INTERPROCESS_LOCK_HPP 20 | #define LIBBITCOIN_DATABASE_LOCKS_INTERPROCESS_LOCK_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace libbitcoin { 29 | namespace database { 30 | 31 | /// This class is not thread safe, and does not throw. 32 | /// The lock is process-exclusive in linux/macOS, globally in win32. 33 | class BCD_API interprocess_lock 34 | : public file_lock 35 | { 36 | public: 37 | /// Construction does not touch the file. 38 | interprocess_lock(const std::filesystem::path& file) NOEXCEPT; 39 | 40 | /// Destruction calls try_unlock. 41 | ~interprocess_lock() NOEXCEPT override; 42 | 43 | /// Creates the file and acquires exclusive access. 44 | /// Returns false if failed to acquire lock or lock already held. 45 | bool try_lock() NOEXCEPT; 46 | 47 | /// Releases access (if locked) and deletes the file. 48 | /// Returns true if lock not held or succesfully unlocked and deleted. 49 | bool try_unlock() NOEXCEPT; 50 | 51 | private: 52 | file_handle_t handle_; 53 | }; 54 | 55 | } // namespace database 56 | } // namespace libbitcoin 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /include/bitcoin/database/locks/locks.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_LOCKS_HPP 20 | #define LIBBITCOIN_DATABASE_LOCKS_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /include/bitcoin/database/memory/accessor.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_MEMORY_ACCESSOR_HPP 20 | #define LIBBITCOIN_DATABASE_MEMORY_ACCESSOR_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace libbitcoin { 28 | namespace database { 29 | 30 | /// Shared r/w access to a memory buffer, mutex blocks memory remap. 31 | template 32 | class accessor 33 | : public memory 34 | { 35 | public: 36 | DELETE_COPY_MOVE_DESTRUCT(accessor); 37 | 38 | /// Mutex guards against remap while object in scope. 39 | inline accessor(Mutex& mutex) NOEXCEPT; 40 | 41 | /// Set the buffer, where end is within allocated space. 42 | /// End should be initialized to logical space though that may contract or 43 | /// expand during accessor lifetime. The only guarantee offered by end is 44 | /// that it remains within allocated space and is initially logical space. 45 | inline void assign(uint8_t* begin, uint8_t* end) NOEXCEPT; 46 | 47 | /// Return an offset from begin, nullptr if end or past end. 48 | inline uint8_t* offset(size_t bytes) const NOEXCEPT override; 49 | 50 | /// The logical buffer size (from begin to end). 51 | inline ptrdiff_t size() const NOEXCEPT override; 52 | 53 | /// Get logical buffer (guarded against remap only). 54 | inline uint8_t* begin() NOEXCEPT override; 55 | inline uint8_t* end() NOEXCEPT override; 56 | 57 | /// Alias for begin. 58 | inline uint8_t* data() NOEXCEPT override { return begin(); } 59 | 60 | private: 61 | uint8_t* begin_{}; 62 | uint8_t* end_{}; 63 | std::shared_lock shared_lock_; 64 | }; 65 | 66 | } // namespace database 67 | } // namespace libbitcoin 68 | 69 | #define TEMPLATE template 70 | #define CLASS accessor 71 | 72 | #include 73 | 74 | #undef CLASS 75 | #undef TEMPLATE 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /include/bitcoin/database/memory/finalizer.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_MEMORY_FINALIZER_HPP 20 | #define LIBBITCOIN_DATABASE_MEMORY_FINALIZER_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace libbitcoin { 28 | namespace database { 29 | 30 | // This is single inheritance. 31 | BC_PUSH_WARNING(DIAMOND_INHERITANCE) 32 | 33 | /// A byte flipper with finalization extentions, that accepts an iostream. 34 | template 35 | class finalizer_ 36 | : public system::byte_flipper 37 | { 38 | public: 39 | DEFAULT_COPY_MOVE_DESTRUCT(finalizer_); 40 | 41 | using finalization = std::function; 42 | 43 | finalizer_(IOStream& stream) NOEXCEPT 44 | : system::byte_flipper(stream) 45 | { 46 | } 47 | 48 | void set_finalizer(finalization&& functor) NOEXCEPT 49 | { 50 | finalize_ = std::move(functor); 51 | } 52 | 53 | // This is expected to have side effect on the stream buffer, specifically 54 | // setting the "next" pointer into beginning of the address space. 55 | bool finalize() NOEXCEPT 56 | { 57 | if (!*this) return false; 58 | 59 | // std::function does not allow for noexcept. 60 | BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) 61 | return finalize_(); 62 | BC_POP_WARNING() 63 | } 64 | 65 | private: 66 | finalization finalize_; 67 | }; 68 | 69 | /// A finalizing byte reader/writer that copies data from/to a memory_ptr. 70 | using finalizer = finalizer_<>; 71 | 72 | BC_POP_WARNING() 73 | 74 | } // namespace database 75 | } // namespace libbitcoin 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /include/bitcoin/database/memory/interfaces/memory.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_MEMORY_INTERFACES_MEMORY_HPP 20 | #define LIBBITCOIN_DATABASE_MEMORY_INTERFACES_MEMORY_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | namespace libbitcoin { 27 | namespace database { 28 | 29 | /// Protected memory access interface. 30 | class memory 31 | { 32 | public: 33 | typedef uint8_t value_type; 34 | typedef value_type* iterator; 35 | typedef const value_type* const_iterator; 36 | typedef std::shared_ptr ptr; 37 | 38 | /// Return an offset from begin, nullptr if end or past end. 39 | virtual uint8_t* offset(size_t value) const NOEXCEPT = 0; 40 | 41 | /// The logical buffer size (from begin to end). 42 | virtual ptrdiff_t size() const NOEXCEPT = 0; 43 | 44 | /// Get logical buffer. 45 | virtual uint8_t* begin() NOEXCEPT = 0; 46 | virtual uint8_t* end() NOEXCEPT = 0; 47 | 48 | /// Alias begin. 49 | virtual uint8_t* data() NOEXCEPT = 0; 50 | }; 51 | 52 | typedef memory::ptr memory_ptr; 53 | 54 | } // namespace database 55 | } // namespace libbitcoin 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /include/bitcoin/database/memory/memory.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_MEMORY_MEMORY_HPP 20 | #define LIBBITCOIN_DATABASE_MEMORY_MEMORY_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /include/bitcoin/database/memory/reader.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_MEMORY_READER_HPP 20 | #define LIBBITCOIN_DATABASE_MEMORY_READER_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | namespace libbitcoin { 27 | namespace database { 28 | 29 | /// A byte reader that copies data. 30 | using reader = system::byte_reader>; 31 | 32 | } // namespace database 33 | } // namespace libbitcoin 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /include/bitcoin/database/memory/streamers.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_MEMORY_STREAMERS_HPP 20 | #define LIBBITCOIN_DATABASE_MEMORY_STREAMERS_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | namespace libbitcoin { 27 | namespace database { 28 | 29 | /// These all operate over a system::iostream. 30 | 31 | using reader = system::byte_reader>; 32 | using writer = system::byte_writer>; 33 | using flipper = system::byte_flipper>; 34 | 35 | } // namespace database 36 | } // namespace libbitcoin 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /include/bitcoin/database/memory/utilities.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_MEMORY_UTILITIES_HPP 20 | #define LIBBITCOIN_DATABASE_MEMORY_UTILITIES_HPP 21 | 22 | #include 23 | 24 | namespace libbitcoin { 25 | namespace database { 26 | 27 | /// The byte size of system pages, zero if failed. 28 | BCD_API size_t page_size() NOEXCEPT; 29 | 30 | /// The bytes of physical memory, zero if failed. 31 | BCD_API uint64_t system_memory() NOEXCEPT; 32 | 33 | } // namespace database 34 | } // namespace libbitcoin 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/bitcoin/database/primitives/keys.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libbitcoin/libbitcoin-database/514ee1eed9c94ecdb3f33af430c6e095ca354ba2/include/bitcoin/database/primitives/keys.hpp -------------------------------------------------------------------------------- /include/bitcoin/database/primitives/linkage.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_PRIMITIVES_LINKAGE_HPP 20 | #define LIBBITCOIN_DATABASE_PRIMITIVES_LINKAGE_HPP 21 | 22 | #include 23 | #include 24 | 25 | namespace libbitcoin { 26 | namespace database { 27 | 28 | /// Link serialization is non-endian. 29 | /// TODO: phase out the Size argument in favor of just Bits. 30 | template If = true> 32 | struct linkage 33 | { 34 | using integer = unsigned_type; 35 | using bytes = std_array; 36 | using self = linkage; 37 | 38 | // Terminal is also a mask to read Bits from Bytes. 39 | static constexpr auto terminal = system::unmask_right(Bits); 40 | static constexpr auto size = Size; 41 | static constexpr auto bits = Bits; 42 | 43 | /// Construct a terminal link. 44 | constexpr linkage() NOEXCEPT; 45 | 46 | /// Integral and array constructors. 47 | constexpr linkage(integer other) NOEXCEPT; 48 | inline linkage(const bytes& other) NOEXCEPT; 49 | 50 | /// Integral and array assignment operators. 51 | constexpr self& operator=(integer other) NOEXCEPT; 52 | inline self& operator=(const bytes& other) NOEXCEPT; 53 | 54 | /// Increment operators (not for use with slab links). 55 | inline self& operator++() NOEXCEPT; 56 | inline self operator++(int) NOEXCEPT; 57 | 58 | /// Integral and array cast operators. 59 | constexpr operator integer() const NOEXCEPT; 60 | inline operator bytes() const NOEXCEPT; 61 | 62 | /// True when value is terminal. 63 | constexpr bool is_terminal() const NOEXCEPT; 64 | 65 | integer value; 66 | }; 67 | 68 | template If = true> 70 | bool operator==(const linkage& left, 71 | const linkage& right) NOEXCEPT 72 | { 73 | return left.value == right.value; 74 | } 75 | 76 | template If = true> 78 | bool operator!=(const linkage& left, 79 | const linkage& right) NOEXCEPT 80 | { 81 | return !(left == right); 82 | } 83 | 84 | } // namespace database 85 | } // namespace libbitcoin 86 | 87 | #define TEMPLATE template If> 89 | #define CLASS linkage 90 | 91 | #include 92 | 93 | #undef CLASS 94 | #undef TEMPLATE 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /include/bitcoin/database/primitives/primitives.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_PRIMITIVES_PRIMITIVES_HPP 20 | #define LIBBITCOIN_DATABASE_PRIMITIVES_PRIMITIVES_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /include/bitcoin/database/settings.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_SETTINGS_HPP 20 | #define LIBBITCOIN_DATABASE_SETTINGS_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | namespace libbitcoin { 27 | namespace database { 28 | 29 | /// 32 bit builds will warn on size downcasts. 30 | /// TODO: helper methods to embed/construct full paths (see store()). 31 | /// Common database configuration settings, properties not thread safe. 32 | struct BCD_API settings 33 | { 34 | DEFAULT_COPY_MOVE_DESTRUCT(settings); 35 | 36 | settings() NOEXCEPT; 37 | settings(system::chain::selection context) NOEXCEPT; 38 | 39 | /// Properties. 40 | std::filesystem::path path; 41 | 42 | /// Archives. 43 | /// ----------------------------------------------------------------------- 44 | 45 | uint32_t header_buckets; 46 | uint64_t header_size; 47 | uint16_t header_rate; 48 | 49 | uint64_t input_size; 50 | uint16_t input_rate; 51 | 52 | uint64_t output_size; 53 | uint16_t output_rate; 54 | 55 | uint32_t point_buckets; 56 | uint64_t point_size; 57 | uint16_t point_rate; 58 | 59 | uint64_t ins_size; 60 | uint16_t ins_rate; 61 | 62 | uint64_t outs_size; 63 | uint16_t outs_rate; 64 | 65 | uint32_t tx_buckets; 66 | uint64_t tx_size; 67 | uint16_t tx_rate; 68 | 69 | uint32_t txs_buckets; 70 | uint64_t txs_size; 71 | uint16_t txs_rate; 72 | 73 | /// Indexes. 74 | /// ----------------------------------------------------------------------- 75 | 76 | uint64_t candidate_size; 77 | uint16_t candidate_rate; 78 | 79 | uint64_t confirmed_size; 80 | uint16_t confirmed_rate; 81 | 82 | uint32_t strong_tx_buckets; 83 | uint64_t strong_tx_size; 84 | uint16_t strong_tx_rate; 85 | 86 | /// Caches. 87 | /// ----------------------------------------------------------------------- 88 | 89 | // This one is 16 bit (could use table link::integer) for these. 90 | uint16_t duplicate_buckets; 91 | uint64_t duplicate_size; 92 | uint16_t duplicate_rate; 93 | 94 | uint32_t prevout_buckets; 95 | uint64_t prevout_size; 96 | uint16_t prevout_rate; 97 | 98 | uint32_t validated_bk_buckets; 99 | uint64_t validated_bk_size; 100 | uint16_t validated_bk_rate; 101 | 102 | uint32_t validated_tx_buckets; 103 | uint64_t validated_tx_size; 104 | uint16_t validated_tx_rate; 105 | 106 | /// Optionals. 107 | /// ----------------------------------------------------------------------- 108 | 109 | uint32_t address_buckets; 110 | uint64_t address_size; 111 | uint16_t address_rate; 112 | 113 | uint32_t filter_bk_buckets; 114 | uint64_t filter_bk_size; 115 | uint16_t filter_bk_rate; 116 | 117 | uint32_t filter_tx_buckets; 118 | uint64_t filter_tx_size; 119 | uint16_t filter_tx_rate; 120 | }; 121 | 122 | } // namespace database 123 | } // namespace libbitcoin 124 | 125 | #endif 126 | -------------------------------------------------------------------------------- /include/bitcoin/database/tables/archives/point.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_TABLES_ARCHIVES_POINT_HPP 20 | #define LIBBITCOIN_DATABASE_TABLES_ARCHIVES_POINT_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | namespace libbitcoin { 30 | namespace database { 31 | namespace table { 32 | 33 | struct point 34 | : public hash_map 35 | { 36 | using hash_map::hashmap; 37 | using ix = linkage; 38 | 39 | struct record 40 | : public schema::point 41 | { 42 | inline bool from_data(reader& source) NOEXCEPT 43 | { 44 | source.rewind_bytes(schema::point::sk); 45 | hash = source.read_hash(); 46 | index = source.read_little_endian(); 47 | 48 | if (index == ix::terminal) 49 | index = system::chain::point::null_index; 50 | 51 | BC_ASSERT(!source || source.get_read_position() == minrow); 52 | return source; 53 | } 54 | 55 | inline bool to_data(flipper& sink) const NOEXCEPT 56 | { 57 | BC_ASSERT(!sink || sink.get_write_position() == minrow); 58 | return sink; 59 | } 60 | 61 | inline bool is_null() const NOEXCEPT 62 | { 63 | return index == system::chain::point::null_index; 64 | } 65 | 66 | inline bool operator==(const record& other) const NOEXCEPT 67 | { 68 | return hash == other.hash 69 | && index == other.index; 70 | } 71 | 72 | hash_digest hash{}; 73 | ix::integer index{}; 74 | }; 75 | 76 | struct get_composed 77 | : public schema::point 78 | { 79 | inline bool from_data(reader& source) NOEXCEPT 80 | { 81 | source.rewind_bytes(schema::point::sk); 82 | key = 83 | { 84 | source.read_hash(), 85 | source.read_little_endian() 86 | }; 87 | BC_ASSERT(!source || source.get_read_position() == minrow); 88 | return source; 89 | } 90 | 91 | system::chain::point key{}; 92 | }; 93 | }; 94 | 95 | } // namespace table 96 | } // namespace database 97 | } // namespace libbitcoin 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /include/bitcoin/database/tables/association.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_TABLES_ASSOCIATION_HPP 20 | #define LIBBITCOIN_DATABASE_TABLES_ASSOCIATION_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace libbitcoin { 28 | namespace database { 29 | 30 | /// Association between block hash and context. 31 | struct association 32 | { 33 | schema::height::link::integer link; 34 | system::hash_digest hash; 35 | system::chain::context context; 36 | 37 | struct key{}; 38 | struct pos{}; 39 | 40 | struct name_extractor 41 | { 42 | using result_type = size_t; 43 | 44 | inline const result_type& operator()( 45 | const association& item) const NOEXCEPT 46 | { 47 | return item.context.height; 48 | } 49 | 50 | inline result_type& operator()(association* item) const NOEXCEPT 51 | { 52 | BC_ASSERT_MSG(item, "null pointer"); 53 | return item->context.height; 54 | } 55 | }; 56 | }; 57 | 58 | } // namespace database 59 | } // namespace libbitcoin 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /include/bitcoin/database/tables/associations.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_TABLES_ASSOCIATIONS_HPP 20 | #define LIBBITCOIN_DATABASE_TABLES_ASSOCIATIONS_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace libbitcoin { 28 | namespace database { 29 | 30 | typedef boost::multi_index_container 31 | < 32 | association, 33 | boost::multi_index::indexed_by 34 | < 35 | boost::multi_index::hashed_unique 36 | < 37 | boost::multi_index::tag, 38 | boost::multi_index::key<&association::hash> 39 | >, 40 | boost::multi_index::ordered_unique 41 | < 42 | boost::multi_index::tag, 43 | association::name_extractor 44 | > 45 | > 46 | > associations_; 47 | 48 | /// Collection of association between block hash and context. 49 | /// Indexed by unique block hash and by unique block height. 50 | class associations 51 | : public associations_ 52 | { 53 | public: 54 | /// Use base class constructors. 55 | using associations_::associations_; 56 | 57 | /// Forward iterator for the ordered_unique index. 58 | inline auto pos_begin() const NOEXCEPT 59 | { 60 | return get().begin(); 61 | } 62 | 63 | /// Forward end iterator for the ordered_unique index. 64 | inline auto pos_end() const NOEXCEPT 65 | { 66 | return get().end(); 67 | } 68 | 69 | /// Returns a pointer to an association instance, or .end(). 70 | inline auto find(const system::hash_digest& hash) const NOEXCEPT 71 | { 72 | BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) 73 | return get().find(hash); 74 | BC_POP_WARNING() 75 | } 76 | 77 | /// Returns a pointer to an association instance, or .pos_end(). 78 | inline auto find(size_t height) const NOEXCEPT 79 | { 80 | BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) 81 | return get().find(height); 82 | BC_POP_WARNING() 83 | } 84 | 85 | /// Hash identifies an element in the hashed_unique index. 86 | inline bool exists(const system::hash_digest& hash) const NOEXCEPT 87 | { 88 | return find(hash) != end(); 89 | } 90 | 91 | /// Height identifies an element in the ordered_unique index. 92 | inline bool exists(size_t height) const NOEXCEPT 93 | { 94 | return find(height) != pos_end(); 95 | } 96 | 97 | /// The context of the maximum ordered_unique index (must not be empty). 98 | inline const system::chain::context& top() const NOEXCEPT 99 | { 100 | BC_ASSERT(!empty()); 101 | 102 | BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) 103 | return get().rbegin()->context; 104 | BC_POP_WARNING() 105 | } 106 | }; 107 | 108 | } // namespace database 109 | } // namespace libbitcoin 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /include/bitcoin/database/tables/caches/duplicate.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_TABLES_CACHES_DOUBLES_HPP 20 | #define LIBBITCOIN_DATABASE_TABLES_CACHES_DOUBLES_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace libbitcoin { 28 | namespace database { 29 | namespace table { 30 | 31 | struct duplicate 32 | : public hash_map 33 | { 34 | using hash_map::hashmap; 35 | 36 | struct record 37 | : public schema::duplicate 38 | { 39 | inline bool from_data(reader& source) NOEXCEPT 40 | { 41 | return source; 42 | } 43 | 44 | inline bool to_data(finalizer& sink) const NOEXCEPT 45 | { 46 | BC_ASSERT(!sink || sink.get_write_position() == count() * minrow); 47 | return sink; 48 | } 49 | }; 50 | }; 51 | 52 | } // namespace table 53 | } // namespace database 54 | } // namespace libbitcoin 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /include/bitcoin/database/tables/caches/validated_bk.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_TABLES_CACHES_VALIDATED_BK_HPP 20 | #define LIBBITCOIN_DATABASE_TABLES_CACHES_VALIDATED_BK_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace libbitcoin { 28 | namespace database { 29 | namespace table { 30 | 31 | /// validated_bk is a slab arraymap of block state, indexed by header.fk. 32 | struct validated_bk 33 | : public array_map 34 | { 35 | using coding = linkage; 36 | using array_map::arraymap; 37 | 38 | struct slab 39 | : public schema::validated_bk 40 | { 41 | link count() const NOEXCEPT 42 | { 43 | using namespace system; 44 | return possible_narrow_cast(coding::size + 45 | variable_size(fees)); 46 | } 47 | 48 | inline bool from_data(reader& source) NOEXCEPT 49 | { 50 | code = source.read_little_endian(); 51 | fees = source.read_variable(); 52 | BC_ASSERT(!source || source.get_read_position() == count()); 53 | return source; 54 | } 55 | 56 | inline bool to_data(finalizer& sink) const NOEXCEPT 57 | { 58 | sink.write_little_endian(code); 59 | sink.write_variable(fees); 60 | BC_ASSERT(!sink || sink.get_write_position() == count()); 61 | return sink; 62 | } 63 | 64 | inline bool operator==(const slab& other) const NOEXCEPT 65 | { 66 | return code == other.code 67 | && fees == other.fees; 68 | } 69 | 70 | coding::integer code{}; 71 | uint64_t fees{}; 72 | }; 73 | 74 | struct slab_get_code 75 | : public schema::validated_bk 76 | { 77 | link count() const NOEXCEPT 78 | { 79 | BC_ASSERT(false); 80 | return {}; 81 | } 82 | 83 | inline bool from_data(reader& source) NOEXCEPT 84 | { 85 | code = source.read_little_endian(); 86 | return source; 87 | } 88 | 89 | coding::integer code{}; 90 | }; 91 | }; 92 | 93 | } // namespace table 94 | } // namespace database 95 | } // namespace libbitcoin 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /include/bitcoin/database/tables/context.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_CONTEXT_HPP 20 | #define LIBBITCOIN_DATABASE_CONTEXT_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace libbitcoin { 28 | namespace database { 29 | 30 | struct context 31 | { 32 | using height_t = linkage; 33 | using flag_t = linkage; 34 | using mtp_t = uint32_t; 35 | static constexpr auto size = flag_t::size + height_t::size + sizeof(mtp_t); 36 | 37 | static inline void from_data(reader& source, context& context) NOEXCEPT 38 | { 39 | context.flags = source.template read_little_endian(); 40 | context.height = source.template read_little_endian(); 41 | context.mtp = source.template read_little_endian(); 42 | }; 43 | 44 | static inline void to_data(finalizer& sink, const context& context) NOEXCEPT 45 | { 46 | sink.template write_little_endian(context.flags); 47 | sink.template write_little_endian(context.height); 48 | sink.template write_little_endian(context.mtp); 49 | }; 50 | 51 | constexpr bool is_enabled(system::chain::flags rule) const NOEXCEPT 52 | { 53 | return system::chain::script::is_enabled(flags, rule); 54 | } 55 | 56 | inline bool operator==(const context& other) const NOEXCEPT 57 | { 58 | return flags == other.flags 59 | && height == other.height 60 | && mtp == other.mtp; 61 | } 62 | 63 | height_t::integer flags{}; 64 | flag_t::integer height{}; 65 | mtp_t mtp{}; 66 | }; 67 | 68 | } // namespace database 69 | } // namespace libbitcoin 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /include/bitcoin/database/tables/event.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_TABLES_EVENT_HPP 20 | #define LIBBITCOIN_DATABASE_TABLES_EVENT_HPP 21 | 22 | namespace libbitcoin { 23 | namespace database { 24 | 25 | enum class event_t 26 | { 27 | create_file, 28 | open_file, 29 | load_file, 30 | unload_file, 31 | close_file, 32 | 33 | create_table, 34 | verify_table, 35 | close_table, 36 | 37 | wait_lock, 38 | flush_body, 39 | backup_table, 40 | copy_header, 41 | archive_snapshot, 42 | 43 | restore_table, 44 | recover_snapshot 45 | }; 46 | 47 | } // namespace database 48 | } // namespace libbitcoin 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /include/bitcoin/database/tables/indexes/height.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_TABLES_INDEXES_HEIGHT_HPP 20 | #define LIBBITCOIN_DATABASE_TABLES_INDEXES_HEIGHT_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace libbitcoin { 28 | namespace database { 29 | namespace table { 30 | 31 | /// height is an array of header fk records. 32 | struct height 33 | : public no_map 34 | { 35 | using header = schema::header::link; 36 | using no_map::nomap; 37 | 38 | struct record 39 | : public schema::height 40 | { 41 | inline bool from_data(reader& source) NOEXCEPT 42 | { 43 | header_fk = source.read_little_endian(); 44 | BC_ASSERT(!source || source.get_read_position() == minrow); 45 | return source; 46 | } 47 | 48 | inline bool to_data(flipper& sink) const NOEXCEPT 49 | { 50 | sink.write_little_endian(header_fk); 51 | BC_ASSERT(!sink || sink.get_write_position() == minrow); 52 | return sink; 53 | } 54 | 55 | inline bool operator==(const record& other) const NOEXCEPT 56 | { 57 | return header_fk == other.header_fk; 58 | } 59 | 60 | header::integer header_fk{}; 61 | }; 62 | }; 63 | 64 | } // namespace table 65 | } // namespace database 66 | } // namespace libbitcoin 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /include/bitcoin/database/tables/indexes/strong_tx.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_TABLES_INDEXES_STRONG_TX_HPP 20 | #define LIBBITCOIN_DATABASE_TABLES_INDEXES_STRONG_TX_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace libbitcoin { 28 | namespace database { 29 | namespace table { 30 | 31 | /// strong_tx is a record hashmap of tx confirmation state. 32 | struct strong_tx 33 | : public hash_map 34 | { 35 | using header = schema::header::link; 36 | using hash_map::hashmap; 37 | static constexpr auto offset = header::bits; 38 | static_assert(offset < to_bits(header::size)); 39 | 40 | static constexpr header::integer merge(bool positive, 41 | header::integer header_fk) NOEXCEPT 42 | { 43 | using namespace system; 44 | BC_ASSERT_MSG(!get_right(header_fk, offset), "overflow"); 45 | return set_right(header_fk, offset, positive); 46 | } 47 | 48 | struct record 49 | : public schema::strong_tx 50 | { 51 | inline bool positive() const NOEXCEPT 52 | { 53 | return system::get_right(block_fk, offset); 54 | } 55 | 56 | inline header::integer header_fk() const NOEXCEPT 57 | { 58 | return system::set_right(block_fk, offset, false); 59 | } 60 | 61 | inline bool from_data(reader& source) NOEXCEPT 62 | { 63 | block_fk = source.read_little_endian(); 64 | BC_ASSERT(!source || source.get_read_position() == minrow); 65 | return source; 66 | } 67 | 68 | inline bool to_data(finalizer& sink) const NOEXCEPT 69 | { 70 | sink.write_little_endian(block_fk); 71 | BC_ASSERT(!sink || sink.get_write_position() == minrow); 72 | return sink; 73 | } 74 | 75 | inline bool operator==(const record& other) const NOEXCEPT 76 | { 77 | return positive() == other.positive() 78 | && header_fk() == other.header_fk(); 79 | } 80 | 81 | header::integer block_fk{}; 82 | }; 83 | }; 84 | 85 | } // namespace table 86 | } // namespace database 87 | } // namespace libbitcoin 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /include/bitcoin/database/tables/names.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_TABLES_NAMES_HPP 20 | #define LIBBITCOIN_DATABASE_TABLES_NAMES_HPP 21 | 22 | #include 23 | #include 24 | 25 | namespace libbitcoin { 26 | namespace database { 27 | namespace schema { 28 | 29 | namespace dir 30 | { 31 | constexpr auto heads = "heads"; 32 | constexpr auto primary = "primary"; 33 | constexpr auto secondary = "secondary"; 34 | } 35 | 36 | namespace archive 37 | { 38 | constexpr auto header = "archive_header"; 39 | constexpr auto input = "archive_input"; 40 | constexpr auto output = "archive_output"; 41 | constexpr auto point = "archive_point"; 42 | constexpr auto ins = "archive_ins"; 43 | constexpr auto outs = "archive_outs"; 44 | constexpr auto spend = "archive_spend"; 45 | constexpr auto tx = "archive_tx"; 46 | constexpr auto txs = "archive_txs"; 47 | } 48 | 49 | namespace indexes 50 | { 51 | constexpr auto candidate = "candidate"; 52 | constexpr auto confirmed = "confirmed"; 53 | constexpr auto strong_tx = "strong_tx"; 54 | } 55 | 56 | namespace caches 57 | { 58 | constexpr auto duplicate = "duplicate"; 59 | constexpr auto prevout = "prevout"; 60 | constexpr auto validated_bk = "validated_bk"; 61 | constexpr auto validated_tx = "validated_tx"; 62 | } 63 | 64 | namespace optionals 65 | { 66 | constexpr auto address = "address"; 67 | constexpr auto filter_bk = "filter_bk"; 68 | constexpr auto filter_tx = "filter_tx"; 69 | } 70 | 71 | namespace locks 72 | { 73 | constexpr auto flush = "flush"; 74 | constexpr auto process = "process"; 75 | } 76 | 77 | namespace ext 78 | { 79 | constexpr auto head = ".head"; 80 | constexpr auto data = ".data"; 81 | constexpr auto lock = ".lock"; 82 | } 83 | 84 | } // namespace schema 85 | } // namespace database 86 | } // namespace libbitcoin 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /include/bitcoin/database/tables/optionals/address.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_TABLES_OPTIONALS_ADDRESS_HPP 20 | #define LIBBITCOIN_DATABASE_TABLES_OPTIONALS_ADDRESS_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace libbitcoin { 28 | namespace database { 29 | namespace table { 30 | 31 | /// address is a record multimap of output fk records. 32 | struct address 33 | : public hash_map 34 | { 35 | using out = schema::output::link; 36 | using hash_map::hashmap; 37 | 38 | struct record 39 | : public schema::address 40 | { 41 | inline bool from_data(reader& source) NOEXCEPT 42 | { 43 | output_fk = source.read_little_endian(); 44 | return source; 45 | } 46 | 47 | inline bool to_data(finalizer& sink) const NOEXCEPT 48 | { 49 | sink.write_little_endian(output_fk); 50 | return sink; 51 | } 52 | 53 | inline bool operator==(const record& other) const NOEXCEPT 54 | { 55 | return output_fk == other.output_fk; 56 | } 57 | 58 | out::integer output_fk{}; 59 | }; 60 | }; 61 | 62 | } // namespace table 63 | } // namespace database 64 | } // namespace libbitcoin 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /include/bitcoin/database/tables/optionals/filter_bk.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_TABLES_OPTIONALS_FILTER_BK_HPP 20 | #define LIBBITCOIN_DATABASE_TABLES_OPTIONALS_FILTER_BK_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace libbitcoin { 28 | namespace database { 29 | namespace table { 30 | 31 | /// filter_bk is a slab arraymap of filter headers indexed by block link. 32 | struct filter_bk 33 | : public array_map 34 | { 35 | using array_map::arraymap; 36 | 37 | struct get_head 38 | : public schema::filter_bk 39 | { 40 | inline bool from_data(reader& source) NOEXCEPT 41 | { 42 | head = source.read_hash(); 43 | return source; 44 | } 45 | 46 | hash_digest head{}; 47 | }; 48 | 49 | struct put_ref 50 | : public schema::filter_bk 51 | { 52 | inline bool to_data(finalizer& sink) const NOEXCEPT 53 | { 54 | sink.write_bytes(head); 55 | BC_ASSERT(!sink || sink.get_write_position() == count() * minrow); 56 | return sink; 57 | } 58 | 59 | const hash_digest& head{}; 60 | }; 61 | }; 62 | 63 | } // namespace table 64 | } // namespace database 65 | } // namespace libbitcoin 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /include/bitcoin/database/tables/optionals/filter_tx.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_TABLES_OPTIONALS_FILTER_TX_HPP 20 | #define LIBBITCOIN_DATABASE_TABLES_OPTIONALS_FILTER_TX_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace libbitcoin { 28 | namespace database { 29 | namespace table { 30 | 31 | /// filter_tx is a slab of neutrino filters indexed by block link. 32 | struct filter_tx 33 | : public array_map 34 | { 35 | using array_map::arraymap; 36 | 37 | struct get_filter 38 | : public schema::filter_tx 39 | { 40 | link count() const NOEXCEPT 41 | { 42 | return system::possible_narrow_cast( 43 | variable_size(filter.size()) + filter.size()); 44 | } 45 | 46 | inline bool from_data(reader& source) NOEXCEPT 47 | { 48 | filter = source.read_bytes(source.read_size()); 49 | BC_ASSERT(!source || source.get_read_position() == count()); 50 | return source; 51 | } 52 | 53 | system::data_chunk filter{}; 54 | }; 55 | 56 | struct put_ref 57 | : public schema::filter_tx 58 | { 59 | link count() const NOEXCEPT 60 | { 61 | return system::possible_narrow_cast( 62 | variable_size(filter.size()) + filter.size()); 63 | } 64 | 65 | inline bool to_data(finalizer& sink) const NOEXCEPT 66 | { 67 | sink.write_variable(filter.size()); 68 | sink.write_bytes(filter); 69 | BC_ASSERT(!sink || sink.get_write_position() == count()); 70 | return sink; 71 | } 72 | 73 | const system::data_chunk& filter{}; 74 | }; 75 | }; 76 | 77 | } // namespace table 78 | } // namespace database 79 | } // namespace libbitcoin 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /include/bitcoin/database/tables/point_set.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_TABLES_POINT_SET_HPP 20 | #define LIBBITCOIN_DATABASE_TABLES_POINT_SET_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | namespace libbitcoin { 27 | namespace database { 28 | 29 | struct point_set 30 | { 31 | using tx_link = schema::transaction::link; 32 | 33 | struct point 34 | { 35 | // From header->prevouts cache. 36 | tx_link tx{}; 37 | bool coinbase{}; 38 | uint32_t sequence{}; 39 | }; 40 | 41 | // From block->txs->tx get version and points.resize(count). 42 | uint32_t version{}; 43 | std::vector points{}; 44 | }; 45 | using point_sets = std::vector; 46 | 47 | } // namespace database 48 | } // namespace libbitcoin 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /include/bitcoin/database/tables/states.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_TABLES_STATES_HPP 20 | #define LIBBITCOIN_DATABASE_TABLES_STATES_HPP 21 | 22 | #include 23 | #include 24 | 25 | namespace libbitcoin { 26 | namespace database { 27 | namespace schema { 28 | 29 | enum block_state : uint8_t 30 | { 31 | /// final 32 | confirmable = 0, 33 | 34 | /// transitional 35 | valid = 1, 36 | 37 | /// final 38 | unconfirmable = 2, 39 | 40 | /// transitional (debug) 41 | block_unknown = 42 42 | }; 43 | 44 | enum tx_state : uint8_t 45 | { 46 | /// final 47 | connected = 0, 48 | 49 | /// final 50 | disconnected = 1, 51 | 52 | /// transitional (debug) 53 | tx_unknown = 42 54 | }; 55 | 56 | } // namespace schema 57 | } // namespace database 58 | } // namespace libbitcoin 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /include/bitcoin/database/tables/table.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_TABLES_TABLE_HPP 20 | #define LIBBITCOIN_DATABASE_TABLES_TABLE_HPP 21 | 22 | namespace libbitcoin { 23 | namespace database { 24 | 25 | enum class table_t 26 | { 27 | store, 28 | 29 | /// Archives. 30 | header_table, 31 | header_head, 32 | header_body, 33 | input_table, 34 | input_head, 35 | input_body, 36 | output_table, 37 | output_head, 38 | output_body, 39 | point_table, 40 | point_head, 41 | point_body, 42 | ins_table, 43 | ins_head, 44 | ins_body, 45 | outs_table, 46 | outs_head, 47 | outs_body, 48 | spend_table, 49 | spend_head, 50 | spend_body, 51 | tx_table, 52 | tx_head, 53 | txs_table, 54 | tx_body, 55 | txs_head, 56 | txs_body, 57 | 58 | /// Indexes. 59 | candidate_table, 60 | candidate_head, 61 | candidate_body, 62 | confirmed_table, 63 | confirmed_head, 64 | confirmed_body, 65 | strong_tx_table, 66 | strong_tx_head, 67 | strong_tx_body, 68 | 69 | /// Caches. 70 | duplicate_table, 71 | duplicate_head, 72 | duplicate_body, 73 | prevout_table, 74 | prevout_head, 75 | prevout_body, 76 | validated_bk_table, 77 | validated_bk_head, 78 | validated_bk_body, 79 | validated_tx_table, 80 | validated_tx_head, 81 | validated_tx_body, 82 | 83 | /// Optionals. 84 | address_table, 85 | address_head, 86 | address_body, 87 | filter_bk_table, 88 | filter_bk_head, 89 | filter_bk_body, 90 | filter_tx_table, 91 | filter_tx_head, 92 | filter_tx_body 93 | }; 94 | 95 | } // namespace database 96 | } // namespace libbitcoin 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /include/bitcoin/database/tables/tables.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_TABLES_TABLES_HPP 20 | #define LIBBITCOIN_DATABASE_TABLES_TABLES_HPP 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | #include 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /include/bitcoin/database/version.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // Copyright (c) 2014-2025 libbitcoin-database developers (see COPYING). 3 | // 4 | // GENERATED SOURCE CODE, DO NOT EDIT EXCEPT EXPERIMENTALLY 5 | // 6 | /////////////////////////////////////////////////////////////////////////////// 7 | #ifndef LIBBITCOIN_DATABASE_VERSION_HPP 8 | #define LIBBITCOIN_DATABASE_VERSION_HPP 9 | 10 | /** 11 | * The semantic version of this repository as: [major].[minor].[patch] 12 | * For interpretation of the versioning scheme see: http://semver.org 13 | */ 14 | 15 | #define LIBBITCOIN_DATABASE_VERSION "4.0.0" 16 | #define LIBBITCOIN_DATABASE_MAJOR_VERSION 4 17 | #define LIBBITCOIN_DATABASE_MINOR_VERSION 0 18 | #define LIBBITCOIN_DATABASE_PATCH_VERSION 0 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /libbitcoin-database-test_runner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ############################################################################### 3 | # Copyright (c) 2014-2025 libbitcoin-database developers (see COPYING). 4 | # 5 | # GENERATED SOURCE CODE, DO NOT EDIT EXCEPT EXPERIMENTALLY 6 | # 7 | ############################################################################### 8 | 9 | # Define tests and options. 10 | #============================================================================== 11 | BOOST_UNIT_TEST_OPTIONS=\ 12 | "--run_test=* "\ 13 | "--log_level=warning "\ 14 | "--show_progress=no "\ 15 | "--detect_memory_leak=0 "\ 16 | "--report_level=no "\ 17 | "--build_info=yes" 18 | 19 | 20 | # Run tests. 21 | #============================================================================== 22 | # ALlow CI to send errors to standard output 23 | if [[ $CI == true ]]; then 24 | ./test/libbitcoin-database-test ${BOOST_UNIT_TEST_OPTIONS} 25 | else 26 | ./test/libbitcoin-database-test ${BOOST_UNIT_TEST_OPTIONS} > test.log 27 | fi 28 | -------------------------------------------------------------------------------- /libbitcoin-database.pc.in: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (c) 2014-2025 libbitcoin-database developers (see COPYING). 3 | # 4 | # GENERATED SOURCE CODE, DO NOT EDIT EXCEPT EXPERIMENTALLY 5 | # 6 | ############################################################################### 7 | 8 | # Substitutions 9 | #============================================================================== 10 | prefix=@prefix@ 11 | exec_prefix=@exec_prefix@ 12 | libdir=@libdir@ 13 | includedir=@includedir@ 14 | 15 | 16 | # Metadata 17 | #============================================================================== 18 | Name: libbitcoin-database 19 | Description: Bitcoin High Performance Blockchain Database 20 | URL: https://github.com/libbitcoin/libbitcoin-database 21 | Version: @PACKAGE_VERSION@ 22 | 23 | 24 | # Variables 25 | #============================================================================== 26 | # Dependencies that publish package configuration. 27 | #------------------------------------------------------------------------------ 28 | Requires: libbitcoin-system >= 4.0.0 29 | 30 | # Include directory and any other required compiler flags. 31 | #------------------------------------------------------------------------------ 32 | Cflags: -I${includedir} 33 | 34 | # Lib directory, lib and any required that do not publish pkg-config. 35 | #------------------------------------------------------------------------------ 36 | Libs: -L${libdir} -lbitcoin-database 37 | 38 | -------------------------------------------------------------------------------- /m4/.gitignore: -------------------------------------------------------------------------------- 1 | /libtool.m4 2 | /lt*.m4 3 | -------------------------------------------------------------------------------- /m4/ax_check_compile_flag.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check whether the given FLAG works with the current language's compiler 12 | # or gives an error. (Warnings, however, are ignored) 13 | # 14 | # ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on 15 | # success/failure. 16 | # 17 | # If EXTRA-FLAGS is defined, it is added to the current language's default 18 | # flags (e.g. CFLAGS) when the check is done. The check is thus made with 19 | # the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to 20 | # force the compiler to issue an error when a bad flag is given. 21 | # 22 | # INPUT gives an alternative input source to AC_COMPILE_IFELSE. 23 | # 24 | # NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this 25 | # macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. 26 | # 27 | # LICENSE 28 | # 29 | # Copyright (c) 2008 Guido U. Draheim 30 | # Copyright (c) 2011 Maarten Bosmans 31 | # 32 | # Copying and distribution of this file, with or without modification, are 33 | # permitted in any medium without royalty provided the copyright notice 34 | # and this notice are preserved. This file is offered as-is, without any 35 | # warranty. 36 | 37 | #serial 6 38 | 39 | AC_DEFUN([AX_CHECK_COMPILE_FLAG], 40 | [AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF 41 | AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl 42 | AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ 43 | ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS 44 | _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" 45 | AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], 46 | [AS_VAR_SET(CACHEVAR,[yes])], 47 | [AS_VAR_SET(CACHEVAR,[no])]) 48 | _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) 49 | AS_VAR_IF(CACHEVAR,yes, 50 | [m4_default([$2], :)], 51 | [m4_default([$3], :)]) 52 | AS_VAR_POPDEF([CACHEVAR])dnl 53 | ])dnl AX_CHECK_COMPILE_FLAGS 54 | -------------------------------------------------------------------------------- /m4/ax_check_link_flag.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_check_link_flag.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CHECK_LINK_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check whether the given FLAG works with the linker or gives an error. 12 | # (Warnings, however, are ignored) 13 | # 14 | # ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on 15 | # success/failure. 16 | # 17 | # If EXTRA-FLAGS is defined, it is added to the linker's default flags 18 | # when the check is done. The check is thus made with the flags: "LDFLAGS 19 | # EXTRA-FLAGS FLAG". This can for example be used to force the linker to 20 | # issue an error when a bad flag is given. 21 | # 22 | # INPUT gives an alternative input source to AC_LINK_IFELSE. 23 | # 24 | # NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this 25 | # macro in sync with AX_CHECK_{PREPROC,COMPILE}_FLAG. 26 | # 27 | # LICENSE 28 | # 29 | # Copyright (c) 2008 Guido U. Draheim 30 | # Copyright (c) 2011 Maarten Bosmans 31 | # 32 | # Copying and distribution of this file, with or without modification, are 33 | # permitted in any medium without royalty provided the copyright notice 34 | # and this notice are preserved. This file is offered as-is, without any 35 | # warranty. 36 | 37 | #serial 6 38 | 39 | AC_DEFUN([AX_CHECK_LINK_FLAG], 40 | [AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF 41 | AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_ldflags_$4_$1])dnl 42 | AC_CACHE_CHECK([whether the linker accepts $1], CACHEVAR, [ 43 | ax_check_save_flags=$LDFLAGS 44 | LDFLAGS="$LDFLAGS $4 $1" 45 | AC_LINK_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], 46 | [AS_VAR_SET(CACHEVAR,[yes])], 47 | [AS_VAR_SET(CACHEVAR,[no])]) 48 | LDFLAGS=$ax_check_save_flags]) 49 | AS_VAR_IF(CACHEVAR,yes, 50 | [m4_default([$2], :)], 51 | [m4_default([$3], :)]) 52 | AS_VAR_POPDEF([CACHEVAR])dnl 53 | ])dnl AX_CHECK_LINK_FLAGS 54 | -------------------------------------------------------------------------------- /m4/ax_check_preproc_flag.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_check_preproc_flag.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CHECK_PREPROC_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check whether the given FLAG works with the current language's 12 | # preprocessor or gives an error. (Warnings, however, are ignored) 13 | # 14 | # ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on 15 | # success/failure. 16 | # 17 | # If EXTRA-FLAGS is defined, it is added to the preprocessor's default 18 | # flags when the check is done. The check is thus made with the flags: 19 | # "CPPFLAGS EXTRA-FLAGS FLAG". This can for example be used to force the 20 | # preprocessor to issue an error when a bad flag is given. 21 | # 22 | # INPUT gives an alternative input source to AC_PREPROC_IFELSE. 23 | # 24 | # NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this 25 | # macro in sync with AX_CHECK_{COMPILE,LINK}_FLAG. 26 | # 27 | # LICENSE 28 | # 29 | # Copyright (c) 2008 Guido U. Draheim 30 | # Copyright (c) 2011 Maarten Bosmans 31 | # 32 | # Copying and distribution of this file, with or without modification, are 33 | # permitted in any medium without royalty provided the copyright notice 34 | # and this notice are preserved. This file is offered as-is, without any 35 | # warranty. 36 | 37 | #serial 6 38 | 39 | AC_DEFUN([AX_CHECK_PREPROC_FLAG], 40 | [AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF 41 | AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]cppflags_$4_$1])dnl 42 | AC_CACHE_CHECK([whether _AC_LANG preprocessor accepts $1], CACHEVAR, [ 43 | ax_check_save_flags=$CPPFLAGS 44 | CPPFLAGS="$CPPFLAGS $4 $1" 45 | AC_PREPROC_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], 46 | [AS_VAR_SET(CACHEVAR,[yes])], 47 | [AS_VAR_SET(CACHEVAR,[no])]) 48 | CPPFLAGS=$ax_check_save_flags]) 49 | AS_VAR_IF(CACHEVAR,yes, 50 | [m4_default([$2], :)], 51 | [m4_default([$3], :)]) 52 | AS_VAR_POPDEF([CACHEVAR])dnl 53 | ])dnl AX_CHECK_PREPROC_FLAGS 54 | -------------------------------------------------------------------------------- /src/locks/file_lock.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | namespace libbitcoin { 26 | namespace database { 27 | 28 | // locks, make_shared 29 | BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) 30 | 31 | file_lock::file_lock(const std::filesystem::path& file) NOEXCEPT 32 | : file_(file) 33 | { 34 | } 35 | 36 | const std::filesystem::path& file_lock::file() const NOEXCEPT 37 | { 38 | return file_; 39 | } 40 | 41 | bool file_lock::exists() const NOEXCEPT 42 | { 43 | system::ifstream stream(file_); 44 | return stream.good(); 45 | } 46 | 47 | // This is non-const as it alters state (externally but may become internal). 48 | bool file_lock::create() NOEXCEPT 49 | { 50 | system::ofstream stream(file_); 51 | return stream.good(); 52 | } 53 | 54 | // This is non-const as it alters state (externally but may become internal). 55 | bool file_lock::destroy() NOEXCEPT 56 | { 57 | // remove returns false if file did not exist though error_code is false if 58 | // file did not exist. use of error_code overload also precludes exception. 59 | std::error_code ec; 60 | std::filesystem::remove(system::to_extended_path(file_), ec); 61 | return !ec; 62 | } 63 | 64 | BC_POP_WARNING() 65 | 66 | } // namespace database 67 | } // namespace libbitcoin 68 | -------------------------------------------------------------------------------- /src/locks/flush_lock.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | namespace libbitcoin { 26 | namespace database { 27 | 28 | flush_lock::flush_lock(const std::filesystem::path& file) NOEXCEPT 29 | : file_lock(file) 30 | { 31 | } 32 | 33 | bool flush_lock::try_lock() NOEXCEPT 34 | { 35 | if (exists()) 36 | return false; 37 | 38 | return create(); 39 | } 40 | 41 | bool flush_lock::try_unlock() NOEXCEPT 42 | { 43 | if (!exists()) 44 | return false; 45 | 46 | return destroy(); 47 | } 48 | 49 | bool flush_lock::is_locked() const NOEXCEPT 50 | { 51 | return exists(); 52 | } 53 | 54 | } // namespace database 55 | } // namespace libbitcoin 56 | -------------------------------------------------------------------------------- /src/locks/interprocess_lock.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | namespace libbitcoin { 28 | namespace database { 29 | 30 | // ipcdetail functions do not throw (but are unannotated). 31 | BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) 32 | 33 | interprocess_lock::interprocess_lock(const std::filesystem::path& file) NOEXCEPT 34 | : file_lock(file), handle_(invalid) 35 | { 36 | } 37 | 38 | interprocess_lock::~interprocess_lock() NOEXCEPT 39 | { 40 | try_unlock(); 41 | } 42 | 43 | // Lock is not idempotent, returns false if already locked (or error). 44 | // This succeeds if no other process has exclusive or sharable ownership. 45 | bool interprocess_lock::try_lock() NOEXCEPT 46 | { 47 | // A valid handle guarantees file existence and ownership. 48 | if (handle_ != invalid) 49 | return false; 50 | 51 | // Create the file. 52 | if (!create()) 53 | return false; 54 | 55 | // Get a handle to the file. 56 | const auto handle = open_existing_file(file()); 57 | bool result; 58 | 59 | // Obtain exclusive access to the file. 60 | if (ipcdetail::try_acquire_file_lock(handle, result) && result) 61 | { 62 | handle_ = handle; 63 | return true; 64 | } 65 | 66 | handle_ = invalid; 67 | return false; 68 | } 69 | 70 | // Unlock is idempotent, returns true if unlocked on return (or success). 71 | // This may leave the lock file behind, which is not a problem. 72 | bool interprocess_lock::try_unlock() NOEXCEPT 73 | { 74 | // An invalid handle guarantees lack of ownership, but file may exist. 75 | // Do not delete the file unless we own it. 76 | if (handle_ == invalid) 77 | return true; 78 | 79 | // Delete before close, to preclude delete of a file that is not owned, 80 | // resulting from a race condition. The file is queued for deletion. 81 | const auto result = destroy(); 82 | 83 | // Release exclusive access to the file. 84 | ipcdetail::close_file(handle_); 85 | handle_ = invalid; 86 | return result; 87 | } 88 | 89 | BC_POP_WARNING() 90 | 91 | } // namespace database 92 | } // namespace libbitcoin 93 | -------------------------------------------------------------------------------- /src/memory/mman-win32/mman.hpp: -------------------------------------------------------------------------------- 1 | // mman-win32 based on code.google.com/p/mman-win32 (MIT License). 2 | 3 | #ifndef LIBBITCOIN_DATABASE_MMAN_HPP 4 | #define LIBBITCOIN_DATABASE_MMAN_HPP 5 | 6 | #ifdef _WIN32 7 | 8 | #include 9 | typedef size_t oft__; 10 | 11 | #define PROT_NONE 0 12 | #define PROT_READ 1 13 | #define PROT_WRITE 2 14 | #define PROT_EXEC 4 15 | 16 | #define MAP_FILE 0 17 | #define MAP_SYNC 0 18 | #define MAP_SHARED 1 19 | #define MAP_SHARED_VALIDATE MAP_SHARED 20 | #define MAP_PRIVATE 2 21 | #define MAP_TYPE 0xf 22 | #define MAP_FIXED 0x10 23 | #define MAP_ANONYMOUS 0x20 24 | #define MAP_ANON MAP_ANONYMOUS 25 | 26 | #define MAP_FAILED ((void*)-1) 27 | 28 | // Flags for msync. 29 | #define MS_ASYNC 1 30 | #define MS_SYNC 2 31 | #define MS_INVALIDATE 4 32 | 33 | // Flags for madvise (stub). 34 | #define MADV_RANDOM 0 35 | 36 | void* mmap(void* addr, size_t len, int prot, int flags, int fd, oft__ off) noexcept; 37 | void* mremap_(void* addr, size_t old_size, size_t new_size, int prot, 38 | int flags, int fd) noexcept; 39 | int munmap(void* addr, size_t len) noexcept; 40 | int madvise(void* addr, size_t len, int advice) noexcept; 41 | int mprotect(void* addr, size_t len, int prot) noexcept; 42 | int msync(void* addr, size_t len, int flags) noexcept; 43 | int mlock(const void* addr, size_t len) noexcept; 44 | int munlock(const void* addr, size_t len) noexcept; 45 | int fsync(int fd) noexcept; 46 | int ftruncate(int fd, oft__ size) noexcept; 47 | 48 | #endif // _WIN32 49 | #endif 50 | -------------------------------------------------------------------------------- /src/memory/utilities.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | 21 | #if defined(HAVE_MSC) 22 | #include 23 | #else 24 | #include 25 | #endif 26 | #include 27 | #include 28 | 29 | namespace libbitcoin { 30 | namespace database { 31 | 32 | #if defined(HAVE_MSC) 33 | 34 | size_t page_size() NOEXCEPT 35 | { 36 | using namespace system; 37 | SYSTEM_INFO info{}; 38 | GetSystemInfo(&info); 39 | 40 | BC_ASSERT(!system::is_limited(info.dwPageSize)); 41 | return info.dwPageSize; 42 | } 43 | 44 | uint64_t system_memory() NOEXCEPT 45 | { 46 | MEMORYSTATUSEX status{}; 47 | status.dwLength = sizeof(status); 48 | return is_zero(GlobalMemoryStatusEx(&status)) ? zero : 49 | status.ullTotalPhys; 50 | } 51 | 52 | #else 53 | 54 | size_t page_size() NOEXCEPT 55 | { 56 | using namespace system; 57 | errno = 0; 58 | 59 | const auto size = sysconf(_SC_PAGESIZE); 60 | if (is_negative(size) || is_nonzero(errno)) 61 | return zero; 62 | 63 | BC_ASSERT(!is_limited(size)); 64 | return possible_narrow_sign_cast(size); 65 | } 66 | 67 | uint64_t system_memory() NOEXCEPT 68 | { 69 | using namespace system; 70 | errno = 0; 71 | 72 | const int64_t pages = sysconf(_SC_PHYS_PAGES); 73 | if (is_negative(pages) || is_nonzero(errno)) 74 | return zero; 75 | 76 | // Failed page_size also results in zero return. 77 | return ceilinged_multiply(to_unsigned(pages), 78 | possible_wide_cast(page_size())); 79 | } 80 | 81 | #endif 82 | 83 | } // namespace database 84 | } // namespace libbitcoin 85 | -------------------------------------------------------------------------------- /src/settings.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | 21 | #include 22 | #include 23 | 24 | namespace libbitcoin { 25 | namespace database { 26 | 27 | using namespace bc::system; 28 | 29 | settings::settings() NOEXCEPT 30 | : path{ "bitcoin" }, 31 | 32 | // Archives. 33 | 34 | header_buckets{ 128 }, 35 | header_size{ 1 }, 36 | header_rate{ 50 }, 37 | 38 | input_size{ 1 }, 39 | input_rate{ 50 }, 40 | 41 | output_size{ 1 }, 42 | output_rate{ 50 }, 43 | 44 | point_buckets{ 128 }, 45 | point_size{ 1 }, 46 | point_rate{ 50 }, 47 | 48 | ins_size{ 1 }, 49 | ins_rate{ 50 }, 50 | 51 | outs_size{ 1 }, 52 | outs_rate{ 50 }, 53 | 54 | tx_buckets{ 128 }, 55 | tx_size{ 1 }, 56 | tx_rate{ 50 }, 57 | 58 | txs_buckets{ 128 }, 59 | txs_size{ 1 }, 60 | txs_rate{ 50 }, 61 | 62 | // Indexes. 63 | 64 | candidate_size{ 1 }, 65 | candidate_rate{ 50 }, 66 | 67 | confirmed_size{ 1 }, 68 | confirmed_rate{ 50 }, 69 | 70 | strong_tx_buckets{ 128 }, 71 | strong_tx_size{ 1 }, 72 | strong_tx_rate{ 50 }, 73 | 74 | // Caches. 75 | 76 | duplicate_buckets{ 128 }, 77 | duplicate_size{ 1 }, 78 | duplicate_rate{ 50 }, 79 | 80 | prevout_buckets{ 128 }, 81 | prevout_size{ 1 }, 82 | prevout_rate{ 50 }, 83 | 84 | validated_bk_buckets{ 128 }, 85 | validated_bk_size{ 1 }, 86 | validated_bk_rate{ 50 }, 87 | 88 | validated_tx_buckets{ 128 }, 89 | validated_tx_size{ 1 }, 90 | validated_tx_rate{ 50 }, 91 | 92 | // Optionals. 93 | 94 | address_buckets{ 128 }, 95 | address_size{ 1 }, 96 | address_rate{ 50 }, 97 | 98 | filter_bk_buckets{ 128 }, 99 | filter_bk_size{ 1 }, 100 | filter_bk_rate{ 50 }, 101 | 102 | filter_tx_buckets{ 128 }, 103 | filter_tx_size{ 1 }, 104 | filter_tx_rate{ 50 } 105 | { 106 | } 107 | 108 | settings::settings(chain::selection context) NOEXCEPT 109 | : settings() 110 | { 111 | switch (context) 112 | { 113 | case chain::selection::mainnet: 114 | { 115 | break; 116 | } 117 | 118 | case chain::selection::testnet: 119 | { 120 | break; 121 | } 122 | 123 | case chain::selection::regtest: 124 | { 125 | break; 126 | } 127 | 128 | default: 129 | case chain::selection::none: 130 | { 131 | } 132 | } 133 | } 134 | 135 | } // namespace database 136 | } // namespace libbitcoin 137 | -------------------------------------------------------------------------------- /test/locks/file_lock.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include "../test.hpp" 20 | 21 | struct file_lock_setup_fixture 22 | { 23 | file_lock_setup_fixture() noexcept 24 | { 25 | BOOST_REQUIRE(test::clear(test::directory)); 26 | } 27 | 28 | ~file_lock_setup_fixture() noexcept 29 | { 30 | BOOST_REQUIRE(test::clear(test::directory)); 31 | } 32 | }; 33 | 34 | BOOST_FIXTURE_TEST_SUITE(file_lock_tests, file_lock_setup_fixture) 35 | 36 | class access final 37 | : public file_lock 38 | { 39 | public: 40 | using file_lock::file_lock; 41 | 42 | bool exists_() const NOEXCEPT 43 | { 44 | return file_lock::exists(); 45 | } 46 | 47 | bool create_() NOEXCEPT 48 | { 49 | return file_lock::create(); 50 | } 51 | 52 | bool destroy_() NOEXCEPT 53 | { 54 | return file_lock::destroy(); 55 | } 56 | }; 57 | 58 | BOOST_AUTO_TEST_CASE(file_lock__construct__file__expected) 59 | { 60 | access instance(TEST_PATH); 61 | BOOST_REQUIRE_EQUAL(instance.file(), TEST_PATH); 62 | } 63 | 64 | BOOST_AUTO_TEST_CASE(file_lock__create__not_exists__true_created) 65 | { 66 | BOOST_REQUIRE(!test::exists(TEST_PATH)); 67 | 68 | access instance(TEST_PATH); 69 | BOOST_REQUIRE(instance.create_()); 70 | BOOST_REQUIRE(test::exists(TEST_PATH)); 71 | } 72 | 73 | // Creation is idempotent. 74 | BOOST_AUTO_TEST_CASE(file_lock__create__exists__true) 75 | { 76 | BOOST_REQUIRE(test::create(TEST_PATH)); 77 | 78 | access instance(TEST_PATH); 79 | BOOST_REQUIRE(instance.create_()); 80 | } 81 | 82 | BOOST_AUTO_TEST_CASE(file_lock__exists__not_exists__false) 83 | { 84 | BOOST_REQUIRE(!test::exists(TEST_PATH)); 85 | 86 | access instance(TEST_PATH); 87 | BOOST_REQUIRE(!instance.exists_()); 88 | } 89 | 90 | BOOST_AUTO_TEST_CASE(file_lock__exists__exists__true) 91 | { 92 | BOOST_REQUIRE(test::create(TEST_PATH)); 93 | 94 | access instance(TEST_PATH); 95 | BOOST_REQUIRE(instance.create_()); 96 | BOOST_REQUIRE(test::exists(TEST_PATH)); 97 | } 98 | 99 | // Destruction is idempotent. 100 | BOOST_AUTO_TEST_CASE(file_lock__destroy__not_exists__true) 101 | { 102 | BOOST_REQUIRE(!test::exists(TEST_PATH)); 103 | 104 | access instance(TEST_PATH); 105 | BOOST_REQUIRE(instance.destroy_()); 106 | } 107 | 108 | BOOST_AUTO_TEST_CASE(file_lock__destroy__exists__true_deleted) 109 | { 110 | BOOST_REQUIRE(test::create(TEST_PATH)); 111 | 112 | access instance(TEST_PATH); 113 | BOOST_REQUIRE(instance.destroy_()); 114 | BOOST_REQUIRE(!test::exists(TEST_PATH)); 115 | } 116 | 117 | BOOST_AUTO_TEST_SUITE_END() 118 | -------------------------------------------------------------------------------- /test/locks/flush_lock.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include "../test.hpp" 20 | 21 | struct flush_lock_setup_fixture 22 | { 23 | flush_lock_setup_fixture() noexcept 24 | { 25 | BOOST_REQUIRE(test::clear(test::directory)); 26 | } 27 | 28 | ~flush_lock_setup_fixture() noexcept 29 | { 30 | BOOST_REQUIRE(test::clear(test::directory)); 31 | } 32 | }; 33 | 34 | BOOST_FIXTURE_TEST_SUITE(flush_lock_tests, flush_lock_setup_fixture) 35 | 36 | BOOST_AUTO_TEST_CASE(flush_lock__construct__file__expected) 37 | { 38 | flush_lock instance(TEST_PATH); 39 | BOOST_REQUIRE_EQUAL(instance.file(), TEST_PATH); 40 | } 41 | 42 | BOOST_AUTO_TEST_CASE(flush_lock__try_lock__not_exists__true_created) 43 | { 44 | BOOST_REQUIRE(!test::exists(TEST_PATH)); 45 | 46 | flush_lock instance(TEST_PATH); 47 | BOOST_REQUIRE(instance.try_lock()); 48 | BOOST_REQUIRE(test::exists(TEST_PATH)); 49 | } 50 | 51 | BOOST_AUTO_TEST_CASE(flush_lock__try_lock__exists__false) 52 | { 53 | BOOST_REQUIRE(test::create(TEST_PATH)); 54 | 55 | flush_lock instance(TEST_PATH); 56 | BOOST_REQUIRE(!instance.try_lock()); 57 | } 58 | 59 | BOOST_AUTO_TEST_CASE(flush_lock__try_unlock__not_exists__false) 60 | { 61 | BOOST_REQUIRE(!test::exists(TEST_PATH)); 62 | 63 | flush_lock instance(TEST_PATH); 64 | BOOST_REQUIRE(!instance.try_unlock()); 65 | } 66 | 67 | BOOST_AUTO_TEST_CASE(flush_lock__try_unlock__exists__true_deleted) 68 | { 69 | BOOST_REQUIRE(test::create(TEST_PATH)); 70 | 71 | flush_lock instance(TEST_PATH); 72 | BOOST_REQUIRE(instance.try_unlock()); 73 | BOOST_REQUIRE(!test::exists(TEST_PATH)); 74 | } 75 | 76 | BOOST_AUTO_TEST_CASE(flush_lock__is_locked__not_exists__false) 77 | { 78 | BOOST_REQUIRE(!test::exists(TEST_PATH)); 79 | 80 | flush_lock instance(TEST_PATH); 81 | BOOST_REQUIRE(!instance.is_locked()); 82 | } 83 | 84 | BOOST_AUTO_TEST_CASE(flush_lock__is_locked__exists__true) 85 | { 86 | BOOST_REQUIRE(test::create(TEST_PATH)); 87 | 88 | flush_lock instance(TEST_PATH); 89 | BOOST_REQUIRE(instance.is_locked()); 90 | } 91 | 92 | BOOST_AUTO_TEST_SUITE_END() 93 | 94 | -------------------------------------------------------------------------------- /test/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #define BOOST_TEST_MODULE libbitcoin_database_test 20 | #include 21 | -------------------------------------------------------------------------------- /test/memory/utilities.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include "../test.hpp" 20 | 21 | BOOST_AUTO_TEST_SUITE(memory_utilities_tests) 22 | 23 | // It is presumed impossible for the page size to be zero, in which case this 24 | // test should never fail on any platform, though an API failure returns zero. 25 | BOOST_AUTO_TEST_CASE(memory_utilities__page_size__always__non_zero) 26 | { 27 | BOOST_REQUIRE(is_nonzero(page_size())); 28 | } 29 | 30 | // It is not possible for the actual memory to be zero and an overflow will 31 | // return max_uint64, so this test should never fail on any platform, though 32 | // an API failure returns zero. 33 | BOOST_AUTO_TEST_CASE(memory_utilities__system_memory__always__nonzero) 34 | { 35 | BOOST_REQUIRE(is_nonzero(system_memory())); 36 | } 37 | 38 | BOOST_AUTO_TEST_SUITE_END() 39 | -------------------------------------------------------------------------------- /test/mocks/chunk_storage.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #ifndef LIBBITCOIN_DATABASE_TEST_MOCKS_CHUNK_STORAGE_HPP 20 | #define LIBBITCOIN_DATABASE_TEST_MOCKS_CHUNK_STORAGE_HPP 21 | 22 | #include "../test.hpp" 23 | #include 24 | 25 | namespace test { 26 | 27 | // A thread safe storage implementation built on data_chunk. 28 | class chunk_storage 29 | : public database::storage 30 | { 31 | public: 32 | chunk_storage() NOEXCEPT; 33 | chunk_storage(system::data_chunk& reference) NOEXCEPT; 34 | chunk_storage(const std::filesystem::path& filename, size_t minimum=1, 35 | size_t expansion=0) NOEXCEPT; 36 | 37 | // test side door. 38 | system::data_chunk& buffer() NOEXCEPT; 39 | 40 | // storage interface. 41 | code open() NOEXCEPT override; 42 | code close() NOEXCEPT override; 43 | code load() NOEXCEPT override; 44 | code reload() NOEXCEPT override; 45 | code flush() NOEXCEPT override; 46 | code unload() NOEXCEPT override; 47 | const std::filesystem::path& file() const NOEXCEPT override; 48 | size_t capacity() const NOEXCEPT override; 49 | size_t size() const NOEXCEPT override; 50 | bool truncate(size_t size) NOEXCEPT override; 51 | bool expand(size_t size) NOEXCEPT override; 52 | bool reserve(size_t chunk) NOEXCEPT override; 53 | size_t allocate(size_t chunk) NOEXCEPT override; 54 | memory_ptr set(size_t offset, size_t size, uint8_t backfill) NOEXCEPT override; 55 | memory_ptr get(size_t offset=zero) const NOEXCEPT override; 56 | memory_ptr get_capacity(size_t offset=zero) const NOEXCEPT override; 57 | memory::iterator get_raw(size_t offset=zero) const NOEXCEPT override; 58 | code get_fault() const NOEXCEPT override; 59 | size_t get_space() const NOEXCEPT override; 60 | 61 | private: 62 | // These are protected by mutex. 63 | system::data_chunk local_{}; 64 | system::data_chunk& buffer_; 65 | size_t logical_; 66 | 67 | // These are thread safe. 68 | const std::filesystem::path path_; 69 | mutable std::shared_mutex field_mutex_{}; 70 | mutable std::shared_mutex map_mutex_{}; 71 | }; 72 | 73 | } // namespace test 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /test/query/archive_read.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include "../test.hpp" 20 | #include "../mocks/blocks.hpp" 21 | #include "../mocks/chunk_store.hpp" 22 | 23 | struct query_archive_read_setup_fixture 24 | { 25 | DELETE_COPY_MOVE(query_archive_read_setup_fixture); 26 | BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) 27 | 28 | query_archive_read_setup_fixture() NOEXCEPT 29 | { 30 | BOOST_REQUIRE(test::clear(test::directory)); 31 | } 32 | 33 | ~query_archive_read_setup_fixture() NOEXCEPT 34 | { 35 | BOOST_REQUIRE(test::clear(test::directory)); 36 | } 37 | 38 | BC_POP_WARNING() 39 | }; 40 | 41 | BOOST_FIXTURE_TEST_SUITE(query_archive_read_tests, query_archive_read_setup_fixture) 42 | 43 | const auto events_handler = [](auto, auto) {}; 44 | 45 | 46 | BOOST_AUTO_TEST_CASE(query_archive_read_test) 47 | { 48 | BOOST_REQUIRE(true); 49 | } 50 | 51 | BOOST_AUTO_TEST_SUITE_END() 52 | -------------------------------------------------------------------------------- /test/query/consensus.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include "../test.hpp" 20 | #include "../mocks/blocks.hpp" 21 | #include "../mocks/chunk_store.hpp" 22 | 23 | struct query_consensus_setup_fixture 24 | { 25 | DELETE_COPY_MOVE(query_consensus_setup_fixture); 26 | BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) 27 | 28 | query_consensus_setup_fixture() NOEXCEPT 29 | { 30 | BOOST_REQUIRE(test::clear(test::directory)); 31 | } 32 | 33 | ~query_consensus_setup_fixture() NOEXCEPT 34 | { 35 | BOOST_REQUIRE(test::clear(test::directory)); 36 | } 37 | 38 | BC_POP_WARNING() 39 | }; 40 | 41 | BOOST_FIXTURE_TEST_SUITE(query_consensus_tests, query_consensus_setup_fixture) 42 | 43 | const auto events_handler = [](auto, auto) {}; 44 | 45 | 46 | BOOST_AUTO_TEST_CASE(query_consensus_test) 47 | { 48 | BOOST_REQUIRE(true); 49 | } 50 | 51 | BOOST_AUTO_TEST_SUITE_END() 52 | -------------------------------------------------------------------------------- /test/query/height.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include "../test.hpp" 20 | #include "../mocks/blocks.hpp" 21 | #include "../mocks/chunk_store.hpp" 22 | 23 | struct query_height_setup_fixture 24 | { 25 | DELETE_COPY_MOVE(query_height_setup_fixture); 26 | BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) 27 | 28 | query_height_setup_fixture() NOEXCEPT 29 | { 30 | BOOST_REQUIRE(test::clear(test::directory)); 31 | } 32 | 33 | ~query_height_setup_fixture() NOEXCEPT 34 | { 35 | BOOST_REQUIRE(test::clear(test::directory)); 36 | } 37 | 38 | BC_POP_WARNING() 39 | }; 40 | 41 | BOOST_FIXTURE_TEST_SUITE(query_height_tests, query_height_setup_fixture) 42 | 43 | const auto events_handler = [](auto, auto) {}; 44 | 45 | 46 | BOOST_AUTO_TEST_CASE(query_height_test) 47 | { 48 | BOOST_REQUIRE(true); 49 | } 50 | 51 | BOOST_AUTO_TEST_SUITE_END() 52 | -------------------------------------------------------------------------------- /test/query/network.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include "../test.hpp" 20 | #include "../mocks/blocks.hpp" 21 | #include "../mocks/chunk_store.hpp" 22 | 23 | struct query_network_setup_fixture 24 | { 25 | DELETE_COPY_MOVE(query_network_setup_fixture); 26 | BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) 27 | 28 | query_network_setup_fixture() NOEXCEPT 29 | { 30 | BOOST_REQUIRE(test::clear(test::directory)); 31 | } 32 | 33 | ~query_network_setup_fixture() NOEXCEPT 34 | { 35 | BOOST_REQUIRE(test::clear(test::directory)); 36 | } 37 | 38 | BC_POP_WARNING() 39 | }; 40 | 41 | BOOST_FIXTURE_TEST_SUITE(query_network_tests, query_network_setup_fixture) 42 | 43 | const auto events_handler = [](auto, auto) {}; 44 | 45 | 46 | BOOST_AUTO_TEST_CASE(query_network_test) 47 | { 48 | BOOST_REQUIRE(true); 49 | } 50 | 51 | BOOST_AUTO_TEST_SUITE_END() 52 | -------------------------------------------------------------------------------- /test/query/objects.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include "../test.hpp" 20 | #include "../mocks/blocks.hpp" 21 | #include "../mocks/chunk_store.hpp" 22 | 23 | struct query_objects_setup_fixture 24 | { 25 | DELETE_COPY_MOVE(query_objects_setup_fixture); 26 | BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) 27 | 28 | query_objects_setup_fixture() NOEXCEPT 29 | { 30 | BOOST_REQUIRE(test::clear(test::directory)); 31 | } 32 | 33 | ~query_objects_setup_fixture() NOEXCEPT 34 | { 35 | BOOST_REQUIRE(test::clear(test::directory)); 36 | } 37 | 38 | BC_POP_WARNING() 39 | }; 40 | 41 | BOOST_FIXTURE_TEST_SUITE(query_objects_tests, query_objects_setup_fixture) 42 | 43 | const auto events_handler = [](auto, auto) {}; 44 | 45 | 46 | BOOST_AUTO_TEST_CASE(query_objects_test) 47 | { 48 | BOOST_REQUIRE(true); 49 | } 50 | 51 | BOOST_AUTO_TEST_SUITE_END() 52 | -------------------------------------------------------------------------------- /test/tables/archives/input.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include "../../test.hpp" 20 | #include "../../mocks/chunk_storage.hpp" 21 | 22 | BOOST_AUTO_TEST_SUITE(input_tests) 23 | 24 | using namespace system; 25 | 26 | BOOST_AUTO_TEST_CASE(input__put__empty_twice_get__expected) 27 | { 28 | const table::input::slab expected 29 | { 30 | {}, // schema::input [all const static members] 31 | {}, // script 32 | {} // witness 33 | }; 34 | 35 | const data_chunk expected_file 36 | { 37 | // slab0 38 | 0x00, // script 39 | 0x00, // witness 40 | 41 | // slab1 42 | 0x00, // script 43 | 0x00 // witness 44 | }; 45 | 46 | test::chunk_storage head_store{}; 47 | test::chunk_storage body_store{}; 48 | table::input instance{ head_store, body_store }; 49 | BOOST_REQUIRE(instance.create()); 50 | BOOST_REQUIRE(!instance.put_link(table::input::slab{}).is_terminal()); 51 | BOOST_REQUIRE(!instance.put_link(expected).is_terminal()); 52 | BOOST_REQUIRE_EQUAL(body_store.buffer(), expected_file); 53 | 54 | table::input::slab element{}; 55 | BOOST_REQUIRE(instance.get(0, element)); 56 | BOOST_REQUIRE(element == table::input::slab{}); 57 | 58 | BOOST_REQUIRE(instance.get(2, element)); 59 | BOOST_REQUIRE(element == expected); 60 | } 61 | 62 | BOOST_AUTO_TEST_CASE(input__put__non_empty_get__expected) 63 | { 64 | const table::input::slab expected 65 | { 66 | {}, // schema::input [all const static members] 67 | chain::script{ { chain::opcode::checkmultisigverify, chain::opcode::op_return } }, 68 | chain::witness{ { { 0x42 }, { 0x01, 0x02, 0x03 } } } 69 | }; 70 | 71 | const data_chunk expected_file 72 | { 73 | // slab0 74 | 0x00, // script 75 | 0x00, // witness 76 | 77 | // slab1 78 | 0x02, 0xaf, 0x6a, // script 79 | 0x02, 0x01, 0x42, 0x03, 0x01, 0x02, 0x03 // witness 80 | }; 81 | 82 | test::chunk_storage head_store{}; 83 | test::chunk_storage body_store{}; 84 | table::input instance{ head_store, body_store }; 85 | BOOST_REQUIRE(instance.create()); 86 | BOOST_REQUIRE(!instance.put_link(table::input::slab{}).is_terminal()); 87 | BOOST_REQUIRE(!instance.put_link(expected).is_terminal()); 88 | BOOST_REQUIRE_EQUAL(body_store.buffer(), expected_file); 89 | 90 | table::input::slab element{}; 91 | BOOST_REQUIRE(instance.get(0, element)); 92 | BOOST_REQUIRE(element == table::input::slab{}); 93 | 94 | BOOST_REQUIRE(instance.get(2u, element)); 95 | BOOST_REQUIRE(element == expected); 96 | } 97 | 98 | BOOST_AUTO_TEST_SUITE_END() 99 | -------------------------------------------------------------------------------- /test/tables/archives/output.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include "../../test.hpp" 20 | #include "../../mocks/chunk_storage.hpp" 21 | 22 | BOOST_AUTO_TEST_SUITE(output_tests) 23 | 24 | using namespace system; 25 | const table::output::slab expected 26 | { 27 | {}, // schema::output [all const static members] 28 | 0x56341201_u32, // parent_fk 29 | 0xdebc9a7856341202_u64, // value 30 | {} // script 31 | }; 32 | constexpr auto slab0_size = 6u; 33 | const data_chunk expected_file 34 | { 35 | // slab 36 | 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 38 | 0x00, 39 | 40 | // -------------------------------------------------------------------------------------------- 41 | 42 | // slab 43 | 0x01, 0x12, 0x34, 0x56, 44 | 0xff, 0x02, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 45 | 0x00 46 | }; 47 | 48 | BOOST_AUTO_TEST_CASE(output__put__get__expected) 49 | { 50 | test::chunk_storage head_store{}; 51 | test::chunk_storage body_store{}; 52 | table::output instance{ head_store, body_store }; 53 | BOOST_REQUIRE(!instance.put_link(table::output::slab{}).is_terminal()); 54 | BOOST_REQUIRE(!instance.put_link(expected).is_terminal()); 55 | BOOST_REQUIRE_EQUAL(body_store.buffer(), expected_file); 56 | 57 | table::output::slab element{}; 58 | BOOST_REQUIRE(instance.get(0, element)); 59 | BOOST_REQUIRE(element == table::output::slab{}); 60 | 61 | BOOST_REQUIRE(instance.get(slab0_size, element)); 62 | BOOST_REQUIRE(element == expected); 63 | } 64 | 65 | BOOST_AUTO_TEST_SUITE_END() 66 | -------------------------------------------------------------------------------- /test/tables/archives/point.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include "../../test.hpp" 20 | #include "../../mocks/chunk_storage.hpp" 21 | 22 | BOOST_AUTO_TEST_SUITE(point_tests) 23 | 24 | ////ffffffff 0000000000000000000000000000000000000000000000000000000000000000 ffffff 25 | ////00000000 110102030405060708090a0b0c0d0e0f220102030405060708090a0b0c0d0e0f 420000 26 | 27 | using namespace system; 28 | constexpr auto hash = base16_array("110102030405060708090a0b0c0d0e0f220102030405060708090a0b0c0d0e0f"); 29 | const data_chunk expected_file 30 | { 31 | // next 32 | 0xff, 0xff, 0xff, 0xff, 33 | 34 | // hash/index 35 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 36 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 37 | 0xff, 0xff, 0xff, 38 | 39 | // -------------------------------------------------------------------------------------------- 40 | 41 | // next 42 | 0x00, 0x00, 0x00, 0x00, 43 | 44 | // hash/index 45 | 0x11, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 46 | 0x22, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 47 | 0x42, 0x00, 0x00 48 | }; 49 | 50 | BOOST_AUTO_TEST_CASE(point__put__get__expected) 51 | { 52 | test::chunk_storage head_store{}; 53 | test::chunk_storage body_store{}; 54 | table::point instance{ head_store, body_store, 5 }; 55 | BOOST_REQUIRE(instance.create()); 56 | 57 | table::point::link link{}; 58 | const system::chain::point null_point{ null_hash, 0x00ffffff_u32 }; 59 | 60 | BOOST_REQUIRE(instance.put_link(link, null_point, table::point::record{})); 61 | BOOST_REQUIRE_EQUAL(link, 0u); 62 | 63 | const system::chain::point key{ hash, 0x00000042_u32 }; 64 | BOOST_REQUIRE(instance.put_link(link, key, table::point::record{})); 65 | BOOST_REQUIRE_EQUAL(link, 1u); 66 | BOOST_REQUIRE_EQUAL(body_store.buffer(), expected_file); 67 | 68 | table::point::record element{}; 69 | BOOST_REQUIRE(instance.get(0, element)); 70 | BOOST_REQUIRE_EQUAL(element.hash, null_hash); 71 | BOOST_REQUIRE(instance.get(1, element)); 72 | BOOST_REQUIRE_EQUAL(element.hash, hash); 73 | } 74 | 75 | BOOST_AUTO_TEST_SUITE_END() 76 | -------------------------------------------------------------------------------- /test/tables/caches/duplicate.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include "../../test.hpp" 20 | #include "../../mocks/chunk_storage.hpp" 21 | 22 | BOOST_AUTO_TEST_SUITE(duplicate_tests) 23 | 24 | BOOST_AUTO_TEST_CASE(duplicate_test) 25 | { 26 | BOOST_REQUIRE(true); 27 | } 28 | 29 | BOOST_AUTO_TEST_SUITE_END() 30 | -------------------------------------------------------------------------------- /test/tables/caches/validated_bk.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include "../../test.hpp" 20 | #include "../../mocks/chunk_storage.hpp" 21 | 22 | BOOST_AUTO_TEST_SUITE(validated_bk_tests) 23 | 24 | using namespace system; 25 | const table::validated_bk::slab slab1{ {}, 0x42, 0x1122334455667788 }; 26 | const table::validated_bk::slab slab2{ {}, 0xab, 0x0000000000000042 }; 27 | const data_chunk expected_head = base16_chunk 28 | ( 29 | "00000000" 30 | "00000000" 31 | "0a000000" 32 | "ffffffff" 33 | "ffffffff" 34 | "ffffffff" 35 | "ffffffff" 36 | "ffffffff" 37 | "ffffffff" 38 | ); 39 | const data_chunk closed_head = base16_chunk 40 | ( 41 | "0c000000" 42 | "00000000" 43 | "0a000000" 44 | "ffffffff" 45 | "ffffffff" 46 | "ffffffff" 47 | "ffffffff" 48 | "ffffffff" 49 | "ffffffff" 50 | ); 51 | const data_chunk expected_body = base16_chunk 52 | ( 53 | "42" // code1 54 | "ff8877665544332211" // fees1 55 | 56 | "ab" // code2 57 | "42" // fees2 58 | ); 59 | 60 | BOOST_AUTO_TEST_CASE(validated_bk__put__two__expected) 61 | { 62 | test::chunk_storage head_store{}; 63 | test::chunk_storage body_store{}; 64 | table::validated_bk instance{ head_store, body_store, 8 }; 65 | BOOST_REQUIRE(instance.create()); 66 | 67 | table::validated_bk::link link1{}; 68 | BOOST_REQUIRE(instance.put(0, slab1)); 69 | BOOST_REQUIRE_EQUAL(instance.at(0), 0u); 70 | 71 | table::validated_bk::link link2{}; 72 | BOOST_REQUIRE(instance.put(1, slab2)); 73 | BOOST_REQUIRE_EQUAL(instance.at(1), 10u); 74 | 75 | BOOST_REQUIRE_EQUAL(head_store.buffer(), expected_head); 76 | BOOST_REQUIRE_EQUAL(body_store.buffer(), expected_body); 77 | BOOST_REQUIRE(instance.close()); 78 | BOOST_REQUIRE_EQUAL(head_store.buffer(), closed_head); 79 | } 80 | 81 | BOOST_AUTO_TEST_CASE(validated_bk__get__two__expected) 82 | { 83 | auto head = expected_head; 84 | auto body = expected_body; 85 | test::chunk_storage head_store{ head }; 86 | test::chunk_storage body_store{ body }; 87 | table::validated_bk instance{ head_store, body_store, 3 }; 88 | BOOST_REQUIRE_EQUAL(head_store.buffer(), expected_head); 89 | BOOST_REQUIRE_EQUAL(body_store.buffer(), expected_body); 90 | 91 | table::validated_bk::slab out{}; 92 | BOOST_REQUIRE(instance.get(0, out)); 93 | BOOST_REQUIRE(out == slab1); 94 | BOOST_REQUIRE(instance.get(10, out)); 95 | BOOST_REQUIRE(out == slab2); 96 | } 97 | 98 | BOOST_AUTO_TEST_SUITE_END() 99 | -------------------------------------------------------------------------------- /test/tables/indexes/height.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include "../../test.hpp" 20 | #include "../../mocks/chunk_storage.hpp" 21 | 22 | BOOST_AUTO_TEST_SUITE(height_tests) 23 | 24 | using namespace system; 25 | const table::height::record in1{ {}, 0x12345678 }; 26 | const table::height::record in2{ {}, 0xabcdef12 }; 27 | const table::height::record out1{ {}, 0x00345678 }; 28 | const table::height::record out2{ {}, 0x00cdef12 }; 29 | const data_chunk expected_head = base16_chunk 30 | ( 31 | "000000" 32 | ); 33 | const data_chunk closed_head = base16_chunk 34 | ( 35 | "020000" 36 | ); 37 | const data_chunk expected_body = base16_chunk 38 | ( 39 | "785634" // header_fk1 40 | "12efcd" // header_fk2 41 | ); 42 | 43 | BOOST_AUTO_TEST_CASE(height__put__two__expected) 44 | { 45 | test::chunk_storage head_store{}; 46 | test::chunk_storage body_store{}; 47 | table::height instance{ head_store, body_store }; 48 | BOOST_REQUIRE(instance.create()); 49 | 50 | table::height::link link1{}; 51 | BOOST_REQUIRE(instance.put_link(link1, in1)); 52 | BOOST_REQUIRE_EQUAL(link1, 0u); 53 | 54 | table::height::link link2{}; 55 | BOOST_REQUIRE(instance.put_link(link2, in2)); 56 | BOOST_REQUIRE_EQUAL(link2, 1u); 57 | 58 | BOOST_REQUIRE_EQUAL(head_store.buffer(), expected_head); 59 | BOOST_REQUIRE_EQUAL(body_store.buffer(), expected_body); 60 | BOOST_REQUIRE(instance.close()); 61 | BOOST_REQUIRE_EQUAL(head_store.buffer(), closed_head); 62 | } 63 | 64 | BOOST_AUTO_TEST_CASE(height__get__two__expected) 65 | { 66 | auto head = expected_head; 67 | auto body = expected_body; 68 | test::chunk_storage head_store{ head }; 69 | test::chunk_storage body_store{ body }; 70 | table::height instance{ head_store, body_store }; 71 | BOOST_REQUIRE_EQUAL(head_store.buffer(), expected_head); 72 | BOOST_REQUIRE_EQUAL(body_store.buffer(), expected_body); 73 | 74 | table::height::record out{}; 75 | BOOST_REQUIRE(instance.get(0u, out)); 76 | BOOST_REQUIRE(out == out1); 77 | BOOST_REQUIRE(instance.get(1u, out)); 78 | BOOST_REQUIRE(out == out2); 79 | } 80 | 81 | BOOST_AUTO_TEST_SUITE_END() 82 | -------------------------------------------------------------------------------- /test/tables/indexes/strong_tx.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include "../../test.hpp" 20 | #include "../../mocks/chunk_storage.hpp" 21 | 22 | BOOST_AUTO_TEST_SUITE(strong_tx_tests) 23 | 24 | using namespace system; 25 | const table::strong_tx::key key1{ 0x01, 0x02, 0x03, 0x04 }; 26 | const table::strong_tx::key key2{ 0xa1, 0xa2, 0xa3, 0xa4 }; 27 | const table::strong_tx::record strong1{ {}, table::strong_tx::merge(true, 0x0078f87f) }; 28 | const table::strong_tx::record strong2{ {}, table::strong_tx::merge(false, 0x0078f87f) }; 29 | 30 | const data_chunk expected_head = base16_chunk 31 | ( 32 | "00000000" 33 | "ffffffff" 34 | "01000000" 35 | "ffffffff" 36 | "ffffffff" 37 | "ffffffff" 38 | "ffffffff" 39 | "ffffffff" 40 | "ffffffff" 41 | ); 42 | const data_chunk closed_head = base16_chunk 43 | ( 44 | "02000000" 45 | "ffffffff" 46 | "01000000" 47 | "ffffffff" 48 | "ffffffff" 49 | "ffffffff" 50 | "ffffffff" 51 | "ffffffff" 52 | "ffffffff" 53 | ); 54 | const data_chunk expected_body = base16_chunk 55 | ( 56 | "ffffffff" // next->end 57 | "01020304" // key1 58 | "7ff8f8" // 0x0078f87f | 0x00800000 59 | 60 | "00000000" // next-> 61 | "a1a2a3a4" // key2 62 | "7ff878" // 0x0078f87f | 0x00000000 63 | ); 64 | 65 | BOOST_AUTO_TEST_CASE(strong_tx__put__two__expected) 66 | { 67 | test::chunk_storage head_store{}; 68 | test::chunk_storage body_store{}; 69 | table::strong_tx instance{ head_store, body_store, 8 }; 70 | BOOST_REQUIRE(instance.create()); 71 | 72 | table::strong_tx::link link1{}; 73 | BOOST_REQUIRE(instance.put_link(link1, key1, strong1)); 74 | BOOST_REQUIRE_EQUAL(link1, 0u); 75 | 76 | table::strong_tx::link link2{}; 77 | BOOST_REQUIRE(instance.put_link(link2, key2, strong2)); 78 | BOOST_REQUIRE_EQUAL(link2, 1u); 79 | 80 | BOOST_REQUIRE_EQUAL(head_store.buffer(), expected_head); 81 | BOOST_REQUIRE_EQUAL(body_store.buffer(), expected_body); 82 | BOOST_REQUIRE(instance.close()); 83 | BOOST_REQUIRE_EQUAL(head_store.buffer(), closed_head); 84 | } 85 | 86 | BOOST_AUTO_TEST_CASE(strong_tx__get__two__expected) 87 | { 88 | auto head = expected_head; 89 | auto body = expected_body; 90 | test::chunk_storage head_store{ head }; 91 | test::chunk_storage body_store{ body }; 92 | table::strong_tx instance{ head_store, body_store, 32 }; 93 | BOOST_REQUIRE_EQUAL(head_store.buffer(), expected_head); 94 | BOOST_REQUIRE_EQUAL(body_store.buffer(), expected_body); 95 | 96 | table::strong_tx::record out{}; 97 | BOOST_REQUIRE(instance.get(0u, out)); 98 | BOOST_REQUIRE_EQUAL(out.header_fk(), strong1.header_fk()); 99 | BOOST_REQUIRE_EQUAL(out.positive(), strong1.positive()); 100 | BOOST_REQUIRE_EQUAL(out.block_fk, bit_or(0x0078f87fu, 0x00800000u)); 101 | 102 | BOOST_REQUIRE(instance.get(1u, out)); 103 | BOOST_REQUIRE_EQUAL(out.header_fk(), strong2.header_fk()); 104 | BOOST_REQUIRE_EQUAL(out.positive(), strong2.positive()); 105 | BOOST_REQUIRE_EQUAL(out.block_fk, bit_or(0x0078f87fu, 0x00000000u)); 106 | } 107 | 108 | BOOST_AUTO_TEST_SUITE_END() 109 | -------------------------------------------------------------------------------- /test/tables/optional/address.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include "../../test.hpp" 20 | #include "../../mocks/chunk_storage.hpp" 21 | 22 | BOOST_AUTO_TEST_SUITE(address_tests) 23 | 24 | using namespace system; 25 | const table::address::key key1 = base16_array("100000000000000000000000000000000000000000000000000000000000000a"); 26 | const table::address::key key2 = base16_array("200000000000000000000000000000000000000000000000000000000000000b"); 27 | const table::address::record in1{ {}, 0x1234567890abcdef }; 28 | const table::address::record in2{ {}, 0xabcdef1234567890 }; 29 | const table::address::record out1{ {}, 0x0000007890abcdef }; 30 | const table::address::record out2{ {}, 0x0000001234567890 }; 31 | const data_chunk expected_head = base16_chunk 32 | ( 33 | "00000000" 34 | "01000000" 35 | "ffffffff" 36 | "ffffffff" 37 | "ffffffff" 38 | "ffffffff" 39 | "ffffffff" 40 | "ffffffff" 41 | "ffffffff" 42 | ); 43 | const data_chunk closed_head = base16_chunk 44 | ( 45 | "02000000" 46 | "01000000" 47 | "ffffffff" 48 | "ffffffff" 49 | "ffffffff" 50 | "ffffffff" 51 | "ffffffff" 52 | "ffffffff" 53 | "ffffffff" 54 | ); 55 | const data_chunk expected_body = base16_chunk 56 | ( 57 | "ffffffff" // next->end 58 | "100000000000000000000000000000000000000000000000000000000000000a" // key1 59 | "efcdab9078" // output1 [low 5 bytes] 60 | 61 | "00000000" // next->0 62 | "200000000000000000000000000000000000000000000000000000000000000b" // key2 63 | "9078563412" // output2 [low 5 bytes] 64 | ); 65 | 66 | BOOST_AUTO_TEST_CASE(address__put__two__expected) 67 | { 68 | test::chunk_storage head_store{}; 69 | test::chunk_storage body_store{}; 70 | table::address instance{ head_store, body_store, 8 }; 71 | BOOST_REQUIRE(instance.create()); 72 | 73 | table::address::link link1{}; 74 | BOOST_REQUIRE(instance.put_link(link1, key1, in1)); 75 | BOOST_REQUIRE_EQUAL(link1, 0u); 76 | 77 | table::address::link link2{}; 78 | BOOST_REQUIRE(instance.put_link(link2, key2, in2)); 79 | BOOST_REQUIRE_EQUAL(link2, 1u); 80 | 81 | BOOST_REQUIRE_EQUAL(head_store.buffer(), expected_head); 82 | BOOST_REQUIRE_EQUAL(body_store.buffer(), expected_body); 83 | BOOST_REQUIRE(instance.close()); 84 | BOOST_REQUIRE_EQUAL(head_store.buffer(), closed_head); 85 | } 86 | 87 | BOOST_AUTO_TEST_CASE(address__get__two__expected) 88 | { 89 | auto head = expected_head; 90 | auto body = expected_body; 91 | test::chunk_storage head_store{ head }; 92 | test::chunk_storage body_store{ body }; 93 | table::address instance{ head_store, body_store, 8 }; 94 | BOOST_REQUIRE_EQUAL(head_store.buffer(), expected_head); 95 | BOOST_REQUIRE_EQUAL(body_store.buffer(), expected_body); 96 | 97 | table::address::record out{}; 98 | BOOST_REQUIRE(instance.get(0, out)); 99 | BOOST_REQUIRE(out == out1); 100 | BOOST_REQUIRE(instance.get(1, out)); 101 | BOOST_REQUIRE(out == out2); 102 | } 103 | 104 | BOOST_AUTO_TEST_SUITE_END() 105 | -------------------------------------------------------------------------------- /tools/initchain/initchain.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) 3 | * 4 | * This file is part of libbitcoin. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | */ 19 | #include 20 | #include 21 | 22 | int main(int, char**) 23 | { 24 | return 0; 25 | } 26 | --------------------------------------------------------------------------------