Skip to content

futurepaul/chin

Repository files navigation

chin

A Bitcoin transaction parser written in Zig. Outputs JSON matching bitcoin-cli decoderawtransaction format.

Includes a TUI mode for interactive learning. Just hover the value on either side to learn how it ser/deserializes.

chin.mov

Building

zig build

Usage

chin [hexstring] [iswitness]
chin < file.hex
echo <hex> | chin

Examples

Parse a transaction directly (like bitcoin-cli decoderawtransaction):

./zig-out/bin/chin 0100000001c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25857fcd3704000000004847304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901ffffffff0200ca9a3b00000000434104ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6cd84cac00286bee0000000043410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac00000000

Pipe from stdin:

echo "0100000001..." | ./zig-out/bin/chin

Read from a file:

./zig-out/bin/chin transaction.hex
# or
cat tx.hex | ./zig-out/bin/chin

Options

Argument Description
hexstring The transaction hex string
iswitness Force witness parsing: true or false (optional, auto-detected by default)
-h, --help Show usage help

TUI Mode

An interactive terminal UI for exploring transactions:

./zig-out/bin/chin-tui 0100000001...
# or
./zig-out/bin/chin-tui transaction.hex

TUI Keybindings

Key Action
h / l Switch focus between hex and JSON panels
j / k Scroll down / up
/ Scroll down / up
y Yank (copy) hovered field's hex value to clipboard
q Quit

Hover over a field with the mouse to highlight it in both panels. The status bar shows field details.

Output Format

Output matches bitcoin-tx -json format:

{
  "txid": "...",
  "hash": "...",
  "version": 1,
  "size": 225,
  "vsize": 225,
  "weight": 900,
  "locktime": 0,
  "vin": [...],
  "vout": [...],
  "hex": "..."
}

Testing

Unit Tests

Run the built-in unit tests:

zig build test

Bitcoin Core Test Vectors

Run against Bitcoin Core's tx_valid.json test vectors:

# Basic run
./zig-out/bin/test-vectors vectors/tx_valid.json

# With custom bitcoin-tx path
./zig-out/bin/test-vectors -b ./bitcoin-tx vectors/tx_valid.json

# Benchmarking mode (run each tx N times)
./zig-out/bin/test-vectors -n 100 vectors/tx_valid.json

Test Vector Options

Option Description
-n <count> Run each transaction N times (for benchmarking)
-b <path> Path to bitcoin-tx binary (default: ./bitcoin-tx)
-v Verbose output
-h Show help

Project Structure

src/
  main.zig          # CLI entry point
  args.zig          # Shared argument parsing
  parser.zig        # Transaction parsing
  script.zig        # Script disassembly and classification
  encoding.zig      # Address encoding (base58, bech32)
  root.zig          # Library exports
  test_vectors.zig  # Test vector loader
  json_compare.zig  # JSON comparison utility
  test_runner.zig   # Test harness
  tui/
    main.zig        # TUI entry point

Dependencies

The main chin CLI has no external dependencies - just the Zig standard library.

The chin-tui interactive viewer depends on libvaxis for terminal rendering.

For running test vector comparisons:

  • bitcoin-tx binary
  • Bitcoin Core test data (tx_valid.json, tx_invalid.json, vendored in vectors/)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors