Skip to content

Commit cb1aa33

Browse files
authored
Merge pull request #11 from janb84/update_class_protection
refactor: consolidate to single BitcoinKernel package with clean namespace layout
2 parents 74bef56 + f6bb439 commit cb1aa33

73 files changed

Lines changed: 2335 additions & 3608 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

BitcoinKernel.NET.sln

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{827E0CD3-B72
1111
EndProject
1212
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{F8E63A4F-7D3E-4B2A-9C1D-8A5F6E9B3C2D}"
1313
EndProject
14-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitcoinKernel.Tests", "tests\BitcoinKernel.Tests\BitcoinKernel.Tests.csproj", "{BC90EFB4-1692-CBCC-EF52-778255F591E2}"
15-
EndProject
1614
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicUsage", "examples\BasicUsage\BasicUsage.csproj", "{0E2DDF4A-A1FE-5424-03EA-7A8E76751354}"
1715
EndProject
1816
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitcoinKernel.Interop", "src\BitcoinKernel.Interop\BitcoinKernel.Interop.csproj", "{9C4AFB5E-ED75-909E-FC61-1BD17BB6BC23}"
1917
EndProject
20-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitcoinKernel.Core", "src\BitcoinKernel.Core\BitcoinKernel.Core.csproj", "{2BDCF8E8-DD35-3BA0-0148-5A2588335678}"
21-
EndProject
22-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitcoinKernel", "src\BitcoinKernel\BitcoinKernel.csproj", "{D6F509B1-C990-0533-2DD1-CFFBA7506249}"
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitcoinKernel", "src\BitcoinKernel\BitcoinKernel.csproj", "{2BDCF8E8-DD35-3BA0-0148-5A2588335678}"
2319
EndProject
2420
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlockProcessing", "examples\BlockProcessing\BlockProcessing.csproj", "{23E19BC3-8829-42BE-BCB4-A2050BE04975}"
2521
EndProject
26-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitcoinKernel.Core.Tests", "tests\BitcoinKernel.Core.Tests\BitcoinKernel.Core.Tests.csproj", "{267842B2-D915-4B9E-8448-F9B5816D4A0A}"
22+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitcoinKernel.Tests", "tests\BitcoinKernel.Tests\BitcoinKernel.Tests.csproj", "{267842B2-D915-4B9E-8448-F9B5816D4A0A}"
2723
EndProject
2824
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "kernel-bindings-test-handler", "tools\kernel-bindings-test-handler\kernel-bindings-test-handler.csproj", "{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}"
2925
EndProject
@@ -37,18 +33,6 @@ Global
3733
Release|x86 = Release|x86
3834
EndGlobalSection
3935
GlobalSection(ProjectConfigurationPlatforms) = postSolution
40-
{BC90EFB4-1692-CBCC-EF52-778255F591E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41-
{BC90EFB4-1692-CBCC-EF52-778255F591E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
42-
{BC90EFB4-1692-CBCC-EF52-778255F591E2}.Debug|x64.ActiveCfg = Debug|Any CPU
43-
{BC90EFB4-1692-CBCC-EF52-778255F591E2}.Debug|x64.Build.0 = Debug|Any CPU
44-
{BC90EFB4-1692-CBCC-EF52-778255F591E2}.Debug|x86.ActiveCfg = Debug|Any CPU
45-
{BC90EFB4-1692-CBCC-EF52-778255F591E2}.Debug|x86.Build.0 = Debug|Any CPU
46-
{BC90EFB4-1692-CBCC-EF52-778255F591E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
47-
{BC90EFB4-1692-CBCC-EF52-778255F591E2}.Release|Any CPU.Build.0 = Release|Any CPU
48-
{BC90EFB4-1692-CBCC-EF52-778255F591E2}.Release|x64.ActiveCfg = Release|Any CPU
49-
{BC90EFB4-1692-CBCC-EF52-778255F591E2}.Release|x64.Build.0 = Release|Any CPU
50-
{BC90EFB4-1692-CBCC-EF52-778255F591E2}.Release|x86.ActiveCfg = Release|Any CPU
51-
{BC90EFB4-1692-CBCC-EF52-778255F591E2}.Release|x86.Build.0 = Release|Any CPU
5236
{0E2DDF4A-A1FE-5424-03EA-7A8E76751354}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
5337
{0E2DDF4A-A1FE-5424-03EA-7A8E76751354}.Debug|Any CPU.Build.0 = Debug|Any CPU
5438
{0E2DDF4A-A1FE-5424-03EA-7A8E76751354}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -85,18 +69,6 @@ Global
8569
{2BDCF8E8-DD35-3BA0-0148-5A2588335678}.Release|x64.Build.0 = Release|Any CPU
8670
{2BDCF8E8-DD35-3BA0-0148-5A2588335678}.Release|x86.ActiveCfg = Release|Any CPU
8771
{2BDCF8E8-DD35-3BA0-0148-5A2588335678}.Release|x86.Build.0 = Release|Any CPU
88-
{D6F509B1-C990-0533-2DD1-CFFBA7506249}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
89-
{D6F509B1-C990-0533-2DD1-CFFBA7506249}.Debug|Any CPU.Build.0 = Debug|Any CPU
90-
{D6F509B1-C990-0533-2DD1-CFFBA7506249}.Debug|x64.ActiveCfg = Debug|Any CPU
91-
{D6F509B1-C990-0533-2DD1-CFFBA7506249}.Debug|x64.Build.0 = Debug|Any CPU
92-
{D6F509B1-C990-0533-2DD1-CFFBA7506249}.Debug|x86.ActiveCfg = Debug|Any CPU
93-
{D6F509B1-C990-0533-2DD1-CFFBA7506249}.Debug|x86.Build.0 = Debug|Any CPU
94-
{D6F509B1-C990-0533-2DD1-CFFBA7506249}.Release|Any CPU.ActiveCfg = Release|Any CPU
95-
{D6F509B1-C990-0533-2DD1-CFFBA7506249}.Release|Any CPU.Build.0 = Release|Any CPU
96-
{D6F509B1-C990-0533-2DD1-CFFBA7506249}.Release|x64.ActiveCfg = Release|Any CPU
97-
{D6F509B1-C990-0533-2DD1-CFFBA7506249}.Release|x64.Build.0 = Release|Any CPU
98-
{D6F509B1-C990-0533-2DD1-CFFBA7506249}.Release|x86.ActiveCfg = Release|Any CPU
99-
{D6F509B1-C990-0533-2DD1-CFFBA7506249}.Release|x86.Build.0 = Release|Any CPU
10072
{23E19BC3-8829-42BE-BCB4-A2050BE04975}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
10173
{23E19BC3-8829-42BE-BCB4-A2050BE04975}.Debug|Any CPU.Build.0 = Debug|Any CPU
10274
{23E19BC3-8829-42BE-BCB4-A2050BE04975}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -138,11 +110,9 @@ Global
138110
HideSolutionNode = FALSE
139111
EndGlobalSection
140112
GlobalSection(NestedProjects) = preSolution
141-
{BC90EFB4-1692-CBCC-EF52-778255F591E2} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
142113
{0E2DDF4A-A1FE-5424-03EA-7A8E76751354} = {B36A84DF-456D-A817-6EDD-3EC3E7F6E11F}
143114
{9C4AFB5E-ED75-909E-FC61-1BD17BB6BC23} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
144115
{2BDCF8E8-DD35-3BA0-0148-5A2588335678} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
145-
{D6F509B1-C990-0533-2DD1-CFFBA7506249} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
146116
{23E19BC3-8829-42BE-BCB4-A2050BE04975} = {B36A84DF-456D-A817-6EDD-3EC3E7F6E11F}
147117
{267842B2-D915-4B9E-8448-F9B5816D4A0A} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
148118
{A1B2C3D4-E5F6-7890-ABCD-EF1234567890} = {F8E63A4F-7D3E-4B2A-9C1D-8A5F6E9B3C2D}

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.2.0] - 2026-03-03
9+
10+
### Breaking Changes
11+
- Removed `BitcoinKernel` facade package and `KernelLibrary` fluent builder; consumers now use the managed API directly
12+
- Renamed package/namespaces from `BitcoinKernel.Core` to `BitcoinKernel`
13+
- `Chain` class moved from `BitcoinKernel.Abstractions` to `BitcoinKernel.Chain`; import `using BitcoinKernel.Chain;` to access it
14+
- `BitcoinKernel.Abstractions` namespace renamed to `BitcoinKernel.Primatives`; update any `using BitcoinKernel.Abstractions;` imports accordingly
15+
- `LoggingConnection` moved from the global namespace into `BitcoinKernel`; add `using BitcoinKernel;` if not already present
16+
17+
### Changed
18+
- Examples rewritten to use the managed API directly without the fluent builder
19+
820
## [0.1.2] - 2026-01-26
921

1022
### Added

README.md

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,36 @@
11
# BitcoinKernel.NET
22

3-
.NET bindings and high-level library for [libbitcoinkernel](https://github.com/bitcoin/bitcoin/tree/master/src/kernel), providing access to Bitcoin Core's consensus and validation logic.
3+
.NET bindings for [libbitcoinkernel](https://github.com/bitcoin/bitcoin/tree/master/src/kernel), providing access to Bitcoin Core's consensus and validation logic.
44

5+
⚠️🚧 This library is still under construction. ⚠️🚧
56

6-
⚠️🚧 This library is still under contruction. ⚠️🚧
7-
8-
This library uses [libbitcoinkernel](https://github.com/bitcoin/bitcoin/tree/master/src/kernel) which is in an experimental state, do not use for production purposes.
9-
10-
## Overview
11-
12-
BitcoinKernel.NET brings Bitcoin Core's robust consensus engine to .NET applications through a clean, idiomatic C# API. Built on top of libbitcoinkernel, it provides everything from low-level P/Invoke bindings to high-level abstractions for common Bitcoin operations.
7+
This library uses [libbitcoinkernel](https://github.com/bitcoin/bitcoin/tree/master/src/kernel) which is in an experimental state, do not use for production purposes.
138

149
## Packages
1510

1611
| Package | Version | Description |
1712
|---------|---------|-------------|
18-
| **BitcoinKernel** | 0.1.2 | High-level API with fluent builder pattern |
19-
| **BitcoinKernel.Core** | 0.1.2 | Managed wrappers and native bindings |
20-
21-
22-
## Quick Start
23-
24-
### Installation
13+
| **BitcoinKernel** | 0.2.0 | Managed wrappers and native bindings |
2514

2615
```bash
2716
dotnet add package BitcoinKernel
2817
```
2918

30-
or
31-
32-
```bash
33-
dotnet add package BitcoinKernel.Core
34-
```
35-
3619
## Architecture
3720

38-
The library is organized in three layers:
21+
The library is organized in two layers:
3922

4023
1. **BitcoinKernel.Interop** - P/Invoke bindings to libbitcoinkernel (bundled, not published separately)
41-
2. **BitcoinKernel.Core** - Managed C# wrappers with automatic memory management
42-
3. **BitcoinKernel** - High-level facade with fluent API
24+
2. **BitcoinKernel** - Managed C# wrappers with automatic memory management
4325

4426
```
4527
┌─────────────────────────────┐
46-
│ BitcoinKernel │ ← Fluent API, simple usage
47-
│ (Facade Layer) │
48-
└─────────────┬───────────────┘
49-
50-
┌─────────────▼───────────────┐
51-
│ BitcoinKernel.Core │ ← Managed wrappers, IDisposable
28+
│ BitcoinKernel │ ← Managed wrappers, IDisposable
5229
│ (Wrapper Layer) │
5330
└─────────────┬───────────────┘
5431
5532
┌─────────────▼───────────────┐
56-
│ BitcoinKernel.Interop │ ← P/Invoke bindings
33+
│ BitcoinKernel.Interop │ ← P/Invoke bindings (bundled)
5734
│ (Binding Layer) │
5835
└─────────────┬───────────────┘
5936
@@ -63,26 +40,44 @@ The library is organized in three layers:
6340
└─────────────────────────────┘
6441
```
6542

43+
## Quick Start
44+
45+
```csharp
46+
using BitcoinKernel;
47+
using BitcoinKernel.Chain;
48+
using BitcoinKernel.Interop.Enums;
49+
50+
using var logging = new LoggingConnection((category, message, level) =>
51+
Console.WriteLine($"[{category}] {message}"));
52+
53+
using var chainParams = new ChainParameters(ChainType.MAINNET);
54+
using var contextOptions = new KernelContextOptions().SetChainParams(chainParams);
55+
using var context = new KernelContext(contextOptions);
56+
using var options = new ChainstateManagerOptions(context, dataDir, blocksDir);
57+
using var chainstate = new ChainstateManager(context, chainParams, options);
58+
59+
var chain = chainstate.GetActiveChain();
60+
Console.WriteLine($"Height: {chain.Height}");
61+
Console.WriteLine($"Genesis: {Convert.ToHexString(chain.GetGenesis().GetBlockHash())}");
62+
```
63+
6664
## Examples
6765

6866
Explore the [examples](examples/) directory for complete working samples:
6967

70-
- **[BasicUsage](examples/BasicUsage/)** - Getting started with the high-level API
71-
- **[BlockProcessing](examples/BlockProcessing/)** - Block validation and chain management
68+
- **[BasicUsage](examples/BasicUsage/)** - Getting started with chain queries
69+
- **[BlockProcessing](examples/BlockProcessing/)** - Block validation and processing
7270

7371
## Tools
7472

7573
### Kernel Bindings Test Handler
7674

77-
A conformance test handler for Kernel bindings Test handler framework, see [tools/kernel-bindings-test-handler](tools/kernel-bindings-test-handler/) for details.
75+
A conformance test handler for the Kernel bindings test framework, see [tools/kernel-bindings-test-handler](tools/kernel-bindings-test-handler/) for details.
7876

79-
**Usage:**
8077
```bash
8178
dotnet run --project tools/kernel-bindings-test-handler
8279
```
8380

84-
The handler communicates via stdin/stdout and is designed for automated conformance testing.
85-
8681
## Building from Source
8782

8883
### Prerequisites
@@ -109,7 +104,7 @@ This package includes pre-built `libbitcoinkernel` binaries for:
109104
- macOS (x64, ARM64)
110105
- others will follow
111106

112-
For other platforms, for now, you'll need to build libbitcoinkernel from the [Bitcoin Core repository](https://github.com/bitcoin/bitcoin).
107+
For other platforms, you'll need to build libbitcoinkernel from the [Bitcoin Core repository](https://github.com/bitcoin/bitcoin).
113108

114109
## Documentation
115110

@@ -135,4 +130,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
135130

136131
- Built on [libbitcoinkernel](https://github.com/bitcoin/bitcoin/tree/master/src/kernel) from Bitcoin Core
137132

138-
**Note**: This library provides access to Bitcoin Core's consensus engine. The libbitcoinkernel and this package is stil experimental and not ready for production use.
133+
**Note**: This library provides access to Bitcoin Core's consensus engine. libbitcoinkernel and this package are still experimental and not ready for production use.

examples/BasicUsage/Program.cs

Lines changed: 61 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,63 @@
1-
using System;
2-
using BitcoinKernel;
3-
4-
namespace FacadeExample
5-
{
6-
class Program
7-
{
8-
static void Main(string[] args)
9-
{
10-
Console.WriteLine("=== Bitcoin Kernel Basic Builder Example ===\n");
11-
12-
FullChainstateExample();
13-
14-
}
15-
16-
static void FullChainstateExample()
17-
{
18-
Console.WriteLine("2. Full Chainstate Example:");
19-
20-
Console.WriteLine(" Creating builder...");
21-
var builder = KernelLibrary.Create()
22-
.ForMainnet()
23-
.WithWorkerThreads(2)
24-
.WithDirectories("/tmp/regtest-data2", "/tmp/regtest-data/blocks2");
25-
26-
Console.WriteLine(" Configuring logging...");
27-
builder = builder.WithLogging((category, message, level) =>
28-
{
29-
if (level <= (int)BitcoinKernel.Interop.Enums.LogLevel.INFO) // Only INFO and above
30-
Console.WriteLine($" [{category}] {message}");
31-
});
32-
33-
Console.WriteLine(" Building kernel...");
34-
using var kernel = builder.Build();
35-
36-
Console.WriteLine(" Kernel built successfully!");
37-
Console.WriteLine(" ✓ Chainstate initialized automatically");
38-
39-
// Process blocks
40-
try
41-
{
42-
43-
Console.WriteLine(" ✓ Ready to process blocks");
44-
45-
// Show new query methods
46-
Console.WriteLine($" Chain height: {kernel.GetChainHeight()}");
47-
Console.WriteLine($" Genesis hash: {Convert.ToHexString(kernel.GetGenesisBlockHash())}");
48-
49-
if (kernel.GetChainHeight() > 0)
50-
{
51-
var tipHash = kernel.GetChainTipHash();
52-
Console.WriteLine($" Tip hash: {Convert.ToHexString(tipHash)}");
53-
54-
var blockInfo = kernel.GetBlockInfo(0);
55-
if (blockInfo != null)
56-
{
57-
Console.WriteLine($" Block 0 hash: {Convert.ToHexString(blockInfo.Hash)}");
58-
}
59-
}
60-
61-
Console.WriteLine(" ✓ Chain queries working");
62-
}
63-
catch (Exception ex)
64-
{
65-
Console.WriteLine($" ✗ Error: {ex.Message}");
1+
using BitcoinKernel;
2+
using BitcoinKernel.Chain;
3+
using BitcoinKernel.Interop.Enums;
4+
5+
namespace BasicUsage;
6+
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
Console.WriteLine("=== Bitcoin Kernel Basic Usage Example ===\n");
12+
FullChainstateExample();
13+
}
14+
15+
static void FullChainstateExample()
16+
{
17+
Console.WriteLine("Creating kernel...");
18+
19+
var dataDir = "/tmp/regtest-data2";
20+
var blocksDir = "/tmp/regtest-data/blocks2";
21+
22+
using var logging = new LoggingConnection((category, message, level) =>
23+
{
24+
if (level <= (int)LogLevel.INFO)
25+
Console.WriteLine($" [{category}] {message}");
26+
});
27+
28+
using var chainParams = new ChainParameters(ChainType.MAINNET);
29+
using var contextOptions = new KernelContextOptions().SetChainParams(chainParams);
30+
using var context = new KernelContext(contextOptions);
31+
using var options = new ChainstateManagerOptions(context, dataDir, blocksDir)
32+
.SetWorkerThreads(2);
33+
using var chainstate = new ChainstateManager(context, chainParams, options);
34+
35+
Console.WriteLine(" Kernel created successfully!");
36+
37+
try
38+
{
39+
var chain = chainstate.GetActiveChain();
40+
Console.WriteLine($" Chain height: {chain.Height}");
41+
Console.WriteLine($" Genesis hash: {Convert.ToHexString(chain.GetGenesis().GetBlockHash())}");
42+
43+
if (chain.Height > 0)
44+
{
45+
var tip = chain.GetTip();
46+
Console.WriteLine($" Tip hash: {Convert.ToHexString(tip.GetBlockHash())}");
47+
48+
var genesis = chain.GetBlockByHeight(0);
49+
if (genesis != null)
50+
Console.WriteLine($" Block 0 hash: {Convert.ToHexString(genesis.GetBlockHash())}");
6651
}
6752

68-
69-
Console.WriteLine("\nPress any key to exit...");
70-
Console.ReadKey();
71-
72-
kernel.Dispose();
73-
Console.WriteLine(" Kernel disposed.");
74-
}
75-
}
76-
}
53+
Console.WriteLine(" Chain queries working");
54+
}
55+
catch (Exception ex)
56+
{
57+
Console.WriteLine($" Error: {ex.Message}");
58+
}
59+
60+
Console.WriteLine("\nPress any key to exit...");
61+
Console.ReadKey();
62+
}
63+
}

0 commit comments

Comments
 (0)