Skip to content

Class X402::SettlementWorker

Inherits: Object

Background thread that broadcasts transactions to ARC with exponential backoff retry. Uses Ruby stdlib Thread + Queue (zero dependencies).

Any object responding to +#enqueue(tx_binary)+ satisfies the pluggable worker interface expected by PayGateway's async settlement path.

@example With failure callback

worker = X402::SettlementWorker.new(
  arc_client: arc,
  on_failure: ->(tx_binary, error) { logger.error("Settlement failed: #{error}") }
)

Constants

ACCEPTABLE_STATUSES

Not documented.

DEFAULT_MAX_QUEUE

Not documented.

Attributes

max_queue [R]

Returns the value of attribute max_queue.

max_retries [R]

Returns the value of attribute max_retries.

Public Instance Methods

enqueue(tx_binary)

Enqueue a transaction for background broadcast. - @param tx_binary [String] raw transaction bytes - @raise [X402::VerificationError] with status 503 when queue is full

initialize(arc_client:, max_retries: = 5, max_queue: = DEFAULT_MAX_QUEUE, on_failure: = nil)

  • @param arc_client [#broadcast] ARC client for broadcasting
  • @param max_retries [Integer] retry attempts before giving up (default 5)
  • @param max_queue [Integer] maximum queued transactions (default 1000). Raises +X402::VerificationError+ (503) when full.
  • @param on_failure [#call, nil] callback invoked with +(tx_binary, error)+ when all retries are exhausted. Default nil (silent drop).
  • @return [SettlementWorker] a new instance of SettlementWorker

stop()

Drain the queue and stop the background thread. Safe to call when no thread has started (no-op). - @return [void]