Class: BSV::Transaction::ChainTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/bsv/transaction/chain_tracker.rb

Overview

Base class for chain trackers that verify merkle roots against the blockchain.

Chain trackers confirm that a given merkle root corresponds to a valid block at a specific height. This is essential for SPV verification — without it, merkle proofs cannot be validated against the actual blockchain.

Subclasses must implement #valid_root_for_height? and #current_height.

Examples:

Implementing a custom chain tracker

class MyTracker < BSV::Transaction::ChainTracker
  def valid_root_for_height?(root, height)
    # query your block header source
  end

  def current_height
    # return current chain tip height
  end
end

Instance Method Summary collapse

Instance Method Details

#current_heightInteger

Return the current blockchain height.

Returns:

  • (Integer)

    the height of the chain tip

Raises:

  • (NotImplementedError)

    if not overridden by a subclass



38
39
40
# File 'lib/bsv/transaction/chain_tracker.rb', line 38

def current_height
  raise NotImplementedError, "#{self.class}#current_height must be implemented"
end

#valid_root_for_height?(_root, _height) ⇒ Boolean

Verify that a merkle root is valid for the given block height.

Parameters:

  • root (String)

    merkle root as a hex string

  • height (Integer)

    block height

Returns:

  • (Boolean)

    true if the root matches the block at the given height

Raises:

  • (NotImplementedError)

    if not overridden by a subclass



30
31
32
# File 'lib/bsv/transaction/chain_tracker.rb', line 30

def valid_root_for_height?(_root, _height)
  raise NotImplementedError, "#{self.class}#valid_root_for_height? must be implemented"
end