Skip to content

Commit 4c8e9b4

Browse files
committed
contrib: add script dump_to_sqlite.sh for direct SQLite3 UTXO dump
1 parent cfda1d1 commit 4c8e9b4

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

contrib/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,7 @@ UTXO Set Tools
5151
This script converts a compact-serialized UTXO set (as generated by Bitcoin Core with `dumptxoutset`)
5252
to a SQLite3 database. For more details like e.g. the created table name and schema, refer to the
5353
module docstring on top of the script, which is also contained in the command's `--help` output.
54+
55+
### [Dump-to-SQLite](/contrib/utxo-tools/dump_to_sqlite.sh) ###
56+
This script creates an UTXO set dump in SQLite3 format on the fly from a running bitcoind instance,
57+
i.e. with the intermediate step of storing the compact-serialized UTXO set on disk is skipped.

contrib/utxo-tools/dump_to_sqlite.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) 2024-present The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
export LC_ALL=C
7+
set -e
8+
9+
if [ $# -ne 2 ]; then
10+
echo "Usage: $0 <bitcoin-cli-path> <output-file>"
11+
exit 1
12+
fi
13+
14+
BITCOIN_CLI=$1
15+
OUTPUT_FILE=$2
16+
UTXO_TO_SQLITE=$(dirname "$0")/utxo_to_sqlite.py
17+
18+
# create named pipe in unique temporary folder
19+
TEMPPATH=$(mktemp -d)
20+
FIFOPATH=$TEMPPATH/utxos.fifo
21+
mkfifo "$FIFOPATH"
22+
23+
# start dumping UTXO set to the pipe in background
24+
$BITCOIN_CLI dumptxoutset "$FIFOPATH" latest &
25+
BITCOIN_CLI_PID=$!
26+
27+
# start UTXO to SQLite conversion tool, reading from pipe
28+
$UTXO_TO_SQLITE "$FIFOPATH" "$OUTPUT_FILE"
29+
30+
# wait and cleanup
31+
wait $BITCOIN_CLI_PID
32+
rm -r "$TEMPPATH"

0 commit comments

Comments
 (0)