bitcoinkernel exposes a C API. It mostly operates on pointers (which
usually, but not always) are managed by the user. This combined with the
fact that C does not have classes makes the API quite different from how
one would organize a Python API.
Wrapper libraries (such as py-bitcoinkernel)
hide this "awkwardness" and expose a much more concise, Pythonic
interface. To give maximum insight into the bitcoinkernel API, we
will use the raw API in this workshop, while also offering a
wrapped/ version using the py-bitcoinkernel library
to highlight the difference. The wrapped version can be used as a
guideline, too.
Both versions use shared code from the common/
library, which you shouldn't have to modify in this workshop.
- Python 3.10 or later
- A Bitcoin Core datadir of the chain you are interested in. For this
workshop, signet or mainnet are recommended. Because
bitcoindrequires exclusive access to the datadir, it is recommended you copy theblocks/andchainstate/directories to a separate directory for this workshop. py-bitcoinkernelandbitcoinkernelare dependencies of this project, and are installed automatically when you install the python package. Please refer to thepy-bitcoinkernelinstallation instructions for more information.
cd python
python -m venv .venv
source .venv/bin/activate
pip install -e . -v
- Complete the code in the
./src/raw/main.pyfile. - Run the application (see args.py for more
information on which arguments are available), as e.g.:
raw --start_height=-10 --datadir=/tmp/kernel-workshop
- If the application runs successfully, you should see a
block_frequencies.jsonfile in thedata/op_code/frequency/directory, containing the frequency of each TapScript OP_CODE in the specified blocks. - Optionally, visualize the results with the frontend.
[!NOTE] The solutions can be found in the
main.pyfile in thesolutionsbranch.