Skip to content

Commit 7b39be0

Browse files
committed
contrib: add script dump_to_sqlite.sh for direct SQLite3 UTXO dump
1 parent 1f15b6e commit 7b39be0

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

contrib/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ to a SQLite3 database. The coins are stored in a table with the following schema
5353
```
5454
CREATE TABLE utxos(txid TEXT, vout INT, value INT, coinbase INT, height INT, scriptpubkey TEXT)
5555
```
56+
57+
### [Dump-to-SQLite](/contrib/utxo-tools/dump_to_sqlite.sh) ###
58+
This script creates an UTXO set dump in SQLite3 format on the fly from a running bitcoind instance,
59+
i.e. with the intermediate step of storing the compact-serialized UTXO set on disk is skipped.

contrib/utxo-tools/dump_to_sqlite.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
if [ $# -ne 2 ]; then
4+
echo "Usage: $0 <bitcoin-cli-path> <output-file>"
5+
exit 1
6+
fi
7+
8+
BITCOIN_CLI=$1
9+
OUTPUT_FILE=$2
10+
UTXO_TO_SQLITE=`dirname $0`/utxo_to_sqlite.py
11+
12+
# create named pipe in unique temporary folder
13+
TEMPPATH=$(mktemp -d)
14+
FIFOPATH=$TEMPPATH/utxos.fifo
15+
mkfifo $FIFOPATH
16+
17+
# start dumping UTXO set to the pipe in background
18+
$BITCOIN_CLI dumptxoutset $FIFOPATH latest &
19+
BITCOIN_CLI_PID=$!
20+
21+
# start UTXO to SQLite conversion tool, reading from pipe
22+
$UTXO_TO_SQLITE $FIFOPATH $OUTPUT_FILE
23+
24+
# wait and cleanup
25+
wait $BITCOIN_CLI_PID
26+
rm -r $TEMPPATH

0 commit comments

Comments
 (0)