Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

TransactionDecoderTrait

Bitcoin transaction decoder trait providing methods to decode raw Bitcoin transaction data.

This trait implements the complete Bitcoin transaction format decoder, supporting both legacy and SegWit transaction formats according to BIP 141. It handles variable-length encoding (compact size), little-endian integer decoding, and proper transaction structure parsing.

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait

pub trait TransactionDecoderTrait

Trait functions

new

Creates a new Bitcoin transaction decoder from raw transaction data.

Arguments

  • data - Raw Bitcoin transaction data as a ByteArray

Returns

  • BTCDecoder - Initialized decoder context with offset set to 0

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::new

fn new(data: ByteArray) -> BTCDecoder

decode_transaction

Decodes a complete Bitcoin transaction from the current decoder context.

Parses the entire transaction structure including version, inputs, outputs, witness data (if SegWit), and locktime. Automatically detects SegWit transactions by checking for the marker (0x00) and flag (0x01) bytes.

Arguments

  • self - Mutable reference to the decoder context

Returns

  • BitcoinTransaction - Complete decoded transaction structure

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::decode_transaction

fn decode_transaction(ref self: BTCDecoder) -> BitcoinTransaction

decode_input

Decodes a single Bitcoin transaction input from the current position.

Parses input structure: previous TXID (32 bytes), previous output index, script signature with compact size length prefix, and sequence number.

Arguments

  • self - Mutable reference to the decoder context

Returns

  • TransactionInput - Decoded input with all fields populated

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::decode_input

fn decode_input(ref self: BTCDecoder) -> TransactionInput

decode_output

Decodes a single Bitcoin transaction output from the current position.

Parses output structure: value (8 bytes, little-endian) and script public key with compact size length prefix.

Arguments

  • self - Mutable reference to the decoder context

Returns

  • TransactionOutput - Decoded output with value and script

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::decode_output

fn decode_output(ref self: BTCDecoder) -> TransactionOutput

decode_witness

Decodes SegWit witness data for a single input.

Parses witness stack structure: witness item count (compact size) followed by each witness item with its length prefix and data.

Arguments

  • self - Mutable reference to the decoder context

Returns

  • TransactionWitness - Decoded witness data with all stack items

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::decode_witness

fn decode_witness(ref self: BTCDecoder) -> TransactionWitness

read_compact_size

Reads a Bitcoin compact size integer (variable-length encoding).

Implements Bitcoin’s compact size encoding:

  • < 0xfd: 1 byte value
  • 0xfd: 3 bytes (1 + 2 little-endian)
  • 0xfe: 5 bytes (1 + 4 little-endian)
  • 0xff: 9 bytes (1 + 8 little-endian)

Arguments

  • self - Mutable reference to the decoder context

Returns

  • u64 - The decoded integer value

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::read_compact_size

fn read_compact_size(ref self: BTCDecoder) -> u64

read_u8

Reads a single byte from the current position.

Arguments

  • self - Mutable reference to the decoder context

Returns

  • u8 - The byte value at the current position

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::read_u8

fn read_u8(ref self: BTCDecoder) -> u8

read_u32_le

Reads 4 bytes as a little-endian unsigned 32-bit integer.

####### Arguments

  • self - Mutable reference to the decoder context

####### Returns

  • u32 - The decoded little-endian u32 value

Panics

Panics with ‘Not enough bytes for u32’ if fewer than 4 bytes remain.

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::read_u32_le

fn read_u32_le(ref self: BTCDecoder) -> u32

read_u64_le

Reads 8 bytes as a little-endian unsigned 64-bit integer.

####### Arguments

  • self - Mutable reference to the decoder context

####### Returns

  • u64 - The decoded little-endian u64 value
Panics

Panics with ‘Not enough bytes for u64’ if fewer than 8 bytes remain.

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::read_u64_le

fn read_u64_le(ref self: BTCDecoder) -> u64

remaining

Checks if there are sufficient bytes remaining to read from the specified offset.

####### Arguments

  • self - Reference to the decoder context
  • offset - The offset position to check from
  • count - Number of bytes needed

####### Returns

  • bool - True if sufficient bytes remain, false otherwise

Fully qualified path: alexandria_btc::decoder::TransactionDecoderTrait::remaining

fn remaining(self: @BTCDecoder, offset: u32, count: u32) -> bool