Skip to contentK.(mufasa)
Menu
← All projects

Rust library & CLI

Bitcoin Transaction Parser

Turn raw Bitcoin transaction bytes into inspectable fields, while keeping parsing separate from transaction validation.

Software engineer

System flow

  1. 01Read transaction hex
  2. 02Parse binary fields
  3. 03Extract witness data
  4. 04Calculate the txid
  5. 05Serialize as JSON

Problem & scope

Raw transaction hex hides the structure of inputs, outputs, scripts, amounts, and witness data. The parser makes those fields inspectable through a Rust library and a thin command-line interface.

The project decodes legacy and SegWit transactions. Parsing a transaction does not establish that its scripts, signatures, or spending rules are valid.

Architecture & packages

The library separates byte readers, transaction types, and errors from command handling. Numeric fields use little-endian conversion, CompactSize decoding rejects noncanonical encodings, and complete parsing rejects trailing bytes.

Clap handles arguments; Hex handles hex conversion; SHA2 supplies SHA-256; Serde and Serde JSON serialize the result; Thiserror represents decoding failures. Transaction parsing is implemented in the project.

SegWit identifiers

For a legacy transaction, the transaction ID is derived from the complete serialized transaction. For SegWit, the parser reconstructs serialization without the marker, flag, and witness data before applying double SHA-256. Witness data remains available in the decoded output.

Verification & next steps

Repository tests include a genesis transaction fixture, a SegWit fixture, malformed hex, trailing bytes, and separate checks for byte readers and CompactSize. These tests were inspected during the portfolio review, rather than independently executed.

Useful next steps include broader comparisons against Bitcoin Core, bounded allocations for untrusted lengths, and exact integer satoshi amounts in JSON output. The current internal amount is an integer, while output converts it to floating-point BTC.

Explore more work