Btczee
Bitcoin protocol implementation in Zig.
Install / Use
/learn @zig-bitcoin/BtczeeREADME
<a href="https://github.com/zig-bitcoin/btczee/actions/workflows/check.yml"><img alt="GitHub Workflow Status" src="https://img.shields.io/github/actions/workflow/status/zig-bitcoin/btczee/check.yml?style=for-the-badge" height=30></a> <a href="https://ziglang.org/"> <img alt="Zig" src="https://img.shields.io/badge/zig-%23000000.svg?style=for-the-badge&logo=zig&logoColor=white" height=30></a> <a href="https://bitcoin.org/"> <img alt="Bitcoin" src="https://img.shields.io/badge/Bitcoin-000?style=for-the-badge&logo=bitcoin&logoColor=white" height=30></a> <a href="https://lightning.network/"><img src="https://img.shields.io/badge/Ligthning Network-000.svg?&style=for-the-badge&logo=data:image/svg%2bxml;base64%2CPD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI%2FPg0KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIEZpcmV3b3JrcyAxMCwgRXhwb3J0IFNWRyBFeHRlbnNpb24gYnkgQWFyb24gQmVhbGwgKGh0dHA6Ly9maXJld29ya3MuYWJlYWxsLmNvbSkgLiBWZXJzaW9uOiAwLjYuMSAgLS0%2BDQo8IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPg0KPHN2ZyBpZD0iYml0Y29pbl9saWdodG5pbmdfaWNvbi5mdy1QYWdlJTIwMSIgdmlld0JveD0iMCAwIDI4MCAyODAiIHN0eWxlPSJiYWNrZ3JvdW5kLWNvbG9yOiNmZmZmZmYwMCIgdmVyc2lvbj0iMS4xIg0KCXhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHhtbDpzcGFjZT0icHJlc2VydmUiDQoJeD0iMHB4IiB5PSIwcHgiIHdpZHRoPSIyODBweCIgaGVpZ2h0PSIyODBweCINCj4NCgk8cGF0aCBpZD0iRWxsaXBzZSIgZD0iTSA3IDE0MC41IEMgNyA2Ni43NjkgNjYuNzY5IDcgMTQwLjUgNyBDIDIxNC4yMzEgNyAyNzQgNjYuNzY5IDI3NCAxNDAuNSBDIDI3NCAyMTQuMjMxIDIxNC4yMzEgMjc0IDE0MC41IDI3NCBDIDY2Ljc2OSAyNzQgNyAyMTQuMjMxIDcgMTQwLjUgWiIgZmlsbD0iI2Y3OTMxYSIvPg0KCTxwYXRoIGQ9Ik0gMTYxLjE5NDMgNTEuNSBDIDE1My4yMzQ5IDcyLjE2MDcgMTQ1LjI3NTYgOTQuNDEwNyAxMzUuNzI0NCAxMTYuNjYwNyBDIDEzNS43MjQ0IDExNi42NjA3IDEzNS43MjQ0IDExOS44MzkzIDEzOC45MDgxIDExOS44MzkzIEwgMjA0LjE3NDcgMTE5LjgzOTMgQyAyMDQuMTc0NyAxMTkuODM5MyAyMDQuMTc0NyAxMjEuNDI4NiAyMDUuNzY2NyAxMjMuMDE3OSBMIDExMC4yNTQ1IDIyOS41IEMgMTA4LjY2MjYgMjI3LjkxMDcgMTA4LjY2MjYgMjI2LjMyMTQgMTA4LjY2MjYgMjI0LjczMjEgTCAxNDIuMDkxOSAxNTMuMjE0MyBMIDE0Mi4wOTE5IDE0Ni44NTcxIEwgNzUuMjMzMyAxNDYuODU3MSBMIDc1LjIzMzMgMTQwLjUgTCAxNTYuNDE4NyA1MS41IEwgMTYxLjE5NDMgNTEuNSBaIiBmaWxsPSIjZmZmZmZmIi8%2BDQo8L3N2Zz4%3D" alt="Bitcoin Lightning" height="30"></a>
</div>About
btczee is a Bitcoin protocol implementation in Zig. It aims to provide a clean and simple implementation of the Bitcoin protocol. The goal is to have a fully functional Bitcoin node that can be used to interact with the Bitcoin network.
Architecture
You can find the architecture of the project and description of components in the docs/architecture.md file.
graph TD
Node[Node] --> Network
Node --> Mempool
Node --> Wallet
Node --> Storage
Node --> Miner
Network --> Mempool
Network --> Storage
Mempool --> Wallet
Mempool --> Storage
Wallet --> Storage
Miner --> Mempool
Miner --> Storage
subgraph "Core Components"
Node
Network
Mempool
Wallet
Storage
Miner
end
subgraph "Supporting Components"
Types
Primitives
Config
end
Node -.-> Types
Node -.-> Primitives
Node -.-> Config
classDef core fill:#f9f,stroke:#333,stroke-width:2px;
classDef support fill:#bbf,stroke:#333,stroke-width:1px;
class Node,Network,Mempool,Wallet,Storage,Miner core;
class Types,Primitives,Config support;
Run
Usage: btczee [command] [args]
Commands:
node <subcommand>
wallet <subcommand>
Node
Usage: btczee node <subcommand>
Subcommands:
help Display help for node
Example:
zig build run -- node
# OR (after a build)
./zig-out/bin/btczee node
Wallet
Usage: btczee wallet <subcommand>
Subcommands:
create Create a new wallet
load Load an existing wallet
help Display help for wallet
Example:
zig build run -- wallet create
# OR (after a build)
./zig-out/bin/btczee wallet create
Test
zig build test --summary all
Build
zig build -Doptimize=ReleaseFast
Benchmark
zig build bench
Documentation
You can generate the documentation by running the following command:
zig build docs
Roadmap
You can find the roadmap of the project in the docs/roadmap.md file.
License
btczee is licensed under the MIT license. See the LICENSE file for more details.
References
- Bitcoin Core
- Learn me a bitcoin
- Mastering Bitcoin
- Onboarding to Bitcoin Core
- Zig
- Zig Standard Library
- Ziglings
Acknowledgements
- Syndica sig client in Zig, we are using a copy of their
timeandtracemodules. Right now, they are not usable as external dependencies, we hope it will be possible in the future, and if so, we will switch to using their libraries directly.
Supported Opcodes
47/107 opcodes supported (43.92%).
%%{init: {"pie": {"textPosition": 0.75}, "themeVariables": {"pieOuterStrokeWidth": "5px"}} }%%
pie showData
title Opcode Implementation Status
"Implemented" : 47
"Disabled" : 0
"Not Implemented" : 60
| Opcode | Hex | Supported | Description | | ---------------------- | --------- | :-------: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | op0 / opFalse | 0x00 | ❌ | An empty array of bytes is pushed onto the stack. | | opData1-opData75 | 0x01-0x4b | ❌ | The next opcode bytes is data to be pushed onto the stack. | | opPushData1 | 0x4c | ✅ | The next byte contains the number of bytes to be pushed onto the stack. | | opPushData2 | 0x4d | ✅ | The next two bytes contain the number of bytes to be pushed onto the stack in little endian order. | | opPushData4 | 0x4e | ✅ | The next four bytes contain the number of bytes to be pushed onto the stack in little endian order. | | op1Negate | 0x4f | ✅ | The number -1 is pushed onto the stack.
