|
| 1 | +# go-bitcoinkernel |
| 2 | + |
| 3 | +A Go wrapper for Bitcoin Core's [`libbitcoinkernel`](https://github.com/bitcoin/bitcoin/pull/30595) library. |
| 4 | + |
| 5 | +## ⚠️ Work in Progress |
| 6 | + |
| 7 | +This library is currently under active development. Check [TODO.md](./TODO.md) for current status and missing wrappers. |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +This repository consists of: |
| 12 | + |
| 13 | +- **Bitcoin Core Source**: [Git subtree](./depend/bitcoin) containing Bitcoin Core source code with `libbitcoinkernel` C |
| 14 | + API |
| 15 | +- **Kernel Package**: Safe, idiomatic Go interfaces with integrated CGO bindings that manage memory and provide error handling |
| 16 | +- **Utils Package**: Helper functions and utilities built on the kernel package wrappers for common operations |
| 17 | + |
| 18 | +## Installation and Usage |
| 19 | + |
| 20 | +Since this library includes native C++ dependencies that must be compiled from source, it cannot be installed directly |
| 21 | +via `go get` (at least for now). Follow these steps: |
| 22 | + |
| 23 | +### Step 1: Clone the Repository |
| 24 | + |
| 25 | +```bash |
| 26 | +git clone https://github.com/stringintech/go-bitcoinkernel.git |
| 27 | +cd go-bitcoinkernel |
| 28 | +``` |
| 29 | + |
| 30 | +### Step 2: Build the Native Library |
| 31 | + |
| 32 | +```bash |
| 33 | +make build-kernel |
| 34 | +``` |
| 35 | + |
| 36 | +This command will: |
| 37 | + |
| 38 | +- Configure Bitcoin Core's CMake build system |
| 39 | +- Build only the `libbitcoinkernel` library |
| 40 | +- Use parallel compilation for faster builds |
| 41 | + |
| 42 | +Refer to Bitcoin Core's build documentation to for the minimum requirements to compile `libbitcoinkernel` from source: |
| 43 | +([Unix](./depend/bitcoin/doc/build-unix.md), |
| 44 | +[macOS](./depend/bitcoin/doc/build-osx.md), |
| 45 | +[Windows](./depend/bitcoin/doc/build-windows.md)) |
| 46 | + |
| 47 | +### Step 3: Run Tests |
| 48 | + |
| 49 | +```bash |
| 50 | +make test |
| 51 | +``` |
| 52 | + |
| 53 | +This ensures that both the native library and Go bindings are working correctly. |
| 54 | + |
| 55 | +The tests also include examples demonstrating how to use different components. For example, see: |
| 56 | +- [`chainstate_manager_test.go`](./kernel/chainstate_manager_test.go) |
| 57 | +- [`logger_test.go`](./utils/logger_test.go) |
| 58 | + |
| 59 | +### Step 4: Use in Your Project |
| 60 | + |
| 61 | +In your Go project directory, add a replace directive to point to your local copy: |
| 62 | + |
| 63 | +```bash |
| 64 | +# Initialize your Go module (if not already done) |
| 65 | +go mod init your-project-name |
| 66 | + |
| 67 | +# Add replace directive to use local go-bitcoinkernel |
| 68 | +go mod edit -replace github.com/stringintech/go-bitcoinkernel=../path/to/go-bitcoinkernel |
| 69 | + |
| 70 | +# Add the dependency |
| 71 | +go get github.com/stringintech/go-bitcoinkernel/kernel |
| 72 | +``` |
| 73 | + |
| 74 | +Your `go.mod` file should look like this: |
| 75 | + |
| 76 | +```go |
| 77 | +module your-project-name |
| 78 | + |
| 79 | +go 1.23.3 |
| 80 | + |
| 81 | +require github.com/stringintech/go -bitcoinkernel/kernel v0.0.0-00010101000000-000000000000 |
| 82 | + |
| 83 | +replace github.com/stringintech/go -bitcoinkernel = >../path/to/go-bitcoinkernel |
| 84 | +``` |
| 85 | + |
| 86 | +## Important Notes |
| 87 | + |
| 88 | +### Memory Management |
| 89 | + |
| 90 | +The library handles memory management automatically through Go's finalizers, but it's highly recommended to explicitly |
| 91 | +call `Destroy()` methods when you're done with objects to free resources immediately. |
0 commit comments